add `caseq` and `casev`

dev-srcloc
Matthew Butterick 8 years ago
parent 626e8f4fd4
commit 726bca2542

@ -0,0 +1,24 @@
#lang racket/base
(require (for-syntax racket/base) br/define)
(provide (all-defined-out))
(define-macro (define-case-macro ID PRED)
#'(define-syntax (ID stx)
(syntax-case stx ()
[(_ test-val
[(match-vals) . result] (... ...)
[else . else-result])
#'(cond
[(PRED test-val '(match-vals)) . result] (... ...)
[else . else-result])]
[(_ test-val
match-clause (... ...))
#'(ID test-val
match-clause (... ...)
[else (error 'ID "no match")])])))
;; like case but strictly uses `eq?` comparison (as opposed to `equal?`)
(define-case-macro caseq memq)
;; `eqv?` is OK for chars (same as `char=?`)
(define-case-macro casev memv)

@ -1,10 +1,10 @@
#lang racket/base
(require racket/provide racket/list racket/string racket/format racket/match racket/port racket/function
br/define br/syntax br/datum br/debug br/cond br/list racket/class racket/vector br/reader-utils
br/define br/syntax br/datum br/debug br/cond br/case br/list racket/class racket/vector br/reader-utils
(for-syntax racket/base racket/syntax br/syntax br/debug br/define br/datum))
(provide (all-from-out racket/base)
(all-from-out racket/list racket/string racket/format racket/match racket/port racket/function
br/syntax br/datum br/debug br/cond br/list racket/class racket/vector br/define br/reader-utils)
br/syntax br/datum br/debug br/cond br/case br/list racket/class racket/vector br/define br/reader-utils)
(for-syntax (all-from-out racket/base racket/syntax br/syntax br/debug br/datum))
(for-syntax caller-stx with-shared-id)) ; from br/define

Loading…
Cancel
Save