-
Notifications
You must be signed in to change notification settings - Fork 0
/
CLASSES-CRUDE.4TH
44 lines (40 loc) · 1.01 KB
/
CLASSES-CRUDE.4TH
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
( primitive "classes" )
( APX Forth, Atari 8 bit )
( BartGo 2024 )
( TODO: CAN WE MANAGE OTHER TYPES - FLOATS, STRINGS? )
( TODO: CAN WE MAKE THESE "CLASSES" NON-STATIC? )
( TODO: INHERITING SHOULD BE POSSIBLE, CHECK )
( TODO: INSTEAD OF ' XYZ SCAL VOC FOR THE LAST CLASS )
: CLASS <BUILDS HERE , DOES> ; : OF 2 * 4 + + ;
: CID 2+ @ ; : U? @ U. ;
CLASS SHOP
9999 , ( 0 : # apples )
9999 , ( 1 : price )
9999 , ( 2 : # oranges )
9999 , ( 3 : price )
9999 , ( 4 : value )
: SHOP/INIT ( -- )
10 ' SHOP 0 OF !
200 ' SHOP 1 OF !
5 ' SHOP 2 OF !
500 ' SHOP 3 OF !
0 ' SHOP 4 OF ! ;
: SHOP/CALC ( -- )
' SHOP 0 OF @
' SHOP 1 OF @ *
' SHOP 2 OF @
' SHOP 3 OF @ * +
' SHOP 4 OF ! ;
: SHOP/SHOW ( -- )
CR
' SHOP 0 OF U? ." apples for "
' SHOP 1 OF U? ." cents each " CR
' SHOP 2 OF U? ." oranges for "
' SHOP 3 OF U? ." cents each " CR
' SHOP 4 OF U? ." total" CR ;
: SHOP/CID ' SHOP CID ;
SHOP/SHOW
SHOP/INIT
SHOP/SHOW
SHOP/CALC
SHOP/SHOW