How can i convert the string "1 2 3 4 5 6 7"
into the list (1 2 3 4 5 6 7)
elegantly? I am using CLISP.
相关问题
- Generating powerset in one function, no explicit r
- Drakma and Dexador both fails at USocket call whil
- Forming Lisp code to task — related to flatten lis
- clisp 2.49: asdf cannot find asd
- unfold function in scheme
相关文章
- Does learning one Lisp help in learning the other?
- Common Lisp: Why does my tail-recursive function c
- What is the definition of “natural recursion”?
- How do I write a macro-defining macro in common li
- How can I unintern a qualified method?
- Changing the nth element of a list
- Is a “transparent” macrolet possible?
- sleep in emacs lisp
You should use
parse-integer
in a loop.For example, using
loop
:⇒
(1 2 3)
If you need better control about the splitting, use the
split-sequence
orcl-ppcre
library.If you need to parse more general number formats, use the
parse-number
library.Libraries are available from Quicklisp.
I think this might work:
This makes a list with spaces as elements. Remove spaces:
I see that Svante is right. My previous attempt did not work. Here is another attempt. I use concatenate to change the string into a list representation. Then I use read-from-string to convert the string (s-2) into an actual list.
I roll it into a function like this:
The only purpose of "let" and "L" is to make the function from-string-to-list return only the list and not return multiple values. read-from-string returns two values: The list and the size of the string, I think.
Here is a recursive solution.
That would do,
Hint: Take a look at with-input-from-string.