June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -0,0 +1,10 @@
|
|||
- 1 2 3
|
||||
¯1 ¯2 ¯3
|
||||
2 * 1 2 3 4
|
||||
2 4 8 16
|
||||
2 × ⍳4
|
||||
2 4 6 8
|
||||
3 * 3 3 ⍴ ⍳9
|
||||
3 9 27
|
||||
81 243 729
|
||||
2187 6561 19683
|
||||
|
|
@ -1,21 +1,19 @@
|
|||
void
|
||||
map(list l, void (*fp)(object))
|
||||
{
|
||||
l_ucall(l, fp, 0);
|
||||
l.ucall(fp, 0);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
out(object o)
|
||||
{
|
||||
o_(o, "\n");
|
||||
}
|
||||
|
||||
|
||||
integer
|
||||
main(void)
|
||||
{
|
||||
map(l_effect(0, 1, 2, 3), out);
|
||||
list(0, 1, 2, 3).map(out);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
. !arg:(?location,?value)
|
||||
& !!value^2:?!value
|
||||
)
|
||||
& ( map
|
||||
& ( mapar
|
||||
= arr len callback i
|
||||
. !arg:(?arr,?len,?callback)
|
||||
& 0:?i
|
||||
|
|
@ -23,7 +23,7 @@
|
|||
& 2:?(1$array)
|
||||
& 3:?(2$array)
|
||||
& 4:?(3$array)
|
||||
& map$(array,4,callbackFunction1)
|
||||
& map$(array,4,callbackFunction2)
|
||||
& map$(array,4,callbackFunction1)
|
||||
& mapar$(array,4,callbackFunction1)
|
||||
& mapar$(array,4,callbackFunction2)
|
||||
& mapar$(array,4,callbackFunction1)
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import system'routines.
|
||||
|
||||
program =
|
||||
public program =
|
||||
[
|
||||
(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) forEach(:n) [ console writeLine(n * n) ].
|
||||
].
|
||||
|
|
|
|||
|
|
@ -1,22 +1,8 @@
|
|||
numbers = [1, 3, 5, 7]
|
||||
|
||||
square1 = [square(n) for n in numbers] # list comprehension
|
||||
|
||||
squares2a = map(square, numbers) # functional form
|
||||
|
||||
squares2b = map(x -> x*x, numbers) # functional form with `lambda`
|
||||
|
||||
#There is also extended block form for the map function
|
||||
squares2c = map(numbers) do x
|
||||
sum = 0
|
||||
for i = 1:x
|
||||
sum += x^2 #trivial, but you get the point
|
||||
end
|
||||
return sum
|
||||
end
|
||||
|
||||
squares3 = [n * n for n in numbers] # no need for a function,
|
||||
|
||||
squares4 = numbers .* numbers # element-wise operation
|
||||
|
||||
squares4a = numbers .^ 2 # most arithmetic operations can be done element-wise
|
||||
@show [n ^ 2 for n in numbers] # list comprehension
|
||||
square(x) = x ^ 2; @show map(square, numbers) # functional form
|
||||
@show map(x -> x ^ 2, numbers) # functional form with anonymous function
|
||||
@show [n * n for n in numbers] # no need for a function,
|
||||
@show numbers .* numbers # element-wise operation
|
||||
@show numbers .^ 2 # includes .+, .-, ./, comparison, and bitwise operations as well
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
function map(f,a) {
|
||||
nr = rows(a)
|
||||
nc = cols(a)
|
||||
b = J(nr,nc,.)
|
||||
for (i=1;i<=nr;i++) {
|
||||
for (j=1;j<=nc;j++) b[i,j] = (*f)(a[i,j])
|
||||
}
|
||||
return(b)
|
||||
}
|
||||
|
||||
function maps(f,a) {
|
||||
nr = rows(a)
|
||||
nc = cols(a)
|
||||
b = J(nr,nc,"")
|
||||
for (i=1;i<=nr;i++) {
|
||||
for (j=1;j<=nc;j++) b[i,j] = (*f)(a[i,j])
|
||||
}
|
||||
return(b)
|
||||
}
|
||||
|
||||
function square(x) {
|
||||
return(x*x)
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
Option Explicit
|
||||
|
||||
Sub Main()
|
||||
Dim arr, i
|
||||
'init
|
||||
arr = Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
|
||||
|
||||
'Loop and apply a function (Fibonacci) to each element
|
||||
For i = LBound(arr) To UBound(arr): arr(i) = Fibonacci(arr(i)): Next
|
||||
|
||||
'return
|
||||
Debug.Print Join(arr, ", ")
|
||||
End Sub
|
||||
|
||||
Private Function Fibonacci(N) As Variant
|
||||
If N <= 1 Then
|
||||
Fibonacci = N
|
||||
Else
|
||||
Fibonacci = Fibonacci(N - 1) + Fibonacci(N - 2)
|
||||
End If
|
||||
End Function
|
||||
Loading…
Add table
Add a link
Reference in a new issue