[REBOL] [REBOL] [REBOL]string to series function Re:(4)
I can't tell all of you enough how much I appreciate this mailing list. As a programmer who earns my living in "C/C++" and doesn't have a R&D budget this is wonderful! I'm getting the impression from the various discussions of this thread, that parse is very powerful function that needs much investigation. >From the clarity of Sterling and Elan's messages, I am hopeful that we will see much revealed in the Official Guide. parse is going to be a major tool when/if I implement rebol professionally. I'm sure that I will have more questions, and perhaps a tutorial will come of it. Maybe I'll do it. In six months. Hah!! Thanks so much tim At 11:28 PM 4/10/00 -0700, you wrote: >At 09:55 PM 4/10/00 -0700, you wrote: >> >>Fair enough. >>I have little time to give a complete course on parse so I went for >>the shortest version. > >Yikes! Of course. I was worried that tim may eventually want to exclude >spaces from his parse rule, and then he'd be frustrated, because he >wouldn't know how to control space parsing. > >(Actually, I'd already written my response, and before I sent it off I >checked my email to avoid duplicate answers, and lo and behold, there was >your message. But I'd chosen a slightly different approach, and I thought >it was still worth mentioning it ...) > >So he gets more than he asked for ;-). > >>I expected to see a few other responses to this >>thread as well and sure enough the old-time REBOL-masters of the >>outside world give a more full answer than us insiders have time for. > >Time? I have time? ... > >Me? > >> >>Take it easy guys, >>Sterling >> > >You to Sterling. > >;- Elan >> [: - )] > >
[REBOL] [REBOL]string to series function Re:(4)
At 09:55 PM 4/10/00 -0700, you wrote: > >Fair enough. >I have little time to give a complete course on parse so I went for >the shortest version. Yikes! Of course. I was worried that tim may eventually want to exclude spaces from his parse rule, and then he'd be frustrated, because he wouldn't know how to control space parsing. (Actually, I'd already written my response, and before I sent it off I checked my email to avoid duplicate answers, and lo and behold, there was your message. But I'd chosen a slightly different approach, and I thought it was still worth mentioning it ...) So he gets more than he asked for ;-). >I expected to see a few other responses to this >thread as well and sure enough the old-time REBOL-masters of the >outside world give a more full answer than us insiders have time for. Time? I have time? ... Me? > >Take it easy guys, >Sterling > You to Sterling. ;- Elan >> [: - )]
[REBOL] [REBOL]string to series function Re:(3)
Hi tim, just-one: pick parse/all "one#two%three four" "#% " 1 or just-one: first parse/all "one#two%three four" "#% " or, if want to continue collecting the complete block in my-series: just-one: pick my-series: parse/all "one#two%three four" "#% " 1 and just-one: first my-series: parse/all "one#two%three four" "#% " Note that pick is safer, it will return none if parse returns none or if parse returns an empty block, whereas first will fail with an error exception in both cases. At 09:07 PM 4/10/00 -0800, you wrote: >Sterling showed me how the following code >gives me a block parse "one#two%three four" "#%" >>== ["one" "two" "three" "four"] > >that's great! Now if I write: >my-series: parse "one#two%three four" "#%" >just-one: my-series/1 >just-one is returned as "one" > >now how do I get "one" into just-one with 1 line >of code instead of two? > >thanks again >tim > > > > ;- Elan >> [: - )]
[REBOL] [REBOL]string to series function Re:(2)
Sterling showed me how the following code gives me a block >>> parse "one#two%three four" "#%" >== ["one" "two" "three" "four"] that's great! Now if I write: my-series: parse "one#two%three four" "#%" just-one: my-series/1 just-one is returned as "one" now how do I get "one" into just-one with 1 line of code instead of two? thanks again tim
[REBOL] [REBOL]string to series function Re:(3)
Fair enough. I have little time to give a complete course on parse so I went for the shortest version. I expected to see a few other responses to this thread as well and sure enough the old-time REBOL-masters of the outside world give a more full answer than us insiders have time for. Take it easy guys, Sterling > Hi Sterling, > > one little detail: your approach works well enough with this particular > example because space is one of the desired delimiters. > > Conceivably Tim may want a more universal solution that enables him to > determine whether or not he wants to include spaces in his parse rule. In > that case IMHO it would be more appropriate to use parse's all refinement > and - for the sake of this particular example - include space explicitly as > a delimiter in the rule: > > With space: > >> parse/all "one#two%three four" "%# " > == ["one" "two" "three" "four"] > > Without space > >> parse/all "one#two%three four" "%#" > == ["one" "two" "three four"] > > Note that the second version returns "three four" as one string because > space is not included in the rule. >
[REBOL] [REBOL]string to series function Re:(2)
Sterling: Wow!! That's just what I wanted. tj At 09:06 PM 4/10/00 -0700, you wrote: > >You really ought to just try these things. ;) >You'll be surprised at what you find. > >>> parse "one#two%three four" "#%" >== ["one" "two" "three" "four"] >>> > >Sterling > >> I would like to have a function to do >> the following >> 1)take two strings as arguments >> a)arg one is source >> b) arg two is delimiters >> 2)return a series >> >> it would work like this: >> >> my-series: string-to-series "one#two%three four" "#% " >> my-series is returned as ["one" "two" "three" "four"] >> >> BTW: I have a c function that does this. With >> subsequent function calls, it is about 40 lines of >> code. I'm pretty lost when it comes to parse, but >> I bet the rebol function would be shorter. >> thanks >> tim > >
[REBOL] [REBOL]string to series function Re:(2)
Hi Sterling, one little detail: your approach works well enough with this particular example because space is one of the desired delimiters. Conceivably Tim may want a more universal solution that enables him to determine whether or not he wants to include spaces in his parse rule. In that case IMHO it would be more appropriate to use parse's all refinement and - for the sake of this particular example - include space explicitly as a delimiter in the rule: With space: >> parse/all "one#two%three four" "%# " == ["one" "two" "three" "four"] Without space >> parse/all "one#two%three four" "%#" == ["one" "two" "three four"] Note that the second version returns "three four" as one string because space is not included in the rule. At 09:06 PM 4/10/00 -0700, you wrote: > >You really ought to just try these things. ;) >You'll be surprised at what you find. > >>> parse "one#two%three four" "#%" >== ["one" "two" "three" "four"] >>> > >Sterling > >> I would like to have a function to do >> the following >> 1)take two strings as arguments >> a)arg one is source >> b) arg two is delimiters >> 2)return a series >> >> it would work like this: >> >> my-series: string-to-series "one#two%three four" "#% " >> my-series is returned as ["one" "two" "three" "four"] >> >> BTW: I have a c function that does this. With >> subsequent function calls, it is about 40 lines of >> code. I'm pretty lost when it comes to parse, but >> I bet the rebol function would be shorter. >> thanks >> tim > > > ;- Elan >> [: - )]
[REBOL] [REBOL]string to series function Re:
You really ought to just try these things. ;) You'll be surprised at what you find. >> parse "one#two%three four" "#%" == ["one" "two" "three" "four"] >> Sterling > I would like to have a function to do > the following > 1)take two strings as arguments > a)arg one is source > b) arg two is delimiters > 2)return a series > > it would work like this: > > my-series: string-to-series "one#two%three four" "#% " > my-series is returned as ["one" "two" "three" "four"] > > BTW: I have a c function that does this. With > subsequent function calls, it is about 40 lines of > code. I'm pretty lost when it comes to parse, but > I bet the rebol function would be shorter. > thanks > tim
[REBOL] [REBOL]string to series function
I would like to have a function to do the following 1)take two strings as arguments a)arg one is source b) arg two is delimiters 2)return a series it would work like this: my-series: string-to-series "one#two%three four" "#% " my-series is returned as ["one" "two" "three" "four"] BTW: I have a c function that does this. With subsequent function calls, it is about 40 lines of code. I'm pretty lost when it comes to parse, but I bet the rebol function would be shorter. thanks tim