Anyone for Object Oriented coding on the QL?

Anything QL Software or Programming Related.
User avatar
XorA
Aurora
Posts: 789
Joined: Thu Jun 02, 2011 11:31 am
Location: Shotts, North Lanarkshire, Scotland, UK

Re: Anyone for Object Oriented coding on the QL?

Postby XorA » Tue Apr 13, 2021 4:59 pm

Derek_Stewart wrote:I also have vonvert the SV book "Version Control with Subversion" to epub, to understand SVN...


The easiest way if your already a git user is git-svn :-D


User avatar
ppe
Over Heated PSU
Posts: 130
Joined: Tue Dec 14, 2010 10:48 am
Location: Espoo, Finland

Re: Anyone for Object Oriented coding on the QL?

Postby ppe » Thu Apr 15, 2021 2:59 pm

XorA wrote:
Derek_Stewart wrote:I also have vonvert the SV book "Version Control with Subversion" to epub, to understand SVN...


The easiest way if your already a git user is git-svn :-D


Seconded! We did this at a customer who had a corporate policy of using SVN but our team wanted to use git.


User avatar
polka
Trump Card
Posts: 168
Joined: Mon Mar 07, 2011 11:43 am

Re: Anyone for Object Oriented coding on the QL?

Postby polka » Thu May 20, 2021 11:01 am

Hi all, Jedi is back

Some of you are seemingly willing to squeeze object oriented programming into the QL ? And for the moment only by crosscompilation of free pascal and maybe only for expanded machines ? I say, why not try object oriented programming with FORTH on a BBQL ?

What follows is only a very basic (and more or less non-functionnal) demonstration that I designed for SupperForth. If you want to try it you will have to LOAD_FILE from SupperForth these three source files :

The first file defines 6 new words that together with two existing FORTH words and two existing FORTH "user" variables, are enough to make FORTH look as an object oriented programming langage.

Code: Select all

: NEW ." NOOP for NEW in FORTH context" ;
: A_CLASS , ;
: AN_INSTANCE @ , ;
: METHOD DUP @ EXECUTE ;

: INSTANCE CREATE AN_INSTANCE DOES> METHOD ;
: CLASS    CREATE A_CLASS   DOES> INSTANCE ;

END_FILE


The second file uses this extension to define a very silly object oriented application.

To understant how this application works, you have to learn about two FORTH words named VOCABULARY and DEFINITIONS and two FORTH variables named CONTEXT and CURRENT.

Basically, the FORTH dictionnary is a linked list of word definitions. When looking for a word to execute or include in a new definition, this list is searched from the most recently defined word to the oldest.

When you use the word VOCABULARY followed by a name, you will define a word adding a branch to this stem ; and when you execute this word you first explore the branch down to the vocabulary definition and then continue down the stem

The branch vocabulary (followed by the FORTH stem) is called the CONTEXT.
When you add after the name of the vocabulary the word DEFINITIONS, the new words you may add are not defined in the FORTH stem but in the branch which is called the CURRENT. To sum up by an example :

FORTH
VOCABULARY FOO
: BAR ." this is BAR in stem FORTH" ;
FOO DEFINITIONS
: BAR ." this is BAR in branch FOO" ;

Then trying :
BAR this is BAR in branch FOO Ok
FORTH
BAR this is BAR in stem FORTH Ok
FOO BAR this is BAR in branch FOO

You notice that to go back to the stem you have to say FORTH (FORTH is the name of the stem vocabulary). Now you may understand this first very silly example that you will LOAD_FILE after the first :

Code: Select all

VOCABULARY CAT> ' CAT> CLASS CAT
CAT> DEFINITIONS
: NEW DROP CR ." Instanciating a CAT" ;
: SPEAK ." MEEEEOOOW !" CR ;

CAT FELIX FELIX NEW
FELIX SPEAK

CAT> VOCABULARY TOMCAT> ' TOMCAT> CLASS TOMCAT
TOMCAT> DEFINITIONS
: HEY ." I am a TOMCAT" CR ;

TOMCAT FRITZ FRITZ NEW
FRITZ SPEAK
FRITZ HEY

END_FILE


You see that you define first a VOCABULARY CAT> (any name will go) ;
then you get its execution address ' CAT> to pass to CLASS CAT
and finally, you open the CAT> DEFINITIONS for adding new words to CAT> as methods for instances of CAT

Actually, the word that you have to define mandatorily is the word NEW, that will manage the memory space for any CAT instance (in this silly example, it only outputs a message, a CAT needs no special data structure). After that, you may define any number of methods (here, we define only one called SPEAK).

Now, you have all that is needed to instanciate CATs :

CAT FELIX
FELIX NEW

and execute its methods (indeed, you had to begin with method NEW)

FELIX SPEAK MEEEOOOW
Ok

That's not all : while in VOCABULARY CAT> , let's define a child class TOMCAT :
you see that we did not redefine NEW (we could have) but use the NEW of CAT to instanciate a TOMCAT.

So let's intanciate :

TOMCAT FRITZ
FRITZ NEW

and execute :

FRITZ SPEAK MEEEOOOW
Ok
FRITZ HEY I am a TOMCAT
Ok
Last edited by polka on Sat May 29, 2021 9:36 pm, edited 4 times in total.


May the FORTH be with you !
POLKa
User avatar
polka
Trump Card
Posts: 168
Joined: Mon Mar 07, 2011 11:43 am

Re: Anyone for Object Oriented coding on the QL?

Postby polka » Thu May 20, 2021 11:05 am

Now let's use this for something a little more serious : let's define a class of VECTORs,
which instances will hold a 16bits number <size> and <size> 16bits cells and react to a lot of operations, their methods implemented in a vocabulary VECTOR>. So after LOAD_FILE of the first file of the previous post, LOAD_FILE the following :

Code: Select all

VOCABULARY VECTOR> ' VECTOR> CLASS VECTOR

VECTOR> DEFINITIONS

VARIABLE SIZE
CR .( SIZE holds the size of the last VECTOR named )
VARIABLE SAME
CR .( SAME is a boolean TRUE if SIZE equals size )
: SAME? ( size --- ) DUP SIZE @ = SAME ! SIZE ! ;
CR .( SAME? is a function to update SIZE and SAME )
: SIZE! ( size --- ) SIZE ! ;
: SIZE@ ( --- size ) SIZE @ ;

: NEW ( size --- ) DUP SIZE! DUP , 2* ALLOT ;
: ! ( Nx16bit#,V --- ) DROP CR ." pop and store Nx16bit# into V" ;
: @ ( V --- N1..NK,K ) DROP CR ." push Nx16bit# from V onto the data stack" ;
: + DROP CR ." add 2 Nx16bit# of the data stack, result : Nx16bit#" ;
: - DROP CR ." substract 2 Nx16bit# of the data stack, result : Nx16bit#" ;
: K* ( Nx16bit#,k --- Nx16bit# ) DROP CR ." product of a VECTOR by a scalar k" ;
: S* ( 2 Nx16bit# --- k ) DROP CR ." k is the scalar product of 2 VECTORs" ;

VECTOR> VOCABULARY 3DVECTOR> ' 3DVECTOR> CLASS 3DVECTOR

3DVECTOR> DEFINITIONS

: NEW 3 NEW CR ." uses NEW of the parent class with size = 3" ;
: * ( 2 3x16bit# --- 3x16bit# ) CR ." vector product of two 3DVECTORs" ;
: M* ( 3 3x16bit# --- m ) CR ." mixed vector product of three 3DVECTORs" ;

END_FILE


1/ After loading this, you may create/instanciate new vectors, but decide first where (let it be in the FORTH stem) :
FORTH DEFINITIONS
2/ create a VECTOR :
VECTOR V1
3/ instanciate it executing its method NEW with its parameter size :
5 V1 NEW ( size 5 )

Do the same thing with a second vector :

VECTOR V2 2 V2 NEW ( size 2 )

When you want to be sure to create vectors with the same size :

1/ give some value to the variable SIZE :
6 SIZE!
2/ create a vector :
VECTOR 6V1
3/ retrieve the value of SIZE to intanciate it :
SIZE@ 6V1 NEW

Do the same thing with all the vectors of the same size that you want :

VECTOR 6V2 SIZE@ 6V2 NEW

Conversively, after having defined a child class with a given size (here, class 3DVECTOR) :

1/ decide first where (let it be in the 3DVECTOR> branch itself ; it could also be in its direct parent branch) :
3DVECTOR> DEFINITIONS
2/ create a 3DVECTOR :
3DVECTOR V3
3/ instanciate it (no need to give its size, NEW of 3DVECTOR sets it to 3)
V3 NEW

After instanciating all these vectors, you may freely use them with all their methods. As I am lazy, I did not actually implement any of them (apart NEW), instead they will just output messages telling what they should do. Frustrating, isn't it ?

Well, I do not intent to better this demo, I prefer to stay with pure FORTH "no syntax" rather than ape OOP.

When I want to code OOP, I prefer use better designed frameworks like Oberon2 or BlackBox/ComponentPascal.

BYE

POLKa
Last edited by polka on Sat May 29, 2021 9:43 pm, edited 1 time in total.


May the FORTH be with you !
POLKa
User avatar
mk79
Aurora
Posts: 983
Joined: Sun Feb 02, 2014 10:54 am
Location: Esslingen/Germany
Contact:

Re: Anyone for Object Oriented coding on the QL?

Postby mk79 » Thu May 27, 2021 2:04 pm

FORTH is definitely not my world. Still, interesting read, thanks, I almost understood some of it :-D


User avatar
polka
Trump Card
Posts: 168
Joined: Mon Mar 07, 2011 11:43 am

Re: Anyone for Object Oriented coding on the QL?

Postby polka » Wed Jun 02, 2021 10:33 am

Hi all, let me continue to try to convert you :

These are four words in FORTH
that make this langage worth


These four words are actually two pairs :

CREATE ... DOES>
and
VOCABULARY --- DEFINITIONS

With these four words, I tried to show some posts above how it would be easy to make FORTH look like an object oriented environment (and remember that FORTH was invented in the early seventies !).

I will show you next an example, where I use this very simple addition to FORTH to define a CLASS 3D for three dimensionnal vectors that could be readily used to code in an object oriented way the perspective algorithm that I showed you here :

https://qlforum.co.uk/viewtopic.php?f=3&t=3238&hilit=forth&start=10#p33721

Here, the complete code to LOAD_FILE with SupperForth (as SupperForth has some strange omissions, I had to first add three words) :

Code: Select all

CR .( Three words needed to complement SupperFORTH )

CR .(   mixed multiplication : two 16 bits operands 32 bits result )
: M* ( n1,n2 --- d ) 1 OVER 0< IF NEGATE SWAP NEGATE ELSE SWAP THEN >R
                       OVER 0< IF NEGATE SWAP NEGATE ELSE SWAP THEN R>
                       UM* ROT 0< IF DNEGATE THEN ;

CR .(   mixed division 32 bits divident 16 bits divisor 16 bits result )
: M/ ( d1,n2 --- n ) 1 OVER 0< IF NEGATE SWAP NEGATE ELSE SWAP THEN >R
                OVER 0< IF NEGATE ROT ROT DNEGATE ELSE ROT ROT THEN R>
                UM/MOD SWAP DROP SWAP 0< IF 1+ NEGATE THEN ;

CR .(   mixed square root : 32 bits operand 16 bits result )
: MSQRT ( d --- n,p | d = p*p + n ) 2DUP OR IF -32768 BEGIN
  DUP >R DUP M* 2OVER D- R@ UM/MOD SWAP DROP 2/ R> SWAP
  ?DUP WHILE - REPEAT 1- >R R@ R@ M* D- DROP R> THEN ;

CR .( Words to implement object oriented programming in FORTH )

: NEW ; ( NOOP word for NEW in FORTH context )

: A_CLASS , ;
: AN_INSTANCE @ , ;
: METHOD DUP @ EXECUTE ;

: INSTANCE CREATE AN_INSTANCE DOES> METHOD ;
: CLASS    CREATE A_CLASS   DOES> INSTANCE ;

CR .( Example CLASS of 3D vectors )
CR .(   3D> is the VOCABULARY of the METHODs )
CR .(   3D is the name of the CLASS )

VOCABULARY 3D> ' 3D> CLASS 3D

3D> DEFINITIONS

CR .( After creating these two words, let's implement the METHODs )
CR .(   first : NEW for intalling an INSTANCE - for 3D, just ALLOT 6 bytes )

: NEW 6 ALLOT DROP ;

CR .( some unary methods : ! and @ like for 16 bits scalars and X Y Z )

: ! ( x,y,z,V --- ) DUP >R 6 + ! R@ 4 + ! R> 2+ ! ;
: X ( V --- x ) 2+ @ ;
: Y ( V --- y ) 4 + @ ;
: Z ( V --- z ) 6 + @ ;
: @ ( V --- x,y,z ) 2+ DUP @ OVER 2+ @ ROT 4 + @ ;

CR .( some binary methods : )

CR .(   add two vectors : overloads scalar addition )
: + ( V,V --- V ) OVER >R @ 3 ROLL @ 3 ROLL + >R ROT + >R + R> R> R@ ! R> ;

CR .(   substract two vectors : overloads scalar substraction )
: - ( V,V --- V ) OVER >R @ 3 ROLL @ 3 ROLL - >R ROT - >R SWAP - R> R> R@ ! R> ;

CR .(   scaled scalar product of two vectors )
: // ( V,V,s --- scalar prpduct / s ) >R SWAP @ 3 ROLL @
  3 ROLL M* 2SWAP 4 ROLL M* ROT 5 ROLL M* D+ D+ R> M/ ;

CR .(   scaled vector product of two vectors : overloads */ for scalars )
: */ ( V,V,s --- vector product / s ) 2 PICK >R >R SWAP @ 3 ROLL @
  4 PICK OVER M* 3 PICK 6 PICK M* D- R@ M/
  4 ROLL 4 PICK M* 3 ROLL 7 PICK M* D- R@ M/
  5 ROLL 3 ROLL M* 4 ROLL 5 ROLL M* D- R> M/ R@ ! R> ;

CR .( modulus of a vector )
: || @ DUP M* ROT DUP M* D+ ROT DUP M* D+ MSQRT SWAP DROP ;

CR END_FILE


So, let's use this new tool :

to define an instance of class 3D, type

3D V1

and to initialise its memory space

V1 NEW

then, to put three 16 bits numbers into it :

3000 4000 0 V1 !

to instanciate another 3D you may type all this in the same sentence

3D V2 V2 NEW 0 0 1000 V2 !

You see in the code listing that you can
- add two 3D ; the result is a 3D that replaces the first one (like when you add with FORTH two numbers ; the result takes the place in the stack of the first one).
- substract two 3D ; same punishment as for +
- do the scalar product of two 3D : the result is a 16 bit number
- do the vector product of two 3D : the result is a 3D
BUT these two words adopt the same semantics as the FORTH */ word : that mutliplies two 16bit numbers but divive the 32bit result by a 16bit scale factor to get a result not overflowing.
- finally computing the modulus of a 3D, which is a 16bit positive number.

So let's play with the two instances V1 and V2 that we created :

V1 and V2 are orthogonal, so their scalar product // should be 0 ; but note the mandatory scale factor (to choose for the product not to overflow) !

V1 V2 1000 // .
0 ok

the vector product of a 3D by itself (or by a parallel 3D) is a null 3D ; the scale factor is also mandatory !

V2 V2 1000 */ @ . . .
0 0 0 ok

the two X and Y components of V1 draw a famous Pythagorean triangle, thus its modulus should be the lenght of its hypothenuse :

V1 || .
5000 ok

As you can notice, the object oriented syntax of FORTH is not quite the usual.

Usually you will code :

V1.ADD(V2) [ <instance>.<method>(<parameters>) ]

In object oriented FORTH you type :

V1 V2 + [ <instance> <parmeters> <method> ]

No need of a dot and no parentheses ; the + method has the same syntax as with numbers.

To be followed be recoding PERSPECTIVE FORTH object oriented wise ?

BYE, POLKA

and to compare with object oriented Free Pascal examples above ? :D
Last edited by polka on Sun Jun 06, 2021 1:10 pm, edited 1 time in total.


May the FORTH be with you !
POLKa
Derek_Stewart
Font of All Knowledge
Posts: 2354
Joined: Mon Dec 20, 2010 11:40 am
Location: Runcorn, Cheshire, UK

Re: Anyone for Object Oriented coding on the QL?

Postby Derek_Stewart » Thu Jun 03, 2021 2:08 pm

Hi,

I find this interesting, OOF is something I have just learned about.

I like to use SupperForth on tbe QL, gforth on Linux/Android, but which is the best Forth to use?


Regards,

Derek
User avatar
polka
Trump Card
Posts: 168
Joined: Mon Mar 07, 2011 11:43 am

Re: Anyone for Object Oriented coding on the QL?

Postby polka » Sun Jun 06, 2021 5:51 am

Hi all,

Here, my last version of Object Oriented Programming in FORTH with a functionnal demo CLASS named 3D :

Code: Select all

CR .( Three words needed to complement SupperFORTH )

CR .(   mixed multiplication : two 16 bits operands 32 bits result )
: M* ( n1,n2 --- d ) 1 OVER 0< IF NEGATE SWAP NEGATE ELSE SWAP THEN >R
                       OVER 0< IF NEGATE SWAP NEGATE ELSE SWAP THEN R>
                       UM* ROT 0< IF DNEGATE THEN ;

CR .(   mixed division 32 bits divident 16 bits divisor 16 bits result )
: M/ ( d1,n2 --- n ) 1 OVER 0< IF NEGATE SWAP NEGATE ELSE SWAP THEN >R
                OVER 0< IF NEGATE ROT ROT DNEGATE ELSE ROT ROT THEN R>
                UM/MOD SWAP DROP SWAP 0< IF 1+ NEGATE THEN ;

CR .(   mixed square root : 32 bits operand 16 bits result )
: MSQRT ( d --- n,p | d = p*p + n ) 2DUP OR IF -32768 BEGIN
  DUP >R DUP M* 2OVER D- R@ UM/MOD SWAP DROP 2/ R> SWAP
  ?DUP WHILE - REPEAT 1- >R R@ R@ M* D- DROP R> THEN ;

CR .( Words to implement object oriented programming in FORTH )
: NEW ; ( NOOP for NEW in FORTH context )
: A_CLASS , ;
: AN_INSTANCE @ , ;
: METHOD DUP @ EXECUTE ;

: INSTANCE CREATE AN_INSTANCE DOES> METHOD ;
: CLASS    CREATE A_CLASS   DOES> INSTANCE ;

CR .( Example CLASS of N.Dimensions vectors )
CR .(   ND> is the VOCABULARY of the METHODs )
CR .(   ND is the name of the CLASS )

VOCABULARY ND> ' ND> CLASS ND

ND> DEFINITIONS

VARIABLE SIZE
: SIZE! ( size --- ) SIZE ! ;
: SIZE@ ( --- size ) SIZE @ ;
VARIABLE SAME
: SAME? ( size --- ) DUP SIZE @ = SAME ! SIZE! ;

: NEW ( size --- ) DUP SIZE! DUP , 2* ALLOT DROP ;

CR .( Example CLASS of 3D vectors )
CR .(   3D> is the VOCABULARY of the METHODs )
CR .(   3D is the name of the CLASS )

ND> VOCABULARY 3D> ' 3D> CLASS 3D

3D> DEFINITIONS

CR .( After creating these two words, let's implement the METHODs )
CR .(   first : NEW for intalling an INSTANCE - for 3D, ND> NEW size = 3  )
: NEW 3 NEW ;

CR .( some unary methods : ! and @ like for 16 bits scalars and X Y Z )
: ! ( x,y,z,V --- ) DUP >R 8 + ! R@ 6 + ! R> 4 + ! ;
: X ( V --- x ) 4 + @ ;
: Y ( V --- y ) 6 + @ ;
: Z ( V --- z ) 8 + @ ;
: @ ( V --- x,y,z ) 4 + DUP @ OVER 2+ @ ROT 4 + @ ;

CR .( some binary methods : )
CR .(   add two vectors : overloads scalar addition )
: + ( V,V --- V ) OVER >R @ 3 ROLL @ 3 ROLL + >R ROT + >R + R> R> R@ ! R> ;
CR .(   substract two vectors : overloads scalar substraction )
: - ( V,V --- V ) OVER >R @ 3 ROLL @ 3 ROLL - >R ROT - >R SWAP - R> R> R@ ! R> ;
CR .(   scaled scalar product of two vectors )
: // ( V,V,s --- scalar prpduct / s ) >R SWAP @ 3 ROLL @
  3 ROLL M* 2SWAP 4 ROLL M* ROT 5 ROLL M* D+ D+ R> M/ ;
CR .(   scaled vector product of two vectors : overloads */ for scalars )
: */ ( V,V,s --- vector product / s ) 2 PICK >R >R SWAP @ 3 ROLL @
  4 PICK OVER M* 3 PICK 6 PICK M* D- R@ M/
  4 ROLL 4 PICK M* 3 ROLL 7 PICK M* D- R@ M/
  5 ROLL 3 ROLL M* 4 ROLL 5 ROLL M* D- R> M/ R@ ! R> ;

CR .( modulus of a vector )
: || ( V --- m ) @ DUP M* ROT DUP M* D+ ROT DUP M* D+ MSQRT SWAP DROP ;

CR END_FILE

It works exactly like my fisrt version (two posts above), but the class 3D is defined as a "child" of class ND, that implement "n dimensionnal" vectors.
However, for ND class I implemented only the mandatory NEW method, to show how the NEW method of thé 3D class could reuse the inherited method of its parent class.

To Derek : all the classic FORTH virtual machines were first implemented on 16bits computer in a 64Kb memory segment.
My first experience of FORTH was on a HP 2100 computer around 1980. I coded on that machine in FORTRAN (for my work), but noticed that a collegue had bought an Algol compiler (on paper tape) but he told me that he never had the time to use it, so I tried it for a while. But then, I learned about the existence of a LISP and a FORTH interpreter, and by curiosity, I bought also these "paper tapes" just to play. I did not like LISP at all because of the parentheses, but I got hooked by FORTH because I already had a HP67 calculator using RPN.
So, when I got a ZX81 for home computing (which tokenized BASIC pleased me very much), I also bought a FORTH for this little machine.
And when I got my first QL, I luckily bought Computer One FORTH (which was then the only one on sale - and today, unfortunately, no longer possible).
But I bought also SuperFORTH, to try, and by comparison with C.O. FORTH, was rather disapointed : it worked all right, but you had much less control of what you are doing. You say you like programming with SupperForth, but I wonder : did you really write large and complex code with it - IMO it's very unpractical.

On the QL you have also a couple of other FORTH, but I did not try them (I will maybe one day)

On my first PC (386 processor, 1Mb memory, 640x480 VGA screen), I used TurboFORTH under DOS : developped by a french FORTH enthusiast, who also animated a FORTH user group called "Jedi", that I took part. For the more modern PCs, they have 32bit FORTH for Windows that are famous, but that I did not use them seriously (only tried a little) and with Unix (Linux on a Pi), for the moment, I did not install FORTH. At this time I mostly play with FORTH on my BBQL and on a PiZero with uQLx.

BYE ! Paul
Last edited by polka on Sun Jun 06, 2021 12:29 pm, edited 1 time in total.


May the FORTH be with you !
POLKa
Derek_Stewart
Font of All Knowledge
Posts: 2354
Joined: Mon Dec 20, 2010 11:40 am
Location: Runcorn, Cheshire, UK

Re: Anyone for Object Oriented coding on the QL?

Postby Derek_Stewart » Sun Jun 06, 2021 9:37 am

Hi Paul,

I will give your OOP(OOF) example a try.

I like to programme in Forth, that does not mean I am any good at it, but I like to try.

I mainly use Linux computer with emulators for QL, the main use is gforth in Linux, but there does seem to be differences in the way gforth works and other books by Leo Brodie describe the use of Forth,

Solo Forth on the ZX Spectrum is also nice to use.


Regards,

Derek
User avatar
polka
Trump Card
Posts: 168
Joined: Mon Mar 07, 2011 11:43 am

Re: Anyone for Object Oriented coding on the QL?

Postby polka » Sun Jun 06, 2021 1:00 pm

Hi Derek,
I just found a bug in the last version of my code : I corrected it !
The method @ of 3D> must be defined after the methods X Y Z not before, because otherwise the methods X Y Z do not use @ of the FORTH stem but @ of the 3D> vocabulary ( the @ that was defined just before ! ).
There are also other subtelties : you have always to watch in what CONTEXT you search for words and the CURRENT vocabulary where you want to create instances.
For instance, if you want to create 3Ds in the FORTH stem, you have to say
FORTH DEFINITIONS
but as the 3D class was defined as a child of ND, so that all methods of ND could be inherited by 3D, you must switch to context ND> by saying ND> before you can create 3Ds
So, in summary :

LOAD_FILE <my code>
FORTH DEFINITIONS ( to create a 3D in the FORTH STEM )
ND> ( to move the CONTEXT to where the class 3D was defined )
3D V1
V1 NEW ( invocation of V1 makes the context be 3D>, so it's method NEW of 3D> that is executed )
3000 4000 0 V1 ! ( here too, it's method ! of 3D> that is executed )

And similarly use all the methods of 3D> : the vocabulary 3D> becomes automatically the CONTEXT every time you name a 3D even if you created it in the FORTH stem or in another vocabulary chosen as CURRENT with the word DEFINITIONS.

try

V1 X .
V1 Y .
V1 Z .
V1 @ . . .
V1 DUP + @ . . .

etc.

Without subclasses and inheritance, things are simpler, these should be used only when necessary, or else be prepared for "FUN" !

BYE ! Paul


May the FORTH be with you !
POLKa

Who is online

Users browsing this forum: No registered users and 6 guests