|
| 1 | +<!doctype html> |
| 2 | + |
| 3 | +<title>CodeMirror: Lambda Calculus mode</title> |
| 4 | +<meta charset="utf-8"/> |
| 5 | +<link rel=stylesheet href="src/docs.css"> |
| 6 | + |
| 7 | +<link rel="stylesheet" href="src/codemirror.css"> |
| 8 | +<link rel="stylesheet" href="src/3024-night.css"> |
| 9 | +<script src="src/codemirror.js"></script> |
| 10 | +<script src="src/matchbrackets.js"></script> |
| 11 | +<script src="../lambdacalc.js"></script> |
| 12 | +<style>.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style> |
| 13 | +<div id=nav> |
| 14 | + <a href="https://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png" alt=""></a> |
| 15 | + <ul> |
| 16 | + <li><a class=active href="#">Lambda Calculus</a> |
| 17 | + </ul> |
| 18 | +</div> |
| 19 | + |
| 20 | +<article> |
| 21 | +<h2>Lambda Calculus mode</h2> |
| 22 | +<form><textarea id="code" name="code"> |
| 23 | + |
| 24 | +# Some code (with ignored arguments) |
| 25 | +false = \ _a b . b |
| 26 | +true = \ a _b . a |
| 27 | +not = \ b . b false true |
| 28 | +const = true |
| 29 | + |
| 30 | +# Invalid - multiple definition |
| 31 | +true = not false |
| 32 | + |
| 33 | +# Invalid names |
| 34 | +%value = () |
| 35 | + |
| 36 | +# Invalid args - unbound |
| 37 | +someFunc = \ local . true nonexistant local |
| 38 | + |
| 39 | +# Invalid args - scoped |
| 40 | +otherFunc = \ x . const (\ scopedArg . x ()) scopedArg x |
| 41 | + |
| 42 | +# More code |
| 43 | +zero = false |
| 44 | +succ = \ n f x . f (n f x) |
| 45 | +isZ = \ n . n (const false) true |
| 46 | +add = \ a b f x . a f (b f x) |
| 47 | +mul = \ a b f . a (b f) |
| 48 | +three = succ (succ (succ zero)) |
| 49 | +mt = mul three |
| 50 | +nine = mul three three |
| 51 | + |
| 52 | +pair = \ a b c . c a b |
| 53 | +fst = \ c . c true |
| 54 | +snd = \ c . c false |
| 55 | + |
| 56 | +nil = pair false () |
| 57 | +null = \ l . not (fst l) |
| 58 | +head = \ l . fst (snd l) |
| 59 | +tail = \ l . snd (snd l) |
| 60 | +cons = \ x xs . pair true (pair x xs) |
| 61 | +replicate = \ n v . n (cons v) nil |
| 62 | +repeat = \ v . cons v (repeat v) |
| 63 | +foldr = \ f b as . null as b (f (head as) (foldr f b (tail as))) |
| 64 | +pred = \ n f x . foldr (const f) x (tail (replicate n ())) # Bit janky lol |
| 65 | +map = \ f xs . null xs nil (cons (f (head xs)) (map f (tail xs))) |
| 66 | +sum = foldr add zero |
| 67 | +drop = \ n . n tail |
| 68 | +take = \ n xs . isZ n nil (cons (head xs) (take (pred n) (tail xs))) |
| 69 | +col = \ n xs . head (drop n xs) |
| 70 | +colS = \ n xs . cons (col n xs) (cons (col (succ n) xs) (cons (col (succ (succ n)) xs) (nil))) |
| 71 | +row = \ n xs . map (col n) xs |
| 72 | +rowS = \ n xs . cons (row n xs) (cons (row (succ n) xs) (cons (row (succ (succ n)) xs) (nil))) |
| 73 | +chunk = \ a b xs . rowS a (colS b xs) |
| 74 | +append = \ as bs . null as bs (cons (head as) (append (tail as) bs)) |
| 75 | +concat = foldr append nil |
| 76 | +eq = \ a b . isZ a (isZ b) (isZ b false (eq (pred a) (pred b))) |
| 77 | +all = foldr (\ a b . a b false) true |
| 78 | +allf = \ f xs . all (map f xs) |
| 79 | +</textarea></form> |
| 80 | + |
| 81 | + <script> |
| 82 | + var editor = CodeMirror.fromTextArea(document.getElementById("code"), { |
| 83 | + lineNumbers: true, |
| 84 | + matchBrackets: true, |
| 85 | + theme: "3024-night", |
| 86 | + specialChars: /\\/, |
| 87 | + specialCharPlaceholder: () => { |
| 88 | + const elem = document.createElement("span"); |
| 89 | + elem.setAttribute("cm-text", "\\"); |
| 90 | + elem.innerHTML = "λ"; |
| 91 | + return elem; |
| 92 | + } |
| 93 | + }); |
| 94 | + editor.setSize(500, 500); |
| 95 | + </script> |
| 96 | + |
| 97 | + <p><strong>MIME types defined:</strong> <code>text/lambda-calc</code>.</p> |
| 98 | + </article> |
0 commit comments