emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Elisp info request: function parameter passing


From: richardeng
Subject: Elisp info request: function parameter passing
Date: Wed, 10 Dec 2008 02:00:09 +0800
User-agent: Thunderbird 2.0.0.18 (Windows/20081105)

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?
--- Begin Message --- Subject: Re: How could I modify list element? Date: Wed, 10 Dec 2008 01:43:23 +0800 User-agent: Thunderbird 2.0.0.18 (Windows/20081105)
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!


--- End Message ---

reply via email to

[Prev in Thread] Current Thread [Next in Thread]