Sponsored Link •
|
Summary
Hygenic macros can not access the local scope where they are expanded, while unhygenic macros (as found in C) can. I want the best of both worlds!
Advertisement
|
Unhygenic macros can access the local scope where they are expanded. This is a dangerous and often unwelcome thing because it can lead to very subtle bugs and name clashes. However, it makes it very easy to write clever AOP style code, I can use it to implement Programming with Contracts, and tons of other nifty things.
A lot of people gave me a kick in the pants for not having hygenic macros ala Common Lisp. So I thought how about both? A regular old hackish macro is defined in Heron as follows:define assertThe dollar signs convert meta-values to values accessible at run-time, and # expands code (and macros). Now the question is how should I syntactically differentiate a hygenic macro? Perhaps:: { if (#e) { throw assertion_error($fxn_name); } };
1) safe_define : /* boring hygenic macro */; 2) hygenic_define : /* boring hygenic macro */; 3) clean_define : /* boring hygenic macro */;Another option, which I kind of like, is a hybrid macro. This is a hygenic macro which has limited access to the local context (i.e. where it is expanded) through some kind of special context meta-variable (for instance _context). To illustrate what I mean, consider the pseudo-code:
define assertYour comments and suggestions would be greatly appreciated!: { if ($e) { throw assertion_error($_context::fxn_name); } };
Have an opinion? Be the first to post a comment about this weblog entry.
If you'd like to be notified whenever Christopher Diggins adds a new entry to his weblog, subscribe to his RSS feed.
Christopher Diggins is a software developer and freelance writer. Christopher loves programming, but is eternally frustrated by the shortcomings of modern programming languages. As would any reasonable person in his shoes, he decided to quit his day job to write his own ( www.heron-language.com ). Christopher is the co-author of the C++ Cookbook from O'Reilly. Christopher can be reached through his home page at www.cdiggins.com. |
Sponsored Links
|