[Seed7-users] Seed7 - Using References
Interpreter and compiler for the Seed7 programming language.
Brought to you by:
thomas_mertes
|
From: Zaakari <Za...@pr...> - 2025-10-20 22:24:49
|
Ah, it never registered with me before that I had to use interfaces to pass references around. So then, given: const type: Point is new interface; const type: Flashy is new struct type_implements_interface(Flashy, Point); Not only is your example possible (same-level reassignment): var Point: a is Flashy.value; var Flashy: b is Flashy.value; var Flashy: c is Flashy.value; a := b; # make adjustments to b using a... a := c; # make adjustments to c using a... But also reassignment via function (given that a, b and c were all declared outside the function): (* A simple example here, but--in reality--the second parameter would end up being either an array or a containing object *) const proc: switch_to (inout Point: base, in Point: target) is func begin base := target; # target isn't local, so all is well.end func; switch_to(a, b); # make adjustments to b using a... switch_to(a, c); # make adjustments to c using a... In the past, I was doing something similar to this without templates, and it was a huge pain (basically using integers to remember object offsets within arrays); so thank you for clearing up the confusion for me (my desire to use Seed7 has been renewed ;). Zachary |