octave-maintainers
[Top][All Lists]
Advanced

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

Re: Crash with inline


From: David Bateman
Subject: Re: Crash with inline
Date: Thu, 16 Sep 2004 18:33:50 +0200
User-agent: Mutt/1.4.1i

According to Teemu Ikonen <address@hidden> (on 09/16/04):
> On 16/09/04 11:01, John W. Eaton wrote:
> > | functions as first-class objects,
> > They are not really first-class objects, are they?  If you write
> 
> Oops, indeed I mistook the function handles returned by inline as functions.
> 
> > | would it be hard to implement real closures?
> > I'm not sure.  How would this work within the current language?
> 
> Well, functions defined in the command line either by inline or function
> keyword would find undefined variables from the top-level environment (if
> they exist) and store their value. Something like:
> 
> > a = 1;
> > f = inline("x + a", "x");
> > f(1)
> ans = 2
> > a = pi;
> > f(1)
> ans = 2
> 
> Looks straightforward, but there might be all kinds of subtleties I'm not
> aware of...

Basically to do this we'd need a copy constructor for symbol_table and make
a copy of curr_sym_tab when creating the function handle. As inline functions
are just specialized function handles and inherit the methods of function
handles no special treatment would be needed.

The problem then arises in a case where for example you have a function
on the loadpath, create a function handle that depends on this function,
and then change directories. If the function hasn't already been parsed
when the copy of curr_sym_tab is made, and a different version of this
function exists in the need directory, then which version is called. So
you also need to save the loadpath.

Ok, lets get even more paranoid. With the same case as above without 
changing directories. However, the function that the function handle
depends on is edited... Should the function handle still use the old
definition or the new one.

So the question is exactly how much of the context is saved when creating
a function handle.. If it is everything, creating a function handle might
be a very very expensive operation...

I haven't checked how matlab does this, but I'd thing a reasonable solution
would be to save curr_sym_tab, fbi_sym_tab and the loadpath. However, it
would be good to hear if others have other ideas..

D.

-- 
David Bateman                                address@hidden
Motorola CRM                                 +33 1 69 35 48 04 (Ph) 
Parc Les Algorithmes, Commune de St Aubin    +33 1 69 35 77 01 (Fax) 
91193 Gif-Sur-Yvette FRANCE

The information contained in this communication has been classified as: 

[x] General Business Information 
[ ] Motorola Internal Use Only 
[ ] Motorola Confidential Proprietary



reply via email to

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