Re: Questions about anonymous functions and classes/functions declarations

Joachim Durchholz <joachim.durchholz@web.de>
6 Oct 2003 21:31:55 -0400

          From comp.compilers

Related articles
Questions about anonymous functions and classes/functions declarations mrfaro@libero.it (Gabriele Farina) (2003-10-04)
Re: Questions about anonymous functions and classes/functions declarat derkgwen@HotPOP.com (Derk Gwen) (2003-10-06)
Re: Questions about anonymous functions and classes/functions declarat lsantil@calstatela.edu (Louis Paul Santillan) (2003-10-06)
Re: Questions about anonymous functions and classes/functions declarat haberg@matematik.su.se (2003-10-06)
Re: Questions about anonymous functions and classes/functions declarat joachim.durchholz@web.de (Joachim Durchholz) (2003-10-06)
Re: Questions about anonymous functions and classes/functions declarat geoff@wozniak.ca (Geoff Wozniak) (2003-10-08)
Re: Questions about anonymous functions and classes/functions declarat joachim.durchholz@web.de (Joachim Durchholz) (2003-10-08)
Re: Questions about anonymous functions and classes/functions declarat witness@t-online.de (Uli Kusterer) (2003-10-13)
Re: Questions about anonymous functions and classes/functions declarat marcov@stack.nl (Marco van de Voort) (2003-10-13)
| List of all articles for this month |

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


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.