<!doctype html> <html> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width" /> <meta name="description" content="Functional programming language based on pure de Bruijn indexed lambda calculus." /> <link rel="stylesheet" href="style.css" type="text/css" media="all" /> <title>bruijn programming language</title> </head> <body> <div class="header"> <img src="res/logo.png" /> <h1>bruijn</h1> </div> <div class="example"> <div class="left"> <pre class="code"> <span class="def">pow</span> <span class="term">[<span class="symbol">index</span> (<span class="symbol">iterate</span> (<span class="symbol">mul</span> 0) <span class="ternary">(+1)</span>)]</span> <span class="def">…**…</span> <span class="symbol">pow</span> <span class="com">:test</span> <span class="test">(<span class="term"><span class="ternary">(+2)</span> <span class="mixfix">**</span> <span class="ternary">(+3)</span> <span class="mixfix">=?</span> <span class="ternary">(+8)</span></span>)</span> <span class="test">(<span class="symbol">true</span>)</span></pre> </div> <div class="right"> <p> Functional programming language based on pure de Bruijn indexed lambda calculus. </p> </div> </div> <div class="bar small"> <b>Hint</b>: Click on anything you don't understand. </div> <div class="example"> <div class="left"> <p> Lambdas all the way down.<br /> No primitive functions. </p> </div> <div class="right"> <pre class="code"> <span class="repl">></span> <span class="ternary">(+5)</span> <span class="term">[[[[2 (2 (1 3))]]]]</span> <span class="repl">></span> <span class="char">'a'</span> <span class="term">[[[1 (0 (0 (0 (0 (1 (1 (0 2)))))))]]]</span> <span class="repl">></span> <span class="symbol">add</span> <span class="term">[[(([([[1 0 [[0]]]] ((((0 [[(((0...</span></pre> </div> <div class="left"> <pre class="code"> <span class="repl">></span> <span class="com">:time</span> <span class="symbol">factorial</span> <span class="ternary">(+42)</span> <span class="time">0.01 seconds</span></pre> </div> <div class="right"> <p> <a href="wiki/technical/performance/">Efficient</a> reduction using abstract machines and higher-order encodings. </p> </div> <div class="left"> <p> Substantial standard library.<br /> <a href="std/">Source</a> </p> </div> <div class="right"> <pre class="code"> <span class="repl">></span> <span class="mixfix">∏</span> <span class="ternary">(+1)</span> <span class="mixfix">→</span> <span class="ternary">(+3)</span> <span class="mixfix">|</span> <span class="symbol">++‣</span> <span class="repl">></span> <span class="symbol">number!</span> <span class="mixfix"><$></span> <span class="left-app">(</span><span class="symbol">lines</span> <span class="string">"42\n25"</span><span class="right-app">)</span> <span class="repl">></span> <span class="term"><span class="symbol">sum</span> (<span class="symbol">take</span> <span class="ternary">(+3)</span> (<span class="symbol">repeat</span> <span class="ternary">(+4)</span>))</span> <span class="repl">></span> <span class="binary">(+10b)</span> <span class="mixfix">⋀!</span> <span class="binary">(+12b)</span></pre> </div> <div class="left"> <pre class="code"> $ echo "main [0]" > echo.bruijn $ bruijn -b echo.bruijn > echo $ wc -c echo 2 echo $ echo "hello world!" | bruijn -e echo hello world!</pre > </div> <div class="right"> <p> <a href="wiki/coding/compilation/">Compilation</a> to Tromp's binary lambda calculus.<br /> Support for byte and ASCII encoding. </p> </div> <div class="left"> <p> <a href="wiki/coding/meta-programming/">Meta-programming</a><br /> and self-interpretation. </p> </div> <div class="right"> <pre class="code"> <span class="repl">></span> <span class="symbol">length</span> <span class="meta">`</span><span class="symbol">factorial</span> <span class="repl">></span> <span class="prefix">!</span><span class="left-app">(</span><span class="symbol">swap</span> <span class="meta">`</span><span class="left-app">(</span><span class="unary">(+2u)</span> <span class="unary">(+3u)</span><span class="right-app">))</span> <span class="repl">></span> <span class="symbol">lhs</span> <span class="left-app">(</span><span class="symbol">blc→meta</span> <span class="string">"010000100000110"</span><span class="right-app">)</span> </pre> </div> </div> <div class="bar big"> Learn more: <a href="wiki/">Wiki</a>, <a href="std/">Std</a>, <a href="samples/">Samples</a> </div> <div class="instructions"> <h1>Installation</h1> <pre class="code"> $ git clone https://github.com/marvinborner/bruijn.git && cd bruijn $ <span class="stack">stack</span> run # for playing around $ <span class="stack">stack</span> install $ bruijn</pre> </div> <div class="instructions"> <h1>Broogle</h1> <pre class="code"> $ ./broogle.sh -f add <span class="def">add</span> ⧗ Unary → Unary → Unary also known as <span class="def">…+…</span> in std/Number/Unary.bruijn:35 # adds two unary numbers ...</pre> </div> <div class="instructions"> <h1>Why?</h1> <ul> <li> By having a very small core (the reducer), bruijn is safe, consistent, and (potentially) proven to be correct! </li> <li> Since it doesn't have builtin functions, bruijn is independent of hardware internals and could easily be run on almost any architecture. </li> <li> Compiled binary lambda calculus is incredibly expressive and tiny. Read the articles by <a href="https://justine.lol/lambda/#why">Jart</a> and <a href="https://tromp.github.io/cl/cl.html">Tromp</a>. </li> <li> Exploring different encodings of data as function abstractions is really fascinating. </li> <li> Naming parameters of functions is annoying. De Bruijn indices are a universal reference independent of the function and can actually help readability! </li> <li> Really, <a href="https://justforfunnoreally.dev/">just for fun</a>. </li> </ul> </div> <div class="instructions"> <h1>Articles</h1> <ul> <!-- feel free to add your own --> <li> <a href="https://text.marvinborner.de/2023-04-06-01.html" >The bruijn programming language</a > </li> <li> <a href="https://text.marvinborner.de/2023-04-07-01.html" >Data structures in pure lambda calculus</a > </li> <li> <a href="https://text.marvinborner.de/2023-06-18-15.html" >Variadic fixed-point combinators</a > </li> <li> <a href="https://text.marvinborner.de/2023-09-03-21.html" >Metaprogramming and self interpretation</a > </li> <li> <a href="https://text.marvinborner.de/2024-04-16-10.html" >Crafting Formulas: Lambdas All the Way Down</a > </li> </ul> </div> <div class="bar big"> Open-source: <a href="https://github.com/marvinborner/bruijn">GitHub</a> </div> <script src="script.js" charset="utf-8"></script> </body> </html>