this post was submitted on 12 Feb 2025
2 points (100.0% liked)

Emacs

2361 readers
15 users here now

Our infinitely powerful editor.

founded 5 years ago
MODERATORS
 

cross-posted from: https://lemmy.ca/post/38996724

Hello,

the most powerful thing in elisp is program as data but what does it mean how can I run data as a program. I was confused too but here is what I found.

First I tried this:

(setq x '(+ 1 3))
(x)

basically setting the value of x as a list. now x is set to some code but when I try to run x as function using (x) syntax we get this error *** Eval error *** Symbol’s function definition is void: x. It tried to look for function in x but couldn't find it. then how can I run the code that I stored in a variable? how to evaluate it? we need a built-in function eval.

If we run this code it works and outputs 4:

(setq x '(+ 1 3))
(eval x)

so yeah, it is how you can evaluate a code stored in a variable. feel free to correct me if there is another way to achieve it :)

you are viewing a single comment's thread
view the rest of the comments
[–] kionite231@lemmy.ca 1 points 1 week ago

Thank you so much for providing these links, I will read it all.