hi list,

here a separation (series division)  func on steroids, which uses parse and
some smart indexing .

it supports, /SKIP /AT /ONLY options directly as refinements and the
separator, if its a series, will be cycled at each separation (unless you
use the /only refinement:)

SEPARATE: func [
    "separates the serie into a serie of the same type using a specified
separator and many flexible options"
    serie [series!] "series you wish to separate"
    separator "if this is a series, it cycles each item at each separation."
    /only "if separator is a series, insert it as-is at each separation."
    /skip skip-count
    /at offset "note, use 0 to insert at head of (before) series!"
    /local here
][

    skip-count: (any [skip-count 1]) - 1 + either only[length? separator]
[1]
    if at [
        serie: system/words/at serie offset
        ; add an item in serie so algorythm adds something after it, instead
of after first char
        if offset = 0 [
            serie: head insert serie "#"
        ]
    ]
    parse/all serie [any [
        here: skip
        (
            unless empty? next here [
                either all [ series? separator not only] [
                    insert next here  any [
                        ; cycle through separator
                        all [not empty? separator first separator ]
                        first separator: head separator
                    ]
                    separator: system/words/skip separator 1 ; error free
way to go to next item
                ][
                    insert next here separator
                ]
            ]
        ) skip-count skip ]
    ]

    if offset = 0 [
        ; remove the first item of series, which we added
        remove serie
    ]

    head serie
]

>> separate/skip  "1234567890" "."  2
== "1.23.45.67.89.0"

>> separate/skip/at   "1234567890" "."  2 0
== ".12.34.56.78.90"
>>

>> separate/at/skip  "1234567890" ".-"  0  2
== ".1234-5678.90"

>> separate/at/skip/only  "1234567890" ".-"  0  4
== ".-1234.-5678.-90"

and a cool advanced example  :-)

>> separate/at/skip  "123112321233" ": "  2  2
== "12:31 12:32 12:33"

also usefull for this:

>> do separate  [12 34 23 12] '+
== 81


HAVE FUN !  :-)

-MAx



On 7/12/07, Alessandro Manotti <[EMAIL PROTECTED]> wrote:
>
> Hello, I created this small function: composeBlock.
>
> >> composeBlock: func [argDivider [string!] argData [block!] /local
> newBlock
> ][newBlock: [] foreach i argData [ app
> end newBlock reduce [argDivider i] ] return copy next newBlock ]
> >>
> >> composeBlock "," [1 2 3 4 5]
> == [1 "," 2 "," 3 "," 4 "," 5]
> >>
>
>
> On 7/12/07, Tom <[EMAIL PROTECTED]> wrote:
> >
> >
> > Carlos Lorenz wrote:
> > > Hi ppl
> > >=20
> > >=20
> > >=20
> > > a: [1 2 3]
> > >> parse a [any [blk: skip (unless empty? next blk [insert next blk
> ","])
> > >> skip
> > >> ] ]
> > >>
> > >> =3D=3D [ 1 "," 2 "," 3" ]
> > >>
> > >=20
> > > Whenever I read things like that I feel like I miss a lot about the
> pow=
> > er of
> > > REBOL parse dialect.
> > >=20
> > > I=B4ll leave a suggestion to the gurus on parsing: please write some
> "p=
> > arsing
> > > for dummies" tutorial. It would be of great help!
> > >=20
> >
> > slightly shorter version of Max's
> >
> > parse a [any[skip here: (all[not tail? here insert here ","])skip]]
> > --
> > To unsubscribe from the list, just send an email to
> > lists at rebol.com with unsubscribe as the subject.
> >
> >
>
>
> --
>
>
> --Alessandro
>
>
> --
> To unsubscribe from the list, just send an email to
> lists at rebol.com with unsubscribe as the subject.
>
>


-- 
To unsubscribe from the list, just send an email to 
lists at rebol.com with unsubscribe as the subject.

Reply via email to