Dyalog Primer - Primitive Functions
2 3 + 4 5
2+3 4 5
2 3 + 3 4 5
⍴(5 6⍴⍳30)×5 6⍴⍳30
DISPLAY ⊂2 3⍴⊂⍳6
⊃'abc' 'def' 'ghi'
⊃'abc' 'def' 'ghi'
1 2⌷4 5⍴⍳20
(1 2) (3 4)⌷4 5⍴⍳20
1 (2 3)⌷4 5⍴⍳20
2⌷'abc' 'def' 'ghi' 'jkl'
2⊃'abc' 'def' 'ghi' 'jkl'
(2⊃'abc' 'def' 'ghi' 'jkl')≡⊃2⌷'abc' 'def' 'ghi' 'jkl'
0 1 1 0 0/⍳5
functions are the "doing" building blocks of APL - "verbs" in the
- Two types:
functions use a one-to-one relationship of left and right arguments -
they work on the scalar elements.
functions have more complex behaviour, typically the left argument is
used to control the transformation of data elements in the right
- Scalar functions automatically
make left- or right- scalar arguments conform to the other argument.
has no functional hierarchy - all functions (including those you define
yourself) are equal.
order of execution is determined by the rule that the right argument of
a function is the result of the entire expression to the right of the
function. One of the conventions of mathematics, for example
- Notice how this execution rule leads
left-to-right reading )sometimes misleadingly referred to as "right to
- You can force disruption of
left-to-right reading by using parentheses.
overuse parentheses, they have other - more important - uses than
breaking up reading flow.
no benefit in writing expressions that are too complicated for you to
read yourself. If it's that hard, do it on more than one line.
alert to emulation level, it can make the same "appearance" do
- The indexing function is "purer"
than the older bracket-indexing; and has advantages.
the difference between "index" and "pick".
a convention that 1 means "true" and 0 means "false" - good to carry
this through to expressions you write yourself.
isn't the only way to work on selected elements, selection is often
more useful and general.
- Primitive Functions - Dyalog Language Reference
- Scalar Functions
- Mixed Functions
- "Puzzle of the Year" -
using all four digits of the year (in order), write expressions to
generate every integer from 1 to 100 inclusive. Calculate the
score for each expression as the number of characters (including
spaces) - for example ×2008 generates 1 and has a score of 5,
⌊20÷08 generates 2 and has a score of 6.
- Write an expression which replaces all values greater than 20 in a random vector of positive integers with the value 0
- Write a series of expressions to do the same value substitution in an arbitrarily-shaped array.
- Write an expression which determines whether a simple vector consists of numbers or characters.
an expression which partitions a random integer vector into parts
beginning with even numbers = for example 1 2 3 3 4 5 would become (1)
(2 3 3) (4 5). How does your expression handle succesive even numbers? What if there are no even numbers?