(missing)
Re: feature/underscorep branch with provisional changes to handle _ Marc Nieper-Wißkirchen (24 Aug 2020 11:08 UTC)
Re: feature/underscorep branch with provisional changes to handle _ Marc Nieper-Wißkirchen (24 Aug 2020 13:37 UTC)
Re: feature/underscorep branch with provisional changes to handle _ Marc Nieper-Wißkirchen (24 Aug 2020 15:57 UTC)
Re: feature/underscorep branch with provisional changes to handle _ Marc Nieper-Wißkirchen (22 Aug 2020 19:14 UTC)

Re: feature/underscorep branch with provisional changes to handle _ Marc Nieper-Wißkirchen 24 Aug 2020 13:37 UTC

Thank you for the MWE.

The problem is that the transformer environment (the lexical
environment in which the transformer procedure is expanded) is, in
general, different from the runtime environment. In "minimal.scm",
"underscore?" does not belong to the transformer environment (in R6RS
language: its binding lives in another phase).

There are two solutions: You can use "eval-when", which is not
standardized, though, or you put "underscore?" in its own library. In
the latter case, the R6RS expander will visit that library in the
correct phase because it notices that "underscore?" is referenced
inside aa macro transformer.

(If, in that case, "underscore?" is also referenced by runtime code,
the library will be made available in two phases.)

Marc

PS I will try to explain all this in detail in my upcoming document on
Scheme macro systems, especially er-macro-transformer and syntax-case.
Note that these phasing issues are related to procedural macros (and
the module system), but are the same whether one uses
er/ir/sc-macro-transformers or syntax-case.

Am Mo., 24. Aug. 2020 um 14:52 Uhr schrieb Felix Thibault
<xxxxxx@gmail.com>:
>
>
> On Mon, Aug 24, 2020 at 7:08 AM Marc Nieper-Wißkirchen <xxxxxx@nieper-wisskirchen.de> wrote:
>>
>> Could you provide me with a minimal working example that exhibits the problem?
>
>
> This file will load into the Loko repl (via include):
>
> ------minimal.scm-----------
> (define (underscore? x )
>   (and (identifier? x) (free-identifier=? x #'_)))
>
> (define-syntax match-underscore
>   (lambda (stx)
>     (syntax-case stx ()
>        ((match-underscore p sk fk)
>         (underscore? #'p)
>         #'sk)
>        ((match-underscore p sk fk)
>         #'fk))))
>
> and works as expected. But this module won't:
>
> -------minimal.sls-----------------------
> (library (feature minimal)
>          (export match-underscore)
>          (import (loko))
>          (begin
>             (include "minimal.scm")))
>
> it gives the same "identifier out of context" error the match module does.
>
>>
>> PS: In principle, you don't need two versions of underscore? because the underscore can also be reliably detected with syntax-rules alone and no literal identifiers.
>>
>> The trick is a bit like detection whether some input is a symbol of not.
>>
>> Felix Thibault <xxxxxx@gmail.com> schrieb am Mo., 24. Aug. 2020, 01:38:
>>>
>>> Chez and Loko both will load if I do
>>>
>>> >(import (srfi :0))
>>> >(include "srfi-204-r6rs-2.scm")
>>> >(match '(1 2 2 2) ((a b ..1) b))
>>> (2 2 2)
>>>
>>> but both give some kind of identifier error for underscore? ("identifier out of context" for Loko and "identifier out of phase" for Chez) when I try to include that file in a library.
>>>
>>>