From 2e3e043cae2dabeb9bf4fa57e0e69b022dfe478d Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Sat, 25 Feb 2023 17:07:30 +0100 Subject: Added documentation/website --- docs/.gitignore | 1 + docs/content.css | 65 ++++++++++++++++++++ docs/content.js | 26 ++++++++ docs/content.template | 17 ++++++ docs/gen.sh | 20 +++++++ docs/index.css | 14 +++++ docs/index.html | 121 ++++++++++++++++++++++++++++++++++++++ docs/index.template | 15 +++++ docs/readme.md | 4 ++ docs/res/logo.png | Bin 0 -> 29198 bytes docs/script.js | 50 ++++++++++++++++ docs/style.css | 160 ++++++++++++++++++++++++++++++++++++++++++++++++++ readme.md | 7 ++- 13 files changed, 498 insertions(+), 2 deletions(-) create mode 100644 docs/.gitignore create mode 100644 docs/content.css create mode 100644 docs/content.js create mode 100644 docs/content.template create mode 100755 docs/gen.sh create mode 100644 docs/index.css create mode 100644 docs/index.html create mode 100644 docs/index.template create mode 100644 docs/readme.md create mode 100644 docs/res/logo.png create mode 100644 docs/script.js create mode 100644 docs/style.css diff --git a/docs/.gitignore b/docs/.gitignore new file mode 100644 index 0000000..4e1ae2d --- /dev/null +++ b/docs/.gitignore @@ -0,0 +1 @@ +std/ diff --git a/docs/content.css b/docs/content.css new file mode 100644 index 0000000..941e5c3 --- /dev/null +++ b/docs/content.css @@ -0,0 +1,65 @@ +body { + font-family: monospace; + background-color: #222222; + color: #cccccc; + font-size: 1.2em; +} + +a { + color: #cccccc; +} + +pre { + margin: 0 0 1em; + padding: .5em 1em; +} + +pre .line { + display: block; + float: left; + margin: 0 1em 0 -1em; + border-right: 1px solid; + text-align: right; +} + +pre .line span { + display: block; + padding: 0 .5em 0 1em; +} + +pre .cl { + display: block; + clear: both; +} + +.com { + color: #ff64bd; +} + +.def { + color: #13dbee; +} + +.comment { + color: #999999; +} + +.type { + color: #ffa120; +} + +.left-abs, .right-abs { + color: #6b82ff; +} + +.left-app, .right-app { + color: #ff8750; +} + +.index { + color: #ff5050; +} + +.number { + color: #b1ee13; +} diff --git a/docs/content.js b/docs/content.js new file mode 100644 index 0000000..4fb7a16 --- /dev/null +++ b/docs/content.js @@ -0,0 +1,26 @@ +const code = document.getElementsByTagName("pre")[0] + +const fixPath = p => p.replace("/", "_") + +const term = t => t + .replaceAll(/(\([+-][0-9]+[ubt]?\))/g, "$1") + .replaceAll(/(?)(\()/g, "(") + .replaceAll(/(\))(?!\<)/g, ")") + .replaceAll("[", "[") + .replaceAll("]", "]") + .replaceAll(/(?$1") + +code.innerHTML = code.innerHTML + .replaceAll(/^:import std\/(.*) (.*)$/gm, (_, p, s) => `:import std/${p} ${s}`) + .replaceAll(/^:input std\/(.*)$/gm, (_, p) => `:input std/${p}`) + .replaceAll(/^:test \((.*)\) \((.*)\)$/gm, (_, t1, t2) => `:test (${term(t1)}) (${term(t2)})`) + .replaceAll(/^([^:\n<#][^ ]*) (.*)$/gm, (_, d, t) => `${d} ${term(t)}`) + .replaceAll(/^# (.*)$/gm, "# $1") + .replaceAll(/ ⧗ (.*)\n/g, " ⧗ $1\n") + +code.innerHTML = `${code.innerHTML}` +const lines = code.innerHTML.split(/\n/).length - 1 +for (let i = 0; i < lines; i++) { + const cur = code.getElementsByTagName("span")[0] + cur.innerHTML += `${i + 1}` +} diff --git a/docs/content.template b/docs/content.template new file mode 100644 index 0000000..c19461f --- /dev/null +++ b/docs/content.template @@ -0,0 +1,17 @@ + + + + + + + bruijn std/ + + +

NAME

+
+CONTENT
+
+ + + + diff --git a/docs/gen.sh b/docs/gen.sh new file mode 100755 index 0000000..4e7a80b --- /dev/null +++ b/docs/gen.sh @@ -0,0 +1,20 @@ +#!/bin/env bash + +set -e + +rm -rf std/ && mkdir -p std/ + +files=$(find ../std/ -type f | sort) +links="" + +for file in $files; do + name=$(echo $file | cut -c8-) + filename=$(sed s@/@_@g <<<"$name") + links="$links\n
  • :import $name
  • " + awk 'NR==FNR { gsub("<", "\\<", $0); gsub(">", "\\>", $0); a[n++]=$0; next } /CONTENT/ { for (i=0;istd/$filename.html + sed -i -e "s@NAME@$name@g" std/$filename.html +done + +sed -e "s@LINKS@$links@g" index.template >std/index.html + +cp content.js content.css index.css std/ diff --git a/docs/index.css b/docs/index.css new file mode 100644 index 0000000..1e70968 --- /dev/null +++ b/docs/index.css @@ -0,0 +1,14 @@ +body { + font-family: monospace; + background-color: #222222; + color: #cccccc; + font-size: 1.2em; +} + +a { + color: #cccccc; +} + +.com { + color: #ff64bd; +} diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 0000000..1644c88 --- /dev/null +++ b/docs/index.html @@ -0,0 +1,121 @@ + + + + + + + bruijn + + +
    + +

    bruijn

    +
    + +
    +
    +pow […!!… (iterate (…⋅… 0) (+1))]
    +
    +…**… pow
    +
    +:test ((+2) ** (+3) =? (+8)) (true)
    + +

    + Functional language based on pure bruijn-indexed lambda calculus. +

    +
    + +
    + Hint: Click on anything you don't understand. +
    + +
    +

    + Lambdas all the way down.
    + No primitive functions. +

    +
    +> (+5)
    +[[[[2 (2 (1 3))]]]]
    +> 'a'
    +[[[1 (0 (0 (0 (0 (1 (1 (0 2)))))))]]]
    +> add
    +[[(([([[1 0 [[0]]]] ((((0 [[(((0...
    +
    + +
    +
    +> :time factorial (+30)
    +0.35 seconds
    +

    + Efficient call-by-need reduction using abstract machines. +

    +
    + +
    +

    + Substantial standard library.
    + Docs +

    +
    +>  (+1)  (+3) | ++‣
    +> number! <$> (lines "42\n25")
    +> sum (take (+3) (repeat (+4)))
    +> (+10b) ⋀! (+12b)
    +
    + +
    +
    +$ echo "main [0]" > echo.bruijn
    +$ bruijn -b echo.bruijn > echo
    +$ wc -c echo
    +2 echo
    +$ echo "hello world!" | bruijn -e echo
    +hello world!
    +

    + Compilation to Tromp's binary lambda calculus.
    + Support for byte and ASCII encoding. +

    +
    + +
    + Learn more: GitHub +
    + +
    +

    Installation

    +
    +$ git clone https://github.com/marvinborner/bruijn.git && cd bruijn
    +$ stack run # for playing around
    +$ stack install
    +$ bruijn
    +
    + +
    +

    Broogle

    +
    +$ ./broogle.sh -f add
    +add ⧗ Unary → Unary → Unary
    +also known as …+…
    +in std/Number/Unary.bruijn:35
    +# adds two unary numbers
    +...
    +
    + +
    +

    Syntax highlighting

    +
      +
    1. Use vim and vim-plug
    2. +
    3. Add "Plug 'marvinborner/bruijn', { 'rtp': 'editors/vim' }" to your .vimrc
    4. +
    5. Run :PlugInstall
    6. +
    + Learn more: GitHub +
    + +
    + Standard library: Docs +
    + + + + diff --git a/docs/index.template b/docs/index.template new file mode 100644 index 0000000..9cbb1f5 --- /dev/null +++ b/docs/index.template @@ -0,0 +1,15 @@ + + + + + + + bruijn standard library + + +

    bruijn standard library

    +
      + LINKS +
    + + diff --git a/docs/readme.md b/docs/readme.md new file mode 100644 index 0000000..a8b0829 --- /dev/null +++ b/docs/readme.md @@ -0,0 +1,4 @@ +# Docs + +Visit the compiled [docs](https://bruijn.marvinborner.de) for the full +experience. diff --git a/docs/res/logo.png b/docs/res/logo.png new file mode 100644 index 0000000..aa2d80b Binary files /dev/null and b/docs/res/logo.png differ diff --git a/docs/script.js b/docs/script.js new file mode 100644 index 0000000..21f0cdf --- /dev/null +++ b/docs/script.js @@ -0,0 +1,50 @@ +[...document.getElementsByClassName("term")].forEach(el => { + el.innerHTML = el.innerHTML + .replaceAll(/(?)(\()/g, "(") + .replaceAll(/(\))(?!\<)/g, ")") + .replaceAll("[", "[") + .replaceAll("]", "]") + .replaceAll(/(?$1") +}) + +const clearPopups = () => { + [...document.getElementsByClassName("popup")].forEach(el => { + el.remove() + }) +} + +const notify = (s, e) => { + console.log(e); + clearPopups() + const popup = document.createElement("div") + popup.className = "popup" + const content = document.createTextNode(s) + popup.style.left = e.pageX + "px"; + popup.style.top = e.pageY + "px"; + popup.appendChild(content) + document.body.appendChild(popup) +} + +const describe = (c, d) => { + [...document.getElementsByClassName(c)].forEach(el => el.addEventListener("click", e => notify(d, e))); +} + +describe("binary", "Syntactic sugar for a binary number representation using abstractions as data. Needs a sign and brackets to differentiate it from bruijn indices"); +describe("char", "Syntactic sugar for a binary representation of characters using abstractions as data."); +describe("com", "This indicates a command to the interpreter. The most common commands are :test (verifying α-equivalency) and :import (importing definitions from other files)."); +describe("def", "This defines a new term substitution."); +describe("header", "[0] is the identity operation. It returns the first argument it gets. Nothing more."); +describe("index", "These numbers reference the nth abstraction, starting counting from the inside. These 'bruijn indices' replace the concept of variables in lambda calculus."); +describe("left-abs", "The opening bracket of a function abstraction. It's basically the equivalent of the λ in lambda calculus."); +describe("left-app", "The opening bracket of a function application."); +describe("mixfix", "This is a mixfix operator. They can be defined like …*… where the … can then be any other term. You can use them without the … as a notation of function application."); +describe("repl", "This indicates a REPL input."); +describe("right-abs", "The closing bracket of a function abstraction."); +describe("right-app", "The closing bracket of a function application."); +describe("stack", "Stack is a dependency manager for Haskell. Install it using the corresponding instructions for your operating system.") +describe("string", "Syntactic sugar for a list of binary encoded chars.") +describe("symbol", "This substitutes a previously defined term (for example from the standard library)."); +describe("ternary", "Syntactic sugar for a balanced ternary number representation using abstractions as data. Needs a sign and brackets to differentiate it from bruijn indices."); +describe("time", "Incredibly fast for lambda calculus standards."); + +document.body.addEventListener("click", clearPopups, true) diff --git a/docs/style.css b/docs/style.css new file mode 100644 index 0000000..7eec6b0 --- /dev/null +++ b/docs/style.css @@ -0,0 +1,160 @@ +body { + font-family: monospace; + background-color: #222222; + color: #cccccc; + font-size: 1.2em; + padding: 0; + margin: 0; +} + +a { + color: #cccccc; +} + +.header { + display: flex; + align-items: center; + flex-direction: column; +} + +.header img { + width: auto; + max-height: 20vh; +} + +.header h1 { + margin-top: -0.5em; + font-size: 3em; +} + +.example { + display: flex; + align-items: center; + justify-content: center; + flex-flow: row wrap; + column-gap: 5vw; + max-width: 80%; + margin: 0 auto; +} + +.example p { + font-size: 1.3em; + max-width: 80vw; + text-align: center; +} + +.instructions { + max-width: 80%; + margin: 0 auto; +} + +@media(min-width: 768px) { + .example { + flex-flow: row nowrap; + max-width: 80%; + } + + .example p { + width: 30vw; + font-size: 1.5em; + } + + .instructions { + max-width: 80%; + } +} + +@media(min-width: 1800px) { + .example { + flex-flow: row nowrap; + max-width: 35%; + } + + .instructions { + max-width: 35%; + } +} + +.bar { + text-align: center; + background-color: #333333; + margin: 30px 0; +} + +.bar.small { + font-size: 1.2em; + line-height: 1.2em; + padding: 15px; +} + +.bar.big { + font-size: 2em; + line-height: 5em; + padding: 20px; +} + +.bar a { + color: #cccccc; +} + +.popup { + position: absolute; + display: block; + border-sizing: border-box; + box-shadow: 0 10px 50px rgba(0,0,0,.6); + background-color: #333333; + border-radius: 10px; + padding: 15px; + max-width: 300px; +} + +.code { + background-color: #333333; + padding: 15px; + font-size: 1.2em; + border-radius: 10px; +} + +.instructions .code { + overflow-x: scroll; +} + +.code .repl { + color: #13dbee; +} + +.code .def { + color: #13dbee; +} + +.code .left-abs, .code .right-abs { + color: #6b82ff; +} + +.code .left-app, .code .right-app { + color: #ff8750; +} + +.code .com { + color: #ff64bd; +} + +.code .ternary, .code .binary { + color: #b1ee13; +} + +.code .char, .code .string { + color: #b1ee13; +} + +.code .mixfix { + color: #eee513; +} + +.code .symbol { + color: #f9f9f9; +} + +.code .index { + color: #ff5050; +} diff --git a/readme.md b/readme.md index d94d993..b521c0f 100644 --- a/readme.md +++ b/readme.md @@ -6,6 +6,8 @@ [Jump to examples](#Examples) or use the navigation tree to jump to other sections. +Docs, examples and more: [website](https://bruijn.marvinborner.de). + ## Features - **De Bruijn indices[\[0\]](#References)** eliminate the complexity of @@ -261,7 +263,7 @@ Some other great functions: # lazy evaluation using infinite lists and indexing pow2 …!!… (iterate (…⋅… (+2)) (+1)) - :test ((pow2 (+5)) =? ((+32))) (true) + :test ((pow2 (+5)) =? (+32)) (true) # options :test (map inc (some (+1))) (some (+2)) @@ -274,7 +276,8 @@ Some other great functions: :test (main [0]) (false) -Read the files in `std/` for an overview of all functions/libraries. +Read the files in `std/` for an overview of all functions/libraries or +visit the interactive [website](https://bruijn.marvinborner.de). ### Compilation to BLC -- cgit v1.2.3