However because it runs through once to count the elements it actually ends up calling everything twice. I guess a E.count(...) would actually serve two purposes.
But does anyone else have any thoughts about whether this would get used?
Personally it feels like a very niche thing and I'm not too sure of the uses. I mean, if eval allowed you to pass in a function then you could just do arr.forEach(eval) for a (probably faster) effect... and on a lot of platforms just doing:
function go() {
"compiled";
en.reset();
console.log("qwertz\n");
en.set();
console.log("asdf\n");
}
would be more readable and significantly faster.
To be honest the best thing would be to just make the interpreter itself able to 'fast path' simple JavaScript functions so they executed extremely quickly - then we wouldn't need a lot of this messing around.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Ahh, ok - so being able to execute an array of functions one after the other?
Something like this is actually very close to doing exactly what you want:
However because it runs through once to count the elements it actually ends up calling everything twice. I guess a
E.count(...)
would actually serve two purposes.But does anyone else have any thoughts about whether this would get used?
Personally it feels like a very niche thing and I'm not too sure of the uses. I mean, if
eval
allowed you to pass in a function then you could just doarr.forEach(eval)
for a (probably faster) effect... and on a lot of platforms just doing:would be more readable and significantly faster.
To be honest the best thing would be to just make the interpreter itself able to 'fast path' simple JavaScript functions so they executed extremely quickly - then we wouldn't need a lot of this messing around.