How would Mug handle the following RuPyScript pseudocode:
for i in 1..10; eval "def function$i; print 'I'm $i'; end"; end
However, you don't need to wrap objects for arithmetic operations. At the moment Mug can determine the result of some types of expressions. If you're adding two doubles, it doesn't wrap the numbers before adding them. If you're calling (10).toString(), then it will autobox the number just as defined in the ECMAScript spec (the [[ToObject]] operation).
Deterction currently only works where types are explicit (a number literal will always be a number, etc.) The next step is to do type analysis on local variables, which will allow loops like for (var i = 0; i < 10; i++) { ... } to be compiled without wrapping primitives at all, greatly improving speed.
If you mean 'dynamically typed', then there's no particular problem - that's mainly a function of how you implement your calling protocols. It's much easier to write a dynamic compiler, actually, since you don't need to catch type errors at compile time.
If you mean 'supports eval', as your example seems to indicate, then you'll have to include either a compiler or interpreter in the language runtime - there's really no way around that. But it's not a big deal unless you're in some kind of embedded environment, and in that case you're probably not using a language that supports 'eval' anyway.
for (var i = 0; i < 10; i += 1)
eval("function function_" + i + "() { print('i am ' + i); }");
for (i = 0; i < 10; i += 1)
this['function_' + i]();
but it seems like eval is not supported yet - i guess for good reasons.However, `apply` is included (cf. test/regression.js line 19). So your example pseudocode could probably be written like this:
for (var i = 1; i <= 10; i++) {
var f = function() {
print("I'm " + i.toString());
};
f();
}A REPL would still be possible, however, it would require some work to maintain the current scope between input.
The gaudy part is that there is only one type of function signature, basically "invoke(Object, Object, Object...)" which means Mug has to convert doubles to Doubles and booleans to Booleans across function calls... so it's somewhat of a tradeoff.
- The ECMA5 document is (slightly) easier to read.
- Most 'extra' ECMA5 features can be added later, piecemeal, so initial development doesn't have to be more complicated.
- People will want ECMA5 eventually anyway.
- It is a waste of time to work through two ugly standards when one would have sufficed.
Found it: