In and Contains plans...

Discuss the future of the AutoHotkey language
Coco
Posts: 771
Joined: 29 Sep 2013, 20:37
GitHub: cocobelgica

In and Contains plans...

01 Jul 2014, 11:28

These are currently reserved keywords. I'm just wondering on what are the plans for these in terms of syntax/usage...
e.g.:

Code: [Select all] [Download] GeSHi © Codebox Plus

if var in/contains ['foo', 'bar', 'others']
OR if var in/contains 'foo,bar,others'

I prefer the former as it's clearer. Hence no need for:
  • Two consecutive commas results in a single literal comma
  • To include a blank item in the list, make the first character a comma
Also in can become multipurpose, e.g.: if key in {a:'A', b:'B', c:'C'}
lexikos
Posts: 5187
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: In and Contains plans...

01 Jul 2014, 20:51

It's up in the air.
User avatar
joedf
Posts: 5326
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada, Quebec
Contact:

Re: In and Contains plans...

01 Jul 2014, 21:02

Interesting idea...
toralf
Posts: 430
Joined: 27 Apr 2014, 21:08
Location: Germany

Re: In and Contains plans...

01 Jul 2014, 21:41

Is there actually any benefit over Regexmatch, instr() or ~=?
Besides that it is easier human readable?
ciao
toralf
Coco
Posts: 771
Joined: 29 Sep 2013, 20:37
GitHub: cocobelgica

Re: In and Contains plans...

02 Jul 2014, 01:55

@toralf InStr() operates on a single string while in/contains operates on a MatchList. As for RegExmatch or ~=, under v1.1, in/contains is way way way faster.
toralf
Posts: 430
Joined: 27 Apr 2014, 21:08
Location: Germany

Re: In and Contains plans...

02 Jul 2014, 02:29

IMHO instr() can be written to fulfill the same. Basically it is a haystack and needle. Thus, depending on if 'in' or 'contains' is required one or the other is the haystack. After looking up the command I'm sure For 'in'. For 'contain' I would have to test it.
Var and matchlist are 'single' strings as well in the if commands
ciao
toralf
Coco
Posts: 771
Joined: 29 Sep 2013, 20:37
GitHub: cocobelgica

Re: In and Contains plans...

02 Jul 2014, 03:30

Something like this which requires 3 function calls:

Code: [Select all] [Download] GeSHi © Codebox Plus

matchlist := "abc|def|ghi|"
needle := "def"
if (SubStr(matchlist, i:=InStr(matchlist, needle), InStr(matchlist, "|",, i-1)-1) == needle)
MsgBox Match found

toralf wrote:Var and matchlist are 'single' strings as well in the if commands

Yes, but AutoHotkey internally takes care of distinguishing the delimiter and members.
The current substitute I use for v2 is (also the fastest, based on some QPX() tests):

Code: [Select all] [Download] GeSHi © Codebox Plus

if {'abc':1, 'def':1, 'ghi':1}['def']
MsgBox Match found

Limitation, you can't do case-sensitive check(s).
toralf
Posts: 430
Joined: 27 Apr 2014, 21:08
Location: Germany

Re: In and Contains plans...

02 Jul 2014, 16:25

I was able to use InStr() for If Var in, but not for If Var contains. There I had to use RegExMatch() or ~=.
Your code didn't really duplicate If Var contains result either.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

ciao
toralf
Coco
Posts: 771
Joined: 29 Sep 2013, 20:37
GitHub: cocobelgica

Re: In and Contains plans...

03 Jul 2014, 03:53

toralf wrote:Your code didn't really duplicate If Var contains result either.

Yep, the code is for if var in only. Regardless, the built in if var in/contains still beats the workarounds both in performance and readability...
For if var in, using InStr("abc,def,ghi", "bc,d"), returns true, so this is not reliable... I'd rather go with if ("def" ~= "i)^(abc|def|ghi)$")

Return to “AutoHotkey v2 Development”

Who is online

Users browsing this forum: No registered users and 2 guests