[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: |
Thu, 8 Mar 2012 17:42:40 +1030 (CST) |
On Sun, 4 Mar 2012, Duke Normandin wrote:
> > 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.
>
> Yes! Of course .... My bad! Poor choice of example. I should have
> put 3 dots in the parentheses to show that I was omitting the
> arguments to describe a "catch-all" function!
>
> [snip]
>
> > there is no return value so you are not forced to use the return
> > value.
> >
> > You choose.
>
> I was just about sure that like Oberon2 (which I'm somewhat
> familiar with), if a function declares a return value (i.e.
> ... ):INT, then it must be *used*. Thanks for confirming that!
> and the fact that "out" args simply give me a choice.
>
> >
> > You might also use a tuple as the return type to handle two
> > return values:
> >
> > divide(x, y):TUP{INT,INT} is
> > ...
> > end;
> Hadn't gotten that far in the tutorial - but thanks for the
> heads-up!
But maybe I was wrong all along. Here is a routine (named create)
with a return value that seems to not require use of the return value.
I want debug messages to be in create expressions like #OUT.
class MAIN is
main is
#DDD+"not debugging\n";
DDD::debugger:=true;
#DDD+"yes, debugging\n"
end;
end;
class DDD is
shared debugger:BOOL;
create:SAME is return new end;
plus(arg:STR) is
if debugger then
#OUT+arg
end;
end;
end;
That works as unexpected. It prints "yes, debugging" without protest,
although DDD::create:SAME has a return value that isn't assigned. Is
this right, or am I missing something? Is the return value used, or not?
--
Michael Talbot-Wilson