The Artima Developer Community
Sponsored Link

Heron-Centric: Ruminations of a Language Designer
Hygenic versus Unhygenic macros in Heron
by Christopher Diggins
March 21, 2005
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 assert : 
  {
    if (#e) { 
      throw assertion_error($fxn_name);
    }     
  };
The 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:

  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 assert : 
  {
    if ($e) {
      throw assertion_error($_context::fxn_name);
    }     
  };
Your comments and suggestions would be greatly appreciated!

Talk Back!

Have an opinion? Be the first to post a comment about this weblog entry.

RSS Feed

If you'd like to be notified whenever Christopher Diggins adds a new entry to his weblog, subscribe to his RSS feed.

About the Blogger

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.

This weblog entry is Copyright © 2005 Christopher Diggins. All rights reserved.

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use