Something went wrong. Try again.
The Mesa programming language
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354type Task(name, priority) def copy self endend
#> Task(name: "laundry", priority: 2)$print(Task("laundry", 2))#> laundry$print(Task("laundry", 2).name)#> Task(name: "laundry", priority: 2)$print(Task("laundry", 2).copy)
copy := &Task("laundry", 2).copy#> Task(name: "laundry", priority: 2)$print(copy())
type Amount(cents) def self.of_dollars(n) Amount(n * 100) end
def self.zero self(0) end
def display self.cents endend
#> Amount(cents: 500)$print(Amount.of_dollars(5))#> Amount(cents: 0)$print(Amount.zero)#> 0$print(Amount.zero.display)
type Rect(w, h) area := w * h half_area := area / 2end
r := Rect(4, 6)#> Rect(w: 4, h: 6, area: 24, half_area: 12)$print(r)#> 24$print(r.area)#> 12$print(r.half_area)
type Counter(start) count := startend
c := Counter(5)c.count := c.count + 1#> 6$print(c.count)
type LinkedList type Node(data, next) def display self.data end end
def self.new_node LinkedList.Node(0, nil) endend
node := LinkedList.Node(3, nil)#> 3$print(node.data)#> 3$print(node.display)#> 0$print(LinkedList.new_node.data)
type Group type Task(priority) type Tag(label) end endend
tag := Group.Task.Tag("x")#> x$print(tag.label)
#> LinkedList.Node(data: 0, next: nil)$print(LinkedList.Node(0, nil))#> Group.Task.Tag(label: "x")$print(tag)
#---
#! runtime error: type Stack is not hashable
type Stack(top) items := [1, 2] count := 0end
{}[Stack(3)]
#---
#! runtime error: type Task has no such member 'unknown'
type Task(priority)end$print(Task(1).unknown)
#---
#! runtime error: member 'status' on type Task is read-only
type Task(priority) def status "queued" endend
t := Task(1)t.status := "done"
#---
#! runtime error: member 'status' on type Task is read-only
type Task(priority) def status "queued" end
def close status := "done" endend
Task(1).close
#---
#! runtime error: type Char cannot be constructed
Char()
#---
#! semantic error: type 'Task' declares member 'priority' more than once
type Task priority := 0 priority := 1end
#---
#! semantic error: type 'Task' declares member 'priority' more than once
type Task priority := 0
def priority 1 endend
#---
#! semantic error: type 'Task' declares member 'priority' more than once
type Task(priority) priority := 0end
#---
#! semantic error: type 'Task' declares member 'priority' more than once
type Task(priority) def priority 1 endend
#---
#! semantic error: type 'Task' declares member 'close' more than once
type Task def close 1 end
def close 2 endend
#---
#! semantic error: type 'Task' declares member 'urgent' more than once
type Task def self.urgent 1 end
def self.urgent 2 endend
#---
#! semantic error: type 'Transaction' declares member 'Void' more than once
type Transaction case Void end
case Void endend
#---
#! semantic error: type 'Transaction' declares member 'Void' more than once
type Transaction case Void end
type Void endend
#---
#! semantic error: duplicate param 'priority'
type Task(priority, priority)end
#---
#! semantic error: duplicate param 'priority'
type Task def close(priority, priority) endend
#---
#! semantic error: duplicate param 'priority'
type Task def self.at(priority, priority) endend
#---
#> 1#> 2
# An instance member and a static are separate namespaces, so one name can# serve both.type Task def priority 1 end
def self.priority 2 endend
$print(Task().priority)$print(Task.priority)
#---
#> Task(name: "laundry", priority: 2)#> a group#> a group
type Task(name, priority)end
type Group(items) def inspect "a group" endend
$print(Task("laundry", 2).inspect)$print(Group([1, 2]))$print(Group([1, 2]).inspect)
#---
import Core.Behaviors.Display
type Group(items) impl Display
def display "a group" endend
#> a group$print(Group([1, 2]))#> Group(items: [1, 2])$print(Group([1, 2]).inspect)
#---
type Task(name) def inspect "task" endend
type Group(tasks)end
#> task$print(Task("a"))#> [task, task]$print([Task("a"), Task("b")])#> {"task": task}$print({"task": Task("b")})#> Group(tasks: [task])$print(Group([Task("a")]))
#---
type Node(n) def inspect [Node(self.n + 1)].inspect "node" endend
#> node$print(Node(0))