Loops/Wrong ranges: Difference between revisions

Line 696:
 
You don't always have to convert a range to a series explicitly. Since 0.6.15, the functions map(), fold(), foldfrom(), and zip() accept ranges in place of arrays.
 
In the following examples, we could have just started with an array of arrays, but following the Python example, we process the .data string into a table.
 
{{trans|Python}}
Line 713 ⟶ 715:
END
 
# Process .data string into .table.
# We could have just started with an array of arrays, of course.
var .table = map(f(.s) split(RE/\s\s+/, replace(.s, RE:m/^\s+/)), split("\n", .data))
for .i in 2..len(.table) {
Line 747:
END
 
# Process .data string into .table.
# We could have just started with an array of arrays, of course.
var .table = map(f(.s) split(RE/\s\s+/, replace(.s, RE:m/^\s+/)), split("\n", .data))
val .f = toNumber
for .i in 2..len(.table) {
.table[.i] = map([toNumber.f, toNumber.f, toNumber.f, _], .table[.i])
}
 
1,006

edits