octave-maintainers
[Top][All Lists]
Advanced

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

Re: Re-implementation of inline functions


From: John W. Eaton
Subject: Re: Re-implementation of inline functions
Date: Wed, 4 Aug 2004 14:59:56 -0400

On  4-Aug-2004, David Bateman <address@hidden> wrote:

| The implementation I sent treats inline functions as function handles.
| See that is_function_handle returns true. Now that you made the changes
| to the octave_fcn_handle class I should probably make the octave_fcn_inline
| class inherit from octave_fcn_handle.
| 
| However I haven't implemented the syntax
| 
| @ ( ARG_LIST ) EXPR
| 
| I don't have the latest release of Matlab and so not sure how this syntax 
| is treated. Is it an inline function or is it a function handle? Also is
| the presence of the "( )" what makes the difference between this and a
| normal function handle?

I also don't have a copy of the latest release of Matlab, so I am
going by the docs from the MathWorks web site.  This syntax is
metioned in the description of function handles, so I believe it
returns a function handle with no name, or a name like "<anonymous
function>" or something, though I don't know precisely since there is
no example for that in the docs.

| Yes, inline could be a special case of function handles in this case.
| However, we'd need someway of specifying that the function handle 
| points to a real physical function or to an inlined expression. We'd also
| need to adapt the function handle class to include a few extra privates
| to allow the function formula and argnames to work correctly.

Yes, you would probably want to cache the extra information.  I was
just suggesting that after you scan the args to inline and decide what
variable names to use, you could construct a string to eval to create
the inline function part.  Then a call like

  inline ('x^2')

could create a function handle by doing the equivalent of

  fh = eval ("@ ( x ) x^2", error_catching_code_here);

So an inlined function is just a function handle with some extra
attributes.  And the inline() function itself does some tricky magic
that is probably best avoided.  Rules like:

  The input argument to the inline function is automatically
  determined by searching expr for an isolated lower case alphabetic
  character, other than i or j, that is not part of a word formed from
  several alphabetic characters.  If no such character exists, x is
  used.  If the character is not unique, the one closest to x is
  used.  If two characters are found, the one later in the alphabet is
  chosen.

seem bad to me.  Perhaps I'm a bit slow today, but what is the
intended meaning of "if the character is not unique", and why is it
"closest to x" in one case and "later in the alphabet" in the other?

| This brings up the question of how does the function print_raw look like
| for the case of "@ (ARG_LIST) EXPR"..

Do you mean what should the printed representation of an anonymous
function handle be?  I think it should just print

  <anonymous function handle>

or similar.

| Also what happens in the case
| 
| octave:1> function y = f (x), y = 1+x; endfunction
| octave:2> g = @(f) "1+f"
| 
| Is the function handle an inlined function with a variable "f" or is
| it a function handle to the function f?

If you mean

  function y = f (x) y = 1+x; endfunction
  g = @ (f) 1+f

then I think f is an argument to the function.  It would be the same
as if you had done

  function y = f (x) y = 1+x; endfunction
  function z = h (f) z = 1+f; endfunction
  g = @h

jwe



reply via email to

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