Skip to content

nos1dot618/lambda-discipline

Repository files navigation

Functional Programming Language based on Lambda Calculus highly inspired by this video Programming with Math | The Lambda Calculus - Eyesomorphic made from scratch, entirely in C++.


Getting Started

Prerequisites

  • CMake (version 3.20+ recommended)
  • A C++20 capable compiler (e.g. g++, clang++, or MSVC on Windows)

Setup

python make.py setup

Run Golden Tests

python make.py test

Samples

Booleans and If-Then construct built entirely using Lambda Expressions.

true: Bool = \x: Any. \y: Any. x
false: Bool = \x: Any. \y: Any. y

if: Any = \condition: Bool.
    \thenClause: Any. \elseClause: Any.
        (condition thenClause elseClause)

boolToString: String = \bool: Bool. (if bool "true" "false")

(print (boolToString true) "\n")
(print (boolToString false) "\n")
$ ./cmake-build-debug/lbd run ./examples/conditional_branching.lbd
true
false

Shapes Demo

-- Define Pi as constant
pi: Number = 3.14

-- Define function to calculate square
square: Number -> Number = \x: Number. (mul x x)

-- Define function to calculate area of circle
areaOfCircle: Number -> Number = \r: Number.
    (mul pi (square r))

-- Define function to calculate volume of cylinder
volumeOfCylinder: Number -> Number -> Number = \r: Number.
	  \h: Number. (mul (areaOfCircle r) h)

-- Calculate the volume of a cylinder
(print "Volume of cylinder is: " (volumeOfCylinder 5.0 10.0) "\n")
$ ./cmake-build-debug/lbd run ./examples/shapes.lbd
Volume of cylinder is: 785.000000

Fibonacci

fibonacci: Number = \num: Number.
    (null (cmp 0 num) 0
        (null (cmp 1 num) 1
            (add (fibonacci (sub num 1.0)) (fibonacci (sub num 2.0)))))

(print (fibonacci 10) "\n")
$ ./cmake-build-debug/lbd run ./examples/math_demos.lbd
55.000000

Usage

After building, you can run the interpreter with:

lbd [subcommands] <options>

Options

OPTIONS:
  -h,     --help              Print this help message and exit
  -d,     --debug

SUBCOMMANDS:
  run                         Run a Lambda Discipline source file
  docs                        Generate native function signatures for reference
  repl                        Start an interactive Read-Eval-Print Loop (REPL)

Generate the language-reference-document by using the docs subcommand, and use it as the source of truth for native-function-signatures.

Editor Plugins

  1. GNU Emacs

Linux Releases

Prebuilt Linux releases are distributed as AppImages, allowing the interpreter to run on most modern Linux distributions without installation.

After downloading an AppImage, make it executable and run it:

chmod +x Lambda_Discipline-*.AppImage
./Lambda_Discipline-*.AppImage --help

You can also integrate the AppImage with your desktop environment using tools such as AppImageLauncher, or simply keep it as a portable executable.

Dependencies

  1. fmt: String formatting.
  2. replxx: For better REPL user experience.
  3. CLI11: For better CLI support.