Skip to content

Instantly share code, notes, and snippets.

// This is a simple interpreter for the untyped lambda calculus
// in JavaScript, used as an example of the possible benefits of
// hash-consing. Skip to the end of the file to see the tests.
// ~ SrPeixinho
var i32size = Math.pow(2,32);
var i32sizeInv = 1/i32size;
var stats = {
beta_reductions : 0,
reductions : 0,
@viclib
viclib / church_fractions.md
Last active December 23, 2023 13:18
Simplifying division of church-numbers with church-fractions.

Simplifying division of church-numbers with church-fractions.

A church number n can be understood as the act of applying a function to a value n times. That is:

(λ f x . (f (f (f x))))

Can be understood as the church number 3, since it is an action that applies a function, f, to a value, x, 3 times. Here, I will be using "number" as a synonym for "church number" and, thus, a "natural number". Implementing addition, multiplication and exponentiation on church numbers is straightforward. Division is more awkward. Wikipedia, for instance, uses a recursive definition that doesn't have a normal form and is, thus, unsuited for strongly normalizing evaluators. This version is total, but has a huge normal form and works for integers, not naturals. There is a simpler way to define it, extending the same intuition to bu

@viclib
viclib / gist:9108f02fb1655cdc0787
Created January 23, 2015 09:52
print array after result
This file has been truncated, but you can view the full file.
var h$currentThread = null;
var h$stack = null;
var h$sp = 0;
var h$initStatic = [];
var h$staticThunks = {};
var h$staticThunksArr = [];
var h$regs = [];
var h$r1 = 0;
var h$r2 = 0;
"perfis":{
"conservador":{
"renda_fixa":{
"percentuais":[70,65,60,55,50,45,40,35,30,25],
"divisao":{
"Renda Fixa Referenciado":100,
"Renda Fixa Índice":0
}
},
"multimercado":{
global.perfis = {}
for p,perfil of data.perfis
perfis[p] = {}
for c,cat of perfil
perfis[p][c] = {}
for sc,parcela of cat.divisao
categoria[sc] = c
perfis[p][c][sc] = interpolated (map (->it*parcela/100), cat.percentuais), 0, 10
@viclib
viclib / gist:6434497
Created September 4, 2013 08:58
why this doesn't compile
testVec : Vect 5 Int
testVec = 3 :: 4 :: 5 :: 6 :: 7 :: Nil
aff : Int
aff = index (2 + 2) testVec