The Artima Developer Community
Sponsored Link

Weblogs Forum
Hygenic versus Unhygenic macros in Heron

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Christopher Diggins

Posts: 1215
Nickname: cdiggins
Registered: Feb, 2004

Hygenic versus Unhygenic macros in Heron (View in Weblogs)
Posted: Mar 21, 2005 12:23 PM
Reply to this message Reply
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!

Topic: Packer Fans are not always football fans Previous Topic   Next Topic Topic: The Humane Interface

Sponsored Links



Google
  Web Artima.com   

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