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