Newbie lisp problem: string to list of strings separated by space



Hi,

I am trying to write a very simple function that accepts a string as input, and that returns a list of strings as output, having a seperate list item for every substring without a space.

Example:
input = "something very odd"
output = ("something" "very" "odd")

I tried to do this with the following function, but I can't understand why it is not working.

(defun parse(a)
(setq pos (or (position #\space a) -1) )
(cond ((= pos -1) (list a))
((> pos -1) (append
(parse (subseq a 0 pos))
(parse (subseq a (+ pos 1) (length a)))))))

Any comment is welcome!

Regards,

Wouter
.



Relevant Pages

  • Re: Newbie lisp problem: string to list of strings separated by space
    ... I am trying to write a very simple function that accepts a string as ... (parse (subseq a 0 pos)) ... dialects and Common Lisp ensured that they were all filled. ...
    (comp.lang.lisp)
  • Re: Newbie lisp problem: string to list of strings separated by space
    ... I am trying to write a very simple function that accepts a string as input, and that returns a list of strings as output, having a seperate list item for every substring without a space. ... (parse (subseq a 0 pos)) ... dialects and Common Lisp ensured that they were all filled. ...
    (comp.lang.lisp)
  • Re: Open Sound Control
    ... \0s at the end of the string to pad it to a 32bit boundary. ... puts [string length $packet] ... instead it extracts both the I* and R* lists once ... set len [lindex $l $pos] ...
    (comp.lang.tcl)
  • FAQ 6.19 What good is "G" in a regular expression?
    ... any characters to find the next match with this anchor, ... It uses the value of pos() as the ... Each string has its own posvalue. ... After the match fails at the letter "a", perl resets pos() and the next ...
    (comp.lang.perl.misc)
  • FAQ 6.19 What good is "G" in a regular expression?
    ... any characters to find the next match with this anchor, ... It uses the value of pos() as the ... Each string has its own posvalue. ... After the match fails at the letter "a", perl resets pos() and the next ...
    (comp.lang.perl.misc)