This is something that keeps coming to me: I often want to know about the
signature of a function, or because I don't remember it from the manual,
or because I want to generate a modified version of the original function,
but keeping the same signature. It is pretty easy to implement the needed
functionality:

(require-extension lolevel)

(define-macro (introspective-lambda formals . body)
  `(extend-procedure (lambda ,formals ,@body) '((formals . ,formals))))

(define (lambda-signature ilambda)
  (cdr (assoc 'formals (procedure-data ilambda))))

;; example:

> (define sum3 (introspective-lambda (x y z) (+ x y z)))
> (lambda-signature sum3)
(x y z)

However, I think this is useful enough to have in the core language (we
could even implement a help system!). One would have to store a few 
bytes more to keep the signature in memory, but it does not look as a big 
deal. 
Any thoughts, comments, ideas?

                Michele Simionato


_______________________________________________
Chicken-users mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/chicken-users

Reply via email to