|Subject:||Re: Feature request: Expose `ellipsis?' from psyntax.ss|
|Date:||Thu, 15 Nov 2018 20:41:09 +0100|
|User-agent:||Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1|
> Let's assume we are writing a macro that reimplements syntax (or some
I have been thinking of the scope in which $sc-ellipsis is bound by `with-syntax'. If `my-syntax' is within the scope of `with-ellipsis', the binding of $sc-ellipsis introduced by this `with-syntax' will be relevant; if `my-syntax' is not in the lexical scope of `with-ellipsis', the binding should be irrelevant; thus my thought that we need the lexical information of my-syntax as well.
Operationally, when (with-ellipsis e (my-syntax a e)) is expanded, 'e'
Aha, so maybe I have misunderstood the scope of `with-syntax'. Please consider the following example:
(syntax-case stx ()
((_ x e) (bar #'(x e)))))))
(define (bar x*)
(syntax-case x* ()
((x ...) ---))))
I would have thought that the `...' identifier in `bar' is recognized as an ellipsis, but from what you are saying it seems that the binding `with-syntax' is dynamic with respect to macro expansion (like syntax parameters). Is this really what we want? This way, as soon we use `with-ellipsis', we can never call third-party macro transformer helpers (like `bar') because they may rely on the fact that the ellipsis `...' still has its usual meaning. And circumventing the problem with (with-ellipsis e --- (with-ellipsis ... ---)) would also not work because the inner `...' is not `bound-identifier=?' to the the global ellipsis `...'.
Therefore I think, we want `with-ellipsis' to be lexically scoped (in the macro transformer code).
> Thanks for the explanation. I have been toying with my own
My environments are lists of ribs where each rib corresponds to a lexical frame. Given the form
(letrec-syntax ((var init)) body ...)
I create a new rib that contains the binding of var to init and add a wrap around each _expression_ in body ... that contains the new rib but no new marks. When the body is examined by the expander, the wraps are gradually pushed down (like in the original description of `syntax-case' by Dybvig and Hieb) so that eventually the environments stored with the identifiers in body gain another rib.
> Will ellipsis? also work outside of macros? Say, what would be the
Is this related to the question above of whether `with-syntax' has lexical or dynamic scope? In the former case I don't see a theoretical reason why it has to be restricted to the dynamic extent of a macro transformer call.
> P.S.: By the way, the module (system syntax) and in particular the
What I have been implementing is a pattern matcher and rewriter as a macro in Guile that works much like syntax-case/syntax. Let's call it my-syntax-case/my-syntax. When `my-syntax' is given a template, it has to check whether an identifier appearing in the template is a "my-"pattern variable or not. For that, `my-syntax-case' introduces (via `let-syntax') lexical bindings of the identifiers that are used as pattern variables. The associated syntax transformer just outputs an error (namely that the pattern variable is used outside of `my-syntax'). However, I also attach a custom property (with `make-object-property`) to this syntax transformer that holds information about the match and the nesting depth of the pattern variable. In order to retrieve this information in `my-syntax', I use `syntax-local-binding' to get hold of the associated syntax transformer.
In Chez Scheme, I would have used `define-property' to define my custom property directly on the identifier standing for the pattern variable. I haven't found an equivalent feature in Guile. I don't know how to nicely code my-syntax-case/my-syntax in standard R6RS.
|[Prev in Thread]||Current Thread||[Next in Thread]|