Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Exploding a string into a list of character atoms?

519 views
Skip to first unread message

Joseph O'Rourke

unread,
Sep 21, 1996, 3:00:00 AM9/21/96
to

Is there a function to take a string like "string" and return
the list (S T R I N G)? (I am using GCL.) Thanks for any help!

Joseph O'Rourke

unread,
Sep 21, 1996, 3:00:00 AM9/21/96
to

Reposting article removed by rogue canceller.

Erik Naggum

unread,
Sep 24, 1996, 3:00:00 AM9/24/96
to

[Joseph O'Rourke]

| Is there a function to take a string like "string" and return the list
| (S T R I N G)? (I am using GCL.) Thanks for any help!

do you really want to use interned _symbols_ to represent each character?

if you only want characters, take a look at `coerce', as in

(coerce "string" 'list)
=> (#\s #\t #\r #\i #\n #\g)

#\Erik
--
Those who do not know Lisp are doomed to reimplement it.

Stefan Bamberger

unread,
Sep 24, 1996, 3:00:00 AM9/24/96
to

In article <R.521lbf$s...@sylvia.smith.edu>, oro...@grendel.csc.smith.edu
(Joseph O'Rourke) wrote:

> Reposting article removed by rogue canceller.
>

> Is there a function to take a string like "string" and return
> the list (S T R I N G)? (I am using GCL.) Thanks for any help!

(defun explode (item)
(flet ((*care-string (thing)
(format nil "~a" thing))
(*create-symbol (charac)
(intern (string (char-upcase charac))))
)
(let ((str (*care-string item))
(erglist nil)
)
(dotimes (i (length str) (nreverse erglist))
(push (*create-symbol (char str i))
erglist)
)
)))

That's what I use to do that.

- stefan

Erik Naggum

unread,
Sep 24, 1996, 3:00:00 AM9/24/96
to

[Stefan Bamberger]

| > Is there a function to take a string like "string" and return
| > the list (S T R I N G)? (I am using GCL.) Thanks for any help!
|
| (defun explode (item)
| (flet ((*care-string (thing)
| (format nil "~a" thing))
| (*create-symbol (charac)
| (intern (string (char-upcase charac))))
| )
| (let ((str (*care-string item))
| (erglist nil)
| )
| (dotimes (i (length str) (nreverse erglist))
| (push (*create-symbol (char str i))
| erglist)
| )
| )))
|
| That's what I use to do that.

you do? really?

I already mentioned this:

(coerce "string" 'list)
=> (#\s #\t #\r #\i #\n #\g)

but if you insist om making symbols:

(defun explode (string)
(mapcar #'(lambda (char) (intern (string (char-upcase char))))
(coerce string 'list)))

(explode "string")
=> (s t r i n g)

a simple comparison using CMUCL at (optimize (speed 3)) says that your
function conses 848 bytes, while mine conses 208 bytes, that your function
requires 531 盜 (microseconds) of CPU time on a 50MHz SPARC 2, while mine
requires 293 盜. compared to this, (coerce "string" 'list) takes 101 盜
and conses 56 bytes, basically the 6 cons cells. YMMV.

Rainer Joswig

unread,
Sep 25, 1996, 3:00:00 AM9/25/96
to

In article <R.521lbf$s...@sylvia.smith.edu>, oro...@grendel.csc.smith.edu
(Joseph O'Rourke) wrote:

> Reposting article removed by rogue canceller.
>

> Is there a function to take a string like "string" and return
> the list (S T R I N G)? (I am using GCL.) Thanks for any help!

(defun explode (string)
(loop for char character across string
collect (intern (string (char-upcase char)))))

0 new messages