4 ms·
As an attempt at an answer: Unhygienic macros offer you more "power". With care, or another macro, you can express exactly the things you want with hygienic mac
by Jtsummers 6y ago
As an attempt at an answer: Unhygienic macros offer you more "power". With care, or another macro, you can express exactly the things you want with hygienic macros in a system like CL which lacks them, but the reverse isn't true. I cannot think of anything off the top of my head which would be particularly useful with unhygienic macros, but there probably is a use-case. My best guess (and just a guess) might be the SERIES and SCREAMER packages which redefine defun, but I could see it going both ways. A hygienic macro within the SERIES package would know the local definition and use it, but one from without would use cl:defun.
With either hygienic or unhygienic macros this can create problems as in either case you may think you're using a particular defun when you're really using the other.
NB: My CL macros are written carefully so they'd be roughly equivalent to the hygienic macros of Scheme, but with more boilerplate. At least when it comes to most variables, but I don't take care to ensure the functions used in my macros are not replaced in the local context where they're used.
- bjoli 6y agoI don't believe anything that can be written with unhygienic macros can't be written in a hygienic macro system. Macros written using implicit renaming is written just like CL macros, and with enough libraries you can do something similar with syntax-case. Heck, implementing an unhygienic defmacro over a regular lambda is something like 7 lines of syntax-case. In guile you could even use lambda* to get optional and keyword arguments.
- Jtsummers 6y agoSo, again, I don't think I know for certain why I'd want to do this, but here's an example of different behavior with the two: (defmacro my-not (x) `(not ,x)) (flet ((not (x) x)) (my-not 't)) In a hygienic macro system, that local definition of not will have zero impact on the execution. In an unhygienic macro system, that local definition is used instead of what the macro writer probably intended. That's a stupid, trivial example that would hopefully never be written. My best guess for wanting something like this, per my previous comment, would be a system like SCREAMER or SERIES which could make use of this local redefinition to produce a different-than-standard behavior. How would you write a hygienic macro which would make use of the local redefinition of not without also having to pass the redefinition to the macro?
- fiddlerwoaroof 6y agoThis is right, but shadowing symbols in the CL namespace like this is usually not allowed: the compiler is free to optimize a lot of these things by inlining definitions and such, so this may not do what you think (unless you shadow CL:NOT)
- junke 6y ago"Usually not allowed": rather the behavior is undefined, it is not a conforming program. (and in practice the error is "Lock on package COMMON-LISP violated when binding NOT as a local function", you can lock your own packages too if you want). Also, you generally mind your own symbols, you don't rebind symbols from other packages (hygienic macros are more useful when you only have one namespace).
- bjoli 6y agoI would use syntax case and introduce unhygienic bindings. That is the deal with all low-level hygienic macro systems: hygiene by default. Break hygiene explicitly. In syntax-case that would be (datum->syntax syntax-object-where-i-want-to-introduce-binding 'not)
- deleted 6y ago[deleted]