liberalize un{quote,syntax}-spliciing to allow a non-list at the end of an enclosing list

svn: r8083
This commit is contained in:
Matthew Flatt 2007-12-20 14:00:15 +00:00
parent b8b7a1bb0d
commit d794bde875
5 changed files with 38 additions and 24 deletions

View File

@ -275,9 +275,10 @@
(if (zero? level) (if (zero? level)
(let-values (let-values
(((l) (normal l old-l))) (((l) (normal l old-l)))
(let-values (if (stx-null? l)
() uqsd
(list (quote-syntax qq-append) uqsd l))) (list (quote-syntax qq-append)
uqsd l)))
(let-values (let-values
(((restx) (qq-list rest (sub1 level)))) (((restx) (qq-list rest (sub1 level))))
(let-values (let-values

View File

@ -66,6 +66,13 @@
stx)] stx)]
[((unsyntax-splicing x) . rest) [((unsyntax-splicing x) . rest)
(if (zero? depth) (if (zero? depth)
(if (stx-null? (syntax rest))
(with-syntax ([temp (car (generate-temporaries '(uqs1)))])
(convert-k (datum->syntax
stx
(syntax temp)
stx)
(list #'[temp x])))
(let ([rest-done-k (let ([rest-done-k
(lambda (rest-v bindings) (lambda (rest-v bindings)
(with-syntax ([temp (car (generate-temporaries '(uqs)))] (with-syntax ([temp (car (generate-temporaries '(uqs)))]
@ -81,7 +88,7 @@
(loop (syntax rest) depth (loop (syntax rest) depth
(lambda () (lambda ()
(rest-done-k (syntax rest) null)) (rest-done-k (syntax rest) null))
rest-done-k)) rest-done-k)))
(let ([mk-rest-done-k (let ([mk-rest-done-k
(lambda (x-v x-bindings) (lambda (x-v x-bindings)
(lambda (rest-v rest-bindings) (lambda (rest-v rest-bindings)

View File

@ -33,7 +33,7 @@ Creates an empty font list.
[underline any/c #f] [underline any/c #f]
[smoothing (one-of/c 'default 'partly-smoothed 'smoothed 'unsmoothed) 'default] [smoothing (one-of/c 'default 'partly-smoothed 'smoothed 'unsmoothed) 'default]
[size-in-pixels? any/c #f]) [size-in-pixels? any/c #f])
void?])]{ (is-a?/c font%)])]{
Finds an existing font in the list or creates a new one (that is Finds an existing font in the list or creates a new one (that is
automatically added to the list). The arguments are the same as for automatically added to the list). The arguments are the same as for

View File

@ -1013,12 +1013,18 @@ and the result of the @scheme[_expr] takes the place of the
@scheme[(unquote-splicing _expr)] similarly escapes, but the @scheme[(unquote-splicing _expr)] similarly escapes, but the
@scheme[_expr] must produce a list, and its elements are spliced as @scheme[_expr] must produce a list, and its elements are spliced as
multiple values place of the @scheme[(unquote-splicing _expr)], which multiple values place of the @scheme[(unquote-splicing _expr)], which
must appear as the @scheme[car] or a quoted pair. must appear as the @scheme[car] or a quoted pair; if the @scheme[cdr]
of the relevant quoted pair is empty, then @scheme[_expr] need not
produce a list, and its result is used directly in place of the quoted
pair (in the same way that @scheme[append] accepts a non-list final
argument).
@examples[ @examples[
(eval:alts (#,(scheme quasiquote) (0 1 2)) `(0 1 2)) (eval:alts (#,(scheme quasiquote) (0 1 2)) `(0 1 2))
(eval:alts (#,(scheme quasiquote) (0 (#,(scheme unquote) (+ 1 2)) 4)) `(1 ,(+ 1 2) 4)) (eval:alts (#,(scheme quasiquote) (0 (#,(scheme unquote) (+ 1 2)) 4)) `(0 ,(+ 1 2) 4))
(eval:alts (#,(scheme quasiquote) (0 (#,(scheme unquote-splicing) (list 1 2)) 4)) `(1 ,@(list 1 2) 4)) (eval:alts (#,(scheme quasiquote) (0 (#,(scheme unquote-splicing) (list 1 2)) 4)) `(0 ,@(list 1 2) 4))
(eval:alts (#,(scheme quasiquote) (0 (#,(scheme unquote-splicing) 1) 4)) `(0 ,@1 4))
(eval:alts (#,(scheme quasiquote) (0 (#,(scheme unquote-splicing) 1))) `(0 ,@1))
] ]
A @scheme[quasiquote], @scheme[unquote], or @scheme[unquote-splicing] A @scheme[quasiquote], @scheme[unquote], or @scheme[unquote-splicing]

View File

@ -663,7 +663,7 @@
(syntax-test #'(unquote-splicing 7)) (syntax-test #'(unquote-splicing 7))
(syntax-test #'`(1 . ,@5)) (syntax-test #'`(1 . ,@5))
(error-test #'`(1 ,@5)) (test (cons 1 5) 'qq `(1 ,@5))
(error-test #'`(1 ,@5 2)) (error-test #'`(1 ,@5 2))
(define (qq-test e) (define (qq-test e)