unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Stefan Israelsson Tampe <stefan.itampe@gmail.com>
To: "Ludovic Courtès" <ludo@gnu.org>
Cc: guile-devel@gnu.org
Subject: Re: Enhancement to the syntax system?
Date: Tue, 10 Jul 2012 09:36:19 +0200	[thread overview]
Message-ID: <CAGua6m1kvgRrwesrheapy5DadHqsHPmPop4v634rPkGaHjooXQ@mail.gmail.com> (raw)
In-Reply-To: <87pq85dj8o.fsf@gnu.org>


[-- Attachment #1.1: Type: text/plain, Size: 2725 bytes --]

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++))
scheme@(guile-user)>
(define (f x)
  #`(let ((x 1)) #,x))

scheme@(guile-user)>
(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
/Stefan

On Mon, Jul 9, 2012 at 5:52 PM, Ludovic Courtès <ludo@gnu.org> wrote:

> Hi!
>
> Stefan Israelsson Tampe <stefan.itampe@gmail.com> 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))))))
>
>   (foo)
>   => 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?
>
> Thanks,
> Ludo’.
>
>
>

[-- Attachment #1.2: Type: text/html, Size: 3457 bytes --]

[-- Attachment #2: unquote++.scm --]
[-- Type: application/octet-stream, Size: 1237 bytes --]

(define-module (syntax unquote++)
  #:export (quasisyntax++ insyntax))

(define *s* (make-fluid '()))

(define (parse stx x)
  (syntax-case x (unsyntax insyntax unsyntax-splicing)
    ((unsyntax          . _) x)
    ((unsyntax-splicing . _) x)
    ((insyntax ((p ...) c ...))
     (with-syntax ((g (datum->syntax stx (gensym "g"))))
       (fluid-set! *s* (cons #'(g (lambda (x) 
                                    (syntax-case x () 
                                      ((_ p ...) (begin c ...)))))
                             (fluid-ref *s*)))
       #'(g p ...)))
    ((x . l)
     (cons (parse stx #'x) (parse stx #'l)))
    (x #'x)))

(define-syntax quasisyntax++
  (lambda (x)
    (syntax-case x ()
      ((_ y)
       (begin
         (fluid-set! *s* '())
         (with-syntax ((statement (parse x #'y))
                       (lets      (fluid-ref *s*)))
           #'(quasisyntax (let-syntax lets statement))))))))
               
(define (rg ch stream)
  (let ((x (read-char stream)))
    (cond
     ((eqv? x #\`)
      `(quasisyntax++ ,(read stream)))
     (#t
      (error "Wrong format of # reader extension")))))

(define (rg. ch stream) `(insyntax ,(read stream)))

(read-hash-extend #\# rg)
(read-hash-extend #\. rg.)

      parent reply	other threads:[~2012-07-10  7:36 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-30 15:22 Enhancement to the syntax system? Stefan Israelsson Tampe
2012-07-02 19:28 ` Ludovic Courtès
2012-07-02 20:43   ` Stefan Israelsson Tampe
2012-07-02 22:41     ` Ludovic Courtès
2012-07-03 14:37       ` Stefan Israelsson Tampe
2012-07-03 21:33         ` Ludovic Courtès
2012-07-03 21:52           ` Stefan Israelsson Tampe
2012-07-04  7:47             ` Marijn
2012-07-04  8:04               ` Stefan Israelsson Tampe
2012-07-09 15:52             ` Ludovic Courtès
2012-07-09 17:40               ` Stefan Israelsson Tampe
2012-07-10  8:24                 ` Ludovic Courtès
2012-07-10 13:35                   ` Stefan Israelsson Tampe
2012-07-10 14:34                     ` Marijn
2012-07-10 14:51                       ` [racket-dev] " Eli Barzilay
     [not found]                         ` <20476.16781.257276.194149-a5nvgYPMCZcx/1z6v04GWfZ8FUJU4vz8@public.gmane.org>
2012-07-10 15:03                           ` Matthew Flatt
2012-07-10 15:26                             ` [racket-dev] " Ludovic Courtès
2012-07-10 15:44                               ` Stefan Israelsson Tampe
2012-07-10 17:47                                 ` Stefan Israelsson Tampe
2012-07-10 16:48                             ` Eli Barzilay
2014-05-03 21:29                             ` Marijn Schouten (hkBst)
2012-07-10 15:44                           ` Ryan Culpepper
2012-07-10 15:22                     ` Ludovic Courtès
2012-07-10  7:36               ` Stefan Israelsson Tampe [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAGua6m1kvgRrwesrheapy5DadHqsHPmPop4v634rPkGaHjooXQ@mail.gmail.com \
    --to=stefan.itampe@gmail.com \
    --cc=guile-devel@gnu.org \
    --cc=ludo@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).