Re: syntax-case as a pattern matcher
Marc Nieper-WiÃkirchen 01 Jul 2020 08:49 UTC
Am Mi., 1. Juli 2020 um 01:36 Uhr schrieb Alex Shinn <xxxxxx@gmail.com>:
>
> On Wed, Jul 1, 2020 at 4:43 AM Shiro Kawai <xxxxxx@gmail.com> wrote:
>>
>> syntax-case can be used to match against a bare (unwrapped) expression, but pattern variables must be referenced within syntax expressions. So you have to do (syntax->datum (syntax ...)) to substitute match, correct? Using syntax-case for general pattern matching is doable, though it feels like re-adapting a tool created for another purpose.
>
>
> As a comparison, we could consider SRFI 115 regular expressions as a general pattern matching library worth referencing. In fact, it is designed for arbitrary strings which makes it more general. To use with Scheme datum you do need to encode with write/read, but this is analogous to encoding via datum->syntax/syntax->datum when matching with syntax-case.
There's some truth in the comparison so using syntax-case for things
not being source code looks like using the wrong tool. But for that,
it can be used outside macro transformers, which is what my initial
objection to the formulation in SRFI 200 was about.
But one can also consider the comparison with SRFI 115 lame.
`datum->syntax' can be implemented in O(1), and `syntax->datum' only
has to touch the non-constant parts of the template, so once packaged
into a nice syntax that abstracts away the conversion procedures, it
is actually quite efficient.
But we should rather make the concept of a syntax object parameterizable.
Marc