From octave-maintainers-request at bevo dot che dot wisc dot edu Sat Jun 21 00:19:08 2003 Subject: Re: Octave 2.2.x Was: A group in Norway ... From: Paul Kienzle To: "John W. Eaton" Cc: octave-maintainers mailing list Date: Sat, 21 Jun 2003 01:21:13 -0400 John W. Eaton wrote: >On 20-Jun-2003, Paul Kienzle wrote: > > >Here is a real kluge. Replace the end of your inline.m with the >following code > >... > >and then you can write > > f = inline ('if (x < 3) y = 3; else y = x; end; y;') > feval (f, 2) ==> 3 > feval (f, 5) ==> 5 > >or you can write anything that can be handled by Matlab's inline >function (a simple expression). The downside is that it requires two >functions to be generated and called to evaluate the inline function >code when you run it. > Thanks, but I think we will stick with simple expressions for now. >Although it might be possible to do this in an M-file, I think this >really needs to be implemented internally as a new data type. Then >you could overload the () indexing operator so that instead of having >to use feval, you could write: > > f = inline ('t^2') > f (2) ==> 4 > It is important that these inline functions can be handed to optimizers and graphing functions, etc., all of which evaluate their args with feval. Would that happen automatically if the new type were an octave_function subclass? >Also, by doing this in C++, it would be easier to detect what >variables are arguments by generating an anonymous function and then >examining its symbol table for variables using the rules of Matlab's >inline function. To do a better job, you could try to analyze the >parse tree and figure out which variables need values (and must be >parameters). > Not always possible without lexical scoping. In the following example, y is free only if x is 0: inline('if x, y=2; end; y') We could at least list the variables that occur and assume they are all arguments. If the inline explicitly lists the arguments, then we could pre-assign the remaining variables with values from the current scope. If the expression contains eval all bets are off. The best we could do then pass a deep copy of the current symbol table at the time the inline was taken. Paul Kienzle pkienzle at users dot sf dot net