The syntax for Smalltalk methods and blocks are very similar. Both contain a series of statements. The primary difference is that blocks are delimited with square brackets [ ], while Smalltalk methods are not. In order to support a declarative language model and normalize the syntax, Bistro uses square brackets as scope delimiters. Thus, the declaration of Bistro classes, types, methods, and blocks are all delimited with square brackets.
In Bistro, natural methods are similar to those of Smalltalk. However, Bistro also supports primitive methods written with Java. Both kinds of methods use signatures similar to those found in Smalltalk. The following code fragments illustrate these distinctions.
"A sample natural method"
"A sample primitive method"
The Bistro compiler translates quoted class and method comments into Java class and method comments. So, the javadoc utility can be used to generate HTML documentation from the resulting Java source files.
To achieve seamless integration between Bistro and Java, their methods must be interoperable. Bistro code must be able to invoke methods in existing Java classes, and Java code must be able to invoke methods in Bistro classes. To achieve method interoperability, the Bistro compiler renames methods using some conventions. Special consideration must be given to both binary operators and keyword selectors.
Bistro supports the standard binary operators provided by Smalltalk. These are renamed using the conventions shown in Table 4. The Bistro compiler includes a prefix ($) in the translated method name to prevent confusion with existing Java protocols. Table 4 also shows the renaming conventions for Smalltalk keyword selectors. The colon in each keyword is replaced by an underscore. The final colon(s) (if any) is dropped. Bistro also supports the use of colons as argument separators, serving as anonymous keywords like those found in block signatures. These are dropped during translation, which allows Bistro to support the definition and invocation of Java methods that take more than one argument (see the ternary: example in Table 4).
|Table 4. Method Renaming Conventions|
Java is a trademark of Sun Microsystems, Inc.
Permission is granted to copy this document provided this
copyright statement is retained in all copies.
Copyright 1999-2001 Nikolas S. Boyd.