forked from alex-eg/sex
match a sum through a pointer to it
A pointer was refused, where . reads through one; a match now reads through the whole chain of them to the sum.
This commit is contained in:
@@ -1018,7 +1018,7 @@
|
||||
;;; binders, or a variant left out with no `else' are all errors here:
|
||||
;;; a missing case is the thing this form exists to catch.
|
||||
(define (walk-match form env)
|
||||
(let* ((scrutinee (and (pair? (cdr form)) (second form)))
|
||||
(let* ((scrutinee (and (pair? (cdr form)) (dereferenced (second form) env form)))
|
||||
;; a comment between arms goes the way the writer already
|
||||
;; drops one between switch clauses
|
||||
(arms (remove comment-form? (cddr form)))
|
||||
@@ -1042,6 +1042,13 @@
|
||||
,(match-branches name held variants arms))
|
||||
env)))))
|
||||
|
||||
;;; A pointer to a sum is matched as the sum, read through however many
|
||||
;;; there are, as `.' reads through them: p : (* * shape) -> (* (* p))
|
||||
(define (dereferenced expr env form)
|
||||
(if (pointer-target (expression-type expr env))
|
||||
(dereferenced (copy-form-source! form (list '* expr)) env form)
|
||||
expr))
|
||||
|
||||
(define (match-binders arms)
|
||||
(append-map (lambda (arm)
|
||||
(if (eq? (car arm) 'else) '() (delete '_ (second (car arm)))))
|
||||
|
||||
Reference in New Issue
Block a user