5 - Forth Interest Group
5 - Forth Interest Group
5 - Forth Interest Group
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
instance variables can re-<br />
solve their addresses by cal-<br />
culating offsets from the<br />
object address on the<br />
ostack.)<br />
Late binding is also re-<br />
ferred to as deferred bind-<br />
ing. In simple terms, it means<br />
the system doesn't know<br />
what object you're going to<br />
send a message to. Hence,<br />
the system can't bind the<br />
message to an execution<br />
address at compile time.<br />
Here's an example of<br />
PCYerk's late binding:<br />
get: { integerobj @ )<br />
Here, I'm assuming that<br />
the variable integerob j<br />
holds an object's address. At<br />
compile time, there's no way<br />
the system can know what<br />
objedwillbe in integerob j<br />
when the program executes.<br />
The system must, therefore,<br />
determine the execution ad-<br />
dress of get : at run time.<br />
The words to handle late<br />
binding are { and 1. (Yerk<br />
used [ and I, but those words<br />
were already taken in UD<br />
<strong>Forth</strong>) The curly brackets<br />
should immediately follow<br />
the message, and may en-<br />
close any <strong>Forth</strong> expression<br />
that yields an object's ad-<br />
dress.<br />
Of course, late binding<br />
yields code that runs more<br />
slowly than code using early<br />
binding. This is because late<br />
binding defers until run time<br />
processing that would have<br />
been performed at compile<br />
time.<br />
Late binding lets you-<br />
with only minor additional<br />
programmin~ypass one<br />
of PCYerk's deficiencies:<br />
namely, that you define all<br />
instance variables using the<br />
ivar word. You cannot use<br />
an object as an instance vari-<br />
able. Suppose you've defined<br />
a class called ldarray that<br />
lets you build one-dimen-<br />
sional array objects, and a<br />
class called polygon that<br />
builds polygon objects. It<br />
would be nice to have a<br />
ldarray object as one of<br />
the instance variables of the<br />
Figure One. Class header structure. I<br />
Tokens Variable<br />
Segment Segment<br />
Listing Three. Building a headerless object. I<br />
:class polygon