Compare commits
4 Commits
c345ac4fe5
...
f2b0e38464
Author | SHA1 | Date | |
---|---|---|---|
f2b0e38464 | |||
1e2c107c1b | |||
c29d463adf | |||
5f57c5aed3 |
@ -2,7 +2,6 @@ fun <- ->
|
||||
do-something()
|
||||
do-something-else()
|
||||
|
||||
|
||||
foo <- ->
|
||||
bar <- ->
|
||||
baz <- ->
|
||||
@ -11,8 +10,7 @@ foo <- ->
|
||||
|
||||
foo() ## Inside foo but not in baz or bar
|
||||
|
||||
add <- x -> y ->
|
||||
return x + y ## Multivariable functions by currying
|
||||
add <- x -> y -> x + y ## Multivariable functions by currying
|
||||
|
||||
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,24 +1,11 @@
|
||||
## 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("Hello world!") ## Hello world
|
||||
|
||||
name <- read()
|
||||
print("Hi there $name") ## Hi there <name>
|
||||
|
||||
have <- 10
|
||||
want <- 11
|
||||
need <- have - want ## This is subtraction
|
||||
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() ## Hi from inside a function
|
||||
|
||||
@ -31,8 +18,8 @@ duck <- {
|
||||
eats? <- food -> food = "bread"
|
||||
} ## Objects created on the fly
|
||||
|
||||
print duck.eats?("bread") ## true
|
||||
print duck.eats?("corn") ## false
|
||||
print(duck.eats?("bread")) ## true
|
||||
print(duck.eats?("corn")) ## false
|
||||
|
||||
cow <- {
|
||||
talk <- print("Moo")
|
||||
@ -43,15 +30,15 @@ human <- {
|
||||
eats? <- _ -> true
|
||||
}
|
||||
|
||||
print cow.eats?("grass") ## true
|
||||
print cow.eats?("corn") ## true
|
||||
print(cow.eats?("grass")) ## true
|
||||
print(cow.eats?("corn")) ## true
|
||||
|
||||
talk-or-pass-wind <- character ->
|
||||
if character has talk then
|
||||
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*"
|
||||
talk-or-pass-wind(human) ## "*Fart*"
|
||||
|
@ -4,7 +4,7 @@ use std::collections::HashSet;
|
||||
use crate::parser;
|
||||
|
||||
fn munge(s: &str) -> String {
|
||||
s.replace("?", "_INT_").replace("-", "_DASH_")
|
||||
s.replace("?", "p").replace("-", "_")
|
||||
}
|
||||
|
||||
pub struct LexicalContext<'a> {
|
||||
|
@ -218,7 +218,7 @@ impl fmt::Display for Stmt {
|
||||
}
|
||||
if let Some(block) = else_block {
|
||||
write!(f, "else")?;
|
||||
write_block(f, &block)?;
|
||||
write_block(f, block)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user