Skip to content

Instantly share code, notes, and snippets.

@eiiches
Created July 21, 2011 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eiiches/1098063 to your computer and use it in GitHub Desktop.
Save eiiches/1098063 to your computer and use it in GitHub Desktop.
Concealing 'lambda' as λ in vim.
# -*- coding: utf-8 -*-
from functools import partial
(lambda x: x*2)((lambda y: y+3)(2))
(lambda x: 5)(10)
(lambda x:(lambda y:x+3*y))(12)(4)
def church2num(church):
try: return church(lambda x: x+1, 0)
except: return church(lambda x: x+1)(0)
# church 0
church0 = (lambda f,x: x)
print church2num(church0) #=> 0
# church 1
church1 = (lambda f,x: f(x))
print church2num(church1) #=> 1
# church 2
church2 = (lambda f,x: f(f(x)))
print church2num(church2) #=> 2
# succ
succ = (lambda n,f,x: f(n(f,x)))
# church 3
church3 = partial(succ, church2)
print church2num(church3) #=> 3
# succ(0)
partial(lambda n,f,x: f(n(f,x)), (lambda f,x: x))
(lambda f,x: f((lambda f,x: x)(f,x)))
(lambda f,x: f(lambda f,x: x))
(lambda f,x: f(x)) # 1
# plus
plus = (lambda m,n,f,x: m(f, n(f, x)))
church5 = partial(plus, church3, church2)
print church2num(church5) #=> 5
# multi
multi = (lambda m,n,f: partial(m, partial(n, f)))
church15 = partial(multi, church5, church3)
print church2num(church15) #=> 15
# :syn keyword Operator lambda conceal cchar=λ
# \ | hi! link Conceal Operator
# \ | set conceallevel=2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment