Setup functions by setq

Started by lyl, August 27, 2020, 10:54:17 PM

Previous topic - Next topic

lyl

I'd like to make a series of functions whose names come from a list, as shown by the following codes:
(setq a '(a1 a2))
(dolist (x a)
  (let (z $idx)
    (setq x (lambda(y) z))
    ))

what I want is to get two functions

a1: (lambda (y) 0)

a2: (lambda (y) 1)

But I fail.

What's wrong with my code, and how to solve it?

newBert

#1
Quote from: lyl post_id=24920 time=1598594057 user_id=1262
(setq a '(a1 a2))
(dolist (x a)
  (let (z $idx)
    (setq x (lambda(y) z))
    ))

What's wrong with my code, and how to solve it?


Maybe with :
(dolist (x a)
  (let (z $idx)
    (set (sym x) (expand (lambda (y) z) 'z))))
<r><I>>Bertrand<e></e></I> − <COLOR color=\"#808080\">><B>newLISP<e></e></B> v.10.7.6 64-bit <B>>on Linux<e></e></B> (<I>>Linux Mint 20.1<e></e></I>)<e></e></COLOR></r>