You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/learn.md
+30-30
Original file line number
Diff line number
Diff line change
@@ -178,26 +178,26 @@ Now that this (hopefully) makes some sense, we can finally introduce the `If` st
178
178
179
179
```cognate
180
180
Print
181
-
If == X 1 then "foo"
182
-
If == X 2 then "bar"
183
-
else "baz";
181
+
If == X 1 then "foo"
182
+
If == X 2 then "bar"
183
+
else "baz";
184
184
```
185
185
186
186
We can combine this with `Do` to have conditional code execution.
187
187
188
188
```cognate
189
189
Do
190
-
If == X 1 then ( Print "foo" )
191
-
If == X 2 then ( Print "bar" )
192
-
else ( Print "baz" );
190
+
If == X 1 then ( Print "foo" )
191
+
If == X 2 then ( Print "bar" )
192
+
else ( Print "baz" );
193
193
```
194
194
195
195
Now, let's use our knowledge of blocks to define our own control flow function `Thrice`, which should evaluate a block three times in a row. This demonstrates a different use of `Def` in which we bind a block from the stack.
196
196
197
197
```cognate
198
198
Def Thrice as (
199
-
Def F;
200
-
F F F
199
+
Def F;
200
+
F F F
201
201
);
202
202
203
203
Thrice (
@@ -355,9 +355,9 @@ The table type provides an efficient, immutable, unordered mapping between keys
355
355
356
356
```cognate
357
357
Let T be Table (
358
-
"foo" is 1;
359
-
"bar" is Range 2 to 10;
360
-
12 is 13; ~~ Keys can be of any type except box or block
358
+
"foo" is 1;
359
+
"bar" is Range 2 to 10;
360
+
12 is 13; ~~ Keys can be of any type except box or block
361
361
);
362
362
363
363
Print . "foo" T;
@@ -368,9 +368,9 @@ Print . "bar" T;
368
368
369
369
```cognate
370
370
Def Remove-baz (
371
-
Remove "baz"
372
-
from Of (Has "baz")
373
-
Of (Table?);
371
+
Remove "baz"
372
+
from Of (Has "baz")
373
+
Of (Table?);
374
374
);
375
375
376
376
Insert "baz" is Range 11 to 100 into T;
@@ -400,12 +400,12 @@ Earlier when we defined loops, you may have noticed something missing -- the bre
400
400
Let I be 1;
401
401
402
402
Begin (
403
-
Def Break;
404
-
While (True) (
405
-
Print Unbox I;
406
-
Set I to + 1 of Unbox I;
407
-
When == 101 Unbox I ( Break out of the begin );
408
-
)
403
+
Def Break;
404
+
While (True) (
405
+
Print Unbox I;
406
+
Set I to + 1 of Unbox I;
407
+
When == 101 Unbox I ( Break out of the begin );
408
+
)
409
409
);
410
410
```
411
411
@@ -415,16 +415,16 @@ This essentially allows any control flow to have a break statement, not just loo
<description>Learn Cognate A brief introduction to the language Install First install CognaC the Cognate Compiler from here using the provided instructions. Currently CognaC will run on recent Linux or Mac systems. Windows users can install it onto the Windows Subsystem for Linux &ndash; native Windows support is planned.
Invoking CognaC is simple. If you have a file named foo.cog containing a Cognate program, it can be compiled into an executable named foo with the following command.</description>
<description>Prelude Drop Discard the top stack item.
Print Drop "foo""bar"; Source Def Drop as ( Let X ); Swap Swaps the top two stack items.
Print Swap 1 2; Source Def Swap as ( Let X ; Let Y ; Y X ); Do Execute a block.
Do ( Print "hello world!" ); Source Def Do as ( Def F ; F ); Any? Takes a parameter of any type and returns True</description>
<description>Prelude Drop Discard the top stack item.
Print Drop "foo""bar"; Source Def Drop as ( Let X ); Swap Swaps the top two stack items.
Print Swap 1 2; Source Def Swap as ( Let X ; Let Y ; Y X ); Do Execute a block.
Do ( Print "hello world!" ); Source Def Do as ( Def F ; F ); Any? Takes a parameter of any type and returns True</description>
0 commit comments