59 lines
1.3 KiB
HTML
59 lines
1.3 KiB
HTML
|
<h2>Comments</h2>
|
||
|
<pre><code>NB. This is a comment</code></pre>
|
||
|
|
||
|
<h2>Strings</h2>
|
||
|
<pre><code>'This is a string.'
|
||
|
'This is a string with ''quotes'' in it.'</code></pre>
|
||
|
|
||
|
<h2>Numbers</h2>
|
||
|
<pre><code>2.3e2 2.3e_2 2j3
|
||
|
2p1 1p_1
|
||
|
1x2 2x1 1x_1
|
||
|
2e2j_2e2 2e2j2p1 2ad45 2ar0.785398
|
||
|
16b1f 10b23 _10b23 1e2b23 2b111.111</code></pre>
|
||
|
|
||
|
<h2>Verbs</h2>
|
||
|
<pre><code>%4
|
||
|
3%4
|
||
|
,b
|
||
|
'I';'was';'here'
|
||
|
3 5$'wake read lamp '</code></pre>
|
||
|
|
||
|
<h2>Adverbs</h2>
|
||
|
<pre><code>1 2 3 */ 4 5 6 7
|
||
|
'%*'(1 3;2 _1)} y</code></pre>
|
||
|
|
||
|
<h2>Conjunctions</h2>
|
||
|
<pre><code>10&^. 2 3 10 100 200
|
||
|
+`*
|
||
|
+:@*: +/ -:@%:</code></pre>
|
||
|
|
||
|
<h2>Examples</h2>
|
||
|
<pre><code>NB. The following functions E1, E2 and E3
|
||
|
NB. interchange two rows of a matrix,
|
||
|
NB. multiply a row by a constant,
|
||
|
NB. and add a multiple of one row to another:
|
||
|
|
||
|
E1=: <@] C. [
|
||
|
E2=: f`g`[}
|
||
|
E3=: F`g`[}
|
||
|
f=: {:@] * {.@] { [
|
||
|
F=: [: +/ (1:,{:@]) * (}:@] { [)
|
||
|
g=: {.@]
|
||
|
M=: i. 4 5
|
||
|
M;(M E1 1 3);(M E2 1 10);(M E3 1 3 10)</code></pre>
|
||
|
|
||
|
<pre><code>NB. Implementation of quicksort
|
||
|
|
||
|
sel=: adverb def 'u # ['
|
||
|
|
||
|
quicksort=: verb define
|
||
|
if. 1 >: #y do. y
|
||
|
else.
|
||
|
(quicksort y <sel e),(y =sel e),quicksort y >sel e=.y{~?#y
|
||
|
end.
|
||
|
)</code></pre>
|
||
|
|
||
|
<pre><code>NB. Implementation of quicksort (tacit programming)
|
||
|
|
||
|
quicksort=: (($:@(<#[), (=#[), $:@(>#[)) ({~ ?@#)) ^: (1<#)</code></pre>
|