Re:On eval in dynamic languages generally and in Racket spec...
by samth on Friday May 30, 2025 @10:05AM
(#44136357)
No, macros and eval are quite different. You can see this for example in Python or JavaScript, which have eval but not macros.
[ Parent
| on HN ]
Re:On eval in dynamic languages generally and in Racket spec...
by Y_Y on Friday May 30, 2025 @10:11AM
(#44136412)
You can make macros in Python: https://github.com/lihaoyi/macropy (note that that project was started for a class taught by Sussman)
There's also a PEP to make them first-class: https://peps.python.org/pep-0638/
Re:On eval in dynamic languages generally and in Racket spec...
by sparkie on Friday May 30, 2025 @10:35AM
(#44136639)
That's a different meaning of first-class from Strachey's definition of a first-class citizen[1] - ie, one that can be passed as an argument, returned from a function, or assigned to a variable.
Syntactic macros are still second-class, like Lisp macros, but an improvement over text-replacement style macros.
For something macro-like which is first-class, there are fexprs[2] and operatives (from Kernel[3]) - these receive their operands verbatim, like macros, so they don't require quotation if we want to suppress evaluation. fexprs/Operatives can be passed around like any other value at runtime.
[1]:https://en.wikipedia.org/wiki/First-class_citizen
Re:On eval in dynamic languages generally and in Racket spec...
by Y_Y on Friday May 30, 2025 @11:45AM
(#44137376)
Stratchey defined "first-class objects". This was by analogy with "first-class citizens" in a legal/political sense, since they are treated just as well as any other object and have no additional limitations. If we extend the analogy to syntax then I think it's clear enough that it means that it is a piece of syntax which is treated the same as any other and does not require special treatment or impose additional restrictions.
Thank you for the clarification and the additional information, I think having macros as first-class objects is a cool (but separate) idea.
Re:On eval in dynamic languages generally and in Racket spec...
by matheusmoreira on Friday May 30, 2025 @05:09PM
(#44139907)
They aren't that different. Fexprs are essentially additional eval cases.