mirror of
https://github.com/Dummi26/mers.git
synced 2026-01-26 10:47:04 +01:00
fix product function and add examples
This commit is contained in:
1
examples/00_Hello_World.mers
Normal file
1
examples/00_Hello_World.mers
Normal file
@@ -0,0 +1 @@
|
||||
"Hello, World!".println
|
||||
3
examples/01_Hello_Name.mers
Normal file
3
examples/01_Hello_Name.mers
Normal file
@@ -0,0 +1,3 @@
|
||||
"What's you name?".println
|
||||
name := ().read_line.trim
|
||||
("Hello, ", name, "!").concat.println
|
||||
13
examples/02_Calc_Sum.mers
Normal file
13
examples/02_Calc_Sum.mers
Normal file
@@ -0,0 +1,13 @@
|
||||
total := 0.0
|
||||
{() -> {
|
||||
("Total: ", total, ". Type a number to change.").concat.println
|
||||
(
|
||||
().read_line.trim.parse_float,
|
||||
(
|
||||
n -> &total = (total, n).sum,
|
||||
// not a number, so return a 1-tuple to break from the loop
|
||||
() -> (())
|
||||
)
|
||||
).try
|
||||
}}.loop
|
||||
"Goodbye.".println
|
||||
30
examples/03_Basic_Calculator.mers
Normal file
30
examples/03_Basic_Calculator.mers
Normal file
@@ -0,0 +1,30 @@
|
||||
"- Calculator -".println
|
||||
"Type =<num> to set the value to that number.".println
|
||||
"Type +<num>, -<num> or *<num> to change the value.".println
|
||||
"Type exit to exit.".println
|
||||
|
||||
current := 0.0
|
||||
|
||||
{() -> {
|
||||
("[ ", current, " ]").concat.println
|
||||
input := ().read_line.trim
|
||||
num := (
|
||||
(input, 1).substring.trim.parse_float,
|
||||
(
|
||||
() -> 0.0,
|
||||
val -> val
|
||||
)
|
||||
).try
|
||||
mode := (input, 0, 1).substring
|
||||
if (mode, "+").eq {
|
||||
¤t = (current, num).sum
|
||||
} else if (mode, "-").eq {
|
||||
¤t = (current, (num, -1).product).sum
|
||||
} else if (mode, "*").eq {
|
||||
¤t = (current, num).product
|
||||
} else if (mode, "=").eq {
|
||||
¤t = num
|
||||
} else if (input, "exit").eq {
|
||||
(())
|
||||
}
|
||||
}}.loop
|
||||
Reference in New Issue
Block a user