guicho271828 / trivia

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

`return for unknown block: TRIVIA.LEVEL1.IMPL::CLAUSE` with `(type t)` #143

Open 3b opened 1 year ago

3b commented 1 year ago

Maybe not too important since (type t) probably should be written as otherwise instead, but still confusing if one doesn't happen to think about that option.


(defun x (x)
  (trivia:match x
    ((type t) x)))

fails to compile with

; in: DEFUN X
;     (TRIVIA.LEVEL2:MATCH X
;       ((TYPE T)))
; --> TRIVIA.LEVEL2:MATCH2+ TRIVIA.LEVEL2:MATCH2*+ SYMBOL-MACROLET 
; --> TRIVIA.LEVEL1:MATCH1 LET BLOCK LET TRIVIA.LEVEL1:TRACE-WHEN WHEN 
; --> IF LET LET RETURN-FROM LOCALLY TRIVIA.LEVEL1:MATCH1 LET BLOCK LET 
; --> RETURN-FROM LOCALLY TRIVIA.LEVEL2:MATCH2*+ SYMBOL-MACROLET 
; --> TRIVIA.LEVEL1:MATCH1 LET BLOCK LET RETURN-FROM LOCALLY 
; --> TRIVIA.SKIP:SKIP TRIVIA.NEXT:NEXT 
; ==>
;   (RETURN-FROM TRIVIA.LEVEL1.IMPL::CLAUSE NIL)
; 
; caught ERROR:
;   return for unknown block: TRIVIA.LEVEL1.IMPL::CLAUSE
guicho271828 commented 1 year ago

Interesting corner case... Will investigate in weekend.

guicho271828 commented 1 year ago

This is due to the optimizer. Screenshot from 2023-08-02 10-32-58

guicho271828 commented 1 year ago

The unknown block is generated by this skip. I remember that I struggled to make this code correct. This skip is needed when multiple fusing creates a nested tree of match2*+. I need a way to detect that this last clause appears in the top level. Unfortunately, CL macros do not provide many facilities to query the current environment, i.e., change the bahavior according to the surrounding envronment. In other words, this felt like the limit of CL. Screenshot from 2023-08-02 10-40-49 Screenshot from 2023-08-02 10-39-22

Gleefre commented 11 months ago

I think you could use macrolet inside the (block clause ...) to achieve the desired modification of the toplevel vs nested behavior; please see it implemented in draft PR #146 .