Re: self modifying code



John J. Lee wrote:
1. I don't think most people would call that "self-modifying code". I
won't try defining that term precisely because I know you'll just
pick holes in my definition ;-)


Don't really disagree about the rewriting code, but the function does re-define itself.


2. The use of global func is just plain weird :-)

3. Peter Otten's version is OK, but how about this, using a closure
instead of globals (UNTESTED)

def make_func():
namespace = object()
namespace.data = None
def func(a):
if namespace.data is None:
namespace.data = somethingcomplexandcostly()
return simple(namespace.data, a)
return func
func = make_func()

........
the inner function is almost precisely what I started with, except I used the global namespace. However, it keeps the test in side the function which costs about 1%.
--
Robin Becker
.



Relevant Pages

  • Re: Beyond CL?
    ... >> made a class called 'bagel', you could just type bagel at the command ... > it will use def, because to create a special shortcut only for functions ... > for defining different variables vs defining classes vs defining ... >> DECLAIM that this variable will never change and the compiler will ...
    (comp.lang.lisp)
  • Re: Beyond CL?
    ... >> M Jared Finder wrote: ... >>>it will use def, because to create a special shortcut only for functions ... >>>for defining different variables vs defining classes vs defining ... I'm a bit confused as to what "special-case shortcut" you're talking ...
    (comp.lang.lisp)
  • Re: What is wrong with Ada?
    ... def: Closure of T ... (P was defined on finite strings of IN. ... Defining it in some reasonable way ... of machines with individual machines parametrized by some number which ...
    (comp.lang.ada)
  • Re: Defining class methods
    ... Opening up self and defining the methods directly: ... module ClassMethods ... or two class methods I use method 1 (def ... core definition of a class (like helper/utility functions), ...
    (comp.lang.ruby)
  • [ANN] traits-0.7.0 - hooks and validation
    ... tweaked writer code so multiple values can be passed to setters ... # defining a trait is like attr_accessor in the simple case ... def using_private_writer_and_query ... # the rememberance of traits can make generic intializers pretty slick ...
    (comp.lang.ruby)