# IRC log for #rosettacode, 2012-09-30

All times shown according to UTC.

Time Nick Message
00:16 mwn3d_phone1 joined #rosettacode
02:29 mwn3d_phone joined #rosettacode
02:43 armitage81 joined #rosettacode
06:21 mwn3d_phone1 joined #rosettacode
08:08 GlitchMr joined #rosettacode
09:26 mischi joined #rosettacode
10:42 GlitchMr reduce(lambda a, b: {b: a}, reversed(list("Hello, world!") + [{}]))
10:42 GlitchMr I've feeling I abuse Python
10:54 GlitchMr Also...
10:54 GlitchMr sum(([1], [2], [3], [4, 5]), []) # works, gives [1, 2, 3, 4, 5]
10:54 GlitchMr sum(("1", "2", "3", "45"), "") # doesn't work?
10:54 GlitchMr Aren't string iterables?
10:55 GlitchMr strings*
10:55 GlitchMr Perhaps...
10:55 GlitchMr str("".join(sum(map(list, ("1", "2", "3", "45")), [])))
11:15 BenBE joined #rosettacode
11:15 BenBE joined #rosettacode
14:09 kpreid GlitchMr: the elements of a string are themselves strings, not integers
14:10 kpreid (if I remember python right)
14:11 GlitchMr Elements of list themselves don't matter
14:11 GlitchMr If I would have list of strings, it would work too
14:11 GlitchMr It's just that + is addition, except I've feeling it has special code to refuse doing that on strings
14:12 GlitchMr (why?)
14:12 kpreid I get: TypeError: unsupported operand type(s) for +: 'int' and 'str'
14:12 kpreid that's pretty clear
14:12 kpreid sum starts with 0, so you get 0 + "1"
14:12 kpreid ...heh.
14:13 kpreid I tried sum(strings, "") and got: TypeError: sum() can't sum strings [use ''.join(seq) instead]
14:13 kpreid that's got to be on purpose
14:13 kpreid well, ''.join is probably a much better idea anyway
14:14 kpreid (pairwise string concatenation is O(n^2), something which knows that it's working on strings can be O(n))
14:26 kpreid joined #rosettacode
15:36 kpreid_ joined #rosettacode
15:37 eMBee why does "1" + "2" + "3" + "45" have to be pairwise concatenation? and why could sum() not know that it's working on strings? pike can handle that: `+(); is the function called for the + operator:  `+(({1}), ({2}), ({3}), ({4, 5})); Result: ({ 1, 2, 3, 4, 5 }); `+("1", "2", "3", "45"); Result: "12345"
15:56 mwn3d_phone1 joined #rosettacode
16:11 kpreid eMBee: it doesn't
16:11 kpreid for example, the Java compiler rewrites a+b+c+d into a smart concatenation
16:12 kpreid and you could have a data-type implementation which either is just lazy (and doesn't concatenate until the value is needed, at which time it can be smart)
16:12 kpreid or is a balanced tree (e.g. ropes)
16:14 kpreid as to why 'sum' rejects strings, I don't know, but I would guess it was felt that the type-pun was undesirable
16:23 mwn3d_phone1 joined #rosettacode
16:56 * eMBee agrees
16:57 eMBee actually, i am guessing that developers never saw a connection between sum and +
20:33 armitage81 joined #rosettacode
22:48 mwn3d_phone joined #rosettacode
22:49 mwn3dsphonesucks joined #rosettacode
23:12 kpreid joined #rosettacode