Diamond

From NARS2000
Jump to: navigation, search

⋄ — Statement separator — Keystroke ALT+` (Accent grave) — Character 8900 or x22C4

[[file:APLKB-Diamond.png]]
[[File:{{{kb2}}}]]

Usage

While the diamond operator () can be used in an immediate statement to the Session Manager, it is most commonly used in a function to start a new statement on the same physical line-row of user-code. It is used similarly to the semi colon (;) in C, Pascal, PHP and many other languages, or the colon (:) and backslash (\) in some versions of Basic. It allows another statement to be concisely set on the same line.

Note: The operator cannot be used after a lamp () comment operator appears on the same line, as all characters after are ignored.

Also note the operator represents an exception to the rule that APL's interpreter executes from right to left, since the leftmost APL statement is executed BEFORE the adjacent APL statement after the next operator and so on. Each APL statement is executed sequentially as if listed on multiple lines. The operator also helps condense APL code since fewer visual lines will contain the same amount of APL coding - and in many instances it can result in cleaner, or easier-to-read-and-understand APL code.

Examples

In the first example, the variable K is tested to see if it is greater than or equal to 1. If the test fails, k is set to 1.

→(k≥1)/Xr ⋄ K←1
Xr:     ⍝This branch/goto Label is deliberately placed first on its own line!

It is the same as

→(k≥1)/Xr
K←1
Xr:

The following represents more condensed :for ... :endfor control structure in a user-function than if it were shown in four separate lines:
A←1 3 5 7 ⋄ :for ii :in ⍳⍴A ⋄ A[ii]←A[ii]*2 ⋄ :endfor ⍝Easier to maintain code if segmented well, esp. when surrounded by long code blocks.


See Also
System Commands System Variables and Functions Operators
Keyboard
A+S
Alt ¨ ¯ < > × ÷
Sh ~ ! @ # $ % ^ & * ( ) _ +
Key ` 1 2 3 4 5 6 7 8 9 0 - =
A+S
Alt ? π
Sh Q W E R T Y U I O P { } |
Key q w e r t y u i o p [ ] \
A+S §
Alt
Sh A S D F G H J K L : "
Key a s d f g h j k l ; '
A+S
Alt
Sh Z X C V B N M < > ?
Key z x c v b n m , . /
NARS 2000 Lang
Tool
Bar
+ - × ÷ * ! ? |
= < >
~ § π .. ,
/ \ ¨ .
_ ¯ b e g p r v x