|
| """
This is a doc string for the whole module.
"""
class Person
"""
This is a class declaration.
"""
var _name as String # declare a class variable. every instance of Person will have a name
def init(name as String)
_name = name
def sayHello
# This is a method
# In strings, anything in brackets ([]) is evaluated as an expression,
# converted to a string and substituted into the string:
print 'Hello. My name is [_name].'
def add(i as int, j as int) as int
"""
Adds the two arguments and returns their sum.
"""
return i + j
class Program
def main is shared
# Create an instance
p = Person('Bob')
# Invoke a method
p.sayHello
# Invoke a method with arguments
print p.add(2, 2)
# Assert the truth of something
assert p.add(2, 2)==4 |