Allow omission of optional parameters in Properties

Propose new features and changes
Coco
Posts: 771
Joined: 29 Sep 2013, 20:37
Contact:

Allow omission of optional parameters in Properties

27 Jan 2015, 11:09

Currently the following exception is thrown when accessing class properties via this form obj.Propery[0,,4] ; 2nd argument is omitted:

Code: Select all

Test.ahk (11) : ==> Unexpected comma
     Specifically: .Property[0,,4]
Is it possible to allow omission of optional argument(s) similar to functions(when calling)?
User avatar
fincs
Posts: 527
Joined: 30 Sep 2013, 14:17
Location: Seville, Spain
Contact:

Re: Allow omission of optional parameters in Properties

27 Jan 2015, 11:43

No, because the default parameters for object invocation do not necessarily exist and even if they exist they are not known at load time.
fincs
Windows 11 Pro (Version 22H2) | AMD Ryzen 7 3700X with 32 GB of RAM | AutoHotkey v2.0.0 + v1.1.36.02
Get SciTE4AutoHotkey v3.1.0 - [My project list]
lexikos
Posts: 9589
Joined: 30 Sep 2013, 04:07
Contact:

Re: Allow omission of optional parameters in Properties

27 Jan 2015, 17:10

Yes, it's possible. It was disallowed before properties were added because it wasn't very useful, and disallowing it simplified objects by allowing them to assume the index/key was never missing (when param count > n). Without that check (and without adding other checks for each type of object), built-in code would treat a missing parameter as an empty string. For example, x[,1] := "foo" would be equivalent to x["",1] := "foo" as far as the default behaviour goes, but for meta-functions and properties the parameter would actually be omitted.

fincs, that's been irrelevant since v1.1.12 (this commit). Nothing about the object is known at load time; the default parameters aren't known at load time in this case, but it still works:

Code: Select all

class x {
    prop[v1, v2:="default"] {
        get {
            return v2
        }
    }
}
MsgBox % x.prop[0]
The default parameters do not necessarily exist in these cases, but the script still loads:

Code: Select all

%fn%()
xx.foo[]
xx.bar()
It might be better to say that the parameters do not necessarily exist, so they can't be "required" at load time.
Coco
Posts: 771
Joined: 29 Sep 2013, 20:37
Contact:

Re: Allow omission of optional parameters in Properties

28 Jan 2015, 03:58

lexikos wrote:Yes, it's possible. It was disallowed before properties ...
I wish it gets allowed since optional parameters w/ default values (esp. the ones in the beginning) are sometimes unusable at the moment.

Return to “Wish List”

Who is online

Users browsing this forum: No registered users and 6 guests