<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">Izabela,<br>
      <br>
      I have not clearly understood why you are speaking about "nested
      functions" in your example.<br>
      A nested function is a function that is <i>defined</i>  in
      another one.<br>
      <br>
      About the example in the function help page:<br>
      It is right, but with Scilab 6, it looks a bit outdated to me.<br>
      Indeed, let's consider the following example:<br>
      <br>
      <font size="-1"><tt>// Content of the File myTest.sci</tt><tt><br>
        </tt><tt>function myTest()</tt><tt><br>
        </tt><tt>   disp("myTest() is running")</tt><tt><br>
        </tt><tt>   myNextFun()</tt><tt><br>
        </tt><tt>endfunction</tt><tt><br>
        </tt><tt>function myNextFun()</tt><tt><br>
        </tt><tt>    disp("myNextFun() is running")</tt><tt><br>
        </tt><tt>endfunction</tt><tt><br>
        </tt><tt>// End of myTest.sci file</tt><tt><br>
        </tt></font><br>
      When building a library (say "myLib"), this file is compiled, and<br>
      <ul>
        <li>With Scilab 5 : both functions myTest() and myNextFun() are
          registered in the library, and so <b>are public</b>: Both can
          be called from anywhere, noticeably from the top-level, the
          console.<br>
          The only way to make <font size="-1"><tt>myNextFun()</tt></font>
          a private function known only by myTest() is to define it IN
          myTest(), as a nested function.<font size="-1"><tt><br>
              <br>
            </tt></font></li>
        <li>With Scilab 6: only myTest() is registered in myLib library,
          so is public, and can be called from anywhere. In the
          opposite, <font size="-1"><tt>myNextFun()</tt></font></li>
        <ul>
          <li>is NOT registered in the library</li>
          <li>so, is unknown from the console,</li>
          <li>is shared and can be called only by other functions
            defined in the same file.<br>
            <br>
            This is a more powerful implementation for the functions
            privacy, because then <br>
          </li>
          <li>a private function (say myNextFun()) does no longer need
            to be recompiled each time that myTest() is called.</li>
          <li>IMO, this makes the code clearer<br>
          </li>
        </ul>
      </ul>
      This change in Scilab 6 could be documented in the --> help
      function page, in order to discourage true nested function. By the
      way, the example in the help misses being indented.<br>
      <br>
      However, out of libraries, nested functions can still be used in
      scripts.sce or in files.sci that are just exec()uted, for the same
      purpose: keeping nested functions private.<br>
      <br>
      HTH<br>
      Regards<br>
      Samuel<br>
      <br>
      Le 10/04/2019 à 16:04, Izabela Wójcik-Grząba a écrit :<br>
    </div>
    <blockquote cite="mid:afa5ae0ecfb456677cf149533abbaa83@il.pw.edu.pl"
      type="cite">Ok, so why nested function in help is so complicated:
      <br>
      <br>
      //nested functions definition
      <br>
      function y=foo(x)
      <br>
         a=sin(x)
      <br>
         function y=sq(x), y=x^2,endfunction
      <br>
         y=sq(a)+1
      <br>
      endfunction
      <br>
      <br>
      foo(%pi/3)
      <br>
      <br>
      Couldn't it be formulated like below:
      <br>
      <br>
      function y1=foo1(x)
      <br>
         a=sin(x);
      <br>
         y1=a^2+1;
      <br>
      endfunction
      <br>
      <br>
      foo1(%pi/3)
      <br>
      <br>
      That's why I had problems with my functions and couldn't
      understand why it has to be so complicated.
      <br>
      <br>
      Thank you once more.
      <br>
      <br>
      Iza
    </blockquote>
    <br>
  </body>
</html>