Hi,
is there a mode to transform a word into a list, e.g. (word) -> (w o r d)?
Thanx
filfil
is there a mode to transform a word into a list, e.g. (word) -> (w o r d)?
Thanx
filfil
Discuss and learn Lisp programming of all dialects
This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.
6 posts · 5909 views
(defun struct->list (l)
(coerce (string (car l)) 'list))
If your argument really is a string, the only thing you need to do is (coerce "string" 'list)
You get a lot of more pointers about strings in CL here: http://cl-cookbook.sourceforge.net/strings.html> (struct->list '(word))
(#\W #\O #\R #\D)
I've read this http://cl-cookbook.sourceforge.net/strings.html and it's quite useful. It's a good thing converting characters into strings...> (setf a (struct->list '(word)))
(#\W #\O #\R #\D)
> (mapcar #'string a)
("W" "O" "R" "D")
...but I'd like get a "pure" letter list, without #\ or "", like this:(W O R D)
and I didn't find the way. Does anyone help me?(mapcar #'intern '("A" "B" "C"))(defun explode (object)
(loop for char across (prin1-to-string object)
collect (intern (string char))))
(defun implode (list)
(read-from-string (coerce (mapcar #'character list) 'string)))
This has the following effect:(explode 'hello) => (H E L L O)
(implode '(h e l l o)) => HELLO
This was necessary because MacLisp had no STRING data type. In Common Lisp it's better to use SYMBOL-NAME and INTERN to convert between symbol-names and strings and do the splitting and concatenating via string functions.