Page 1 of 1

out parameters?

PostPosted: Sat Jan 03, 2009 5:37 pm
by gauthier
how can I define out parameters?

class Foo
def bar(out value as int)
value = 1

class Program
def main is shared
foo = Foo()
foo.bar(out v)
print v


gives:

Code: Select all
main.cobra(2): error: main.cobra(2,10): error: Expecting ID, but got "out" instead.
Compilation failed - 1 error, 0 warnings
Not running due to errors above.


EDIT:

found at ~/Tests/200-misc/400-arguments/

argumentName as out ArgumentType

Re: out parameters?

PostPosted: Sat Jan 03, 2009 7:38 pm
by Charles
I enhanced the parser to catch this (and some other possibilities) and show the correct syntax in the error message. changeset:1875

Example error message:

error: The correct parameter syntax is "paramName as out ParamType".

Re: out parameters?

PostPosted: Sun Jan 04, 2009 6:59 pm
by natter
:idea:
what do you think about using existing 'get, set, pro' instead of 'in, out, inout'?

Code: Select all
def bar(get value_x as int, set value_y as int, pro value_z as int)

.bar(get x, set y, pro z)

Re: out parameters?

PostPosted: Sun Jan 04, 2009 7:30 pm
by Charles
natter, where you been, man? Haven't seen you since November. :-)

The "set" doesn't look too bad, but the "pro" really does stand for property and I don't think it fits in the signature. I took the names of in/out/inout from the .NET VM itself per a book on the CLR. Also, I think they make sense. And more sense than C#'s out/ref.

Re: out parameters?

PostPosted: Mon Jan 05, 2009 3:29 am
by hopscc
For method parameters I think in,out,inout is a whole lot clearer that set, get,pro -
'setting' a value is not the same as passing a value in ,,,,

Re: out parameters?

PostPosted: Mon Jan 05, 2009 9:06 am
by natter
i have been coding in D since november, but reading almost every day this forum ;-)

i thought get/set/pro would mean the very same and would be more cobra style
tbh, i didnt know pro stands for property, my guess was 'process'.. :roll:

Re: out parameters?

PostPosted: Mon Jan 05, 2009 1:15 pm
by Charles
What do you like/dislike about Cobra compared to D based on your experience and your reading?

Re: out parameters?

PostPosted: Mon Jan 05, 2009 3:05 pm
by natter
i like cobra more than D. i only dont like its current C# only backend.
i would never ever write anything else than a small and fast executable.
D is the mightiest tool for writing those, but its ugly like hell.
im reading the cobra forums to see the process towards a multibackend language.
once there is a good basis to implement a D backend i will sit down and .. fail ;)

Re: out parameters?

PostPosted: Mon Jan 05, 2009 4:41 pm
by Charles
Thanks for the feedback. "cobra hello" produces a fairly small program:

3,584 hello.exe

I know it still requires the .NET run-time, but on the plus side you have access to profilers, libraries and other tools. In any case, I look forward to your D backend later this year. :-)