context seq fn: compile


compile:
    description:
        compile input-seq
        unpack the input-seq and compile the result
        the first superposition is the operator name
        the rest are parameters to be fed to that operator
        NB: the parameters are only superpositions, not sequences
        If you require sequence parameters, then you need to do it indirectly using a wrapper function

    examples:
        -- define a function, then compile it:
        fn (*,*,*) #=> 2|__self0> . 3|__self1> . 5|__self2> . 7|__self3>
        compile (|op: fn> . |input> . |a> . |b> . |c>)
            2|input> . 3|a> . 5|b> . 7|c>

        -- Now, if you require sequence parameters, you need a wrapper function:
        wrapper-fn (*,*,*) #=> fn(seq |__self1>, seq |__self2>, seq |__self3>) seq |__self0>

        -- Then we define our sequence parameters
        -- They can be anything:
        seq |input> => |input seq>
        seq |a> => |seq 1>
        seq |b> => |seq 2>
        seq |c> => |seq 3>

        -- Now, compile it:
        compile (|op: wrapper-fn> . |input> . |a> . |b> . |c>)
            2|input seq> . 3|seq 1> . 5|seq 2> . 7|seq 3>


        -- use the compile operator to define the expand-srange operator:
        -- NB: we can use other operators in place of srange() too
        -- For foo() simply replace |op: srange> with |op: foo>
        -- And you will probably want to change ssplit[" .. "] to something else too
        expand-srange |*> #=>
            unlearn[the] |result>
            the |result> => compile (|op: srange> . |> . ssplit[" .. "] |__self>)
            value-if( do-you-know the |result>, the |result>, |__self>)

        -- now apply it:
        expand-srange |3 .. 8>
            |3> . |4> . |5> . |6> . |7> . |8>

        -- an example with categories:
        expand-srange |number: 8 .. number: 11>
            |number: 8> . |number: 9> . |number: 10> . |number: 11>

        -- an example with a specified step:
        expand-srange |3 .. 9 .. 2>
            |3> . |5> . |7> . |9>

        -- if applied to a non-range, then return it unchanged:
        expand-srange |alpha>
            |alpha>

        -- if applied to a badly defined range, then return it unchanged:
        expand-srange |5 .. gamma>
            |5..gamma>

    see also:
        apply

Home