Karim Belabas on Tue, 08 Jul 2014 08:50:31 +0200 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: concat([]) |
* Jack Brennen [2014-07-08 01:23]: > 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[]" This is consistent with the documentation: concatenation from left to right. > 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? Exactly, this follows from the rule above. This is not stated in the docs (I'll add it) but the basic 2-argument form concat(x, y) returns a t_STR if either x or y is a t_STR. In fact, the string obtained from concatenating the printed representations of x and y (without the enclosing quotes, for the one which is a t_STR) Note that using this behavious is somewhat deprecated now that Str accepts an arbitrary number of arguments: Str(x,y,[]) is more natural (and less surprising) than concat(["",x,y,[]]) Cheers, K.B. -- Karim Belabas, IMB (UMR 5251) Tel: (+33) (0)5 40 00 26 17 Universite Bordeaux 1 Fax: (+33) (0)5 40 00 69 50 351, cours de la Liberation http://www.math.u-bordeaux1.fr/~kbelabas/ F-33405 Talence (France) http://pari.math.u-bordeaux1.fr/ [PARI/GP] `