From: | Joachim Durchholz <joachim.durchholz@web.de> |
Newsgroups: | comp.compilers |
Date: | 6 Oct 2003 21:31:55 -0400 |
Organization: | Oberberg Online Infosysteme |
References: | 03-10-004 |
Keywords: | code, design |
Posted-Date: | 06 Oct 2003 21:31:55 EDT |
Gabriele Farina wrote:
> Where I have to store them?? I have to have a table only
> for anonymous functions?? Someone asks to me to treat them as
> constants, but I can't understanda how to develop it.
They are "constants" just like any other function. In fact you can
treat them like any ordinary function. They just happen not to have a
name that the programmers knows.
> Now there is another questions: I'd like to give the users the ability
> to edit a class definition at runtime. For example:
>
> test = class()
> input value
>
> if value == 10
> test.a_new_method = function(a) print a
> else
> test.a_new_method = function(a) print 'Your wrong the number, you
> inserted'.append(a)
>
> instance = new test()
> instance.a_new_method(value)
>
> test = class() defines a new class, where, dynamically, I add a new method
> looking at a variable value given as input.
> As you can see I add new method at runtime.
>
> Do you think this can be useful
Yes, but it's dangerous.
Reading the source code isn't enough to understand what the class does -
unless you restrict who can modify the class (but even then I'd
recommend against it - the human mind isn't built for understanding
self-modifying code).
> and can be implemented??
> There could be any
> problems??
Yes, easily (for some suitable definition of "easy").
You'd have to plan the run-time data structures for that, though, and
that may interfere with other design goals.
Regards,
Jo
Return to the
comp.compilers page.
Search the
comp.compilers archives again.