Extended foldl and foldr to be variadic, fixed foldr, and added pattern matching!

This commit is contained in:
Nathan Braswell
2021-08-01 20:21:14 -04:00
parent dfde35ee79
commit 537386d97b
4 changed files with 131 additions and 14 deletions

41
match_test.kp Normal file
View 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)
))
))