guicho271828 / trivia

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

Type inference and SATISFIES, GUARD1, etc #133

Open no-defun-allowed opened 2 years ago

no-defun-allowed commented 2 years ago

I'd like to shift some more predicates into patterns, so that I can avoid a bunch of code that looks like (when (foo-p bar) (trivia.next:next)). But, so far, Trivia seems to consider the use of predicates that don't correspond to types deserving of a full warning.

A little example is:

CL-USER> (trivia:match 2
           ((satisfies evenp) 'even))
WARNING: failed to infer the type from test (EVENP ?) !
WARNING: failed to infer the type from test (EVENP ?) !
WARNING: failed to infer the type from test (EVENP ?) !
EVEN

There isn't a type that corresponds to the set of values which satisfy evenp, so I am not sure what I can do to avoid the warning. The same also happens with guard1:

CL-USER> (trivia:defpattern even-number ()
           `(trivia:guard1 (x) (evenp x)))
#<FUNCTION 'EVEN-NUMBER {52E5A57B}>
CL-USER> (trivia:match 2
           ((even-number) 'even))
WARNING: failed to infer the type from test (EVENP ?) !
WARNING: failed to infer the type from test (EVENP ?) !
WARNING: failed to infer the type from test (EVENP ?) !
EVEN

(Also, I'd guess the function name for the pattern should just be even-number - sb-int:named-lambda doesn't evaluate the name provided to it.)

Is signalling a full warning intended behaviour for Trivia? Can I write a pattern for some arbitrary test expression which doesn't signal a full warning at compile time? I ask since, in the end, I want to clean up some tests in the rewriter of one-more-re-nightmare, but I want to submit it to Quicklisp, and (to my knowledge) I cannot do so if compilation signals full warnings.

guicho271828 commented 2 years ago

It is part of type-i so the issue should go there

guicho271828 commented 2 years ago

For namedlambda thanks, will fix