Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a string to list using clisp?

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.

like image 627
z_axis Avatar asked Sep 18 '11 04:09

z_axis


People also ask

Can you convert a string to a list?

Strings can be converted to lists using list() .

What is LISP list?

Lists are single linked lists. In LISP, lists are constructed as a chain of a simple record structure named cons linked together.

How do you compare two strings in Lisp?

To compare the characters of two strings, one should use equal, equalp, string=, or string-equal. Compatibility note: The Common Lisp function eql is similar to the Interlisp function eqp.


1 Answers

Here is a recursive solution.

    ;Turns a string into a stream so it can be read into a list
    (defun string-to-list (str)
        (if (not (streamp str))
           (string-to-list (make-string-input-stream str))
           (if (listen str)
               (cons (read str) (string-to-list str))
               nil)))
like image 162
Banjocat Avatar answered Sep 21 '22 13:09

Banjocat