srfi/34: work with else
frmo racket
or mzscheme
This commit is contained in:
parent
9eacbec35e
commit
b6218097d2
|
@ -707,6 +707,10 @@ This SRFI's syntax is part of Racket's default reader.
|
|||
(raise #f "raise")
|
||||
)]
|
||||
|
||||
An @racket[else] is recognized as either the one from
|
||||
@racketmodname[racket/base] or as an identifier with the symbolic form
|
||||
@racket['else] and no binding.
|
||||
|
||||
@; ----------------------------------------
|
||||
|
||||
@srfi[35]{Conditions}
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
#lang racket/base
|
||||
(require (for-syntax racket/base
|
||||
syntax/stx))
|
||||
|
||||
;; SRFI 34 for PLT Scheme
|
||||
;; Zhu Chongkai, April 2005
|
||||
;; <mrmathematica@yahoo.com>
|
||||
(module exception mzscheme
|
||||
|
||||
(provide with-exception-handler
|
||||
guard
|
||||
|
@ -12,14 +15,18 @@
|
|||
((_ handler thunk)
|
||||
(with-handlers (((lambda (exn) #t) handler)) (thunk)))))
|
||||
|
||||
(define-syntax guard
|
||||
(syntax-rules (else)
|
||||
((_ (var clause ... (else de ...)) e1 e2 ...)
|
||||
(define-syntax (guard stx)
|
||||
(syntax-case stx ()
|
||||
((_ (var clause ... (els de ...)) e1 e2 ...)
|
||||
(and (identifier? #'els)
|
||||
(module-or-top-identifier=? #'els #'else))
|
||||
(syntax/loc stx
|
||||
(with-handlers (((lambda (exn) #t)
|
||||
(lambda (var) (cond clause ...
|
||||
(else de ...)))))
|
||||
e1 e2 ...))
|
||||
e1 e2 ...)))
|
||||
((_ (var clause ...) e1 e2 ...)
|
||||
(syntax/loc stx
|
||||
(with-handlers (((lambda (exn) #t)
|
||||
(lambda (var) (cond clause ...
|
||||
(else (raise var))))))
|
||||
|
|
18
pkgs/srfi-pkgs/srfi-test/tests/srfi/34/else.rkt
Normal file
18
pkgs/srfi-pkgs/srfi-test/tests/srfi/34/else.rkt
Normal file
|
@ -0,0 +1,18 @@
|
|||
#lang racket/base
|
||||
(require srfi/34)
|
||||
|
||||
(guard (condition
|
||||
(else
|
||||
(display "condition: ")
|
||||
(write condition)
|
||||
(newline)
|
||||
'exception))
|
||||
(+ 1 (raise 'an-error)))
|
||||
|
||||
(guard (condition
|
||||
(#t ; <- not an identifier
|
||||
(display "condition: ")
|
||||
(write condition)
|
||||
(newline)
|
||||
'exception))
|
||||
(+ 1 (raise 'an-error)))
|
10
pkgs/srfi-pkgs/srfi-test/tests/srfi/34/mz-else.rkt
Normal file
10
pkgs/srfi-pkgs/srfi-test/tests/srfi/34/mz-else.rkt
Normal file
|
@ -0,0 +1,10 @@
|
|||
#lang mzscheme
|
||||
(require srfi/34)
|
||||
|
||||
(guard (condition
|
||||
(else
|
||||
(display "condition: ")
|
||||
(write condition)
|
||||
(newline)
|
||||
'exception))
|
||||
(+ 1 (raise 'an-error)))
|
Loading…
Reference in New Issue
Block a user