|
1 |
| - |
2 |
| -<!doctype html> |
3 |
| -<html> |
4 |
| - <head> |
5 |
| - <meta name="generator" content="Hugo 0.130.0"> |
6 |
| - <meta charset="UTF-8" /> |
7 |
| - <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
8 |
| - <link rel="stylesheet" href="/main.min.css" /> |
9 |
| - <title>Cognate: Readable and concise concatenative programming</title> |
10 |
| - </head> |
11 |
| - <body> |
12 |
| - |
13 |
| - <main> |
14 |
| - |
15 |
| -<h1 id="cognate">Cognate</h1> |
16 |
| -<h2 id="readable-and-concise-concatenative-programming">Readable and concise concatenative programming</h2> |
17 |
| -<div class="code"><pre><code><span style='font-style: italic;color: #969896'>~~ Fizzbuzz in Cognate</span> |
18 |
| - |
19 |
| -<span style='color: #0086b3'>Def</span> <span style='color: #795da3'>Multiple</span> <span style='color: #333333'>as</span> <span style='color: #4e4e4e'>(</span><span style='color: #183691'>Zero?</span> <span style='color: #183691'>Modulo</span><span style='color: #4e4e4e'>)</span>; |
20 |
| - |
21 |
| -<span style='color: #0086b3'>Def</span> <span style='color: #795da3'>Fizzbuzz</span> |
22 |
| - <span style='color: #a71d5d'>Case</span> <span style='color: #4e4e4e'>(</span><span style='color: #795da3'>Multiple</span> <span style='color: #333333'>of</span> <span style='color: #0086b3'>15</span><span style='color: #4e4e4e'>)</span> <span style='color: #333333'>is</span> <span style='color: #183691'>"fizzbuzz"</span> |
23 |
| - <span style='color: #a71d5d'>Case</span> <span style='color: #4e4e4e'>(</span><span style='color: #795da3'>Multiple</span> <span style='color: #333333'>of</span> <span style='color: #0086b3'>3</span><span style='color: #4e4e4e'>)</span> <span style='color: #333333'>is</span> <span style='color: #183691'>"fizz"</span> |
24 |
| - <span style='color: #a71d5d'>Case</span> <span style='color: #4e4e4e'>(</span><span style='color: #795da3'>Multiple</span> <span style='color: #333333'>of</span> <span style='color: #0086b3'>5</span><span style='color: #4e4e4e'>)</span> <span style='color: #333333'>is</span> <span style='color: #183691'>"buzz"</span> |
25 |
| - <span style='color: #333333'>otherwise</span> <span style='color: #4e4e4e'>(</span><span style='color: #4e4e4e'>)</span>; |
26 |
| - |
27 |
| -<span style='color: #a71d5d'>For</span> <span style='color: #333333'>each</span> <span style='color: #333333'>in</span> <span style='color: #183691'>Range</span> <span style='color: #0086b3'>1</span> <span style='color: #333333'>to</span> <span style='color: #0086b3'>100</span> <span style='color: #4e4e4e'>(</span><span style='color: #183691'>Print</span> <span style='color: #795da3'>Fizzbuzz</span><span style='color: #4e4e4e'>)</span> |
28 |
| -</code></pre></div><p>Cognate is a project aiming to create a human readable programming language with as little syntax as possible. Where natural language programming usually uses many complex syntax rules, instead Cognate takes them away. What it adds is simple, a way to embed comments into statements.</p> |
29 |
| -<div class="code"><pre><code><span style='font-style: italic;color: #969896'>~~ Towers of Hanoi in Cognate</span> |
30 |
| - |
31 |
| -<span style='color: #0086b3'>Def</span> <span style='color: #795da3'>Move</span> <span style='color: #333333'>discs</span> <span style='color: #333333'>as</span> <span style='color: #4e4e4e'>(</span> |
32 |
| - |
33 |
| - <span style='color: #0086b3'>Let</span> <span style='color: #795da3'>N</span> <span style='color: #333333'>be</span> <span style='color: #333333'>number</span> <span style='color: #333333'>of</span> <span style='color: #333333'>discs</span>; |
34 |
| - <span style='color: #0086b3'>Let</span> <span style='color: #795da3'>A</span> <span style='color: #333333'>be</span> <span style='color: #333333'>first</span> <span style='color: #333333'>rod</span>; |
35 |
| - <span style='color: #0086b3'>Let</span> <span style='color: #795da3'>B</span> <span style='color: #333333'>be</span> <span style='color: #333333'>second</span> <span style='color: #333333'>rod</span>; |
36 |
| - <span style='color: #0086b3'>Let</span> <span style='color: #795da3'>C</span> <span style='color: #333333'>be</span> <span style='color: #333333'>third</span> <span style='color: #333333'>rod</span>; |
37 |
| - |
38 |
| - <span style='color: #a71d5d'>Unless</span> <span style='color: #183691'>Zero?</span> <span style='color: #795da3'>N</span> <span style='color: #4e4e4e'>(</span> |
39 |
| - <span style='color: #795da3'>Move</span> <span style='font-weight: bold;color: #4e4e4e'>-</span> <span style='color: #0086b3'>1</span> <span style='color: #795da3'>N</span> <span style='color: #333333'>discs</span> <span style='color: #333333'>from</span> <span style='color: #795da3'>A</span> <span style='color: #333333'>via</span> <span style='color: #795da3'>C</span> <span style='color: #333333'>to</span> <span style='color: #795da3'>B</span>; |
40 |
| - <span style='color: #183691'>Prints</span> <span style='color: #4e4e4e'>(</span><span style='color: #183691'>"Move disc "</span> <span style='color: #795da3'>N</span> <span style='color: #183691'>" from "</span> <span style='color: #795da3'>A</span> <span style='color: #183691'>" to "</span> <span style='color: #795da3'>C</span><span style='color: #4e4e4e'>)</span>; |
41 |
| - <span style='color: #795da3'>Move</span> <span style='font-weight: bold;color: #4e4e4e'>-</span> <span style='color: #0086b3'>1</span> <span style='color: #795da3'>N</span> <span style='color: #333333'>discs</span> <span style='color: #333333'>from</span> <span style='color: #795da3'>B</span> <span style='color: #333333'>via</span> <span style='color: #795da3'>A</span> <span style='color: #333333'>to</span> <span style='color: #795da3'>C</span>; |
42 |
| - <span style='color: #4e4e4e'>)</span> |
43 |
| -<span style='color: #4e4e4e'>)</span>; |
44 |
| - |
45 |
| -<span style='color: #795da3'>Move</span> <span style='color: #0086b3'>5</span> <span style='color: #333333'>discs</span> <span style='color: #333333'>from</span> <span style='color: #183691'>"a"</span> <span style='color: #333333'>via</span> <span style='color: #183691'>"b"</span> <span style='color: #333333'>to</span> <span style='color: #183691'>"c"</span> |
46 |
| -</code></pre></div><p>As you can see, Cognate ignores words starting with lowercase letters, allowing them to be used to describe functionality and enhance readability. This makes Cognate codebases intuitive and maintainable.</p> |
47 |
| -<div class="code"><pre><code><span style='font-style: italic;color: #969896'>~~ Square numbers in Cognate</span> |
48 |
| - |
49 |
| -<span style='color: #0086b3'>Def</span> <span style='color: #795da3'>Square</span> <span style='color: #333333'>as</span> <span style='color: #4e4e4e'>(</span><span style='font-weight: bold;color: #4e4e4e'>*</span> <span style='color: #183691'>Twin</span><span style='color: #4e4e4e'>)</span>; |
50 |
| -<span style='color: #183691'>Map</span> <span style='color: #4e4e4e'>(</span><span style='color: #795da3'>Square</span><span style='color: #4e4e4e'>)</span> <span style='color: #333333'>over</span> <span style='color: #183691'>Range</span> <span style='color: #0086b3'>1</span> <span style='color: #333333'>to</span> <span style='color: #0086b3'>10</span>; |
51 |
| -<span style='color: #183691'>Print</span> |
52 |
| -</code></pre></div><p>Cognate is a stack-oriented programming language similar to Forth or Factor, except statements are evaluated right to left. This gives the expressiveness of concatenative programming as well as the readability of prefix notation. Statements can be delimited at arbitrary points, allowing them to read as sentences would in English.</p> |
53 |
| -<div class="code"><pre><code><span style='font-style: italic;color: #969896'>~~ Prime numbers in Cognate</span> |
54 |
| - |
55 |
| -<span style='color: #0086b3'>Def</span> <span style='color: #795da3'>Factor</span> <span style='color: #4e4e4e'>(</span><span style='color: #183691'>Zero?</span> <span style='color: #183691'>Modulo</span> <span style='color: #183691'>Swap</span><span style='color: #4e4e4e'>)</span>; |
56 |
| - |
57 |
| -<span style='color: #0086b3'>Def</span> <span style='color: #795da3'>Primes</span> <span style='color: #4e4e4e'>(</span> |
58 |
| - <span style='color: #0086b3'>Let</span> <span style='color: #795da3'>U</span> <span style='color: #333333'>is</span> <span style='color: #333333'>upper</span> <span style='color: #333333'>bound</span>; |
59 |
| - <span style='color: #333333'>initially</span> <span style='color: #794da3'>List</span> <span style='color: #4e4e4e'>(</span><span style='color: #4e4e4e'>)</span>; |
60 |
| - <span style='color: #a71d5d'>For</span> <span style='color: #183691'>Range</span> <span style='color: #0086b3'>2</span> <span style='color: #333333'>to</span> <span style='color: #795da3'>U</span> <span style='color: #4e4e4e'>(</span> |
61 |
| - <span style='color: #0086b3'>Let</span> <span style='color: #795da3'>P</span> <span style='color: #333333'>is</span> <span style='color: #333333'>potential</span> <span style='color: #333333'>prime</span>; |
62 |
| - <span style='color: #0086b3'>Let</span> <span style='color: #795da3'>Found</span> <span style='color: #333333'>be</span> <span style='color: #333333'>list</span> <span style='color: #333333'>of</span> <span style='color: #333333'>found</span> <span style='color: #333333'>primes</span>; |
63 |
| - <span style='color: #0086b3'>Let</span> <span style='color: #795da3'>To-check</span> <span style='color: #333333'>be</span> <span style='color: #a71d5d'>Take-while</span> <span style='color: #4e4e4e'>(</span><span style='font-weight: bold;color: #4e4e4e'><=</span> <span style='color: #183691'>Sqrt</span> <span style='color: #795da3'>P</span><span style='color: #4e4e4e'>)</span> <span style='color: #795da3'>Found</span>; |
64 |
| - <span style='color: #a71d5d'>When</span> <span style='color: #183691'>All</span> <span style='color: #4e4e4e'>(</span><span style='font-weight: bold;color: #4e4e4e'>Not</span> <span style='color: #795da3'>Factor</span> <span style='color: #333333'>of</span> <span style='color: #795da3'>P</span><span style='color: #4e4e4e'>)</span> <span style='color: #795da3'>To-check</span> <span style='color: #4e4e4e'>(</span> |
65 |
| - <span style='color: #183691'>Append</span> <span style='color: #795da3'>P</span> |
66 |
| - <span style='color: #4e4e4e'>)</span> <span style='color: #333333'>to</span> <span style='color: #795da3'>Found</span> |
67 |
| - <span style='color: #4e4e4e'>)</span> |
68 |
| -<span style='color: #4e4e4e'>)</span>; |
69 |
| - |
70 |
| -<span style='color: #183691'>Print</span> <span style='color: #795da3'>Primes</span> <span style='color: #333333'>up</span> <span style='color: #333333'>to</span> <span style='color: #0086b3'>1000</span>; |
71 |
| -</code></pre></div><p>Cognate borrows from other concatenative languages, but also adds unique features of its own.</p> |
72 |
| -<ul> |
73 |
| -<li>Point-free functions</li> |
74 |
| -<li>Operation chaining</li> |
75 |
| -<li>Multiple return values</li> |
76 |
| -<li>Combinator oriented programming</li> |
77 |
| -<li>Predicate pattern matching</li> |
78 |
| -<li>Natural language programming</li> |
79 |
| -</ul> |
80 |
| -<p>Interested? Read the <a href="/learn/">tutorial</a>, check out the <a href="https://cognate-playground.hedy.dev/">interactive web playground</a>, or visit our <a href="https://github.com/cognate-lang/cognate">GitHub repository</a>.</p> |
81 |
| - |
82 |
| - |
83 |
| - </main> |
84 |
| - <br /><br /><br /> |
85 |
| - </body> |
86 |
| -</html> |
| 1 | +<!doctype html><html><head><meta name=generator content="Hugo 0.130.0"><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><link rel=stylesheet href=wow/main.min.css><title>About</title></head><body><main><h1 id=cognate>Cognate</h1><h2 id=readable-and-concise-concatenative-programming>Readable and concise concatenative programming</h2><div class=code><pre><code> |
| 2 | +~~ Fizzbuzz in Cognate |
| 3 | + |
| 4 | +Def Multiple as (Zero? Modulo); |
| 5 | + |
| 6 | +Def Fizzbuzz |
| 7 | + Case (Multiple of 15) is "fizzbuzz" |
| 8 | + Case (Multiple of 3) is "fizz" |
| 9 | + Case (Multiple of 5) is "buzz" |
| 10 | + otherwise (); |
| 11 | + |
| 12 | +For each in Range 1 to 100 (Print Fizzbuzz) |
| 13 | +</code></pre></div><p>Cognate is a project aiming to create a human readable programming language with as little syntax as possible. Where natural language programming usually uses many complex syntax rules, instead Cognate takes them away. What it adds is simple, a way to embed comments into statements.</p><div class=code><pre><code> |
| 14 | +~~ Towers of Hanoi in Cognate |
| 15 | + |
| 16 | +Def Move discs as ( |
| 17 | + |
| 18 | + Let N be number of discs; |
| 19 | + Let A be first rod; |
| 20 | + Let B be second rod; |
| 21 | + Let C be third rod; |
| 22 | + |
| 23 | + Unless Zero? N ( |
| 24 | + Move - 1 N discs from A via C to B; |
| 25 | + Prints ("Move disc " N " from " A " to " C); |
| 26 | + Move - 1 N discs from B via A to C; |
| 27 | + ) |
| 28 | +); |
| 29 | + |
| 30 | +Move 5 discs from "a" via "b" to "c" |
| 31 | +</code></pre></div><p>As you can see, Cognate ignores words starting with lowercase letters, allowing them to be used to describe functionality and enhance readability. This makes Cognate codebases intuitive and maintainable.</p><div class=code><pre><code> |
| 32 | +~~ Square numbers in Cognate |
| 33 | + |
| 34 | +Def Square as (* Twin); |
| 35 | +Map (Square) over Range 1 to 10; |
| 36 | +Print |
| 37 | +</code></pre></div><p>Cognate is a stack-oriented programming language similar to Forth or Factor, except statements are evaluated right to left. This gives the expressiveness of concatenative programming as well as the readability of prefix notation. Statements can be delimited at arbitrary points, allowing them to read as sentences would in English.</p><div class=code><pre><code> |
| 38 | +~~ Prime numbers in Cognate |
| 39 | + |
| 40 | +Def Factor (Zero? Modulo Swap); |
| 41 | + |
| 42 | +Def Primes ( |
| 43 | + Let U is upper bound; |
| 44 | + initially List (); |
| 45 | + For Range 2 to U ( |
| 46 | + Let P is potential prime; |
| 47 | + Let Found be list of found primes; |
| 48 | + Let To-check be Take-while (<= Sqrt P) Found; |
| 49 | + When All (Not Factor of P) To-check ( |
| 50 | + Append P |
| 51 | + ) to Found |
| 52 | + ) |
| 53 | +); |
| 54 | + |
| 55 | +Print Primes up to 1000; |
| 56 | +</code></pre></div><p>Cognate borrows from other concatenative languages, but also adds unique features of its own.</p><ul><li>Point-free functions</li><li>Operation chaining</li><li>Multiple return values</li><li>Combinator oriented programming</li><li>Predicate pattern matching</li><li>Natural language programming</li></ul><p>Interested? Read the <a href=/learn/>tutorial</a>, check out the <a href=https://cognate-playground.hedy.dev/>interactive web playground</a>, or visit our <a href=https://github.com/cognate-lang/cognate>GitHub repository</a>.</p></main><br><br><br></body></html> |
0 commit comments