why does (Object is Object) evalute to true?

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
20170201225639
Posts: 144
Joined: 01 Feb 2017, 22:57

why does (Object is Object) evalute to true?

25 Aug 2023, 22:25

According to the doc,
(0) "Value is Class yields true (1) if Value is an instance of Class or false (0) otherwise".

So from the fact that :
(1) (Object is Object) evalutes to 1
we can infer that:
(2) Object is an instance of the class Object

However, the first occurence of "Object" in (2) refers to none other than the class Object, so (2) is equivalent to
(3) the class Object is an instance of the class Object

But how can a class be an instance of itself? Seems to raise a chicken and egg problem. How did this class come into existence in the first place? Since it's an instance of class, don't we have to call that class's, i.e. its own, constructor (as in: Object := Object())? But wait, that would presuppose that this class already exists, in which case what need is there to call the constructor?

(edit: relatedly, it's also possible for 2 classes to be instances of each other, e.g. (Class is Object)==1 && (Object is Class)==1; (Object is Any)==1 && (Any is Object)==1)

How do you wrap your head around this? I'm not saying (Object is Object) shoudn't evalute to 1. I can see one argument it *must* ("Object is a class, and every class is an instance of Class, which is a subclass of Object, and that's why 'Object is Object' has to be true"). But that still doesn't fully explain away the chicken and egg problem.

What are all the other instances where (X is X) evaluates to true? I only found 2 other instances, (Class is Class) and (Any is Any), both of which again kind of makes sense but also raise the chicken and egg problem.

Of course, most other cases of (X is X) (as expected) do not evaluate to true

Code: Select all

	Msgbox(String is String) ; 0
	Msgbox(Number is Number) ; 0
	Msgbox(Map is Map) ; 0
	Msgbox(Array is Array) ; 0
edit: (Something related, but probably less paradoxical is that a superclass can be an instance of a subclass, e.g. (Any is Object)==1, (Any is Class)==1)
lexikos
Posts: 9679
Joined: 30 Sep 2013, 04:07
Contact:

Re: why does (Object is Object) evalute to true?

27 Aug 2023, 01:12

tl;dr

All Classes are instances of Object. You can probably find a post by me somewhere (or documentation) explaining this, if you try.

I think you should not post in AutoHotkey Development or Bug Reports in future. Try Ask for Help first. I have moved the topic.

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: Draken, wilkster, yuhuyy and 20 guests