info-sather
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using "return" values or "out" arguments


From: Sather User
Subject: Re: Using "return" values or "out" arguments
Date: Mon, 5 Mar 2012 13:02:16 +1030 (CST)

On Sun, 4 Mar 2012, Duke Normandin wrote:

> In:
>
> http://www.icsi.berkeley.edu/~sather/Documentation/LanguageDescription/webmaker/DescriptionX2Echapter2-1.html#HEADING1-87
>
> it says that Sather forces the use of return values, i.e. something
> like the following needs to exist:
>
> blah := some_method() + 4;

"expression expected, but found a right parenthesis ')' (in expression
(prec = 0))"

In Sather, a function that doesn't have arguments is not designated by
empty parentheses.  Following the "(" an expression was expected.

>
> Yet, down the page a bit, the "divide" function is declared, and
> simply "called" to load up the "div" and "rem" variables.
>
> divide(a,b,out div, out rem);


somemethod:INT is
  return 5;
end;

othermethod is
  #OUT+5;
end;

The first returns an integer which must be assigned.  The second does
not.  There is no return value so Sather does not force the use of the
return value.

> So, am I to understand that an *out* argument in a function, is a
> way to get around *having* to use use an explicit "return"
> value/statement? Any benefit to doing this way, rather than
> following the Sather "return a value and use it" discipline?

Think of

divide(x, y, out remainder:INT):INT is
...
end;

The dividend is a return value in that case, so has to be assigned.  But with

divide(x, y, out dividend, out remainder:INT) is
...
end;

there is no return value so you are not forced to use the return value.

You choose.

You might also use a tuple as the return type to handle two return values:

divide(x, y):TUP{INT,INT} is
...
end;

-- 
Michael Talbot-Wilson



reply via email to

[Prev in Thread] Current Thread [Next in Thread]