Boo Keywords
Index
abstract
and
as
AST
break
callable
cast
char
class
constructor
continue
def
destructor
do
elif
else
ensure
enum
event
except
failure
final
from
for
false
get
given
goto
if
import
in
interface
internal
is
isa
not
null
of
or
otherwise
override
namespace
partial
pass
public
protected
private
raise
ref
retry
return
self
set
super
static
struct
success
transient
true
try
typeof
unless
virtual
when
while
yield
Keywords
abstract
"abstract" is used to designate a class as a base class. A derivative of the abstract class must implement all of its abstract methods and properties.
AST
"AST" is used to create AST objects for use with the Boo compiler.
h4: Examples
/* Usage: result = ast: /* code block * */
break
"break" is a keyword used to escape program execution. Typically break is used inside a loop and may be coupled with the "if" or "unless" keywords.
char
"char" is a data type representing a single character. The char data type is distinct from a string containing a single character. char('t') refers to a System.Char type, whereas "t" or 't' is a System.String.
constructor
"constructor" is a method belonging to a class that is used to define how an instance of the class should be created. The constructor may include input parameters and may be overloaded.
continue
"continue" is a keyword used to resume program execution at the end of the current loop.
The continue keyword is used when looping. It will cause the position of the code to return to the start of the loop (as long as the condition still holds).
destructor
"destructor" is used to destroy objects. Destructors are necessary to release memory used by non-managed resources in the .NET CLI. Desctructors should never be called explicitly. They can be invoked by implementing the IDisposable() interface.
do
"do" is synonymous with 'def' for closures. However, "do" reads as an imperative and therefore should be used in an active sense.
elif
"elif" is similar the same as the "if" conditional statement in form, except that it needs to be preceded by an if statement or another elif statement and that it is only evaluated (checked) if the if/elif statement preceding it evaulates to false.
If one of the preceding if/elifs statements evaluates to true, the rest of the elifs will not be evaluated, thus sparing extra CPU power from a pointless task.
ensure
"ensure" is user with the "try" and "except" keywords to guarantee a certain block of code runs whether the try/except block is sucessful or not. "ensure" is often used to add some post executions o an exceptionevent.
Examples
import System class Dog: [Property (Name)] _name as string def constructor(): Name = 'Fido' def Bark(): print "woof woof" ### The name will match so we will bark once. The ensure keyword reminds us to place the dog in the pen and wait for keyboard input to continue. try: fido = Dog() if fido.Name == 'Fido': fido.Bark() else: fido.Bark() fido.Bark() raise "throw an exception" except e: print("The dog barks too much. error: " + e) ensure: print("Always put the dog back in the pen.") Console.ReadLine() ### The name does not match we bark twice and report an exception. Again, the ensure statement executes and reminds us to place the dog back into the pen. try: fido = Dog() if fido.Name == 'fluffy': fido.Bark() else: fido.Bark() fido.Bark() raise "throw an exception" except e: print("The dog barks too much. error: " + e) ensure: print("Always put the dog back in the pen.") Console.ReadLine()
enum
"enum" is used to create a list of static values. Internally the names values are assigned to an Int32 value.
except
"except" is keyword use to identify a block of code that is to be executed if the "try" block fails.
final
"final" is a keyword used to identify a class that cannot have subclasses. final may also be used to declare a field as a constant.
from
"from" is used with the "import" keyword to identify the assembly being imported from. Form usage is "import TARGET (from ASSEMBLY). The "from" keyword is optional.
for
"for" is used to loop through items in a series. "for" loops are frequently used with a range or a listarray.
get
"get" is used to identify a field that is exposed for external access. Use "get" to make a field available as read-only. Use "set" to add write access. "get" is suffixed by a colon when implemented and includes a return statement. See example 1.
"get" is also used when defining an interface to define which fields should be implemented as accessible. When "get" is used to define an interface the colon and return statements are excluded. See example 2.
given
"given" is used as the entry to a "given ... when" loop. "given" identifies a state. A series of "when" statements may be executed based on the identified state. _ The "given" keyword is currently not implemented. _
goto
"goto" exits a line of code and moves to a named line in the code. The named line must be prefixed wtih a colon. Good programming practice eschews the use of "goto"
The example below names two lines ":start" and "test". They are referenced in the code by separate goto statements. This example produces an endless loop. The "ensure" statement includes a Console.Readline() that prevents the loop from continuing without user input.
if
"if" is a conditional statement, followed by a statement that either evaluates to true or false. In block form, the code within the block is executed only if the expression following the if statement evaluates to true.
The if statement can be used to selectively execute a line of code by placing "if <expression>" at the very end of the statement. This form of the if conditional is useful in circumstances when you are only going to perform one operation based entirely on an expression: this makes the code cleaner to read than an unnecessary if block.
import
"import" is used to include a namespace from other assemblies within your program. If the assembly is not automatically included the "from" keyword must be included to identify the respective assembly.
in
"in" is used in conjunction with "for" to iterate through items in a list. "in" may also be used to test items in a set.
interface
"inteface" is used to define the fields and methods that may be implemented by a class. The implementation is never performed by the interface. Interfaces allow you to establish an API that is the basis for other classes.
internal
"internal" is a keyword that precedes a class definition to limit the class to the assembly in which it is found.
is
"is" is an equvalence operator keyword that is used to test a value. "is" may not be used with ints, doubles, or boolean types. "is" is commonly used to test for null.
not
"not" is used with "is" to perform a negative comparison. "not" can also be used in logical expressions.
or
"or" is a logical operator that is applied to test if either of two boolean expressions are true.
otherwise
"otherwise" is part of the conditional phrase "given ... when ... otherwise". The otherwise block is executed for a given state if none of the when conditions match. _ The otherwise keyword is not yet implemented _
override
"override" is used in a derived class declare a method is being inherited especially when the derived implementation will differ from the parent. "override" may only be used on methods that are defined as "virtual" or "abstract" in the parent class.
namespace
"namespace" is a name that uniquely identifies a set of objects so there is no ambiguity when objects from different sources are used together. To declare a namespace place the namespace followed by the name you choose at the top of the file.
public
"public" is used to define a class as available to all. "public" is never required because a defined class defaults to public.
protected
"protected" is a keyword used to declare a class, method, or field visible within only its containing class. Prefixing a field name with an underscore automatically declares it as private and is recommended practice.
private
"private" is keyword used to declare a class, method, or field visible within only its containing class and inherited classes..
ref
"ref" makes a parameter be passed by reference instead of by value. This allows you to change a variable's value outside of the context where it is being used
self
"self" is used to reference the current class. "self" is not required for boo buy may be used to add clarity to the code. "self" is synonymous with the c# keyword "this".
struct
"struct" is short for structure. A structure is similar to a class except it a definition of value types rather than reference types.
Refer to the Boo Primer for more information on structures.
super
"super" is used to reference a base class from a child class when one wants to exectue the base behavior.
transient
"transient" transient marks a member as not to be serialized. By default, all members in Boo are serializable.
try
"try" is used with the "ensure" and "except" keywords to guarantee o test whether a block of code executes without error or not.
unless
"unless" is similar to the "if" statement, except that it does not execute a block of code unless the expression is false.
virtual
"virtual" is a keyword that may precede the 'def' keyword when the developer wishes to provide the ability to override a defined method in a child class. The 'virtual' keyword is used in the paren class.
when
"when" is used with the "given" keyword to identify the condition in a which the "given" value may be executed. _b "when" is currently not implemented.
while
"while" will execute a block of code as long as the expression it evaluates is true.
It is useful in cases where a variable must constantly be evalulated (in another thread, perhaps) , such as checking to make sure a socket still has a connection before emptying a buffer (filled by another thread, perhaps).


