Hmm, this looks good to me:

show functions
/*
 * rectest
 */
function rectest (level){

   print "level="+ level +" maxLevel=" + maxLevel + "\n";
   if (level < maxLevel) {
     print "recursing at level " + level+"\n";
     recTest(level + 1);
   } else {
     print "recursion finished at level " + level+"\n";
   }
}

recTest(1)


level=1 maxLevel=5

recursing at level 1

level=2 maxLevel=5

recursing at level 2

level=3 maxLevel=5

recursing at level 3

level=4 maxLevel=5

recursing at level 4

level=5 maxLevel=5

recursion finished at level 5

recursion finished at level 4

recursion finished at level 3

recursion finished at level 2

recursion finished at level 1


Bob


On Mon, May 11, 2015 at 10:55 AM, Rolf Huehne <rhue...@fli-leibniz.de>
wrote:

> Hi all,
>
> I tried to implement a recursive function in Jmol 14.3.13_2015.05.07 but
> got strange results. In the documentation I couldn't find anything about
> recursive user-defined functions.
>
> For comparison the same example is shown below in Jmol (strange results)
> and in Perl (expected results):
>
> ----- Jmol Example ------------------------
> function recTest(level, maxLevel) {
>    print "level=" + level + "  maxLevel=" + maxLevel;
>    if (level < maxLevel) {
>      recTest(level + 1, maxLevel);
>    } else {
>      print "recursion finished at level " + level;
>    }
> }
> recTest(1,3);
>
> level=1  maxLevel=3
> level=2  maxLevel=3
> level=3  maxLevel=3
> recursion finished at level 3
> recursion finished at level 2
> recursion finished at level 1
>
> ----- Perl Example ------------------------
> sub recTest {
>    my ($level, $maxLevel) = @_;
>    print "level=$level  maxLevel=$maxLevel\n";
>    if ($level < $maxLevel) {
>      recTest($level + 1, $maxLevel);
>    } else {
>      print "recursion finished at level $level\n";
>    }
> }
> recTest(1,3);
>
> level=1  maxLevel=3
> level=2  maxLevel=3
> level=3  maxLevel=3
> recursion finished at level 3
> -------------------------------------------
>
> Q: Is this a bug or is recursion generally not allowed?
>
> Regards,
> Rolf
> --
>
> Rolf Huehne
> Postdoc
>
> Leibniz Institute for Age Research - Fritz Lipmann Institute (FLI)
> Beutenbergstrasse 11
> 07745 Jena, Germany
>
> Phone:   +49 3641 65 6205
> Fax:     +49 3641 65 6210
> E-Mail:  rhue...@fli-leibniz.de
> Website: http://www.fli-leibniz.de
>
>            Scientific Director: Prof. Dr. K. Lenhard Rudolph
>         Head of Administration: Dr. Daniele Barthel
> Chairman of Board of Trustees: Dennys Klein
>
> VAT No: DE 153 925 464
> Register of Associations: No. 230296, Amtsgericht Jena
> Tax Number: 162/141/08228
>
>
>
> ------------------------------------------------------------------------------
> One dashboard for servers and applications across Physical-Virtual-Cloud
> Widest out-of-the-box monitoring support with 50+ applications
> Performance metrics, stats and reports that give you Actionable Insights
> Deep dive visibility with transaction tracing using APM Insight.
> http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
> _______________________________________________
> Jmol-users mailing list
> Jmol-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jmol-users
>



-- 
Robert M. Hanson
Larson-Anderson Professor of Chemistry
Chair, Department of Chemistry
St. Olaf College
Northfield, MN
http://www.stolaf.edu/people/hansonr


If nature does not answer first what we want,
it is better to take what answer we get.

-- Josiah Willard Gibbs, Lecture XXX, Monday, February 5, 1900
------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Jmol-users mailing list
Jmol-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-users

Reply via email to