learn rules: !=>


 !=> :
    description:
        op |ket> !=> sequence
        op |ket> !=>
            statements ... 

        associate the uncompiled sequence with op|ket>
        this "sequence" can be any type of BaseSequence
        on invocation of op|ket>, the sequence is compiled and then returned
        and further, op|ket> is set to that final result
        ie, this is a memoizing operator definition
        useful when you want to store the results of (expensive) computations so you don't need to recalculate them
        toy examples where this is useful are Fibonacci and factorials
        frequently used with label-descent

    examples:
        -- the standard example, Fibonacci:
        Fib |0> => |0>
        Fib |1> => |1>
        Fib |*> !=> Fib minus[1] |_self> ++ Fib minus[2] |_self>

        -- see what we know before invocation:
        sa: dump
            ------------------------------------------
            |context> => |Global context>

            Fib |0> => |0>
            Fib |1> => |1>
            Fib |*> !=> Fib minus[1]|_self> ++ Fib minus[2]|_self>
            ------------------------------------------

        -- now find Fibonacci 10:
        sa: Fib |10>
            |55>

        -- now see what we know:
        sa: dump
            ------------------------------------------
            |context> => |Global context>

            Fib |0> => |0>
            Fib |1> => |1>
            Fib |*> !=> Fib minus[1]|_self> ++ Fib minus[2]|_self>
            Fib |2> => |1>
            Fib |3> => |2>
            Fib |4> => |3>
            Fib |5> => |5>
            Fib |6> => |8>
            Fib |7> => |13>
            Fib |8> => |21>
            Fib |9> => |34>
            Fib |10> => |55>
            ------------------------------------------

    see also:
        => , .=> , +=> , #=> 

Home