all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: richardeng <richardeng@foxmail.com>
To: emacs-devel@gnu.org
Cc: Alan Mackenzie <acm@muc.de>,
	Thierry Volpiatto <thierry.volpiatto@gmail.com>
Subject: Elisp info request: function parameter passing
Date: Wed, 10 Dec 2008 02:00:09 +0800	[thread overview]
Message-ID: <493EB229.20308@foxmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 648 bytes --]

I just found elisp is different in function parameter passing than C, or 
we can say elisp is reference passing style. That is, the variable in 
function call is itself, the same one in elisp language. Following code 
can show this different feature.

(setq x '(1 2 3 "one" "two" "three"))
(defun fun (arg)
   (if (eq arg x)
       (message "they are eq, the same one")
     (message "they are different")))
(fun x)

I think we need to add more info about it in (elisp)Top > Functions

Another question:
I think change the element of list should be a common request. Why 
doesn't elisp provide a primitive/function for this feature. Did I miss it?

[-- Attachment #2: Re: How could I modify list element?.eml --]
[-- Type: message/rfc822, Size: 1184 bytes --]

From: richardeng <richardeng@foxmail.com>
To: Alan Mackenzie <acm@muc.de>
Cc: help-gnu-emacs@gnu.org
Subject: Re: How could I modify list element?
Date: Wed, 10 Dec 2008 01:43:23 +0800
Message-ID: <493EAE3B.8020707@foxmail.com>

Alan Mackenzie wrote:
> 
> 
> On Tue, 9 Dec 2008, richardeng wrote:
> 
>> Hi all,
>>    setcar/setcdr is not convenient.
>>    In a long list, ex.
>>    (setq a '(a b c d e f g))
>>    I want to change 'e to 'E.
>>    I need a function: (set-list-elt list old-elt new-elt)
>>
>>    How? translate list to vector, modify, then turn it back???
> 
> Try this (not tested):
> 
> (defun change-nth (liszt, n, nieuw)
>   (while (> n 0)
>     (setq liszt (cdr liszt)
>           n (1- n)))
>   (if liszt
>      (setcar liszt nieuw)))
> 
(setq aaa '(1 2 3 4 5 b a "ccc"))
(change-nth aaa 3 'BB)
aaa  --> (1 2 3 BB 5 b a "ccc")    , it works, thank you!


             reply	other threads:[~2008-12-09 18:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-09 18:00 richardeng [this message]
2008-12-09 18:50 ` Elisp info request: function parameter passing richardeng
2008-12-09 19:44 ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=493EB229.20308@foxmail.com \
    --to=richardeng@foxmail.com \
    --cc=acm@muc.de \
    --cc=emacs-devel@gnu.org \
    --cc=thierry.volpiatto@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.