4818
|
1 ## Copyright (C) 1998 Ariel Tankus |
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by |
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License for more details. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
5307
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
4818
|
19 |
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Mapping Function} {[@var{r1}, @var{r2}, @dots{}, @var{rn}] =} deal (@var{a}) |
|
22 ## @deftypefnx {Mapping Function} {[@var{r1}, @var{r2}, @dots{}, @var{rn}] =} deal (@var{a1}, @var{a2}, @dots{}, @var{an}) |
|
23 ## |
|
24 ## Copy the input parameters into the corresponding output parameters. |
|
25 ## If only one input parameter is supplied, its value is copied to each |
|
26 ## of the outputs. |
|
27 ## |
|
28 ## For example, |
|
29 ## |
|
30 ## @example |
|
31 ## [a, b, c] = deal (x, y, z); |
|
32 ## @end example |
|
33 ## |
|
34 ## @noindent |
|
35 ## is equivalent to |
|
36 ## |
|
37 ## @example |
|
38 ## @group |
|
39 ## a = x; |
|
40 ## b = y; |
|
41 ## c = z; |
|
42 ## @end group |
|
43 ## @end example |
|
44 ## |
|
45 ## @noindent |
|
46 ## and |
|
47 ## |
|
48 ## @example |
|
49 ## [a, b, c] = deal (x); |
|
50 ## @end example |
|
51 ## |
|
52 ## @noindent |
|
53 ## is equivalent to |
|
54 ## |
|
55 ## @example |
|
56 ## a = b = c = x; |
|
57 ## @end example |
|
58 ## @end deftypefn |
|
59 |
|
60 ## Author: Ariel Tankus |
|
61 ## Author: Paul Kienzle and Etienne Grossman |
|
62 ## Created: 13.11.98 |
|
63 ## Adapted-by: jwe |
|
64 |
|
65 function [varargout] = deal (varargin) |
|
66 |
|
67 if (nargin == 0) |
|
68 usage ("[a, b, c, d] = deal (x, y, z, a)"); |
4819
|
69 elseif (nargin == 1 || nargin == nargout) |
4820
|
70 varargout(1:nargout) = varargin; |
4818
|
71 else |
|
72 error ("deal: nargin > 1 and nargin != nargout"); |
|
73 endif |
|
74 |
|
75 endfunction |
4819
|
76 |
|
77 %!test |
|
78 %! [a,b]=deal(1,2); |
|
79 %! assert(a,1); |
|
80 %! assert(b,2); |
|
81 %!test |
|
82 %! [a,b]=deal(1); |
|
83 %! assert(a,1); |
|
84 %! assert(b,1); |