(cond
((null head)
(if (pcase--self-quoting-p pat) `',pat pat))
- ((memq head '(pred guard quote)) pat)
+ ((memq head '(pred guard quote cheq)) pat)
((memq head '(or and)) `(,head ,@(mapcar #'pcase--macroexpand (cdr pat))))
((eq head 'app) `(app ,(nth 1 pat) ,(pcase--macroexpand (nth 2 pat))))
(t
((eq then :pcase--dontcare) `(progn (ignore ,test) ,else))
(t (macroexp-if test then else))))
+(defvar pcase--equal #'eql)
+
;; Note about MATCH:
;; When we have patterns like `(PAT1 . PAT2), after performing the `consp'
;; check, we want to turn all the similar patterns into ones of the form
(let* ((carbranch (car branches))
(match (car carbranch)) (cdarbranch (cdr carbranch))
(code (car cdarbranch))
- (vars (cdr cdarbranch)))
+ (vars (cdr cdarbranch))
+ (pcase--equal #'eql))
(pcase--u1 (list match) code vars (cdr branches)))))
(defun pcase--and (match matches)
(let ((v (assq upat vars)))
(if (not v)
(pcase--u1 matches code (cons (list upat sym) vars) rest)
- ;; Non-linear pattern. Turn it into an `eq' test.
+ ;; Non-linear pattern. Turn it into an equality test.
(setcdr (cdr v) 'used)
- (pcase--u1 (cons `(match ,sym . (pred (eql ,(cadr v))))
+ (pcase--u1 (cons `(match ,sym . (pred (,pcase--equal ,(cadr v))))
matches)
code vars rest))))
((eq (car-safe upat) 'app)
(pcase--u rest))
vars
(list `((and . ,matches) ,code . ,vars))))
+ ((eq (car-safe upat) 'cheq)
+ (let ((pcase--equal (cadr upat)))
+ (pcase--u1 matches code vars rest)))
(t (error "Unknown pattern `%S'" upat)))))
(t (error "Incorrect MATCH %S" (car matches)))))