Alex Rivera | Logout

String to list without #\ in common lisp

Asked 2012-01-30T15:59:38.550
8

I'd like to turn String into lists. For example, http => (h t t p).

I try:

(defun string-to-list (s)
  (assert (stringp s) (s) "~s :questa non e una stringa")
  (coerce s 'list))

but if I do

(string-to-list "http")

results:

(#\h #\t #\t #\p).

Can I remove #\ ? thanks in advance :)

Edit
Report

1 Answer

20

Why would you do that? What you ask is to split a string (a one-dimensional array of characters) into a list of symbols. Do you really want that?

#\h is a character object printed.

You can print them differently:

CL-USER 8 > (princ #\h)
h

CL-USER 9 > (prin1 #\h)
#\h

Let's print the list using PRINC:

CL-USER 10 > (map nil #'princ (coerce "Hello!" 'list))
Hello!

Btw., since strings, vectors and lists are sequences, you can MAP directly over the string...

CL-USER 11 > (map nil #'princ "Hello!")
Hello!
answered 2012-01-30T17:50:58.090

Your Answer