Arc Forumnew | comments | leaders | submitlogin
Implicit gensyms (letoverlambda.com)
2 points by akkartik 4819 days ago | 9 comments


2 points by akkartik 4817 days ago | link

(Warning, uses syntax from OP)

Ah, I just ran into a limitation of defmacro! -- it can't 'see inside' when the macro is computed by a function. For example:

  (defun foodef(x)
    `(let ((,g!x ,x))
       (+ 1 ,g!x)))

  (defmacro! foomac(x)
    (foodef x))
The solution I came up with is to create a defun! to generate such functions, and then have def and mac generate defun! and defmacro! https://github.com/akkartik/wart/commit/f4e4859ea77ff02691c3... (Warning: uses different syntax than OP)

I like this idea more and more; I've basically gotten rid of w/uniq entirely in wart.

-----

4 points by rocketnia 4817 days ago | link

Have you considered just making 'g an anaphoric variable of 'mac that holds a memoized function that generates gensyms, so that g!x is (g 'x) as usual? ^_^

Then you can explicitly pass 'g to 'foodef. If that isn't enough, 'g could instead be a global function whose behavior changes during the dynamic scope of each macro expansion. Hmm, then you can't have more than one 'g at once, but when would you have that anyway? XD Something like Lathe's namespaces might use multiple instances of 'g, but those occasional cases can fend for themselves.

-----

1 point by akkartik 4817 days ago | link

Ooh, interesting idea.

-----

2 points by akkartik 4819 days ago | link

Other things from the book that seem worth stealing for arc: heredocs (http://letoverlambda.com/index.cl/guest/chap4.html#sec_3, http://en.wikipedia.org/wiki/Here_document), perl-like regexp syntax (http://letoverlambda.com/index.cl/guest/chap4.html#sec_4).

-----

1 point by evanrmurphy 4819 days ago | link

> Common Lisp's wise design decision to separate the variable namespace from the function namespace eliminates an entire dimension of unwanted variable capture problems. [...] when programming sophisticated macros it can be hard enough to keep track of symbols in a single, isolated namespace. Having any cross-pollination of names to consider just makes macro writing more difficult than it needs to be.

I still haven't run into any problems re: Arc being a lisp-1 with unhygienic macros. Has anybody else?

-----

2 points by rocketnia 4819 days ago | link

I have here and there, but renaming something is easy enough in a small codebase.

Still, when I'm writing code I don't know how I'll use in practice, I try to plug up abstraction leaks whenever I can, in the "why write programs with small bugs when you can write programs with no bugs" spirit.

I've been discovering that my purer utilities are useful in unexpected places, where what once was future-proofing is now essential to their newfound role. I don't think this is a particular advantage of hygienic/minimalistic stuff over more off-the-cuff or bundle-of-features systems, but I do enjoy being able to justify the "shape" of a utility completely in terms of its original motive.

...Whoops, you weren't asking about hygiene in general. XD Pretend I'm starting this post from scratch! * whoosh, changes costume*

I'm not sure what being a lisp-1 has to do with it, really. well, actually...

I suppose it's a little less likely for someone to need a local function than a local anything-else, but when they do need that, the local functions can still be captured by conventional gensym-savvy macros, right? So a lisp-2 can develop a culture of "don't use macros inside an 'flet unless you know what they expand to," whereas a lisp-1's corresponding "don't use macros except at global scope unless you know what they expand to" isn't quite as tractable.

When it comes to this kind of variable capture, I haven't encountered the problem or bothered writing code in a way that avoids it, even though I put up some possible techniques in a recent Semi-Arc thread. (This is exactly the issue Semi-Arc's hygiene should eliminate.) At this point, I almost consider my code to be better future-proofed if it's Penknife code that uses hygiene, and I'm just crossing my fingers that the Arc code will never capture in practice.

-----

1 point by akkartik 4819 days ago | link

Not me. Though I see 'rationally' that a single namespace adds more pressure on names, and I see that rocketnia is concerned about accidental lexical capture with his patterns like do.foo.

Perhaps dozens of programmers contributing code simultaneously makes collisions more likely. I doubt any of us have that sort of experience with lisp.

-----

2 points by akkartik 4819 days ago | link

Really cool idea, but:

Warning, lots of editorializing that may turn off scheme programmers.

I choose to find it hilarious :)

-----

2 points by evanrmurphy 4819 days ago | link

Really cool and hilarious indeed. :)

-----