Page 1 of 1

newLISP development release v.10.0.6

Posted: Wed May 20, 2009 6:30 pm
by Lutz
• minor feature enhancements
• bug fixes

for files and CHANGES notes see:

http://www.newlisp.org/downloads/development/

Posted: Wed May 20, 2009 10:01 pm
by Kazimir Majorinc
Excellent. Now my crawler tractor works without problems so we have that infinite evaluation without loop and without recursion. I think CL and Scheme have no equivalent, since their functions are not just lambda lists, but results of evaluation of lambda lists.

Thanx for fixing that. Is there any performance penalty?

I noticed similar problem here. It would be nice if that can be fixed as well.

Code: Select all

(set 'counter 0)
(set 'f '(begin (begin (if (= (% counter 10000) 0)
                           (println "Hi for the " counter ". time. "))
                       (inc counter)
                       (push (nth 1 f) f -1)
                       (if (>= (length f) 3) (pop f 0)))))

(eval f)
(exit)

Posted: Thu May 21, 2009 12:01 am
by Lutz
... so we have that infinite evaluation without loop and without recursion ...
Yes, your crawler tractor is a nice discovery and a fine example for self modifying code in newLISP.

There has been no measurable performance hit for this optimization in lambda expressions. But I don't want to do it for 'begin' where it would impact the speed of all iterating constructs where this optimization is already done on the looping level.

Posted: Thu May 21, 2009 1:30 am
by Jeff
What prevents adding this optimization for defined functions?

Posted: Thu May 21, 2009 2:22 am
by Lutz
Having it for lambda means its already done for defined functions too ;-).

(define (f ..) ...)
(set 'f (lambda (..) ...)
(set 'f (fn (..) ...)

its all the same.

Posted: Thu May 21, 2009 6:31 am
by chi
Kazimir Majorinc wrote:(...) I think CL and Scheme have no equivalent, since their functions are not just lambda lists, but results of evaluation of lambda lists. (...)
At least Scheme ought to have this feature. To be a Scheme, the system has to support two important features: call/cc and tail recursion optimization. For instance this

Code: Select all

(set! lop (lambda (n) (print "n: " n) (lop (+ n 1))))
(lop 1)
will run endlessly without growing stack space at around 960K. While this

Code: Select all

(set! lop! (lambda (n) (print "n: " n) (+ (lop (+ n 1)) 1)))
(lop! 1)
will slowly raise the stack space up to 1.9G while nearly killing my system :-)

But I do not know anything for CL about that ...

Ciao,
chi :-)

Posted: Thu May 21, 2009 6:41 am
by chi
Oops, perhaps I posted too fast! Suddenly I am not sure, if I interpreted the line in the release notes
lambda functions (not lambda-macro) now allow for large or infinite running bodies without stack impact
correctly!

My Scheme example will crash the newLISP interpreter due to stack size. So perhaps I did misunderstood the line above.

Could someone, please, clarify the meaning for me?

Thanks in advance and

ciao,
chi :-)

Posted: Thu May 21, 2009 8:36 am
by Kazimir Majorinc
chi, this is about function:

Code: Select all

(set 'f (lambda()
            (begin (println "Hi for the " (inc counter) ". time. ")
                   
                   (push (last f) f -1)
                   (if (> (length f) 3) (pop f 1)))))

(f)
This function modifies its code during evaluation, so it runs indefinitely although there is no loop or recursion. Until recently this function didn't released memory so at one point (800 000 "Hi" on my Newlisp) it crashed. Now Lutz fixed it. I wrote about it here and Alessandro wrote in his blog in Italian here. (Google translate for those of us who do not know Italian.)

I think it is not possible to do the same directly in Scheme or Cl, because their functions are not lists, but results of evaluation of lists so they cannot be modified "in fly". But maybe I'm wrong. Maybe it is possible using eval, I didn't tried.

Posted: Thu May 21, 2009 12:29 pm
by Jeff
Lutz wrote:Having it for lambda means its already done for defined functions too ;-).

(define (f ..) ...)
(set 'f (lambda (..) ...)
(set 'f (fn (..) ...)

its all the same.
That's what I was hoping, but the wording made me wonder.

Posted: Thu May 21, 2009 11:55 pm
by chi
Kazimir Majorinc wrote:chi, (...)
This function modifies its code during evaluation, so it runs indefinitely although there is no loop or recursion. (...) I wrote about it (...)
Hello Kazimir,

thank you very much for your explanation. Now I do understand! I think, you are right, that this is not normally possible via CL or Scheme. But OTOH both languages are not forced to compile theirs lambdas, so there may be some implementations, where this nice trick could be possible :-)

Unfortunately I did not stumble over said article of your block, as that would probably spared you the time to answer my question ...

I am at blog article #7 right now ... well done! :-D

Ciao,
chi :-)

Posted: Fri May 22, 2009 7:38 am
by newdep
Lutz,

Is it default that the $0–$15 are not cleared befor a function is called that uses these.. Like regex?

Im running into old content (previously returned regex data) inside $1...$15 when using regex multiple times..
(tested on Windows XP only)

Norman.

Posted: Fri May 22, 2009 11:34 am
by Lutz
Your code will always know how many subexpressions you have used in your pattern, if the regular expression fails, you know the sub expressions are invalid and old.

There is normally no need to clear these and it would take much performance doing this. If you must clear them for some reason, you can do it, system variables $0 thru $15 are the only once which are not protected.

Posted: Fri May 22, 2009 3:14 pm
by cormullion
newdep wrote:Is it default that the $0–$15 are not cleared befor a function is called that uses these.. Like regex?
Yes, that's standard behaviour... ! :)

http://www.alh.net/newlisp/phpbb/viewtopic.php?t=2427
http://www.alh.net/newlisp/phpbb/viewtopic.php?t=1948

Posted: Wed May 27, 2009 1:12 pm
by newdep
Aaah yeah look.. thanks! ;-)