• My take on DO, was Re: push for memory safe languages ...

    From albert@albert@spenarnc.xs4all.nl to comp.lang.forth on Wed Mar 13 14:30:00 2024
    From Newsgroup: comp.lang.forth

    - DOxxx performs the loop
    - Indices are integers.
    - forms of DO
    one-bound {BODY} DO) \ 0 ... one-bound-1
    one-bound {BODY} DO] \ 1 ... one-bound
    b1 b2 {BODY} DO[] \ b1 .. b2
    b1 b2 stride {BODY} DO[..] \ b1 b1+stride b1+2*stride .. b2

    Maybe
    b1 b2 {BODY} DO[) \ b1 .. b2-1
    to accommodate
    array length OVER + {BODY} DO[)

    Note the stride is now constant obviously.
    If it is negative, the loop goes down.
    If you want to straddle from positive to negative (addresses?),
    program it explicitly and conspicuously.

    Note 1
    The [ ) convention comes from mathematics, example:
    [1,9] interval 1 2 3 4 5 6 7 8 9
    [1,9) interval 1 2 3 4 5 6 7 8
    (0,9) interval 1 2 3 4 5 6 7 8

    Note 2
    {BODY} leans heavily on [: ;] presence. (Or ciforth's { } )

    Note 3
    If you want to change the stride mid-program, you have to
    use BEGIN WHILE REPEAT, as you should have done in the first place.

    The four DO's replace the four don't's : ?DO DO LOOP +LOOP .

    Groetjes Albert
    --
    Don't praise the day before the evening. One swallow doesn't make spring.
    You must not say "hey" before you have crossed the bridge. Don't sell the
    hide of the bear until you shot it. Better one bird in the hand than ten in
    the air. First gain is a cat purring. - the Wise from Antrim -
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From minforth@minforth@gmx.net (minforth) to comp.lang.forth on Wed Mar 13 13:53:14 2024
    From Newsgroup: comp.lang.forth

    Also handy When you have list types:

    (( 1 2 3 5 7 11 13 17 )) DO-WITH ..

    or

    (( H2 O2 CO CO2 )) DO-WITH ..
    where H2 et al can be numbers/addresses or arrays/strings
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From dxf@dxforth@gmail.com to comp.lang.forth on Fri Mar 15 16:34:49 2024
    From Newsgroup: comp.lang.forth

    On 14/03/2024 12:30 am, albert@spenarnc.xs4all.nl wrote:
    - DOxxx performs the loop
    - Indices are integers.
    - forms of DO
    one-bound {BODY} DO) \ 0 ... one-bound-1
    one-bound {BODY} DO] \ 1 ... one-bound
    b1 b2 {BODY} DO[] \ b1 .. b2
    b1 b2 stride {BODY} DO[..] \ b1 b1+stride b1+2*stride .. b2

    Maybe
    b1 b2 {BODY} DO[) \ b1 .. b2-1
    to accommodate
    array length OVER + {BODY} DO[)

    Note the stride is now constant obviously.
    If it is negative, the loop goes down.
    If you want to straddle from positive to negative (addresses?),
    program it explicitly and conspicuously.

    Note 1
    The [ ) convention comes from mathematics, example:
    [1,9] interval 1 2 3 4 5 6 7 8 9
    [1,9) interval 1 2 3 4 5 6 7 8
    (0,9) interval 1 2 3 4 5 6 7 8

    Note 2
    {BODY} leans heavily on [: ;] presence. (Or ciforth's { } )

    Note 3
    If you want to change the stride mid-program, you have to
    use BEGIN WHILE REPEAT, as you should have done in the first place.

    The four DO's replace the four don't's : ?DO DO LOOP +LOOP .

    All these alternatives to DO LOOP that folks propose don't get off the
    ground because the 'lesser programmers' for whom they're intended don't eventuate.

    --- Synchronet 3.20a-Linux NewsLink 1.114