Lambda Calculus
Notes
Not logged in

Notes

VM

MISC

# compose = (rec \compose rest func if-continue . if-continue (compose (\x . rest (func x))) \x . rest (func x)) identity

# Random number generator taken from "Xorshift RNGs", by George Marsaglia, Florida State University
# Here's where I found it: http://www.jstatsoft.org/v08/i14/paper
# This works on a list of booleans, using this formula for the next step:
#	x ^= x << a
#	x ^= x >> b
#	x ^= x << c
#
#	Some small numbers that work are: a = 1, b = 7, c = 9
#
# so:	if we say xorF = \x f . lxor x (f x), that's kind of like x ^= f(x)
#	rand = xorF (xorF (xorF x 1rshift) 7lshift) 9rshift

map = rec \map op l . l (\h t D . cons (op h) (map op t)) false
map2 = rec \map2 op l1 l2 . l1 (\h1 t1 D . l2 (\h2 t2 D . cons (op h1 h2) (map2 op t1 t2)) t1) l2
lxor = \l1 l2 . map2 xor l1 l2
1rshift = \l . cons false l
7lshift = \l . tail (tail (tail (tail (tail (tail (tail l))))))
3rshift = \l . cons false (cons false (cons false l))
9rshift = \l . 3rshift (3rshift (3rshift l))
xorF = \x f . lxor x (f x)
rand = \x . xorF (xorF (xorF x 1rshift) 7lshift) 9rshift