You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Typescript we can currently do something like this:
arr.map(x(=)>x*2).map(x()=>x*x);
From what I understand most javascript interpreters will run the first map to completion before starting the second as javascript is too dynamic to allow for proper analysis of pure functions.
Would it be possible to investigate limiting certain dinamicness of borrowScript to allow for merging each step of the above code in compilation so the array is not iterated twice?
While my example is simplistic there's more complicated ones where being able to automatically pipeline pure functions would be useful.
I don't really see the connection to generators here,.
The transformation that I'm considering just removes the unnecessary double iteration of the array and would mainly be a compiler optimisation aided by enforcing some constraints on what code in the callbacks can do.
From what I understand most javascript interpreters will run the first map to completion before starting the second
Generators solve this exact problem; both maps are running at pretty much the same time. The first value of the array goes through the first map, and then immediately through the second.
I guess I'm not really following then. Are there any existing languages that do the optimizations you're describing so that I can read about them?
Activity
SuperSonicHub1 commentedon Oct 23, 2021
So you want the code to become something like this?
Honestly, if you want something like this, it would be much better to use generators instead:
Perhaps we should make ECMAScript generators have a greater focus in BorrowScript?
Isaac-Leonard commentedon Oct 23, 2021
While my example is simplistic there's more complicated ones where being able to automatically pipeline pure functions would be useful.
I don't really see the connection to generators here,.
The transformation that I'm considering just removes the unnecessary double iteration of the array and would mainly be a compiler optimisation aided by enforcing some constraints on what code in the callbacks can do.
SuperSonicHub1 commentedon Oct 24, 2021
Generators solve this exact problem; both maps are running at pretty much the same time. The first value of the array goes through the first map, and then immediately through the second.
I guess I'm not really following then. Are there any existing languages that do the optimizations you're describing so that I can read about them?
Isaac-Leonard commentedon Oct 29, 2021
Alan lang does it, pretty sure Julia does too along with other functional languages