Re: Discuss changing the behaviour of append()
- Posted by gimlet Jun 07, 2014
- 4467 views
DerekParnell said...
Would it be a bad thing to remove this restriction such that when appending to an atom, Euphoria would automatically build a new sequence? This would be similar to how concatenation works.
Simple answer: not such a good idea.
The function append is:
fn(seq, obj) -> seq
The proposed change would require that append be
fn(obj, obj) -> seqwhich makes the test part of append whether you want it or not.
It would seem that append is wanted most often when the first parameter is a sequence....
As to the code being 'ugly' ..
function F(object A, object B) sequence x if atom(A) then x = append({A}, B) else x = append(A, B) end if return x end function
try
function F(object A, object B) if atom(A) then A = {A] end if return append(A, B) end function
or, ditching the function
sequence x if atom(A) then x = append({A},B) else x = append(A,B) end if