frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Ask HN: Anyone making a living from a paid API?

184•meander_water•21h ago•140 comments

Ask HN: What is the best LLM for consumer grade hardware?

229•VladVladikoff•2d ago•175 comments

Ask HN: What's the best AI for meme creation?

2•faangguyindia•8h ago•2 comments

Ask HN: Why reinvent front-end frameworks and static site builders?

3•keepamovin•9h ago•2 comments

Ask HN: What are you working on? (May 2025)

346•david927•6d ago•1068 comments

Ask HN: GEtting a Remote Job in the US

6•gsablewskinunes•17h ago•10 comments

Ask HN: How do I learn practical electronic repair?

11•juanse•1d ago•11 comments

What motivates you to contribute to open source projects?

17•rizs12•1d ago•13 comments

Ask HN: Hardware for 1k RPS?

5•gsky•1d ago•3 comments

Volume label field can't be longer than "VolumeLabel" when formatting in Windows

4•eisolo•1d ago•3 comments

Ask HN: How do you improve code for future AI?

2•tmaly•22h ago•4 comments

How to improve interview skill?

6•gogo61•1d ago•9 comments

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

9•behnamoh•1d ago•10 comments

Tell HN: Namecheap pre-purchasing searched domain names?

19•iamtoomas•2d ago•27 comments

Ask HN: Anyone struggling to get value out of coding LLMs?

339•bjackman•6d ago•275 comments

Ask HN: How do you set up a new dev machine? (2025 edition)

10•daryllxd•2d ago•7 comments

Ask HN: Why doesn't Google offer POS credit card reader like Square?

2•Openai2•1d ago•5 comments

Ask HN: How are people using ChatGPT to increase productivity in personal life?

13•shreythecray•2d ago•12 comments

Tell HN: eBay doesn't allow changing country

7•peterburkimsher•1d ago•5 comments

Ask HN: Career Plateau: Looking for Advice on How to Break Through

6•vaderyondu•2d ago•9 comments

Tasks Per Day – A minimalist productivity app that works

6•TerrenceTian•2d ago•4 comments

Ask HN: New Economics of Software Development Lifecycle

4•breckenedge•1d ago•10 comments

Ask HN: Management wants to talk to my Datalake. What's the best way to do this?

4•GaiusCoffee•2d ago•1 comments

Can we take a moment to appreciate what kind of web experience we are building?

11•tomdesantis•2d ago•7 comments

Ask HN: How do you stay motivated when hunting for a job?

7•tombert•1d ago•24 comments

Ask HN: Why that many more US-based companies are hiring "US-only" remote?

18•soneca•4d ago•19 comments

Ask HN: What tools do you use to discover competitors?

4•flippyhead•1d ago•9 comments

Self-Hosted Cloudflare Alternatives

2•andyong71•1d ago•4 comments

Ask HN: Building LLM apps? How are you handling user context?

30•marcospassos•5d ago•18 comments

Best Buy is selling a $400 "digital Ethernet" cable for "cleaner, clearer sound"

16•34679•3d ago•15 comments
Open in hackernews

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

9•behnamoh•1d ago
Is my understanding correct that Lisp's powerful macro system stems from the ability to write the eval function in Lisp itself? From what I gather, Lisp starts with a small set of primitives and special forms—seven in the original Lisp, including lambda. I recall Paul Graham demonstrating in one of his essays that you can build an eval function using just these primitives. Those primitives are typically implemented in a host language like C, but once you have an eval function in Lisp, you can extend it with new rules. The underlying C interpreter only sees the primitives, but as a programmer, you can introduce new syntax rules via eval. This seems like a way to understand macros, where you effectively add new language rules. I know Lisp macros are typically defined using specific keywords like defmacro, but is the core idea similar—extending the language by building on the eval function with new rules?

Comments

andsoitis•1d ago
eval and macros both deal with code-as-data (homoiconicity), but they serve very different purposes and work at different times in the program lifecycle:

eval

Runs at runtime.

Takes a data structure (usually a list) and evaluates it as Lisp code.

Example: (eval '(+ 1 2)) ; => 3

Use case: Dynamically construct and run code while the program is running.

Macros

Runs at compile time (or macro-expansion time).

Transform Lisp code before it's evaluated. They return new code (a Lisp form) to be compiled/evaluated later.

Example: (defmacro my-unless (condition body) `(if (not ,condition) ,body))

(my-unless (= 1 2) (print "Not equal")) ; expands to (if (not (= 1 2)) (print ...))

Use case: Extend the language by defining new syntactic constructs. Enables powerful DSLs and optimizations.

uticus•1d ago
https://gigamonkeys.com/book/macros-standard-control-constru...

https://www.lispworks.com/documentation/HyperSpec/Body/f_eva...

timonoko•1d ago
If you have to ask about macros, you REALLY dont need macros.

Macros are really only instructions for the compiler, how to compile things faster.

The syntax improvement aspect is minuscule, because Lisp has no actual syntax perse.

timonoko•1d ago
Hey Grok: Write commonlisp macro "test", which is usually an addition, but when two parameters are already numbers, it is the sum of those numbers.

  (defmacro test (a b)
    (if (and (numberp a) (numberp b))
        (+ a b)
        `(+ ,a ,b)))
kazinator•1d ago
These are very strange statements, coming from you. Please teach the kids properly! :)
timonoko•1d ago
Bad memories. Some malformed macro may evaluate differently than compile and the problem is impossible to find.
timonoko•1d ago
Hey Grok: Does commonlisp have some mechanism to prevent malformed macro to do things globally, so that eval works differently than compile?

  Grok: Yes.
  < 5 pages of semi-incomprehensible explanations omitted >
kazinator•20h ago
This is a feature. It is something you want sometimes and don't want at other times.

Macros can stage calculations to compile time. Compile time can happen in a completely different environment from run-time, such as on a different machine. It only happens once, whereas run-time can repeat many times.

A macro can be designed to that it opens a specific file, reads the content and generates some code based on that (or simply includes the file as a literal constant). That file exists only on the build machine, perhaps part of the source tree of the program. Thus, compiled code containing the macro call can run anyhere, but source code containing the macro cannot be evaled anywhere.

fsmv•1d ago
They are subtly different. Macros are the only way to process s-expressions without first calling eval on them. This is necessary because without macros you could only generate and eval quoted code. Also practically it's cumbersome to work with everything being quoted when writing lisp code generators.

Without macros you could implement eval still but your internal lisp implementation could only work on quoted s-expressions, there would be no way to get back to the base unquoted level of lisp code (assuming you can't use the primitive eval, since you're trying to implement lisp in lisp).

Another use case is implementing a shortcutting boolean and function. You can't do the shortcutting without macros because all of the arguments get eval'd before passing to your and function.

frou_dh•1d ago
Given an eval primitive function that's a black-box, using it does seem somewhat similar to the use of a macro, in that a kind of "double evaluation" occurs (First, eval's argument is evaluated. Then the result of that is evaluated).

When a macro is used for any given purpose, what happens is a bit more general because it first "does something with" its argument (rather than necessarily straight-up evaluating it). Then the result of that is evaluated.