<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <font face="Courier New"><br>
      Stéphane,<br>
      <br>
      Thanks for the explanation.<br>
      <br>
      I find it </font><font face="Courier New">already </font><font
      face="Courier New">dangerous that a function be aware of the
      calling level variables of equal name. But allowing so even for
      input arguments is too much. I agree with you.<br>
      <br>
      Generally, variables inside a function are bound or dummy
      variables. Any other variable or parameter to be collected from
      the context should be passed through the arguments. This is much
      safer and better programming style, I think, since everybody is
      aware of the </font><font face="Courier New"> previously assigned
    </font><font face="Courier New">variables </font><font
      face="Courier New">required </font><font face="Courier New">to be
      to be able to apply the function.  <br>
      <br>
      I guess a macro designed for general use will never ever exploit
      this feature...<br>
      <br>
      Regards,<br>
      <br>
      Federico <br>
      <br>
    </font><br>
    <div class="moz-cite-prefix">On 07/02/2020 05:14, Stéphane Mottelet
      wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:eaa3630e-08ef-d57b-bcf0-0ab2f9740fcc@utc.fr">
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <p>Here is the explanation : when you write a macro prototype,
        e.g. like this one</p>
      <p>function foo(x)</p>
      <p>endfunction</p>
      <p>when you call it with too many arguments, then the error always
        triggered by the parser. <br>
      </p>
      <p>When you call the function with not enough arguments, then the
        variable scope takes precedence. For example the following is
        legal:</p>
      <p>x=1<br>
        foo()</p>
      <p>i.e. even when not enough input arguments, then the call may be
        OK, but hopefully argn(2) will have the correct value, i.e. 0
        above. That is the reason why the parser always allow the call
        when there is not enough arguments, leaving the body of the
        macro do the verification, if necessary.<br>
      </p>
      <p>To me this kind of scoping is always source of error and side
        effects. Accessing the calling context variable by value is OK,
        but that formal arguments may be asssigned like this id very
        prone to errors, at least for beginners.</p>
      <p>S.<br>
      </p>
      <div class="moz-cite-prefix">Le 07/02/2020 à 06:09, Federico
        Miyara a écrit :<br>
      </div>
      <blockquote type="cite"
        cite="mid:bb5b1dc2-4093-6e4b-9d2a-fe4ba6661405@fceia.unr.edu.ar">
        <meta http-equiv="Content-Type" content="text/html;
          charset=UTF-8">
        <br>
        <font face="Courier New">Samuel,<br>
          <br>
          Thanks for clarifying. I have still a doubt regardihng the
          hard coding. Functions such as cos and abs, which are <br>
        </font>primitives, do declare an excess of arguments:<br>
        <br>
        --> cos(6,7)<br>
        <br>
        cos: Wrong number of input argument(s): 1 expected.<br>
        <br>
        Is the behavior different for primitives or they have a way of
        bypassing the hard-coded detection?<br>
        <br>
        Regards,<br>
        <br>
        Federico Miyara<br>
         <br>
        <br>
        <div class="moz-cite-prefix">On 06/02/2020 18:35, Samuel Gougeon
          wrote:<br>
        </div>
        <blockquote type="cite"
          cite="mid:8e6bac18-ca57-a1a9-e018-c7c16d0d9a30@free.fr">
          <meta http-equiv="Content-Type" content="text/html;
            charset=UTF-8">
          <div class="moz-cite-prefix">Hello Federico,</div>
          <div class="moz-cite-prefix"><br>
          </div>
          <div class="moz-cite-prefix">Le 06/02/2020 à 22:04, Federico
            Miyara a écrit :<br>
          </div>
          <blockquote type="cite"
            cite="mid:14dffcee-2416-90f8-9d75-8184ededd60b@fceia.unr.edu.ar">
            <meta http-equiv="content-type" content="text/html;
              charset=UTF-8">
            <br>
            <font face="Courier New">Dear All,<br>
              <br>
              I'm trying to cast an error message for a function<br>
              <br>
              The test and message are<br>
              <br>
            </font><font face="Courier New">if argn(2)<>1<br>
                 t1 = "%s: Wrong number of input arguments: %d
              expected.\n"</font><br>
            <font face="Courier New">   t2 = "Si" </font><br>
            <font face="Courier New">  
              error(msprintf(gettext(t1),t2,1));<br>
              end<br>
            </font></blockquote>
          <p><br>
          </p>
          <p>Please pay attention to avoid separating the gettext() call
            from its first literal argument. The reason is described
            with details in the gettext() page. So, to abstract,
            writting both the following is not fully equivalent:</p>
          <p><font face="Courier New"><font face="Courier New">t1 = "%s:
                Wrong number of input arguments: %d expected.\n"<br>
              </font>gettext(t1)</font><br>
            <br>
            and<br>
            <font face="Courier New"><br>
              gettext(</font><font face="Courier New"><font
                face="Courier New"><font face="Courier New">"%s: Wrong
                  number of input arguments: %d expected.\n"</font></font>)</font></p>
          <p><br>
            Here, this separation has no consequence, because you are
            using a standard message that already has a translation in
            Scilab. But for custom messages as in a toolbox, gettext()
            could here fail finding the translation.<br>
          </p>
          <blockquote type="cite"
            cite="mid:14dffcee-2416-90f8-9d75-8184ededd60b@fceia.unr.edu.ar"><font
              face="Courier New"> <br>
              The function has only one argument, so if invoked with 0
              or more than one argument, the message should be the same.
              With 0 arguments I get:<br>
              <br>
              <br>
              --> y = Si()<br>
              <br>
                 0.<br>
              at line    26 of function Si ( D:\work_scilab\Si.sci line
              26 )<br>
              <br>
              Si: Wrong number of input arguments: 1 expected.<br>
            </font><font face="Courier New"><br>
              <br>
              This is the correct and expected message. However, with 2
              arguments I get<br>
              <br>
              <br>
              --> y = Si(1,2)<br>
              <br>
              Wrong number of input arguments.<br>
              <br>
              <br>
              This error seems to have been trapped before my test, </font></blockquote>
          <p><br>
          </p>
          <p>Yes, this is the case. This is a general features for all
            macros. The detection of a number of input arguments greater
            than the max acceptable by the macro is hard-coded, and
            stops the execution BEFORE "really" calling and entering the
            macro. This is the very first step that must be passed.
            Afterward, things actually "occur" in the macro<font
              face="Courier New">.<br>
            </font><br>
          </p>
          <blockquote type="cite"
            cite="mid:14dffcee-2416-90f8-9d75-8184ededd60b@fceia.unr.edu.ar"><font
              face="Courier New">the execution is halted and my message
              doesn't show. I've also tested the function wavwrite,
              which requires 2 or 3 arguments. With 0 or 1 the message
              is the expected one, but with 4 or more arguments, I get
              the same result as in my example.<br>
              <br>
              Seems as if less arguments are handled by the custom error
              handler, but more than required is handled by sort of a
              parser.  <br>
              <br>
              I think this behavior contradicts the facility of
              customizing error messages.<br>
            </font></blockquote>
          <p>Not really. Only this one, related to an excessive number
            of inputs. Since the number of possible distinct errors is
            infinite, it's cool. Our freedom to customize all other
            messages is also infinite :-))<br>
          </p>
          <br>
          Regards<br>
          Samuel<br>
          <br>
          <br>
          <fieldset class="mimeAttachmentHeader"></fieldset>
          <pre class="moz-quote-pre" wrap="">_______________________________________________
users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:users@lists.scilab.org" moz-do-not-send="true">users@lists.scilab.org</a>
<a class="moz-txt-link-freetext" href="https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users" moz-do-not-send="true">http://lists.scilab.org/mailman/listinfo/users</a>
</pre>
        </blockquote>
        <br>
        <br>
        <fieldset class="mimeAttachmentHeader"></fieldset>
        <pre class="moz-quote-pre" wrap="">_______________________________________________
users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:users@lists.scilab.org" moz-do-not-send="true">users@lists.scilab.org</a>
<a class="moz-txt-link-freetext" href="https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users" moz-do-not-send="true">https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users</a>
</pre>
      </blockquote>
      <pre class="moz-signature" cols="72">-- 
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
<a class="moz-txt-link-freetext" href="http://www.utc.fr/~mottelet" moz-do-not-send="true">http://www.utc.fr/~mottelet</a>
</pre>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <pre class="moz-quote-pre" wrap="">_______________________________________________
users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:users@lists.scilab.org">users@lists.scilab.org</a>
<a class="moz-txt-link-freetext" href="http://lists.scilab.org/mailman/listinfo/users">http://lists.scilab.org/mailman/listinfo/users</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>