notation: objects: key names to avoid clashes with methods/properties

Get help with using AutoHotkey and its commands and hotkeys
User avatar
jeeswg
Posts: 6371
Joined: 19 Dec 2016, 01:58
Location: UK

notation: objects: key names to avoid clashes with methods/properties

31 Jan 2018, 02:47

- I use associative arrays a lot, e.g. to remove duplicates from a list (check each item against an array, if the array does not already have the item, add it to the array and append it to the new list) and for frequency counts. However, because of the risk of creating a key with the same name as a method/property, I now tend to prefix 'z' to every key name.
- Here's a real-life example:
How to get length of an audio file? - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 81#p182781
- This problem is so common that this should be mentioned in the documentation, together with an example. What prefix/suffix should the documentation use for key names? Alternatively, a new default AutoHotkey class could be created, a case-insensitive equivalent of the case-sensitive Scripting.Dictionary class, simply to avoid doing something as quirky as prefixing/suffixing key names. How do you deal with this problem? Cheers.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
nnnik
Posts: 4145
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: notation: objects: key names to avoid clashes with methods/properties

31 Jan 2018, 03:52

I use that a lot too - it seems I forgot to mention it in my tutorial.
The only method you really need for the algorythm you described is .hasKey - and luckily

Code: Select all

ObjHasKey( array, "Key" )
[/c] is a thing so you don't even need to care whether you have overwritten a method or not.
Generally I prefer to put all data into the associative array first before appending it to the list afterwards - this gives me the advatage that I don't even need .hasKey since I can just overwrite the old value.
Then afterwards I put all the data into a new list. Then I delete the associative array.
Problems where you need to filter distinct values once or twice are common, but maintaining a list for constantly filtering new values on the fly is something I haven't found a lot yet.
I also don't understand why you want to avoid overwriting methods when you don't use this associative array for anything else than the checking for doubles.
Recommends AHK Studio
User avatar
jeeswg
Posts: 6371
Joined: 19 Dec 2016, 01:58
Location: UK

Re: notation: objects: key names to avoid clashes with methods/properties

31 Jan 2018, 04:12

- Sometimes maintaining order is important, i.e. I don't want the items in alphabetical order. E.g. the text is: old list / barrier / new list, remove duplicates and you end up with new items under the barrier.
- In AHK v2, numeric-looking keys are forced as numeric keys (which appear before string keys in a for loop), so I need a non-blank prefix to keep them as strings, so that a for loop retrieves the items in alphabetical order. In AHK v1, I may want to at least use "" (a blank prefix) to force numeric-looking keys as strings. In both cases a quirky-looking prefix is needed.
- Thanks re. ObjHasKey, I had come across that before. Is there definitely no other method/property that can be overwritten, that could likely cause a problem, in AHK v1/v2.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
nnnik
Posts: 4145
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: notation: objects: key names to avoid clashes with methods/properties

31 Jan 2018, 08:11

Well .base is always an issue. - this could be solved by using a property in .base
Sadly there is no ObjectRawGet or we could avoid this issue entirely.
Hmm yeah I never combine both numeric looking keys and strings using this method.
Recommends AHK Studio
User avatar
jeeswg
Posts: 6371
Joined: 19 Dec 2016, 01:58
Location: UK

Re: notation: objects: key names to avoid clashes with methods/properties

31 Jan 2018, 15:50

- Cheers nnnik. I did some tests and indeed if you assign a key called 'base', it is not found by ObjHasKey or by for loops.
- I also found that if I assign a key called '_NewEnum', the for loops will fail. It seems that ObjNewEnum does not provide a workaround for this. If there is a workaround, that would be great to know about.
- AFAIK no other key names cause any problems.
- [EDIT:] I got the same results in AHK v2, although I had to comment out a few lines that were failing in both AHK v1 and v2, but that were only causing error messages in AHK v2.

Code: Select all

q:: ;objects - do methods/properties interfere with ObjHasKey/for loops?
;answer: it appears that only base interferes with ObjHasKey
;answer: it appears that only _NewEnum interferes with for loops (and base doesn't appear in for loops)
vList := "__Call,__Class,__Delete,__Get,__Init,__New,__Set,_NewEnum,base,Next"
. ",Clone,Delete,GetAddress,GetCapacity,HasKey,InsertAt,Length,MaxIndex,MinIndex,Pop,Push,RemoveAt,SetCapacity"
. ",Insert,Remove" ;deprecated
. ",Call"

oArray := ["a","b","c"]
MsgBox, % oArray.1 ;a
MsgBox, % oArray.Length() ;3

Loop, Parse, vList, % ","
	oArray[A_LoopField] := 1
	;oArray[A_LoopField] := {}

MsgBox, % oArray.1 ;a
MsgBox, % oArray.Length() ;(blank)
MsgBox, % ObjHasKey(oArray, 1) ;1
MsgBox, % ObjHasKey(oArray, 4) ;0

vOutput := ""
for vKey, vValue in oArray
	vOutput .= vKey " " vValue "`r`n"
MsgBox, % vOutput ;(blank)

;all report 1 apart from base
vOutput := ""
Loop, Parse, vList, % ","
	vOutput .= ObjHasKey(oArray, A_LoopField) " " A_LoopField "`r`n"
MsgBox, % vOutput

vOutput := ""
for vKey, vValue in oArray
	vOutput .= vKey " " vValue "`r`n"
MsgBox, % vOutput ;(blank)

vOutput := ""
for vKey, vValue in ObjNewEnum(oArray)
	vOutput .= vKey " " vValue "`r`n"
MsgBox, % vOutput ;(blank)

;remove _NewEnum to list keys
ObjDelete(oArray, "_NewEnum")
vOutput := ""
for vKey, vValue in oArray
	vOutput .= vKey " " vValue "`r`n"
MsgBox, % vOutput
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
nnnik
Posts: 4145
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: notation: objects: key names to avoid clashes with methods/properties

01 Feb 2018, 04:36

-I recently found that writing to .base does not actually add anything to the dictionary but rather modifies the supoerclass thats stored somehwere else.
That it modifies the super class is nothing new but that the super class is not actually stored in the array itself is new.
You can use ObjRawSet to avoid that and write a key named .base into the object.
-You can just use ObjNewEnum to iterate manually - sadly the for loop doesn't accept an enumerator object as parameter yet - I think.

Edit:There is a workaround though

Code: Select all

Obj := { _NewEnum:1 }
for each, value in ( new useCustomIterator( Obj, "ObjNewEnum" ) )
	Msgbox % each . " : " . value
	
class useCustomIterator {
	__New( obj, iteratorFunc ) {
		this.obj := obj
		this.iteratorFunc := iteratorFunc
	}
	_NewEnum() {
		iteratorFunc := this.iteratorFunc
		return %iteratorFunc%( this.obj )
	}
}
Recommends AHK Studio
Helgef
Posts: 3703
Joined: 17 Jul 2016, 01:02
Contact:

Re: notation: objects: key names to avoid clashes with methods/properties

01 Feb 2018, 06:26

I did some tests and indeed if you assign a key called 'base', it is not found by ObjHasKey or by for loops.
You must have been very surprised > :angel: <.
sadly the for loop doesn't accept an enumerator object as parameter yet - I think.
That is correct.
In v2 this works, I'm not sure why it doesn't work in v1,

Code: Select all

o:={_newenum:0}
for k, v in {_newenum:func("objnewenum").bind(o)}
	msgbox k  "`t" v
This works in both v1 and v2,

Code: Select all

o:={_newenum:0}
for k, v in {_newenum:func("f").bind(objnewenum(o))}
	msgbox  k  "`t" v
f(o){
	return o
}
Sadly there is no ObjectRawGet or we could avoid this issue entirely.
If you get a property, what would it return? ObjGET/SETBase() would probably be useful, assuming they do not invoke meta functions, and maybe BaseHasKey :think: .

Cheers
User avatar
nnnik
Posts: 4145
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: notation: objects: key names to avoid clashes with methods/properties

01 Feb 2018, 08:25

Helgef wrote:
Sadly there is no ObjectRawGet or we could avoid this issue entirely.
If you get a property, what would it return? ObjGET/SETBase() would probably be useful, assuming they do not invoke meta functions, and maybe BaseHasKey :think: .
Well getting a property would return the property like:

Code: Select all

for each, key in propertyContainer
{
	if ( each = "property" )
		Msgbox % ( val := key ) . "`n" propertyContainer[each]
}
obj := {}
obj.obj := val
Msgbox % obj.obj

class propertyContainer {
	property[]{
		get{
			return "Hello World!"
		}
		set{
			return value
		}
	}
}
That would actually enhance the ability to work with properties.
Recommends AHK Studio
User avatar
jeeswg
Posts: 6371
Joined: 19 Dec 2016, 01:58
Location: UK

Re: notation: objects: key names to avoid clashes with methods/properties

01 Feb 2018, 22:33

OK, it seems we have workarounds to both write to and read from an associative array with all of the special key names. I've made the minimum required modifications to my script from earlier. Any further comments on the 'wonder line', would be appreciated. Btw can the custom ObjNewEnumAux function use ByRef?

Code: Select all

q:: ;objects - do methods/properties interfere with ObjHasKey/for loops?
;answer: it appears that only base interferes with ObjHasKey
;answer: it appears that only _NewEnum interferes with for loops (and base doesn't appear in for loops)
vList := "__Call,__Class,__Delete,__Get,__Init,__New,__Set,_NewEnum,base,Next"
. ",Clone,Delete,GetAddress,GetCapacity,HasKey,InsertAt,Length,MaxIndex,MinIndex,Pop,Push,RemoveAt,SetCapacity"
. ",Insert,Remove" ;deprecated
. ",Call"

oArray := ["a","b","c"]
MsgBox, % oArray.1 ;a
MsgBox, % oArray.Length() ;3

Loop, Parse, vList, % ","
	ObjRawSet(oArray, A_LoopField, 1) ;use ObjRawSet (instead of the line below) to handle .base (otherwise the .base key is not written to)
	;oArray[A_LoopField] := 1
	;oArray[A_LoopField] := {}

MsgBox, % oArray.1 ;a
MsgBox, % oArray.Length() ;(blank)
MsgBox, % ObjHasKey(oArray, 1) ;1
MsgBox, % ObjHasKey(oArray, 4) ;0

vOutput := ""
for vKey, vValue in oArray
	vOutput .= vKey " " vValue "`r`n"
MsgBox, % vOutput ;(blank)

;all report 1 apart from base
vOutput := ""
Loop, Parse, vList, % ","
	vOutput .= ObjHasKey(oArray, A_LoopField) " " A_LoopField "`r`n"
MsgBox, % vOutput

vOutput := ""
for vKey, vValue in oArray
	vOutput .= vKey " " vValue "`r`n"
MsgBox, % vOutput ;(blank)

vOutput := ""
for vKey, vValue in ObjNewEnum(oArray)
	vOutput .= vKey " " vValue "`r`n"
MsgBox, % vOutput ;(blank)

;remove _NewEnum to list keys
;ObjDelete(oArray, "_NewEnum")
vOutput := ""
for vKey, vValue in {_NewEnum:Func("ObjNewEnumAux").Bind(ObjNewEnum(oArray))} ;use this wonder line (instead of the line below) to handle _NewEnum (otherwise you must delete the _NewEnum key to run the for loop)
;for vKey, vValue in oArray
	vOutput .= vKey " " vValue "`r`n"
MsgBox, % vOutput
return

ObjNewEnumAux(o)
{
	return o
}
I feel there's a Code Puzzle Thread question here somewhere, and the question is going to be horrible.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Helgef
Posts: 3703
Joined: 17 Jul 2016, 01:02
Contact:

Re: notation: objects: key names to avoid clashes with methods/properties

02 Feb 2018, 04:48

I feel there's a Code Puzzle Thread question here somewhere, and the question is going to be horrible.
I actually considered to only allow one enumerator to be created for List in this puzzle, but since that would imply two separate problems, I left it out.
User avatar
jeeswg
Posts: 6371
Joined: 19 Dec 2016, 01:58
Location: UK

Re: notation: objects: key names to avoid clashes with methods/properties

03 Feb 2018, 07:44

- In reference to these 2 threads:
objects: backport AHK v2 Gui/Menu classes to AHK v1 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 37&t=43530
object classes: redefine __Set() temporarily / general queries - Page 3 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=42674
I had said:
I'm trying to interact with a class object directly. Properties/methods seemed fine, but not __Set. Is there an obvious reason for this? Thanks.
- I did some simple tests relating to functions/methods. They don't shed much too much light, but are worth posting.
- The answer to the original question may be that to use meta-functions directly in an object class, you have to add references to them explicitly to the base object of that object class. However, which meta-functions / methods qualify I'm not exactly sure yet. Also, technically, which methods are/aren't meta-functions, I haven't found a perfect list of these.

Code: Select all

;which functions appear in the base

global vLog
;list contains 26 items
vList := "__Call,__Class,__Delete,__Get,__Init,__New,__Set,_NewEnum,base,Next"
. ",Clone,Delete,GetAddress,GetCapacity,HasKey,InsertAt,Length,MaxIndex,MinIndex,Pop,Push,RemoveAt,SetCapacity"
. ",Insert,Remove" ;deprecated
. ",Call"
Loop, Parse, vList, % ","
{
	vLog .= A_LoopField "`t"
	MyEverythingClass[A_LoopField]()
	if !(RTrim(vLog) = vLog)
		vLog .= "`r`n"
}
MsgBox, % Clipboard := vLog

vOutput := ""
oArray := new MyEverythingClass
for vKey, vValue in oArray.base
	vOutput .= vKey " " vValue "`r`n"
MsgBox, % vOutput

class MyEverythingClass
{
	__Call()
	{
		vLog .= A_ThisFunc "`r`n"
	}
;	__Class()
;	{
;		vLog .= A_ThisFunc "`r`n"
;	}
	__Delete()
	{
		vLog .= A_ThisFunc "`r`n"
	}
	__Get()
	{
		vLog .= A_ThisFunc "`r`n"
	}
	__Init()
	{
		vLog .= A_ThisFunc "`r`n"
	}
	__New()
	{
		vLog .= A_ThisFunc "`r`n"
	}
	__Set()
	{
		vLog .= A_ThisFunc "`r`n"
	}
;	_NewEnum()
;	{
;		vLog .= A_ThisFunc "`r`n"
;	}
;	base()
;	{
;		vLog .= A_ThisFunc "`r`n"
;	}
	Next()
	{
		vLog .= A_ThisFunc "`r`n"
	}
	Clone()
	{
		vLog .= A_ThisFunc "`r`n"
	}
	Delete()
	{
		vLog .= A_ThisFunc "`r`n"
	}
	GetAddress()
	{
		vLog .= A_ThisFunc "`r`n"
	}
	GetCapacity()
	{
		vLog .= A_ThisFunc "`r`n"
	}
	HasKey()
	{
		vLog .= A_ThisFunc "`r`n"
	}
	InsertAt()
	{
		vLog .= A_ThisFunc "`r`n"
	}
	Length()
	{
		vLog .= A_ThisFunc "`r`n"
	}
	MaxIndex()
	{
		vLog .= A_ThisFunc "`r`n"
	}
	MinIndex()
	{
		vLog .= A_ThisFunc "`r`n"
	}
	Pop()
	{
		vLog .= A_ThisFunc "`r`n"
	}
	Push()
	{
		vLog .= A_ThisFunc "`r`n"
	}
	RemoveAt()
	{
		vLog .= A_ThisFunc "`r`n"
	}
	SetCapacity()
	{
		vLog .= A_ThisFunc "`r`n"
	}
	Insert()
	{
		vLog .= A_ThisFunc "`r`n"
	}
	Remove()
	{
		vLog .= A_ThisFunc "`r`n"
	}
	Call()
	{
		vLog .= A_ThisFunc "`r`n"
	}
}
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Helgef
Posts: 3703
Joined: 17 Jul 2016, 01:02
Contact:

Re: notation: objects: key names to avoid clashes with methods/properties

03 Feb 2018, 14:32

- I did some simple tests relating to functions/methods. They don't shed much too much light, but are worth posting.
Trying to figure out how stuff works by seemingly random tests isn't a good apporach. You should look in the documentation, and then you can make tests to verify your understanding.
Also, technically, which methods are/aren't meta-functions, I haven't found a perfect list of these.
As far as I know there isn't a list in the documentation, and it is not very interesting, all methods are documented and there is (afaik) no general claims in the docs about the meta functions which requires you to guess who they are.
Here is A list:
  • __call
  • __get
  • __set
  • __new
  • __delete
  • __init
  • _newEnum
The first three are listed under the head line Meta-Functions, so no discussion there. The others are also often refered to as meta functions, I believe.
User avatar
jeeswg
Posts: 6371
Joined: 19 Dec 2016, 01:58
Location: UK

Re: notation: objects: key names to avoid clashes with methods/properties

03 Feb 2018, 16:49

- The test above, was trying to check something, but partway through I realised it wouldn't work. However, it did help to check the scope of variables within the methods, and, whether you could invoke all the methods in a class object directly.
- In general, invoking things directly in a class object, appears to work, but to invoke things indirectly, you need to set the contents of the base object.
- Here are the further tests, that complete the tests in the post above.

Code: Select all

global vLog

;various things that do not trigger methods in the class object
MyEverythingClass.MyNonExistentMethod ;__Call
;MyEverythingClass := "" ;__Delete
;MsgBox, % IsObject(MyEverythingClass)
vValue := MyEverythingClass.MyNonExistentKey ;__Get
MyEverythingClass.MyNonExistentKey := 1 ;__Set
MsgBox, % "LOG:`r`n" vLog

;testing a for loop
vOutput := ""
for vKey, vValue in MyEverythingClass
	vOutput .= vKey " " vValue "`r`n"
MsgBox, % vOutput
MsgBox, % "LOG:`r`n" vLog

;direct calls will invoke the class object's methods
obj := MyEverythingClass.__Get()
MyEverythingClass.__Set()
MyEverythingClass.Clone()
MyEverythingClass.Delete("MyKey")
MsgBox, % "LOG:`r`n" vLog

MsgBox, % MyEverythingClass.HasKey()
MsgBox, % MyEverythingClass.Length()
MsgBox, % MyEverythingClass.MyMethod()
MsgBox, % MyEverythingClass.MyProperty
MsgBox, % "LOG:`r`n" vLog

obj := new MyEverythingClass
vLog := ""
MsgBox, % "LOG:`r`n" vLog
return

class MyEverythingClass
{
	MyKey := "K"
	static MyStaticKey := "SK"
	__Call()
	{
		vLog .= A_ThisFunc "`r`n"
	}
;	__Class()
;	{
;		vLog .= A_ThisFunc "`r`n"
;	}
	__Delete()
	{
		vLog .= A_ThisFunc "`r`n"
	}
	__Get()
	{
		vLog .= A_ThisFunc "`r`n"
	}
;	__Init()
;	{
;		vLog .= A_ThisFunc "`r`n"
;	}
	__New()
	{
		MyKey2 := "K2"
		static MyStaticKey2 := "SK2"
		vLog .= A_ThisFunc "`r`n"
	}
	__Set()
	{
		vLog .= A_ThisFunc "`r`n"
	}
	_NewEnum()
	{
		vLog .= A_ThisFunc "`r`n"
		return this
	}
;	base()
;	{
;		vLog .= A_ThisFunc "`r`n"
;	}
	Next(ByRef vKey, ByRef vValue)
	{
		vLog .= A_ThisFunc "`r`n"
	}
	Clone()
	{
		vLog .= A_ThisFunc "`r`n"
	}
	Delete()
	{
		vLog .= A_ThisFunc "`r`n"
	}
	GetAddress()
	{
		vLog .= A_ThisFunc "`r`n"
	}
	GetCapacity()
	{
		vLog .= A_ThisFunc "`r`n"
	}
	HasKey()
	{
		vLog .= A_ThisFunc "`r`n"
	}
	InsertAt()
	{
		vLog .= A_ThisFunc "`r`n"
	}
	Length()
	{
		vLog .= A_ThisFunc "`r`n"
	}
	MaxIndex()
	{
		vLog .= A_ThisFunc "`r`n"
	}
	MinIndex()
	{
		vLog .= A_ThisFunc "`r`n"
	}
	Pop()
	{
		vLog .= A_ThisFunc "`r`n"
	}
	Push()
	{
		vLog .= A_ThisFunc "`r`n"
	}
	RemoveAt()
	{
		vLog .= A_ThisFunc "`r`n"
	}
	SetCapacity()
	{
		vLog .= A_ThisFunc "`r`n"
	}
	Insert()
	{
		vLog .= A_ThisFunc "`r`n"
	}
	Remove()
	{
		vLog .= A_ThisFunc "`r`n"
	}
	Call()
	{
		vLog .= A_ThisFunc "`r`n"
	}
	MyMethod()
	{
		vLog .= A_ThisFunc "`r`n"
	}
	MyProperty[]
	{
		;vLog .= A_ThisFunc "`r`n" ;Error: Not a valid property getter/setter.
		get
		{
			vLog .= A_ThisFunc "`r`n"
		}
		set
		{
			vLog .= A_ThisFunc "`r`n"
		}
	}
}
- I read the documentation in full, then I checked forum examples, then I experimented, then I asked questions. Now that I know more, I can get more from the documentation, the next time I read it.
- No doubt the documentation is technically sound, but it is very difficult to learn from, especially for someone who hasn't used objects in that way before. I wonder to what extent prior knowledge has helped you to get the most out of objects/object classes in AHK, and whether you have any useful links.
- I searched the entire text of the documentation for references to meta-functions, __Get/__Set/__Call [EDIT: and __Delete] are the only methods described as meta-functions. [EDIT: Meta-functions are also methods, according to a quote in an old version of the documentation, I only know this because I came across an old post which quotes it.]
Link:
object classes: redefine __Set() temporarily / general queries - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 68#p193868
- Part of the reason I'm interested in what is/isn't a meta-function, is that there may be some properties which meta-functions have/lack in comparison to other methods. Also, if it's a widely used term, it might be useful to mention it for any people new to AutoHotkey, but who know other programming languages.

- I have asked about methods in two places before.
Suggestions on documentation improvements - Page 16 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 32#p191632
object classes: redefine __Set() temporarily / general queries - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 68#p193868
- I will start my tutorial with a list of methods, and I will state that unfortunately: a definition, and a complete list of meta-functions, were not available. In tutorials you have to be clear what you're telling someone, and you have to be clear what you're not.

- [EDIT:] This link has some good information on meta-functions. In short, obj.MyMethod() is direct, obj.key := "value" is indirect, you don't see a method name (it uses the __Set() method if the key doesn't already exist). This is something I've been aware of since trying to interact with a class object directly. AFAIK this is the principle of meta-functions, using methods without explicitly specifying their name, direct v. indirect.
- So since a for loop uses _NewEnum() and Next(), but not explicitly, perhaps those methods could be considered meta-functions. Perhaps there are methods that have a not-immediately-obvious way of being called indirectly. If __Class() is a key, and base is a property, but there is indirect behaviour involved, are they candidates? Does a '__' prefix imply a meta-function. Why is _NewEnum() different, to fit with COM objects? Anyhow, having an official list would make things easier.
Classes in AHK, a Dissection (Advanced) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=6177
- Btw is something like this possible? obj.__Set("k", "v") or obj.__Set(obj, "k", "v").
re. 'surprised'
Last edited by jeeswg on 07 Feb 2018, 08:08, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Helgef
Posts: 3703
Joined: 17 Jul 2016, 01:02
Contact:

Re: notation: objects: key names to avoid clashes with methods/properties

04 Feb 2018, 13:47

- I read the documentation in full, then I checked forum examples, then I experimented, then I asked questions. Now that I know more, I can get more from the documentation, the next time I read it.
What do you mean? Like you read it from start to finish, once? That is not how you read documentation, unless you are one of those weird people who remembers everything they read :crazy:.
- I searched the entire text of the documentation for references to meta-functions, __Get/__Set/__Call are the only methods described as meta-functions.
That is good, thanks :thumbup:. So it is sufficient to list those as meta functions, the rest in my list isn't needed.
- Part of the reason I'm interested in what is/isn't a meta-function, is that there may be some properties which meta-functions have/lack in comparison to other methods. Also, if it's a widely used term, it might be useful to mention it for any people new to AutoHotkey, but who know other programming languages.
Even in mathematics there are ambigous defintions and notations, the world of programming is of course much worse, so do not assume that your knowledge in one programming language transfers to another, ever. (Of course, in reality we all do :lol: )
In summary: I still do not think it matters, very much.
- Btw is something like this possible? obj.__Set("k", "v")
Yes, you can call __set like any other method, it doesn't imply the special behaviour of __set as obj[k] := v does. In v2, it might (eventually, but currently it doesn't).

Cheers :wave:
re. 'surprised'
Spoiler
User avatar
jeeswg
Posts: 6371
Joined: 19 Dec 2016, 01:58
Location: UK

Re: notation: objects: key names to avoid clashes with methods/properties

04 Feb 2018, 15:15

- I read through different sources in an ad hoc manner initially, but subsequently, to try and understand things in a more complete way, I was fairly systematic.
- I'm curious re. __Init.Call(obj) which you mentioned, which I haven't seen on the forum or in the documentation.
- 'Of course, in reality we all do' hahaha.
- You never know how people are going to approach the documentation. Sometimes people can waste a lot of time, looking for a definition that isn't there.
- Sometimes when studying mathematics, the best help has been: concrete lists and very basic examples that illustrate principles. Have you had the m1sf0rtune of x-periencing a lot of mathematics yourself?
- Could you give a demo of using __Set directly, I couldn't get it to work. Also, GeekDude's tutorial mentioned this, which I couldn't get to work either:
MyObject.base.__Set.(MyObject, "Pizza", "Cheez")
Also, I was curious what would happen if you invoked __Set directly, when a key already existed. Also again, '__Set.(' looks curious.
re. 'surprised'
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Helgef
Posts: 3703
Joined: 17 Jul 2016, 01:02
Contact:

Re: notation: objects: key names to avoid clashes with methods/properties

06 Feb 2018, 04:11

Could you give a demo of using __Set directly, I couldn't get it to work.
Get what to work? As I said, you can call __set like any other method, but the special behaviour caused by := isn't invoked.
Also, GeekDude's tutorial mentioned this, which I couldn't get to work either:
MyObject.base.__Set.(MyObject, "Pizza", "Cheez")
I still didn't read it. I will guess that, that is only used to demonstrate what is beeing called, not implying it is equivalent to myObj["pizza"] := "cheez", which it isn't in general.
Also again, '__Set.(' looks curious.
It does, and it is deprecated, even in v1.

Cheers.
Helgef
Posts: 3703
Joined: 17 Jul 2016, 01:02
Contact:

Re: notation: objects: key names to avoid clashes with methods/properties

07 Feb 2018, 07:24

- I searched the entire text of the documentation for references to meta-functions, __Get/__Set/__Call are the only methods described as meta-functions.
Actually, __delete is called a meta-function in the documentation, search __delete meta-function on the general object page.

Cheers
User avatar
jeeswg
Posts: 6371
Joined: 19 Dec 2016, 01:58
Location: UK

Re: notation: objects: key names to avoid clashes with methods/properties

07 Feb 2018, 08:01

- Thanks. It turns out I have that quote here already. The link also mentions two conflicting quotes re. what a meta-function is.
object classes: redefine __Set() temporarily / general queries - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 68#p193868
- Apologies, the confusion may have arisen because I had three key distinctions to be resolved: which items are *methods*, and which items are *meta-functions*, and which are both. E.g. checking again now, I couldn't find '__Delete' and 'method' together.
- The only way to confirm some of these method/meta-function queries for sure is to reread the entire AHK v1 and AHK v2 documentations, and to also look out for indirect mentions of things that imply a certain meaning ... Explicit definitions/lists of what are/aren't methods/meta-functions/both look increasingly useful.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Odlanir and 142 guests