AutoHotkey Community

It is currently May 27th, 2012, 3:39 am

All times are UTC [ DST ]




Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 1036 posts ]  Go to page Previous  1 ... 42, 43, 44, 45, 46, 47, 48 ... 70  Next
Author Message
 Post subject:
PostPosted: July 16th, 2010, 3:10 pm 
Lexikos wrote:
or allowing either syntax to be used are possibilities

I support this idea completely.

About expression efficiency, I think that is not that important. AHK is fast enough now for 99.9% possible usses and rapid development is more important for general purpose script language. In that manner, new syntax possibilities (syntax sugars etc) and features should be more important.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 19th, 2010, 9:21 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
Hi Lexikos,

can you have a look at this, looks like numbers are not handled properly?
Code:
0:=Object(),o:=Object()
0.a:=1,o.a:=1
MsgBox % o.a ;works as expected
MsgBox % 0.a ;does not work but will work if 0:=Object() is in a separate line
MsgBox % o["a"] ;works as expected
MsgBox % 0["a"] ;does not work
MsgBox % o.("a") ;returns empty string (as expected)
MsgBox % 0.("a") ;returns 0.(a)

Also this displays 1.1
Code:
1:=Object()
1.1:=1
MsgBox % 1.1

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 19th, 2010, 10:46 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
Numbers are handled just fine, but numbers aren't variables. :roll:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 19th, 2010, 11:16 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
Lexikos wrote:
Numbers are handled just fine, but numbers aren't variables. :roll:

What do you mean :?:
Code:
0:="test",123:="another one"
MsgBox %0%          ;0 as variable
MsgBox %123%          ;123 as variable

Okay I agree for 1.1 since this is actually a number, but what about this, especially since 0.a works :?
Code:
0:=Object()         ;0 as object
0.a:="test"
MsgBox % 0.a       ;works if 0:=Object() is in a separate line and not part of expression
MsgBox % 0["a"]    ;does not work
MsgBox % 0.("a")    ;returns 0.(a)

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 19th, 2010, 11:42 pm 
Offline

Joined: March 27th, 2008, 2:14 pm
Posts: 700
The VarSetCapacity character fill trick doesn't work anymore:

Code:
FillChar(char=" ", cnt=100) {
   return x, VarSetCapacity(x,64), VarSetCapacity(x,0), VarSetCapacity(x, cnt, Asc(char))
}

_________________
Scripts - License


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 20th, 2010, 12:09 am 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
infogulch wrote:
The VarSetCapacity character fill trick doesn't work anymore:

Code:
FillChar(char=" ", cnt=100) {
   return x, VarSetCapacity(x,64), VarSetCapacity(x,0), VarSetCapacity(x, cnt, Asc(char))
}

It does but not for Unicode version :)
Code:
BYTE fill_byte = (BYTE)TokenToInt64(*aParam[2]);
// I assume for Unicode it should be
TBYTE fill_byte = (TBYTE)TokenToInt64(*aParam[2]);

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 20th, 2010, 2:19 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
HotKeyIt wrote:
What do you mean :?:
Quote:
Such numeric names cannot be used in expressions because they would be seen as numbers rather than variables.
Source: Variables and Expressions

Quote:
but will work if 0:=Object() is in a separate line
I had overlooked this comment. This works only because the var:= part of a standalone assignment is handled separately from the expression part, for performance reasons. It is processed the same way as the variable in 0=a.
Quote:
0.a works :?
This is a bug. 0 should be interpreted as a numeric literal for use with the default base mechanism, like "".a. Even if it works, it is extremely bad style.
infogulch wrote:
The VarSetCapacity character fill trick doesn't work anymore:
VarSetCapacity is designed to fill bytes, not characters, as the RequestedCapacity parameter is in bytes, not characters.
Quote:
VarSetCapacity(x,64), VarSetCapacity(x,0)
This trick also won't work as intended in Unicode builds, as the maximum "persistent" allocation is 64 characters (128 bytes), including the null terminator (VarSetCapacity excludes it).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 20th, 2010, 3:38 pm 
Offline

Joined: March 27th, 2008, 2:14 pm
Posts: 700
Quote:
Code:
VarSetCapacity(x,64), VarSetCapacity(x,0)
This trick also won't work as intended in Unicode builds, as the maximum "persistent" allocation is 64 characters (128 bytes), including the null terminator (VarSetCapacity excludes it).

Ah I see. Would this be consistent across builds instead? VarSetCapacity(x,64*(A_IsUnicode ? 2 : 1))

Quote:
VarSetCapacity is designed to fill bytes, not characters, as the RequestedCapacity parameter is in bytes, not characters.

Aw damn that's right. Can you think of another method? (well, one that doesn't involve loops :P )

_________________
Scripts - License


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 20th, 2010, 11:22 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
infogulch wrote:
Would this be consistent across builds instead? VarSetCapacity(x,64*(A_IsUnicode ? 2 : 1))
Yes. You could also just use 128, which would probably be faster as the expression is simpler and the size of allocation makes very little difference.
Quote:
Can you think of another method?
Code:
FillChar(char=" ", cnt=100) {
    if A_IsUnicode
        VarSetCapacity(buf, cnt*2, 1)
        , DllCall("msvcrt\_wcsset", "str", buf, "int", Asc(char), "Cdecl")
    else
        VarSetCapacity(buf, cnt, 1)
        , DllCall("msvcrt\_strset", "str", buf, "int", Asc(char), "Cdecl")
    return buf
}
It can also be condensed...
Code:
FillChar(char=" ", cnt=100) {
    VarSetCapacity(buf, cnt*(A_IsUnicode ? 2:1), 1)
    , DllCall("msvcrt\_" (A_IsUnicode ? "wcsset":"strset"), "str", buf, "int", Asc(char), "Cdecl")
    return buf
}
...but in that case the function name can't be resolved at load-time, so the call takes twice as long.

There are also _wcsnset and _strnset which accept a maximum count, but they still stop at the first null character (the null-terminator) so these are easier and faster.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 21st, 2010, 12:49 am 
Offline

Joined: March 27th, 2008, 2:14 pm
Posts: 700
Awesome thanks!

I think you forgot the first part btw:
Code:
FillChar(char=" ", cnt=100) {
    varsetcapacity(buf, 128), varsetcapacity(buf, 0)
    if A_IsUnicode
        VarSetCapacity(buf, cnt*2, 1)
        , DllCall("msvcrt\_wcsset", "str", buf, "int", Asc(char), "Cdecl")
    else
        VarSetCapacity(buf, cnt, 1)
        , DllCall("msvcrt\_strset", "str", buf, "int", Asc(char), "Cdecl")
    return buf
}

FillChar(char=" ", cnt=100) {
    varsetcapacity(buf, 128), varsetcapacity(buf, 0), VarSetCapacity(buf, cnt*(A_IsUnicode ? 2:1), 1)
    , DllCall("msvcrt\_" (A_IsUnicode ? "wcsset":"strset"), "str", buf, "int", Asc(char), "Cdecl")
    return buf
}

_________________
Scripts - License


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 21st, 2010, 9:21 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
infogulch wrote:
I think you forgot the first part btw:
I had forgotten VarSetCapacity ignores RequestedCapacity when filling the variable. VarSetCapacity(buf, 128), VarSetCapacity(buf, 0) helps because it prevents buf from being allocated persistent memory, instead forcing the allocations to be the requested size. However, it only has an effect on the first call, then it becomes unnecessary overhead. (Edit: It should also be noted that this is undocumented behaviour and as such should not be relied upon.) Here is an alternative approach:
Code:
FillChar(char=" ", cnt=100) {
    if A_IsUnicode
        VarSetCapacity(buf, cnt*2, 1), NumPut(0, buf, cnt*2, "short")
        , DllCall("msvcrt\_wcsset", "str", buf, "int", Asc(char), "Cdecl")
    else
        VarSetCapacity(buf, cnt, 1), NumPut(0, buf, cnt, "char")
        , DllCall("msvcrt\_strset", "str", buf, "int", Asc(char), "Cdecl")
    return buf
}
This explicitly null-terminates the variable at the correct position. It appears to add about 9% to the benchmark time (with default parameters), whereas the redundant VarSetCapacity method adds about 60%.

I also tried a variant using:
Code:
VarSetCapacity(buf, cnt*2, 1) != cnt*2 ? NumPut(0, buf, cnt*2, "short") : 0
...but it turns out that the code to avoid the unnecessary NumPut takes about as long as the NumPut itself. :lol:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 21st, 2010, 11:45 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
Is this a bug :?:
Code:
obj1:=Object()
obj2:=Object()
obj1.object:=obj2
obj1.base:=Object("__GET","TEST")
obj2.base:=Object("__GET","TEST")
MsgBox % obj1[]          ;works
MsgBox % obj2[]          ;works
MsgBox % obj1.object[]   ;does not work

TEST(o,k=""){
   MsgBox % "k = " k
}

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 22nd, 2010, 3:03 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
You may consider it a bug/limitation. It is related to the following:
Quote:
Although only a single literal parameter can be specified this way, any number of additional parameters can be specified:
Code:
Value  := Object.Param1[ Param2, Param3, ... ]            ; GET
Result := Object.Param1[ Param2, Param3, ... ] := Value   ; SET
Result := Object.Param1( Param2, Param3, ... )            ; CALL
Source: Objects - Syntax - Invoking an Object
Specifically, as obj1.object[x] would be equivalent to obj1["object",x], obj1.object[] is equivalent to obj1["object"].

For now, `(obj1.object)[] can be used to force obj1.object to be evaluated separately. (The escape character is only necessary if it is at the start of a line.)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 22nd, 2010, 11:34 am 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
I see, many thanks for clarification.

So actually, obj1.object[] is equivalent to obj1["object"] and equivalent to obj1.object.

So if I got you right this will not change?

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 22nd, 2010, 12:56 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
I am considering changing it. It seems pointless to write x.y[] when it is equivalent to x.y, but I'm not sure which behaviour is more intuitive. Obviously it is more useful for [] to actually do something in that context. Another workaround: obj1["object"][] is probably cleaner than the `() method.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 1036 posts ]  Go to page Previous  1 ... 42, 43, 44, 45, 46, 47, 48 ... 70  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 6 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group