Don't know if this is allowed, but it certainly doesn't break given rules and yields desired result!
Code: Select all
for , l in List
x:="abcd " l
Code: Select all
for k in List
x:="abcd " k
Code: Select all
for , l in List
x:="abcd " l
Code: Select all
for k in List
x:="abcd " k
Code: Select all
for k in List
!x ? x:="abcd " A_Index-99 : ""
Code: Select all
for , l in list
Code: Select all
for k, l in List
x:=l
Code: Select all
for k, x in List
continue
Code: Select all
Min(List*)
{ ; https://autohotkey.com/boards/viewtopic.php?f=6&t=40898 by FanaticGuru
!(X := List[List.MaxIndex()]) ? List._NewEnum().Next( , X) : ""
Code: Select all
Min(List*)
{ ; https://autohotkey.com/boards/viewtopic.php?f=6&t=40898 by FanaticGuru
Enum := List._NewEnum(), Enum.Next(Y), Enum.Next(,X)
for key, element in List ; This line is not allowed to be modified.
if (element < X) ; This line is not allowed to be modified.
X := element ; This line is not allowed to be modified.
return X
}
Code: Select all
Min(X:="�", List*) ; X := chr(0xffff)
{ ; https://autohotkey.com/boards/viewtopic.php?f=6&t=40898 by FanaticGuru
for key, element in List ; This line is not allowed to be modified.
if (element < X) ; This line is not allowed to be modified.
X := element ; This line is not allowed to be modified.
return X
}
Code: Select all
Min(List) ; Removed *
{ ; https://autohotkey.com/boards/viewtopic.php?f=6&t=40898 by FanaticGuru
!(X := List[List.MaxIndex()]) ? List._NewEnum().Next( , X) : ""
for key, element in List ; This line is not allowed to be modified.
if (element < X) ; This line is not allowed to be modified.
X := element ; This line is not allowed to be modified.
return X
}
Min(p) ; Removed *
Code: Select all
for k, x in List
continue
Code: Select all
for k in List
if (A_Index == 2)
break
X := List[k]
The function must work for any input the original does, eg, Min(1) will return blank if you do that. If you do X:="abcd 1" and call the function like this, Min("x","y") you will get back "abcd 1" instead of x.Why not just simply use X:=List[2] instead?
The default value is not used when X is assigned a value from the call, hence in those cases, it can be anything. When you call the function like Min(AssociativeArray*) , and AssociativeArray doesn't only have numeric keys like 1,2,... and lacks a key named X, the X parameter's default value is used, example, Min({a:1,b:2}*) and Min({a:1, x:0}*).works if I assign anything to X even X:=""?
As Helgef touched on the tricky part is associative arrays.rommmcek wrote:Awesome tractates!
One think I still don't understand. Why count to two? Why not just simply use X:=List[2] instead?, knowing what is at the second place. And then why would X:="abcd 1" break the function? Any way I do understand this things a bit better now.
Bye!
P.s.: In FG's superior solution Min(X:="�", List*) for me works if I assign anything to X even X:=""?
Code: Select all
List := {one:1, two:2}
MsgBox % List[2] ; this does not work as there is no key equal to "2", the only keys are "one" and "two"
Code: Select all
Func1(1,2)
Func1(X:="�", List*)
{
MsgBox % X "`n" List[1]
}
Data := {one:1}
Func2(Data*)
Func2(X:="�", List*)
{
MsgBox % X "`n" List["one"]
}
Code: Select all
; https://autohotkey.com/boards/viewtopic.php?f=37&t=42328
; [BUG]Associative Arrays
setbatchlines,-1
#noenv
class Task {
static time:= 0
static tick:= 0
static List:= []
__new(name, mode:= 0x13) {
this.mode:= mode
this.name:= name
Task.List[this]:= "" ;no value for key
}
end() { ;initate destruct
if !Task.time
Task.time:= A_TickCount
Task.List.Delete(this) ;self kill
}
;Task.List.Delete(this)
;Task.List:= ""
__delete() { ;destruct idea by Helgef
if !Task.time
Task.time:= A_TickCount
this.name:= ""
Task.tick:= A_TickCount - Task.time
}
}
result:= ""
count:= 50000
; SLOW -----------------------------------------------
loop % count
new Task("name" A_Index)
Task.time:= ""
SLOW:
for key in Task.List {
key.end()
goto SLOW
}
key:=""
msgBOX(result.= "SLOW`t:= " Task.tick "`n")
; FAST -----------------------------------------------
array:= []
loop % count
new Task("name" A_Index)
Task.time:= ""
for key in Task.List
array[A_Index]:= key
loop % array.length()
array[A_Index].end()
array:= ""
key:=""
msgBOX(result.= "FAST`t:= " Task.tick "`n")
; ENUM -----------------------------------------------
loop % count
new Task("name" A_Index)
Task.time:= ""
while (_enum:= Task.List._newEnum()).Next(key, val) {
loop {
key.end()
} until !_enum.Next(key, val)
}
key:=""
msgBOX(result.= "ENUM`t:= " Task.tick "`n")
; LOOP -----------------------------------------------
loop % count
new Task("name" A_Index)
Task.time:= ""
loop {
isEmpty:= 1
for key in Task.List {
key.end()
isEmpty:= 0
}
} until isEmpty
key:="" ; <-- edit: conversion mistake fixed
msgBOX(result.= "LOOP`t:= " Task.tick "`n")
; Helgef ---------------------------------------------
loop % count
new Task("name" A_Index)
Task.time:= ""
Task.List:= [] ;Task.List:= "" change type from Array to string if further use
msgBOX("Wait for Helgef",, "2") ;this 2 seconds is out of tick (destruction in background)
msgBOX(result.= "HELL`t:= " Task.tick "`n")
msgBOX(a,b:="",c:=""){
msgbox,,,% a, % c
}
Puzzle hint: When you correct the mistake, you can expect the last test to work as intended.
Return to “General Discussion”
Users browsing this forum: No registered users and 15 guests