3 ms·
The with-solved-problem macro shows how (in this case, I think termed "unhygienic") Lisp macros allow fancy stuff with the code-is-data approach. The first arg
by namibj 7y ago
The with-solved-problem macro shows how (in this case, I think termed "unhygienic") Lisp macros allow fancy stuff with the code-is-data approach.
The first argument seems to be a normal Lisp expression, with no special syntax, and the second argument has the solution variable and all the variables mentioned in the expression bound to (the solution object, the values of the variables in the solution it found).
This approach is obviously available for everything. You can just use fully-flexible S-Expressions as essentially function arguments, and the function can modify the variables / identifiers in scope during execution of it's arguments.
It makes me want to do more with Racket again...
- behnamoh 7y agoYou mention good points about why Lisp could be advantageous compared with other languages in this context. That actually was my question when I read the post. But mind you, aren't Racket's macros hygienic?
- namibj 7y agoThey are. But I didn't have the time to research what statement I could make about Racket allowing or not allowing such an interface, therefore I made no statement as to that.
- ddragon 7y agoHygienic Macros usually have ways to violate the hygiene, so that property doesn't change how expressive they can be, just that the default behavior is safer because you won't accidentally overwrite anything on the scope the macro was called from. And yes, racket's macros are hygienic.
- jxy 7y agoIf you are willing to give up S-Expressions, you might try Nim [0]. Its compile time macro system allows this fancy stuff easily, even with access to the type system. [0] https://nim-lang.org https://nim-lang.org
- kd0amg 7y agoThe first argument seems to be a normal Lisp expression, with no special syntax, and the second argument has the solution variable and all the variables mentioned in the expression bound to (the solution object, the values of the variables in the solution it found). That doesn't sound any more unhygienic than pattern matching.