mindchamber wrote:es wrote:You might prefer something made for this task:
Code:a.apply(@(v) v.tointeger());
It will be more productive than a cycle?
Yes because this is exactly why apply was made, and lambdas are officially recommended by the Squirrel manual to be used like this.
"Lambda expressions are a synctactic sugar to quickly define a function that consists of a single expression. This feature comes handy when functional programming patterns are applied, like map/reduce or passing a compare method to array.sort()."
('apply' internally uses 'map' and replaces the array with the return value from it. The code above is the equivalent of this:
Code:a = a.map(@(v) v.tointeger());
)
This is also functionally equivalent code to the foreach statement suggested above but is a lot neater and focuses on what to do rather than how to do it.
However, if you prefer imperative programming over declarative, you would be fine with foreach.