guicho271828 / trivia

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

Style warning when matching structs on SBCL. #104

Closed marcoheisig closed 5 years ago

marcoheisig commented 5 years ago

The following snippet of code produces a weird style warning on SBCL. (Both on 1.4.5 and 1.4.15):

(in-package #:cl-user)

(defstruct (foo (:predicate foop)))

(trivia:defpattern foo ()
  (let ((it (gensym)))
    `(trivia:guard1 ,it (foop ,it))))

(defun foo-finder (x)
  (trivia:match x
    ((foo) (format t "Found a foo!"))))

The style warning is

; in: defun foo-finder ; (TRIVIA.LEVEL2:MATCH X ; ((FOO) (FORMAT T "Found a foo!"))) ; --> TRIVIA.LEVEL2:MATCH2 TRIVIA.LEVEL2:MATCH2+ ; ==> ; (TRIVIA.LEVEL2:MATCH2*+ (X) ; (T) ; (((FOO)) (FORMAT T "Found a foo!")) ; ((TRIVIA.LEVEL2.IMPL::_) NIL)) ; ; caught style-warning: ; undefined type: (foo) ; ; compilation unit finished ; Undefined type: ; (foo) ; caught 1 STYLE-WARNING condition

I only get this style warning with the latest Trivia release on Quicklisp, so it must have been due to a recent change.

guicho271828 commented 5 years ago
marcoheisig commented 5 years ago

Thank you for the quick reply and the excellent explanation!

I am trying to think what a sensible workaround would be. I see the following options:

  1. Simply muffle style warnings on SBCL where necessary.
  2. Improve type-i:all-compound-types such that when the atomic type specifier in question is a subtype of structure-class, it only emits foo and not (foo).

I think I prefer option 2. If you want, I can implement that and open a pull request.

guicho271828 commented 5 years ago

I also prefer 2. thanks

marcoheisig commented 5 years ago

Here we go: https://github.com/guicho271828/type-i/pull/2.

guicho271828 commented 5 years ago

merged. thanks!