use for/list intead of a (one off) map/i function.

This commit is contained in:
Robby Findler 2010-12-06 09:19:53 -06:00
parent 45a97cb561
commit b884623da2

View File

@ -49,8 +49,10 @@
(with-syntax ([(i ...) (build-list len add1)])
#`(define (fn-name args ... . final-arg)
(let ([args (check/normalize 'fn-name 'args args i)] ...
[final-arg (map/i (λ (x j) (check/normalize 'fn-name 'final-arg x (+ #,(+ len 1) j)))
final-arg)])
[final-arg
(for/list ([x (in-list final-arg)]
[j (in-naturals #,(+ len 1))])
(check/normalize 'fn-name 'final-arg x j))])
body ...))))]
[(define/chk (fn-name args ...) body ...)
(with-syntax ([(i ...) (build-list (length (syntax->list #'(args ...))) add1)]
@ -70,14 +72,6 @@
(let ([arg-ids (check/normalize 'fn-name 'arg-ids arg-ids i)] ...)
body ...)))])))
(define (map/i f l)
(let loop ([l l]
[i 0])
(cond
[(null? l) null]
[else (cons (f (car l) i)
(loop (cdr l) (+ i 1)))])))
;; check/normalize : symbol symbol any number -> any
;; based on the name of the argument, checks to see if the input
;; is valid and, if so, transforms it to a specific kind of value