1
0
dust/examples/scope.ds

61 lines
630 B
Plaintext
Raw Normal View History

2023-10-29 23:31:06 +00:00
# Function
x = "bar"
2023-10-06 12:17:37 +00:00
2023-10-29 23:31:06 +00:00
func = function <> {
x = "foo"
x
}
2023-10-06 12:17:37 +00:00
2023-10-31 02:12:03 +00:00
(assert_equal "foo", (func))
(assert_equal "bar", x)
2023-10-06 12:17:37 +00:00
2023-10-29 23:31:06 +00:00
# For Loop
x = 42
2023-10-06 12:17:37 +00:00
2023-10-29 23:31:06 +00:00
for number in [1 2 3] {
x += number
}
2023-10-31 02:12:03 +00:00
(assert_equal 48, x)
2023-10-29 23:31:06 +00:00
# Async Loops
## Transform Loop
x = 42
y = [1 2 3]
transform number in y {
number += x
x = 1000
}
2023-10-31 02:12:03 +00:00
(assert_equal [43, 44, 45], y)
(assert_equal 42, x)
2023-10-29 23:31:06 +00:00
## Filter Loop
x = 42
y = [1 2 3]
transform number in y {
number += x
x = 1000
}
2023-10-31 02:12:03 +00:00
(assert_equal [43, 44, 45], y)
(assert_equal 42, x)
2023-10-29 23:31:06 +00:00
## Filter Loop
x = 42
y = [1 2 3]
filter number in y {
number += x
x = 1000
}
2023-10-31 02:12:03 +00:00
(assert_equal [43, 44, 45], y)
(assert_equal 42, x)