# Dyalog Primer - Primitive Operators

##
Exploration

+/⍳5

-/⍳5

×/⍳5

2+/⍳5

2×/⍳5

+\⍳5

×\⍳5

2+\⍳5

(⍳5)∘.+⍳2

(⍳2)∘.+⍳5

(⍳2)∘.×⍳5

(3 4⍴⍳12)+.×4 3⍴⍳12

(3 4⍴⍳12)+.=4 3⍴⍳12

(3 4⍴⍳12)+[1]⍳4

(3 4⍴⍳12)+[0]⍳3

⍴¨(⍳5) 'abc'

2 1⌷¨'abc' 'def'
##
Discussion

- Operators
are distinct from functions:
- Functions
take data as arguments and return data as results
- Operators
take data and/or functions as operands, producing a derived function;
the derived function returns data as a result

- There
are fewer primitive operators than there are primitive functions.
- The
syntax of operators is a little less consistent than the syntax of
functions.
- Notice
the value of abstraction - inner product is a much more valuable
construct than having a "matrix multiply" primitive, for example.
- Look
at when and how you use "each" - it implies a loop and you may be
falling into scalar thinking.
- Purists may quibble about Dyalog's Modified Assignment operator (is Assignment strictly a function?)

Further reading:- Dyalog Language Reference
- Operator Syntax
- Commute Each Reduction Span Spawn
- Axis Composition Inner Product Outer Product
- Modified Assignment

Exercises:- Given a matrix a, write an expression equivalent to (1+⍴a)⍴a which does not contain parentheses
- Given
a character matrix a, write an expression which returns 1 for each row
which matches a given vector w (assume that a and w are appropriately
shaped).
- Each is "handy" but can lead to "pepperpot code such as +/¨⍳¨2 4 6, use the Compose operator to write an equivalent statement containing only a single Each
- Write
expressions to add a (correctly-shaped) vector to each row of a matrix,
and another expression to add a vector to each column
- Write an expression which returns a 1 for every row of a character matrix which contains a (shorter) character vector.