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 <code>0</code> si la fonction a été appelée sans argument de sortie.
48 Nombre d'arguments passés en entrée de la fonction Scilab considérée.
55 <title>Description</title>
57 Cette fonction est utilisée à l'intérieur d'une définition de fonction.
58 Elle donne le nombre effectif (au moment de l'appel) d'arguments d'entrée <varname>rhs</varname>
59 et de sortie <varname>lhs</varname>. Elle permet d'utiliser des arguments optionnels.
62 L'existence d'un argument d'entrée nommé (hors de la portée d'un éventuel varargin)
63 peut être testée avec <literal>isdef(..,"l")</literal> de manière plus robuste
64 qu'en utilisant <literal>argn()</literal>. Un exemple figure ci-après.
68 <title>Exemples</title>
69 <para>Exemples élémentaires :</para>
70 <programlisting role="example"><![CDATA[
71 function [res, res2] = test(a, b)
73 [res, res2] = ("abc", %pi);
74 disp([lhs rhs]) // <<<<<<<<<<<
87 <para>Avec varargin ou/et varargout:</para>
88 <programlisting role="example"><![CDATA[
89 function [varargout] = disp_argn(varargin)
90 varargout = list("abc",%i);
92 disp([lhs rhs]) // <<<<<<<<<<<
95 function [res, varargout] = disp_argn_with_args(a, varargin)
99 disp([lhs rhs]) // <<<<<<<<<<<
104 disp_argn_with_args(1);
106 disp_argn_with_args(1, 2);
108 disp_argn_with_args(1, 2, 3);
112 out1 = disp_argn_with_args();
113 [o1, o2] = disp_argn();
114 [o1, o2] = disp_argn_with_args();
115 [o1, o2, o3] = disp_argn();
116 [o1, o2, o3] = disp_argn_with_args();
119 <para>Test robuste de l'existence d'un argument d'entrée:</para>
120 <programlisting role="example"><![CDATA[
121 function res = test(a, b, varargin)
127 res = res + " b passed."
130 res = res + " c passed."
144 <para>Autre usage fréquent:</para>
145 <programlisting role="example"><![CDATA[
146 function concat = maFonction(nom,option)
149 option = "mon argument optionnel";
152 error("Au moins un argument attendu");
154 concat = nom+" "+option;
158 <refsection role="see also">
159 <title>Voir aussi</title>
160 <simplelist type="inline">
162 <link linkend="isdef">isdef</link>
165 <link linkend="varargin">varargin</link>
168 <link linkend="varargout">varargout</link>
171 <link linkend="macrovar">macrovar</link>
174 <link linkend="function">function</link>
179 <title>History</title>
180 <revhistory><revision><revnumber>6.1.0</revnumber><revremark>L'argument <code>lhs</code> est assigné à zero si appelé sans argument de sortie.</revremark></revision></revhistory>