2020-12-31

keywords "this", "self", "returned" for adda

 20.10.28: adda/lexicon/this, self, returned:

a discussion about adding keywords to the language.

11.2: intro:

. in mainstream oop, 

there is an implied object;

eg, to evaluate x`= x + y,

you would see x`add(y)

and then x would add y to itself.

. we use the term "this" to refer to x

because since the class's methods are operating on 

an implied object

we don't otherwise know the name of 

of the particular object (x in this example).

. in the adda model of oop

there are some cases without an implied object;

eg, z`= x+y would be this call:

z`= number.type`+( x, y )

but adda does support calls like x`add(y)

so it has a use for "this".


20.10.28: 

. use of "this" is useful when

wanting to refer to the whole object

rather than its individual fields


. the term "self" is more suggestive of

an actor than an object,

so it will best serve as the name of

an anonymous subprogram;

a subprogram's ability to do recursion

depend's on it knowing what to call itself.


. another special term in oop is "super";

representing the type's parent type;

for when there are multiple levels of inheritance;

eg, when type A can be inherited by B

and then B can be inherited by C,

B can use "super" to refer to A,

but then when C reuses B,

the reference to super within C will refer to B not A.

. then again,

do we want to support that sort of inheritance?

. in the sort of oop that type number needs

there is only one level of inheritance:

the abstract type class number,

and the various concrete polymorphisms of number.

[2021.11.15, 16: 

are you sure that type number has only one level of inheritance?

inheriting subclasses are defined by variations in

either the interface or the implementation;

eg, ints have a divide operation that differs from that for reals.

and then another way that ints are further divided,

is by considering only a limited range,

in order to fit the number within a certain number of bits.

int32 inherits from int inherits from number.]

. if we did have multiple levels of inheritance

it could have it apply only to 

interfaces and not implementation,

so then there would be no use for the term "super".

. however,

when you do allow for implementation inheritance,

that is a lot of code that 

doesn't have to be rewritten and retested.

. before deciding on limitations,

you should see what might be needed by

AI systems that are writing their own code

to adapt to changes in the environment.

todo:

. study how oop is used by various gaming engines.

. review oop notes

http://amerdreamdocs.blogspot.com/search/label/oop


10.28: 11.2: 

. if we were to name the returned object

we can't call it "this" because,

a type can define a method that returns some other type,

so then "this" would refer to both the current object

and to the returned object.

. in languages that don't have anonymous functions,

the name of the function can double as 

the name of its return, depending on context:

if an argument is applied (even an empty one),

then it is a recursion,

otherwise it is a returned object access;

and, anonymous functions could work the same way:

"self" is a returned object access

"self(..)" is a recursion.

. but suppose this is a function with no parameters;

and then adda is requiring "self()" for recursion;

then to be consistent,

any launching of a parameterless subprogram

must use "subprogram()", instead of just

"subprogram".

. the returned object could be named "returned";

but suppose you were to say for the sake of 

reducing the size of the language's vocabulary

that an anonymous function would never need

a name for "returned" because it can declare a local 

and then return that by name.

. such a local may better reflect reality

when supporting more concurrency;

the function could be moved to a different processor

and would no longer have easy access to

the stack of its caller.

. if there is no concurrency, 

the returned object already exists on the stack

so that when you say "return x"

it means "returned`= x; exit self".

ie, the returned object is a pointer to

whatever the call got assigned to when it returns.

. say the callee is evaluating f(anon(x)),

it creates f's activation record on the stack;

then it remembers the address of f's parameter as

[what needs to be returned by anon]

then it creates anon's activation record on the stack;

and assigns to anon's returned pointer

the address of [what needs to be returned by anon].

. if there is concurrency;

"returned" is an implicit local declaration.



No comments:

Post a Comment