AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

v1.0.46 released: SubStr() and more expression operators
Goto page 1, 2, 3, 4, 5, 6, 7, 8  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Announcements
View previous topic :: View next topic  
Author Message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10450

PostPosted: Wed Nov 29, 2006 7:29 pm    Post subject: v1.0.46 released: SubStr() and more expression operators Reply with quote

NOTE: Although this release has been extensively tested and is not expected to break any existing scripts, several low-level enhancements were made. If you have any mission-critical scripts, it is recommended that you retest them and/or wait a few weeks for any bugs to get fixed.

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).
Back to top
View user's profile Send private message Send e-mail
Laszlo



Joined: 14 Feb 2005
Posts: 3877
Location: Pittsburgh

PostPosted: Wed Nov 29, 2006 8:17 pm    Post subject: Reply with quote

Wow! These changes should warrant a new subversion number. How about v1.1.0? Scripts will look drastically different with the new syntax enhancements...
Back to top
View user's profile Send private message Visit poster's website
toralf



Joined: 31 Jan 2005
Posts: 3842
Location: Bremen, Germany

PostPosted: Wed Nov 29, 2006 8:17 pm    Post subject: Reply with quote

Hi Chris,
Thanks for the new features. I will use several of them for sure.
_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
ahklerner



Joined: 26 Jun 2006
Posts: 1004
Location: USA

PostPosted: Wed Nov 29, 2006 8:27 pm    Post subject: Reply with quote

Chris.....You are making this better all of the time.....
Back to top
View user's profile Send private message
foom



Joined: 19 Apr 2006
Posts: 386

PostPosted: Wed Nov 29, 2006 9:07 pm    Post subject: Reply with quote

Wow after seeing a new version is released and reading that expression way of concatenating is as fast as the deref way i had to do a little benchmarking.
Code:
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"Laughing

Thank Chris. Keep up the hard work. Smile
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 5298

PostPosted: Wed Nov 29, 2006 9:41 pm    Post subject: Reply with quote



I never expected so much! Many thanks .. Very Happy

Special thanks for the SubStr(). I was craving for it for a long time!

Chris wrote:
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, Smile
_________________
SKAN - Suresh Kumar A N
Back to top
View user's profile Send private message
PhiLho



Joined: 27 Dec 2005
Posts: 6702
Location: France (near Paris)

PostPosted: Thu Nov 30, 2006 9:53 am    Post subject: Reply with quote

Laszlo wrote:
Wow! These changes should warrant a new subversion number. How about v1.1.0? Scripts will look drastically different with the new syntax enhancements...
That's funny, while reading this long list of features, I was thinking exactly the same thing... Smile
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()...
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Last edited by PhiLho on Thu Nov 30, 2006 11:37 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
Thalon



Joined: 12 Jul 2005
Posts: 640

PostPosted: Thu Nov 30, 2006 10:49 am    Post subject: Reply with quote

I can just say: wow!
_________________
AHK-Icon-Changer
AHK-IRC
deutsches Forum
SacredVault
Back to top
View user's profile Send private message
corrupt



Joined: 29 Dec 2004
Posts: 2328

PostPosted: Fri Dec 01, 2006 2:05 am    Post subject: Re: v1.0.46 released: SubStr() and more expression operators Reply with quote

I'm glad I waited a bit longer before updating a few existing scripts. Thanks for the improvements Smile .

Chris wrote:
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.
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 do Wink .
Back to top
View user's profile Send private message Visit poster's website
JSLover



Joined: 20 Dec 2004
Posts: 542
Location: LooseChange911.com... the WTC attacks were done by the US Gov't... the official story is a lie...

PostPosted: Fri Dec 01, 2006 9:19 am    Post subject: Re: v1.0.46 released: SubStr() and more expression operators Reply with quote

corrupt wrote:
The only drawback for me is that I frequently use the index in a help file as a quick reference.

...I say name stuff the way that sounds best...like SubStr (substring) vs StrSub (string sub??? tract? stitute?)...but then add index entries like...
    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...
_________________

LooseChange911.com • See Loose Change (click image!) • LC Blog
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10450

PostPosted: Fri Dec 01, 2006 1:42 pm    Post subject: Re: v1.0.46 released: SubStr() and more expression operators Reply with quote

PhiLho wrote:
Laszlo wrote:
Wow! These changes should warrant a new subversion number. How about v1.1.0? Scripts will look drastically different with the new syntax enhancements...
That's funny, while reading this long list of features, I was thinking exactly the same thing... Smile
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.

JSLover wrote:
so name for best-looking/sounding, but patch it up in the index
Thanks for the idea. I've added index entries called "string: InStr()" and "string: SubStr()".
Back to top
View user's profile Send private message Send e-mail
Tuncay



Joined: 07 Nov 2006
Posts: 379
Location: Berlin

PostPosted: Sun Dec 03, 2006 9:02 pm    Post subject: Reply with quote

Chris, thx for the changes you made in this version. I like this update, 'cauze SubStr() and some operators, especially .=.
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.
Back to top
View user's profile Send private message Send e-mail
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10450

PostPosted: Mon Dec 04, 2006 12:43 am    Post subject: Reply with quote

Tuncay wrote:
I do not understand why you have introduced the ternary operator ?: and command separated expressions? They lead to badly readable scripts.
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.
Back to top
View user's profile Send private message Send e-mail
hs2



Joined: 25 Feb 2005
Posts: 11
Location: Germany

PostPosted: Mon Dec 04, 2006 1:04 am    Post subject: Reply with quote

@Chris: You are my number one hero !

@Tuncay: If you don't like it - don't use it Wink

HS2
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 5298

PostPosted: Mon Dec 04, 2006 10:37 am    Post subject: Reply with quote

Tuncay wrote:
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:

Code:
2GuiClose:
 Gui, 2:Destroy
 Var1=
 Var2=
 Var3=
 Var4=
 Var5=
 Var6=
Return


Instead of:

Code:
2GuiClose:
 Gui, 2:Destroy
 Var1:="" , Var2:="" , Var3:="" , Var4:="" , Var5:="" , Var6:="" ; Resetting Vars
Return


JMHO .. Regards, Smile

Edit:ListView is an another situation where I find it very useful:

Code:
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")

_________________
SKAN - Suresh Kumar A N


Last edited by SKAN on Mon Dec 04, 2006 11:08 am; edited 1 time in total
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Announcements All times are GMT
Goto page 1, 2, 3, 4, 5, 6, 7, 8  Next
Page 1 of 8

 
Jump to:  
You cannot post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group