[Top][All Lists]

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

Re: syntax-local-value patch for discussion

From: Stefan Israelsson Tampe
Subject: Re: syntax-local-value patch for discussion
Date: Mon, 23 Jan 2012 17:06:09 +0100

Ok, here is a discussoin using code in syntax-parse.

Let's start with the defintion of a syntax-class, str in the macro package syntax-parse:
(define-syntax-class str #:attributes () #:opaque #:commit
  #:description "string"
  (pattern (~and x (~fail #:unless (string? (syntax-e #'x))))))

So the and patterns first match x and then on the same element match a ~fail
that fails if the supplied code (string? (syntax-e #'x)) is false.

The headake for me is that #'(string? (syntax-e #'x)) is stored in a struct and hence
does not get wrapped correctly e.g. after the packaging of this code in a struct, say S
we will then issue something like the following code in the expansion of the first match

#'(with-syntax ((x  stx))  (parse stx S))

and when parse is ready to unpack S we could have

S = #(syntax-object #<struct-s> wrap-part hygiene)

Now I basically solve this problem by constructing
a = (vector 'syntax-object (vector-ref (struct-s-code (syntax->datum S)) 1) (un-mark wrap-part) hygiene)
crossing the fingers that the "code" will be nonatomic and then the expander will use it like,

(with-syntax ((code a)) #'( .... code))

This is the story. I do not want to rest here because this solution is not resistant to bitrot and depends on internals that I do not want to touch. The solution would be to have an interface in guile that allows to write,

(with-syntax ((code (syntax-embedd (struct-s-code (syntax->datum S)) S))) (.... code ...))


(syntax-embedd exp env-stx) = embedds exp in the syntax env-stx

I'm much more fine with dropping env-stx and replace that with the equivalent syntax environment at the macro call

I Hope that things are less foggy now!


On Mon, Jan 23, 2012 at 11:53 AM, Andy Wingo <address@hidden> wrote:
Hi Stefan,

On Thu 19 Jan 2012 10:50, Stefan Israelsson Tampe <address@hidden> writes:

> Working on porting syntax-parse is a learning experience and I know
> understand how it uses syntax-local-value as a way to lookup a syntax
> object by joining the wraps together with the total wrap at the macro
> call.

syntax-local-binding just uses the wrap from the id that you give it,
without joining it to the macro expansion environment's wrap.

> I would like to have a syntax-join function that takes two syntax
> objects and join them correctly and robustly in the pressense of
> eventual marks or not.

Why would you want to do something like this?

You might try writing the documentation of the function first; it would
clarify the conversation.



reply via email to

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