Support multi-clause patterns as syntactic sugar
And disable multi-patterns clauses. I was originally just controlling whether we did disable that from the parser but then I figured we could actually support multi-patterns clauses quite easily by simply desugaring a multi-pattern into multiple clauses. This is only a syntactic sugar, which means that the cost of writing that on-chain is as expensive as writing the fully expanded form; yet it seems like a useful shorthand; especially for short clause expressions. This commit however disables multi-pattern when clauses, which we do not support in the code-generation. Instead, one pattern on tuples for that.
This commit is contained in:
5
examples/acceptance_tests/078/aiken.lock
Normal file
5
examples/acceptance_tests/078/aiken.lock
Normal file
@@ -0,0 +1,5 @@
|
||||
# This file was generated by Aiken
|
||||
# You typically do not need to edit this file
|
||||
|
||||
requirements = []
|
||||
packages = []
|
||||
2
examples/acceptance_tests/078/aiken.toml
Normal file
2
examples/acceptance_tests/078/aiken.toml
Normal file
@@ -0,0 +1,2 @@
|
||||
name = "aiken-lang/acceptance_test_078"
|
||||
version = "0.0.0"
|
||||
45
examples/acceptance_tests/078/lib/tests.ak
Normal file
45
examples/acceptance_tests/078/lib/tests.ak
Normal file
@@ -0,0 +1,45 @@
|
||||
type DayOfTheWeek {
|
||||
Monday
|
||||
Tuesday
|
||||
Wednesday
|
||||
Thursday
|
||||
Friday
|
||||
Saturday
|
||||
Sunday
|
||||
}
|
||||
|
||||
fn is_work(day: DayOfTheWeek) {
|
||||
when day is {
|
||||
Tuesday | Wednesday | Thursday | Friday | Saturday ->
|
||||
True
|
||||
_ ->
|
||||
False
|
||||
}
|
||||
}
|
||||
|
||||
test is_work_1() {
|
||||
is_work(Thursday)
|
||||
}
|
||||
|
||||
test is_work_2() {
|
||||
!is_work(Monday)
|
||||
}
|
||||
|
||||
fn is_happy_hour(day: DayOfTheWeek, current_time: Int) {
|
||||
when day is {
|
||||
Monday | Sunday ->
|
||||
True
|
||||
Tuesday | Wednesday | Thursday | Friday | Saturday if current_time > 18 ->
|
||||
True
|
||||
_ ->
|
||||
False
|
||||
}
|
||||
}
|
||||
|
||||
test is_happy_hour_1() {
|
||||
is_happy_hour(Sunday, 14)
|
||||
}
|
||||
|
||||
test is_happy_hour_2() {
|
||||
is_happy_hour(Friday, 22)
|
||||
}
|
||||
8
examples/acceptance_tests/078/plutus.json
Normal file
8
examples/acceptance_tests/078/plutus.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"preamble": {
|
||||
"title": "aiken-lang/acceptance_test_078",
|
||||
"version": "0.0.0",
|
||||
"plutusVersion": "v2"
|
||||
},
|
||||
"validators": []
|
||||
}
|
||||
Reference in New Issue
Block a user