Path: csiph.com!weretis.net!feeder6.news.weretis.net!border-3.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-1.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail NNTP-Posting-Date: Fri, 19 Apr 2024 22:14:19 +0000 From: steve Newsgroups: comp.lang.lisp Subject: Re: how to map a variable to a list? References: Date: Fri, 19 Apr 2024 18:14:18 -0400 Message-ID: <87bk6580g5.fsf@gmail.com> Organization:  User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:XjtrKL89Hub9zVcBHOPnwsx9eI8= MIME-Version: 1.0 Content-Type: text/plain Lines: 45 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-sICnUAArwJ/MxVMfoyuZS7cuTSMStYwcSbWTBUCpxxPNZgVqNBuNkS61LKMcc9hWsjvaRR8T8X3iexw!Gp9D4L2r+9lBAHJ/8ZJHzKfkuXM1OozhRT1W7fbYQknR4A== X-Complaints-To: abuse@giganews.com X-DMCA-Notifications: http://www.giganews.com/info/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 Xref: csiph.com comp.lang.lisp:59554 Spiros Bousbouras writes: < On Mon, 10 Apr 2023 21:05:23 +0800 < Jinsong Zhao wrote: >> Hi there, >> >> In the following code example, >> >> (defun a-test (lst) >> (let ((a (elt lst 0)) >> (b (elt lst 1)) >> (c (elt lst 2))) >> (+ a (- c b)))) >> >> How to map local variable a, b, and c to the elements of lst? In my >> actual code, the lst have 12 elements, and I have 12 named local >> variables that appeared in the body with high frequency. < Why is the above code not satisfactory ? no idea, works for me. (defun a-test (lst) (let ((a (pop lst)) (b (pop lst)) (c (pop lst))) (+ a (- c b)))) (a-test '(3 5 7)) (defun a-test2 (lst) (let ((a (elt lst 0)) (b (elt lst 1)) (c (elt lst 2))) (+ a (- c b)))) (a-test2 '(1 4 7)) show the code? might be helpful. 12 variables can be done with reduce mapcar, depending on the operation.