v1.0.46 released: SubStr() and more expression operators
#1
Posted 29 November 2006 - 06:29 PM
Here are the changes for v1.0.46:
Added function SubStr(), which retrieves the specified number of characters at the specified position in a string.
Added assignment operators //=, .=, |=, &=, ^=, >>=, and <<=, which can be used anywhere in expressions. For example, Var .= "abc" appends the string "abc" to the end of Var's current contents.
Added full support in expressions for the operators ++, --, +=, -=, *=, and /= (formerly, they could be used only as the leftmost operator on a line). All assignment operators (especially ++ and --) behave in a C-like way when their result is used by some other operator.
Added the ternary operator (?:), which is a shorthand replacement for the if-else statement. For example, var := x>y ? 2 : 3 assigns the value 2 if x is greater than y; otherwise it assigns 3.
Added support for comma-separated expressions, which allow a single line to contain multiple assignments, function calls, and other expressions. [thanks PhiLho & Titan]
Improved variable declarations to support initialization on the same line. Note: A static variable's initialization occurs only once, before the script begins executing.
Improved line continuation to support all expression operators. For example, a line that starts with "?" or "+" is automatically merged with the line above it.
Improved performance of operators "." and ".=" to be as fast as the percent-sign method of appending a string.
Improved expressions to allow more types of consecutive unary operators such as !!Var. [thanks Laszlo]
Changed Critical to check messages less often (20 vs. 10ms), which improves the reliability of frequently-called OnMessage functions. [thanks Majkinetor]
Changed: A variable named simply "?" is no longer valid in expressions due to the new ternary operator.
Fixed hotkeys to support ":::" (colon as a hotkey) and ": & x" (colon as a hotkey prefix).
Fixed the installer to remove psapi.dll from the AutoHotkey folder (except on Windows NT4). This avoids a conflict with Internet Explorer 7. [thanks to all those who reported it]
-----
In case anyone is wondering, I chose SubStr() as the name rather than StrSub() or StrMid() because naming functions consistently doesn't seem as valuable as good readability and conciseness. Furthermore, many other languages have a SubStr() function that behaves the same way, which reduces the learning curve for people coming from some other language to AutoHotkey (or vice versa).
#2
Posted 29 November 2006 - 07:17 PM
#3
Posted 29 November 2006 - 07:17 PM
Thanks for the new features. I will use several of them for sure.
#4
Posted 29 November 2006 - 07:27 PM
#5
Posted 29 November 2006 - 08:07 PM
setbatchlines -1
#noenv
DllCall("QueryPerformanceCounter", "Int64 *", CounterBefore)
loop, 1000
{
x .="xxxxxxxxxxxxxxxxxxxxxxxxxxx"
;x=%x%xxxxxxxxxxxxxxxxxxxxxxxxxxx
}
DllCall("QueryPerformanceCounter", "Int64 *", CounterAfter)
MsgBox % "Elapsed QPC time // 1000 is " . (CounterAfter - CounterBefore)//1000; deref method ~ 6000; old expression method ~ 90000 .~ 12 times slower
; new expression method ~ 7000 .Not exactly like deref. But still wow:"Warp Speed Twelve, Mr. La Forge":lol:
Thank Chris. Keep up the hard work.
#6
Posted 29 November 2006 - 08:41 PM

I never expected so much! Many thanks ..
Special thanks for the SubStr(). I was craving for it for a long time!
In case anyone is wondering, I chose SubStr() as the name rather than StrSub() or StrMid() because naming functions consistently doesn't seem as valuable as good readability and conciseness.
IMHO, SubStr() is very much consistent with InStr(), and I can forsee the usage of InStr() as a SubStr() parameter.
Regards,
#7
Posted 30 November 2006 - 08:53 AM
That's funny, while reading this long list of features, I was thinking exactly the same thing... :-)Wow! These changes should warrant a new subversion number. How about v1.1.0? Scripts will look drastically different with the new syntax enhancements...
I will have to update my lexer for Scintilla...
Lot of hard work here, I download it immediately to test it!
And as Goyyah pointed out, the new function is at least consistent with its brother, InStr()...
#8
Posted 30 November 2006 - 09:49 AM
#9
Posted 01 December 2006 - 01:05 AM
The only drawback for me is that I frequently use the index in a help file as a quick reference. I could always use the Contents tab I guess... but I never doIn case anyone is wondering, I chose SubStr() as the name rather than StrSub() or StrMid() because naming functions consistently doesn't seem as valuable as good readability and conciseness.
#10
Posted 01 December 2006 - 08:19 AM
...I say name stuff the way that sounds best...like SubStr (substring) vs StrSub (string sub??? tract? stitute?)...but then add index entries like...The only drawback for me is that I frequently use the index in a help file as a quick reference.
StrSub (see SubStr)...clicking on the entry would take you to the help page with the correct name...so name for best-looking/sounding, but patch it up in the index...I too only use the index for help...
#11
Posted 01 December 2006 - 12:42 PM
I was thinking the opposite because I thought not many people would care about C-like operators. I even delayed this release to add SubStr() to help justify making it a major vs. minor version number.That's funny, while reading this long list of features, I was thinking exactly the same thing... :-)Wow! These changes should warrant a new subversion number. How about v1.1.0? Scripts will look drastically different with the new syntax enhancements...
Thanks for the idea. I've added index entries called "string: InStr()" and "string: SubStr()".so name for best-looking/sounding, but patch it up in the index
#12
Posted 03 December 2006 - 08:02 PM
But on the other hand, adding some of the operators is a bad idea. I do not understand why you have introduced the ternary operator ?: and command separated expressions? They lead to badly readable scripts. Ok, its a lot fewer to write, but I don't like that.
#13
Posted 03 December 2006 - 11:43 PM
It's a matter of personal scripting style. Some people crave the ability to write related expressions all on one line. In addition, the ternary operator can simplify some kinds of expressions, and in some cases gives better performance.I do not understand why you have introduced the ternary operator ?: and command separated expressions? They lead to badly readable scripts.
#14
Posted 04 December 2006 - 12:04 AM
@Tuncay: If you don't like it - don't use it
HS2
#15
Posted 04 December 2006 - 09:37 AM
adding some of the operators is a bad idea. I do not understand why you have introduced the ternary operator ?: and command separated expressions? They lead to badly readable scripts.
I had faced instances where my script had a specific need to nullify the variable contents.
Maybe initialising variables one-a-line might be readable for others. But nullifying existing variables the same way looks ugly and will make the code unneccessarily long. Like:
2GuiClose: Gui, 2:Destroy Var1= Var2= Var3= Var4= Var5= Var6= Return
Instead of:
2GuiClose: Gui, 2:Destroy Var1:="" , Var2:="" , Var3:="" , Var4:="" , Var5:="" , Var6:="" ; Resetting Vars Return
JMHO .. Regards,
Edit:ListView is an another situation where I find it very useful:
LV_ModifyCol(1,"60 Integer"), LV_ModifyCol(2,"60 Integer"), LV_ModifyCol(3,"36 Center") LV_ModifyCol(4,"36 Integer"), LV_ModifyCol(5,"36 Center"), LV_ModifyCol(6,"100")




