mirror of
https://github.com/Dummi26/mers.git
synced 2025-03-10 14:13:52 +01:00
fixed examples
This commit is contained in:
parent
b652cb57cc
commit
c32419508e
@ -10,7 +10,7 @@ fn print_linked_list(start elem) {
|
|||||||
println("[END]")
|
println("[END]")
|
||||||
true // break
|
true // break
|
||||||
}
|
}
|
||||||
elem start = elem // continue
|
elem &start = elem // continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[]
|
[]
|
||||||
|
@ -1,13 +1,10 @@
|
|||||||
list = [1 2 3 4 5 6 7 8 9 ...]
|
list = [1 2 3 4 5 6 7 8 9 ...]
|
||||||
|
|
||||||
// second = &list.get_ref(2).assume1()
|
// calling get on an &list will get a reference
|
||||||
// second.debug()
|
&list.get(2).assume1() = 24
|
||||||
// *second = 24
|
// calling get on a list will get a value
|
||||||
// second.debug()
|
should_not_be_changeable = list.get(3).assume1()
|
||||||
|
&should_not_be_changeable = 24
|
||||||
&list.get_ref(2).assume1() = 24
|
|
||||||
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()))
|
if list.get(2) != [24] println("[!!] list.get(2) != 24 (was {0})".format(list.get(2).to_string()))
|
||||||
if list.get(3) == [24] println("[!!] list.get(3) == 24")
|
if list.get(3) == [24] println("[!!] list.get(3) == 24")
|
||||||
|
@ -27,8 +27,8 @@ fn square_numbers() {
|
|||||||
i = 0
|
i = 0
|
||||||
val = 0
|
val = 0
|
||||||
() {
|
() {
|
||||||
val = val + { 2 * i } + 1
|
&val = val + { 2 * i } + 1
|
||||||
i = i + 1
|
&i = i + 1
|
||||||
[val]
|
[val]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,11 +12,10 @@ calculator = (max int) {
|
|||||||
sum = 0
|
sum = 0
|
||||||
for i max {
|
for i max {
|
||||||
i = i + 1
|
i = i + 1
|
||||||
// println("i: {0}".format(i.to_string()))
|
// println("i: {0} s: {1}".format(i.to_string() sum.to_string()))
|
||||||
println("i: {0} s: {1}".format(i.to_string() sum.to_string()))
|
&sum = sum + i
|
||||||
sum = sum + i + 1
|
|
||||||
if fake_delay sleep(1)
|
if fake_delay sleep(1)
|
||||||
v = i * 100 / max
|
&progress = i * 100 / max
|
||||||
}
|
}
|
||||||
"the sum of all numbers from 0 to {0} is {1}!".format(max.to_string() sum.to_string())
|
"the sum of all numbers from 0 to {0} is {1}!".format(max.to_string() sum.to_string())
|
||||||
}
|
}
|
||||||
|
@ -587,7 +587,43 @@ impl BuiltinFunction {
|
|||||||
unreachable!("await called without args")
|
unreachable!("await called without args")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Self::Pop | Self::Remove | Self::Get => {
|
Self::Pop => {
|
||||||
|
if let Some(v) = input.first() {
|
||||||
|
if let Some(v) = v.dereference() {
|
||||||
|
VType {
|
||||||
|
types: vec![
|
||||||
|
VSingleType::Tuple(vec![]),
|
||||||
|
VSingleType::Tuple(vec![v
|
||||||
|
.get_any(info)
|
||||||
|
.expect("cannot use get on this type")]),
|
||||||
|
],
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
unreachable!("pop called on a non-reference");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
unreachable!("pop called without args");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Self::Remove => {
|
||||||
|
if input[1].fits_in(&VSingleType::Int.to(), info).is_empty() {
|
||||||
|
if let Some(v) = input[0].dereference() {
|
||||||
|
VType {
|
||||||
|
types: vec![
|
||||||
|
VSingleType::Tuple(vec![]),
|
||||||
|
VSingleType::Tuple(vec![v
|
||||||
|
.get_any(info)
|
||||||
|
.expect("cannot use get on this type")]),
|
||||||
|
],
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
unreachable!("remove called on a non-reference");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
unreachable!("remove called, but second arg not an int");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Self::Get => {
|
||||||
if let Some(v) = input.first() {
|
if let Some(v) = input.first() {
|
||||||
VType {
|
VType {
|
||||||
types: vec![
|
types: vec![
|
||||||
@ -598,7 +634,7 @@ impl BuiltinFunction {
|
|||||||
],
|
],
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
unreachable!("get, pop or remove called without args")
|
unreachable!("get called without args")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Self::Exit => VType { types: vec![] }, // doesn't return
|
Self::Exit => VType { types: vec![] }, // doesn't return
|
||||||
|
Loading…
Reference in New Issue
Block a user