Page 1 of 1

[Suggestion:] v in RegExMatch('x','y',&v) should return 0 or false

Posted: 19 Jan 2024, 23:51
by V2User
I wish v in RegExMatch('x','y',&v) to be set to 0/false rather than "", when match is not found.

See these code below:
<code a:>

Code: Select all

	
	;(1) Match is not found, and v will be ""
	RegExMatch('x','y',&v) 

 	;(2)A Match is found, and both will be a matchObj in v this time, and v[] is ""
	RegExMatch('x','y?',&v)
	,RegExMatch('x',"",&v)
<code b:>

Code: Select all

	;(1) A subPattern is found, and v['c'] is ""
	;It's the with v[] in <code a>.  It's right.
	RegExMatch('x','(?<c>y?)',&v)
	,OutputDebug(v['c'])

	;(2) SubPattern is not found, but v['c'] is also ""
	;Both results are the same, this time.
	;This is inconsist with <code a> where both results are different.
	;It is not reasonable.  
	; I think v['c'] is better to return 0 this time.
	RegExMatch('x','(?<c>y)|.*',&v)
	,OutputDebug(v['c'])

	;(3) SubPattern name is not found and it will return unset.
	;At least, I wish v['f'] would return unset, just like v.f??XXX
	RegExMatch('x','(?<c>y)|.*',&v)
	;,OutputDebug(v['f'])
I wish both v in <code a> and v['c'] in <code b> would return 0, when match is not found.

By the way, the suggestion is backward compatible. Because both "" and 0 works equally for an If keyword.

Re: [Suggestion:] v in RegExMatch('x','y',&v) should return 0 or false

Posted: 20 Jan 2024, 04:02
by just me
V2User wrote: By the way, the suggestion is backward compatible. Because both "" and 0 works equally for a If keyword.
So why should it be changed?

Re: [Suggestion:] v in RegExMatch('x','y',&v) should return 0 or false

Posted: 20 Jan 2024, 06:29
by V2User
just me wrote:
20 Jan 2024, 04:02
V2User wrote: By the way, the suggestion is backward compatible. Because both "" and 0 works equally for a If keyword.
So why should it be changed?
If it finds a blank String in sub pattern, then returning "" is reasonable.
If it doesn't find in sub pattern, then it might be better to return 0, for distinguishing, I think.
Thereupon, through what it returns, we could know exactly whether it has found or not.

Re: [Suggestion:] v in RegExMatch('x','y',&v) should return 0 or false

Posted: 20 Jan 2024, 09:52
by iseahound
Completely agree at how frustrating this is. I'm just using type(c) == RegExMatchInfo for now, but in my opinion an empty array with a default of "" should fix most errors like v[1]. Also Lexikos might make it unset because that should be the default return value for v2.1

Re: [Suggestion:] v in RegExMatch('x','y',&v) should return 0 or false

Posted: 20 Jan 2024, 17:50
by just me
V2User wrote: Thereupon, through what it returns, we could know exactly whether it has found or not.

Code: Select all

MsgBox(RegExMatch('x','(?<c>y)|.*',&v))    ; 1
MsgBox(v.Count)                            ; 1
MsgBox(v.Pos["c"])                         ; 0 !!!

V2User wrote: ;At least, I wish v['f'] would return unset, just like v.f??XXX
If no property named "f" exists, it cannot be unset.

Re: [Suggestion:] v in RegExMatch('x','y',&v) should return 0 or false

Posted: 20 Jan 2024, 20:37
by V2User
Maybe v.f? could return unset in language support. ;)