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

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Tue Oct 12 11:26:24 EDT 2010

At Tue, 12 Oct 2010 11:16:35 -0400, Eli Barzilay wrote:
> 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? 

Rarely. Very few syntactic forms expand to applications that are
intended to use the `#%app' of the use site.

> 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? 

Because wanting `#%app' from the use site is very rare, while wanting
implicit-begin from the use site looks very common.

> (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.)

In the case of `#%app', you choose the original context attaching it to
the relevant parentheses. Another problem for `#%body' is that there
are no such parentheses to attach to.

> > 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?

Yes, that's my question.

> 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.)

How did you get the call-site `let'?



Posted on the dev mailing list.