Data update
This commit is contained in:
parent
4d5544505c
commit
4924dd0264
3073 changed files with 55820 additions and 4408 deletions
7
Task/Currying/ArkScript/currying.ark
Normal file
7
Task/Currying/ArkScript/currying.ark
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
(let addN (fun (n)
|
||||
(fun (x &n)
|
||||
(+ x n))))
|
||||
|
||||
(let add2 (addN 2))
|
||||
(print (type add2))
|
||||
(assert (= 7 (add2 5)) "add2 5 is 7")
|
||||
4
Task/Currying/Pluto/currying.pluto
Normal file
4
Task/Currying/Pluto/currying.pluto
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
local function add_n(n) return |x| -> n + x end
|
||||
|
||||
local adder = add_n(40)
|
||||
print($"The answer to life is {adder(2)}.")
|
||||
36
Task/Currying/Red/currying.red
Normal file
36
Task/Currying/Red/currying.red
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
Red[ "Currying in Red - Hinjo, 21 July 2025" ]
|
||||
|
||||
; define a custome simple currying function
|
||||
c!: func ['f x][do compose/deep [func [y] [do compose [(get f) (x) y]]]]
|
||||
|
||||
; test with Red's built-in functions "add" and "multiply"
|
||||
add10: c! add 10
|
||||
print add10 5
|
||||
print add10 7
|
||||
|
||||
double: c! multiply 2
|
||||
print double 5
|
||||
print double 100
|
||||
|
||||
; test with a custom function to get x to power of y
|
||||
my-power: func [x y][either y = 0 [1][tot: 1 loop y [tot: tot * x]]]
|
||||
|
||||
; create a binary power by currying it
|
||||
my-binary-power: c! my-power 2
|
||||
foreach i [0 1 2 3 4 5 6 7 8 9 10] [print my-binary-power i]
|
||||
|
||||
; this is currying the built-in Red's "if" function!
|
||||
doit: c! if true
|
||||
doit [print "Hello currying world!"]
|
||||
|
||||
; simulate a realistic use
|
||||
random/seed now
|
||||
test: func [bCond bAction] [if do bCond bAction]
|
||||
system-failed?: c! test [(random 100) > 80]
|
||||
|
||||
; how many time failures in ten years?
|
||||
fail: 0 year: 1 while [year <= 10] [ print [year " "]
|
||||
system-failed? [ fail: fail + 1 print "Maintenance!" ]
|
||||
year: year + 1
|
||||
]
|
||||
print ["Failed " fail]
|
||||
Loading…
Add table
Add a link
Reference in a new issue