Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.lisp > #59554

Re: how to map a variable to a list?

From steve <sgonedes1977@gmail.com>
Newsgroups comp.lang.lisp
Subject Re: how to map a variable to a list?
References <u111j3$26d7d$1@dont-email.me> <O5sf1cOqAlzNMgIN7@bongo-ra.co>
Date 2024-04-19 18:14 -0400
Message-ID <87bk6580g5.fsf@gmail.com> (permalink)
Organization 

Show all headers | View raw


Spiros Bousbouras <spibou@gmail.com> writes:

< On Mon, 10 Apr 2023 21:05:23 +0800
< Jinsong Zhao <jszhao@yeah.net> 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.

Back to comp.lang.lisp | Previous | Next | Find similar


Thread

Re: how to map a variable to a list? steve <sgonedes1977@gmail.com> - 2024-04-19 18:14 -0400

csiph-web