<$BlogRSDUrl$>

Thursday, February 19, 2004

syntactic closures
looking through library.readscheme.org -- yum. just read through the paper, Syntactic Closures by Alan Bawden and Jonathan Rees. This was sort of what I was thinking when I mentioned macro expansions being somewhat like closures. The idea being that a syntactic closure is a paramaterized expression -- the parameters are resolved (read: evaluated) in the environment where the expression is used, and the others in the environment in which the expression was created. so, exactly like a regular closure except you don't call it explicitly with its parameters, you just use as usual. (which makes me think that syntactic closures are a more general type of closure).

so, are syntactic closures everything i'd need to do something like the hygenic macro thang? to be honest, my head is slightly spinning with all of this. i probably need to sit down and work through some examples using this method again. when i tried it before (last week sometime) I arranged things so that the expression returned by each macro transformer was a syntactic closure. this worked for one macro tranformation, but failed when i had nested macros (i.e. a macro composed of another macro). this happened because expressions in the inner macro were captured by its closure, even though they should have refered to something in the outer macro. that is, this happens when a macro's parameter was 'replicated' (well, this is what Petrofsky calls it) by the inner macro and then put in an expression which assigned it a different value:

(let ((x 1)) (let-syntax ((foo (syntax-rules () ((_ y) (let-syntax ((bar (syntax-rules () ((_) (let ((x 2)) y))))) (bar)))))) (foo x)))
i suspect i was doing something wacky...

anyhow, Bawden and Rees refer to hygenic macros as the "other complete solution", and give a nice short description of it (aside: so i take it guess it's proper to refer to /syntactic closures/ as a solution to the problem of writing well-behaved macros, not as a solution to writing /hygenic macros/).

blurp.

quasiquotation
just for fun i decided to implement simple quasiquotation, just backquote and comma. doing it showed me a little bit more about how wonky using two stacks can be. wonky in that i have to use both the RTN stack and the EXP stack to hold arguments to a function. The EXP stack holds unevaled arguments, the RTN evaled ones. I had to do this with the second and third operands for if, and then again with the template argument to quasiquote since the quasiquote needs the template to find out the bits that need to be evaled (i.e. the appropriately unquoted things), and then again to piece together the quoted expression.

scaling Mount Oregano
oh and by the way, i think i might be in love with scheme (at least for the moment). oregano and autumn still beat it out for the top positions, but scheme is gaining. it has just pushed its way passed pressing my hand across a carpet and corn bread.

0 Comments:

This page is powered by Blogger. Isn't yours?