Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It's like you didn't read the previous poster: They're claiming lisp macros can work BEFORE the compiler generates an AST.


Yes, it's the same in nim.

For instance, see this example which defines a compact definition syntax that is certainly not valid vanilla nim:

https://peterme.net/metaprogramming-and-read-and-maintainabi...

Refer to lines 63-88 of the large final example.


Ok this is nice but you this would be rougly the same in Lisp, apart from AST constructors ("newIdentNode()",...), which would simply be backquote/unquote. Plus you have to write enumInfo[0], enumInfo[1] instead of pattern matching.


And if I wanted to make 'for' into a valid variable name, or change the tokens for specifying numbers, for example, how would I go about doing that?


Easily. The macro gets handed the ast of the input. It can interpret it however it wants. There are no reserved words or anything like that. Much of nim is implemented as macros, just like most lisps


The lisp macros run before the AST exists.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: