# defining newmap and oldmap (map) in Joy

## icpdesign — 2005-09-28 20:05:43

    DEFINE

    dig == [] swap 1 - [cons] times # pop nth element and push on top

               dip;

    peek == [] swap 1 - [cons] times # read nth element and push

                  swap dup [swap] dip swap dip; # on top

    # input at iteration 1: [] [P] [S1 S2 ... Sn]

    # input at iteration i : [Ri-1 ... R1] [P] [Si ... Sn]

    nmap ==  [null]

                  [pop pop]

                  [uncons # [Ri-1 ... R1] [P] Si [Si+1 ... Sn]

                   2 dig #  [Ri-1 ... R1] [P] [Si+1 ... Sn] Si

                   3 peek infra # [Ri-1 ... R1] [P] [Si+1 ... Sn] Si [P]

    infra

                   4 dig # [P] [Si+1 ... Sn] Ri [Ri-1 ... R1]

                   cons #  [P] [Si+1 ... Sn] [Ri Ri-1 ... R1]

                   3 dig # [Si+1 ... Sn] [Ri Ri-1 ... R1] [P]

                   3 dig # [Ri Ri-1 ... R1] [P] [Si+1 ... Sn]

                  nmap]

                  ifte;

    # input at iteration 1: [] [P] [S1 S2 ... Sn]

    # input at iteration i : [Ri-1 ... R1] [P] [Si ... Sn]

    omap ==  [null]

                  [pop pop]

                  [uncons # [Ri-1 ... R1] [P] Si [Si+1 ... Sn]

                   3 dig # [Ri-1 ... R1] Si [Si+1 ... Sn] [P]

                   4 dig # Si [Si+1 ... Sn] [P] [Ri-1 ... R1]

                   [] cons cons cons cons # [Si [Si+1 ... Sn] [P] [Ri-1

    ... R1]]

                   [stack] dip # [T] [Si [Si+1 ... Sn] [P] [Ri-1 ... R1]]

                   uncons uncons

                   uncons uncons #  [T] Si [Si+1 ... Sn] [P] [Ri-1 ...

    R1] []

                   pop #  [T] Si [Si+1 ... Sn] [P] [Ri-1 ... R1]

                   4 dig 5 dig #  [Si+1 ... Sn] [P] [Ri-1 ... R1] Si [T]

                   cons #  [Si+1 ... Sn] [P] [Ri-1 ... R1] [Si T]

                   3 peek #  [Si+1 ... Sn] [P] [Ri-1 ... R1] [Si T] [P]

                   infra #  [Si+1 ... Sn] [P] [Ri-1 ... R1] [Ri ...]

                   uncons pop # [Si+1 ... Sn] [P] [Ri-1 ... R1] Ri

                   2 dig #  [Si+1 ... Sn] [P] Ri [Ri-1 ... R1]

                   cons # [Si+1 ... Sn] [P] [Ri Ri-1 ... R1]

                   2 dig 3 dig # [Ri Ri-1 ... R1] [P]  [Si+1 ... Sn]

                  omap]

                  ifte;

    newmap == [] 2 dig 3 dig nmap reverse;

    oldmap ==  [] 2 dig 3 dig omap reverse;

    END.

    I did not find a primitive reverse in Joy; so i have to

    find a defintion for reverse (when i have more time).

    newmap and oldmap use the following Joy primitives: pop cons

    uncons swap dup dip times infra null ifte.

    As we can see from the definitions newmap is simpler than oldmap;

    can we do better, in the sense of using the minimum number of

    primitives

    I would like to define the maximum (all) number of Joy primitives

    using

    dig peek cons pop i and few other combinators; the less the better.

    Kind regards

    Taoufik Dachraoui

## icpdesign — 2005-09-29 08:02:21

    --- In concatenative@yahoogroups.com, "icpdesign"

    <taoufik.dachraoui@w...> wrote:

     > DEFINE

    > dig == [] swap 1 - [cons] times # pop nth element and push on top

    >            dip;

    > peek == [] swap 1 - [cons] times # read nth element and push

    >               swap dup [swap] dip swap dip; # on top

    >

    > # input at iteration 1: [] [P] [S1 S2 ... Sn]

    > # input at iteration i : [Ri-1 ... R1] [P] [Si ... Sn]

    > nmap ==  [null]

    >               [pop pop]

    >               [uncons # [Ri-1 ... R1] [P] Si [Si+1 ... Sn]

    >                2 dig #  [Ri-1 ... R1] [P] [Si+1 ... Sn] Si

    >                3 peek infra # [Ri-1 ... R1] [P] [Si+1 ... Sn] Si

     [P]

     > infra

    >                4 dig # [P] [Si+1 ... Sn] Ri [Ri-1 ... R1]

    >                cons #  [P] [Si+1 ... Sn] [Ri Ri-1 ... R1]

    >                3 dig # [Si+1 ... Sn] [Ri Ri-1 ... R1] [P]

    >                3 dig # [Ri Ri-1 ... R1] [P] [Si+1 ... Sn]

    >               nmap]

    >               ifte;

    > # input at iteration 1: [] [P] [S1 S2 ... Sn]

    > # input at iteration i : [Ri-1 ... R1] [P] [Si ... Sn]

    > omap ==  [null]

    >               [pop pop]

    >               [uncons # [Ri-1 ... R1] [P] Si [Si+1 ... Sn]

    >                3 dig # [Ri-1 ... R1] Si [Si+1 ... Sn] [P]

    >                4 dig # Si [Si+1 ... Sn] [P] [Ri-1 ... R1]

    >                [] cons cons cons cons # [Si [Si+1 ... Sn] [P] [Ri-1

    > ... R1]]

    >                [stack] dip # [T] [Si [Si+1 ... Sn] [P] [Ri-1 ...

     R1]]

     >                uncons uncons

    >                uncons uncons #  [T] Si [Si+1 ... Sn] [P] [Ri-1 ...

    > R1] []

    >                pop #  [T] Si [Si+1 ... Sn] [P] [Ri-1 ... R1]

    >                4 dig 5 dig #  [Si+1 ... Sn] [P] [Ri-1 ... R1] Si

     [T]

     >                cons #  [Si+1 ... Sn] [P] [Ri-1 ... R1] [Si T]

    >                3 peek #  [Si+1 ... Sn] [P] [Ri-1 ... R1] [Si T] [P]

    >                infra #  [Si+1 ... Sn] [P] [Ri-1 ... R1] [Ri ...]

    >                uncons pop # [Si+1 ... Sn] [P] [Ri-1 ... R1] Ri

    >                2 dig #  [Si+1 ... Sn] [P] Ri [Ri-1 ... R1]

    >                cons # [Si+1 ... Sn] [P] [Ri Ri-1 ... R1]

    >                2 dig 3 dig # [Ri Ri-1 ... R1] [P]  [Si+1 ... Sn]

    >               omap]

    >               ifte;

    >

    > newmap == [] 2 dig 3 dig nmap reverse;

    > oldmap ==  [] 2 dig 3 dig omap reverse;

    > END.

    >

    > I did not find a primitive reverse in Joy; so i have to

    > find a defintion for reverse (when i have more time).

    >

    > newmap and oldmap use the following Joy primitives: pop cons

    > uncons swap dup dip times infra null ifte.

    >

     Just a correction:

    newmap uses: pop null uncons cons dup infra ifte dig peek

    oldmap (map) uses: pop null uncons cons dup

             infra ifte dig peek stack

     > As we can see from the definitions newmap is simpler than oldmap;

    > can we do better, in the sense of using the minimum number of

    > primitives

    >

    > I would like to define the maximum (all) number of Joy primitives

    > using

    > dig peek cons pop i and few other combinators; the less the better.

    >

    > Kind regards

    > Taoufik Dachraoui