update sugar/list

pull/2/head
Matthew Butterick 10 years ago
parent ac469d6d3f
commit f9a68d0ae1

@ -1,4 +1,5 @@
#lang racket/base
(require (for-syntax racket/base))
(require racket/list racket/set)
(require "define.rkt" "len.rkt" "coerce.rkt")
@ -58,4 +59,14 @@
(error (string-append "members-unique? failed because " (if (= (len duplicate-keys) 1)
"item isnt"
"items arent") " unique:") duplicate-keys))
result))
result))
;; for use inside quasiquote
;; instead of ,(when ...) use ,@(when/splice ...)
;; to avoid voids
(provide when/splice)
(define-syntax (when/splice stx)
(syntax-case stx ()
[(_ test body)
#'(if test (list body) '())]))

@ -1,32 +0,0 @@
#lang racket/base
(require (for-syntax racket/base))
(require racket/syntax)
(provide define->macro)
(define-syntax define->macro
(syntax-rules ()
[(_ (proc-name arg ... . rest-arg) proc-expr ...) (define->macro proc-name (λ(arg ... . rest-arg) proc-expr ...))]
[(_ proc-name proc) (define-syntax proc-name
(syntax-id-rules ()
[(proc-name expr (... ...)) (proc expr (... ...))]
[proc-name proc]))]))
;(define foo (λ(x) (add1 x)))
;(define->macro foo (λ(x) (add1 x)))
;(foo 4)
;(map foo '(2 4 6))
;(define (bar x) (add1 x))
;(define->macro (bar x y) (+ x y))
;(bar 4 1)
;(map bar '(2 4 6) '(2 4 6))
;(define-syntax zam (add1 x))
;(zam 4)
;(map zam '(2 4 6))

@ -21,11 +21,3 @@
[else (format "~a bytes" bytecount)]))
;; for use inside quasiquote
;; instead of ,(when ...) use ,@(when/splice ...)
;; to avoid voids
(provide when/splice)
(define-syntax (when/splice stx)
(syntax-case stx ()
[(_ test body)
#'(if test (list body) '())]))

@ -73,4 +73,12 @@ Same as @racket[members-unique?], but if the members are not unique, raises a de
(members-unique?/error '(a b c d e f a b))
]
@defform[(when/splice test expr)]
A special version of @racket[when] that you can use inside @racket[quasiquote] to suppress @racket[void] values when @racket[_test] is @racket[#f]. As the name suggests, it works in conjunction with the @litchar["@"] splicing operator.
@examples[#:eval my-eval
`(,(when (even? 2) "hooray"))
`(,(when (even? 3) "hooray"))
`(,@(when/splice (even? 2) "hooray"))
`(,@(when/splice (even? 3) "hooray"))
]

Loading…
Cancel
Save