newLISP Fan Club

Forum => Anything else we might add? => Topic started by: Jeremy Dunn on January 10, 2005, 07:14:51 AM

Title: String Lists
Post by: Jeremy Dunn on January 10, 2005, 07:14:51 AM
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.
Title:
Post by: Sammo on January 10, 2005, 07:23:41 AM
> (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")
Title:
Post by: eddier on January 10, 2005, 07:38:55 AM
I know Perl uses:


qw/cat dog rat bat/

Just curious, what is it in Python
Title:
Post by: Sammo on January 10, 2005, 11:21:57 AM
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")
Title:
Post by: Jeremy Dunn on January 11, 2005, 06:55:57 AM
Thank you one and all.