Closed vindarel closed 3 years ago
generator-form
and subpattern2
in guard
is no longer supported in the current guard
implementation, due to the difficulty in correctly characterising its behavior. This is reflected in the docstring, but unfortunately not in wiki.
Imagine the following case:
(match (list 1 (list 2 5) 2)
((list a
(guard (list x y) ; subpattern1
(= 10 (* x y a b)) ; test-form
(list (- x y) (- a b)) ; generator-form,
(satisfies evenp)) ; subpattern2
b)
t))
What is the correct scope of test-form
? Optima and guard forms in ML langs in general support referencing outside variables, which is implemnted by lifting
of guard clauses.
This is ok, but when it comes to generator-form
, you notice that the form must be evaluated after evaluating test-form
, therefore generator-form
must also be put in a scope where all variables x y a b
are visible.
When multiple guard forms are nested, then this means that there is a sequence of tests, generation, matching. When multiple generator-forms are present, which one should be evaluated first? My brain stopped around here and I decided not to implement it rather than providing an ill-defined implementation.
OK, thanks for the explanation.
I'll change the wiki the example to this simpler form:
(match (list 2 5)
((guard (list x y) ; subpattern1
(= 10 (* x y))) ; test-form
t))
Hello,
This example:
from https://github.com/guicho271828/trivia/wiki/Logic-Based-Patterns
throws:
How should it be fixed?
Best,
SBCL 1.4.5-debian, QL dist "2020-12-20"