ThisVare <assignment> Var1 ; Now both variables point to same content.

Discuss the future of the AutoHotkey language
RFM
Posts: 28
Joined: 21 May 2016, 12:50

ThisVare <assignment> Var1 ; Now both variables point to same content.

18 Feb 2017, 15:27

I didn't find a "Wish List" for V2 so putting it here. The comments in the code explain the capability I'd like to see implemented.
Let me know if I should post such things elsewhere.

Code: Select all

; This program does not run, it is an example of a capability I'd like to see implemented.
global Var1 := "Here is a super global string."

Var4 := "Here is a global string."
MyClass.MyMethod(<#>, ByRef Var4)

class MyClass
{
	static Var2 := "Here is a class static string."
	
	MyMethod(WhichOne := 1, ByRef MyVar)
	{
		static Var3 := "Here is a method string."
		
		ThisVar #= WhichOne = 1 ? Var1 : WhichOne = 2 ? This.Var2 : WhichOne = 3 ? Var3 : MyVar
		; where #= causes ThisVar to be whichever var# is assigned to it.
		ThisVar := "This" . SubStr(ThisVar, 10, StrLen(ThisVar) - 10) . " is in Var" . WhichOne
		; if WhichOne = 1, Var1 will now be "This super global string is in Var1"
		; if WhichOne = 2, Var2 will now be "This class static string is in Var2"
		; if WhichOne = 3, Var3 will now be "This method string is in Var3"
		; if WhichOne = 4, Var4 will now be "This global string is in Var4"
		
		; One of my favorite languages was capable of this and it was quite handy.
		; Of course the way it stored its variables made it easy:
		; Var# pointed to a permanent location for that variable's descriptor.
		; A descriptor contained, among other things, the address of the actual variable's
		; contents and its length. The descriptors below are shortend to contain only
		; the address of the actual variable's contents and its length.
		; For example, in memory location:
		; 10000 - 10003: Address to Var1's contents: 58000 initially.
		; 10004 - 10007: Var1's content length plus terminating zero (0) byte: 31 initially.
		; 10008 - 10011: Address to Var2.
		; 10012 - 10015: Var2's length.
		; 10016 - 10019: Address to Var3.
		; 10020 - 10023: Var3's length.
		; ..... - .....: Other descriptors and data and code.
		; 58000 - 58030: Contents of Var1 initially: "Here is a super global string."0
		;
		; Wherever Var1 is used, Var1 points to the descriptor located at 10000.
		; ThisVar #= Var1 simply causes ThisVar to point to the descriptor located at 10000.
		; And now Var1 and ThisVar are the same variable.
		; It doesn't matter if the actual variable's content address changes, the
		; descriptor address never changes and allways contains the address
		; to the actual variable's contents.
		; 
		; The above assumes ASCII mode, that is, one byte of memory per character.
	}
}
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: ThisVare <assignment> Var1 ; Now both variables point to same content.

19 Feb 2017, 05:50

For that you can use %:

Code: Select all

var := "variableName"
%var% := "something"
I prefer this mode over the one you suggested since yours isn't highlighting the fact that we are in fact accessing another variable.
Other methods could involve using getters and setters and is my prefered method.
There is also a function that does exactly what you want to want to do in AutoHotkey_H
Recommends AHK Studio

Return to “AutoHotkey Development”

Who is online

Users browsing this forum: No registered users and 39 guests