September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
49
Task/Topic-variable/AppleScript/topic-variable-1.applescript
Normal file
49
Task/Topic-variable/AppleScript/topic-variable-1.applescript
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
on run
|
||||
1 + 2
|
||||
|
||||
ap({square, squareRoot}, {result})
|
||||
|
||||
--> {9, 1.732050807569}
|
||||
end run
|
||||
|
||||
|
||||
-- square :: Num a => a -> a
|
||||
on square(x)
|
||||
x * x
|
||||
end square
|
||||
|
||||
-- squareRoot :: Num a, Float b => a -> b
|
||||
on squareRoot(x)
|
||||
x ^ 0.5
|
||||
end squareRoot
|
||||
|
||||
|
||||
-- GENERIC FUNCTIONS ----------------------------------------------------------
|
||||
|
||||
-- A list of functions applied to a list of arguments
|
||||
-- (<*> | ap) :: [(a -> b)] -> [a] -> [b]
|
||||
on ap(fs, xs)
|
||||
set intFs to length of fs
|
||||
set intXs to length of xs
|
||||
set lst to {}
|
||||
repeat with i from 1 to intFs
|
||||
tell mReturn(item i of fs)
|
||||
repeat with j from 1 to intXs
|
||||
set end of lst to |λ|(contents of (item j of xs))
|
||||
end repeat
|
||||
end tell
|
||||
end repeat
|
||||
return lst
|
||||
end ap
|
||||
|
||||
-- Lift 2nd class handler function into 1st class script wrapper
|
||||
-- mReturn :: Handler -> Script
|
||||
on mReturn(f)
|
||||
if class of f is script then
|
||||
f
|
||||
else
|
||||
script
|
||||
property |λ| : f
|
||||
end script
|
||||
end if
|
||||
end mReturn
|
||||
51
Task/Topic-variable/AppleScript/topic-variable-2.applescript
Normal file
51
Task/Topic-variable/AppleScript/topic-variable-2.applescript
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
on run
|
||||
script
|
||||
-- The given function applied to the value 3
|
||||
on |λ|(f)
|
||||
mReturn(f)'s |λ|(3)
|
||||
end |λ|
|
||||
end script
|
||||
|
||||
-- Here, 'result' is bound to the script above
|
||||
map(result, {square, squareRoot})
|
||||
|
||||
--> {9, 1.732050807569}
|
||||
end run
|
||||
|
||||
|
||||
-- square :: Num a => a -> a
|
||||
on square(x)
|
||||
x * x
|
||||
end square
|
||||
|
||||
-- squareRoot :: Num a, Float b => a -> b
|
||||
on squareRoot(x)
|
||||
x ^ 0.5
|
||||
end squareRoot
|
||||
|
||||
|
||||
-- GENERIC FUNCTIONS ----------------------------------------------------------
|
||||
|
||||
-- map :: (a -> b) -> [a] -> [b]
|
||||
on map(f, xs)
|
||||
tell mReturn(f)
|
||||
set lng to length of xs
|
||||
set lst to {}
|
||||
repeat with i from 1 to lng
|
||||
set end of lst to |λ|(item i of xs, i, xs)
|
||||
end repeat
|
||||
return lst
|
||||
end tell
|
||||
end map
|
||||
|
||||
-- Lift 2nd class handler function into 1st class script wrapper
|
||||
-- mReturn :: Handler -> Script
|
||||
on mReturn(f)
|
||||
if class of f is script then
|
||||
f
|
||||
else
|
||||
script
|
||||
property |λ| : f
|
||||
end script
|
||||
end if
|
||||
end mReturn
|
||||
4
Task/Topic-variable/Haskell/topic-variable.hs
Normal file
4
Task/Topic-variable/Haskell/topic-variable.hs
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
Prelude> [1..10]
|
||||
[1,2,3,4,5,6,7,8,9,10]
|
||||
Prelude> map (^2) it
|
||||
[1,4,9,16,25,36,49,64,81,100]
|
||||
4
Task/Topic-variable/Julia/topic-variable.julia
Normal file
4
Task/Topic-variable/Julia/topic-variable.julia
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
julia> 3
|
||||
3
|
||||
julia> ans * ans, ans - 1
|
||||
(9, 2)
|
||||
9
Task/Topic-variable/Kotlin/topic-variable.kotlin
Normal file
9
Task/Topic-variable/Kotlin/topic-variable.kotlin
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
// version 1.1.2
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
3.let {
|
||||
println(it)
|
||||
println(it * it)
|
||||
println(Math.sqrt(it.toDouble()))
|
||||
}
|
||||
}
|
||||
9
Task/Topic-variable/Ring/topic-variable.ring
Normal file
9
Task/Topic-variable/Ring/topic-variable.ring
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
see "sum1 = " + sum1(1,2) + nl
|
||||
see "sum2 = " + sum2(2,3) + nl
|
||||
|
||||
func sum1 (x, y)
|
||||
sum = x + y
|
||||
return sum
|
||||
|
||||
func sum2 (x, y)
|
||||
return x + y
|
||||
5
Task/Topic-variable/Zkl/topic-variable.zkl
Normal file
5
Task/Topic-variable/Zkl/topic-variable.zkl
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
a,_,c:=List(1,2,3,4,5,6) //-->a=1, c=3, here _ is used as "ignore"
|
||||
3.0 : _.sqrt() : println(_) //-->"1.73205", _ (and :) is used to "explode" a computation
|
||||
// as syntactic sugar
|
||||
1.0 + 2 : _.sqrt() : _.pow(4) // no variables used, the compiler "implodes" the computation
|
||||
// --> 9
|
||||
Loading…
Add table
Add a link
Reference in a new issue