PDA

View Full Version : Static Type-members and scopes



ReneMiner
08-07-2020, 11:23
I am Not Sure its years ago but i thought Eros Said, No Problem for static members to assign the value on Definition of a Type since statics are Same to all objects of the Type.
Somehow it does Not Accept , i tried value, equal-sign and even without and the equate-style



Type tApple
Static is_a1 AS String Value "fruit"
'nor
Static is_a2 As String = "fruit"
' neither
Static $IS_A "fruit" As String
' Not even
Static String Value "fruit" To is_a$
'and Not
Static String isA$ Value "fruit"
End Type

IT we're also OK If on udt-definition assigned statics we're named Const which tells the Parser that an assignement will follow to the actual static member and IT must Not Change its value again.

That's the one Thing. The other ist Bit complex but related.
Assume the udt like

Type tVec2L
X AS Long 'Type-Scope
Y AS Long
Function _Create(Byval lX as Long, Byval lY as Long)
X= lX
Y= lY
End Function
Function Put(Byval lX as Long, Byval lY as Long)
Me.X=lX
Me.Y=lY
End Type


As obvious X and Y subelements of the Udt used without to refer to Me.
to clarify:
Within _Create() actually the X and Y are already used variables in Type-Scope that WE prefix Me currently. They should be available without Me inside the Type-EndType and no more possible to use again Same variable names local in functions Nor AS parameter-names of Type Functions.

To dim X or Y within the types function must result in an Error. Because

Use of Me:

If we append the tVec2L as position or size to an Udt of a window-udt- who will be Me?
Difficult because the call starts as

MyWin.Position.Put(x,y)

Obviously even If attached to the window which is the object- the properties - since their scope during Put() are what is named ME Here


But how within the call If Me.X and Me.Y mean the Position
but Not the window?
How we get a reference to the owner of the property "Position"???

Position must Not become Me! That's why X and Y have to BE valid in scope of tVec2L without the Me

That's why nga.
Me has to become /Stick to the actual highest scope the First of the dot-notation-seperated Expression. The Main object.
And what is x and y within the udt tVec2L must become within the type-function somewhat Like global variables in global Functions.
In Type-Scope the udt-subelements must BE available inside the types Functions without any prefix. If With-End With- construct became illegal within Type-Scope IT we're a possibility that X and Y in _Create() were used AS .X and .Y to refer to current Type-Scope but it still should be illegal to dim X local within a types function If the Type has a subelement X already.

So the Type have between Type and End Type a Type-scope that appears as a global scope within the Functions of the Udt while from global scope they must BE prefixed AS "myobj.myvar".

I Hope i was able to Express IT a way IT IS understandeable.

If types have their own scope between global scope and Type Functions scope - so Type Functions scope becomes one Level lower than now it will be much easier to implement actually working Public and Private accessible properties and type-functions.

But for now it should be the step to make Me stick with the Maintype. And Access udt-subelements without prefixing from within Type Functions.

Petr Schreiber
17-07-2020, 20:54
Hi Rene,

A/
The following works here:


uses "console"

Type tApple
Static is_a1 AS String Value "fruit"
Static is_a2 As String = "fruit"
End Type


dim fruit as tApple

printl fruit.is_a1
printl fruit.is_a2

WaitKey


B/
Interesting ideas for sure!


Petr

ReneMiner
22-07-2020, 19:06
ideas? ok. i call it required rules to avoid complications.



I suggest also a voluntary possibility that users could prefix globally dimensioned UDTs and Variables.
Mandatory: it must be a global dimensioned object when using the prefix.
Voluntary: the use of it for now.

I am not sure what char or sign to use, thoughts:

the first "unused" ascii-char on my keyboard is !
!
in combination with equal-sign in some languages it means NOT ( != where we use <> in tB)- as i see, RegEx uses ?! for preview negation- thats why exclamation marks no good for a prefix...

@ = AT
- i think in the future we might be able to use "With Long @myVar" to one-time gain a byref-access... also no good candidate.

?
question-mark has always been a shortcut for query/print or to access help- no good neither...

~ chr$(126), \0x7D
this is used to shorten filenames or strings by windows. For us always wrapped between $DQ - some could say it means "Round" or "Near" but to be honest, using round()-function in thinBasic is rare and for shortcutting it X=Round(X) we could do as with +=, -= :: X~=X so it were always followed by an equal sign. Anyway, it can stay a delimiter - no need to add it to the
alphanumeric tokens. Only ~ means now follows a Global user variables name.

{} []
we could place it between curly braces or brackets to tell on local scope we want to access a global.
the curly ones are used to insert values into string-expressions and also we will have a problem if
thinBasic is not going to become "thinBasic 3.0" but "thin# 1.0"
so either ~x or [x] ?

As said - usage voluntary for the meantime...
if within a function a local variable has equal name as a global one it were a way to access explicit the global one without the workaround to pass the global byref as an additional parameter.


___________________________________________________________________________

The other thing- as always there is one
(in my case a dozen at once):
:D

Thinking of private scope etc. to limit accessing subelements of udts even to such
that are ReadOnly or WriteOnceOnly or absolutely inaccessible from outside its a few steps
and requires that udt-subelements have a description-part which is not accessible to the user.
It has to be hidden somewhere with the udt-function-pointers and udt-statics and to keep
backward-compatibility we leave the current UDT defined through Type-End Type as they are -
and in mind we create a copy of the whole mechanics.

I will not name it "Class" now. After searching for a good translation of what i mean there
in italian it's "la categoria", in czech as well as in german "Kategorie" or english "category", also
"Genus" (latin/english) were a nice candidate... but i continue using "TYPE" for now.

Just keep in mind the TYPE as is should remain for backward-compatibility and for easy-usage
without any ownerships etc.


if i have



'====================================================
Type tPointL
X As Long ' X IS DEFINED ON tPointL-Scope!
Y As Long ' no other X nor Y must be Dimensioned before "End Type"
' X and Y ARE IN USE FOR THESE NOW until END TYPE
' X would override a global X except we explicit point the global ~X
' or the global X gets passed byref with another name here

' == Sizeof( Long ) * 2

' ------------------------------------------------------

function _Create(byval lX As Long, ByVal lY As Long)
X = lX
Y = lY
' do not use ME ! X and Y are already dimensioned on Type-scope!
end function
' ------------------------------------------------------
End type

'====================================================

Type tRectL Extends tPointL
W As Long
H As Long

' == Sizeof( Long ) * 4

' ------------------------------------------------------

function _Create(byval lX As Long, ByVal lY As Long,
Byval lW As Long Byval lH As Long)
X = lX
Y = lY
W = lW
H = lH
' also here X and Y inherited through extends, W and H are obvious
end function
' ------------------------------------------------------
End Type
'====================================================

until here stiill all easy to understand. A new "Category" can not extends a type but
can have subelements that are udts.

I will not name subelements of a Category like "Property" or "Member".

But all subelements content is kind of secret.
It should not be as easy as with a Type to access the subelement simply like

X=CategorizedObject.Property or CategorizedObject.Property(X)
(X might be an expression)

but have to use Get and Set or other ways ofcontrolled assignment

CategorizedObject.Property Value To ( X ) 'parenthesis= expression, no parenthesis = scalar
CategorizedObject.Property Value As ( X )

"Public" : possible to use "Value To"/Get and "Value As"/Set on it automatic
"ReadOnly" : that property only supports "Value To" or GET
"Const" : Value As/Set only once, Value To/Get always thereafter
"Private" there is no support of Value To nor As nor Get nor Set
"Union-With" kind of virtual layover allows to access parts of a property using another name and different rights

and for the local scope is no need to protect any values



Category selfdrawingObject_Rect

Public Backcolor As Long
Public BorderColor As Long
Const Bordersize As Long

' here i would like to use
'"Measurement As RectL" which provides X,Y, W and H but equals 2 times PointL also

' so write it like that:
Private Measurement As RectL
[UnionBeginWith]
Const Location [At This.Measurement] As tPointL
Const Size [At This.Measurement+[8|SizeOf(This.Location)|2 * SizeOf(Long)]]As tPointL
[UnionEndWith]
Method _Create(Byval lX as Long, Byval lY as Long, Byval lW as Long, Byval lH as Long,
optional byval lBS as Long = 1, byval lBackCol As Long = 0xFFFFFF, Byval lBordCol As Long=0)

' this makes sense to use Me - (but in common ME should mean the toplevel of the UDT/Category)

With Me.Measurement
.X=lX
.Y=lY
.W = lW
.H = lH
End With

BorderSize = lBS
Backcolor = lBackCol
BorderColor = lBordCol
DrawMe()

End Method


End Category

Long lSize =SizeOf(selfdrawingObject_Rect)

Dword myRect(Array Value Heap_Alloc(lSize), 5)
For Each sDOR In myRect
With selfDrawingObject_Rect At sDOR



i see, getting too much na... continue if ME no more nescessary within type-scope and if used it should access the primary object -the actually dimensioned variable only but not its subelements.