From: ······@gmail.com
Subject: Need help with lisp, yes i'm a newbie
Date: 
Message-ID: <a47a7c86-8b0e-4354-b3eb-5e4ea4fa74ab@k10g2000prm.googlegroups.com>
i already know how to create lists
(setf x (list a b c d))

or

(setf x (list :a "apple" :b "bob"))


my questions is how do I set delimiters for a string and split it into
an array or list, I know how to do this with other languages.

example

i have a string

"apple,oranges,pears"

or

"apple oranges pears"

I want it to end up like

(list "apple" "oranges" "pears")

or better yet

(list :typea "apple" :typeb "oranges" :typec "pears")

I know I am a newbie, please do not flame. I am asking advice.

From: danb
Subject: Re: Need help with lisp, yes i'm a newbie
Date: 
Message-ID: <89fe9b27-1e5f-4744-b9d7-3b1bd8a67cca@d1g2000hsg.googlegroups.com>
On Apr 18, 6:19 pm, ······@gmail.com wrote:
> how do I set delimiters for a string and split it into
> an array or list

It's called SPLIT, just like in Perl, but it's in
a regular-expression library called cl-ppcre.
Here's the man page:
http://weitz.de/cl-ppcre/#split

--Dan

------------------------------------------------
Dan Bensen
http://www.prairienet.org/~dsb/
From: Vagif Verdi
Subject: Re: Need help with lisp, yes i'm a newbie
Date: 
Message-ID: <a3fe0178-1d71-4d5b-93dc-e761651bd0f5@b5g2000pri.googlegroups.com>
On Apr 18, 4:19 pm, ······@gmail.com wrote:
> i already know how to create lists
> (setf x (list a b c d))
>
> or
>
> (setf x (list :a "apple" :b "bob"))
>
> my questions is how do I set delimiters for a string and split it into
> an array or list, I know how to do this with other languages.
>
> example
>
> i have a string
>
> "apple,oranges,pears"
>
> or
>
> "apple oranges pears"
>
> I want it to end up like
>
> (list "apple" "oranges" "pears")

Download this library: http://www.cliki.net/SPLIT-SEQUENCE

there's one function split-sequence that does what you need.
Here's the example:

(split-sequence #\Space "apple oranges pears")

Or if you have different delimiter:

(split-sequence #\, "apple,oranges,pears")
From: Vagif Verdi
Subject: Re: Need help with lisp, yes i'm a newbie
Date: 
Message-ID: <da6cb817-a366-407e-bddc-18ad569fcca9@s33g2000pri.googlegroups.com>
On Apr 18, 4:19 pm, ······@gmail.com wrote:
> i already know how to create lists
> (setf x (list a b c d))
>
> or
>
> (setf x (list :a "apple" :b "bob"))
>
> my questions is how do I set delimiters for a string and split it into
> an array or list, I know how to do this with other languages.
>
> example
>
> i have a string
>
> "apple,oranges,pears"
>

download library http://www.cliki.net/SPLIT-SEQUENCE

(split-sequence #\Space "apple oranges pears")

or with another delimiter:

(split-sequence #\, "apple,oranges,pears")
From: Lars Rune Nøstdal
Subject: Re: Need help with lisp, yes i'm a newbie
Date: 
Message-ID: <480b6c2d$0$28883$c83e3ef6@nn1-read.tele2.net>
Vagif Verdi wrote:
> On Apr 18, 4:19 pm, ······@gmail.com wrote:
>> i already know how to create lists
>> (setf x (list a b c d))
>>
>> or
>>
>> (setf x (list :a "apple" :b "bob"))
>>
>> my questions is how do I set delimiters for a string and split it into
>> an array or list, I know how to do this with other languages.
>>
>> example
>>
>> i have a string
>>
>> "apple,oranges,pears"
>>
> 
> download library http://www.cliki.net/SPLIT-SEQUENCE
> 
> (split-sequence #\Space "apple oranges pears")
> 
> or with another delimiter:
> 
> (split-sequence #\, "apple,oranges,pears")
> 

May I suggest:
   http://common-lisp.net/project/cl-utilities/

..it has SPLIT-SEQUENCE etc. and is "contained in" what seems to be a 
maintained project.

-- 
Lars Rune N�stdal
http://nostdal.org/
From: Pascal Bourguignon
Subject: Re: Need help with lisp, yes i'm a newbie
Date: 
Message-ID: <877ieuiuah.fsf@hubble.informatimago.com>
······@gmail.com writes:

> i already know how to create lists
> (setf x (list a b c d))
>
> or
>
> (setf x (list :a "apple" :b "bob"))
>
>
> my questions is how do I set delimiters for a string and split it into
> an array or list, I know how to do this with other languages.

Oh, really?  Proove it!


> example
>
> i have a string
>
> "apple,oranges,pears"
>
> or
>
> "apple oranges pears"
>
> I want it to end up like
>
> (list "apple" "oranges" "pears")
>
> or better yet
>
> (list :typea "apple" :typeb "oranges" :typec "pears")
>
> I know I am a newbie, please do not flame. I am asking advice.

No, really, just show us what you'd do in another language (or in
pseudo-code) to parse a string into substrings.  What operations do
you use in that other language?  Can you imagine a way to find out the
equivalent operations in lisp?  



For example, you could just google for common lisp, and find a lot of
very good references. CLHS has whole chapters on sequence, vector and
string operators.


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

"Do not adjust your mind, there is a fault in reality"
 -- on a wall many years ago in Oxford.
From: Robert Maas, http://tinyurl.com/uh3t
Subject: Re: Need help with lisp, yes i'm a newbie
Date: 
Message-ID: <rem-2008apr27-006@yahoo.com>
> > my questions is how do I set delimiters for a string and split it into
> > an array or list, I know how to do this with other languages.
> From: Pascal Bourguignon <····@informatimago.com>
> Oh, really?  Proove it!

I second that motion.

> No, really, just show us what you'd do in another language (or in
> pseudo-code) to parse a string into substrings.  What operations
> do you use in that other language?

Elaboration of original motion, seconded again.

> Can you imagine a way to find out the equivalent operations in lisp?

If I ever get this finished:
 <http://www.rawbw.com/~rem/HelloPlus/CookBook/Matrix.html>
then it would be possible to search for the name of any function in
any of the six or seven languages covered and then immediately see
the equivalent function in each of the other languages covered.
For the OP claiming to know how to do this in other languages, this
mode of search should be a cinch.

> For example, you could just google for common lisp, and find a
> lot of very good references. CLHS has whole chapters on sequence,
> vector and string operators.

<http://www.lispworks.com/documentation/HyperSpec/Front/Contents.htm>
Let's see how easy this might be for a newbie...
Link that you currently have selected
   Linkname: Strings
        URL: http://www.lispworks.com/documentation/HyperSpec/Body/16_.htm
16. Strings
16.1 String Concepts (clicked on link where I see these two deeper sections)
  16.1.1 Implications of Strings Being Arrays
  16.1.2 Subtypes of STRING
16.2 The Strings Dictionary (clicked on link where I see a huge list:)
   System Class STRING
   Type BASE-STRING
   Type SIMPLE-STRING
   Type SIMPLE-BASE-STRING
   Function SIMPLE-STRING-P
   Accessor CHAR, SCHAR
and on and on and on.
This really doesn't seem quite newbie-friendly, IMO.
Not a mention that substring can be accomplished by subseq, or that
position works with strings, or *any* mention anywhere in the
String section that a string is a sub-type of sequence. Maybe
that's in the section on Implications of Strings Being Arrays?
Looking there now...

16.1.1 Implications of Strings Being Arrays
   Since all strings are arrays, all rules which apply generally to
   arrays also apply to strings. See Section 15.1 (Array Concepts).
   For example, strings can have fill pointers, and strings are also
   subject to the rules of element type upgrading that apply to arrays.

Still no mention of string being a sub-type of sequence, hence the
sequence functions would work on them. By comparison, the table of
contents to my Matrix shows clearly that strings are sub-type of
sequence:

   [Sequences] (including integer indexes)
     * [Vectors] (1-d arrays, see also sub under arrays)
       and [LinkedLists] Integers
          + [Strings]
            and Characters [LinkedLists] [Symbols] [Sequences] Integers /
            Floats [Anything]
     * [LinkedLists]
       and [StandardPairs] [Vectors] [LambdaExpressions] [Association
       lists] [Property lists] [Forms]

so if I ever get that finished, a newbie could look first in the
section on sequences, then vectors, then strings, to find all
useful functions that might be useful for the task.
Currently I have POSITION but not SUBSEQ documented, sigh.
(because POSITION applied to a string parameter has a direct equivalent in C,
 whereas SUBSEQ doesn't, requires calls to two different functions in C,
 and so-far I've been working almost only from C to Lisp)
From: Robert Maas, http://tinyurl.com/uh3t
Subject: Re: Need help with lisp, yes i'm a newbie
Date: 
Message-ID: <rem-2008apr27-005@yahoo.com>
> From: ······@gmail.com
> i already know how to create lists
> (setf x (list a b c d))

No, that's not creating a list.
That's creating a list *and*then*also* assigning the list-value to a variable.
Depending on the context, it may be setting the value cell of a
symbol to that list value, or it may be setting a lexical variable
(not attached to any symbol at runtime) to that list value, or it
may be overwriting a parameter to the function where this code
resides.

To create a list, just do this: (list a b c d)

Furthermore, in both cases, you're also doing four more things:
You're looking up the value currently bound to the variable a, and
you're looking up the value currently bound to the variable b, and
you're looking up the value currently bound to the variable c, and
you're looking up the value currently bound to the variable d.
So that one line of code you gave is actually doing six different
things, and the code I gave is doing five things.

> (setf x (list :a "apple" :b "bob"))

Now you're only doing two things, making a list, and assigning a variable.
To get a pure example, making a list and doing nothing else:
  (list :a "apple" :b "bob")

Now at the top level of REP, even *that* will do several other things:
(shiftf '+++ '++ '+ whatYouTyped)
(shiftf '*** '** '* resultOfEvaluationOfWhatYouTyped)
(shiftf '/// '// '/ listOfAllResultsFromEvaluationOfWhatYouTyped)
but that's just the workings of the REP, not something your code
itself does.

> my questions is how do I set delimiters for a string and split it
> into an array or list, I know how to do this with other languages.

Do you want just a single delimiter at any one time, or a whole
"bag" of delimiters whereby any of them that appear in the string
would work equally well? For example, which of these do you want to code?
(onedelim-split #\x "ewxksxhasoipae") -> ("ew" "ks" "hasoipae")
(delims-split '(#\x #\a) "ewxksxhasoipae") -> ("ew" "ks" "h" "soip" "e")
State your problem clearly before we go on.

Also, please post code showing how you already can do this in
at least one other language among these:  c c++ java perl php

> example
> i have a string
> "apple,oranges,pears"
> or
> "apple oranges pears"
> I want it to end up like
> (list "apple" "oranges" "pears")

In that example, either space or comma would suffice as delimiter,
so you want a *single* call that will accept either as delimiter,
so you want to implement delims-split rather than onedelim-split,
(delims-split '(#\, #\space) ...)
will accept either of those strings in the ... place?
Is that your correct intention?

Or do you mean that the function will accept only one delimiter at
a time, so you need to make different calls to get it to accept
those two different strings. So you must do these:
(onedelim-split #\,     "apple,oranges,pears")
(onedelim-split #\space "apple oranges pears")

> or better yet
> (list :typea "apple" :typeb "oranges" :typec "pears")

Now you're asking for something more elaborate, and I have no idea
what you mean by what you said there. Why would you want a function
to return a list whose first element is the symbol LIST and then
after that it returns alternating gensymmed keywords and
sub-strings of your input? Why not just return this list instead?
  (:typea "apple" :typeb "oranges" :typec "pears")

> I know I am a newbie, please do not flame. I am asking advice.

I'm not flaming. I'm trying to get to you to follow procedure:
- First you get clear in your mind what task you want the computer
   to perform, and please do just one at a time, either it takes
   just one delim or it takes a bag of delims, either it returns
   just the list of sub-strings or it returns an alternating list
   of GENSYMmed tags and sub-strings. We can program only one task
   at a time, so please pick one combination and stick with it
   until we're done with that one task before moving on to
   questions about other tasks.
- Next you tell us clearly which of those tasks you have chosen,
   and express it clearly, both descriptive and by example. It
   might be best if you make up a reasonable name for the function
   you want to define (I've suggested onedelim-split and
   delims-split as plausable names; you can pick one of those, or
   make up a name you like better), and give examples that clearly
   show form to be evaluated and result from evaluation, for example:
(onedelim-split #\space "apple oranges pears") => ("apple" "oranges" "pears")
- Finally you tell us your preliminary ideas how to go about
   accomplishing the task. You don't have to write pseudo code.
   Just any vague ruminations that give us an idea you have the
   foggiest idea what todo first to solve the task, or in fact
   *any* piece of the solution you can think of. Then we can tell
   you which parts of the solution you are thinking correctly, and
   which parts you still have missing. For any parts of the
   solution which you have stated correctly, we can suggest where
   in documentation to find a function that you can call to perform
   that piece of the solution.


OK, I'm going to give you a freebie by example:

Suppose you say that you want to extract a sub-string of the
original string that consists of the first word "apple".

We would show you where to find the Common Lisp function for
extracting sub-strings, and ask you to read that documentation and
then tell us what parameters you will need to pass to that function
in order that it will proceed to extract exactly the desired
sub-string instead of any of the other many possible sub-strings
within the overall 19-character string you started with.

You would then say that the indixes are from 0 to 5, which is correct,
or you'd say the indexes are from 1 to 5, which is not correct.

We'd help you to understand why 0,5 is correct ad 1,5 is wrong,
and we's ask you to tell us how the computer is to know those
particular indices 0 (that one is easy) and 5 (that is more interesting).