Example from Beta

Here is an example from Beta. Personally, I tend to find the Beta syntax rather unintelligible, so let me walk you through this slowly and carefully. The idea is to write a series of functions that will print html anchors. The first function is called printAnchor, and it simply prints the begining part of an anchor, then calls INNER, and then prints the end. The arrow leading to the right is the syntax for ``pass and argument to'' and in this case the argument is being passed to the function puttext.

The next function is named printOSUAnchor, and this function inherits from printAnchor. (functions can inherit, just like classes, in Beta). Because it is inheriting, when it executes the parent will first be performed, and when the parent executes the inner statement, then the body of this function will be performed. It simply adds my departmental URL to the address, and once more executes inner.

The third function inherits again from OSUAnchor. This time when it gets executed, its grandparent function (two levels up) will be executed, then the parent function, and finally this function.

Beta even allows you to put the code for the inner statement in something that looks like an argument list. This is shown at the bottom of the slide. This is very close to the idea of an anonymous class in Java.

[audio] 16a [real] 16a Text to accompany slide 16a, in Chapter 11 of An Introduction to Object-Oriented Programming