[Top][All Lists]

[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:
> 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;

othermethod is

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

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

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

Michael Talbot-Wilson

reply via email to

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