an Array of "ClipboardAll" contents Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: an Array of "ClipboardAll" contents

14 Jan 2019, 08:21

teadrinker wrote:
14 Jan 2019, 08:10
The call of clipArr.Push(SaveClipboard()) doesn't put data into Clipboard, it only saves data which is currently present in Clipboard. You need to add
Ah...
Right...

I added that line.
Yes
Good
Works !!
Thanks !!!
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: an Array of "ClipboardAll" contents

14 Jan 2019, 08:59

Just use normal ifs. Using short circuit evaluation is considered unreadeable and bad practice.
If the goal is keeping the value below a specific value and then overflowing to the beginning again you could also consider using:

Code: Select all

k := mod(k, clipArr.MaxIndex()) + 1
Recommends AHK Studio
teadrinker
Posts: 4295
Joined: 29 Mar 2015, 09:41
Contact:

Re: an Array of "ClipboardAll" contents

14 Jan 2019, 09:33

nnnik wrote:
14 Jan 2019, 08:59
Using short circuit evaluation is considered unreadeable and bad practice.
Proof?
Short circuit evaluation, is it bad practice?
nnnik wrote:

Code: Select all

k := mod(k, clipArr.MaxIndex()) + 1
Do you really consider this as well readable? :)
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: an Array of "ClipboardAll" contents

14 Jan 2019, 10:29

All 4 should work in AHK v1 and v2.

Code: Select all

if (k > clipArr.MaxIndex())
	k := 1
    (k > clipArr.MaxIndex() && k := 1)
;    k > clipArr.MaxIndex() ? (k := 1) : "" ;doesn't work in AHK v2
    (k > clipArr.MaxIndex()) ? (k := 1) : ""
k := k > clipArr.MaxIndex() ? 1 : k
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: an Array of "ClipboardAll" contents

14 Jan 2019, 12:05

readable...
they are talking about...
not workable...

(I guess)
User avatar
gwarble
Posts: 524
Joined: 30 Sep 2013, 15:01

Re: an Array of "ClipboardAll" contents

14 Jan 2019, 14:23

teadrinker wrote:
06 Jan 2019, 06:23
Without using files:
Very nice, teadrinker!


Re: readability
Use whatever style you want, let the "reader" strive for readability by learning how if, ternary, short circuit, etc actually work when reading code!
Last edited by gwarble on 14 Jan 2019, 16:52, edited 1 time in total.
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: an Array of "ClipboardAll" contents

14 Jan 2019, 15:13

teadrinker wrote:
14 Jan 2019, 07:15

Code: Select all

clipArr := [1, 2, 3]
k := 2
(k > clipArr.MaxIndex() && k := 1)
MsgBox, % k

k := 2
k := k > clipArr.MaxIndex() ?  1 : ""
MsgBox, % k
i took (k > clipArr.MaxIndex() && k := 1) in isolation. if uve defined k elsewhere beforehand, then obviously ud put k in the else branch, instead of an empty str ""
teadrinker wrote:
14 Jan 2019, 07:15
As for this

Code: Select all

k > clipArr.MaxIndex() ?  k := 1
IMO this is semantically incorrect use of the ternary operator.
ok, granted
It is invalid, it currently yields silent failure in v1, in v2 you get a load time error :thumbup: .
how is it invalid? looks perfectly valid to me:

Code: Select all

; v1
k := 2

bool := false
bool ? k := 1
MsgBox % k ; k := 2

bool := true
bool ? k := 1
MsgBox % k ; k := 1
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: an Array of "ClipboardAll" contents

14 Jan 2019, 23:23

Where in the documentation do you find the binary operator op1 ? op2 (or the unary operator = op1 ;) )?

Cheers.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: an Array of "ClipboardAll" contents

15 Jan 2019, 00:17

i havent checked, but since ure asking, id assume "nowhere"?

which means the docs should probably be updated to include it, seeing how it appears to be perfectly valid
we can call it the single-line-ahk-binary-if-operator lol
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: an Array of "ClipboardAll" contents

15 Jan 2019, 01:26

- It would seem logical a ? b, for an if-statement with no else alternative.
- Has there ever been a language that allowed it?
- But since AHK v1 can't actually handle it, ideally it should raise an error before the script begins. (It already does in AHK v2.)
- It seems like the best thing to do would be to explicitly state in the help that *3* arguments must be specified. It's tripped up sufficiently many people.

Code: Select all

q:: ;incomplete ternary operator
MsgBox, % (1 = 1) ? "y" : "n" ;y
MsgBox, % (1 = 1) ? "y" ;(blank) ;silent error
return
[EDIT: @Helgef: Re. the post below.]
[EDIT: Yes a && b is available in AutoHotkey, but has any language ever allowed a ? b.]
[EDIT: A warning in the documentation would be useful: (a) for people using older versions of AHK v1, (b) if an error message is never added to AHK v1.]
Last edited by jeeswg on 15 Jan 2019, 11:40, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: an Array of "ClipboardAll" contents

15 Jan 2019, 02:10

It would seem logical a ? b, for an if-statement with no else alternative.
It's already available, a && b.
It seems like the best thing to do would be to explicitly state in the help that *3* arguments must be specified.
No, any invalid expression should yield a load time error.

Cheers.

Edit, sorry for off topic. :offtopic:
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: an Array of "ClipboardAll" contents

15 Jan 2019, 03:43

Code: Select all

MsgBox, % (1 = 1) ? "y"
damn lol, i guess this was the wrong hill to die on. helgef is correct

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: gongnl, Google [Bot], Shifted_Right and 206 guests