newLISP development release v.10.0.6

Notices and updates
Locked
Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

newLISP development release v.10.0.6

Post by Lutz »

• minor feature enhancements
• bug fixes

for files and CHANGES notes see:

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

Kazimir Majorinc
Posts: 388
Joined: Thu May 08, 2008 1:24 am
Location: Croatia
Contact:

Post 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)

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post 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.

Jeff
Posts: 604
Joined: Sat Apr 07, 2007 2:23 pm
Location: Ohio
Contact:

Post by Jeff »

What prevents adding this optimization for defined functions?
Jeff
=====
Old programmers don't die. They just parse on...

Artful code

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post 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.

chi
Posts: 7
Joined: Mon May 11, 2009 1:59 pm

Post 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 :-)

chi
Posts: 7
Joined: Mon May 11, 2009 1:59 pm

Post 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 :-)

Kazimir Majorinc
Posts: 388
Joined: Thu May 08, 2008 1:24 am
Location: Croatia
Contact:

Post 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.
Last edited by Kazimir Majorinc on Thu May 21, 2009 1:35 pm, edited 1 time in total.

Jeff
Posts: 604
Joined: Sat Apr 07, 2007 2:23 pm
Location: Ohio
Contact:

Post 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.
Jeff
=====
Old programmers don't die. They just parse on...

Artful code

chi
Posts: 7
Joined: Mon May 11, 2009 1:59 pm

Post 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 :-)

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post 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.
-- (define? (Cornflakes))

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post 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.

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post 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

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

Aaah yeah look.. thanks! ;-)
-- (define? (Cornflakes))

Locked