newLISP Fan Club

Forum => newLISP in the real world => Topic started by: sigipa on October 18, 2016, 06:43:50 PM

Title: string function returns literal list
Post by: sigipa on October 18, 2016, 06:43:50 PM
Hello All,



When the string function is applied to a list, it returns a literal list. See code below.



(string '("a" "b" "c"))



This returns: ("a" "b" "c")



I expected it to return: "abc"



Is this working as intended? If so, is there another function that will return a string without the parens and quotes?



Thanks,

-S
Title: Re: string function returns literal list
Post by: steloflute on October 18, 2016, 09:13:12 PM
It is intended. See //http://www.newlisp.org/downloads/newlisp_manual.html#string


QuoteTranslates into a string anything that results from evaluating exp-1—. If more than one expression is specified, the resulting strings are concatenated.


(string 'hello)          → "hello"
(string 1234)            → "1234"
(string '(+ 3 4))        → "(+ 3 4)"
(string (+ 3 4) 8)       → "78"
(string 'hello " " 123)  → "hello 123"


I suggest using apply as follows:
> (apply string '("a" "b" "c"))
"abc"
Title: Re: string function returns literal list
Post by: sigipa on October 19, 2016, 05:24:54 AM
Hi,



Works perfectly. Thanks.



-S
Title: Re: string function returns literal list
Post by: kesha on November 10, 2016, 05:04:36 PM
Hi,

//http://www.newlisp.org/downloads/newlisp_manual.html#join



> (set 'MYLIST '("a" "b" "c"))
("a" "b" "c")
> (join MYLIST)
"abc"
> (join MYLIST "-")
"a-b-c"
> (join MYLIST (string "-" (join MYLIST) "-"))
"a-abc-b-abc-c"