[v2] Loop comma, &OutputVar Topic is solved

Share your ideas as to how the documentation can be improved.
AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

[v2] Loop comma, &OutputVar

Post by AHK_user » 28 Jul 2021, 15:47

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])
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: AHK V2 Helpfile

Post by swagfag » 28 Jul 2021, 16:11

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)
Last edited by swagfag on 28 Jul 2021, 16:30, edited 1 time in total.
AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: AHK V2 Helpfile

Post by AHK_user » 28 Jul 2021, 16:22

My excuses, I have done some tests and it seems indeed to work.

I just started getting used to V2.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: AHK V2 Helpfile

Post by swagfag » 28 Jul 2021, 16:32

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
AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: AHK V2 Helpfile

Post by AHK_user » 30 Jul 2021, 18:00

@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..."
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: AHK V2 Helpfile

Post by swagfag » 31 Jul 2021, 02:17

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]
lexikos
Posts: 9559
Joined: 30 Sep 2013, 04:07
Contact:

Re: [v2] Loop comma, &OutputVar

Post by lexikos » 31 Jul 2021, 02:24

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.
neogna2
Posts: 586
Joined: 15 Sep 2016, 15:44

Re: [v2] Loop comma, &OutputVar

Post by neogna2 » 31 Jul 2021, 03:37

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.
User avatar
Ragnar
Posts: 611
Joined: 30 Sep 2013, 15:25

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

Post by Ragnar » 05 Aug 2021, 06:24

Changes added in PR #492.
AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: [v2] Loop comma, &OutputVar

Post by AHK_user » 05 Sep 2021, 05:37

Ragnar wrote:
05 Aug 2021, 06:24
Changes added in PR #492.
Thanks :D
Post Reply

Return to “Suggestions on Documentation Improvements”