Forums

Named and optional parameters

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

Named and optional parameters

Postby Charles » Mon Aug 05, 2013 9:33 pm

Thanks to a patch by hopscc, we now have named parameters (ticket:326).

Also, an earlier patch from hopscc provided optional parameters through default values.

Here is a simplistic example:
class X

def main
.show('foo')
.show('bar', 5)
.show('baz', count=3)
.show(s='can', count=2)

def show(s as String, count as int = 2)
for i in count, print s
print
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Named and optional parameters

Postby torial » Mon Aug 05, 2013 10:18 pm

Awesome, thanks hopscc!
torial
 
Posts: 229
Location: IA

Re: Named and optional parameters

Postby nerdzero » Tue Aug 06, 2013 7:55 am

Nice work, hops!
nerdzero
 
Posts: 286
Location: Chicago, IL

Re: Named and optional parameters

Postby nerdzero » Sun Aug 11, 2013 10:12 pm

I'm working on parameter completion right now in the MD addin and am needing to parse the line to determine which overload to show the tooltip for. I have a question. How will using named parameters interact with the proposal for requiring a space for binary operators? In the examples listed there's no spaces before and after the equals sign. Is this going to change to require spaces or will this usage be an exception to that rule? I hope the question is clear.
nerdzero
 
Posts: 286
Location: Chicago, IL

Re: Named and optional parameters

Postby Charles » Mon Aug 12, 2013 12:00 am

Your question is clear. The requiring spaces around binary ops is very tentative. I would not bank on it right now.

Also, you should see that MemberOverload has a .computeBestMember method. If you can't use that directly, we could discuss how to refactor it if that makes sense, or you could use it as inspiration for a new method. As always, you can ping me here or by email to bounce ideas around.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Named and optional parameters

Postby nerdzero » Mon Aug 12, 2013 6:55 am

Cool, thanks. I'll write up a post on how I'm planning on implementing this to get some ideas from you guys. There's some interesting challenges. I think I know how to do the common cases but I think the trickier stuff will need to wait for the separate source analysis library that's been rolling around in my head for a while now.

I'll also send you an email about an internal exception I'm getting trying to compile the addin with latest SVN version of the compiler. I'm not sure what's going on there yet.

I'm getting ready for GenCon so I might not get around to this stuff until next week.
nerdzero
 
Posts: 286
Location: Chicago, IL


Return to Discussion

Who is online

Users browsing this forum: No registered users and 13 guests