-
-
Notifications
You must be signed in to change notification settings - Fork 4
variable
A scoped variable is a key in the current object map. There are subtle differences between constant variable declarations and mutating variable assignments. In the root score and constructor scopes, symbols are assumed to be newly defined:
a=3
{a:3}
Here a is freshly created. If it exists in an outer scope
{
a:4
b:{a:5}
}
these two instances of symbol 'a' exist independently side-by-side. they can naturally be accessed by it.a (==4) and it.b.a (==5)
sub scopes have access to parent variables:
{
c:4
b:{a:c}
}
it.b.a==4
it.b.c==4
ideally future IDEs offer support for different layout of those inherited properties in auto completion: integrate parent properties alphabetically or separate by degree of inheritance.
variables are different to functions
The parser should differentiate between variables and functions via these heuristics:
- functions have braces left of the assignment
square(n)=n*n
or - functions have blocks right of the assignment
square = {it*it}
or - functions use
:=
for the assignmentsquare:=it*it
The difference to square=it*it
is that variables get evaluated instantly and only once, whereas
The function square:=it*it
is a dangling closure
sometimes it is desirable to access variables which are not directly in the parent scope:
{
colors:{red:(1 0 0) green:(0 1 0)}
circle:{radius:5 color:red}
}
color:red is unambivalent if there are no other occurrences of red, however it might be necessary to specify the exact reference via path or making it global via ID. todo Each subpath acts as a pattern for the current scope:
{
colors:{red:(1 0 0) green:(0 1 0)}
circle:{radius:5 color: colors.red}
}
Here colors.red
can be understood
- in an object oriented way (accessing the property
red
of the variable colors) - as an enum colors with value red
- as a reference path for the parent scopes
- in an agnostic way
let person be...
variables cannot be reassigned
the person
reference to previous declaration
a person
declaration or reference