Re: Discuss changing the behaviour of append()
- Posted by DerekParnell (admin) Jun 22, 2014
- 4035 views
An argument could be made that:
append(1,{}) -- {1,{}} prepend(1,{}) -- {{},1}
ought to be identical as {} is empty. (We assume the return value is a sequence).
i.e. it should not matter if you prepend or append an empty sequence you have added nothing.
Ahh... I see what you were trying to get across now.
However, "you have added nothing" is not accurate. The append()/prepend() functions add the second argument as a whole to form the new sequence element. An empty list is still a list; it is a something; an object. The append()/prepend() functions do not add the contents of a list to the first argument, but the entire object itself. For example ...
append({1}, {1}) --> gives {1, {1}} and not {1, 1} prepend({1}, {1}) --> gives {{1}, 1} and not {1, 1} --thus-- append({1}, {}) --> gives {1, {}} and not {1} prepend({}, {1}) --> gives {{}, 1} and not {1}
In all cases, append(X,Y) is identical in result to X & {Y} and prepend(X,Y) is identical in result to {Y} & X so that gives ...
object X, Y, Z X = {1} Y = {} Z = append(X, Y) --> gives {1, {}} Z = X & {Y} --> gives {1, {}} Z = prepend(X, Y) --> gives {{}, 1} Z = {Y} & X --> gives {{}, 1}
Mathmatically this means: {} is the identify under append. which would mean:
{} append A == A append {} -- == equivalence
I certainly could understand people reading things this way.
I know it doesn't fit with the mechanics of Eu.
If append(1,{}) were to give {1}, then it must follow that append(1, {2,3}) should give {1,2,3}, and that is not what it is intended to do. Likewise if prepend(1,{}) were to give {1}, then it must follow that prepend(1, {2,3}) should give {2,3,1}, and again, that is not what it is intended to do.
Appending an empty slice might appear as an error.
There is effectively nothing different between an empty slice and an empty sequence.

