Skip to content

Commit d7e931c

Browse files
fix fizzbuzz example
1 parent 368dd2b commit d7e931c

File tree

4 files changed

+325
-246
lines changed

4 files changed

+325
-246
lines changed

content/_index.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ title = 'About'
1212
Def Fizzbuzz (
1313
Let N be Of (Integer?);
1414
Def Multiple as (Zero? Modulo Swap N);
15-
Print
16-
If Multiple of 15 then "fizzbuzz"
17-
If Multiple of 3 then "fizz"
18-
If Multiple of 5 then "buzz"
19-
else N
15+
16+
If Multiple of 15 then "fizzbuzz"
17+
If Multiple of 3 then "fizz"
18+
If Multiple of 5 then "buzz"
19+
else N
2020
);
2121
2222
For each in Range 1 to 100 (Print Fizzbuzz);

public/categories/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
<!doctype html>
33
<html>
4-
<head>
4+
<head><script src="/livereload.js?mindelay=10&amp;v=2&amp;port=1313&amp;path=livereload" data-no-instant defer></script>
55
<meta charset="UTF-8" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
77
<link rel="stylesheet" href="/main.min.css" />

public/index.html

+53-48
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<!doctype html>
33
<html>
44
<head>
5-
<meta name="generator" content="Hugo 0.130.0">
5+
<meta name="generator" content="Hugo 0.130.0"><script src="/livereload.js?mindelay=10&amp;v=2&amp;port=1313&amp;path=livereload" data-no-instant defer></script>
66
<meta charset="UTF-8" />
77
<meta name="viewport" content="width=device-width, initial-scale=1.0">
88
<link rel="stylesheet" href="/main.min.css" />
@@ -17,63 +17,68 @@
1717

1818
<h1 id="cognate">Cognate</h1>
1919
<h2 id="readable-and-concise-concatenative-programming">Readable and concise concatenative programming</h2>
20-
<div class="code"><pre><code><span style='font-style: italic;color: #969896'>~~ Fizzbuzz in Cognate</span>
20+
<!--cognate--><div class="code"><pre><code>
21+
~~ Fizzbuzz in Cognate
2122

22-
<span style='color: #0086b3'>Def</span> <span style='color: #795da3'>Fizzbuzz</span> <span style='color: #4e4e4e'>(</span>
23-
<span style='color: #0086b3'>Let</span> <span style='color: #795da3'>N</span> <span style='color: #333333'>be</span> <span style='color: #183691'>Of</span> <span style='color: #4e4e4e'>(</span><span style='color: #183691'>Integer?</span><span style='color: #4e4e4e'>)</span>;
24-
<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: #183691'>Swap</span> <span style='color: #795da3'>N</span><span style='color: #4e4e4e'>)</span>;
25-
<span style='color: #183691'>Print</span>
26-
<span style='color: #a71d5d'>If</span> <span style='color: #795da3'>Multiple</span> <span style='color: #333333'>of</span> <span style='color: #0086b3'>15</span> <span style='color: #333333'>then</span> <span style='color: #183691'>&quot;fizzbuzz&quot;</span>
27-
<span style='color: #a71d5d'>If</span> <span style='color: #795da3'>Multiple</span> <span style='color: #333333'>of</span> <span style='color: #0086b3'>3</span> <span style='color: #333333'>then</span> <span style='color: #183691'>&quot;fizz&quot;</span>
28-
<span style='color: #a71d5d'>If</span> <span style='color: #795da3'>Multiple</span> <span style='color: #333333'>of</span> <span style='color: #0086b3'>5</span> <span style='color: #333333'>then</span> <span style='color: #183691'>&quot;buzz&quot;</span>
29-
<span style='color: #333333'>else</span> <span style='color: #795da3'>N</span>
30-
<span style='color: #4e4e4e'>)</span>;
23+
Def Fizzbuzz (
24+
Let N be Of (Integer?);
25+
Def Multiple as (Zero? Modulo Swap N);
26+
Print
27+
If Multiple of 15 then "fizzbuzz"
28+
If Multiple of 3 then "fizz"
29+
If Multiple of 5 then "buzz"
30+
else N
31+
);
3132

32-
<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>
33-
</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>
34-
<div class="code"><pre><code><span style='font-style: italic;color: #969896'>~~ Towers of Hanoi in Cognate</span>
33+
For each in Range 1 to 100 (Print Fizzbuzz);
34+
</code></pre></div>
35+
<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>
36+
<!--cognate--><div class="code"><pre><code>
37+
~~ Towers of Hanoi in Cognate
3538

36-
<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>
39+
Def Move discs as (
3740

38-
<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>;
39-
<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>;
40-
<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>;
41-
<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>;
41+
Let N be number of discs;
42+
Let A be first rod;
43+
Let B be second rod;
44+
Let C be third rod;
4245

43-
<span style='color: #a71d5d'>Unless</span> <span style='color: #183691'>Zero?</span> <span style='color: #795da3'>N</span> <span style='color: #4e4e4e'>(</span>
44-
<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>;
45-
<span style='color: #183691'>Prints</span> <span style='color: #4e4e4e'>(</span><span style='color: #183691'>&quot;Move disc &quot;</span> <span style='color: #795da3'>N</span> <span style='color: #183691'>&quot; from &quot;</span> <span style='color: #795da3'>A</span> <span style='color: #183691'>&quot; to &quot;</span> <span style='color: #795da3'>C</span><span style='color: #4e4e4e'>)</span>;
46-
<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>;
47-
<span style='color: #4e4e4e'>)</span>
48-
<span style='color: #4e4e4e'>)</span>;
46+
Unless Zero? N (
47+
Move - 1 N discs from A via C to B;
48+
Prints ("Move disc " N " from " A " to " C);
49+
Move - 1 N discs from B via A to C;
50+
)
51+
);
4952

50-
<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'>&quot;a&quot;</span> <span style='color: #333333'>via</span> <span style='color: #183691'>&quot;b&quot;</span> <span style='color: #333333'>to</span> <span style='color: #183691'>&quot;c&quot;</span>
51-
</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>
52-
<div class="code"><pre><code><span style='font-style: italic;color: #969896'>~~ Square numbers in Cognate</span>
53+
Move 5 discs from "a" via "b" to "c";
54+
</code></pre></div>
55+
<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>
56+
<!--cognate--><div class="code"><pre><code>
57+
~~ Square numbers in Cognate
5358

54-
<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>;
55-
<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>;
56-
<span style='color: #183691'>Print</span>
57-
</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>
58-
<div class="code"><pre><code><span style='font-style: italic;color: #969896'>~~ Prime numbers in Cognate</span>
59+
Def Square as (* Twin);
60+
Map (Square) over Range 1 to 10;
61+
Print;
62+
</code></pre></div>
63+
<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>
64+
<!--cognate--><div class="code"><pre><code>
65+
~~ Prime numbers in Cognate
5966

60-
<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>;
67+
Def Factor (Zero? Modulo Swap);
6168

62-
<span style='color: #0086b3'>Def</span> <span style='color: #795da3'>Primes</span> <span style='color: #4e4e4e'>(</span>
63-
<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>;
64-
<span style='color: #333333'>initially</span> <span style='color: #794da3'>List</span> <span style='color: #4e4e4e'>(</span><span style='color: #4e4e4e'>)</span>;
65-
<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>
66-
<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>;
67-
<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>;
68-
<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'>&lt;=</span> <span style='color: #183691'>Sqrt</span> <span style='color: #795da3'>P</span><span style='color: #4e4e4e'>)</span> <span style='color: #795da3'>Found</span>;
69-
<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>
70-
<span style='color: #183691'>Append</span> <span style='color: #795da3'>P</span>
71-
<span style='color: #4e4e4e'>)</span> <span style='color: #333333'>to</span> <span style='color: #795da3'>Found</span>
72-
<span style='color: #4e4e4e'>)</span>
73-
<span style='color: #4e4e4e'>)</span>;
69+
Def Primes (
70+
Fold (
71+
Let I be our potential prime;
72+
Let Primes are the found primes;
73+
Let To-check be Take-while (<= Sqrt I) Primes;
74+
When None (Factor of I) To-check
75+
(Append List (I)) to Primes;
76+
) from List () over Range from 2
77+
);
7478

75-
<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>;
76-
</code></pre></div><p>Cognate borrows from other concatenative languages, but also adds unique features of its own.</p>
79+
Print Primes up to 1000;
80+
</code></pre></div>
81+
<p>Cognate borrows from other concatenative languages, but also adds unique features of its own.</p>
7782
<ul>
7883
<li>Point-free functions</li>
7984
<li>Operation chaining</li>

0 commit comments

Comments
 (0)