* Bug 15380 fixed: argn() page was unclear & uncomplete
[scilab.git] / scilab / modules / functions / help / ja_JP / argn.xml
index 490f870..555a362 100644 (file)
 <?xml version="1.0" encoding="UTF-8"?>
-
-<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:lang="ja" xml:id="argn">
-
+<!--
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) ????-2008 - INRIA
+ * Copyright (C) 2018 - Samuel GOUGEON
+ *
+ * Copyright (C) 2012 - 2016 - Scilab Enterprises
+ *
+ * This file is hereby licensed under the terms of the GNU GPL v2.0,
+ * pursuant to article 5.3.4 of the CeCILL v.2.1.
+ * This file was originally licensed under the terms of the CeCILL v2.1,
+ * and continues to be available under such terms.
+ * For more information, see the COPYING file which you should have received
+ * along with this program.
+ *
+ -->
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
+        xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML"
+        xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org"
+        xml:lang="ja" xml:id="argn">
     <refnamediv>
-
         <refname>argn</refname>
-
         <refpurpose>関数コールの入力/出力引数の数を返す</refpurpose>
-
     </refnamediv>
-
     <refsynopsisdiv>
-
         <title>呼出し手順</title>
-
-        <synopsis>[lhs [,rhs] ]=argn()
-
-            lhs=argn(1)
-
-            rhs=argn(2)
-
+        <synopsis>
+           [lhs, rhs] = argn()
+            lhs = argn(1)
+            rhs = argn(2)
         </synopsis>
-
     </refsynopsisdiv>
-
+    <refsection role="arguments">
+        <title>設定</title>
+        <variablelist>
+            <varlistentry>
+                <term>lhs</term>
+                <listitem>
+                <para>Number of expected Left-Hand-Side output arguments. Is set to 1 when no output
+                argument is expected.
+                </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>rhs</term>
+                <listitem>
+                <para>Number of Right-Hand-Side input arguments provided in the function call.
+                </para>
+                </listitem>
+            </varlistentry>
+        </variablelist>
+    </refsection>
     <refsection>
-
         <title>説明</title>
-
         <para>
-
             この関数は関数定義の内部で使用されます.
-
             この関数は関数がコールされた際に関数に指定された実際の入力引数(<varname>lhs</varname>)と
-
             出力引数(<varname>lhs</varname>) の数を出力します.
-
             通常,関数の定義においてオプションの引数を処理する際に使用されます.
-
         </para>
+        <warning>
+            <varname>lhs</varname> は常に1以上であることに注意してください.
+            言い換えると,関数が出力引数なしにコールされた場合であっても,
+            <varname>lhs</varname> は 1 となります.
+        </warning>
+        <warning>
+            Testing the existence of a named input argument with <literal>isdef(..,"l")</literal>
+            is more robust that with <literal>argn()</literal>. Please see examples.
+        </warning>
+    </refsection>
+    <refsection>
+        <title>例</title>
+        <para>Simple examples:</para>
+        <programlisting role="example"><![CDATA[
+function [res, res2] = test(a, b)
+  [lhs, rhs] = argn()
+  [res, res2] = ("abc", %pi);
+  disp([lhs rhs])  // <<<<<<<<<<<
+endfunction
 
-        <para>
+test();
+test(4.321);
+test(3, -1);
+test(3, -1, a=0);
+test(3, -1, c=8);
 
-            <note>
+out1 = test();
+[o1, o2] = test(%pi);
+ ]]></programlisting>
+    <screen><![CDATA[
+--> test();
+   1.   0.
 
-                <varname>lhs</varname> は常に1以上であることに注意してください.
+--> test(4.321);
+   1.   1.
 
-                言い換えると,関数が出力引数なしにコールされた場合であっても,
+--> test(3, -1);
+   1.   2.
 
-                <varname>lhs</varname> は 1 となります.
+--> test(3, -1, a=0);
+Wrong number of input arguments.
 
-            </note>
+--> test(3, -1, c=8);
+Wrong number of input arguments.
 
-        </para>
+--> out1 = test();
+   1.   0.
 
-    </refsection>
+--> [o1, o2] = test(%pi);
+   2.   1.
+]]></screen>
+    <para/>
+    <para>With varargin and varargout:</para>
+        <programlisting role="example"><![CDATA[
+function [res, varargout] = test(a, varargin)
+  res = "abc";
+  varargout = list(%i);
+  [lhs, rhs] = argn()
+  disp([lhs rhs])  // <<<<<<<<<<<
+endfunction
 
-    <refsection>
+test();
+test(4.321);
+test(3, -1);
+test(3, -1, a=0);
+test(3, -1, 8);
 
-        <title>例</title>
+out1 = test();
+[o1, o2] = test(%pi);
+[o1, o2, o3] = test(%pi);
+ ]]></programlisting>
+    <screen><![CDATA[
+--> test();
+   1.   0.
+
+--> test(4.321);
+   1.   1.
+
+--> test(3, -1);
+   1.   2.
+
+--> test(3, -1, a=0);
+   1.   3.
 
+--> test(3, -1, 8);
+   1.   3.
+
+--> out1 = test();
+   1.   0.
+
+--> [o1, o2] = test(%pi);
+   2.   1.
+
+--> [o1, o2, o3] = test(%pi);
+   3.   1.
+]]></screen>
+    <para/>
+    <para>Robustly testing the existence of input arguments:</para>
+        <programlisting role="example"><![CDATA[
+function res = test(a, b, varargin)
+    res = ""
+    if isdef("a","l")
+        res = "a passed."
+    end
+    if isdef("b","l")
+        res = res + " b passed."
+    end
+    if isdef("c","l")
+        res = res + " c passed."
+    end
+endfunction
+clc
+test()
+test(4.321)
+test(4.321, %z)
+test(b=3)
+test(c=3)
+test(-1, c=3)
+test(-1, a=2, c=3)
+test(b=-1, a=2, c=3)
+ ]]></programlisting>
+    <screen><![CDATA[
+--> test()
+ ans  =
+
+--> test(4.321)
+ ans  =
+ a passed.
+
+--> test(4.321, %z)
+ ans  =
+ a passed. b passed.
+
+--> test(b=3)
+ ans  =
+  b passed.
+
+--> test(c=3)
+ ans  =
+  c passed.
+
+--> test(-1, c=3)
+ ans  =
+ a passed. c passed.
+
+--> test(-1, a=2, c=3) // argins in varargin are/become always anonymous
+ ans  =
+ a passed.
+
+--> test(b=-1, a=2, c=3)
+ ans  =
+ a passed. b passed.
+]]></screen>
+    <para/>
+    <para>Another usage:</para>
         <programlisting role="example"><![CDATA[
 function concat=myOwnFunction(name,optional)
-  [lhs,rhs]=argn(0)
+  [lhs,rhs] = argn()
   if rhs <= 1 then
-        optional="my Optional value"
+     optional="my Optional value"
   end
   if rhs == 0 then
-        error("Expect at least one argument")
+     error("Expect at least one argument")
   end
   concat=name+" "+optional
 endfunction
  ]]></programlisting>
-
     </refsection>
-
     <refsection role="see also">
-
         <title>参照</title>
-
         <simplelist type="inline">
-
             <member>
-
-                <link linkend="function">function</link>
-
+                <link linkend="isdef">isdef</link>
             </member>
-
             <member>
-
                 <link linkend="varargin">varargin</link>
-
             </member>
-
+            <member>
+                <link linkend="varargout">varargout</link>
+            </member>
+            <member>
+                <link linkend="macrovar">macrovar</link>
+            </member>
+            <member>
+                <link linkend="function">function</link>
+            </member>
         </simplelist>
-
     </refsection>
-
-</refentry>
-
+</refentry>
\ No newline at end of file