Hi!
I've been reading through the reference manual and come across examples involving ref parameters and returns, as well as optionals.
Refs seem to enable pass-by/return-by reference semantics, similar to ref parameters/returns/locals in C#, or reference types in C++ (except in C++ the reference-ness is part of the type rather then part of the variable).
Optionals seem to encode the typical Option/Maybe type and encode a value that is either a valid object, or null.
Now, there is a List example in the manual showing a function:
func Nth_Element(ref L : List, N : Univ_Integer) -> ref optional Element
implying that the element is returned by reference if found, or null if no nth element exists. In most languages with an Optional type you would encode such a thing as an optional reference to the object (optional ref Element) rather then a reference to optional (ref optional Element). However, in Parasail the reference-ness is part of the variable/return value instead of the type (as in C++), so that's not possible. So we have to use ref optional Element instead, and indeed the example code in the manual seems to return null just fine.
In most languages that allow reference semantics you can only create a reference to a concrete location (aka a lvalue) and not a temporary object or literal (aka a rvalue). Here however we are returning the literal value null by reference, and I wonder what the exact semantics of such an operation are. Where is that null object stored that we refer to? If we return null by reference, and assign it to a ref var local of type Element, what happens if we reassign that local variable? Or is there some special case going on behind the scenes for null? Or do reassignments of reference locals reseat the referred-to object to a different object - like pointers - rather then reassigning the referred-to object?
I hope my question is clear and would appreciate some insight in order to understand the Parasail language concepts better, as the reference manual did not clear that up to me.
Regards,
A