Is there any reason that a function/property can not return unset?
Is there any reason that a function/property can not return unset?
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".
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.
-
- Posts: 63
- Joined: 02 Jul 2020, 11:55
Re: Is there any reason that a function/property can not return unset?
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
Re: Is there any reason that a function/property can not return unset?
@SandyClamsSandyClams wrote: ↑09 Jan 2023, 14:26I'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
Thank you very much! It works in V2.0.0. I am so grateful for this, because I had been ignoring it all along before your reminder.
Re: Is there any reason that a function/property can not return unset?
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.
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.
-
- Posts: 63
- Joined: 02 Jul 2020, 11:55
Re: Is there any reason that a function/property can not return unset?
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.
Re: Is there any reason that a function/property can not return unset?
@Lexicos
Maybe it was time for you to reconsider it. As what you have described in the changes in v2.0.4:
If all situations of the vars return blank instead of blank string by default, the above optimization could come back again.
Maybe it was time for you to reconsider it. As what you have described in the changes in v2.0.4:
v2.0.4Removed an optimization for return var which caused the variable to appear blank when accessed within a finally block.
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.
Re: Is there any reason that a function/property can not return unset?
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".
Also, "blank" is synonymous with "empty string", not "unset".
Re: Is there any reason that a function/property can not return unset?
Oh, I see. Thank you for your patient answer.