mirror of
https://github.com/Dummi26/mers.git
synced 2026-01-26 10:47:04 +01:00
added := for initialization/declaration
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -4,7 +4,7 @@ type elem [int []/elem]
|
||||
fn print_linked_list(start elem) {
|
||||
loop {
|
||||
println(start.0.to_string())
|
||||
elem = start.1
|
||||
elem := start.1
|
||||
switch! elem {
|
||||
[] {
|
||||
println("[END]")
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
list = [1 2 3 4 5 6 7 8 9 ...]
|
||||
list := [1 2 3 4 5 6 7 8 9 ...]
|
||||
|
||||
// calling get on an &list will get a reference
|
||||
&list.get(2).assume1() = 24
|
||||
// calling get on a list will get a value
|
||||
should_not_be_changeable = list.get(3).assume1()
|
||||
should_not_be_changeable := list.get(3).assume1()
|
||||
&should_not_be_changeable = 24
|
||||
|
||||
if list.get(2) != [24] println("[!!] list.get(2) != 24 (was {0})".format(list.get(2).to_string()))
|
||||
|
||||
@@ -4,7 +4,7 @@ fn map_string_to_int(list [string ...] func fn((string int))) {
|
||||
// this function will be called by the for loop
|
||||
// whenever it wants to retrieve the next item in the collection.
|
||||
// get the element
|
||||
elem = &list.remove(0)
|
||||
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] {
|
||||
@@ -24,8 +24,8 @@ for v ["1" "2" "5" "-10" ...].map_string_to_int((s string) s.parse_int().assume1
|
||||
// returns an iterator to iteratively compute square numbers
|
||||
// using the fact that (n+1)^2 = n^2 + 2n + 1
|
||||
fn square_numbers() {
|
||||
i = 0
|
||||
val = 0
|
||||
i := 0
|
||||
val := 0
|
||||
() {
|
||||
&val = val + { 2 * i } + 1
|
||||
&i = i + 1
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
val = "some string"
|
||||
val = !(mers {
|
||||
val := "some string"
|
||||
val := !(mers {
|
||||
println("macro is running now!")
|
||||
"macro returned value"
|
||||
})
|
||||
println(val)
|
||||
val = !(mers "my_macro.mers")
|
||||
val := !(mers "my_macro.mers")
|
||||
println(val)
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
// NOTE: Might change, but this is the current state of things
|
||||
x = 10
|
||||
t = thread(() {
|
||||
x := 10
|
||||
t := thread(() {
|
||||
sleep(0.25)
|
||||
println(x.to_string())
|
||||
})
|
||||
// if this was x = 20 instead, the thread would still be using the old x = 10 value.
|
||||
&x = 20
|
||||
&x = 20 // -> 20 20 because it modifies the original variable x
|
||||
// x := 20 // -> 10 20 because it shadows the original variable x
|
||||
t.await()
|
||||
println(x.to_string())
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
// this is true by default so the example doesn't finish too quickly or too slowly depending on your hardware.
|
||||
// you can set it to false and tweak the max value for a more authentic cpu-heavy workload.
|
||||
fake_delay = true
|
||||
fake_delay := true
|
||||
|
||||
// this will be shared between the two threads to report the progress in percent (0-100%).
|
||||
progress = 0
|
||||
progress := 0
|
||||
|
||||
// an anonymous function that sums all numbers from 0 to max.
|
||||
// it captures the progress variable and uses it to report its status to the main thread, which will periodically print the current progress.
|
||||
// once done, it returns a string with the sum of all numbers.
|
||||
calculator = (max int) {
|
||||
sum = 0
|
||||
calculator := (max int) {
|
||||
sum := 0
|
||||
for i max {
|
||||
i = i + 1
|
||||
i := i + 1
|
||||
// println("i: {0} s: {1}".format(i.to_string() sum.to_string()))
|
||||
&sum = sum + i
|
||||
if fake_delay sleep(1)
|
||||
@@ -21,7 +21,7 @@ calculator = (max int) {
|
||||
}
|
||||
|
||||
// start the thread. if fake_delay is true, calculate 1+2+3+4+5+6+7+8+9+10. if fake_delay is false, count up to some ridiculously large number.
|
||||
slow_calculation_thread = calculator.thread(if fake_delay 10 else 20000000)
|
||||
slow_calculation_thread := calculator.thread(if fake_delay 10 else 20000000)
|
||||
|
||||
// every second, print the progress. once it reaches 100%, stop
|
||||
loop {
|
||||
@@ -31,6 +31,6 @@ loop {
|
||||
}
|
||||
|
||||
// use await() to get the result from the thread. if the thread is still running, this will block until the thread finishes.
|
||||
result = slow_calculation_thread.await()
|
||||
result := slow_calculation_thread.await()
|
||||
|
||||
println("Thread finished, result: {0}".format(result))
|
||||
|
||||
Reference in New Issue
Block a user