match and set-ref-all stack overflow

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

match and set-ref-all stack overflow

Post by cormullion »

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

Code: Select all

(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
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

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

Meanwhile I suggest the following work-around:

Code: Select all

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

Code: Select all

(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
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post by cormullion »

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

Locked