Page 1 of 1

String Lists

Posted: Mon Jan 10, 2005 3:14 pm
by Jeremy Dunn
In the Python language one can write long lists of strings without having to type all the quotation marks. I would like a function that would do the following

(str cat dog rat bat) -> ("cat" "dog" "rat" "bat")

How can one accomplish this in NewLISP? Of course strings with spaces would not be allowed.

Posted: Mon Jan 10, 2005 3:23 pm
by Sammo
> (map string '(cat dog rat bat))
("cat" "dog" "rat" "bat")

> (define-macro (str) (map string (args)))
(lambda-macro () (map string (args)))

> (str cat dog rat bat)
("cat" "dog" "rat" "bat")

Posted: Mon Jan 10, 2005 3:38 pm
by eddier
I know Perl uses:

Code: Select all

qw/cat dog rat bat/
Just curious, what is it in Python

Posted: Mon Jan 10, 2005 7:21 pm
by Sammo
Oh, and strings with embedded spaces may simply be quoted.

> (str "string with spaces" cat rat bat hat sat mat fat gat gnat pat vat)
("string with spaces" "cat" "rat" "bat" "hat" "sat" "mat" "fat" "gat" "gnat" "pat" "vat")

Posted: Tue Jan 11, 2005 2:55 pm
by Jeremy Dunn
Thank you one and all.