Added let-abort and let*-abort

This commit is contained in:
Georges Dupéron 2015-11-06 15:32:40 +01:00
parent 40fe7e03d5
commit 449a6f4a09
2 changed files with 33 additions and 1 deletions

View File

@ -0,0 +1,13 @@
#lang typed/racket
(require "cond-abort.rkt")
(match-abort '(1 (a b) 3)
[(list x y z)
(let-abort ([new-x x]
[new-y (match-abort y
[(list n p) (list 'A n p)]
[(list q r s) (list 'B q r s)])]
[new-z z])
(list new-x new-y new-z))])

View File

@ -1,7 +1,9 @@
#lang typed/racket
(provide cond-abort
match-abort)
match-abort
let-abort
let*-abort)
(define-syntax (cond-abort orig-stx)
(let rec ([stx orig-stx])
@ -37,6 +39,23 @@
[_ 'continue])]
...)))
(define-syntax-rule (let-abort ([binding value] ...) . body)
(let ([binding value] ...)
(cond
[(or (eq? 'continue binding) (eq? 'break binding)) binding]
...
[else (begin . body)])))
(define-syntax (let*-abort stx)
(syntax-case stx ()
[(_ () . body)
#'(begin . body)]
[(_ ([binding0 value0] . rest) . body)
#'(let ([binding0 value0])
(if (or (eq? 'continue binding) (eq? 'break binding))
binding
(let*-abort rest . body)))]))
(module* test typed/racket
(require typed/rackunit)
(require (submod ".."))