mirror of
https://github.com/false-schemers/skint.git
synced 2025-01-13 20:03:30 +01:00
safer use of ... in syntax-rules
This commit is contained in:
parent
cbb8eed040
commit
cd1b192446
2 changed files with 1760 additions and 1681 deletions
24
src/k.sf
24
src/k.sf
|
@ -557,19 +557,23 @@
|
||||||
(assq tmpl new-literals)))]
|
(assq tmpl new-literals)))]
|
||||||
[(vector? tmpl)
|
[(vector? tmpl)
|
||||||
(list->vector (expand-part (vector->list tmpl)))]
|
(list->vector (expand-part (vector->list tmpl)))]
|
||||||
[(pair? tmpl)
|
[(and (pair? tmpl) (ellipsis-pair? (cdr tmpl)))
|
||||||
(if (ellipsis-pair? (cdr tmpl))
|
(let ([vars-to-iterate (list-ellipsis-vars (car tmpl))])
|
||||||
(let ([vars-to-iterate (list-ellipsis-vars (car tmpl))])
|
(define (lookup var)
|
||||||
(define (lookup var)
|
(cdr (assq var bindings)))
|
||||||
(cdr (assq var bindings)))
|
(define (expand-using-vals . vals)
|
||||||
(define (expand-using-vals . vals)
|
(expand (car tmpl)
|
||||||
(expand (car tmpl)
|
(map cons vars-to-iterate vals)))
|
||||||
(map cons vars-to-iterate vals)))
|
(if (null? vars-to-iterate)
|
||||||
|
; ellipsis following non-repeatable part is an error, but we don't care
|
||||||
|
(cons (expand-part (car tmpl)) (expand-part (cddr tmpl))) ; repeat once
|
||||||
|
; correct use of ellipsis
|
||||||
(let ([val-lists (map lookup vars-to-iterate)])
|
(let ([val-lists (map lookup vars-to-iterate)])
|
||||||
(append
|
(append
|
||||||
(apply map (cons expand-using-vals val-lists))
|
(apply map (cons expand-using-vals val-lists))
|
||||||
(expand-part (cddr tmpl)))))
|
(expand-part (cddr tmpl))))))]
|
||||||
(cons (expand-part (car tmpl)) (expand-part (cdr tmpl))))]
|
[(pair? tmpl)
|
||||||
|
(cons (expand-part (car tmpl)) (expand-part (cdr tmpl)))]
|
||||||
[else tmpl]))))
|
[else tmpl]))))
|
||||||
|
|
||||||
(lambda (use use-env)
|
(lambda (use use-env)
|
||||||
|
|
Loading…
Reference in a new issue