Page 1 of 1

[v2] Loop comma, &OutputVar

Posted: 28 Jul 2021, 15:47
by AHK_user
I think I foud some corrections for the helpfile of V2 2.0-beta.1.


Loop Parse String [, Delimiters, OmitChars]
=>
Loop Parse, String [, Delimiters, OmitChars]


FoundPos := RegExMatch(Haystack, NeedleRegEx , OutputVar, StartingPos := 1)
=>
FoundPos := RegExMatch(Haystack, NeedleRegEx , &OutputVar, StartingPos := 1)


NewStr := RegExReplace(Haystack, NeedleRegEx [, Replacement := "", OutputVarCount := "", Limit := -1, StartingPos := 1])
=>
NewStr := RegExReplace(Haystack, NeedleRegEx [, Replacement := "", &OutputVarCount := "", Limit := -1, StartingPos := 1])


ReplacedStr := StrReplace(Haystack, Needle [, ReplaceText, CaseSense, OutputVarCount, Limit])
=>
ReplacedStr := StrReplace(Haystack, Needle [, ReplaceText, CaseSense, &OutputVarCount, Limit])

Re: AHK V2 Helpfile

Posted: 28 Jul 2021, 16:11
by swagfag
none seem to apply
v2-changes::Loop wrote:Currently the keyword [secondary keyword (Files, Parse, Read or Reg)] can be followed by a comma, but it is not required as this is not a parameter.

varref
that usage is neither implied nor required. u can pass a plain variable containing a VarRef just as well(ie the & is not necessarily necessary, no pun intended)

Re: AHK V2 Helpfile

Posted: 28 Jul 2021, 16:22
by AHK_user
My excuses, I have done some tests and it seems indeed to work.

I just started getting used to V2.

Re: AHK V2 Helpfile

Posted: 28 Jul 2021, 16:32
by swagfag
no need to apologize. an untainted gaze may after all spot something others have been missing all along. or it might not. u never know. keep digging

Re: AHK V2 Helpfile

Posted: 30 Jul 2021, 18:00
by AHK_user
@swagfag: Could you confirm something for me?

In RegExreplace, if you enter a value in the 4th parameter, should it always have a "&" in front if it is not empty?

If that is the case, wouldn`t it be logically and user-friendly to also add a "&" before it in the syntax in the helpfile like I proposed above?

The same applies for many functions with byref variables.

NewStr := RegExReplace(Haystack, NeedleRegEx [, Replacement := "", &OutputVarCount := "", Limit := -1, StartingPos := 1])

If I do not include the & I get errors like "This variable appears to never be assigned a value." or "Parameter #4 of RegExReplace requires a variable refernce, but recieved a String/Integer..."

Re: AHK V2 Helpfile

Posted: 31 Jul 2021, 02:17
by swagfag
i think i already confirmed that
swagfag wrote:
28 Jul 2021, 16:11
that usage is neither implied nor required. u can pass a plain variable containing a VarRef just as well(ie the & is not necessarily necessary, no pun intended)

Code: Select all

#Requires AutoHotkey v2.0-beta.1

Ref := &Var
RegExMatch('abcdef', '(def)', Ref)
MsgBox Var[1]

Re: [v2] Loop comma, &OutputVar

Posted: 31 Jul 2021, 02:24
by lexikos
Putting aside any other reasons to include & or not...

Suppose that you want to remove all digits in the string "abc123". Would you call RegExReplace(abc123, "") or RegExReplace("abc123", "")? If you do not include the "", you will get errors like "This variable appears to never be assigned a value." or "This variable has not been assigned a value." (Actually, the first one is a warning, not an error.)

With the current definition, if used literally, OutputVarCount should be a variable containing a VarRef, just as Haystack should be a variable containing a String.


Adding the & prefix would show at a glance what the parameter requires, and would facilitate "copy-paste coding".

If someone wants to make this change, I would support it.

I have moved and renamed the topic.

Re: [v2] Loop comma, &OutputVar

Posted: 31 Jul 2021, 03:37
by neogna2
Loop Parse String [, Delimiters, OmitChars]
I was confused by that at first too, I think because of Parse being a "secondary keyword" for Loop, whereas in most other cases in v2 there is only a single keyword, for example WinGetClass (not Win GetClass or Win Get Class). Lexikos, any reason for choosing Loop Parse rather than LoopParse (and LoopRead, LoopReg, LoopFiles) for v2 other than similarity with v1 usage?
lexikos wrote:
31 Jul 2021, 02:24
Adding the & prefix would show at a glance what the parameter requires, and would facilitate "copy-paste coding".
I like that.
lexikos wrote:
31 Jul 2021, 02:24
Putting aside any other reasons to include & or not...
It could help me in training my brain from v1 to v2 to hear about such reasons and especially if there are some cases where it is better coding practice to pass a variable containing a VarRef rather than passing &MyVar as e.g. OutputVarCount argument in RegExReplace.

Re: [v2] Loop comma, &OutputVar  Topic is solved

Posted: 05 Aug 2021, 06:24
by Ragnar
Changes added in PR #492.

Re: [v2] Loop comma, &OutputVar

Posted: 05 Sep 2021, 05:37
by AHK_user
Ragnar wrote:
05 Aug 2021, 06:24
Changes added in PR #492.
Thanks :D