Arc Forumnew | comments | leaders | submitlogin
Some thoughts on how to cope without namespaces and macro hygiene
2 points by are 5932 days ago | 6 comments
PG seems to be opposed to building macro hygiene and namespaces into the language. If we assume there are good reasons for this (although I'm not too sure in the case of macro hygiene; see other comments defending the power of hygienic macros), would there be good ways of coping with the possible problems you get by not "restricting" the language with namespaces and macro hygiene?

My thinking is that there are some commonalities between:

1) unintended symbol clashes when bringing in code from "elsewhere" into the single namespace

2) unintended symbol shadowing when expanding unhygienic macros

In both these cases, the potential problem arises when assigning a value to a symbol (with =).

What about giving the programmer increased control over symbol tables (they could be exposed as hashtables) at both read-time, macroexpansion-time, compile-time and even runtime, in order to have options for fine-grained control of symbol assignment?

Examples:

- When importing an Arc source file into the Arc image, you should have both the symbol table for the image (before importing) and the symbol table created by compiling the code to be imported available _before_ those symbol tables are merged, so you can use tools for comparing such tables for possible conflicts, and then merging them in a programmer-controlled way.

- Likewise, when the compiler expands a macro where you think there should be no symbol shadowing, the programmer should have access to the symbol table that would result from the macroexpansion, and the symbol table that exists before the macro-expansion is done.

(A common symbol table manipulation library could also be useful for increased control over the lexical scope of expressions or even continuations.)



6 points by pg 5932 days ago | link

I'll eventually add modules of some sort. Hygienic macros are less likely.

-----

3 points by viergroupie 5931 days ago | link

I don't totally understand your aversion to hygiene. You've probably explained it a few times already, can you post a link?

-----

5 points by pg 5931 days ago | link

What defmacro does is so simple and elegant. A macro is just a function than returns an expression. I wouldn't want to discard that simplicity in return for a solution to something I know from many years' experience is a non-problem.

-----

4 points by kennytilton 5930 days ago | link

Perhaps the pro-hygiene crowd needs to step up and tell us unhygienic types how long they have programmed with unhygienic macros and how often they have run afoul of variable capture. I am reminded of static/dynamic debates in which the pro-static crowd wants it to be taken as a given that it is better to have type errors detected at compile time. There is a prima facie compellingness to such assertions that may not pan out in practice, and at bottom the pro-safety crowd might just be imposing their (sorry) timidity on those of us who prefer to climb unroped in return for getting up the peak faster, which itself does more for safety when the climber is capable. uhoh, here comes my Reinhold Messner analogy....

-----

1 point by andreuri2000 5928 days ago | link

I regard it more as a lexical binding/dynamic binding debate. DEFMACRO or MAC are like dynamic binding, because the meaning of a macro can be affected by local variable bindings surrounding its site of use, contrary to the intended meaning of the macro writer at the definition site.

-----

1 point by Xichekolas 5931 days ago | link

Well frankly toothpaste tastes bad and soap chafes his skin. PG likes to keep in natural... an earthy scent if you will.

... oh, you meant hygiene as in hygienic macros... uh...

-----