newLISP Fan Club

Forum => newLISP in the real world => Topic started by: winger on September 10, 2012, 07:02:24 AM

Title: confused by replace ?
Post by: winger on September 10, 2012, 07:02:24 AM

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

Title: Re: confused by replace ?
Post by: cormullion on September 11, 2012, 03:14:23 PM
I think it's because your first replace expression is trying to replace the found string with a list:


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


(replace "(a)bc" "abcabc" (list $1) 0)
;-> abcabc


whereas this will:


(replace "(a)bc" "abcabc" (upper-case $1) 0)
;-> AA
Title: Re: confused by replace ?
Post by: winger on September 12, 2012, 08:53:33 AM
OMG
 
QuoteIf all arguments are strings
 

include  exp-replacement evaluated !!!!!!