Pointers and references: Difference between revisions

Add Ecstasy example
m (→‎{{header|Wren}}: Changed to Wren S/H)
(Add Ecstasy example)
 
Line 675:
→ 666
</syntaxhighlight>
 
=={{header|Ecstasy}}==
In Ecstasy, all values are references to objects. These references are like pointers in C, but address information is not accessible, and no arithmetic operations can be performed on them. Additionally, each reference is itself an object, providing reflective information about the reference.
 
Objects are always accessed and manipulated through references, using the <code>.</code> ("dot") operator.
 
Ecstasy uses call-by-value. When passing arguments, all arguments are references, passed by value.
 
<syntaxhighlight lang="ecstasy">
module test {
@Inject Console console;
 
public class Point(Int x, Int y) {
@Override String toString() = $"({x},{y})";
}
 
void run() {
Point p = new Point(0, 0);
p.x = 7;
p.y = p.x;
console.print($"{p=}");
 
// obtain the reference object itself
Ref<Point> r = &p;
console.print($"{r.actualType=}");
}
}
</syntaxhighlight>
 
{{out}}
<pre>
x$ xec test
p=(7,7)
r.actualType=Point
</pre>
 
=={{header|Forth}}==
162

edits