33 lines
651 B
Plaintext
33 lines
651 B
Plaintext
square = fn (N) {
|
|
N * N
|
|
}
|
|
|
|
# list comprehension
|
|
squares1 = fn (Numbers) {
|
|
[square(N) for N in Numbers]
|
|
}
|
|
|
|
# functional form
|
|
squares2a = fn (Numbers) {
|
|
lists.map(fn square:1, Numbers)
|
|
}
|
|
|
|
# functional form with lambda
|
|
squares2b = fn (Numbers) {
|
|
lists.map(fn (N) { N * N }, Numbers)
|
|
}
|
|
|
|
# no need for a function
|
|
squares3 = fn (Numbers) {
|
|
[N * N for N in Numbers]
|
|
}
|
|
|
|
@public
|
|
run = fn () {
|
|
Numbers = [1, 3, 5, 7]
|
|
io.format("squares1 : ~p~n", [squares1(Numbers)])
|
|
io.format("squares2a: ~p~n", [squares2a(Numbers)])
|
|
io.format("squares2b: ~p~n", [squares2b(Numbers)])
|
|
io.format("squares3 : ~p~n", [squares3(Numbers)])
|
|
}
|