Compare commits
No commits in common. "f2b0e38464136291ed91a63fb73e4bf70a96e3c8" and "c345ac4fe58e95244096ae6396f46cc3bfc9e47b" have entirely different histories.
f2b0e38464
...
c345ac4fe5
@ -2,6 +2,7 @@ fun <- ->
|
|||||||
do-something()
|
do-something()
|
||||||
do-something-else()
|
do-something-else()
|
||||||
|
|
||||||
|
|
||||||
foo <- ->
|
foo <- ->
|
||||||
bar <- ->
|
bar <- ->
|
||||||
baz <- ->
|
baz <- ->
|
||||||
@ -10,7 +11,8 @@ foo <- ->
|
|||||||
|
|
||||||
foo() ## Inside foo but not in baz or bar
|
foo() ## Inside foo but not in baz or bar
|
||||||
|
|
||||||
add <- x -> y -> x + y ## Multivariable functions by currying
|
add <- x -> y ->
|
||||||
|
return x + y ## Multivariable functions by currying
|
||||||
|
|
||||||
add(x) ## Returns a _function_
|
add(x) ## Returns a _function_
|
||||||
add(x, y) ## This is equivalent to add(x)(y)
|
add(x, y) ## This is equivalent to add(x)(y)
|
@ -1,11 +1,24 @@
|
|||||||
|
## By the end of the book I want to have an interpreter
|
||||||
|
## for this little language, maybe a compiler too
|
||||||
|
|
||||||
print(1 + 1) ## 2
|
print(1 + 1) ## 2
|
||||||
print("Hello world!") ## Hello world
|
print("Hello world!") ## Hello world
|
||||||
|
|
||||||
|
name <- read()
|
||||||
|
print("Hi there $name") ## Hi there <name>
|
||||||
|
|
||||||
have <- 10
|
have <- 10
|
||||||
want <- 11
|
want <- 11
|
||||||
need <- have - want ## This is subtraction
|
need <- have - want ## This is subtraction
|
||||||
have-want <- 1 ## This is a variable named "have-want"
|
have-want <- 1 ## This is a variable named "have-want"
|
||||||
|
|
||||||
|
print(HaVe-WAnt) ## 1 (case doesn't matter)
|
||||||
|
%%option meaningful-casing
|
||||||
|
Apples <- 1
|
||||||
|
print(apples) ## <undef> (or maybe it does)
|
||||||
|
|
||||||
|
print("one fish"); print("two fish") ## Two statements on the same line
|
||||||
|
|
||||||
say-hi <- -> print("Hi from inside a function")
|
say-hi <- -> print("Hi from inside a function")
|
||||||
say-hi() ## Hi from inside a function
|
say-hi() ## Hi from inside a function
|
||||||
|
|
||||||
@ -18,8 +31,8 @@ duck <- {
|
|||||||
eats? <- food -> food = "bread"
|
eats? <- food -> food = "bread"
|
||||||
} ## Objects created on the fly
|
} ## Objects created on the fly
|
||||||
|
|
||||||
print(duck.eats?("bread")) ## true
|
print duck.eats?("bread") ## true
|
||||||
print(duck.eats?("corn")) ## false
|
print duck.eats?("corn") ## false
|
||||||
|
|
||||||
cow <- {
|
cow <- {
|
||||||
talk <- print("Moo")
|
talk <- print("Moo")
|
||||||
@ -30,11 +43,11 @@ human <- {
|
|||||||
eats? <- _ -> true
|
eats? <- _ -> true
|
||||||
}
|
}
|
||||||
|
|
||||||
print(cow.eats?("grass")) ## true
|
print cow.eats?("grass") ## true
|
||||||
print(cow.eats?("corn")) ## true
|
print cow.eats?("corn") ## true
|
||||||
|
|
||||||
talk-or-pass-wind <- character ->
|
talk-or-pass-wind <- character ->
|
||||||
if character has talk
|
if character has talk then
|
||||||
character.talk()
|
character.talk()
|
||||||
else
|
else
|
||||||
print("*Fart*")
|
print("*Fart*")
|
||||||
|
@ -4,7 +4,7 @@ use std::collections::HashSet;
|
|||||||
use crate::parser;
|
use crate::parser;
|
||||||
|
|
||||||
fn munge(s: &str) -> String {
|
fn munge(s: &str) -> String {
|
||||||
s.replace("?", "p").replace("-", "_")
|
s.replace("?", "_INT_").replace("-", "_DASH_")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct LexicalContext<'a> {
|
pub struct LexicalContext<'a> {
|
||||||
|
@ -218,7 +218,7 @@ impl fmt::Display for Stmt {
|
|||||||
}
|
}
|
||||||
if let Some(block) = else_block {
|
if let Some(block) = else_block {
|
||||||
write!(f, "else")?;
|
write!(f, "else")?;
|
||||||
write_block(f, block)?;
|
write_block(f, &block)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user