chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] making lambdas more introspective


From: felix winkelmann
Subject: Re: [Chicken-users] making lambdas more introspective
Date: Mon, 30 May 2005 08:02:05 +0200

On 5/28/05, Michele Simionato <address@hidden> wrote:
> 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?
> 

I wouldn't want to have this for every `lambda': among other things
the optimizer wouldn't be able to do a god enough job on this
kind of code (it wouldn't be able to associate the lambda with the
binding name, and so a lot of opportunities for optimization would
be lost). So, whille I agree with the usefulness of such a thing, I must
decline for purely technical reasons... ;-)


cheers,
felix




reply via email to

[Prev in Thread] Current Thread [Next in Thread]