newLISP Fan Club

Forum => newLISP in the real world => Topic started by: dukester on December 22, 2014, 12:46:53 PM

Title: Using "replace" on a list of symbols
Post by: dukester on December 22, 2014, 12:46:53 PM
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:


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


but it's not working!



Would someone point me in the right direction - please!!
Title: Re: Using "replace" on a list of symbols
Post by: rrq on December 22, 2014, 02:11:22 PM
(dolist (s '(var1 var2 var3 var4 var5))
(replace "<" (eval s) "<"))
Title: Re: Using "replace" on a list of symbols
Post by: dukester on December 22, 2014, 02:36:16 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:
(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?
Title: Re: Using "replace" on a list of symbols
Post by: rrq on December 22, 2014, 04:11:00 PM
(eval s)
Title: Re: Using "replace" on a list of symbols
Post by: dukester on December 22, 2014, 04:51:31 PM
I haven't tried your (eval s) trick yet.



I solved the issue with:


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