On Thu, Jan 21, 2021 at 10:56 AM Marc Nieper-Wißkirchen
<xxxxxx@nieper-wisskirchen.de> wrote:
> The difference is hygiene, which effectively renames the macro's "var". Binding "syn" in the macro never binds "var" as seen by the macro. So you do not have to worry about the macro, you just have to worry about the correct semantics of
>
> (match '(1 1) (((var var) (var var))) var))
>
> It should really match and evaluate to 1.
>
> Another test case is:
>
> (match '(2 1) (((var and) (and 1 x)) (list and x))
>
> This should, in my opinion, evaluate to (2 1).
>
Well, that matches '(2 (2 1 3)), which is like '(1 (1 1)): not what
was intended. I'm new at this whole macro business, so I don't really
know what would be involved in making this library late binding- it
sounds like a complete re-implementation. The way var is set up right
now is there is this block in match-one:
((match-one v (var x) g+s (sk ...) fk (id ...))
(match-check-identifier
x
(let-syntax
((new-sym?
(syntax-rules (id ...)
((new-sym? x sk2 fk2) sk2)
((new-sym? y sk2 fk2) fk2))))
(new-sym? random-sym-to-match
(let ((x v)) (sk ... (id ... x)))
(if (equal? v x) (sk ... (id ...)) fk)))
(if (equal? v x) (sk ... (id ...)) fk)))
and this block in match-extract-vars:
((match-extract-vars (var p) (k ...) (i ...) v)
(let-syntax
((new-sym?
(syntax-rules (i ...)
((new-sym? p sk fk) sk)
((new-sym? any sk fk) fk))))
(new-sym? random-sym-to-match
(k ... ((p p-ls) . v))
(k ... v))))
and maybe there is some obvious mistake I made in these macros.