codecombat/esper.js

Tuple in Python allows reassignment

Opened this issue · 2 comments

I'm not sure if this is the intended behavior in Esper.js but if you use the Python language a tuple can be reassigned.

var engine = new esper.Engine({language: 'python'})
console.log(engine.evalSync("x = ('a', 'b'); x[0] = 'reassigned'; x;"))

If you use a Python interpreter instead of Esper.js an error is raised: TypeError: 'tuple' object does not support item assignment. Interestingly using Skulpt directly raises the error correctly.

The intended behavior is to be as as close to python as possible. We just aren't there yet.

Currently when skulpty generates an AST it does a few things to try to make javascript objects that have pythonic behavior, but we can only get so close. For example heres the tuple implementation.

https://github.com/codecombat/skulpty/blob/master/lib/stdlib.js#L371

Currently skulpty generates javascript that is just picked up by esper. This isn't ideal for a few reason. 1. Its quite slow, as all the standard library for the types runs inside esper, 2. We cant hook type behavior as deeply.

The plan forward is to add native esper value types for python types with the right behavior, and native implementations of the methods. Quite a ways off though unless your looking to help : )

Got it, thanks for the explanation. I thought it was using Skulpt directly.