word to list
word to list
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
Re: word to list
The way you write it seems like its a list with one elemet which is symbol.
If your argument really is a string, the only thing you need to do is
You get a lot of more pointers about strings in CL here: http://cl-cookbook.sourceforge.net/strings.html
Code: Select all
(defun struct->list (l)
(coerce (string (car l)) 'list))
Code: Select all
(coerce "string" 'list)
I'm the author of two useless languages that uses BF as target machine.
Currently I'm planning a Scheme compiler :p
Currently I'm planning a Scheme compiler :p
Re: word to list
Thank you ![Smile :-)](./images/smilies/icon_e_smile.gif)
with your function, the result is thus:
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...
...but I'd like get a "pure" letter list, without #\ or "", like this:
and I didn't find the way. Does anyone help me?
Thank you
filfil
![Smile :-)](./images/smilies/icon_e_smile.gif)
with your function, the result is thus:
Code: Select all
> (struct->list '(word))
(#\W #\O #\R #\D)
Code: Select all
> (setf a (struct->list '(word)))
(#\W #\O #\R #\D)
> (mapcar #'string a)
("W" "O" "R" "D")
Code: Select all
(W O R D)
Thank you
filfil
Re: word to list
Use intern:
Code: Select all
(mapcar #'intern '("A" "B" "C"))
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.
Re: word to list
In MacLisp (one of the predecessor languages of Common Lisp) there existed two functions:
This has the following effect:
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.
See What is the equivalent of EXPLODE and IMPLODE in Common Lisp?
- edgar
- EXPLODE - split a symbol-name into a list of single-character symbols
- IMPLODE - concatenate a list of single-character symbols into a symbol-name
Code: Select all
(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)))
Code: Select all
(explode 'hello) => (H E L L O)
(implode '(h e l l o)) => HELLO
See What is the equivalent of EXPLODE and IMPLODE in Common Lisp?
- edgar
Re: word to list
INTERN
Thank you very much, Goheeca,
and Edgar for your Lisp cultural notes
![Exclamation :!:](./images/smilies/icon_exclaim.gif)
Thank you very much, Goheeca,
and Edgar for your Lisp cultural notes