[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Enhancement to the syntax system?

From: Stefan Israelsson Tampe
Subject: Re: Enhancement to the syntax system?
Date: Tue, 10 Jul 2012 09:36:19 +0200

Ok, I coded a suggested syntax that is a quick solution but maybe not ideal because really this should be hanlded on the psyntax level. We probably cannot use the old syntax because it can break old code in other words one has to introduce new language elements. Also I asked on #scheme and tried to look into reference documentation for quasisyntax semantics. The answer I got on #scheme was that psyntax is buggy although I do not agree on that. I also felt that people is suspicious of my approach which is to write one macro and then dispatch to functions in stead of writing macro after macro. In all I don't think I am able to lift this idea to a larger community.

So I sat down and implemented a simple algorithm see attachement. with this I can write,

scheme@(guile-user)> (use-modules (syntax unquote++))
(define (f x)
  #`(let ((x 1)) #,x))

(define-syntax g
  (lambda (x)
    (syntax-case x ()
      ((_ y)
        ##`(let ((x y))
            #.((x) (f #'x)))))))

scheme@(guile-user)> (g 4)
$1 = 4

This will explicitly state what variables to transfer to the inserted _expression_. It's not ideal because I
feel that the good way to handle this is to implicitly, which demands hacking psyntax, do this and simplify the syntax even more. also I cannot see how to implement #.@ but to hack psyntax.

##` also allow #, and #,@ which has the old meaning.

Have fun

On Mon, Jul 9, 2012 at 5:52 PM, Ludovic Courtès <address@hidden> wrote:

Stefan Israelsson Tampe <address@hidden> skribis:

> You do not need gensyms if you try to mimic or implement my suggested #. .
> On the
> other hand when if you do this
> (define (f stx) #`(let ((x 1)) #,stx))
> and use this with
> #`(let ((x 2)) #,(f #'x))

OK, got it, thanks!

(In case others wonder, the complete example is:

  (define (f stx)
    #`(let ((x 1)) #,stx))
  (define-syntax foo
    (lambda (s)
      (syntax-case s ()
         #`(let ((x 2)) #,(f #'x))))))

  => 1

The situation can be diagnosed with:

  (define (f stx)
    #`(let ((x 1))
      #,(if (bound-identifier=? stx #'x) (error) stx)))

But it doesn’t help.

> (with-syntax ((x (datum->syntax stx (gensym "x")))) #`(let ((x 2)) #,(f
> #'x))))))

Often, you could use ‘generate-temporaries’, which is a bit nicer.

> Hope that this makes things clear!

It does, thanks!

It’s true that it’s annoying that the wrong binding is silently used.
Do you think it’s common enough to justify new syntax?


Attachment: unquote++.scm
Description: Binary data

reply via email to

[Prev in Thread] Current Thread [Next in Thread]