RosettaCodeData/Task/Break-OO-privacy/Forth/break-oo-privacy.fth
2016-12-05 22:15:40 +01:00

17 lines
412 B
Forth

include FMS-SI.f
99 value x \ create a global variable named x
:class foo
ivar x \ this x is private to the class foo
:m init: 10 x ! ;m \ constructor
:m print x ? ;m
;class
foo f1 \ instantiate a foo object
f1 print \ 10 access the private x with the print message
x . \ 99 x is a globally scoped name
50 .. f1.x ! \ use the dot parser to access the private x without a message
f1 print \ 50