Mercurial > forge
changeset 883:125a742f9169 octave-forge
Extend the deal function to handle [a,b]=deal(b,a)
No change to the incompatible [a,b]=deal([1,2]) behaviour.
author | pkienzle |
---|---|
date | Mon, 31 Mar 2003 20:28:10 +0000 |
parents | e624d86db651 |
children | 1eb91fa57b97 |
files | main/general/deal.m main/time/datestr.m |
diffstat | 2 files changed, 35 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/main/general/deal.m Sat Mar 29 13:26:08 2003 +0000 +++ b/main/general/deal.m Mon Mar 31 20:28:10 2003 +0000 @@ -18,23 +18,44 @@ ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ## -## deal Split the input vector into the corresponding number of output -## parameters. Possible usage: in functions where several input -## arguments can be gathered to a single argument. +## [...] = deal(...) ## -## [...] = deal(v) -## v - input vector. -## [x1, x2, ..., xn] - outputs, each contains a single element of -## the vector v. +## Copy the input parameters into the corresponding output parameters. +## E.g., [a,b,c]=deal(x,y,z) is equivalent to a=x; b=y; c=z; +## +## [...] = deal(v) ## +## Split the input vector into the corresponding output parameters. +## E.g., [a,b,c]=deal([1,2,3]) is equivalent to a=1; b=2; c=3; +## +## NOTE: this is not compatible behaviour. When converting code to +## run under octave, use a=b=c=X instead of [a,b,c] = deal(X). ## Author: Ariel Tankus. ## Created: 13.11.98. +## Almost completely replaced by Paul Kienzle and Etienne Grossman. ## pre 2.1.39 function [...] = deal(v) -function [varargout] = deal(v) ## pos 2.1.39 +function [varargout] = deal(varargin) ## pos 2.1.39 -for i=1:nargout - ## pre 2.1.39 vr_val(v(i)); - varargout{i} = v(i); ## pos 2.1.39 -end + if (nargin == 0) + usage("[a,b,c,d]=deal(x,y,z,a)"); + elseif (nargin == 1) + persistent warn = 1; + if warn + warning("[a,b,c]=deal(X) is not the same as a=b=c=X"); + warn = 0; + endif + v = varargin{1}; + for i=1:nargout + ## pre 2.1.39 vr_val(v(i)); + varargout{i} = v(i); ## pos 2.1.39 + end + elseif nargin == nargout; + ## pre 2.1.39 this needs a loop + varargout = varargin; ## pos 2.1.39 + else + error("deal should have one input for each output"); + endif + +endfunction
--- a/main/time/datestr.m Sat Mar 29 13:26:08 2003 +0000 +++ b/main/time/datestr.m Mon Mar 31 20:28:10 2003 +0000 @@ -108,7 +108,8 @@ "Jul";"Aug";"Sep";"Oct";"Nov";"Dec"]; global __time_names = ["AM";"PM"]; for i=1:rows(V) - [Y, M, D, h, m, s] = deal(V(i,:)); + Y=V(i,1); M=V(i,2); D=V(i,3); + h=V(i,4); m=V(i,5); s=V(i,6); Y2 = rem(Y,100); switch (code) case { 0, 'dd-mmm-yyyy HH:MM:SS' }