call stack overflow in function set : if

Started by HPW, March 22, 2005, 03:55:06 AM

Previous topic - Next topic

HPW

With this user functions:



(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:

(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

#1
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

#2
Hello Lutz,



of cource you are right that there are native commands in newlisp for the most commands.


Quote
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