-
Notifications
You must be signed in to change notification settings - Fork 0
/
playground.red
75 lines (63 loc) · 1.3 KB
/
playground.red
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
Red [
Title: "playground"
Author: "unchartedworks"
File: %all-test.red
Tabs: 4
Rights: "unchartedworks. All rights reserved."
License: "MIT"
]
#include %haskell.red
;data-list
print "DataList"
;map
print "map"
xs: [1 2 3]
ys: (map :to-string xs)
print ys
;filter
print "filter"
xs: [1 "2" 3 "4" 5 "6"]
ys: filter :integer? xs
print ys
;foldl
print "foldl"
xs: [1 2 3 4]
f: func [y x][x * y]
ys: foldl :f 1 xs
print ys
print ""
;data-char
print "DataChar"
print isControl #"t"
print ""
;data-function
print "DataFunction"
f1: func [x][x * 2]
f2: func [x][length? x]
f: :f1 . :f2
print f "abc"
print ""
;prelude
print "Prelude"
f: [x] -> [x + 1]
print f 1
print ""
;maybe
print "Maybe"
hit: [x] -> [Just (x + 8)]
stand: [x] -> [either x > 21 [Nothing][Just x]]
win: [x] -> [Just "$1000"]
showtime: [x] -> [Just ("You win " ++ x ++ "!")]
blackjack: [x [object!]] -> [x >>= :hit >>= :hit >>= :stand >>= :win >>= :showtime]
print blackjack Just 3
print ""
;either
print "Either"
print fromRight Right 3
print ""
;control-monad
print "Control-Monad"
isTestFile: [x] -> [(isSuffixOf "-test.red" (to-string x)) && (%all-test.red <> x) && (not (isPrefixOf ".#" (to-string x)))]
filterTestFiles: [xs] -> [filter :isTestFile xs]
xs: %./ >>>= [read filterTestFiles]
print xs