You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In mathematics, you have the ∑ symbol that appears all over the place. It can be combined with a body with an arbitrary mathematical expression. Dyon uses this concept, making it easier to write programs in a more mathematical style.
The unicode symbol is be allowed in the syntax instead of the words "sum".
Example:
a := ∑ i len(list){ list[i]}
vs
sum := 0for i len(list){
sum += list[i]}
It can be used within an expression:
n := len(list)
mean := ∑ i n{ list[i]} / n
geometric_mean := exp(∑ i n{ ln(list[i])} / n)
You can use continue and break, just like a normal for loop:
continue skips the current index
break skips the rest of the indices
Other loops:
∏/prod (starts with 1)
min (starts with none())
max (starts with none())
sift (starts with [], puts result of block into an array)
∃/any (returns bool, starts with false)
∀/all (returns bool, starts with true)
Composition of loops
All the loops described here can be composed, which means to nest them and return a value from the inner loop:
a := min i {
min j { ...}}
This can be written as a packed loop:
a := min i, j { ...}
Secrets
any, all, min and max loops, and their compositions, generate a secret. This is used to find out why or where a value was returned from the loop:
a := min i, j { ...}println(where(a))// prints `[i, j]` of minimum value.
In mathematics, you have the ∑ symbol that appears all over the place. It can be combined with a body with an arbitrary mathematical expression. Dyon uses this concept, making it easier to write programs in a more mathematical style.
The unicode symbol is be allowed in the syntax instead of the words "sum".
Example:
vs
It can be used within an expression:
You can use
continue
andbreak
, just like a normalfor
loop:continue
skips the current indexbreak
skips the rest of the indicesOther loops:
1
)none()
)none()
)[]
, puts result of block into an array)bool
, starts withfalse
)bool
, starts withtrue
)Composition of loops
All the loops described here can be composed, which means to nest them and return a value from the inner loop:
This can be written as a packed loop:
Secrets
any
,all
,min
andmax
loops, and their compositions, generate a secret. This is used to find out why or where a value was returned from the loop:For more information about secrets, see #266
The text was updated successfully, but these errors were encountered: