Study the following expression. It contains an error guard ::
and the primitive functions format ⍕
and execute ⍎
.
)ns Names ⍝ Create a namespace called Names
Names.vn←({2 6::0 ⋄ ⍎(⎕UCS ⍵),'←',⍕⍵}¨⍳1E4)~0 ⍝ Valid Naming Character Codes
Which two errors are trapped by the error guard?
⎕AV
is the list of characters which was used before Unicode was introduced.
How many valid naming characters are in ⎕AV
?
When are digits ⎕D
not allowed in names?
Why is 9109 9054
printed to the session when the expression is run?
Another way to find valid naming characters is to filter ⎕AV
using ⎕NC
.
Names.avn←⎕AV/⍨0≤⎕NC⍪⎕AV ⍝ ⎕AVU Valid Naming Characters
How do Names.vn
and Names.avn
differ?
Assign values at specified indices.
t←4 4⍴'some sample text'
t[⍸t∊'aeiou']←'!'
Define n←5 5⍴⍳25
in your workspace.
n
to 0
.
For example, (2 2↓n)←0
.Experiment with the following expressions, paying particular attention to the name f← array
construct.
salaries←18250 42500 56000 57250 48640
codes←'ACDDC'
salaries×←1.1
salaries[⍸codes='C']×←1.05
a←⎕A
(3↑a),←'abcd'
Monadic functions take a single right argument array as input. Dyadic functions take two argument arrays.
Monadic operators take a single left operand which can be a function or an array (as in +/
where plus +
is the function operand and reduce /
is the operator).
Dyadic operators take two operands which could be functions or arrays depending on the operator’s definition.
Selective and indexed assignment methods will change the values of variables. The “at” operator @
merges two arrays at specified indices and returns a new array.
If a function right operand returns a boolean array when applied to ⍵
(e.g. 3=1 3 5
) then ones 1
in the boolean array determine where scalars of ⍺
are inserted.
('∆⍥'@{⍵∊'AEIOU'})2 3⍴'DYALOG'
('∆⍥'@1)2 3⍴'DYALOG'
(' '@2 3 4)'DYALOG'
(' '@(1 2)(1 3)(2 1))2 3⍴'DYALOG'
Generally, the left operand to @
is a function applied to scalars in ⍵
specified by a right operand array of indices; or a boolean array returned by a right operand function.
{1↓(1∘⎕C@{¯1⌽' '=⍵})' ',⍵}'my excellent heading'
Distributed assignment or strand assignment allows multiple names to be defined using a single assignment arrow ←
.
(max min avg)←{(⌈⌿⍵)(⌊⌿⍵)((+⌿÷≢)⍵)}3 1 4 1 5
i Note: Strand assignment does not require names to be parenthesised, but we strongly recommend it for clarity.
We can assign items in nest
to the three variables s←'A'
v←1 2 3
and m←3 3⍴⍳9
using a single assignment arrow.
nest←('A'(1 2 3))(3 3⍴⍳9)
((s v) m)←nest