sw-examples: test-for.sw3

Raw file here.
-- a small test of the new sfor and for statements:

op |for test> #=>
    the |start> => |true>
    print |----->
    sfor( var|x> in ssplit |abc>):
        sfor( var|y> in ssplit |xyz>):
            print (var|x> __ var|y>)
        end:
        print |----->
    end:
    the |middle> => |true>
    for( var|a> in split |abc>):
        print var|a>
    end:
    print |----->
    the |end> => |true>


-- Note, we can overload the range operator here,
-- because these are literal operator definitions,
-- which are distinct from function definitions.
range |*> #=> compile (|op: range> . |> . ssplit[" .. "] |_self>)
srange |*> #=> compile (|op: srange> . |> . ssplit[" .. "] |_self>)

-- memoizing versions:
-- ie, store the range after it is calculated,
-- so we don't have to recalculate it if we see it again.
-- Basically a memory vs cpu trade-off.
-- range |*> !=> compile (|op: range> . |> . ssplit[" .. "] |_self>)
-- srange |*> !=> compile (|op: srange> . |> . ssplit[" .. "] |_self>)


op |for test 2> #=>
    for( var|i> in range |0 .. 10 .. 2>):
        print var|i>
    end:


Home