[racket-dev] `cond' / `when' / `unless' / etc bodies

From: Eli Barzilay (eli at barzilay.org)
Date: Tue Oct 12 11:16:35 EDT 2010

Three minutes ago, Matthew Flatt wrote:
> At Tue, 12 Oct 2010 10:43:03 -0400, Eli Barzilay wrote:
> > An hour ago, Matthew Flatt wrote:
> > > At Mon, 11 Oct 2010 20:38:58 -0400, Eli Barzilay wrote:
> > > > > At Mon, 11 Oct 2010 19:15:09 -0400, Eli Barzilay wrote:
> > > > > > I'd love to see an implicit `#%begin', which could have the
> > > > > > above apply in more places automatically.  (It was one of the
> > > > > > feature requests I asked for in the summer meeting.)
> > > > > 
> > > > > Recall that no one solved the technical problem with where to
> > > > > pull the lexical context for the implicit `#%begin' or `#%body':
> > > > > 
> > > > >   http://lists.racket-lang.org/dev/archive/2010-July/003624.html
> > > > 
> > > > I remember being confused with how that problem would look like,
> > > > but I don't think that I've seen an example where this would be
> > > > problematic.  (I think that we talked about it, but I can't
> > > > remember any concrete details...)
> > > 
> > > Can you say more about how the `squawk' example in the referenced
> > > post doesn't illustrate the problem?
> > 
> > It doesn't specify any clear problem -- either that or I'm missing
> > something obvious...  AFAICT, the problem that is described there is
> > similar to:
> > 
> >  (define-syntax-rule (squawk body ...)
> >    (begin
> >      (printf "squick ~a!" "squawk")
> >      (let () body ...)))
> > 
> > having the implicit `#%app' come from this macro's module rather than
> > the use site, for example, if it's defined in a module that has
> > implicitlty curried applications then the `printf' call becomes
> > curried.
> 
> Isn't the point of a configurable "implicit begin" that `squawk' can
> inherit the implicit-begin behavior of the use site instead of the
> definition site? That is, the intent of the example is that the
> `squawk' syntactic form has a body, and "body" means whatever it's
> configured to mean at the use site.

But the same thing happens with `#%app' right?  And the macro writer
gets to choose whether to use its own implicit application or the one
from the macro use -- so why is this case worse than that?  (That kind
of choice looks like it must be there, since whatever it looks like,
you (the macro author) can choose one of the two.)


> Other macros, meanwhile, may expand to uses of `let' where the body
> of the `let' is meant to be used as in the context of the definition
> site (probably because the body of that `let' is not supplied as an
> argument to the macro).
> 
> So, how does a macro implementor make the distinction between those
> kinds of `let's?

It still sounds like I'm missing something.  If I write that `squawk'
macro and if there's some way to make the implicit `#%begin' come from
the macro call site, then what would I do if I don't want that?

And if the goal is to make it easier to use the call site's implicit
begin, then how about this: `let's expansion plants a `#%begin' with
the same context as itself, so the `squawk' author can use the
call-site `let' or use its own binding to get something else.  How
does that break?  (I'm asking this mostly in an attempt to figure out
the problem.)

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!


Posted on the dev mailing list.