Setup functions by setq

Q&A's, tips, howto's
Locked
lyl
Posts: 44
Joined: Sun Mar 25, 2018 5:00 am

Setup functions by setq

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

newBert
Posts: 156
Joined: Fri Oct 28, 2005 5:33 pm
Location: France

Re: Setup functions by setq

Post 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))))
BertrandnewLISP v.10.7.6 64-bit on Linux (Linux Mint 20.1)

Locked