Diamond: Difference between revisions

From NARS2000
Jump to navigationJump to search
No edit summary
(expanded description, added example)
 
(7 intermediate revisions by one other user not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
<h1> {diamond} &mdash; (Replace this with Meaning of symbol) &mdash; Keystroke ?ALT+X &mdash; Character 0000</h1>
{{Article header
|sym={diamond}
|def=Statement separator
|ks=ALT+` (Accent grave)
|char=8900 or x22C4
|kb=[[File:APLKB-Diamond.png]]}}
 
==Usage==
==Usage==
==Example==
While the diamond operator ('''<big><big>{diamond}</big></big>''') can be used in an immediate statement to the Session Manager, it is most commonly used in a [[functions|function]] to start a new statement '''on the same''' physical line-row of user-code. It is used similarly to the semi colon ('''<big>;</big>''') in C, Pascal, PHP and many other languages, or the colon ('''<big>:</big>''') and backslash ('''<big>\</big>''') in some versions of Basic. It allows another statement to be concisely set on the same line.
==See Also==
 
'''Note:''' The '''<big><big>{diamond}</big></big>''' operator <u>cannot</u> be used after a [[lamp]] (<big><big>{lamp}</big></big>) comment operator appears on the same line, as all characters after <big><big>{lamp}</big></big> are ignored.
 
'''Also note''' the '''<big><big>{diamond}</big></big>''' operator represents an <u>exception to the rule</u> that APL's interpreter executes from right to left, since the ''leftmost APL statement'' is executed BEFORE the adjacent APL statement after the next '''<big><big>{diamond}</big></big>''' operator and so on. Each APL statement is executed sequentially '''as if''' listed on multiple lines. The '''<big><big>{diamond}</big></big>''' 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.<br/>
:<code><big>{goto}(k{ge}1)/Xr {diamond} K{:=}1<br/>Xr: &nbsp; &nbsp; ⍝This branch/goto Label is deliberately placed <u>first</u> on its own line!</big></code><br/>
It is the same as
:<code><big>{goto}(k{ge}1)/Xr <br/> K{:=}1<br/>Xr:</big></code><br/>


The following represents more <u>condensed</u> ''':for ... :endfor''' control structure in a user-function than if it were shown in four separate lines:<br><font color=purple><strong>
<code>
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.
</code></strong></font>


{{Language Toolbar}}
{{Article footer}}
[[Category:Mouse Group 11|D]]
{{Symbol footer|11|D}}
[[Category:Symbols|D]]

Latest revision as of 22:03, 21 February 2015

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

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

[[Category:Mouse Group {{{1}}}|{{{2}}}]]