dummy argument to return



proposal: change of mreturn


(defmfun mreturn (&optional (x nil))
  (if (and (not mprogp) (not mdop))
      (merror "`return' not in `block':~%~M" x))
  (throw 'mprog (if x (ncons x) (ncons '$done))))


(%i7) do( return() );
(%o7)                                done
(%i8) do( return(0) );
(%o8)                                 0


Are there conflicts with other parts of the code?

Volker van Nek


Am 10 Nov 2007 um 16:23 hat van Nek geschrieben:

> Sometimes it nerves me to introduce a dummy argument to return from a loop.
> 
> e.g.
> 
> (%i1) (i:1, do ( i:i+1, if i=21 then return('dummy_argument) ), 2*i);
> (%o1)                                 42
> 
> I do not use the return value here. I'd rather would like to write 
> 
> (i:1, do ( i:i+1, if i=21 then return() ), 2*i);
> 
> I would like to see that return() is allowed. In that case do should return done as well or false 
> according to an empty argument.
> 
> Comments?
> 
> Where is this mechanism defined? Tracing didn't help me very much. I guess there happens 
> a caught throw.
> 
> Volker van Nek
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima