Is there any reason that a function/property can not return unset?

Discuss the future of the AutoHotkey language
User avatar
V2User
Posts: 195
Joined: 30 Apr 2021, 04:04

Is there any reason that a function/property can not return unset?

Post by V2User » 08 Jan 2023, 08:29

As we know, unset can be directly assigned to a variable since beta12 like x:=unset. Is there any reason that it can not return unset/(var?) in a function or property?
If this can be implemented, then Any's base will return UnSet rather than a empty string "" which causes a confusing and endless "base cycle".
Last edited by V2User on 09 Jan 2023, 16:58, edited 1 time in total.

SandyClams
Posts: 63
Joined: 02 Jul 2020, 11:55

Re: Is there any reason that a function/property can not return unset?

Post by SandyClams » 09 Jan 2023, 14:26

I'm still using a v2 a few releases old, but unless the behavior has changed, it is possible to return unset from a function, i.e. to assign the result of the function call to a "lvalue" and cause it to be unset.

Code: Select all

Empty() {
  return (x := unset)
}
HasArgument(argument := unset) {
  return IsSet(argument)
}

a := Empty()
b := [Empty()]
c := HasArgument(Empty())
d := Map(Empty(), 'ass')
e := { prop: Empty() }

MsgBox(IsSet(a) || b.Has(1) || c || d.Count || e.HasProp('prop')) ; all false

User avatar
V2User
Posts: 195
Joined: 30 Apr 2021, 04:04

Re: Is there any reason that a function/property can not return unset?

Post by V2User » 10 Jan 2023, 00:12

SandyClams wrote:
09 Jan 2023, 14:26
I'm still using a v2 a few releases old, but unless the behavior has changed, it is possible to return unset from a function, i.e. to assign the result of the function call to a "lvalue" and cause it to be unset.

Code: Select all

Empty() {
  return (x := unset)
}
HasArgument(argument := unset) {
  return IsSet(argument)
}

a := Empty()
b := [Empty()]
c := HasArgument(Empty())
d := Map(Empty(), 'ass')
e := { prop: Empty() }

MsgBox(IsSet(a) || b.Has(1) || c || d.Count || e.HasProp('prop')) ; all false
@SandyClams
Thank you very much! It works in V2.0.0. :xmas: I am so grateful for this, because I had been ignoring it all along before your reminder.

lexikos
Posts: 9683
Joined: 30 Sep 2013, 04:07
Contact:

Re: Is there any reason that a function/property can not return unset?

Post by lexikos » 13 Jan 2023, 23:01

This is unintended, undocumented and unsafe to rely upon.

Unset (the state of lacking a value) is not meant to be quietly propagated. It should not be possible for HasArgument(Empty()) to return false, because an argument is clearly being passed without the ? operator.

unset, ? and ?? aren't supported more widely because I need to decide exactly what to consider correct behaviour, and then I need to implement it. Both aspects take time, and this is not a priority; it certainly wasn't a priority for the v2.0 release, which as you know, only happened a matter of weeks ago. Don't be impatient.

SandyClams
Posts: 63
Joined: 02 Jul 2020, 11:55

Re: Is there any reason that a function/property can not return unset?

Post by SandyClams » 14 Jan 2023, 02:03

lexikos wrote:
13 Jan 2023, 23:01
This is unintended, undocumented and unsafe to rely upon.

...
lol, I knew this so hard the second I saw what it did. It's so bad. I'm sorry! lolol

User avatar
V2User
Posts: 195
Joined: 30 Apr 2021, 04:04

Re: Is there any reason that a function/property can not return unset?

Post by V2User » 14 Jan 2023, 05:51

lexikos wrote:
13 Jan 2023, 23:01
I need to decide exactly what to consider correct behaviour, and then I need to implement it.
I hope it will become a correct behavior for you. Strongly please do not delete it at least. If this is supported, then dynamic properties can return unset. As value properties assigned by Unset does not exist. Dyanmic properties will become the only choice that can make it possible to directly pass many obj's properties with Unset to an optional param function like WinShow.

User avatar
V2User
Posts: 195
Joined: 30 Apr 2021, 04:04

Re: Is there any reason that a function/property can not return unset?

Post by V2User » 12 Jul 2023, 13:54

@Lexicos
Maybe it was time for you to reconsider it. As what you have described in the changes in v2.0.4:
Removed an optimization for return var which caused the variable to appear blank when accessed within a finally block.
v2.0.4
If all situations of the vars return blank instead of blank string by default, the above optimization could come back again. ;)
Last edited by V2User on 13 Jul 2023, 06:35, edited 2 times in total.

lexikos
Posts: 9683
Joined: 30 Sep 2013, 04:07
Contact:

Re: Is there any reason that a function/property can not return unset?

Post by lexikos » 13 Jul 2023, 06:24

I think you fail to understand the issue that this fixed. In my example, the string should have contained "Hello". Having it appear unset is just as incorrect as yielding an empty string.

Also, "blank" is synonymous with "empty string", not "unset".

User avatar
V2User
Posts: 195
Joined: 30 Apr 2021, 04:04

Re: Is there any reason that a function/property can not return unset?

Post by V2User » 13 Jul 2023, 06:44

lexikos wrote:
13 Jul 2023, 06:24
I think you fail to understand the issue that this fixed. In my example, the string should have contained "Hello". Having it appear unset is just as incorrect as yielding an empty string.

Also, "blank" is synonymous with "empty string", not "unset".
Oh, I see. Thank you for your patient answer. :P

Post Reply

Return to “AutoHotkey Development”