1 <?xml version="1.0" encoding="UTF-8"?>
3 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
4 * Copyright (C) ????-2008 - INRIA
5 * Copyright (C) 2018 - Samuel GOUGEON
7 * Copyright (C) 2012 - 2016 - Scilab Enterprises
9 * This file is hereby licensed under the terms of the GNU GPL v2.0,
10 * pursuant to article 5.3.4 of the CeCILL v.2.1.
11 * This file was originally licensed under the terms of the CeCILL v2.1,
12 * and continues to be available under such terms.
13 * For more information, see the COPYING file which you should have received
14 * along with this program.
17 <refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
18 xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML"
19 xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org"
20 xml:lang="fr" xml:id="argn">
22 <refname>argn</refname>
23 <refpurpose>nombre effectif d'arguments d'entrée reçus / attendus en sortie d'une fonction</refpurpose>
26 <title>Séquence d'appel</title>
33 <refsection role="arguments">
34 <title>Arguments</title>
40 Nombre d'arguments de sortie attendus. Vaut 1 (au lieu de 0) si la fonction
41 a été appelée sans argument de sortie.
49 Nombre d'arguments passés en entrée de la fonction Scilab considérée.
56 <title>Description</title>
58 Cette fonction est utilisée à l'intérieur d'une définition de fonction.
59 Elle donne le nombre effectif (au moment de l'appel) d'arguments d'entrée <varname>rhs</varname>
60 et de sortie <varname>lhs</varname>. Elle permet d'utiliser des arguments optionnels.
63 L'existence d'un argument d'entrée nommé (hors de la portée d'un éventuel varargin)
64 peut être testée avec <literal>isdef(..,"l")</literal> de manière plus robuste
65 qu'en utilisant <literal>argn()</literal>. Un exemple figure ci-après.
69 <title>Exemples</title>
70 <para>Exemples élémentaires :</para>
71 <programlisting role="example"><![CDATA[
72 function [res, res2] = test(a, b)
74 [res, res2] = ("abc", %pi);
75 disp([lhs rhs]) // <<<<<<<<<<<
98 Wrong number of input arguments.
100 --> test(3, -1, c=8);
101 Wrong number of input arguments.
106 --> [o1, o2] = test(%pi);
110 <para>Avec varargin ou/et varargout:</para>
111 <programlisting role="example"><![CDATA[
112 function [res, varargout] = test(a, varargin)
114 varargout = list(%i);
116 disp([lhs rhs]) // <<<<<<<<<<<
126 [o1, o2] = test(%pi);
127 [o1, o2, o3] = test(%pi);
139 --> test(3, -1, a=0);
148 --> [o1, o2] = test(%pi);
151 --> [o1, o2, o3] = test(%pi);
155 <para>Test robuste de l'existence d'un argument d'entrée:</para>
156 <programlisting role="example"><![CDATA[
157 function res = test(a, b, varargin)
163 res = res + " b passed."
166 res = res + " c passed."
203 --> test(-1, a=2, c=3) // Les arguments passés via varargin sont toujours anonymes
207 --> test(b=-1, a=2, c=3)
212 <para>Autre usage fréquent:</para>
213 <programlisting role="example"><![CDATA[
214 function concat = maFonction(nom,option)
217 option = "mon argument optionnel";
220 error("Au moins un argument attendu");
222 concat = nom+" "+option;
226 <refsection role="see also">
227 <title>Voir aussi</title>
228 <simplelist type="inline">
230 <link linkend="isdef">isdef</link>
233 <link linkend="varargin">varargin</link>
236 <link linkend="varargout">varargout</link>
239 <link linkend="macrovar">macrovar</link>
242 <link linkend="function">function</link>