2021-08-01 20:21:14 -04:00
|
|
|
(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)
|
|
|
|
|
))
|
2021-08-01 23:48:41 -04:00
|
|
|
(println "seventh "
|
|
|
|
|
(let (b 2)
|
|
|
|
|
(match [ 1337 [ 1 2 3] 11 ]
|
|
|
|
|
1 true
|
|
|
|
|
"str" "It was a string!"
|
|
|
|
|
[ 1337 [ a ~b c] 11 ] (str "matched, and got " a c " while checking based on inserted " b)
|
|
|
|
|
a "sigh, failed to match"
|
|
|
|
|
)))
|
2021-08-01 20:21:14 -04:00
|
|
|
))
|