reference - pannous/warp GitHub Wiki
reference
A reference is an abstract handle to an object.
references in angle
see Variables for now
reference in wasp
Wasp as data language can represent cyclic graphs through references independent of the consuming programming language ( like Angle).
A node can refer back to an enclosing node by name with the prefix $, or by its id attribute with the prefix
@; in words ref a and ref 1. A reference stays a name, so a cyclic graph prints without looping, and a path
follows it:
x = a{
b: 2
c{ parent=$a }
}
x.c.parent.b # 2
x = a[id=1]{
b: 2
c{ parent=@1 }
}
x.c.parent.b # 2
a[id=1]{…} is a{@id:1 …}: attributes in brackets before a body are its meta entries.
ref a / ref 1 say the same in words (a variable or function you name ref wins).
$1 is never an id: $0, $1 are the positional parameters of a closure ({ $0 + $1 }) and of a compiled function.
Writing $1 where an enclosing node has id 1 gives a got-it note naming @1.
TODO Variables are referenceIndices to values. peter=person#2
One needs to distinguish between changing the reference and changing the value of the reference. (In c this is achieved via *x=7 or int &y=… y=8).
In angle this might be achieved with special keywords reference or value or inout:
Planned: (card reference-value-of)
peter=person#2
peter=person#3 // changing reference
value of peter=James // now person#3 is charged to James (following reference)
person#3=John // now peter points to John too (reference following)
As in swift, reference is the standard modus operandi, only when attributes are charged will a true copy occur : Swift doesn't copy until there's a mutation or the possibility of mutation.
Internal usage:
Special hardwired ternary operators: array#position=value, list[index]=value, data[pattern]=value, condition?then:else The first cases can be handled via references