(not (memq (car object) seen))
(loop (cdr object) (cons (car object) seen)))))))
+(define (fold-r4rs-lambda-list procedure initial bvl)
+ (let loop ((bvl* bvl))
+ (cond ((and (pair? bvl*) (identifier? (car bvl*)))
+ (procedure (car bvl*) (loop (cdr bvl*))))
+ ((null? bvl*) (initial #f))
+ ((identifier? bvl*) (initial bvl*))
+ (else (error:not-a r4rs-lambda-list? bvl)))))
+
(define (parse-r4rs-lambda-list bvl)
- (let loop ((bvl* bvl) (required '()))
- (cond ((and (pair? bvl*)
- (identifier? (car bvl*)))
- (loop (cdr bvl*)
- (cons (car bvl*) required)))
- ((null? bvl*)
- (values (reverse! required) #f))
- ((identifier? bvl*)
- (values (reverse! required) bvl*))
- (else
- (error:not-a r4rs-lambda-list? bvl)))))
+ (let ((parsed
+ (fold-r4rs-lambda-list (lambda (var parsed)
+ (cons (cons var (car parsed))
+ (cdr parsed)))
+ (lambda (var)
+ (cons '() var))
+ bvl)))
+ (values (car parsed) (cdr parsed))))
+
+(define (r4rs-lambda-list-arity bvl)
+ (let ((arity
+ (fold-r4rs-lambda-list (lambda (var arity)
+ (declare (ignore var))
+ (cons (fix:+ 1 (car arity))
+ (and (cdr arity)
+ (fix:+ 1 (cdr arity)))))
+ (lambda (var)
+ (cons 0 (if var #f 0)))
+ bvl)))
+ (make-procedure-arity (car arity) (cdr arity))))
(define (map-r4rs-lambda-list procedure bvl)
(let loop ((bvl* bvl))