Bistro Methods

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"
naturalMethod: argument
[ "..."
"A sample primitive method"
primitiveMethod: argument
{ //...

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
Smalltalk Java™
receiver & arg
receiver | arg
receiver @ arg
receiver , arg
receiver.$and( arg )
receiver.$or( arg )
receiver.$at( arg )
receiver.$append( arg )
receiver + arg
receiver - arg
receiver * arg
receiver % arg
receiver / arg
receiver // arg
receiver \ arg
receiver \\ arg
receiver.$plus( arg )
receiver.$minus( arg )
receiver.$times( arg )
receiver.$modulus( arg )
receiver.$dividedBy( arg )
receiver.$idiv( arg )
receiver.$into( arg )
receiver.$imod( arg )
receiver = arg
receiver ~= arg
receiver == arg
receiver ~~ arg
receiver < arg
receiver <= arg
receiver > arg
receiver >= arg
receiver.$equal( arg )
receiver.$notEqual( arg )
receiver.$is( arg )
receiver.$isnt( arg )
receiver.$lessThan( arg )
receiver.$lessEqual( arg )
receiver.$moreThan( arg )
receiver.$moreEqual( arg )
receiver unary
receiver binary: arg
receiver ternary: arg1 : arg2
receiver keyword: arg1 keyword: arg2
receiver.unary( )
receiver.binary( arg )
receiver.ternary( arg1, arg2 )
receiver.keyword_keyword( arg1, arg2 )

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.