Page 1 of 1

Setup functions by setq

Posted: Fri Aug 28, 2020 5:54 am
by lyl
I'd like to make a series of functions whose names come from a list, as shown by the following codes:

Code: Select all

(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?

Re: Setup functions by setq

Posted: Fri Aug 28, 2020 10:21 am
by newBert
lyl wrote:
Fri Aug 28, 2020 5:54 am

Code: Select all

(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 :

Code: Select all

(dolist (x a)
  (let (z $idx)
    (set (sym x) (expand (lambda (y) z) 'z))))