guicho271828 / trivia

Pattern Matcher Compatible with Optima
Other
332 stars 22 forks source link

Guard pattern doesn't bind variables on successful match #23

Closed PuercoPop closed 8 years ago

PuercoPop commented 8 years ago

Hi, when evaluating

(trivia:ematch '(shader foo :fragment "")
  ((trivia:guard (list shader name type value)
                 (string-equal (symbol-name shader) "shader"))
   (list name type value)))

I get

The variable SHADER is unbound.
   [Condition of type UNBOUND-VARIABLE]

In optima it works

(optima:ematch '(shader foo :fragment "")
  ((optima:guard (list shader name type value)
                 (string-equal (symbol-name shader) "shader"))
   (list name type value)))

Am I miss using the guard subpattern?

guicho271828 commented 8 years ago

no, your example seems correct, its trivia's bug. thanks for reporting!

guicho271828 commented 8 years ago

the quick fix for this is using

(trivia:ematch '(shader foo :fragment "")
  ((list (symbol (name (trivia:guard shader (string-equal shader "shader")))) name type value)
   (list name type value)))
(FOO :FRAGMENT "")

there seems to be a problem in lifting the guard pattern.

PuercoPop commented 8 years ago

Thanks for the prompt fix