Forums

out parameters?

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

out parameters?

Postby gauthier » Sat Jan 03, 2009 5:37 pm

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
gauthier
 
Posts: 116

Re: out parameters?

Postby Charles » Sat Jan 03, 2009 7:38 pm

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".
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: out parameters?

Postby natter » Sun Jan 04, 2009 6:59 pm

: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)
natter
 
Posts: 20

Re: out parameters?

Postby Charles » Sun Jan 04, 2009 7:30 pm

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.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: out parameters?

Postby hopscc » Mon Jan 05, 2009 3:29 am

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 ,,,,
hopscc
 
Posts: 632
Location: New Plymouth, Taranaki, New Zealand

Re: out parameters?

Postby natter » Mon Jan 05, 2009 9:06 am

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:
natter
 
Posts: 20

Re: out parameters?

Postby Charles » Mon Jan 05, 2009 1:15 pm

What do you like/dislike about Cobra compared to D based on your experience and your reading?
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: out parameters?

Postby natter » Mon Jan 05, 2009 3:05 pm

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 ;)
natter
 
Posts: 20

Re: out parameters?

Postby Charles » Mon Jan 05, 2009 4:41 pm

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. :-)
Charles
 
Posts: 2515
Location: Los Angeles, CA


Return to Discussion

Who is online

Users browsing this forum: No registered users and 53 guests

cron