Extended foldl and foldr to be variadic, fixed foldr, and added pattern matching!
This commit is contained in:
41
match_test.kp
Normal file
41
match_test.kp
Normal file
@@ -0,0 +1,41 @@
|
||||
(with_import "./match.kp"
|
||||
(do
|
||||
(println "first "
|
||||
(match 1
|
||||
1 true
|
||||
a (+ a 1)
|
||||
))
|
||||
|
||||
(println "second "
|
||||
(match 3
|
||||
1 true
|
||||
a (+ a 1)
|
||||
))
|
||||
(println "third "
|
||||
(match "str"
|
||||
1 true
|
||||
"str" "It was a string!"
|
||||
a (+ a 1)
|
||||
))
|
||||
(println "fourth "
|
||||
(match [ 1337 "str" ]
|
||||
1 true
|
||||
"str" "It was a string!"
|
||||
[ 1337 "str" ] "matched an array of int str"
|
||||
a (+ a 1)
|
||||
))
|
||||
(println "fifth "
|
||||
(match [ 1337 "str" 'sy ]
|
||||
1 true
|
||||
"str" "It was a string!"
|
||||
[ 1337 "str" 'sy ] "matched an array of int str symbol"
|
||||
a (+ a 1)
|
||||
))
|
||||
(println "sixth "
|
||||
(match [ 1337 "str" 'walla + 11 false 'kraken [ 'inner 'middle 'end ] [ 'inner1 'middle1 'end1 ] ]
|
||||
1 true
|
||||
"str" "It was a string!"
|
||||
[ 1337 "str" 'walla + a false b [ 'inner c 'end ] d ] (str "matched, and got " a b c d)
|
||||
a (+ a 1)
|
||||
))
|
||||
))
|
||||
Reference in New Issue
Block a user