guicho271828 / trivia

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

Corner case: (quote (a)) does not compile to (list 'a) #86

Closed guicho271828 closed 7 years ago

guicho271828 commented 7 years ago

It compiles to (list a) instead, and the eq-test against the symbol a is not performed.

guicho271828 commented 7 years ago

This was a surprise for me while using Trivia for building an algorithm. However,

  (is (eql 3 (match '(1 2 3) ('(1 _ a) a))))
  (is (eql 3 (match #(1 2 3) (#(1 _ a) a))))

this behavior has been present in Optima and I will preserve this behavior. I almost got bitten by my own product :)

Looking twice, this was indeed I was bitten by myself. Thinking about it...

guicho271828 commented 7 years ago

I would like to ask someone's opinion... @fare ? I summarized the point below: https://github.com/guicho271828/trivia/wiki/Known-Differences#extended-semantics-of-constant-patterns

fare commented 7 years ago

Uh, shouldn't (quote (a)) be the same as '(a) and thus (list 'a) ? If you want non-constant, you should be using fare-quasiquote, it was designed exactly for that: `(,a). Or if you don't want a special readtable, still (quasiquote ((unquote a)).

fare commented 7 years ago

I can understand why the situation sucks with arrays, though. I blame the CL standard (itself constrained by backward compatibility)

guicho271828 commented 7 years ago

Thanks. It should be a result of an excessive extrapolation when I implemented the structure/array literal patterns, I clearly didn't think enough. I will fix the commits soon.