String Lists

For the Compleat Fan
Locked
Jeremy Dunn
Posts: 95
Joined: Wed Oct 13, 2004 8:02 pm
Location: Bellingham WA

String Lists

Post 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.

Sammo
Posts: 180
Joined: Sat Dec 06, 2003 6:11 pm
Location: Loveland, Colorado USA

Post 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")

eddier
Posts: 289
Joined: Mon Oct 07, 2002 2:48 pm
Location: Blue Mountain College, MS US

Post by eddier »

I know Perl uses:

Code: Select all

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

Sammo
Posts: 180
Joined: Sat Dec 06, 2003 6:11 pm
Location: Loveland, Colorado USA

Post 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")

Jeremy Dunn
Posts: 95
Joined: Wed Oct 13, 2004 8:02 pm
Location: Bellingham WA

Post by Jeremy Dunn »

Thank you one and all.

Locked