https://github.com/codewars/lambda-calculus
Lambda Calculus compiler for Codewars
https://github.com/codewars/lambda-calculus
code-runner code-runner-image
Last synced: 8 months ago
JSON representation
Lambda Calculus compiler for Codewars
- Host: GitHub
- URL: https://github.com/codewars/lambda-calculus
- Owner: codewars
- License: mit
- Created: 2022-01-13T23:41:13.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-02-05T19:53:06.000Z (almost 2 years ago)
- Last Synced: 2025-04-20T11:54:51.438Z (8 months ago)
- Topics: code-runner, code-runner-image
- Language: JavaScript
- Homepage:
- Size: 416 KB
- Stars: 16
- Watchers: 3
- Forks: 4
- Open Issues: 16
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# LC Compiler for Codewars


Written by [Kacarott](https://github.com/Kacarott) and [JohanWiltink](https://github.com/JohanWiltink)
### Install
```bash
$ npm i --save @codewars/lambda-calculus
```
### Usage
> NOTE: When writing tests on Codewars, you can use the predefined wrapper module "./files.js" to get
> the solution file instead of using `fs` like below.
```javascript
import { readFileSync } from "fs";
// Import module
import * as LC from "@codewars/lambda-calculus";
// Set config options
LC.config.purity = "Let";
LC.config.numEncoding = "Church";
const code = readFileSync("solution.lc", {encoding: "utf8"});
// Compile
const solution = compile(code).TRUE;
// or
const {TRUE,FALSE} = compile(code);
// Use
console.log(solution(true)(false)); // true
// or
console.log(TRUE(true)(false)) // true
```
### Documentation
---
`compile :: String -> {String: (Term -> Term)}`
`compile` is the main entry point of the module. Compiles the specified text according the current `config` options, and returns an object binding all defined terms to their corresponding functions.
---
`config :: {String: String}`
`config` is an object which provides the interface for controlling how compilation behaves. Currently there are three configurable properties: `purity`, `numEncoding` and `verbosity`.
| Property | Option | Description |
| -------- | ---- | ---- |
| `purity` | `Let` | Allows definition of named terms which can be used in subsequent definitions. Does *not* support recursion. |
| | `LetRec` | The same as `Let`, but additionally supporting direct recursion. |
| | `PureLC` (default) | Pure lambda calculus only. Terms are still named so that they can be accessed by tests, but named terms may not be used elsewhere. |
| `numEncoding` | `None` | No number encoding. Use of number literals will cause an error. |
| | `Church`
`Scott`
`BinaryScott` | Number literals will be automatically converted to corresponding LC terms, according to the encoding chosen. |
| `verbosity` | `Calm`
`Concise`
`Loquacious`
`Verbose` | Controls the amount of information that will be reported during compilation. |
### Container Image
The container image used by the Code Runner is available on [GHCR](https://github.com/codewars/lambda-calculus/pkgs/container/lambda-calculus).
```bash
docker pull ghcr.io/codewars/lambda-calculus:latest
```
#### Building
The image can be built from this repository:
```bash
docker build -t ghcr.io/codewars/lambda-calculus:latest .
```
#### Usage
See [example/](./example/) to learn how to use the image to test locally.