Added let-abort and let*-abort
This commit is contained in:
parent
40fe7e03d5
commit
449a6f4a09
13
graph/graph/_examples_cond-abort.rkt
Normal file
13
graph/graph/_examples_cond-abort.rkt
Normal 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))])
|
||||
|
|
@ -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 ".."))
|
||||
|
|
Loading…
Reference in New Issue
Block a user