Hi, I was playing around with using tail recursion to do looping in
gnuplot. The result are pretty good, but I do run across the following:
gnuplot> tr(x, s) = (x < 1 ? s : tr(x-1, s+x))
gnuplot> looptr(a, b, cmd) = (b < a ? cmd : looptr(a+1, b,
gnuplot> sprintf("%s;\nprint 'a=%g ', tr(%g,0)", cmd, a, a)))
gnuplot> eval looptr(20135,20155,"")
a=20135 202719180
a=20136 202739316
a=20137 202759453
a=20138 202779591
a=20139 202799730
a=20140 202819870
a=20141 202840011
a=20142
Process gnuplot segmentation fault
That is pretty decent, given that the non tail-recursive function
t(x) = (x < 1 ? 0 : x+t(x-1))
gives a stack overflow error for t(99). However, it just seems like bad
form for gnuplot to segfault.
---------------------------------------------------------------------
G N U P L O T
Version 4.4 patchlevel 0
last modified March 2010
System: Linux 3.2.0-1-686-pae
--
Leo Butler l_b...@us...
SDF Public Access UNIX System - http://sdf.lonestar.org
|