match and set-ref-all stack overflow

Started by cormullion, November 26, 2008, 11:52:46 AM

Previous topic - Next topic

cormullion

Is there another way to do this - I'm getting a stack overflow in match for values over 1300...


(for (i 0 1400)
   (push (list (string i) i) results -1))
(set 'l (last (first  results)))
(set-ref-all '(+ +)  results (list (first $it) (- (last $it) l))  match)


newLISP v.9.9.95

Lutz

#1
I took care of the stack overflow in 'set-ref-all' with 'match' for 9.9.96.



Meanwhile I suggest the following work-around:


(replace '(+ +)  results (list (first $it) (- (last $it) l))  match)


replace/match does not grow the stack.



Not sure why you have chosen 'set-ref-all' for that type of data. You would use 'set-ref-all', if the pattern you are looking for '(+ +) can be found on different nesting levels. In your example we deal with a flat list of lists.



But in case you real data does have more complex nesting you could do this:


(set 'refs (ref-all '(+ +) results match))
(dolist (vec refs)
(setf (results vec) (list (first $it) (- (last $it) l))))


in '(results vec)' you are indexing with an index vector list, its a nice example how the result from 'ref' or 'ref-all' can be used for multi-dimensional indexing



ps: note that in your data l (letter l) was zero, so the replacement didn't really change. I plugged in 1 (number one) to make sure all is working and gives no stack overflow.

cormullion

#2
Cool - thanks.



Choosing the right function is the key thing - newLISP has many cool functions now, working with different flavours of lists. And I forgot that I could use match with replace... :)