Mercurial > octave-nkf
annotate scripts/general/deal.m @ 20654:b65888ec820e draft default tip gccjit
dmalcom gcc jit import
author | Stefan Mahr <dac922@gmx.de> |
---|---|
date | Fri, 27 Feb 2015 16:59:36 +0100 |
parents | 7503499a252b |
children |
rev | line source |
---|---|
19731
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19186
diff
changeset
|
1 ## Copyright (C) 1998-2015 Ariel Tankus |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2 ## |
4818 | 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 | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
4818 | 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 | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
4818 | 18 |
19 ## -*- texinfo -*- | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
20 ## @deftypefn {Function File} {[@var{r1}, @var{r2}, @dots{}, @var{rn}] =} deal (@var{a}) |
6714 | 21 ## @deftypefnx {Function File} {[@var{r1}, @var{r2}, @dots{}, @var{rn}] =} deal (@var{a1}, @var{a2}, @dots{}, @var{an}) |
4818 | 22 ## |
23 ## Copy the input parameters into the corresponding output parameters. | |
20193
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
24 ## |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
25 ## If only a single input parameter is supplied, its value is copied to each |
4818 | 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 | |
19101
4fd271cd9b37
deal.m: Document using interpreter, rather than deal, for comma separated lists.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
58 ## |
4fd271cd9b37
deal.m: Document using interpreter, rather than deal, for comma separated lists.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
59 ## 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
|
60 ## 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
|
61 ## interpreter can perform the same action without the overhead of a function |
19186
0f9c5a15c8fa
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
19101
diff
changeset
|
62 ## call. For example: |
19101
4fd271cd9b37
deal.m: Document using interpreter, rather than deal, for comma separated lists.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
63 ## |
4fd271cd9b37
deal.m: Document using interpreter, rather than deal, for comma separated lists.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
64 ## @example |
4fd271cd9b37
deal.m: Document using interpreter, rather than deal, for comma separated lists.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
65 ## @group |
4fd271cd9b37
deal.m: Document using interpreter, rather than deal, for comma separated lists.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
66 ## c = @{[1 2], "Three", 4@}; |
4fd271cd9b37
deal.m: Document using interpreter, rather than deal, for comma separated lists.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
67 ## [x, y, z ] = c@{:@} |
4fd271cd9b37
deal.m: Document using interpreter, rather than deal, for comma separated lists.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
68 ## @result{} |
4fd271cd9b37
deal.m: Document using interpreter, rather than deal, for comma separated lists.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
69 ## x = |
19186
0f9c5a15c8fa
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
19101
diff
changeset
|
70 ## |
19101
4fd271cd9b37
deal.m: Document using interpreter, rather than deal, for comma separated lists.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
71 ## 1 2 |
19186
0f9c5a15c8fa
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
19101
diff
changeset
|
72 ## |
19101
4fd271cd9b37
deal.m: Document using interpreter, rather than deal, for comma separated lists.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
73 ## y = Three |
4fd271cd9b37
deal.m: Document using interpreter, rather than deal, for comma separated lists.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
74 ## z = 4 |
4fd271cd9b37
deal.m: Document using interpreter, rather than deal, for comma separated lists.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
75 ## @end group |
4fd271cd9b37
deal.m: Document using interpreter, rather than deal, for comma separated lists.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
76 ## @end example |
4fd271cd9b37
deal.m: Document using interpreter, rather than deal, for comma separated lists.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
77 ## @seealso{cell2struct, struct2cell, repmat} |
4818 | 78 ## @end deftypefn |
79 | |
80 ## Author: Ariel Tankus | |
81 ## Author: Paul Kienzle and Etienne Grossman | |
82 ## Created: 13.11.98 | |
83 ## Adapted-by: jwe | |
84 | |
85 function [varargout] = deal (varargin) | |
86 | |
87 if (nargin == 0) | |
6046 | 88 print_usage (); |
4819 | 89 elseif (nargin == 1 || nargin == nargout) |
4820 | 90 varargout(1:nargout) = varargin; |
4818 | 91 else |
92 error ("deal: nargin > 1 and nargin != nargout"); | |
93 endif | |
94 | |
95 endfunction | |
4819 | 96 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
97 |
4819 | 98 %!test |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
99 %! [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
|
100 %! assert (a, 1); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
101 %! assert (b, 2); |
4819 | 102 %!test |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
103 %! [a,b] = deal (1); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
104 %! assert (a, 1); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
105 %! assert (b, 1); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
106 |
19101
4fd271cd9b37
deal.m: Document using interpreter, rather than deal, for comma separated lists.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
107 %!error deal () |
4fd271cd9b37
deal.m: Document using interpreter, rather than deal, for comma separated lists.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
108 %!error <nargin . 1 and nargin != nargout> y = deal (1, 2) |
4fd271cd9b37
deal.m: Document using interpreter, rather than deal, for comma separated lists.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
109 |