> [Gerhard Schellhorn <[EMAIL PROTECTED]>]
> 
> So my question now is: what is the correct solution,
> when I want to use dynamically generated (and dynamically modified)
> functions? After all, elegant dynamic creation of functions
> (using backquote syntax)  is THE feature of Lisp that I find
> the most attractive in comparison to other programming languages.

Are you sure you need to build the bodies of functions at run time?
If you can express the computation in terms of function composition
instead of function-text construction, then everything comes out more
elegantly.  E.g., instead of writing

     `(and ,b1 ,b2)

where b1 and b2 build some text, write

     (let ((fb1 (build-function b1))
           (fb2 (build-function b2)))
        (lambda () (and (funcall fb1) (funcall fb2))))

But if you do have to build functions from text at run time, you can
build 'labels' expressions and avoid defining the global function
values of any symbols:

    `(labels ((,fun-name ()
                  ,(big-function-builder fun-name)))
        (,fun-name))

where 'fun-name' is any name, and 'big-function-builder' knows to use
that name to call the function recursively.

You can expand the function list in the 'labels' expression if you
need to use more function names.

Compile the 'labels' expression before using it.

-- 
                                             -- Drew McDermott
                                                Yale CS Department



Reply via email to