On Wed, Nov 5, 2014 at 7:53 AM, Alexander Burger <a...@software-lab.de> wrote:
> Hi Christophe,

Hi Alex, hi all.

> I can assure you that 'conc' always evaluates its first arg.

OK, then the reason why there is no need to quote A in the example at:
http://www.software-lab.de/doc/refC.html#conc
is that A is not really needed as a symbol because conc changes
directly the value it links to.

>> (dm push> (elt)
>>    (conc (:: elts) (list elt)) )  # this doesn't work
>
> 'conc' destructively concatenates the arguments. This means that the
> pointer to the second list is stored in the CDR of the last cell of the
> first list.
>
> But here you pass (:: elts) as the first argument, which is the property
> cell in the symbol. That doesn't make much sense.

OK

> What you could do is
>
>    (dm push> (Elt)
>       (conc (: elts) (list Elt)) )
>
> But this works only if the property 'elts' is not empty (NIL). Because
> despite the fact that concatenating NIL with a second list returns that
> list, there is no storing in any CDR as a side effect, so the result of
> the 'conc' is lost.
>
> Thus, if you want to start with empty 'elts', you might do
>
>    (dm push> (Elt)
>       (=: elts (conc (: elts) (list Elt))) )
>
> In this way you don't lose the result of the first 'conc'.
>
>
>> So is there a mean to implement the problematic line ?
>> (=: elts (append (: elts) elt))
>
> This would be correct, and is basically the same as my proposal, just:
>
>> but found it maybe not efficient (recreates the list?).
>
> Correct. 'conc' and 'append' are equivalent to a certain degree, at
> least as far as the return value is concerned. But 'append' copies all
> arguments except for the last one.

Great. I changed to your version which also makes the tests pass.

> Having said all this, if you want to implement 'push', why don't
> you use 'push' directly?
>
>    (dm push> (Elt)
>       (push (:: elts) Elt)) )
>
> This inserts the elements in opposite order as with 'conc' though, but
> that is what push is after all:
>
>   […]

If it was only for me, that would be OK.
I chose to «push», which I call «Add_to» in my language, at the right side
of the list. I believe it's more natural for beginners (least astonishment)

Reply via email to