confused by replace ?

Q&A's, tips, howto's
Locked
winger
Posts: 46
Joined: Wed Mar 14, 2012 7:31 am

confused by replace ?

Post by winger »

Code: Select all

> (setf str {abc1111abc222})
"abc1111abc222"
> (replace {a(bc)} str (push  $1 lst -1) 0)
"abc1111abc222"
;why ?
;(push  $1 lst -1)  will return lst then  lst replace {a(bc)}    ???
;
> (setf lst nil)
nil
> (replace {a(bc)} str (println (push  $1 lst -1)) 0)
("bc")
("bc" "bc")
"abc1111abc222"

> (replace {a(bc)} str $1  0)
"bc1111bc222"

Welcome to a newlisper home:)
http://www.cngrayhat.org

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

Re: confused by replace ?

Post by cormullion »

I think it's because your first replace expression is trying to replace the found string with a list:
If all arguments are strings, replace replaces all occurrences of str-key in str-data with the evaluated exp-replacement, returning the changed string. (newLISP Reference Manual)
So this won't do anything:

Code: Select all

(replace "(a)bc" "abcabc" (list $1) 0)
;-> abcabc
whereas this will:

Code: Select all

(replace "(a)bc" "abcabc" (upper-case $1) 0)
;-> AA

winger
Posts: 46
Joined: Wed Mar 14, 2012 7:31 am

Re: confused by replace ?

Post by winger »

OMG
If all arguments are strings

include exp-replacement evaluated !!!!!!
Welcome to a newlisper home:)
http://www.cngrayhat.org

Locked