Tuple not converted to list

36 views
Skip to first unread message

Bruce Sherwood

unread,
Nov 8, 2015, 11:06:40 PM11/8/15
to RapydScript
I  thought it was the case that tuples are always converted to lists, but not in this (admittedly unusual) case:

d = {}
d[(1,2)] = 'cat'
d[(3,4)] = 'dog'

transpiles to


d = { };
d[[1,2,]] = "cat";
d[3, 4] = "dog";  // note that [(3,4)] has been converted to [3,4]

This bug is present in the newest RS as well as in earlier versions.

Bruce


Alexander Tsepkov

unread,
Nov 9, 2015, 1:51:50 AM11/9/15
to Bruce Sherwood, RapydScript
Ah yes, you're correct about the last case. I will take a look at it. However, you're saying that d[(1,2)] compiles to d[[#,#]], and d[(3,4)] does not? I'm seeing them both compile to d[#,#], and in fact that's what I'd expect - there is nothing in second case that would cause the tokenizer engine to interpret the two differently and I'd be concerned if it did. Are you sure there wasn't a typo? This is what I'm seeing for compiled output:

var d;
d = {};
d[1,2] = "cat";
d[3,4] = "dog";

Bruce Sherwood

unread,
Nov 9, 2015, 12:40:43 PM11/9/15
to Alexander Tsepkov, RapydScript
You're right -- there's an unfortunate typo in my input code, which was supposed to read like this:

d = { };
d[ [1, 2] ] = "cat";
d[ (3, 4) ] = "dog";

which transpiles as I said to

d = { };
d[[1,2,]] = "cat";
d[3, 4] = "dog";

Sorry for the confusion!

Bruce

I'm reminded of the wonderful Monty Python skit in which an auditioning singer sings "You say tomatoes and I say tomatoes, you say potatoes and I say potatoes; tomatoes/tomatoes, potatoes/potatoes, let's call the whole thing off", in which he pronounces the supposedly different pairs exactly the same. Eventually he stops and says, "I don't see what their problem is!"

Bruce Sherwood

unread,
Nov 12, 2015, 8:32:33 PM11/12/15
to RapydScript, atse...@gmail.com
Here's a simpler case:

a = ((1,2), (5,2), (8,4)) # compiles to a = [1,2,5,2,8,4,]; but presumably should be [[1,2], [5,2], [8,4],]

b = [(1,2), (5,2), (8,4)] # compiles to b = [[1,2,],[5,2,],[8,4,],];
Reply all
Reply to author
Forward
0 new messages