AutoHotkey Community

It is currently May 27th, 2012, 12:55 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: September 6th, 2011, 5:35 pm 
Offline
User avatar

Joined: May 10th, 2007, 10:54 am
Posts: 649
Location: .switzerland
It's questionable whenever this is a bug or a feature request, but as all Languages I know naturally handle this, I decided to go for the bug. :)

Code:
arr := []
Test(arr[1])
MsgBox % arr[1] ; empty
Exitapp

Test(byref test){
   test := "value"
}

For consistency byref on an Array-Indexer (as well as on a Object Property) should behave as a reference operation, thus the callers variable should be changed.

_________________
http://securityvision.ch
AHK 2D GAME ENGINE


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 6th, 2011, 7:04 pm 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
This would be a feature request - for which I would say +1, but Lexikos said it's low priority (concerning byref variadic params anyways).

_________________
Image
Recommended: AutoHotkey_L
Basic Webpage Controls


Report this post
Top
 Profile  
Reply with quote  
PostPosted: September 6th, 2011, 7:34 pm 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
IsNull wrote:
It's questionable whenever this is a bug or a feature request,

The Bug Reports subheading attempts to clarify such questions.
Quote:
Report problems with documented functionality.
The implication is that bug reports should generally be of a format saying, "The documentation states X (quote here). The implemented behavior is Y (code here). This is an apparent contradiction because... (your reasoning here)." Tying code back to the AHK documentation is the key that usually separates bugs from wishes.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 6th, 2011, 8:52 pm 
Offline
User avatar

Joined: May 28th, 2011, 9:03 am
Posts: 466
Location: Germany
Just to clarify the reason -> de.autohotkey.com

IsNull wrote:
IMHO sollte auch bei einer byref Parameterübergabe eine Referenz auf ein Array-Element übergeben werden. Man kann das auch mit einer UDF nachstellen - da funktioniert es auch nicht:
Code:
var := ""
Test(var) ; übergibt variablen-referenz
MsgBox % var
arr := []
Test(arr[1]) ; übergibt keine Variablen-Referenz
MsgBox % arr[1] ; daher leer

Exitapp

Test(byref test){
   test := "value"
}

Das könnte man Mr L mal mitteilen, denn das ist eine allgemeines Array<-->byref Problem :)

Edit: Gerade in C# nachgestellt, da geht das natürlich auch:
Code:
        static void Main(string[] args) {
            string vars = "";
            Test(ref vars);
            Console.WriteLine(vars);

            string[] arr = { };
            Test(ref arr[0]);
            Console.WriteLine(arr[0]);

            Console.ReadKey();
        }


        static void Test(ref string test){
            test = "value";
        }

@Isnull: Would it work in IronAHK or IsNullAHK?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 7th, 2011, 12:44 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
Arr[1] is equivalent to (pseudo-code*) ObjGet(Arr, 1) while Arr[1] := Val is equivalent to ObjSet(Arr, 1, Val). Both return a plain value, not a reference to an item or variable. The value doesn't even need to be stored anywhere; it could be dynamically calculated. It may be worth noting that C# similarly does not support passing properties, indexers or dynamic members as ref or out parameters. I know some other languages transparently create a temporary variable and pass that instead.

*Originally, ObjGet and ObjSet could be called directly by the script.

I tentatively plan to add support for it, but realistically, it may never happen.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 7th, 2011, 10:47 am 
Offline
User avatar

Joined: May 10th, 2007, 10:54 am
Posts: 649
Location: .switzerland
@jaco0646:
Documented behaviour is nothing which one-to-one must apply; A Programming-Language is a set of syntax roules and in the case of byref it states: "Parameters are passed as a Reference".

As an "Expression" is a defined subset of rules I decided for the bug report, as the reference behavoir for any method parameter can be expected when the byref keyword is used.


@Lexikos:
The implementation of AHK is the other (real) thing, and I can see the difficulty in it. Also, I think this is a low priority issue as it won't be used often. However, I would then add an note to the byref doc and state that this won't work with Object Properties/Indexers. So this issue becomes a clear wish :)

Quote:
It may be worth noting that C# similarly does not support passing properties, indexers or dynamic members as ref or out parameters.

Huh? C# does support it. Give it a try:
Code:
  static void Main(string[] args) {
            string[] arr = { };
            Test(ref arr[0]);
            Console.WriteLine(arr[0]);

            Console.ReadKey();
        }

        static void Test(ref string test){
            test = "value";
        }

_________________
http://securityvision.ch
AHK 2D GAME ENGINE


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 8th, 2011, 1:46 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
IsNull wrote:
However, I would then add an note to the byref doc and state that this won't work with Object Properties/Indexers. So this issue becomes a clear wish :)
Okay. OTOH,
Quote:
Variable names may be up to 253 characters long and may consist of letters, numbers and the following punctuation: # _ @ $
Quote:
... the use of ByRef causes each parameter to become an alias for the variable passed in from the caller.
...so clearly arr[1] is not a variable and therefore cannot be passed ByRef.

Quote:
Quote:
It may be worth noting that C# similarly does not support passing properties, indexers or dynamic members as ref or out parameters.

Huh? C# does support it. Give it a try:
Please pay attention.
Code:
static void Main(string[] args) {
    C c = new C();
    Test(ref c[0]);
    // Above line gives a compiler/intellisense error:
    // "A
property, indexer or dynamic member access may not be passed as an out or ref parameter."
}
static void Test(ref string test) {
    test = "value";
}
class C {
    public string this[int i] { get; set; }
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 8th, 2011, 9:22 am 
Offline
User avatar

Joined: May 10th, 2007, 10:54 am
Posts: 649
Location: .switzerland
I'm talking about Arrays not Objects (in C# as in AHK), no matter that your implementation (currently) doesn't distinguish between them. (Which is just fine, and suitable for a non typed language)

Thinking about it, I come to the point that we all should stay away using the word "Array" in therms of AHKs Objects. It would be clearer to talk about "List" or "Collection" or "Hash Table/Associative Array" to describe the behavior of it, including the auto expanding feature. But this is just a detail which becomes important in discussions like that.

I think we are on the same line now, and I just like to have some facts pointed out better in the documentation.

ot/

Quote:
// "A property, indexer or dynamic member access may not be passed as an out or ref parameter."

IMHO this message is not really correct, accessing an Array by index is nothing other than an indexed property (in scope of C#), and it works on arrays in a ref/out context.
The point that in C# even arrays or any other primitive type are objects is another topic. :lol:

_________________
http://securityvision.ch
AHK 2D GAME ENGINE


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 8th, 2011, 3:53 pm 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
IsNull wrote:
It would be clearer to talk about "List" or "Collection" or "Hash Table/Associative Array" to describe the behavior of it,

AutoHotkey_L beta with JSON support
jaco0646 wrote:
can we pick another name?
Lexikos and I talked it to an impasse, but maybe you have a new perspective to add.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 9th, 2011, 5:56 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
IsNull wrote:
Thinking about it, I come to the point that we all should stay away using the word "Array" ...
I disagree. In the contexts of AutoHotkey, scripting, and the English language, "array" does not have the specific meaning you seem to think it does. (Or maybe you meant for this discussion specifically, in which case, never mind.)
Quote:
IMHO this message is not really correct, accessing an Array by index is nothing other than an indexed property (in scope of C#),
I think that reinforces my point. C# doesn't support it when the underlying implementation makes it infeasible, and neither does AutoHotkey.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google Feedfetcher and 3 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