Sign up to save tools and stay up to date with the latest in AI
bg
bg
1

Ask HN: Lisp eval vs. Lisp macros. Are they the same underlying concept?

May 30, 2025 - news.ycombinator.com
The article explains the differences between `eval` and macros in Lisp, highlighting their roles in handling code-as-data due to Lisp's homoiconicity. `Eval` is a function that operates at runtime, taking a data structure, typically a list, and evaluating it as Lisp code. This allows for the dynamic construction and execution of code while the program is running, exemplified by the expression `(eval '(+ 1 2))`, which evaluates to `3`.

On the other hand, macros operate at compile time or during macro-expansion time. They transform Lisp code before it is evaluated, returning new code to be compiled or evaluated later. This process allows for the extension of the language by defining new syntactic constructs, enabling the creation of powerful domain-specific languages (DSLs) and optimizations. An example provided is the macro `my-unless`, which expands into an `if` statement, demonstrating how macros can introduce new language features and syntactic sugar.

Key takeaways:

  • Eval runs at runtime, taking a data structure and evaluating it as Lisp code.
  • Macros run at compile time, transforming Lisp code before it's evaluated.
  • Eval is used to dynamically construct and run code while the program is running.
  • Macros are used to extend the language by defining new syntactic constructs, enabling powerful DSLs and optimizations.
View Full Article

Comments (0)

Be the first to comment!