octave-maintainers
[Top][All Lists]
Advanced

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

Re: Crash with inline


From: John W. Eaton
Subject: Re: Crash with inline
Date: Thu, 16 Sep 2004 23:00:38 -0400

On 16-Sep-2004, David Bateman <address@hidden> wrote:

| > Also, I'm wondering about the difference between inline functions and user
| > defined functions defined on the command line with the function keyword.
| 
| An inline function deosn't appear in the fbi_sym_tab. Apart from that 
| not much different. A function handle however has a subtle difference,
| for example
| 
| octave:1> fcn = @not
| octave:2> function y = not (x), y = x; endfunction
| octave:3> fcn(1), not(1)
| ans = 0
| ans = 1
| 
| This happens due to the fact that the function handle saves the 
| octave_function in the original symbol table before it was replaced..
| However, this is not true for inline functions, for example
| 
| octave:1> fcn = inline('not(x)')
| fcn =
| 
| f(x) = not(x)
| 
| octave:2> not = inline('x')
| not =
| 
| f(x) = x
| 
| octave:3> fcn(1), not(1)
| ans = 0
| ans = 0
| 
| Err, in fact this seems to be a compatiability problem with matlab,
| as it seems matlab save a copy of the current symbol table for inline
| functions, since in matlab the above example gives 
| 
| >> fcn = inline('not(x)')
| 
| fcn =
| 
|      Inline function:
|      fcn(x) = not(x)
| 
| >> not = inline('x')
| 
| not =
| 
|      Inline function:
|      not(x) = x
| 
| >> fcn(1), not(1)
| 
| ans =
| 
|      0
| 
| 
| ans =
| 
|      1

Please try the following patch.

I've checked this in, but unfortunately, the anonymous CVS archive is
down at the moment and probably won't be back until sometime tomorrow
(after around 9AM USA central time).

jwe


src/ChangeLog:

2004-09-16  John W. Eaton  <address@hidden>

        * parse.y (frob_function): Clear id_name from curr_sym_tab, not
        top_level_sym_tab.

 
Index: src/parse.y
===================================================================
RCS file: /usr/local/cvsroot/octave/src/parse.y,v
retrieving revision 1.222
diff -u -r1.222 parse.y
--- a/src/parse.y       6 Sep 2004 20:19:57 -0000       1.222
+++ b/src/parse.y       17 Sep 2004 02:51:23 -0000
@@ -2715,7 +2715,21 @@
 
   fcn->stash_function_name (id_name);
 
-  top_level_sym_tab->clear (id_name);
+  // Enter the new function in fbi_sym_tab.  If there is already a
+  // variable of the same name in the current symbol table, we won't
+  // find the new function when we try to call it, so we need to clear
+  // the old symbol from the current symbol table.  Note that this
+  // means that for things like
+  //
+  //   function f () eval ("function g () 1, end"); end
+  //   g = 13;
+  //   f ();
+  //   g
+  //
+  // G will still refer to the variable G (with value 13) rather
+  // than the function G, until the variable G is cleared.
+
+  curr_sym_tab->clear (id_name);
 
   symbol_record *sr = fbi_sym_tab->lookup (id_name, true);
 



reply via email to

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