The Cobra Programming Language
How To
Print Hello World
Print Hello World.co
Write Basic Syntax
Use Properties
Make An If Else Ladder
Make A Branch Statement
Declare Inits
Use Arrays
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
WPF
GTK
Access MySQL
"""
You can refer to a method, rather than invoking it,
by using the "ref" keyword before it.

Invoking a method is far more popular than referencing/passing a method. So
invocation is the syntactically clean case (obj.toString.trim) and method
reference the verbose case (ref obj.someMethod). Also, the use of "ref"
immediately clues you in to what's going on as you read code left-to-right.

See the lines below marked with:   # <---
"""


class Customer

    cue init(name as String, totalSpent as decimal)
        _name = name
        _totalSpent = totalSpent

    get name from var as String

    get totalSpent from var as decimal

    def toString as String is override
        # example: Snake Charmers LLC: $5,000.00
        return '[.name]: [.totalSpent:C]'


class Example

    def main is shared

        customers = [
            Customer('Yin Yang Inc.', 10_000.00),
            Customer('Acme Inc.', 100_000.00),
            Customer('Snake Charmers LLC', 5_000.00),
        ]

        print 'Ordered by name:'
        customers.sort(ref .orderByName)  # <---
        for cust in customers, print cust

        print
        print 'Ordered by total spent:'
        customers.sort(ref .orderByTotalSpent)  # <---
        for cust in customers, print cust

        # Yes, there will be lambdas in a future version so
        # the comparison can be inlined in the sort() call.

    def orderByName(a as Customer, b as Customer) as int is shared
        return a.name.toLower.compareTo(b.name.toLower)

    def orderByTotalSpent(a as Customer, b as Customer) as int is shared
        return a.totalSpent.compareTo(b.totalSpent)