optional parameters in functions

17 views
Skip to first unread message

chris

unread,
Apr 25, 2011, 3:45:11 PM4/25/11
to Aardvark
Hi:

Are optional parameters allowed in non-target functions allowed in
aardvark? The following simple vark file reports errors:

function targetUsingOptionalValue() {
withOptionalParameter("some parameter")
}

function targetSpecifyingValue() {
withOptionalParameter("some other param", true)
}


private function withOptionalParameter(required_param : String,
bg=false) {
print("Hello: ${required_param} - ${bg}")
}


Wrong number of arguments to function
withOptionalParameter(java.lang.String, boolean). Expected 2, got 1.
[line:3 col:25] in
line 2: function targetUsingOptionalValue() {
line 3: withOptionalParameter("some parameter")
line 4: }
Line Number: 3 Column: 25

Thanks

Chris

Gus Prevas

unread,
Apr 25, 2011, 4:15:55 PM4/25/11
to aardv...@googlegroups.com
I think you need to specify the type of your optional parameter:

private function withOptionalParameter(required_param : String,
bg : boolean = false) {

Chris Gow

unread,
Apr 25, 2011, 4:24:41 PM4/25/11
to aardv...@googlegroups.com
Yeah, I tried that with the same result. The code does work as is if its a gsp file (gotta love type inference) and I call one of the functions.

Carson Gross

unread,
Apr 25, 2011, 4:31:08 PM4/25/11
to aardv...@googlegroups.com
It might be a vark issue, rather than a gosu issue.  I don't know what version of gosu the current release of vark is using...

Cheers,
Carson

Brian Chang

unread,
Apr 25, 2011, 5:09:41 PM4/25/11
to aardv...@googlegroups.com
Hm, I see this issue in 0.3.2, but somehow things are fine in my bleeding edge 0.3.3 build, both with and without the parameter type.  Hang on, and I'll follow up on the other thread so that you can build 0.3.3 from source.


Carson Gross

unread,
Apr 25, 2011, 5:11:39 PM4/25/11
to aardv...@googlegroups.com
Maybe a bug fix in Gosu?

Cheers,
Carson

chris

unread,
Apr 26, 2011, 9:48:45 AM4/26/11
to Aardvark
Yeah looks like the problem goes away with the latest aardvark from
git.

On Apr 25, 5:11 pm, Carson Gross <carsongr...@gmail.com> wrote:
> Maybe a bug fix in Gosu?
>
> Cheers,
> Carson
>
>
>
>
>
>
>
> On Mon, Apr 25, 2011 at 2:09 PM, Brian Chang <bchan...@gmail.com> wrote:
> > Hm, I see this issue in 0.3.2, but somehow things are fine in my bleeding
> > edge 0.3.3 build, both with and without the parameter type.  Hang on, and
> > I'll follow up on the other thread so that you can build 0.3.3 from source.
>
> > On Mon, Apr 25, 2011 at 1:31 PM, Carson Gross <carsongr...@gmail.com>wrote:
>
> >> It might be a vark issue, rather than a gosu issue.  I don't know what
> >> version of gosu the current release of vark is using...
>
> >> Cheers,
> >> Carson
>
> >> On Mon, Apr 25, 2011 at 1:24 PM, Chris Gow <chris....@gmail.com> wrote:
>
> >>> Yeah, I tried that with the same result. The code does work as is if its
> >>> a gsp file (gotta love type inference) and I call one of the functions.
>
> >>> On Mon, Apr 25, 2011 at 4:15 PM, Gus Prevas <kpre...@gmail.com> wrote:
>
> >>>> I think you need to specify the type of your optional parameter:
>
> >>>> private function withOptionalParameter(required_param : String,
> >>>> bg* : boolean* = false) {
>
> >>>> On Mon, Apr 25, 2011 at 3:45 PM, chris <chris....@gmail.com> wrote:
>
> >>>>> Hi:
>
> >>>>> Are optional parameters allowed in non-target functions allowed in
> >>>>> aardvark? The following simple vark file reports errors:
>
> >>>>> function targetUsingOptionalValue() {
> >>>>>  withOptionalParameter("some parameter")
> >>>>> }
>
> >>>>> function targetSpecifyingValue() {
> >>>>>  withOptionalParameter("some other param", true)
> >>>>> }
>
> >>>>> private function withOptionalParameter(required_param : String,
> >>>>> bg=false) {
> >>>>>  print("Hello: ${required_param} - ${bg}")
> >>>>> }
>
> >>>>> Wrong number of arguments to function
> >>>>> withOptionalParameter(java.lang.String, boolean).  Expected 2, got 1.
> >>>>> [line:3 col:25] in
> >>>>> line 2: function targetUsingOptionalValue() {
> >>>>> line 3:   withOptionalParameter("some parameter")
> >>>>> line 4: }
> >>>>> Line Number: 3  Column: 25
>
> >>>>> Thanks
>
> >>>>> Chris
>
> > --
> > Brian
> > bchan...@gmail.com
Reply all
Reply to author
Forward
0 new messages