From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: richardeng Newsgroups: gmane.emacs.devel Subject: Elisp info request: function parameter passing Date: Wed, 10 Dec 2008 02:00:09 +0800 Message-ID: <493EB229.20308@foxmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------060609030006060900060505" X-Trace: ger.gmane.org 1228845660 25482 80.91.229.12 (9 Dec 2008 18:01:00 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 9 Dec 2008 18:01:00 +0000 (UTC) Cc: Alan Mackenzie , Thierry Volpiatto To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Dec 09 19:02:02 2008 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1LA6tu-00066N-Dq for ged-emacs-devel@m.gmane.org; Tue, 09 Dec 2008 19:01:38 +0100 Original-Received: from localhost ([127.0.0.1]:45404 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LA6sj-0005TY-Gx for ged-emacs-devel@m.gmane.org; Tue, 09 Dec 2008 13:00:25 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LA6se-0005RL-0c for emacs-devel@gnu.org; Tue, 09 Dec 2008 13:00:20 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LA6sd-0005Qk-B6 for emacs-devel@gnu.org; Tue, 09 Dec 2008 13:00:19 -0500 Original-Received: from [199.232.76.173] (port=57802 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LA6sd-0005Qc-5J for emacs-devel@gnu.org; Tue, 09 Dec 2008 13:00:19 -0500 Original-Received: from smtpbg1.foxmail.com ([58.61.33.111]:51653) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1LA6sc-0007mb-BB for emacs-devel@gnu.org; Tue, 09 Dec 2008 13:00:18 -0500 Original-Received: from 172.23.147.51 (foxmail.com [172.23.147.51]) by smtpbg1 (foxmail.com) with SMTP id vxDsKkvz; Wed, 10 Dec 2008 02:00:10 +0800 (envelope-from richardeng@foxmail.com) X-QQ-mid: esmtp4122884561020910524 Original-Received: from [192.168.1.202] (unknown [116.224.216.28]) by smtp.foxmail.com (Postfix) with ESMTP id ; Wed, 10 Dec 2008 02:00:10 +0800 (CST) User-Agent: Thunderbird 2.0.0.18 (Windows/20081105) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.4-2.6 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:106720 Archived-At: This is a multi-part message in MIME format. --------------060609030006060900060505 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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? --------------060609030006060900060505 Content-Type: message/rfc822; name="Re: How could I modify list element?.eml" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="Re: How could I modify list element?.eml" X-Mozilla-Keys: Message-ID: <493EAE3B.8020707@foxmail.com> Date: Wed, 10 Dec 2008 01:43:23 +0800 From: richardeng User-Agent: Thunderbird 2.0.0.18 (Windows/20081105) MIME-Version: 1.0 To: Alan Mackenzie CC: help-gnu-emacs@gnu.org Subject: Re: How could I modify list element? References: <493E7D65.3020405@foxmail.com> <20081209163258.B7055@colin2.muc.de> In-Reply-To: <20081209163258.B7055@colin2.muc.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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! --------------060609030006060900060505--