Example #1
0
def build_rightpart():
    """Build the right part of the fireball function."""
    # build in 1: (K dec)
    apply_card("put", 1)
    apply_slot(1, "dec")
    apply_card("K", 1)

    # build in 0: greg
    build_greg(0)

    # smash together to get (greg (K dec)) in 0
    smash()

    # copy it to 1.
    apply_card("put", 1)
    apply_slot(1, "zero")
    apply_card("get", 1)

    # build horace in 0.
    build_horace(0)

    # smash together to get (horace (greg (K dec))) in 0.
    smash()

    # Wrap with an S.
    apply_card("S", 0)

    # build ian in 1.
    build_ian(1)

    # smash together to get ((S (horace (greg (K dec)))) ian) in 0.
    smash()
Example #2
0
def build_rightpart():
    """Build the right part of the fireball function."""
    # build in 1: (K dec)
    apply_card("put", 1)
    apply_slot(1, "dec")
    apply_card("K", 1)

    # build in 0: greg
    build_greg(0)

    # smash together to get (greg (K dec)) in 0
    smash()

    # copy it to 1.
    apply_card("put", 1)
    apply_slot(1, "zero")
    apply_card("get", 1)

    # build horace in 0.
    build_horace(0)

    # smash together to get (horace (greg (K dec))) in 0.
    smash()

    # Wrap with an S.
    apply_card("S", 0)

    # build ian in 1.
    build_ian(1)

    # smash together to get ((S (horace (greg (K dec)))) ian) in 0.
    smash()
Example #3
0
def build_onemore():
    """(S ((S (horace (greg (K dec)))) (greg I)))"""
    apply_card("put", 1)
    apply_slot(1, "dec")
    apply_card("K", 1)
    build_greg(0)
    smash()

    # now should have (greg (K dec)) in 0.
    copy(0, 1)
    build_horace(0)
    smash()
    apply_card("S", 0)
    # now up to (S (horace (greg (K dec)))) in 0.

    # (greg I) is equivalent to K, so we can just apply slot 0 to K!
    apply_slot(0, "K")

    apply_card("S", 0)
Example #4
0
def build_onemore():
    """(S ((S (horace (greg (K dec)))) (greg I)))"""
    apply_card("put", 1)
    apply_slot(1, "dec")
    apply_card("K", 1)
    build_greg(0)
    smash()

    # now should have (greg (K dec)) in 0.
    copy(0,1)
    build_horace(0)
    smash()
    apply_card("S", 0)
    # now up to (S (horace (greg (K dec)))) in 0.

    # (greg I) is equivalent to K, so we can just apply slot 0 to K!
    apply_slot(0, "K")

    apply_card("S", 0)
Example #5
0
def build_applicative_y(n):
    """
    Build the applicative-order Y combinator into slot n.  Warning:
    touches slots 0 and 1 as well as slots n, n+1, and n+2.

    Supposedly, what we're building is:

    ((S 
      ((S (horace (greg I))) 
       ((S (horace (june1 ((S (horace (june1 kelly))) kelly)))) (greg ian))))
     ((S (horace (greg I))) 
      ((S (horace (june1 ((S (horace (june1 kelly))) kelly)))) (greg ian)))))

    """

    # Put (june1 kelly) in slot n.
    build_june1()
    copy(0, n) # move june1 to slot n
    build_kelly()
    apply_slotX_to_slotY(n, 0)

    # Put address of n in slot 0.
    build_num_in_slot(n, 0)

    # Put (horace (june1 kelly)) in slot n+1.
    build_horace(n+1)
    apply_slotX_to_slotY(n+1, n, yaddr=0)

    # Put (S (horace (june1 kelly))) in slot n+1.
    apply_card("S", n+1)

    # Put ((S (horace (june1 kelly))) kelly) in slot n+1.
    build_kelly() # always ends up in slot 0.
    apply_slotX_to_slotY(n+1, 0)

    # Put june1 in slot 0.
    build_june1()

    # Put address of n+1 in slot 1.
    build_num_in_slot(n+1, 1)

    # Put (june1 ((S (horace (june1 kelly))) kelly)) in slot 0.
    apply_slotX_to_slotY(0, n+1, yaddr=1)

    # Put horace in slot n.
    build_horace(n)

    # Put (horace (june1 ((S (horace (june1 kelly))) kelly))) in slot n.
    apply_slotX_to_slotY(n, 0)

    # Put (S (horace (june1 ((S (horace (june1 kelly))) kelly)))) in slot n.
    apply_card("S", n)

    # Put (greg ian) in slot 0.
    build_greg(0)
    build_ian(1)
    smash()

    # Put 
    # ((S (horace (june1 ((S (horace (june1 kelly))) kelly)))) (greg ian)) 
    # in slot n.
    apply_slotX_to_slotY(n, 0)
    
    # Put (greg I) in slot n+1.
    # It turns out (greg I) is equivalent to K!
    apply_card("put", n+1)
    apply_slot(n+1, "K")

    # Put (horace (greg I)) in slot n+2.
    build_horace(n+2)
    # Put address of n+1 in slot 1.
    build_num_in_slot(n+1, 1)
    apply_slotX_to_slotY(n+2, n+1, yaddr=1)

    # Put (S (horace (greg I))) in slot n+2.
    apply_card("S", n+2)

    # Put
    # ((S (horace (greg I))) 
    #  ((S (horace (june1 ((S (horace (june1 kelly))) kelly)))) (greg ian)))
    # in slot n+2.
    build_num_in_slot(n, 0)
    apply_slotX_to_slotY(n+2, n, yaddr=0)

    # Copy slot n+2 to slot n+1.
    copy(n+2, n+1)

    # Apply S to slot n+2, leaving the result in slot n+2.
    apply_card("S", n+2)

    # Apply contents of n+2 to contents of n+1, leaving the result in
    # slot n+2.
    #build_num_in_slot(n+1, 1)
    apply_slotX_to_slotY(n+2, n+1, yaddr=1)

    # Copy slot n+2 to slot n.
    copy(n+2, n)