Quick start¶
For people willing to get hands quickly on coding:
Install
$ pip install calchylus3
Open Hy
$ hy
Import lambda library
(require [calchylus3.lambdas [*]])
Initialize lambda macros
(with-macros L)
Lambda dance
((L x y [x [x y]]) 'a 'b) ; output: (a (a b))
(FIBONACCI SEVEN 'x 'y) ; output: (x (x (x (x (x (x (x (x (x (x (x (x (x y)))))))))))))
Explanation¶
calchylus3
module works in Windows, Linux, and MacOS operating systems.
3.7 or greater is required. The whole great Python ecosystem
can be installed from Anaconda.
Install Hy language interpreter and calchylus3
module by using pip
Python package management tool:
$ pip install calchylus3
Open Hy, since calchylus3
is mostly written as Hy macros:
$ hy
Import Lambda calculus macros:
(require [calchylus.lambdas [*]])
Define Lambda function indicator letter L
and Lambda argument-body
separator character ,
with one of the initializer macros:
(with-macros L)
By with-macros
we want to say that arguments should
be internally renamed to prevent argument name collision and that we want to
load custom macros representing Lambda forms.
Now, we are ready to evaluate Lambda expressions. Here we apply
Church numeral five to the two values, a
and b
:
((L x y [x [x [x [x [x y]]]]]) 'a 'b)
[output]
[a [a [a [a [a b]]]]]
Without going deeper into this yet, we can see that all x
got replaced by
a
and all y
got replaced by b
.
Predefined macros are available as shorthands for the most common Lambda forms.
For example, calculating the seventh Fibonacci number can be done by using the
Church numeral SEVEN
and the FIBONACCI
shorthands:
(FIBONACCI SEVEN 'x 'y)
[output]
[x [x [x [x [x [x [x [x [x [x [x [x [x y]]]]]]]]]]]]]
That is the Church numeral 13, the seventh Fibonacci number.
In calchylus3
these custom macro shorthands representing Lambda forms serves
as a mathematical and logical foundation for a prototype programming language
that is based on purely untyped Lambda calculus.