learn rules: =>


 => :
    description:
        op |ket> => sequence
        op general-sequence => sequence
        standard learn rule
        associate a ket/superposition/sequence with an operator/ket pair
        once defined, any invocation of "op|ket>" will return the associated sequence
        if "op|ket>" is invoked and it hasn't been defined by some kind of learn rule, it will return the empty ket |>
        if the right hand side is a general sequence, it will be compiled to a sequence before being associated with the op/ket

        if the learn rule has the second form, the general sequence on the left of the learn rule symbol will be compiled to a sequence
        then for each ket in that sequence we learn op ket => sequence
        |_self> is then set to that ket, so you can access it if needed

    examples:
        -- associate a ket:
        -- ie, learn Mary's age:
        age |Mary> => |37>

        -- associate a superposition:
        -- ie, learn Sam's friends:
        friends |Sam> => |Tom> + |Matt> + |Emma> + |Mary> + |Luke>

        -- associate a sequence:
        -- in this case, the first 8 primes
        integer |sequence> => |2> . |3> . |5> . |7> . |11> . |13> . |17> . |19>

        -- once the above have been defined, we can see what we have using the dump command:
        sa: dump
            ------------------------------------------
            |context> => |Global context>

            age |Mary> => |37>
            friends |Sam> => |Tom> + |Matt> + |Emma> + |Mary> + |Luke>
            integer |sequence> => |2> . |3> . |5> . |7> . |11> . |13> . |17> . |19>
            ------------------------------------------

        -- and we can now invoke them in the shell:
        sa: age |Mary>
            |37>

        sa: friends |Sam>
            |Tom> + |Matt> + |Emma> + |Mary> + |Luke>

        sa: integer |sequence>
            |2> . |3> . |5> . |7> . |11> . |13> . |17> . |19>


        -- an example of the second form:
        -- first, learn the days of the week, and the weekend:
        list-of |weekdays> => split[" "] |Monday Tuesday Wednesday Thursday Friday>
        list-of |weekend> => split[" "] |Saturday Sunday>

        -- now say a shop opens 9am - 5pm on weekdays, and 11am to 4pm on weekends
        -- here is a compact way to learn that:
        open list-of |weekdays> => |9 am>
        close list-of |weekdays> => |5 pm>
        open list-of |weekend> => |11 am>
        close list-of |weekend> => |4 pm>

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

            list-of |weekdays> => |Monday> + |Tuesday> + |Wednesday> + |Thursday> + |Friday>
            list-of |weekend> => |Saturday> + |Sunday>

            open |Monday> => |9 am>
            close |Monday> => |5 pm>

            open |Tuesday> => |9 am>
            close |Tuesday> => |5 pm>

            open |Wednesday> => |9 am>
            close |Wednesday> => |5 pm>

            open |Thursday> => |9 am>
            close |Thursday> => |5 pm>

            open |Friday> => |9 am>
            close |Friday> => |5 pm>

            open |Saturday> => |11 am>
            close |Saturday> => |4 pm>

            open |Sunday> => |11 am>
            close |Sunday> => |4 pm>
            ------------------------------------------

    see also:
        learn, unlearn, +=> , .=> , #=> , !=> 

Home