Skip to content

Instantly share code, notes, and snippets.

@deathbeam
Last active May 23, 2016 09:47
Show Gist options
  • Save deathbeam/d42bb788f5d8f80e2548 to your computer and use it in GitHub Desktop.
Save deathbeam/d42bb788f5d8f80e2548 to your computer and use it in GitHub Desktop.
# Pythonic module system
from Sys import print
# Annotations and generic types
\:generic
class MyValue<T>
# Fat arrow closures means no implicit return
new = (value : T) =>
@value = value
# Interfaces with default implementation
interface Greeter
# Thin arrow closures means return
greet = (name : MyValue<String>) : Void ->
print "Hello #name"
# Classes and OOP
class Person implements Greeter
new = (name) ->
@name = name
# Cool naming with support for - as delimiter
greet-self = ->
greet name
# Top-level expressions
name = MyValue<String>("Alice")
# Creating of objects
alice = Person(name)
# Dynamic methods, closures
alice.greet = (name) ->
print "#name is awesome"
# Calling of methods
# We will use ! operator, what is replacement for ()
alice.greet-self!
# Above will output "Alice is awesome" to console
# vim: set ft=coffee:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment