[racket] Again on bindings visibility in eval

From: Eli Barzilay (eli at barzilay.org)
Date: Thu Jul 14 15:33:52 EDT 2011

15 minutes ago, Markku Rontu wrote:
> On Thu, Jul 14, 2011 at 9:58 PM, Eli Barzilay <eli at barzilay.org> wrote:
> >  (define-syntax (rapp stx)
> >    (syntax-case stx ()
> >      [(rapp f x ...) #`(f #,@(reverse (syntax->list #'(x ...))))]))
> > [...]
> > 
> I would not call this piece of code much more obvious, it has too much line
> noise for my comfort :-)

Compare it with a symbolic version:

  (define (rapp l)
    `(,(cadr l) ,@(reverse (cddr l))))

it's not that far -- the extra noise is in converting between syntaxes
and lists.  Had reversals been more common, we could add a simple
`reverse-list' function.


> > As an antidote to such illusions of black magic, here's another
> > version that doesn't even use `syntax-case':
> >
> >  (define-syntax (rapp stx)
> >    (let ([l (cdr (syntax->list stx))])
> >      (datum->syntax stx (cons (car l) (reverse (cdr l))))))
> >
> Thanks anyway for these, they are more of what I was talking about.
> I do use "the full power of Racket" when writing my macros. Like
> introducing new names through string manipulation and
> syntax->datum and datum->syntax. Still that part usually looks ugly
> and un-Rackety to me. Have to ponder more why it feels so.

(Here's a guess: you see that `datum->syntax' and get a reflex
reaction of "bad, unhygienic code"...)


> > That is a social problem:
> > - There are many people who still think that macros are a bad idea
> >   in general, and advocate that idea.
> > - From the peole who manage to get passed that propaganda line,
> >   there are people who think that there's nothing wrong with plain
> >   CPP-style textual macros, and advocate that idea.
> > - From the peole who manage to get passed that propaganda line,
> >   there are people who think that symbolic macros are superior,
> >   and advocate that idea.
> > - From the peole who manage to get passed that propaganda line,
> >   there are people who think that `syntax-rules' are better since
> >   they don't get phases, and advocate that idea.
> >
> Who else to praise the awesomeness of Racket macros and syntax-case
> and phase levels if not the Racket people? If you get them young
> then they might not need to pass all those filters :-)

I'm not objecting to that, of course -- I try my best...  (The filters
are there though -- they're very real.)

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


Posted on the users mailing list.