Yep, I've struggled with single line loops myself, so I remembered that since AutoHotkey has first-class functions, it's possible to "forget" all control statements such as
return,
break and just invent your own using a formally untyped lambda calculus.
The following example contains a single line
Loop statement. Specifically, it runs
MsgBox("Hello world!") 3 times. See:
viewtopic.php?f=82&t=124744
Code: Select all
#Requires AutoHotkey v2.0
; Define a Z-combinator extended to accept an additional argument to evaluate.
Z := f => (x => f(v => w => x(x)(v)(w)))(x => f(v => w => x(x)(v)(w)))
; The user defined loop statement, which I've called "L" for Loop.
L := g => y => z => (y > 0 ? (z(), g(y - 1)(z)) : 0)
; The single line loop statement is defined as Z(L)( number of loops ) ( The function you'd like to execute)
Z(L)(3)( MsgBox.Bind("Hello world!") )
And the single line version would be: (ChatGPT Explains:
https://sl.bing.net/cd7z0YOhQlM)
Code: Select all
#Requires AutoHotkey v2.0
; Show Hello World 3 times!
(f=>(x=>f(v=>w=>x(x)(v)(w)))(x=>f(v=>w=>x(x)(v)(w))))(g=>y=>z=>(y>0?(z(),g(y-1)(z)):0))(3)( MsgBox.Bind("Hello world!") )
It's important to remember how to build things as dictated by the very structure of the world itself, with complete disregard for any appeals to tradition and authority, i.e. the "accepted" way of doing things.