[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Chicken-users] making lambdas more introspective
From: |
Michele Simionato |
Subject: |
[Chicken-users] making lambdas more introspective |
Date: |
Sat, 28 May 2005 01:41:27 -0400 |
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] making lambdas more introspective,
Michele Simionato <=