Using "replace" on a list of symbols

Q&A's, tips, howto's

Using "replace" on a list of symbols

Postby dukester » Mon Dec 22, 2014 8:46 pm

Is it possible?

I have 5 symbols containing various strings.

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

I was thinking of:

Code: Select all
(dolist (s (var1 var2 var3 var4 var5))
(replace "<" s "&lt;"))


but it's not working!

Would someone point me in the right direction - please!!
duke
dukester
 
Posts: 108
Joined: Tue May 08, 2007 1:06 pm
Location: Alberta, Canada

Re: Using "replace" on a list of symbols

Postby ralph.ronnquist » Mon Dec 22, 2014 10:11 pm

Code: Select all
(dolist (s '(var1 var2 var3 var4 var5))
(replace "<" (eval s) "&lt;"))
ralph.ronnquist
 
Posts: 202
Joined: Mon Jun 02, 2014 1:40 am
Location: Melbourne, Australia

Re: Using "replace" on a list of symbols

Postby dukester » Mon Dec 22, 2014 10:36 pm

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 "&lt;"))
(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
dukester
 
Posts: 108
Joined: Tue May 08, 2007 1:06 pm
Location: Alberta, Canada

Re: Using "replace" on a list of symbols

Postby ralph.ronnquist » Tue Dec 23, 2014 12:11 am

Code: Select all
(eval s)
ralph.ronnquist
 
Posts: 202
Joined: Mon Jun 02, 2014 1:40 am
Location: Melbourne, Australia

Re: Using "replace" on a list of symbols

Postby dukester » Tue Dec 23, 2014 12:51 am

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 "&lt;")
(println  data)
)
(addData)


Thx for your input!!
duke
dukester
 
Posts: 108
Joined: Tue May 08, 2007 1:06 pm
Location: Alberta, Canada


Return to newLISP in the real world

Who is online

Users browsing this forum: No registered users and 2 guests

cron