diff src/ov-fcn-handle.cc @ 7767:71f068b22fcc

scope and context fixes for function handles
author John W. Eaton <jwe@octave.org>
date Wed, 07 May 2008 13:45:30 -0400
parents 5adeea5de26c
children 3e4c9b69069d
line wrap: on
line diff
--- a/src/ov-fcn-handle.cc	Tue May 06 13:39:55 2008 -0400
+++ b/src/ov-fcn-handle.cc	Wed May 07 13:45:30 2008 -0400
@@ -242,7 +242,7 @@
       octave_user_function *f = fcn.user_function_value ();
 
       std::list<symbol_table::symbol_record> vars
-	= symbol_table::all_variables (f->scope ());
+	= symbol_table::all_variables (f->scope (), 0);
 
       size_t varlen = vars.size ();
 
@@ -410,7 +410,7 @@
       octave_user_function *f = fcn.user_function_value ();
 
       std::list<symbol_table::symbol_record> vars
-	= symbol_table::all_variables (f->scope ());
+	= symbol_table::all_variables (f->scope (), 0);
 
       size_t varlen = vars.size ();
 
@@ -654,7 +654,7 @@
       octave_user_function *f = fcn.user_function_value ();
 
       std::list<symbol_table::symbol_record> vars
-	= symbol_table::all_variables (f->scope ());
+	= symbol_table::all_variables (f->scope (), 0);
 
       size_t varlen = vars.size ();
 
@@ -1276,41 +1276,36 @@
 
 	      std::string nm = fcn->fcn_file_name ();
 
-	      if (nm.empty ())
+	      if (fh_nm == "@<anonymous>")
 		{
-		  if (fh_nm == "@<anonymous>")
-		    {
-		      m.assign ("file", "");
+		  m.assign ("file", nm);
+
+		  octave_user_function *fu = fh->user_function_value ();
 
-		      octave_user_function *fu = fh->user_function_value ();
+		  std::list<symbol_table::symbol_record> vars
+		    = symbol_table::all_variables (fu->scope (), 0);
+
+		  size_t varlen = vars.size ();
 
-		      std::list<symbol_table::symbol_record> vars
-			= symbol_table::all_variables (fu->scope ());
-
-		      size_t varlen = vars.size ();
-
-		      if (varlen > 0)
+		  if (varlen > 0)
+		    {
+		      Octave_map ws;
+		      for (std::list<symbol_table::symbol_record>::const_iterator p = vars.begin ();
+			   p != vars.end (); p++)
 			{
-			  Octave_map ws;
-			  for (std::list<symbol_table::symbol_record>::const_iterator p = vars.begin ();
-			       p != vars.end (); p++)
-			    {
-			      ws.assign (p->name (), p->varval ());
-			    }
-
-			  m.assign ("workspace", ws);
+			  ws.assign (p->name (), p->varval (0));
 			}
+
+		      m.assign ("workspace", ws);
 		    }
-		  else if (fcn->is_user_function () || fcn->is_user_script ())
-		    {
-		      octave_function *fu = fh->function_value ();
-		      m.assign ("file", fu->fcn_file_name ());
-		    }
-		  else
-		    m.assign ("file", "");
+		}
+	      else if (fcn->is_user_function () || fcn->is_user_script ())
+		{
+		  octave_function *fu = fh->function_value ();
+		  m.assign ("file", fu->fcn_file_name ());
 		}
 	      else
-		m.assign ("file", nm);
+		m.assign ("file", "");
 
 	      retval = m;
 	    }
@@ -1387,6 +1382,21 @@
 }
 
 /*
+%!function y = testrecursionfunc (f, x, n)
+%!  if (nargin < 3)
+%!    n = 0;
+%!  endif
+%!  if (n > 2)
+%!    y = f (x);
+%!  else
+%!    n++;
+%!    y = testrecursionfunc (@(x) f(2*x), x, n);
+%!  endif
+%!test
+%! assert (testrecursionfunc (@(x) x, 1), 8);
+*/
+
+/*
 ;;; Local Variables: ***
 ;;; mode: C++ ***
 ;;; End: ***