annotate scripts/general/deal.m @ 30564:796f54d4ddbf stable

update Octave Project Developers copyright for the new year In files that have the "Octave Project Developers" copyright notice, update for 2021. In all .txi and .texi files except gpl.txi and gpl.texi in the doc/liboctave and doc/interpreter directories, change the copyright to "Octave Project Developers", the same as used for other source files. Update copyright notices for 2022 (not done since 2019). For gpl.txi and gpl.texi, change the copyright notice to be "Free Software Foundation, Inc." and leave the date at 2007 only because this file only contains the text of the GPL, not anything created by the Octave Project Developers. Add Paul Thomas to contributors.in.
author John W. Eaton <jwe@octave.org>
date Tue, 28 Dec 2021 18:22:40 -0500
parents 7854d5752dd2
children 597f3ee61a48
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ########################################################################
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 ##
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
3 ## Copyright (C) 1998-2022 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 27898
diff changeset
4 ##
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 ## See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 ## distribution or <https://octave.org/copyright/>.
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
7 ##
4818
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
8 ## This file is part of Octave.
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
9 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
4818
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
11 ## under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
12 ## the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22699
diff changeset
13 ## (at your option) any later version.
4818
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
14 ##
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22699
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22699
diff changeset
18 ## GNU General Public License for more details.
4818
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
19 ##
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
20 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6714
diff changeset
21 ## along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
22 ## <https://www.gnu.org/licenses/>.
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 ##
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ########################################################################
4818
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
25
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
26 ## -*- texinfo -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20158
diff changeset
27 ## @deftypefn {} {[@var{r1}, @var{r2}, @dots{}, @var{rn}] =} deal (@var{a})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20158
diff changeset
28 ## @deftypefnx {} {[@var{r1}, @var{r2}, @dots{}, @var{rn}] =} deal (@var{a1}, @var{a2}, @dots{}, @var{an})
4818
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
29 ##
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
30 ## Copy the input parameters into the corresponding output parameters.
20158
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
31 ##
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
32 ## If only a single input parameter is supplied, its value is copied to each
4818
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
33 ## of the outputs.
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
34 ##
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
35 ## For example,
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
36 ##
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
37 ## @example
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
38 ## [a, b, c] = deal (x, y, z);
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
39 ## @end example
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
40 ##
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
41 ## @noindent
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
42 ## is equivalent to
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
43 ##
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
44 ## @example
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
45 ## @group
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
46 ## a = x;
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
47 ## b = y;
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
48 ## c = z;
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
49 ## @end group
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
50 ## @end example
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
51 ##
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
52 ## @noindent
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
53 ## and
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
54 ##
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
55 ## @example
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
56 ## [a, b, c] = deal (x);
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
57 ## @end example
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
58 ##
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
59 ## @noindent
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
60 ## is equivalent to
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
61 ##
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
62 ## @example
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
63 ## a = b = c = x;
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
64 ## @end example
19067
4fd271cd9b37 deal.m: Document using interpreter, rather than deal, for comma separated lists.
Rik <rik@octave.org>
parents: 17744
diff changeset
65 ##
4fd271cd9b37 deal.m: Document using interpreter, rather than deal, for comma separated lists.
Rik <rik@octave.org>
parents: 17744
diff changeset
66 ## Programming Note: @code{deal} is often used with comma separated lists
4fd271cd9b37 deal.m: Document using interpreter, rather than deal, for comma separated lists.
Rik <rik@octave.org>
parents: 17744
diff changeset
67 ## derived from cell arrays or structures. This is unnecessary as the
4fd271cd9b37 deal.m: Document using interpreter, rather than deal, for comma separated lists.
Rik <rik@octave.org>
parents: 17744
diff changeset
68 ## interpreter can perform the same action without the overhead of a function
19152
0f9c5a15c8fa doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 19067
diff changeset
69 ## call. For example:
19067
4fd271cd9b37 deal.m: Document using interpreter, rather than deal, for comma separated lists.
Rik <rik@octave.org>
parents: 17744
diff changeset
70 ##
4fd271cd9b37 deal.m: Document using interpreter, rather than deal, for comma separated lists.
Rik <rik@octave.org>
parents: 17744
diff changeset
71 ## @example
4fd271cd9b37 deal.m: Document using interpreter, rather than deal, for comma separated lists.
Rik <rik@octave.org>
parents: 17744
diff changeset
72 ## @group
4fd271cd9b37 deal.m: Document using interpreter, rather than deal, for comma separated lists.
Rik <rik@octave.org>
parents: 17744
diff changeset
73 ## c = @{[1 2], "Three", 4@};
22699
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22323
diff changeset
74 ## [x, y, z] = c@{:@}
19067
4fd271cd9b37 deal.m: Document using interpreter, rather than deal, for comma separated lists.
Rik <rik@octave.org>
parents: 17744
diff changeset
75 ## @result{}
4fd271cd9b37 deal.m: Document using interpreter, rather than deal, for comma separated lists.
Rik <rik@octave.org>
parents: 17744
diff changeset
76 ## x =
19152
0f9c5a15c8fa doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 19067
diff changeset
77 ##
19067
4fd271cd9b37 deal.m: Document using interpreter, rather than deal, for comma separated lists.
Rik <rik@octave.org>
parents: 17744
diff changeset
78 ## 1 2
19152
0f9c5a15c8fa doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 19067
diff changeset
79 ##
19067
4fd271cd9b37 deal.m: Document using interpreter, rather than deal, for comma separated lists.
Rik <rik@octave.org>
parents: 17744
diff changeset
80 ## y = Three
4fd271cd9b37 deal.m: Document using interpreter, rather than deal, for comma separated lists.
Rik <rik@octave.org>
parents: 17744
diff changeset
81 ## z = 4
4fd271cd9b37 deal.m: Document using interpreter, rather than deal, for comma separated lists.
Rik <rik@octave.org>
parents: 17744
diff changeset
82 ## @end group
4fd271cd9b37 deal.m: Document using interpreter, rather than deal, for comma separated lists.
Rik <rik@octave.org>
parents: 17744
diff changeset
83 ## @end example
4fd271cd9b37 deal.m: Document using interpreter, rather than deal, for comma separated lists.
Rik <rik@octave.org>
parents: 17744
diff changeset
84 ## @seealso{cell2struct, struct2cell, repmat}
4818
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
85 ## @end deftypefn
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
86
28904
930cb0ae24fd maint: Don't enclose single output of function with '[]'.
Rik <rik@octave.org>
parents: 28896
diff changeset
87 function varargout = deal (varargin)
4818
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
88
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
89 if (nargin == 0)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5307
diff changeset
90 print_usage ();
4819
de3b34644549 [project @ 2004-03-05 04:57:07 by jwe]
jwe
parents: 4818
diff changeset
91 elseif (nargin == 1 || nargin == nargout)
4820
a436d388b041 [project @ 2004-03-05 05:58:37 by jwe]
jwe
parents: 4819
diff changeset
92 varargout(1:nargout) = varargin;
4818
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
93 else
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
94 error ("deal: nargin > 1 and nargin != nargout");
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
95 endif
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
96
ef6ae7349d59 [project @ 2004-03-04 22:10:45 by jwe]
jwe
parents:
diff changeset
97 endfunction
4819
de3b34644549 [project @ 2004-03-05 04:57:07 by jwe]
jwe
parents: 4818
diff changeset
98
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
99
4819
de3b34644549 [project @ 2004-03-05 04:57:07 by jwe]
jwe
parents: 4818
diff changeset
100 %!test
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
101 %! [a,b] = deal (1,2);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
102 %! assert (a, 1);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
103 %! assert (b, 2);
4819
de3b34644549 [project @ 2004-03-05 04:57:07 by jwe]
jwe
parents: 4818
diff changeset
104 %!test
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
105 %! [a,b] = deal (1);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
106 %! assert (a, 1);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
107 %! assert (b, 1);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
108
28896
90fea9cc9caa test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents: 27985
diff changeset
109 ## Test input validation
90fea9cc9caa test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents: 27985
diff changeset
110 %!error <Invalid call> deal ()
19067
4fd271cd9b37 deal.m: Document using interpreter, rather than deal, for comma separated lists.
Rik <rik@octave.org>
parents: 17744
diff changeset
111 %!error <nargin . 1 and nargin != nargout> y = deal (1, 2)