The Cobra Programming Language
How To
Print Hello World
Write Basic Syntax
Use Properties
Make An If Else Ladder
Make A Branch Statement
Declare Inits
Make A Class Hierarchy
Use Nil And Nilable Types
Use Dynamic Typing
Declare Variable Number Of Args
Read And Write Files
Check Inheritance And Implementation
Pass References To Methods
Translate Pseudo Code To Cobra1
Translate Pseudo Code To Cobra2
Implement IEnumerable1
Implement IEnumerable2
Iterate Through Recursive Data With Yield
Make A Collection Class
Declare Contracts
Threads
Win Forms
GTK
Access MySQL
""" CheckInheritanceAndImplementation.cobra To check if a value inherits a particular class, use the `inherits` operator which gives a boolean value (true or false): isACar = vehicle inherits Car To check if a value implements a particular interface, use the `implements` operator: isComparable = x implements IComparable If you use these in an `if` statement with a variable, you can treat the variable as the given class or interface with no explicit typecasting: if vehicle inherits Car vehicle.drive carCrusher.crush(vehicle) else if vehicle inherits Plane vehicle.fly airplaneGraveyard.take(vehicle) Of course, it would be nice if Car and Plane were derived from a common Vehicle class with an `operate` method, but sometimes you don't have control over the class hierarchy you are working with. """ class BankAccount var _balance as decimal def deposit(x as Object) if x inherits Money _balance += x.amount else if x inherits decimal _balance += x else if x inherits int _balance += x else throw FallThroughException(x) # ^ In a way this is a bad example. Since we have control over the code, # providing method overloads of `deposit` would make the BankAccount interface # more clear and the program run faster. def deposit2(x) # dynamic typed arg if x inherits Money _balance += x.amount else _balance = _balance + x # woops, += isn't implemented for dynamic yet get balance from var class Money var _amount as decimal def init(amount as decimal) _amount = amount get amount from var class Program def main is shared ba = BankAccount() ba.deposit(10) ba.deposit(Money(10)) assert ba.balance == 20