mirror of
https://github.com/Dummi26/mers.git
synced 2026-01-26 10:47:04 +01:00
revamped switch and match syntax
This commit is contained in:
@@ -4,14 +4,14 @@ text := "ℑ𝔠𝔥 𝔨𝔞𝔫𝔫 𝔡𝔞𝔰 𝔳𝔢𝔯𝔡𝔞𝔪𝔪
|
||||
fn random(min int max int) {
|
||||
res := run_command("fish" ["-c" "random " + min.to_string() + " " + max.to_string() ...])
|
||||
switch res {
|
||||
[[]/int string string] res.1.trim().parse_int().assume1()
|
||||
[[]/int string string] res res.1.trim().parse_int().assume1()
|
||||
}
|
||||
}
|
||||
fn rnd() {
|
||||
r := random(5 15)
|
||||
switch r {
|
||||
int r
|
||||
[] 10
|
||||
int r r
|
||||
[] [] 10
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,11 +6,11 @@ fn print_linked_list(start elem) {
|
||||
println(start.0.to_string())
|
||||
elem := start.1
|
||||
switch! elem {
|
||||
[] {
|
||||
[] elem {
|
||||
println("[END]")
|
||||
true // break
|
||||
}
|
||||
elem &start = elem // continue
|
||||
elem elem &start = elem // continue
|
||||
}
|
||||
}
|
||||
[]
|
||||
|
||||
@@ -7,11 +7,11 @@ fn map_string_to_int(list [string ...] func fn((string int))) {
|
||||
elem := &list.remove(0)
|
||||
switch! elem {
|
||||
// if the element was present, run the map function to convert it from a string to an int and return the result
|
||||
[string] {
|
||||
[func.run(elem.0)]
|
||||
[string] [elem] {
|
||||
[func.run(elem)]
|
||||
}
|
||||
// if there are no more elements, return something that doesn't match.
|
||||
[] []
|
||||
[] [] []
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
19
examples/switch_match.mers
Normal file
19
examples/switch_match.mers
Normal file
@@ -0,0 +1,19 @@
|
||||
x := if true [10 "my text"] else 10
|
||||
|
||||
switch! x {
|
||||
[int string] [num text] {
|
||||
num.debug()
|
||||
text.debug()
|
||||
}
|
||||
int num {
|
||||
println("number:")
|
||||
num.debug()
|
||||
}
|
||||
}
|
||||
|
||||
text := "12.5"
|
||||
match {
|
||||
parse_int(text) num println("int: " + num.to_string())
|
||||
parse_float(text) num println("float: " + num.to_string())
|
||||
true [] println("not a number: " + text)
|
||||
}
|
||||
Reference in New Issue
Block a user