45 lines
931 B
Plaintext
45 lines
931 B
Plaintext
print(1 + 1) ## 2
|
|
print("Hello world!") ## Hello world
|
|
|
|
have <- 10
|
|
want <- 11
|
|
need <- have - want ## This is subtraction
|
|
have-want <- 1 ## This is a variable named "have-want"
|
|
|
|
say-hi <- -> print("Hi from inside a function")
|
|
say-hi() ## Hi from inside a function
|
|
|
|
say-hi-again <- say-hi
|
|
say-hi-again() ## "Hi from inside a function" (First class functions!)
|
|
|
|
duck <- {
|
|
bills <- 1
|
|
talk <- -> print("Quack")
|
|
eats? <- food -> food = "bread"
|
|
} ## Objects created on the fly
|
|
|
|
print(duck.eats?("bread")) ## true
|
|
print(duck.eats?("corn")) ## false
|
|
|
|
cow <- {
|
|
talk <- print("Moo")
|
|
eats? <- food -> food oneof "grass", "corn"
|
|
}
|
|
|
|
human <- {
|
|
eats? <- _ -> true
|
|
}
|
|
|
|
print(cow.eats?("grass")) ## true
|
|
print(cow.eats?("corn")) ## true
|
|
|
|
talk-or-pass-wind <- character ->
|
|
if character has talk
|
|
character.talk()
|
|
else
|
|
print("*Fart*")
|
|
|
|
talk-or-pass-wind(duck) ## "Quack"
|
|
talk-or-pass-wind(cow) ## "Moo"
|
|
talk-or-pass-wind(human) ## "*Fart*"
|