call stack overflow in function set : if

Q&A's, tips, howto's
Locked
HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

call stack overflow in function set : if

Post by HPW »

With this user functions:

Code: Select all

(define (car lst)
	(if lst(first lst)nil))

(define (cadr lst)
	(if lst(first(rest lst))nil))

(define (read readstr   readret)
	(cond
		((float readstr)
		 (if (find "." readstr)
			(setq readret (float readstr))
			(setq readret (integer readstr))
		 )
		)
		((=(slice readstr 0 1)"(")
			(setq readret(eval-string(append "'" readstr)))
		)
		(true
			(setq readret (symbol readstr))
		)
	)
	)

(define-macro (strcat _startstr)
	(if (not(string? _startstr))
		(setq _startstr (eval _startstr)))
	(if (args)
	(dolist (_strcatx (args))
		(if (string? _strcatx)
		(setq _startstr(append _startstr _strcatx))
		(setq _startstr(append _startstr (eval _strcatx)))
		)
		))_startstr)

 (define-macro (foreach _foreachx _foreachlst)(eval (list 'dolist (list _foreachx _foreachlst) (append (list 'begin) (args)))))
And this call:

Code: Select all

(foreach lst (list (list "MySym" "MyVal"))(set (read(strcat(car lst))) (cadr lst)))
I get:

call stack overflow in function set : if
called from user defined function read
called from user defined function read
called from user defined function read
called from user defined function read
called from user defined function read
called from user defined function read
called from user defined function read
called from user defined function read
called from user defined function read
called from user defined function read
called from user defined function read
...
...

Any hints?
Hans-Peter

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

Post by Lutz »

The recursion seems to happen in 'strcat' when doing (eval _strcatx) the variable _stcatx itself conatins an expression containing an evaluation of 'strcat'.

I wonder if the whole code generally could be improved? Why are you defining 'car', 'cdr' 'strcat' etc.? newLISP has functions for all of these, although they may work different than the once you are defining, they work well together and would lead to much shorter code? Are you trying to emulate another LISP in newLISP to port another LISP application to newLISP?

Perhaps you can tell us about the problem you are solving and we can come up with different methods, ideas to solve it.

Lutz

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post by HPW »

Hello Lutz,

of cource you are right that there are native commands in newlisp for the most commands.
Are you trying to emulate another LISP in newLISP to port another LISP application to newLISP?
I have build a sort of compatibility layer to older alisp-sources, which are then easier to port to newlisp. Since this was a big project, and I am very familar with the syntax, it was attractive to me to use the 'programmable programming-language LISP' to rebuild it under newLISP.

So at least I get a compromise between the amount of port-work and the work to build this compatibility layer.

(Did you remember in the past my wishes to setq, repeat and the infix-parser etc. - all is used here and there are a lot others)
Hans-Peter

Locked