Max Alekseyev on Tue, 08 Jul 2014 02:14:54 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: concat([])


Hi Jack,

I believe the general purpose of concat() is to concatenate vectors,
while strings are viewed as a special type of vectors (of characters).
>From this perspective, the default type of concat result is 'vector',
unless it is specifically asked to concatenate strings (in which case
result type is 'string').
That's why I think concat([]) should not be much different from

? concat([[]])
%3 = []

Regards,
Max


On Mon, Jul 7, 2014 at 7:23 PM, Jack Brennen <jfb@brennen.net> wrote:
> Or should it be "" ?
>
> "ab" <- concat(["a","b"])
> "a"  <- concat(["a"])
> ""   <- concat([])
>
> I guess it's ambiguous, so it is rejected?
>
> Note that concat() has some serious weirdnesses
> when you mix strings with other types...
> This is version 2.5.5 behavior:
>
> ? concat(["",1,x,y])
> %1 = "1xy"
> ? concat([1,x,y,""])
> %2 = "[1, x, y]"
> ? concat([[],x,y,""])
> %3 = "[x, y]"
> ? concat([[],x,y,[]])
> %4 = [x, y]
> ? concat(["",x,y,[]])
> %5 = "xy[]"
>
> It seems as if it progresses using non-string-based concatenation
> until it finds a string, at which point it converts the result
> so far to a string and then continues?
>
>
>
>
>
> On 7/7/2014 3:34 PM, Max Alekseyev wrote:
>>
>> ? concat([])
>>    ***   at top-level: concat([])
>>    ***                 ^----------
>>    *** concat: domain error in concat: vector = []
>>    ***   Break loop: type 'break' to go back to GP prompt
>>
>>
>> Should it simply return [] ?
>>
>> Regards,
>> Max
>>
>>
>>
>