changelog shortlog tags changeset files revisions annotate raw

scripts/general/deal.m

changeset 10289: 4b124317dc38
parent:93c65f2a5668
author: John W. Eaton <jwe@octave.org>
date: Tue Feb 09 20:58:55 2010 -0500 (60 minutes ago)
permissions: -rw-r--r--
description: base_properties::set_children: account for hidden children
1## Copyright (C) 1998, 2004, 2005, 2006, 2007 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 3 of the License, or (at
8## your option) 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, see
17## <http://www.gnu.org/licenses/>.
18
19## -*- texinfo -*-
20## @deftypefn {Function File} {[@var{r1}, @var{r2}, @dots{}, @var{rn}] =} deal (@var{a})
21## @deftypefnx {Function File} {[@var{r1}, @var{r2}, @dots{}, @var{rn}] =} deal (@var{a1}, @var{a2}, @dots{}, @var{an})
22##
23## Copy the input parameters into the corresponding output parameters.
24## If only one input parameter is supplied, its value is copied to each
25## of the outputs.
26##
27## For example,
28##
29## @example
30## [a, b, c] = deal (x, y, z);
31## @end example
32##
33## @noindent
34## is equivalent to
35##
36## @example
37## @group
38## a = x;
39## b = y;
40## c = z;
41## @end group
42## @end example
43##
44## @noindent
45## and
46##
47## @example
48## [a, b, c] = deal (x);
49## @end example
50##
51## @noindent
52## is equivalent to
53##
54## @example
55## a = b = c = x;
56## @end example
57## @end deftypefn
58
59## Author: Ariel Tankus
60## Author: Paul Kienzle and Etienne Grossman
61## Created: 13.11.98
62## Adapted-by: jwe
63
64function [varargout] = deal (varargin)
65
66 if (nargin == 0)
67 print_usage ();
68 elseif (nargin == 1 || nargin == nargout)
69 varargout(1:nargout) = varargin;
70 else
71 error ("deal: nargin > 1 and nargin != nargout");
72 endif
73
74endfunction
75
76%!test
77%! [a,b]=deal(1,2);
78%! assert(a,1);
79%! assert(b,2);
80%!test
81%! [a,b]=deal(1);
82%! assert(a,1);
83%! assert(b,1);