Multiple return values ====================== Syntax for returning multiple values is trivial, it could be one of the following: return 1 2 # this matches how function calls look like return 1, 2 return [ 1 2 ] But how about the following: * How to define such functions: See func_sections.txt * How to receive multiple return values to existing variables? * How to receive multiple return values to new variables? - This can lead to quite long lines - But it could also be convenient. - But in C89 and Pascal you had to define the variables on separate lines in many cases and it worked fine. * How to return all return values as-is? Syntax test ----------- Syntax 1: Int e1 Bool e2 [ e1 e2 ] = somefunc [ Int n1 Bool n2 ] = somefunc return somefunc Syntax 2: Int e1 Bool e2 to e1 to e2 somefunc to Int n1 to Bool n2 somefunc return somefunc Syntax 3: # Using ,= to make it less confusing for C, Java or C++ programmers Int e1 Bool e2 e1, e2 ,= somefunc Int n1, Bool n2 ,= somefunc return somefunc Syntax 4: Int e1 Bool e2 e1 =, e2 = somefunc Int n1=, Bool n2 = somefunc return somefunc Syntax 5: Int e1 Bool e2 e1, e2 ]= somefunc Int n, Bool n2 ]= somefunc return somefunc Syntax 6: # Skip support for declarations of multiple variables on 1 line. Int e1 Bool e2 e1, e2 = somefunc Int n1 Bool n2 n1, n2 = somefunc return somefunc Syntax 7: Int e1 Bool e2 e1, e2 = somefunc Int n1, Bool n2, = somefunc return somefunc Syntax 8: # This leads to an ambiguity with array element assignment, # but maybe it can be solved somehow? Int e1 Bool e2 e1 e2 = somefunc arr i = somefunc return somefunc Syntax 9: Int e1 Bool e2 set e1 e2 = somefunc return somefunc Alternative solutions --------------------- Alternative solution 1: Error/Context objects Int e1 Bool e2 e1 = somefunc e2 = ctx.get_xxx Int n1 = somefunc Bool n2 = ctx.get_xxx return somefunc # context is available to the caller Alternative solution 2: Make ad-hoc definitions of structs easy # Syntax 1: without names Pair Int Bool ep ep = somefunc Pair Int Bool np = somefunc return somefunc # Syntax 2: also without names Int/Bool ep ep = somefunc Int/Bool np = somefunc return somefunc # Syntax 3: also without names # a comma is still required to distinguish it from generic types (Int, Bool) ep ep = somefunc (Int, Bool) np = somefunc return somefunc # Syntax 4: record definitions, with names record SomeFuncReturn Int x Bool b end SomeFuncReturn ep ep = somefunc SomeFuncReturn np = somefunc return somefunc Alternative solution 3: Don't support multiple-return values Classes are quite easy to define in SLUL, so it might not be necessary.