Skip to content

Commit

Permalink
Added s-combinator experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
bvssvni committed Jul 7, 2017
1 parent cc72ea1 commit 4b77ef1
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
3 changes: 3 additions & 0 deletions dyon_experiments/scomb/.gitignore
@@ -0,0 +1,3 @@
/target/
Cargo.lock

10 changes: 10 additions & 0 deletions dyon_experiments/scomb/Cargo.toml
@@ -0,0 +1,10 @@
[package]
name = "scomb"
version = "0.1.0"
authors = ["Sven Nilsen <bvssvni@gmail.com>"]

[[bin]]
name = "scomb"

[dependencies]
dyon = "0.24.5"
58 changes: 58 additions & 0 deletions dyon_experiments/scomb/src/main.dyon
@@ -0,0 +1,58 @@
fn main() {
/*
// λf.((λx.x x)(λx.f (x x)))
y := \(f) = {
x := \(x) = \x(x)
\(x) = {
f := grab f
\f(\x(x))
}
}
a := \y(\(f) = \(ind) = {
println(ind)
if ind > 0 {
f := grab f
y := grab '2 y
println(f)
println(\f(y))
}
3
})
b := \a(y)
// println(b)
println(\b(1))
*/

h := \(x, ind) = {
// println(ind)
if ind == 1 {
1
} else {
collatz := if (ind % 2) == 0 {ind / 2} else {3 * ind + 1}
ind + \x(collatz)
}
}

h := \(self, n) = {
if n == 0 {0} else if n == 1 {1} else {\self(n-1) + \self(n-2)}
}

sc := \(sc, f) = \(n) = {
sc := grab sc
f := grab f
\f(\sc(sc, f), n)
}

// First you create the combinator.
// println(a)

// Then you pass the combinator to itself.
b := \sc(sc, h)
// println(b)

// Then you pass the value you want to compute.
for i [1, 10) {
println(\b(i))
}
println(\b(20))
}
7 changes: 7 additions & 0 deletions dyon_experiments/scomb/src/main.rs
@@ -0,0 +1,7 @@
extern crate dyon;

use dyon::{error, run};

fn main() {
error(run("src/main.dyon"));
}

0 comments on commit 4b77ef1

Please sign in to comment.