-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(hash): hash key * feat(hash): hash inspect function * feat(eval): hash * doc(README): improve readme with examples * refactor(example): move monkey.rs to .monkey
- Loading branch information
Showing
6 changed files
with
296 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1 @@ | ||
let to_integer = fn(proc) { proc(fn(x) { x + 1 })(0) }; | ||
|
||
let ZERO = fn(f) { fn(x) { x } }; | ||
let ONE = fn(f) { fn(x) { f(x) } }; | ||
let TWO = fn(f) { fn(x) { f(f(x)) } }; | ||
let THREE = fn(f) { fn(x) { f(f(f(x))) } }; | ||
|
||
let TRUE = fn(x) { fn(y) { x } }; | ||
let FALSE = fn(x) { fn(y) { y } }; | ||
|
||
let EXP = fn(m) { fn(n) { m(n) } }; | ||
let SUCC = fn(n) { fn(f) { fn(x) { f(n(f)(x)) } } }; | ||
|
||
puts(to_integer(TWO)); | ||
puts("succ one: ", to_integer(SUCC(ONE))); | ||
puts("exp two three: ", to_integer(EXP(TWO)(THREE))); | ||
puts("number 10: ", to_integer(fn(f) { fn(x) { f(f(f(f(f(f(f(f(f(f(x)))))))))) } })); | ||
puts("Hello World!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package object | ||
|
||
import "testing" | ||
|
||
func TestStringHashKey(t *testing.T) { | ||
hello1 := &String{Value: "Hello World"} | ||
hello2 := &String{Value: "Hello World"} | ||
diff1 := &String{Value: "My name is vitor"} | ||
diff2 := &String{Value: "My name is vitor"} | ||
|
||
if hello1.HashKey() != hello2.HashKey() { | ||
t.Errorf("strings with same content have different hash keys") | ||
} | ||
|
||
if diff1.HashKey() != diff2.HashKey() { | ||
t.Errorf("strings with same content have different hash keys") | ||
} | ||
|
||
if hello1.HashKey() == diff1.HashKey() { | ||
t.Errorf("strings with different content have same hash keys") | ||
} | ||
} |