Page 1 of 1

Named and optional parameters

PostPosted: Mon Aug 05, 2013 9:33 pm
by Charles
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

Re: Named and optional parameters

PostPosted: Mon Aug 05, 2013 10:18 pm
by torial
Awesome, thanks hopscc!

Re: Named and optional parameters

PostPosted: Tue Aug 06, 2013 7:55 am
by nerdzero
Nice work, hops!

Re: Named and optional parameters

PostPosted: Sun Aug 11, 2013 10:12 pm
by nerdzero
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.

Re: Named and optional parameters

PostPosted: Mon Aug 12, 2013 12:00 am
by Charles
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.

Re: Named and optional parameters

PostPosted: Mon Aug 12, 2013 6:55 am
by nerdzero
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.