APL Wiki logo: Difference between revisions
Jump to navigation
Jump to search
→References
Miraheze>Adám Brudzewsky |
Miraheze>Adám Brudzewsky |
||
Line 76: | Line 76: | ||
</source> | </source> | ||
== A number is a number == | |||
The next step is to halve everything: | |||
<source lang=apl> | |||
.5×4!⍨⍳5 | |||
0.5 2 3 2 0.5 | |||
</source> | |||
Notice how we were dealing with integers until now, but then we multiply by a float (non-integer). In APL, you don't need to worry about numeric data type conversions. All numeric types get automatically promoted and demoted as needed. APL will usually use the most compact internal representation. | |||
== Tables == | |||
Remember the multiplication table from school? | |||
Let's pause for a moment by giving our numbers a name: | |||
<source lang=apl> | |||
1 2 3 4 5∘.×1 2 3 4 5 | |||
1 2 3 4 5 | |||
2 4 6 8 10 | |||
3 6 9 12 15 | |||
4 8 12 16 20 | |||
5 10 15 20 25 | |||
</source> | |||
In fact, any function will do: | |||
<source lang=apl> | |||
1 2 3 4 5∘.+1 2 3 4 5 | |||
2 3 4 5 6 | |||
3 4 5 6 7 | |||
4 5 6 7 8 | |||
5 6 7 8 9 | |||
6 7 8 9 10 | |||
</source> | |||
=== Using an argument twice === | |||
It gets tedious to type the same argument twice. Enter the [[self]]ie operator which shares its symbol with the above-mentioned [[swap]] operator. There's no ambiguity here. ''Swap'' swaps the two arguments, while ''selfie'' uses a single argument twice: | |||
<source lang=apl> | |||
∘.+⍨1 2 3 4 5 | |||
2 3 4 5 6 | |||
3 4 5 6 7 | |||
4 5 6 7 8 | |||
5 6 7 8 9 | |||
6 7 8 9 10 | |||
</source> | |||
We'll use this in our logo expression: | |||
<source lang=apl> | |||
∘.+⍨.5×4!⍨⍳5 | |||
1 2.5 3.5 2.5 1 | |||
2.5 4 5 4 2.5 | |||
3.5 5 6 5 3.5 | |||
2.5 4 5 4 2.5 | |||
1 2.5 3.5 2.5 1 | |||
</source> | |||
== References == | == References == | ||
<references /> | <references /> |