summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2009-05-21 15:34:29 +0200
committerAndy Wingo <wingo@pobox.com>2009-05-21 15:34:29 +0200
commitd63927150aa22bb7e57125ed50e5ecbe11765fba (patch)
tree6fa382547cbe29e7df157e834e9aa65ee6b8d33a
parent47c8983f08157865a3937722c06acbbb3cbd7621 (diff)
downloadguile-d63927150aa22bb7e57125ed50e5ecbe11765fba.tar.gz
just parse method arguments once.
* module/oop/goops.scm (method): Tweak to just run through the arguments once. Thanks to Eli Barzilay for the tip.
-rw-r--r--module/oop/goops.scm38
1 files changed, 20 insertions, 18 deletions
diff --git a/module/oop/goops.scm b/module/oop/goops.scm
index 8c980485f..fd2d60058 100644
--- a/module/oop/goops.scm
+++ b/module/oop/goops.scm
@@ -479,23 +479,26 @@
(define-syntax method
(lambda (x)
- (define (compute-formals args)
- (let lp ((ls args) (out '()))
- (syntax-case ls ()
- (((f s) . rest) (lp (syntax rest) (cons (syntax f) out)))
- ((f . rest) (identifier? (syntax f))
- (lp (syntax rest) (cons (syntax f) out)))
- (() (reverse out))
- (tail (identifier? (syntax tail))
- (append (reverse out) (syntax tail))))))
-
- (define (compute-specializers args)
- (let lp ((ls args) (out '()))
+ (define (parse-args args)
+ (let lp ((ls args) (formals '()) (specializers '()))
(syntax-case ls ()
- (((f s) . rest) (lp (syntax rest) (cons (syntax s) out)))
- ((f . rest) (lp (syntax rest) (cons (syntax <top>) out)))
- (() (reverse (cons (syntax '()) out)))
- (tail (reverse (cons (syntax <top>) out))))))
+ (((f s) . rest)
+ (and (identifier? (syntax f)) (identifier? (syntax s)))
+ (lp (syntax rest)
+ (cons (syntax f) formals)
+ (cons (syntax s) specializers)))
+ ((f . rest)
+ (identifier? (syntax f))
+ (lp (syntax rest)
+ (cons (syntax f) formals)
+ (cons (syntax <top>) specializers)))
+ (()
+ (list (reverse formals)
+ (reverse (cons (syntax '()) specializers))))
+ (tail
+ (identifier? (syntax tail))
+ (list (append (reverse formals) (syntax tail))
+ (reverse (cons (syntax <top>) specializers)))))))
(define (find-free-id exp referent)
(syntax-case exp ()
@@ -561,8 +564,7 @@
(syntax-case x ()
((_ args) (syntax (method args (if #f #f))))
((_ args body0 body1 ...)
- (with-syntax ((formals (compute-formals (syntax args)))
- ((specializer ...) (compute-specializers (syntax args))))
+ (with-syntax (((formals (specializer ...)) (parse-args (syntax args))))
(call-with-values
(lambda ()
(compute-procedures (syntax formals) (syntax (body0 body1 ...))))