ELI (programming language): Difference between revisions

Content deleted Content added
Wukefe (talk | contribs)
Modified the description of the last example.
Line 32:
</pre>
Exclamation point (!) is an '''interval''' function. It can generate a vector of n integer from 1 to n.
<source lang="q">
<pre>
5 * 2 + 10 // from right to left, 5 * (2 + 10)
60
</presource>
The execution order of ELI is from right to left and all primitive functions have '''equal precedence'''.
<source lang="q">
<pre>
{add: x+y} // short function form
add
Line 44:
1 add !10 // 1+(1..10)
2 3 4 5 6 7 8 9 10 11
</presource>
First, a function <code>add</code> is declared in a short function form. Then, the arguments of the function can take either a scalar or a vector.
<source lang="q">
<pre>
$!10 // rotation
10 9 8 7 6 5 4 3 2 1
</presource>
The rotation operator returns the reverse order of a vector.
<source lang="q">
<pre>
2 3#!6 // 2 dimension array (matrix)
1 2 3
4 5 6
</presource>
A 2-by-3 matrix (or higher dimension array, e.g. <code>2 3 4#!24</code>) can be generated by <code>#</code> with left argument <code>2 3</code>.
<source lang="q">
<pre>
x <- !20 // 1..20
x
Line 63:
(1 = 2|x) / x // get odd numbers from x
1 3 5 7 9 11 13 15 17 19
</presource>
The <code>x</code> is assigned with a vector from 1 to 20. <code>1 = 2|x</code> returns odd number <code>True</code> and even number <code>False</code>. The <code>/</code> is a primitive function for compression which '''picks up''' the value in <code>x</code> corresponding to the <code>True</code> values in its left argument.