Glowscript list.reverse() bug?

12 views
Skip to first unread message

Adam Hausknecht

unread,
Sep 2, 2017, 11:41:59 PM9/2/17
to Glowscript Users
Hi,

I have a GlowScript 2.1 program that reverses a list by using the statement 

 xList.reverse()

However, the  revisedGlowScript 2.6 version of the program freezes at this statement (see below).  Is this statement no longer supported?

================================
def initTest():
    ##alert("initTest 1")
    global gItems, gDataSize
    global gCurrentViewMode
    maxR = floor(kSize/2)
    if kSize % gDataSize == 0:
        yList = range(maxR, -maxR, -kTab)
        xList = range(maxR, -maxR, -kTab)
    else:  
        yList = range(maxR-floor(kTab/2), -maxR, -kTab)
        xList = range(maxR-floor(kTab/2), -maxR, -kTab)
    alert("initTest 2a, "+ xList[0])
    xList.reverse().  ## Freezes here!
    alert("initTest 2b, "+ xList[0])
    if gCurrentDataOrder == kIncreasing:
       alert("initTest 2c, "+ yList[0])
       yList.reverse()
       alert("initTest 2d, "+ yList[0])
    elif gCurrentDataOrder == kRandomOrder:
       shuffle(yList)
#  more code


Thanks in advance,

Adam Hausknecht
Department of Mathematics
UMass Dartmouth






Adam Hausknecht

unread,
Sep 3, 2017, 1:19:35 AM9/3/17
to Glowscript Users
Never mind! I now understand that  the range function returns an iterator instead of a list!

Adam Hausknecht 

Bruce Sherwood

unread,
Sep 3, 2017, 2:20:51 PM9/3/17
to Glowscript Users
Good for you for catching this before I could. In Python 2.x range produced a list, but Python 3 (which the RapydScript-NG Python-to-JavaScript transpiler attempts to implement), range indeed produces an iterator. The switch from the older RapydScript to RapydScript-NG occurred in GlowScript 2.3, in January 2017.

Reply all
Reply to author
Forward
0 new messages