# dup == [[]] [i] map i

## icpdesign — 2005-09-20 14:45:26

    I could not understand how is that dup == [[]] [i] map i

    If map removes the

    My understanding is that the map combinator removes the list ([[]])

    and the quotation ([i]) then constructs a new list by applying the

    program (i) to each member of the given list ([])

    or

    [] i == id

    so how come that

        5 [[]] [i] map i ==> 5 5

    I am certainly missed something, thank for your help

    Taoufik Dachraoui

## William Tanksley, Jr — 2005-09-20 22:58:42

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

     > I could not understand how is that dup == [[]] [i] map i

    > My understanding is that the map combinator removes the list ([[]])

    > and the quotation ([i]) then constructs a new list by applying the

    > program (i) to each member of the given list ([])

     The trick is in seeing where map gets the members that are going to be

    placed into the list -- it ALWAYS takes the top thing that's left on

    the stack, no matter whether it was produced by the program being

    mapped or whether it was already on the stack. The really tricky part

    is that map preserves the stack, and after each program runs it

    replaces the stack the same way it was when the program started.

     > Taoufik Dachraoui

     -Billy

## icpdesign — 2005-09-21 12:35:32

    I am sorry, but i am still lost with this. I understood from the

    tutorial page (Joy's web site) that the map combinator executes the

    quotation on each element of the given list and puts the results in

    a new list that is pushed on the stack, and the net effect is that

    the new constructed list replaces the quotation and the list.

    My problem is by following this definition of map i do the following:

    run quotation [i] on the first element of the list ; that is []

    and push the result on a new list; the result is a new empty list,

    since [] i == id

    In other words is the following true and what is the proof:

    dup == [[]] [i] map i

    Thank you for enlightening me, i am lost here, and would like to

    understand how things work.

    Taoufik Dachraoui

    --- In concatenative@yahoogroups.com, "William Tanksley, Jr"

    <wtanksleyjr@g...> wrote:

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

    > > I could not understand how is that dup == [[]] [i] map i

    >

    > > My understanding is that the map combinator removes the list

     ([[]])

     > > and the quotation ([i]) then constructs a new list by applying

     the

     > > program (i) to each member of the given list ([])

    >

    > The trick is in seeing where map gets the members that are going

     to be

     > placed into the list -- it ALWAYS takes the top thing that's left

     on

     > the stack, no matter whether it was produced by the program being

    > mapped or whether it was already on the stack. The really tricky

     part

     > is that map preserves the stack, and after each program runs it

    > replaces the stack the same way it was when the program started.

    >

    > > Taoufik Dachraoui

    >

    > -Billy

## icpdesign — 2005-09-21 12:45:46

    Also,

    [] cons == [[]] [i] map

    knowing that the combinator i is used to uncons a quotation ([A] i

    == A)

    it looks puzzling for me, but this is because i am certainly missing

    something

    Thank you

    Taoufik Dachraoui

    --- In concatenative@yahoogroups.com, "William Tanksley, Jr"

    <wtanksleyjr@g...> wrote:

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

    > > I could not understand how is that dup == [[]] [i] map i

    >

    > > My understanding is that the map combinator removes the list

     ([[]])

     > > and the quotation ([i]) then constructs a new list by applying

     the

     > > program (i) to each member of the given list ([])

    >

    > The trick is in seeing where map gets the members that are going

     to be

     > placed into the list -- it ALWAYS takes the top thing that's left

     on

     > the stack, no matter whether it was produced by the program being

    > mapped or whether it was already on the stack. The really tricky

     part

     > is that map preserves the stack, and after each program runs it

    > replaces the stack the same way it was when the program started.

    >

    > > Taoufik Dachraoui

    >

    > -Billy

## icpdesign — 2005-09-21 13:57:20

    I found an example that will probably show why I am puzzled:

    5 [[100]] [i] map stack.

    => [[100] 5]

    the prvious example shows how the i combinator unquote the list

    [100] (result = 100) and pushed the result into the result list of

    map, thus :

    [[100]] [i] map => [100]

    remark: the top element (5) of the stack is not used at all

    (apparently)

    But the following seems incorrect, because instead of unquoting the

    list [] (the first element of the list passed to map) and push empty

    into the result list thus giving as result an empty list, map return

    the list [5]

    5 [[]] [i] map stack.

    => [[5] 5]

    I thought that [[X]] [i] map will result in [X] even when X is

    nothing, but it seems that there is a special use of empty lists

    Can someone please explain this, what is wrong in my reasoning?

    Thanks

    Taoufik Dachraoui

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

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

     > Also,

    >

    > [] cons == [[]] [i] map

    >

    > knowing that the combinator i is used to uncons a quotation ([A] i

    > == A)

    >

    > it looks puzzling for me, but this is because i am certainly

     missing

     > something

    >

    > Thank you

    >

    > Taoufik Dachraoui

    >

    > --- In concatenative@yahoogroups.com, "William Tanksley, Jr"

    > <wtanksleyjr@g...> wrote:

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

    > > > I could not understand how is that dup == [[]] [i] map i

    > >

    > > > My understanding is that the map combinator removes the list

    > ([[]])

    > > > and the quotation ([i]) then constructs a new list by applying

    > the

    > > > program (i) to each member of the given list ([])

    > >

    > > The trick is in seeing where map gets the members that are going

    > to be

    > > placed into the list -- it ALWAYS takes the top thing that's

     left

     > on

    > > the stack, no matter whether it was produced by the program being

    > > mapped or whether it was already on the stack. The really tricky

    > part

    > > is that map preserves the stack, and after each program runs it

    > > replaces the stack the same way it was when the program started.

    > >

    > > > Taoufik Dachraoui

    > >

    > > -Billy

## William Tanksley, Jr — 2005-09-22 04:57:16

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

     > In other words is the following true and what is the proof:

    > dup == [[]] [i] map i

     Yes, it's true. It's the result of what I consider a kludge, though,

    so I can't give a clean proof. I can give you another example, though

    -- what happens when you run:

    5  [[] [] []] map i

    ?

     > Taoufik Dachraoui

     -Billy

## phimvt@lurac.latrobe.edu.au — 2005-09-30 04:59:07

    On Wed, 21 Sep 2005, icpdesign wrote:

     > I found an example that will probably show why I am puzzled:

    >

    > 5 [[100]] [i] map stack.

    > => [[100] 5]

     [..]

    I am sorry I have not been around to answer your question about

    dup being definable in a (rather clever!) way, but Billy did

    a good job of it already. So I will try to clarify from the assumption

    that you puzzlement arises from the behaviour of map.

    The most common usage is map being used on a list together with

    a unary operator, say the squaring operator dup *. Then what is

    below the list is not affected:

       42 [1 2 3 4] [dup *] map    ==   42 [1 4 9 16]

    Instead of the dup * one could have 10 *, as in

       42 [1 2 3 4] [10 *] map   ==   42 [10 20 30 40]

    Note that 10 has to be pushed 4 times for the multiplications.

    If you do not like that, here is another version:

       42 10 [1 2 3 4] [*] map   ==  42 10 [10 20 30 40]

    Explanation: map steps through the list, successively pushing

    its members onto the stack, applies the function ([dup *],

    [10 *], [*] in the examples so far), and collects the results

    in a list of the same length as the original.

    Exactly the same explanation also holds for the following

    (rather curious) uses of map, where the function is [pop]

        42 [1 2 3 4] [pop] map   ==   42 [42 42 42 42]

    Then you can also do

        42 [1 2 3 4] [pop] map i  ==   42 42 42 42 42

    or even

        42 [1] [pop] map i   ==   42 42

    or even

        42 ["hello"] [pop] map i  ==  42 42

    or even

        42 [[]] [pop] map i  ==  42 42

    I can see no reason why such curious uses should be forbidden -

    any language allows curious uses.

    I hope this helps

      - Manfred