confused by replace ?

Started by winger, September 10, 2012, 07:02:24 AM

Previous topic - Next topic

winger


> (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\">//http://www.cngrayhat.org

cormullion

#1
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

winger

#2
OMG
 
QuoteIf all arguments are strings
 

include  exp-replacement evaluated !!!!!!
Welcome to a newlisper home:)

http://www.cngrayhat.org\">//http://www.cngrayhat.org