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?
------------------------------------------------------------------------
Subject:
Re: How could I modify list element?
From:
richardeng <address@hidden>
Date:
Wed, 10 Dec 2008 01:43:23 +0800
To:
Alan Mackenzie <address@hidden>
To:
Alan Mackenzie <address@hidden>
CC:
address@hidden
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!