ruricolist / serapeum

Utilities beyond Alexandria

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`match-of` with ADT (together with `defunion`).

jsulmont opened this issue · comments

Hi
Assuming the following following

(defunion ski
  S
  K
  I
  (E (lhs ski) (rhs ski)))

, the following code

(defun blah (expr)
(match-of ski expr
  (K K)
  (I I)
  (S S)
  ((E I x) (interpret x))))

interprets I in the (E I x) clause as a variable rather than the I unit type.
Or have I missed something (probably)?

Thank you!

Answering my own question (after reading pattern-type) ... the correct way of doing this is:

(defun interpret (expr)
  (match-of ski expr
    ((or S K I)  expr)
    ((E (eql I) x) (interpret x))))

(also helpful to read about trivia...)