Using "replace" on a list of symbols

Q&A's, tips, howto's
Post Reply
dukester
Posts: 108
Joined: Tue May 08, 2007 1:06 pm
Location: Alberta, Canada

Using "replace" on a list of symbols

Post by dukester »

Is it possible?

I have 5 symbols containing various strings.

I want to replace all the "<" characters with "<" in one, slick expression.

I was thinking of:

Code: Select all

(dolist (s (var1 var2 var3 var4 var5))
(replace "<" s "<"))
but it's not working!

Would someone point me in the right direction - please!!
duke

ralph.ronnquist
Posts: 216
Joined: Mon Jun 02, 2014 1:40 am
Location: Melbourne, Australia

Re: Using "replace" on a list of symbols

Post by ralph.ronnquist »

Code: Select all

(dolist (s '(var1 var2 var3 var4 var5))
(replace "<" (eval s) "<"))

dukester
Posts: 108
Joined: Tue May 08, 2007 1:06 pm
Location: Alberta, Canada

Re: Using "replace" on a list of symbols

Post by dukester »

Thx Ralph!! I'm doing something wrong, because it's still not working for me. I did try your suggestion before posting.

Here the complete test function:

Code: Select all

(define (addData)
(set 'formTitle "<abc")
(set 'formDesc "<def")
(set 'formWords "<xyz")
(set 'formEmail "ijkl")
(set 'formURL "<opq")
(set 'data_file "data.txt")
(dolist (s '(formTitle formDesc formWords formEmail formURL))
	(replace ("<"  s "<"))
(append-file data_file (string formTitle "|" formDesc "|" formWords "|" formEmail "|" formURL "\n")))
)
(addURL)
I keep getting:

ERR: value expected in function replace : s
called from user defined function addURL

Where have I blown it?
duke

ralph.ronnquist
Posts: 216
Joined: Mon Jun 02, 2014 1:40 am
Location: Melbourne, Australia

Re: Using "replace" on a list of symbols

Post by ralph.ronnquist »

Code: Select all

(eval s)

dukester
Posts: 108
Joined: Tue May 08, 2007 1:06 pm
Location: Alberta, Canada

Re: Using "replace" on a list of symbols

Post by dukester »

I haven't tried your (eval s) trick yet.

I solved the issue with:

Code: Select all

(define (addData)
(set 'formTitle "<abc")
(set 'formDesc "<def")
(set 'formWords "<xyz")
(set 'formEmail "ijkl")
(set 'formURL "<opq")
(set 'data_file "data.txt")

(set 'data (string formTitle "|" formDesc "|" formWords "|" formEmail "|" formURL))

(replace ("<"  data "<")
(println  data)
)
(addData)
Thx for your input!!
duke

Post Reply