The simplest functional programming language
Project description
λ-Calculus Interpreter v0.1.0
λ-calculus is the simplest functional programming language.
In λ-calculus, "function" means "abstraction from something". For example, instead of 2 + 1, you can write \X. X + 1, and then substitute an arbitrary object for X.
This concept of "function" (or, more correctly, "abstraction") is so fundamental, every programming language implements it more or less explicitely, as it's necessary to avoid code duplication and allow code reuse. So, in some sense, λ-calculus directly follows from DRY itself.
At the same time, you can express any computation or idea by solely using "functions". This is the only mechanism λ-calculus relies on. No built-in numbers or strings, no control flow statements.
So, "abstraction from something" is not only necessary, but it's also sufficient. This is what makes λ-calculus so important and beautiful.
Installation & Usage Example
Using pip
Pip
To install λ-lang you can use this command in your terminal:
python3 -m pip install lmdlang
To run your λ-program:
lmdlang code.lambda
From source code
Source Code
To run your λ-program you can use this command in your terminal:
python3 -m lmdlang.main code.lambda
Advanced way (poetry)
poetry buildpython3 -m pip install dist/package.whllmdlang code.lambda
Then your λ-expression will be fully evaluated and the program will print the result.
Program Example
This is an example of a λ-program:
three := \f. \x. f (f (f x));
square := \num. \f. num (num f);
square three
You can find more examples here: https://en.wikipedia.org/wiki/Church_encoding
Language Overview
In general, a λ-program consists of several definitions followed by a main expression that is the target for evaluation.
In fact, definitions (:=) are just syntactic sugar over λ-expressions, and they are not required at all. Their main purpose is to simplify the beginner experience.
λ-expression
So, the real basis of λ-calculus is λ-expression.
And you're probably already familliar with it.
Take a look at this example:
\f. \x. f (f (f x))
It can be roughly translated into Python like this:
lambda f: lambda x: f(f(f(x)))
f x y z can be interpreted as f(x, y, z).
But actually it is f(x)(y)(z), since this is how argument passing works in λ-calculus. We don't need the concept of multiple arguments.
So, we only use:
- λ-function (
\argument_name. body_term) - variable (
variable_name) - application (
applied_term argument_term)
And that gives us a Turing-complete language.
Evaluation Order
λ-calculus also supports unusual evaluation order.
For example, if you type (\x. \y. y) (...), the contents of (...) never matter or being touched. It's like an "if" statement with condition being false.
Thus, only the necessary calculations occur, allowing us to work with infinite constructions that in other languages like Python would result in an endless loop.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lmdlang-0.1.0.tar.gz.
File metadata
- Download URL: lmdlang-0.1.0.tar.gz
- Upload date:
- Size: 10.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
03cbc82139d243b4734acefeadd6a2c86dd6175ff890810a4fdd1285549293e4
|
|
| MD5 |
655e6366d2bfb6aedf156b5060b62de3
|
|
| BLAKE2b-256 |
df4fc0966d574a6c009c6ca98fce0d8f3affa80e80b437bc1608673674820468
|
Provenance
The following attestation bundles were made for lmdlang-0.1.0.tar.gz:
Publisher:
publish-lmdlang.yml on LambdaCalculusDev/LambdaCalculus
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lmdlang-0.1.0.tar.gz -
Subject digest:
03cbc82139d243b4734acefeadd6a2c86dd6175ff890810a4fdd1285549293e4 - Sigstore transparency entry: 164411338
- Sigstore integration time:
-
Permalink:
LambdaCalculusDev/LambdaCalculus@a7306111ee26f2126c83bf66b7cd581605156837 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/LambdaCalculusDev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-lmdlang.yml@a7306111ee26f2126c83bf66b7cd581605156837 -
Trigger Event:
push
-
Statement type:
File details
Details for the file lmdlang-0.1.0-py3-none-any.whl.
File metadata
- Download URL: lmdlang-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0f629360eb11c19cc2533a4b717aa7433d22dede2f8f378a52fc2d94ac347037
|
|
| MD5 |
9570ee66d5bdd868d700b89a9630867f
|
|
| BLAKE2b-256 |
fe0dc48ca333d454a0b75b86474df6db141d71753336edbcf7e5e13be585677c
|
Provenance
The following attestation bundles were made for lmdlang-0.1.0-py3-none-any.whl:
Publisher:
publish-lmdlang.yml on LambdaCalculusDev/LambdaCalculus
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lmdlang-0.1.0-py3-none-any.whl -
Subject digest:
0f629360eb11c19cc2533a4b717aa7433d22dede2f8f378a52fc2d94ac347037 - Sigstore transparency entry: 164411339
- Sigstore integration time:
-
Permalink:
LambdaCalculusDev/LambdaCalculus@a7306111ee26f2126c83bf66b7cd581605156837 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/LambdaCalculusDev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-lmdlang.yml@a7306111ee26f2126c83bf66b7cd581605156837 -
Trigger Event:
push
-
Statement type: