Page 1 of 1

confused by replace ?

Posted: Mon Sep 10, 2012 2:02 pm
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"


Re: confused by replace ?

Posted: Tue Sep 11, 2012 10:14 pm
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

Re: confused by replace ?

Posted: Wed Sep 12, 2012 3:53 pm
by winger
OMG
If all arguments are strings

include exp-replacement evaluated !!!!!!