| 1 |
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
| 2 |
<html> |
| 3 |
|
| 4 |
<head> |
| 5 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
<title>GNU APL</title> |
| 11 |
|
| 12 |
<meta name="description" content="GNU APL"> |
| 13 |
<meta name="keywords" content="GNU APL"> |
| 14 |
<meta name="resource-type" content="document"> |
| 15 |
<meta name="distribution" content="global"> |
| 16 |
<meta name="Generator" content="makeinfo"> |
| 17 |
<meta name="viewport" content="width=device-width,initial-scale=1"> |
| 18 |
|
| 19 |
<link href="#Top" rel="start" title="Top"> |
| 20 |
<link href="#SEC_Contents" rel="contents" title="Table of Contents"> |
| 21 |
<link href="#Installing-and-Starting-GNU-APL" rel="next" title="Installing and Starting GNU APL"> |
| 22 |
<style type="text/css"> |
| 23 |
<!-- |
| 24 |
|
| 25 |
/* CSS for HTML output of apl.texi */ |
| 26 |
|
| 27 |
|
| 28 |
a.copiable-anchor {visibility: hidden; text-decoration: none; line-height: 0em} |
| 29 |
a.summary-letter {text-decoration: none} |
| 30 |
blockquote.indentedblock {margin-right: 0em} |
| 31 |
div.display {margin-left: 3.2em} |
| 32 |
div.example {margin-left: 3.2em} |
| 33 |
kbd {font-style: oblique} |
| 34 |
pre.display {font-family: inherit} |
| 35 |
pre.format {font-family: inherit} |
| 36 |
pre.menu-comment {font-family: serif} |
| 37 |
pre.menu-preformatted {font-family: serif} |
| 38 |
span.nolinebreak {white-space: nowrap} |
| 39 |
span.roman {font-family: initial; font-weight: normal} |
| 40 |
span.sansserif {font-family: sans-serif; font-weight: normal} |
| 41 |
span:hover a.copiable-anchor {visibility: visible} |
| 42 |
ul.no-bullet {list-style: none} |
| 43 |
pre.example { font-family: "Courier New", monospace; |
| 44 |
font-size: 16 px; font-weight: bold; background: #EEF; |
| 45 |
border: 2px solid black; border-radius: 10px; |
| 46 |
padding: 1em 2em 1em 2em; } |
| 47 |
|
| 48 |
code { font-family: "Courier New", monospace; |
| 49 |
font-size: 16 px; font-weight: bold; } |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
--> |
| 54 |
</style> |
| 55 |
|
| 56 |
|
| 57 |
</head> |
| 58 |
|
| 59 |
<body lang="en"> |
| 60 |
<h1 class="settitle" align="center">GNU APL</h1> |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
<div class="top" id="Top"> |
| 70 |
<div class="header"> |
| 71 |
<p> |
| 72 |
Next: <a href="#Installing-and-Starting-GNU-APL" accesskey="n" rel="next">Installing and Starting GNU APL</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 73 |
</div> |
| 74 |
<span id="GNU-APL-Reference-Manual"></span><h1 class="top">GNU APL Reference Manual</h1> |
| 75 |
|
| 76 |
<p>March 15, 2026. |
| 77 |
This manual briefly documents GNU APL, an interpreter for APL as described |
| 78 |
in ISO standard 13751, aka. "Programming Language APL, Extended". |
| 79 |
</p> |
| 80 |
<p>This manual for GNU APL can be distributed under the terms of the |
| 81 |
GNU Free Documentation License, *Note Chapter 8. |
| 82 |
</p> |
| 83 |
<p>This manual does NOT describe APL itself; there exist a number of good books |
| 84 |
and texts about APL. We would like to refer the reader to the following: |
| 85 |
</p> |
| 86 |
<p>ISO Standard for APL: <br> |
| 87 |
www.math.uwaterloo.ca/~ljdickey/apl-rep/docs/is13751.pdf |
| 88 |
</p> |
| 89 |
<p>Note that the file <b>is13751.pdf</b> above is compressed with <b>gzip</b>, |
| 90 |
therefore it must be expanded with e.g. <b>gunzip</b> before it can be read. |
| 91 |
</p> |
| 92 |
<p>More pointers to APL resources on the Web: <br> |
| 93 |
ftp://rtfm.mit.edu/pub/usenet-by-group/comp.lang.apl/APL_language_FAQ |
| 94 |
</p> |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
<div class="Contents_element" id="SEC_Contents"> |
| 99 |
<h2 class="contents-heading">Table of Contents</h2> |
| 100 |
|
| 101 |
<div class="contents"> |
| 102 |
|
| 103 |
<ul class="no-bullet"> |
| 104 |
<li><a id="toc-Installing-and-Starting-GNU-APL-1" href="#Installing-and-Starting-GNU-APL">1 Installing and Starting GNU APL</a> |
| 105 |
<ul class="no-bullet"> |
| 106 |
<li><a id="toc-Installing-APL-1" href="#Installing-APL">1.1 Installing APL</a></li> |
| 107 |
<li><a id="toc-Starting-APL-1" href="#Starting-APL">1.2 Starting APL</a></li> |
| 108 |
<li><a id="toc-Command-Line-Options-1" href="#Command-Line-Options">1.3 Command Line Options</a></li> |
| 109 |
<li><a id="toc-Configuration-File-for-GNU-APL-1" href="#Configuration-File-for-GNU-APL">1.4 Configuration File for GNU APL</a></li> |
| 110 |
<li><a id="toc-File-Names-and-Paths-1" href="#File-Names-and-Paths">1.5 File Names and Paths</a></li> |
| 111 |
</ul></li> |
| 112 |
<li><a id="toc-Non_002dstandard-GNU-APL-Features-1" href="#Non_002dstandard-GNU-APL-Features">2 Non-standard GNU APL Features</a> |
| 113 |
<ul class="no-bullet"> |
| 114 |
<li><a id="toc-APL-Scripting-1" href="#APL-Scripting">2.1 APL Scripting</a> |
| 115 |
<ul class="no-bullet"> |
| 116 |
<li><a id="toc-Introduction-and-Terminology-1" href="#Introduction-and-Terminology">2.1.1 Introduction and Terminology</a></li> |
| 117 |
<li><a id="toc-Redirect-the-script-file-to-the-stdin-of-the-GNU-APL-interpreter-1" href="#Redirect-the-script-file-to-the-stdin-of-the-GNU-APL-interpreter">2.1.2 Redirect the script file to the stdin of the GNU APL interpreter</a></li> |
| 118 |
<li><a id="toc-Make-the-script-file-executable-1" href="#Make-the-script-file-executable">2.1.3 Make the script file executable</a></li> |
| 119 |
<li><a id="toc-Starting-GNU-APL-Scripts_003a-a-Conclusion-1" href="#Starting-GNU-APL-Scripts_003a-a-Conclusion">2.1.4 Starting GNU APL Scripts: a Conclusion</a></li> |
| 120 |
<li><a id="toc-How-command-line-arguments-are-handled-1" href="#How-command-line-arguments-are-handled">2.1.5 How command line arguments are handled</a></li> |
| 121 |
<li><a id="toc-Helpful-Features-for-Scripting-1" href="#Helpful-Features-for-Scripting">2.1.6 Helpful Features for Scripting</a> |
| 122 |
<ul class="no-bullet"> |
| 123 |
<li><a id="toc-_005b_003f_005dARG" href="#g_t_2395ARG">2.1.6.1 ⎕ARG</a></li> |
| 124 |
<li><a id="toc-_005b_003f_005dENV" href="#g_t_2395ENV">2.1.6.2 ⎕ENV</a></li> |
| 125 |
<li><a id="toc-_005b_003f_005dINP" href="#g_t_2395INP">2.1.6.3 ⎕INP</a></li> |
| 126 |
</ul></li> |
| 127 |
<li><a id="toc-Double_002dquoted-Strings-1" href="#Double_002dquoted-Strings">2.1.7 Double-quoted Strings</a></li> |
| 128 |
<li><a id="toc-Multi_002dLine-Strings-1" href="#Multi_002dLine-Strings">2.1.8 Multi-Line Strings</a> |
| 129 |
<ul class="no-bullet"> |
| 130 |
<li><a id="toc-Old_002dstyle-Multi_002dLine-Strings-1" href="#Old_002dstyle-Multi_002dLine-Strings">2.1.8.1 Old-style Multi-Line Strings</a></li> |
| 131 |
<li><a id="toc-New_002dstyle-Multi_002dLine-Strings-1" href="#New_002dstyle-Multi_002dLine-Strings">2.1.8.2 New-style Multi-Line Strings</a></li> |
| 132 |
<li><a id="toc-_00ab-_00bb-Strings-1" href="#g_t_00ab-_00bb-Strings">2.1.8.3 « » Strings</a></li> |
| 133 |
<li><a id="toc-Multi_002dLine-Comments-1" href="#Multi_002dLine-Comments">2.1.8.4 Multi-Line Comments</a></li> |
| 134 |
</ul></li> |
| 135 |
<li><a id="toc-Multi_002dLine-Literals-1" href="#Multi_002dLine-Literals">2.1.9 Multi-Line Literals</a></li> |
| 136 |
<li><a id="toc-Automatic-_0029MORE-1" href="#Automatic-_0029MORE">2.1.10 Automatic )MORE</a></li> |
| 137 |
<li><a id="toc-Script-Example-1" href="#Script-Example">2.1.11 Script Example</a></li> |
| 138 |
</ul></li> |
| 139 |
<li><a id="toc-Axis-argument-in-defined-functions-1" href="#Axis-argument-in-defined-functions">2.2 Axis argument in defined functions</a></li> |
| 140 |
<li><a id="toc-Function-Groups-1" href="#Function-Groups">2.3 Function Groups</a> |
| 141 |
<ul class="no-bullet"> |
| 142 |
<li><a id="toc-Phase-1_003a-Numerical-Axis-Argument-1" href="#Phase-1_003a-Numerical-Axis-Argument">2.3.1 Phase 1: Numerical Axis Argument</a></li> |
| 143 |
<li><a id="toc-Phase-2_003a-String-Axis-Argument-1" href="#Phase-2_003a-String-Axis-Argument">2.3.2 Phase 2: String Axis Argument</a></li> |
| 144 |
<li><a id="toc-Phase-3_003a-Member-Notation-1" href="#Phase-3_003a-Member-Notation">2.3.3 Phase 3: Member Notation</a></li> |
| 145 |
<li><a id="toc-Subfunction-Lists-1" href="#Subfunction-Lists">2.3.4 Subfunction Lists</a></li> |
| 146 |
</ul></li> |
| 147 |
<li><a id="toc-Colored-Output-1" href="#Colored-Output">2.4 Colored Output</a></li> |
| 148 |
<li><a id="toc-Comparison-Rules-1" href="#Comparison-Rules">2.5 Comparison Rules</a></li> |
| 149 |
<li><a id="toc-Complex-Numbers-1" href="#Complex-Numbers">2.6 Complex Numbers</a></li> |
| 150 |
<li><a id="toc-Debug-Commands-1" href="#Debug-Commands">2.7 Debug Commands</a></li> |
| 151 |
<li><a id="toc-Direct-Functions-_0028Lambdas_0029-1" href="#Direct-Functions-_0028Lambdas_0029">2.8 Direct Functions (Lambdas)</a> |
| 152 |
<ul class="no-bullet"> |
| 153 |
<li><a id="toc-Named-Lambdas-1" href="#Named-Lambdas">2.8.1 Named Lambdas</a></li> |
| 154 |
<li><a id="toc-Unnamed-Lambdas-1" href="#Unnamed-Lambdas">2.8.2 Unnamed Lambdas</a></li> |
| 155 |
<li><a id="toc-Limitations-of-GNU-APL-Lambdas-1" href="#Limitations-of-GNU-APL-Lambdas">2.8.3 Limitations of GNU APL Lambdas</a></li> |
| 156 |
</ul></li> |
| 157 |
<li><a id="toc-Commands-_0029COPY_005fONCE_002c-_0029DUMP_002c-and-DUMP_002dHTML" href="#Commands-_0029COPY_005fONCE-_0029DUMP-and-DUMP_002dHTML">2.9 Commands )COPY_ONCE, )DUMP, and DUMP-HTML</a> |
| 158 |
<ul class="no-bullet"> |
| 159 |
<li><a id="toc-_0029DUMP-Command-1" href="#g_t_0029DUMP-Command">2.9.1 )DUMP Command</a></li> |
| 160 |
<li><a id="toc-_0029DUMP_002dHTML-Command-1" href="#g_t_0029DUMP_002dHTML-Command">2.9.2 )DUMP-HTML Command</a></li> |
| 161 |
<li><a id="toc-_0029COPY_005fONCE-Command-1" href="#g_t_0029COPY_005fONCE-Command">2.9.3 )COPY_ONCE Command</a></li> |
| 162 |
</ul></li> |
| 163 |
<li><a id="toc-_005dDOXY-Command-1" href="#g_t_005dDOXY-Command">2.10 ]DOXY Command</a></li> |
| 164 |
<li><a id="toc-_005dKEYB-Command-1" href="#g_t_005dKEYB-Command">2.11 ]KEYB Command</a> |
| 165 |
<ul class="no-bullet"> |
| 166 |
<li><a id="toc-The-transformation-of-Keycodes-to-Unicodes-1" href="#The-transformation-of-Keycodes-to-Unicodes">2.11.1 The transformation of Keycodes to Unicodes</a></li> |
| 167 |
<li><a id="toc-xmodmap-and-friends-1" href="#xmodmap-and-friends">2.11.2 xmodmap and friends</a></li> |
| 168 |
<li><a id="toc-The-_005dKEYB-command-1" href="#The-_005dKEYB-command">2.11.3 The ]KEYB command</a> |
| 169 |
<ul class="no-bullet"> |
| 170 |
<li><a id="toc-_005dKEYB-Syntax-1" href="#g_t_005dKEYB-Syntax">2.11.3.1 ]KEYB Syntax</a></li> |
| 171 |
<li><a id="toc-_005dKEYB-without-a-mode-1" href="#g_t_005dKEYB-without-a-mode">2.11.3.2 ]KEYB without a mode</a></li> |
| 172 |
<li><a id="toc-_005dKEYB-XMOD-1" href="#g_t_005dKEYB-XMOD">2.11.3.3 ]KEYB XMOD</a></li> |
| 173 |
<li><a id="toc-_005dKEYB-USER-1" href="#g_t_005dKEYB-USER">2.11.3.4 ]KEYB USER</a></li> |
| 174 |
<li><a id="toc-_005dKEYB-GUESS-1" href="#g_t_005dKEYB-GUESS">2.11.3.5 ]KEYB GUESS</a></li> |
| 175 |
<li><a id="toc-Optional-_005dKEYB-arguments-1" href="#Optional-_005dKEYB-arguments">2.11.3.6 Optional ]KEYB arguments</a></li> |
| 176 |
</ul></li> |
| 177 |
</ul></li> |
| 178 |
<li><a id="toc-_005dNEXTFILE-and-_005dPUSHFILE-Commands-1" href="#g_t_005dNEXTFILE-and-_005dPUSHFILE-Commands">2.12 ]NEXTFILE and ]PUSHFILE Commands</a> |
| 179 |
<ul class="no-bullet"> |
| 180 |
<li><a id="toc-_005dNEXTFILE-1" href="#g_t_005dNEXTFILE">2.12.1 ]NEXTFILE</a></li> |
| 181 |
<li><a id="toc-_005dPUSHFILE-1" href="#g_t_005dPUSHFILE">2.12.2 ]PUSHFILE</a></li> |
| 182 |
</ul></li> |
| 183 |
<li><a id="toc-History-and-TAB-completion-1" href="#History-and-TAB-completion">2.13 History and TAB completion</a></li> |
| 184 |
<li><a id="toc-Logging-Facilities-1" href="#Logging-Facilities">2.14 Logging Facilities</a> |
| 185 |
<ul class="no-bullet"> |
| 186 |
<li><a id="toc-Static-Logging-1" href="#Static-Logging">2.14.1 Static Logging</a></li> |
| 187 |
<li><a id="toc-Dynamic-Logging-1" href="#Dynamic-Logging">2.14.2 Dynamic Logging</a></li> |
| 188 |
</ul></li> |
| 189 |
<li><a id="toc-Rational-Numbers-1" href="#Rational-Numbers">2.15 Rational Numbers</a></li> |
| 190 |
<li><a id="toc-Hex-Numbers-1" href="#Hex-Numbers">2.16 Hex Numbers</a></li> |
| 191 |
<li><a id="toc-User_002ddefined-Commands-1" href="#User_002ddefined-Commands">2.17 User-defined Commands</a></li> |
| 192 |
<li><a id="toc-Structured-Variables-and-Associative-Arrays-1" href="#Structured-Variables-and-Associative-Arrays">2.18 Structured Variables and Associative Arrays</a> |
| 193 |
<ul class="no-bullet"> |
| 194 |
<li><a id="toc-Structured-Variables-1" href="#Structured-Variables">2.18.1 Structured Variables</a></li> |
| 195 |
<li><a id="toc-Associative-Arrays-1" href="#Associative-Arrays">2.18.2 Associative Arrays</a></li> |
| 196 |
</ul></li> |
| 197 |
<li><a id="toc-Monadic-_005b_003f_005d-and-_22a3_003b-dyadic-_005b_003f_005d-with-Axis" href="#Monadic-_22a2-and-_22a3_003b-dyadic-_22a2-with-Axis">2.19 Monadic ⊢ and ⊣; dyadic ⊢ with Axis</a></li> |
| 198 |
<li><a id="toc-Bit_002dwise-Logical-Functions-_005b_003f_005d_005b_003f_005d_002c-_005b_003f_005d_005b_003f_005d_002c-_005b_003f_005d_005b_003f_005d_002c-_005b_003f_005d_005b_003f_005d_002c-_005b_003f_005d_005b_003f_005d_002c-and-_005b_003f_005d_003d" href="#Bit_002dwise-Logical-Functions_003a-_22a4_2227-_22a4_2228-_22a4_2372-_22a4_2371-_22a4_2260-and-_22a4_003d">2.20 Bit-wise Logical Functions ⊤∧, ⊤∨, ⊤⍲, ⊤⍱, ⊤≠, and ⊤=</a> |
| 199 |
<ul class="no-bullet"> |
| 200 |
<li><a id="toc-Dyadic-_005b_003f_005d_005b_003f_005d_002c-_005b_003f_005d_005b_003f_005d_002c-_005b_003f_005d_005b_003f_005d_002c-_005b_003f_005d_005b_003f_005d_002c-_005b_003f_005d_003d_002c-and-_005b_003f_005d_005b_003f_005d" href="#Dyadic-_22a4_2227-_22a4_2228-_22a4_2372-_22a4_2371-_22a4_003d-and-_22a4_2260">2.20.1 Dyadic ⊤∧, ⊤∨, ⊤⍲, ⊤⍱, ⊤=, and ⊤≠</a></li> |
| 201 |
<li><a id="toc-Monadic-_005b_003f_005d_005b_003f_005d-and-_005b_003f_005d_005b_003f_005d" href="#Monadic-_22a4_2228-and-_22a4_2371">2.20.2 Monadic ⊤∨ and ⊤⍱</a></li> |
| 202 |
<li><a id="toc-Monadic-_005b_003f_005d_005b_003f_005d" href="#Monadic-_22a4_2227">2.20.3 Monadic ⊤∧</a></li> |
| 203 |
<li><a id="toc-Character-Arguments-for-Monadic-_005b_003f_005d_005b_003f_005d-and-Dyadic-_005b_003f_005d_005b_003f_005d_002c-_005b_003f_005d_005b_003f_005d_002c-_003d_003d_002c-and-_005b_003f_005d_005b_003f_005d" href="#Character-Arguments-for-Monadic-_22a4_2371-and-Dyadic-_22a4_2227-_22a4_2228-_003d_003d-and-_2260_2260">2.20.4 Character Arguments for Monadic ⊤⍱ and Dyadic ⊤∧, ⊤∨, ==, and ≠≠</a></li> |
| 204 |
</ul></li> |
| 205 |
<li><a id="toc-_005b_003f_005d-_0028Encode_0029-with-Axis" href="#g_t_22a4-_0028Encode_0029-with-Axis">2.21 ⊤ (Encode) with Axis</a></li> |
| 206 |
<li><a id="toc-Generalized-_005b_003f_005d" href="#Generalized-_2373">2.22 Generalized ⍳</a> |
| 207 |
<ul class="no-bullet"> |
| 208 |
<li><a id="toc-Generalized-monadic-_005b_003f_005d" href="#Generalized-monadic-_2373">2.22.1 Generalized monadic ⍳</a></li> |
| 209 |
<li><a id="toc-Generalized-dyadic-_005b_003f_005d" href="#Generalized-dyadic-_2373">2.22.2 Generalized dyadic ⍳</a></li> |
| 210 |
</ul></li> |
| 211 |
<li><a id="toc-_005b_003f_005d_005bX_005d-_002d-Miscellaneous-Matrix-and-Vector-Operations" href="#g_t_2339_005bX_005d-_002d-Miscellaneous-Matrix-and-Vector-Operations">2.23 ⌹[X] - Miscellaneous Matrix and Vector Operations</a> |
| 212 |
<ul class="no-bullet"> |
| 213 |
<li><a id="toc-_005b_003f_005d_005b1_005d-and-_005b_003f_005d_005b2_005d-_002d-QR-Factorizations" href="#g_t_2339_005b1_005d-and-_2339_005b2_005d-_002d-QR-Factorizations">2.23.1 ⌹[1] and ⌹[2] - QR Factorizations</a></li> |
| 214 |
<li><a id="toc-The-Impact-of-_005b_003f_005dCT-for-_005b_003f_005d" href="#The-Impact-of-_2395CT-for-_2339">2.23.2 The Impact of ⎕CT for ⌹</a> |
| 215 |
<ul class="no-bullet"> |
| 216 |
<li><a id="toc-A_005b_003f_005dB-and-_005b_003f_005dB" href="#A_2339B-and-_2339B">2.23.2.1 A⌹B and ⌹B</a></li> |
| 217 |
<li><a id="toc-_005b_003f_005d_005bX_005d-B_003a-Various-Factorizations-of-B" href="#g_t_2339_005bX_005d-B_003a-Various-Factorizations-of-B">2.23.2.2 ⌹[X] B: Various Factorizations of B</a></li> |
| 218 |
<li><a id="toc-Matrix-Inverse-1" href="#Matrix-Inverse">2.23.2.3 Matrix Inverse</a></li> |
| 219 |
<li><a id="toc-_005b_003f_005d_005b7_005d-B_003a-Print-Polynomial-B" href="#g_t_2339_005b7_005d-B_003a-Print-Polynomial-B">2.23.2.4 ⌹[7] B: Print Polynomial B</a></li> |
| 220 |
<li><a id="toc-A-_005b_003f_005d_005b8_005d-B_003a-Multiply-Polynomials-A-and-B" href="#A-_2339_005b8_005d-B_003a-Multiply-Polynomials-A-and-B">2.23.2.5 A ⌹[8] B: Multiply Polynomials A and B</a></li> |
| 221 |
<li><a id="toc-A-_005b_003f_005d_005b9_005d-B_003a-Divide-Polynomial-A-by-Polynomial-B-_0028univariate_0029" href="#A-_2339_005b9_005d-B_003a-Divide-Polynomial-A-by-Polynomial-B-_0028univariate_0029">2.23.2.6 A ⌹[9] B: Divide Polynomial A by Polynomial B (univariate)</a></li> |
| 222 |
<li><a id="toc-A-_005b_003f_005d_005b10_005d-B_003a-Divide-Polynomial-A-by-Polynomial-B-_0028multivariate_0029" href="#A-_2339_005b10_005d-B_003a-Divide-Polynomial-A-by-Polynomial-B-_0028multivariate_0029">2.23.2.7 A ⌹[10] B: Divide Polynomial A by Polynomial B (multivariate)</a></li> |
| 223 |
<li><a id="toc-A-_005b_003f_005d_005b11_005d-B_003a-Divide-Polynomial-A-by-Polynomial-B-_0028with-order_0029" href="#A-_2339_005b11_005d-B_003a-Divide-Polynomial-A-by-Polynomial-B-_0028with-order_0029">2.23.2.8 A ⌹[11] B: Divide Polynomial A by Polynomial B (with order)</a></li> |
| 224 |
<li><a id="toc-_005b_003f_005d_005b11_005d-B_003a-Scan-Polynomial-B" href="#g_t_2339_005b11_005d-B-Scan-Polynomial-B">2.23.2.9 ⌹[11] B: Scan Polynomial B</a></li> |
| 225 |
<li><a id="toc-A-_005b_003f_005d_005b20_005d-B_003a-Integral-B" href="#A-_2339_005b20_005d-B_003a-Integral-B">2.23.2.10 A ⌹[20] B: Integral B</a></li> |
| 226 |
</ul></li> |
| 227 |
</ul></li> |
| 228 |
<li><a id="toc-_005b_003f_005dCC-_002d-Character-Classes" href="#g_t_2395CC-_002d-Character-Classes">2.24 ⎕CC - Character Classes</a> |
| 229 |
<ul class="no-bullet"> |
| 230 |
<li><a id="toc-monadic-_005b_003f_005dCC-B_003a-Return-character-class" href="#monadic-_2395CC-B_003a-Return-character-class">2.24.1 monadic ⎕CC B: Return character class</a></li> |
| 231 |
<li><a id="toc-dyadic-A-_005b_003f_005dCC-B_003a-Test-character-class" href="#dyadic-A-_2395CC-B_003a-Test-character-class">2.24.2 dyadic A ⎕CC B: Test character class</a></li> |
| 232 |
</ul></li> |
| 233 |
<li><a id="toc-Dyadic-_005b_003f_005dCR" href="#Dyadic-_2395CR">2.25 Dyadic ⎕CR</a></li> |
| 234 |
<li><a id="toc-Dyadic-_005b_003f_005dFX-_0028Native-Functions_0029" href="#Dyadic-_2395FX-_0028Native-Functions_0029">2.26 Dyadic ⎕FX (Native Functions)</a></li> |
| 235 |
<li><a id="toc-_005b_003f_005dARG-_002d-Interpreter-command-line-arguments" href="#g_t_2395ARG-_002d-Interpreter-command-line-arguments">2.27 ⎕ARG - Interpreter command line arguments</a></li> |
| 236 |
<li><a id="toc-_005b_003f_005dDLX-_002d-Knuth_0027s-Dancing-Links-Algorithm" href="#g_t_2395DLX-_002d-Knuth_0027s-Dancing-Links-Algorithm">2.28 ⎕DLX - Knuth’s Dancing Links Algorithm</a></li> |
| 237 |
<li><a id="toc-_005b_003f_005dENV-_002d-Environment-Variables" href="#g_t_2395ENV-_002d-Environment-Variables">2.29 ⎕ENV - Environment Variables</a></li> |
| 238 |
<li><a id="toc-_005b_003f_005dFIO-_002d-File-I_002fO-Functions" href="#g_t_2395FIO-_002d-File-I_002fO-Functions">2.30 ⎕FIO - File I/O Functions</a></li> |
| 239 |
<li><a id="toc-_005b_003f_005dFFT-_002d-Fast-Fourier-Transform" href="#g_t_2395FFT-_002d-Fast-Fourier-Transform">2.31 ⎕FFT - Fast Fourier Transform</a></li> |
| 240 |
<li><a id="toc-_005b_003f_005dGTK-_002d-GTK-Interface" href="#g_t_2395GTK-_002d-GTK-Interface">2.32 ⎕GTK - GTK Interface</a></li> |
| 241 |
<li><a id="toc-_005b_003f_005dJSON-_002d-JSON-Parsing" href="#g_t_2395JSON-_002d-JSON-Parsing">2.33 ⎕JSON - JSON Parsing</a> |
| 242 |
<ul class="no-bullet"> |
| 243 |
<li><a id="toc-Monadic-_005b_003f_005dJSON" href="#Monadic-_2395JSON">2.33.1 Monadic ⎕JSON</a></li> |
| 244 |
<li><a id="toc-Dyadic-_005b_003f_005dJSON" href="#Dyadic-_2395JSON">2.33.2 Dyadic ⎕JSON</a></li> |
| 245 |
</ul></li> |
| 246 |
<li><a id="toc-_005b_003f_005dMAP-_002d-Map-Value" href="#g_t_2395MAP-_002d-Map-Value">2.34 ⎕MAP - Map Value</a></li> |
| 247 |
<li><a id="toc-_005b_003f_005dMX-_002d-Matrix_002fStatistics" href="#g_t_2395MX-_002d-Matrix_002fStatistics">2.35 ⎕MX - Matrix/Statistics</a> |
| 248 |
<ul class="no-bullet"> |
| 249 |
<li><a id="toc-Determinant-1" href="#Determinant">2.35.1 Determinant</a></li> |
| 250 |
<li><a id="toc-Cross-Product-1" href="#Cross-Product">2.35.2 Cross Product</a></li> |
| 251 |
<li><a id="toc-Vector-Angle-1" href="#Vector-Angle">2.35.3 Vector Angle</a></li> |
| 252 |
<li><a id="toc-Eigenvector-1" href="#Eigenvector">2.35.4 Eigenvector</a></li> |
| 253 |
<li><a id="toc-Eigenvalue-1" href="#Eigenvalue">2.35.5 Eigenvalue</a></li> |
| 254 |
<li><a id="toc-Ident-1" href="#Ident">2.35.6 Ident</a></li> |
| 255 |
<li><a id="toc-Rotation-1" href="#Rotation">2.35.7 Rotation</a></li> |
| 256 |
<li><a id="toc-Homogeneous-transform-1" href="#Homogeneous-transform">2.35.8 Homogeneous transform</a></li> |
| 257 |
<li><a id="toc-Norm-1" href="#Norm">2.35.9 Norm</a></li> |
| 258 |
<li><a id="toc-Randoms-1" href="#Randoms">2.35.10 Randoms</a></li> |
| 259 |
<li><a id="toc-Covariance-1" href="#Covariance">2.35.11 Covariance</a></li> |
| 260 |
<li><a id="toc-Histograms-1" href="#Histograms">2.35.12 Histograms</a></li> |
| 261 |
<li><a id="toc-Print-1" href="#Print">2.35.13 Print</a></li> |
| 262 |
</ul></li> |
| 263 |
<li><a id="toc-_005b_003f_005dPLOT-_002d-Plot-Data" href="#g_t_2395PLOT-_002d-Plot-Data">2.36 ⎕PLOT - Plot Data</a> |
| 264 |
<ul class="no-bullet"> |
| 265 |
<li><a id="toc-The-Plot-Data-B-1" href="#The-Plot-Data-B">2.36.1 The Plot Data B</a> |
| 266 |
<ul class="no-bullet"> |
| 267 |
<li><a id="toc-Complex-Plot-Data-B-1" href="#Complex-Plot-Data-B">2.36.1.1 Complex Plot Data B</a></li> |
| 268 |
<li><a id="toc-Real-Plot-Data-B-1" href="#Real-Plot-Data-B">2.36.1.2 Real Plot Data B</a></li> |
| 269 |
</ul></li> |
| 270 |
<li><a id="toc-The-Plot-Attributes-A-1" href="#The-Plot-Attributes-A">2.36.2 The Plot Attributes A</a> |
| 271 |
<ul class="no-bullet"> |
| 272 |
<li><a id="toc-Tick-formatting-_0028GTK-only_0029" href="#Tick-formatting-_0028GTK-only_0029">2.36.2.1 Tick formatting (GTK only)</a></li> |
| 273 |
</ul></li> |
| 274 |
<li><a id="toc-Plot-Window-Handling-1" href="#Plot-Window-Handling">2.36.3 Plot Window Handling</a></li> |
| 275 |
<li><a id="toc-Output-File-Format-1" href="#Output-File-Format">2.36.4 Output File Format</a></li> |
| 276 |
<li><a id="toc-GUI-driver-1" href="#GUI-driver">2.36.5 GUI driver</a></li> |
| 277 |
</ul></li> |
| 278 |
<li><a id="toc-_005b_003f_005dPNG-_002d-Portable-Network-Graphics" href="#g_t_2395PNG-_002d-Portable-Network-Graphics">2.37 ⎕PNG - Portable Network Graphics</a> |
| 279 |
<ul class="no-bullet"> |
| 280 |
<li><a id="toc-The-GNU-APL-Color-Model-1" href="#The-GNU-APL-Color-Model">2.37.1 The GNU APL Color Model</a></li> |
| 281 |
<li><a id="toc-Monadic-_005b_003f_005dPNG" href="#Monadic-_2395PNG">2.37.2 Monadic ⎕PNG</a></li> |
| 282 |
<li><a id="toc-Dyadic-_005b_003f_005dPNG" href="#Dyadic-_2395PNG">2.37.3 Dyadic ⎕PNG</a></li> |
| 283 |
<li><a id="toc-APL-Examples-1" href="#APL-Examples">2.37.4 APL Examples</a></li> |
| 284 |
</ul></li> |
| 285 |
<li><a id="toc-_005b_003f_005dPS-_002d-Print-Style" href="#g_t_2395PS-_002d-Print-Style">2.38 ⎕PS - Print Style</a></li> |
| 286 |
<li><a id="toc-_005b_003f_005dRE-_002d-Regular-Expressions" href="#g_t_2395RE-_002d-Regular-Expressions">2.39 ⎕RE - Regular Expressions</a> |
| 287 |
<ul class="no-bullet"> |
| 288 |
<li><a id="toc-Preconditions-1" href="#Preconditions">2.39.1 Preconditions</a></li> |
| 289 |
<li><a id="toc-_005b_003f_005dRE-Syntax" href="#g_t_2395RE-Syntax">2.39.2 ⎕RE Syntax</a></li> |
| 290 |
<li><a id="toc-The-Regular-Expression-A-1" href="#The-Regular-Expression-A">2.39.3 The Regular Expression A</a></li> |
| 291 |
<li><a id="toc-The-String_0028s_0029-B-Being-Matched-1" href="#The-String_0028s_0029-B-Being-Matched">2.39.4 The String(s) B Being Matched</a></li> |
| 292 |
<li><a id="toc-The-Flags-X-1" href="#The-Flags-X">2.39.5 The Flags X</a> |
| 293 |
<ul class="no-bullet"> |
| 294 |
<li><a id="toc-The-libpcre2-flags_003a-i_002c-m_002c-s_002c-and-x" href="#The-libpcre2-flags_003a-i-m-s-and-x">2.39.5.1 The libpcre2 flags: i, m, s, and x</a></li> |
| 295 |
<li><a id="toc-The-_005b_003f_005dRE-_0028APL-output-format_0029-flags-_007c_002c-_005b_003f_005d_002c-and-_002f" href="#The-_2395RE-_0028APL-output-format_0029-flags-_2193-_2282-and-_002f">2.39.5.2 The ⎕RE (APL output format) flags ↓, ⊂, and /</a></li> |
| 296 |
<li><a id="toc-the-_005b_003f_005dRE-global-flag-g" href="#the-_2395RE-global-flag-g">2.39.5.3 the ⎕RE global flag g</a></li> |
| 297 |
<li><a id="toc-the-_005b_003f_005dRE-error-flag-E" href="#the-_2395RE-error-flag-E">2.39.5.4 the ⎕RE error flag E</a></li> |
| 298 |
</ul></li> |
| 299 |
<li><a id="toc-Complex-Matches-1" href="#Complex-Matches">2.39.6 Complex Matches</a></li> |
| 300 |
</ul></li> |
| 301 |
<li><a id="toc-_005b_003f_005dRVAL-_002d-Random-APL-value" href="#g_t_2395RVAL-_002d-Random-APL-value">2.40 ⎕RVAL - Random APL value</a> |
| 302 |
<ul class="no-bullet"> |
| 303 |
<li><a id="toc-General-1" href="#General">2.40.1 General</a></li> |
| 304 |
<li><a id="toc-Dyadic-_005b_003f_005dRVAL" href="#Dyadic-_2395RVAL">2.40.2 Dyadic ⎕RVAL</a> |
| 305 |
<ul class="no-bullet"> |
| 306 |
<li><a id="toc-Control-of-the-underlying-random-number-generator_003a-0-_005b_003f_005dRVAL-B" href="#Control-of-the-underlying-random-number-generator_003a-0-_2395RVAL-B">2.40.2.1 Control of the underlying random number generator: 0 ⎕RVAL B</a></li> |
| 307 |
<li><a id="toc-Control-of-the-ranks_003a-1-_005b_003f_005dRVAL-B" href="#Control-of-the-ranks_003a-1-_2395RVAL-B">2.40.2.2 Control of the ranks: 1 ⎕RVAL B</a></li> |
| 308 |
<li><a id="toc-Control-of-the-shapes_003a-2-_005b_003f_005dRVAL-B" href="#Control-of-the-shapes_003a-2-_2395RVAL-B">2.40.2.3 Control of the shapes: 2 ⎕RVAL B</a></li> |
| 309 |
<li><a id="toc-Control-of-the-data-types_003a-3-_005b_003f_005dRVAL-B" href="#Control-of-the-data-types_003a-3-_2395RVAL-B">2.40.2.4 Control of the data types: 3 ⎕RVAL B</a></li> |
| 310 |
<li><a id="toc-Control-of-a-maximum-depth_003a-4-_005b_003f_005dRVAL-B" href="#Control-of-a-maximum-depth_003a-4-_2395RVAL-B">2.40.2.5 Control of a maximum depth: 4 ⎕RVAL B</a></li> |
| 311 |
<li><a id="toc-monadic-_005b_003f_005dRVAL-B" href="#monadic-_2395RVAL-B">2.40.2.6 monadic ⎕RVAL B</a></li> |
| 312 |
<li><a id="toc-Syntax-Alternatives-1" href="#Syntax-Alternatives">2.40.2.7 Syntax Alternatives</a></li> |
| 313 |
</ul></li> |
| 314 |
</ul></li> |
| 315 |
<li><a id="toc-_005b_003f_005dSI-_002d-State-Indicator" href="#g_t_2395SI-_002d-State-Indicator">2.41 ⎕SI - State Indicator</a></li> |
| 316 |
<li><a id="toc-_005b_003f_005dSQL-_002d-SQL-Database-Interface" href="#g_t_2395SQL-_002d-SQL-Database-Interface">2.42 ⎕SQL - SQL Database Interface</a> |
| 317 |
<ul class="no-bullet"> |
| 318 |
<li><a id="toc-_005b_003f_005dSQL_005b0_005d-_005b_003f_005d-_003a-display-sub_002dfunction-numbers" href="#g_t_2395SQL_005b0_005d-_236c-_003a-display-sub_002dfunction-numbers">2.42.1 ⎕SQL[0] ⍬ : display sub-function numbers</a></li> |
| 319 |
<li><a id="toc-_005b_003f_005dSQL_005b0_005d-_0027_0027-_003a-display-sub_002dfunction-names" href="#g_t_2395SQL_005b0_005d-_0027_0027-_003a-display-sub_002dfunction-names">2.42.2 ⎕SQL[0] <code>''</code> : display sub-function names</a></li> |
| 320 |
<li><a id="toc-ref-_002d-A-_005b_003f_005dSQL_005b1_005d-B-_003a-open-database" href="#ref-_2190-A-_2395SQL_005b1_005d-B-_003a-open-database">2.42.3 ref ← A ⎕SQL[1] B : open database</a></li> |
| 321 |
<li><a id="toc-_005b_003f_005dSQL_005b2_005d-B-_003a-close-database" href="#g_t_2395SQL_005b2_005d-B-_003a-close-database">2.42.4 ⎕SQL[2] B : close database</a></li> |
| 322 |
<li><a id="toc-Z-_002d-A-_005b_003f_005dSQL_005b3_002c-ref_005d-B-_003a-database-query-_0028with-result_0029" href="#Z-_2190-A-_2395SQL_005b3-ref_005d-B-_003a-database-query-_0028with-result_0029">2.42.5 Z ← A ⎕SQL[3, ref] B : database query (with result)</a></li> |
| 323 |
<li><a id="toc-Z-_002d-A-_005b_003f_005dSQL_005b4_002c-ref_005d-B-_003a-database-query-_0028w_002fo-result_0029" href="#Z-_2190-A-_2395SQL_005b4-ref_005d-B-_003a-database-query-_0028w_002fo-result_0029">2.42.6 Z ← A ⎕SQL[4, ref] B : database query (w/o result)</a></li> |
| 324 |
<li><a id="toc-_005b_003f_005dSQL_005b5_005d-B-_003a-start-transaction" href="#g_t_2395SQL_005b5_005d-B-_003a-start-transaction">2.42.7 ⎕SQL[5] B : start transaction</a></li> |
| 325 |
<li><a id="toc-_005b_003f_005dSQL_005b6_005d-B-_003a-commit-transaction" href="#g_t_2395SQL_005b6_005d-B-_003a-commit-transaction">2.42.8 ⎕SQL[6] B : commit transaction</a></li> |
| 326 |
<li><a id="toc-_005b_003f_005dSQL_005b7_005d-B-_003a-rollback-transaction" href="#g_t_2395SQL_005b7_005d-B-_003a-rollback-transaction">2.42.9 ⎕SQL[7] B : rollback transaction</a></li> |
| 327 |
<li><a id="toc-Z_002d_005b_003f_005dSQL_005b8_005d-B-_003a-table-names" href="#Z_2190_2395SQL_005b8_005d-B-_003a-table-names">2.42.10 Z←⎕SQL[8] B : table names</a></li> |
| 328 |
<li><a id="toc-Z_002d_005b_003f_005dSQL_005b9_005d-B-_003a-column-names" href="#Z_2190_2395SQL_005b9_005d-B-_003a-column-names">2.42.11 Z←⎕SQL[9] B : column names</a></li> |
| 329 |
<li><a id="toc-Z-_002d-_005b_003f_005dSQL_005b10_005d-B-_003a-library-version-number" href="#Z-_2190-_2395SQL_005b10_005d-B-_003a-library-version-number">2.42.12 Z ← ⎕SQL[10] B : library version number</a></li> |
| 330 |
<li><a id="toc-Z-_002d-_005b_003f_005dSQL_005b11_005d-B-_003a-library-version-string" href="#Z-_2190-_2395SQL_005b11_005d-B-_003a-library-version-string">2.42.13 Z ← ⎕SQL[11] B : library version string</a></li> |
| 331 |
<li><a id="toc-SQLite-Quickstart-1" href="#SQLite-Quickstart">2.42.14 SQLite Quickstart</a> |
| 332 |
<ul class="no-bullet"> |
| 333 |
<li><a id="toc-Deleting-a-Database-1" href="#Deleting-a-Database">2.42.14.1 Deleting a Database</a></li> |
| 334 |
<li><a id="toc-Creating-a-new-Database-1" href="#Creating-a-new-Database">2.42.14.2 Creating a new Database</a></li> |
| 335 |
<li><a id="toc-Creating-a-Database-Table-1" href="#Creating-a-Database-Table">2.42.14.3 Creating a Database Table</a></li> |
| 336 |
<li><a id="toc-Excursus_003a-Dynamic-Query-Strings-1" href="#Excursus_003a-Dynamic-Query-Strings">2.42.14.4 Excursus: Dynamic Query Strings</a></li> |
| 337 |
<li><a id="toc-Writing-an-APL-matrix-into-a-Database-Table-1" href="#Writing-an-APL-matrix-into-a-Database-Table">2.42.14.5 Writing an APL matrix into a Database Table</a></li> |
| 338 |
<li><a id="toc-Reading-a-Database-Table-into-an-APL-Matrix-1" href="#Reading-a-Database-Table-into-an-APL-Matrix">2.42.14.6 Reading a Database Table into an APL Matrix</a></li> |
| 339 |
<li><a id="toc-Updating-a-Database-Table-1" href="#Updating-a-Database-Table">2.42.14.7 Updating a Database Table</a></li> |
| 340 |
</ul></li> |
| 341 |
<li><a id="toc-Deleting-Rows-From-a-Database-Table-1" href="#Deleting-Rows-From-a-Database-Table">2.42.15 Deleting Rows From a Database Table</a></li> |
| 342 |
</ul></li> |
| 343 |
<li><a id="toc-_005b_003f_005dSYL-_002d-System-limits" href="#g_t_2395SYL-_002d-System-limits">2.43 ⎕SYL - System limits</a> |
| 344 |
<ul class="no-bullet"> |
| 345 |
<li><a id="toc-_005b_003f_005dSYL_005b1-2-3-4-5-6_003b_005d" href="#g_t_2395SYL_005b1-2-3-4-5-6_003b_005d">2.43.1 ⎕SYL[1 2 3 4 5 6;]</a></li> |
| 346 |
<li><a id="toc-_005b_003f_005dSYL_005b7-8-9-10-11-12-13-14-15-16-17-18-19-20-21-22-23_003b_005d" href="#g_t_2395SYL_005b7-8-9-10-11-12-13-14-15-16-17-18-19-20-21-22-23_003b_005d">2.43.2 ⎕SYL[7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23;]</a></li> |
| 347 |
<li><a id="toc-_005b_003f_005dSYL_005b24-25-26_003b_005d" href="#g_t_2395SYL_005b24-25-26_003b_005d">2.43.3 ⎕SYL[24 25 26;]</a></li> |
| 348 |
<li><a id="toc-_005b_003f_005dSYL_005b27_003b_005d" href="#g_t_2395SYL_005b27_003b_005d">2.43.4 ⎕SYL[27;]</a></li> |
| 349 |
</ul></li> |
| 350 |
<li><a id="toc-_005b_003f_005dXML-_002d-XML-Parsing" href="#g_t_2395XML-_002d-XML-Parsing">2.44 ⎕XML - XML Parsing</a> |
| 351 |
<ul class="no-bullet"> |
| 352 |
<li><a id="toc-Purpose-1" href="#Purpose">2.44.1 Purpose</a></li> |
| 353 |
<li><a id="toc-Some-XML-Terminology-1" href="#Some-XML-Terminology">2.44.2 Some XML Terminology</a></li> |
| 354 |
<li><a id="toc-How-_005b_003f_005dXML-maps-XML-documents-to-APL-Values" href="#How-_2395XML-maps-XML-documents-to-APL-Values">2.44.3 How ⎕XML maps XML documents to APL Values</a></li> |
| 355 |
<li><a id="toc-Monadic-_005b_003f_005dXML" href="#Monadic-_2395XML">2.44.4 Monadic ⎕XML</a></li> |
| 356 |
<li><a id="toc-Dyadic-_005b_003f_005dXML" href="#Dyadic-_2395XML">2.44.5 Dyadic ⎕XML</a></li> |
| 357 |
<li><a id="toc-XML-Queries-1" href="#XML-Queries">2.44.6 XML Queries</a></li> |
| 358 |
</ul></li> |
| 359 |
<li><a id="toc-Conditionals-1" href="#Conditionals">2.45 Conditionals</a> |
| 360 |
<ul class="no-bullet"> |
| 361 |
<li><a id="toc-Design-considerations_002e-1" href="#Design-considerations_002e">2.45.1 Design considerations.</a></li> |
| 362 |
<li><a id="toc-Syntax-1" href="#Syntax">2.45.2 Syntax</a></li> |
| 363 |
<li><a id="toc-A-Possible-Pitfall-1" href="#A-Possible-Pitfall">2.45.3 A Possible Pitfall</a></li> |
| 364 |
</ul></li> |
| 365 |
<li><a id="toc-Matrix-Product-1" href="#Matrix-Product">2.46 Matrix Product</a></li> |
| 366 |
<li><a id="toc-Monadic-_005b_003f_005d-_0028Nub-Sieve_0029" href="#Monadic-_2260-_0028Nub-Sieve_0029">2.47 Monadic ≠ (Nub Sieve)</a></li> |
| 367 |
</ul></li> |
| 368 |
<li><a id="toc-Limitations-and-Missing-Features-1" href="#Limitations-and-Missing-Features">3 Limitations and Missing Features</a> |
| 369 |
<ul class="no-bullet"> |
| 370 |
<li><a id="toc-System-Limits-1" href="#System-Limits">3.1 System Limits</a></li> |
| 371 |
<li><a id="toc-Shared-Variables-1" href="#Shared-Variables">3.2 Shared Variables</a></li> |
| 372 |
</ul></li> |
| 373 |
<li><a id="toc-Internationalization-1" href="#Internationalization">4 Internationalization</a></li> |
| 374 |
<li><a id="toc-Vector-Notation-1" href="#Vector-Notation">5 Vector Notation</a> |
| 375 |
<ul class="no-bullet"> |
| 376 |
<li><a id="toc-History-1" href="#History">5.1 History</a></li> |
| 377 |
<li><a id="toc-Standardization-1" href="#Standardization">5.2 Standardization</a></li> |
| 378 |
<li><a id="toc-Quotes-from-the-lrm-1" href="#Quotes-from-the-lrm">5.3 Quotes from the lrm</a></li> |
| 379 |
<li><a id="toc-Some-APL2-Tests-1" href="#Some-APL2-Tests">5.4 Some APL2 Tests</a> |
| 380 |
<ul class="no-bullet"> |
| 381 |
<li><a id="toc-Test-1_003a-Binding-strength-of-_005b_005d-1" href="#Test-1_003a-Binding-strength-of-_005b_005d">5.4.1 Test 1: Binding strength of []</a></li> |
| 382 |
<li><a id="toc-Test-2_003a-Binding-strength-of-the-left-operand-1" href="#Test-2_003a-Binding-strength-of-the-left-operand">5.4.2 Test 2: Binding strength of the left operand</a></li> |
| 383 |
</ul></li> |
| 384 |
<li><a id="toc-Definitions-1" href="#Definitions">5.5 Definitions</a></li> |
| 385 |
<li><a id="toc-Unexpected-Stranding-1" href="#Unexpected-Stranding">5.6 Unexpected Stranding</a> |
| 386 |
<ul class="no-bullet"> |
| 387 |
<li><a id="toc-Performance-considerations" href="#Performance-considerations">5.6.1 Performance considerations</a></li> |
| 388 |
</ul></li> |
| 389 |
<li><a id="toc-GNU-APL-Vector-Notation-1" href="#GNU-APL-Vector-Notation">5.7 GNU APL Vector Notation</a> |
| 390 |
<ul class="no-bullet"> |
| 391 |
<li><a id="toc-Example" href="#Example">5.7.1 Example</a></li> |
| 392 |
</ul></li> |
| 393 |
</ul></li> |
| 394 |
<li><a id="toc-GNU-APL-Project-Structure-1" href="#GNU-APL-Project-Structure">6 GNU APL Project Structure</a> |
| 395 |
<ul class="no-bullet"> |
| 396 |
<li><a id="toc-The-sub_002ddirectory-src-1" href="#The-sub_002ddirectory-src">6.1 The sub-directory src</a></li> |
| 397 |
<li><a id="toc-The-sub_002ddirectory-support_002dfiles-1" href="#The-sub_002ddirectory-support_002dfiles">6.2 The sub-directory support-files</a></li> |
| 398 |
<li><a id="toc-The-sub_002ddirectory-doc-1" href="#The-sub_002ddirectory-doc">6.3 The sub-directory doc</a></li> |
| 399 |
<li><a id="toc-The-sub_002ddirectory-HOWTOs-1" href="#The-sub_002ddirectory-HOWTOs">6.4 The sub-directory HOWTOs</a></li> |
| 400 |
<li><a id="toc-The-sub_002ddirectories-workspaces-and-wslib2-_002e_002e_002e-wslib5-1" href="#The-sub_002ddirectories-workspaces-and-wslib2-_002e_002e_002e-wslib5">6.5 The sub-directories workspaces and wslib2 ... wslib5</a></li> |
| 401 |
<li><a id="toc-The-sub_002ddirectory-m4-1" href="#The-sub_002ddirectory-m4">6.6 The sub-directory m4</a></li> |
| 402 |
<li><a id="toc-The-sub_002ddirectories-debian-and-debian_005ftmp-1" href="#The-sub_002ddirectories-debian-and-debian_005ftmp">6.7 The sub-directories debian and debian_tmp</a></li> |
| 403 |
<li><a id="toc-The-sub_002ddirectory-tools-1" href="#The-sub_002ddirectory-tools">6.8 The sub-directory tools</a></li> |
| 404 |
</ul></li> |
| 405 |
<li><a id="toc-Libraries-Contributed-by-GNU-APL-Users-1" href="#Libraries-Contributed-by-GNU-APL-Users">7 Libraries Contributed by GNU APL Users</a> |
| 406 |
<ul class="no-bullet"> |
| 407 |
<li><a id="toc-The-GNU-APL-Community-Webpage-1" href="#The-GNU-APL-Community-Webpage">7.1 The GNU APL Community Webpage</a></li> |
| 408 |
<li><a id="toc-Core-Libraries-1" href="#Core-Libraries">7.2 Core Libraries</a></li> |
| 409 |
</ul></li> |
| 410 |
<li><a id="toc-Licenses-for-this-GNU-APL-Manual-and-for-GNU-APL-1" href="#Licenses-for-this-GNU-APL-Manual-and-for-GNU-APL">8 Licenses for this GNU APL Manual and for GNU APL</a> |
| 411 |
<ul class="no-bullet"> |
| 412 |
<li><a id="toc-The-GNU-Free-Documentation-License-1" href="#The-GNU-Free-Documentation-License">8.1 The GNU Free Documentation License</a></li> |
| 413 |
<li><a id="toc-The-GNU-GENERAL-PUBLIC-LICENSE-1" href="#The-GNU-GENERAL-PUBLIC-LICENSE">8.2 The GNU GENERAL PUBLIC LICENSE</a></li> |
| 414 |
</ul></li> |
| 415 |
</ul> |
| 416 |
</div> |
| 417 |
</div> |
| 418 |
<hr> |
| 419 |
<div class="chapter" id="Installing-and-Starting-GNU-APL"> |
| 420 |
<div class="header"> |
| 421 |
<p> |
| 422 |
Next: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="n" rel="next">Non-standard GNU APL Features</a>, Previous: <a href="#Top" accesskey="p" rel="prev">GNU APL Reference Manual</a>, Up: <a href="#Top" accesskey="u" rel="up">GNU APL Reference Manual</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 423 |
</div> |
| 424 |
<span id="Installing-and-Starting-GNU-APL-1"></span><h2 class="chapter">1 Installing and Starting GNU APL</h2> |
| 425 |
|
| 426 |
<ul class="section-toc"> |
| 427 |
<li><a href="#Installing-APL" accesskey="1">Installing APL</a></li> |
| 428 |
<li><a href="#Starting-APL" accesskey="2">Starting APL</a></li> |
| 429 |
<li><a href="#Command-Line-Options" accesskey="3">Command Line Options</a></li> |
| 430 |
<li><a href="#Configuration-File-for-GNU-APL" accesskey="4">Configuration File for GNU APL</a></li> |
| 431 |
<li><a href="#File-Names-and-Paths" accesskey="5">File Names and Paths</a></li> |
| 432 |
</ul> |
| 433 |
<hr> |
| 434 |
<div class="section" id="Installing-APL"> |
| 435 |
<div class="header"> |
| 436 |
<p> |
| 437 |
Next: <a href="#Starting-APL" accesskey="n" rel="next">Starting APL</a>, Up: <a href="#Installing-and-Starting-GNU-APL" accesskey="u" rel="up">Installing and Starting GNU APL</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 438 |
</div> |
| 439 |
<span id="Installing-APL-1"></span><h3 class="section">1.1 Installing APL</h3> |
| 440 |
|
| 441 |
<p>APL is built and installed like this: |
| 442 |
</p> |
| 443 |
<ul> |
| 444 |
<li> download the tar file containing GNU APL, from |
| 445 |
<a href="ftp://ftp.gnu.org/gnu/apl">ftp://ftp.gnu.org/gnu/apl</a> or from one of its mirrors |
| 446 |
(see <a href="http://www.gnu.org/prep/ftp.html">http://www.gnu.org/prep/ftp.html</a>), and |
| 447 |
un-tar the file. |
| 448 |
|
| 449 |
</li><li> read (and follow) the instructions given in file README in the |
| 450 |
unpacked directory. |
| 451 |
</li></ul> |
| 452 |
|
| 453 |
<p>For the experienced, but impatient reader: it is the well-known sequence |
| 454 |
</p> |
| 455 |
<div class="example"> |
| 456 |
<pre class="example">$ ./configure [configure-option]... |
| 457 |
$ make |
| 458 |
$ sudo make install |
| 459 |
</pre></div> |
| 460 |
|
| 461 |
<p>On success, <b>make</b> produces an executable filee named <b>apl</b> in |
| 462 |
sub-directory <b>src</b> while <b>make install</b> installs that file (in |
| 463 |
<b>/usr/local/bin</b>) as well as some other files in other locations |
| 464 |
(that can be controlled via <b>configure-options</b>). |
| 465 |
</p> |
| 466 |
<p>File README contains further instructions about the installation GNU APL. |
| 467 |
</p> |
| 468 |
<hr> |
| 469 |
</div> |
| 470 |
<div class="section" id="Starting-APL"> |
| 471 |
<div class="header"> |
| 472 |
<p> |
| 473 |
Next: <a href="#Command-Line-Options" accesskey="n" rel="next">Command Line Options</a>, Previous: <a href="#Installing-APL" accesskey="p" rel="prev">Installing APL</a>, Up: <a href="#Installing-and-Starting-GNU-APL" accesskey="u" rel="up">Installing and Starting GNU APL</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 474 |
</div> |
| 475 |
<span id="Starting-APL-1"></span><h3 class="section">1.2 Starting APL</h3> |
| 476 |
|
| 477 |
<p>Last things first: before explaining how to start APL, it is important to |
| 478 |
remember how to stop (i.e. exit) it. Neither <b>^C</b> nor <b>^D</b> will stop |
| 479 |
APL - these serve other purposes. Instead, you leave APL with the command |
| 480 |
<b>)OFF</b> or <b>)off</b> (on a separate line) like this: |
| 481 |
</p> |
| 482 |
<div class="example"> |
| 483 |
<pre class="example"> )OFF |
| 484 |
</pre></div> |
| 485 |
|
| 486 |
|
| 487 |
<p>If APL is computing a function (and possibly caught in an endless loop), |
| 488 |
then you may have to press <b>^C</b> (this is called <i>ATTENTION</i> in APL) to |
| 489 |
return to APL’s command mode so that the <b>)OFF</b> command can be entered. |
| 490 |
In some circumstances it may be necessary to press <b>^C</b> twice within a |
| 491 |
short time interval (this is called <i>INTERRUPT</i> in APL). |
| 492 |
</p> |
| 493 |
<p>Using the )OFF command will not automatically save your work, however, a |
| 494 |
history of your GNU APL commands will have been preserved. Having that said, |
| 495 |
APL is started like every other program - by entering its name and optional |
| 496 |
command line parameters, for example: |
| 497 |
</p> |
| 498 |
<div class="example"> |
| 499 |
<pre class="example">$ apl |
| 500 |
</pre></div> |
| 501 |
|
| 502 |
<p>or: |
| 503 |
</p> |
| 504 |
<div class="example"> |
| 505 |
<pre class="example">$ apl -id 1001 |
| 506 |
</pre></div> |
| 507 |
|
| 508 |
<p>GNU APL is script-able; a text file whose first line looks like this (assuming |
| 509 |
the APL interpreter binary is called ’apl’ and is located in the current |
| 510 |
directory): |
| 511 |
</p> |
| 512 |
<div class="example"> |
| 513 |
<pre class="example">#! ./apl |
| 514 |
</pre></div> |
| 515 |
|
| 516 |
<p>or (if the APL interpreter binary is not in the current directory but in |
| 517 |
/mypath/apl): |
| 518 |
</p> |
| 519 |
<div class="example"> |
| 520 |
<pre class="example">#! /mypath/apl |
| 521 |
</pre></div> |
| 522 |
|
| 523 |
<p>The path to the ’apl’ binary can be missing (like in the first example), |
| 524 |
relative, or absolute (second example). The exact details of how the first |
| 525 |
line of a GNU APL script shall look vary slightly among operating systems. |
| 526 |
Please consult the <b>info</b> (or <b>man</b>) pages for <b>path_resolution</b> |
| 527 |
and/or <b>execve</b> |
| 528 |
on your operating system. After the name of the binary, optional GNU APL |
| 529 |
command line options, usually <b>–script</b>, can be provided. |
| 530 |
</p> |
| 531 |
<p>The text file must, of course, have execute permission, and should be ASCII |
| 532 |
or, more likely, UTF-8 encoded. The APL characters in the script shall be |
| 533 |
those defined in the Unicode character set (most of them in the U+2200 - |
| 534 |
U+23FF range). |
| 535 |
</p> |
| 536 |
<hr> |
| 537 |
</div> |
| 538 |
<div class="section" id="Command-Line-Options"> |
| 539 |
<div class="header"> |
| 540 |
<p> |
| 541 |
Next: <a href="#Configuration-File-for-GNU-APL" accesskey="n" rel="next">Configuration File for GNU APL</a>, Previous: <a href="#Starting-APL" accesskey="p" rel="prev">Starting APL</a>, Up: <a href="#Installing-and-Starting-GNU-APL" accesskey="u" rel="up">Installing and Starting GNU APL</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 542 |
</div> |
| 543 |
<span id="Command-Line-Options-1"></span><h3 class="section">1.3 Command Line Options</h3> |
| 544 |
|
| 545 |
<p>GNU APL understands the following command line options: |
| 546 |
</p> |
| 547 |
<ul> |
| 548 |
<li> <b>-C new_root</b> |
| 549 |
|
| 550 |
<p>Perform chroot("new_root") followed by chdir("/"). This restricts the access |
| 551 |
of the process running GNU APL to files in or below directory new_root, and |
| 552 |
it also changes the current directory (which could have resided above |
| 553 |
new_root before the chroot() was executed). |
| 554 |
</p> |
| 555 |
<p>The -C option is intended to be a security feature for GNU APL interpreters |
| 556 |
that are facing hostile environments such as the public Internet. |
| 557 |
</p> |
| 558 |
<p>NOTES: |
| 559 |
</p><ul> |
| 560 |
<li> For -C to work, new_root needs to contain a minimal set of binaries, in |
| 561 |
particular a shell, and possibly libraries needed by the shell. Consult |
| 562 |
’info chroot invocation’ for issues to consider and common pitfalls. |
| 563 |
|
| 564 |
</li><li> GNU APL processes the -C option (i.e. it calls chroot("new_root")) before |
| 565 |
all other command line options. As a consequence, file names in other command |
| 566 |
line options of GNU APL are also affected by -C. That means that the file |
| 567 |
names in command line options are being interpreted relative to new_root |
| 568 |
and <b>not</b> relative to the current directory of the process that had |
| 569 |
started GNU APL. |
| 570 |
|
| 571 |
</li><li> GNU APL may automatically start other processes such as APserver and friends |
| 572 |
after processing the -C option. These processes (and the libraries that they |
| 573 |
depend on) should reside in the proper directory below new_root. For example, |
| 574 |
with the default configuration of GNU APL, GNU APL installs itself in |
| 575 |
/usr/local/bin and also expects APserver in the same directory. After -C |
| 576 |
new_root, however, /usr/local/bin is no longer accessible and one would need |
| 577 |
to copy /usr/local/bin/APserver to new_root/usr/local/bin/APserver |
| 578 |
|
| 579 |
</li><li> Depending on your platform, the process using <b>-C</b> may need root privileges. |
| 580 |
|
| 581 |
</li></ul> |
| 582 |
|
| 583 |
</li><li> <code>--cfg</code> |
| 584 |
|
| 585 |
<p>Show ./configure options that were used to configure GNU APL, and exit. |
| 586 |
</p> |
| 587 |
</li><li> <b>–[no]Color</b> |
| 588 |
|
| 589 |
<p>Start with ]COLOR ON [OFF]. |
| 590 |
</p> |
| 591 |
</li><li> <b>–CPU_limit_secs sec</b> |
| 592 |
|
| 593 |
<p>Set CPU time limit to <i>sec</i> seconds. |
| 594 |
</p> |
| 595 |
</li><li> <code>-d</code> |
| 596 |
|
| 597 |
<p>Run the APL interpreter (or APL script) in the background (i.e. as a daemon). |
| 598 |
For this to work you need to provide some input to the background process, |
| 599 |
e.g. via the -f option. |
| 600 |
</p> |
| 601 |
</li><li> <code>--emacs</code> |
| 602 |
|
| 603 |
<p>Run in (old) Emacs mode. |
| 604 |
</p> |
| 605 |
</li><li> <code>--emacs_arg arg</code> |
| 606 |
|
| 607 |
<p>Run in (new) Emacs mode with argument arg. |
| 608 |
</p> |
| 609 |
</li><li> <code>--eval line</code> |
| 610 |
|
| 611 |
<p>Evaluate one APL <i>line</i> and exit (-s without -f is implied). This option |
| 612 |
can be given several times; in that case several lines will be executed in |
| 613 |
command line order before GNU apl exits. Keep in mind that command line |
| 614 |
options are normally processed by the shell before being passed to apl. |
| 615 |
Therefore quoting the argument of –eval may often be necessary and it is |
| 616 |
common wisdom to always quote the –eval argument. |
| 617 |
</p> |
| 618 |
</li><li> <code>-f file</code> |
| 619 |
|
| 620 |
<p>Read input from <i>file</i> rather than from the keyboard. When the end of |
| 621 |
the file is reached, input is switched back to the keyboard. |
| 622 |
If you want to terminate the APL interpreter after executing the file, |
| 623 |
then use )OFF as last line in the file or include the –OFF option. |
| 624 |
</p> |
| 625 |
</li><li> <code>--gpl</code> |
| 626 |
|
| 627 |
<p>Show GNU APL license (GPL) and exit. |
| 628 |
</p> |
| 629 |
</li><li> <code>-L wsname</code> |
| 630 |
|
| 631 |
<p>)LOAD wsname on start-up. |
| 632 |
</p> |
| 633 |
</li><li> <code>--LX expr</code> |
| 634 |
|
| 635 |
<p>Execute <b>expr</b> first. The workspace behaves as if ⎕LX (latent |
| 636 |
expression) were set to <b>expr</b> in the workspace. This can be used, |
| 637 |
for example, to start the same workspace with different start-up values. |
| 638 |
</p> |
| 639 |
</li><li> <code>-h</code>, <code>--help</code> |
| 640 |
|
| 641 |
<p>Print all command line options with a brief hint about what they do. |
| 642 |
</p> |
| 643 |
</li><li> <code>--id proc</code> |
| 644 |
|
| 645 |
<p>Use processor ID proc for this interpreter. If no ID is provided, then the |
| 646 |
first unused ID > 1000 is taken by this interpreter and the ID becomes used |
| 647 |
as long as the interpreter runs. Processor IDs are used by shared variables |
| 648 |
to identify share partners. |
| 649 |
</p> |
| 650 |
</li><li> <code>-l num</code> |
| 651 |
|
| 652 |
<p>Turn logging facility <b>num</b> ON (provided that dynamic logging was |
| 653 |
./configure’d). The logging facility 37 (start-up messages) is of particular |
| 654 |
importance for troubleshooting and it works even if dynamic logging |
| 655 |
was not ./configure’d. |
| 656 |
</p> |
| 657 |
</li><li> <code>--mem [memory-limit]</code> |
| 658 |
|
| 659 |
<p>Tell the interpreter not to use more than memory-limit bytes of RAM. By |
| 660 |
using this option, the user is fully responsible for ensuring that the |
| 661 |
specified amount of memory will always be available. The following rules |
| 662 |
should be observed. |
| 663 |
</p> |
| 664 |
<p>The interpreter will exit at start-up if <code>-mem</code> is used and: |
| 665 |
</p> |
| 666 |
<ul> |
| 667 |
<li> the platform on which the interpreter runs has no /proc/meminfo, or |
| 668 |
</li><li> the platform has no /proc/sys/vm/overcommit_memory, or |
| 669 |
</li><li> /proc/sys/vm/overcommit_memory is not 2 (aka. ’never overcommit’) |
| 670 |
</li></ul> |
| 671 |
|
| 672 |
<p>On GNU/Linux systems these conditions are normally satisfied, but the root |
| 673 |
user has to set /proc/sys/vm/overcommit_memory to 2 which differs from the |
| 674 |
default value 0 (aka. overcommit allowed). |
| 675 |
</p> |
| 676 |
<p>If no memory-limit is given, then a memory-limit of 50% is used. |
| 677 |
</p> |
| 678 |
<p>If a memory-limit is provided then it must have a unit of %, kB, MB, or GB. |
| 679 |
If the unit is % then the limit is computed as that percentage (between 5% |
| 680 |
and 95%) of parameter ’MemFree:’ in /proc/meminfo. Otherwise the limit |
| 681 |
is the given amount in kB, MB, or GB. |
| 682 |
</p> |
| 683 |
<p>For example: |
| 684 |
</p> |
| 685 |
<ul> |
| 686 |
<li> <code>--mem</code> (50% of MemFree: in /proc/meminfo are guaranteed) |
| 687 |
</li><li> <code>--mem 80%</code> (80% of MemFree: in /proc/meminfo are guaranteed) |
| 688 |
</li><li> <code>--mem 5G</code> (5 GB are guaranteed) |
| 689 |
</li></ul> |
| 690 |
|
| 691 |
<p>WARNING: The memory-limit is checked against parameter ’MemFree’ in |
| 692 |
/proc/meminfo when GNU APL starts, but this does not protect against |
| 693 |
other processes consuming the available free memory sometime later. |
| 694 |
</p> |
| 695 |
<p>If that happens (and according to the rules above the user has the |
| 696 |
responsibility to prevent it), then ⎕WA becomes unreliable and the |
| 697 |
interpreter may crash badly (i.e. without a WS FULL error, and without |
| 698 |
any chance to )SAVE the workspace) when the available memory is exhausted. |
| 699 |
</p> |
| 700 |
</li><li> <code>--echoCIN</code> |
| 701 |
|
| 702 |
<p>Copy the input line (after editing) to stdout. For creating session logs. |
| 703 |
</p> |
| 704 |
</li><li> <code>--noCIN</code> |
| 705 |
|
| 706 |
<p>Do not echo stdin to stdout. Almost a must for scripting (unless you |
| 707 |
intend to troubleshoot a script). |
| 708 |
</p> |
| 709 |
</li><li> <code>--to_COUT</code> |
| 710 |
|
| 711 |
<p>normally GNU APL writes its output to stderr (i.e. file descriptor 2) so that, |
| 712 |
when GNU APL is started in a script, the output of the script appears on |
| 713 |
stdout (i.e. file descriptor 1) while the output of GNU APL appears on stderr. |
| 714 |
</p> |
| 715 |
<p>This option redirects the stderr output of GNU APL to stdout. The same effect |
| 716 |
can be achieved with the option "OUTPUT-TO-COUT Yes" in a preferences file. |
| 717 |
</p> |
| 718 |
</li><li> <code>--tcp_port PORT</code> |
| 719 |
|
| 720 |
<p>This option starts GNU APL as a server that listens on TCP port PORT. |
| 721 |
Every TCP connection accepted by the server forks a new GNU APL instance |
| 722 |
which has its stdin, stdout, and stderr redirected to the TCP connection. |
| 723 |
</p> |
| 724 |
<p>WARNING: This option is dangerous if PORT is directly exposed to the Internet! |
| 725 |
</p> |
| 726 |
</li><li> <code>--noCONT</code> |
| 727 |
|
| 728 |
<p>Do not load a SETUP or CONTINUE workspace on start-up. |
| 729 |
</p> |
| 730 |
</li><li> <code>--OFF</code> |
| 731 |
|
| 732 |
<p>This option causes GNU APL to perform an automatic )OFF command after the |
| 733 |
last line of the last input file (as per -f option) was executed. |
| 734 |
</p> |
| 735 |
</li><li> <code>--PW COLS</code> |
| 736 |
|
| 737 |
<p>set the initial value of ⎕PW to COLS (min. 30, max. 10000) |
| 738 |
</p> |
| 739 |
</li><li> <code>--[no]SV</code> |
| 740 |
|
| 741 |
<p>do [not] start APserver (a shared variable server) on start-up. This disables |
| 742 |
communication with other workspaces or auxiliary processors through |
| 743 |
shared variables. |
| 744 |
</p> |
| 745 |
</li><li> <code>-p N</code> |
| 746 |
|
| 747 |
<p>use profile number N in preferences files. A preference file may contain |
| 748 |
several sets of settings for different purposes; the profile number selects |
| 749 |
one of these sets. |
| 750 |
</p> |
| 751 |
</li><li> <code>--par pproc</code> |
| 752 |
|
| 753 |
<p>Use processor parent ID pproc (default: no parent ID). |
| 754 |
</p> |
| 755 |
</li><li> <code>--rawCIN</code> |
| 756 |
|
| 757 |
<p>Do not emit ESC sequences. Normally ESC sequences are emitted for colored |
| 758 |
output and during line editing. In scripts, however, ESC sequences usually |
| 759 |
are not wanted and can be turned off with this option. |
| 760 |
</p> |
| 761 |
</li><li> <code>-s</code>, <code>--script</code> |
| 762 |
|
| 763 |
<p>This option is an abbreviation for: |
| 764 |
<code>--silent</code> <code>--noCIN</code> <code>--noCONT</code> <code>-f -</code> |
| 765 |
(which is a typical combination of options for APL scripts). |
| 766 |
</p> |
| 767 |
</li><li> <code>-q</code>, <code>--silent</code> |
| 768 |
|
| 769 |
<p>Suppress printing of the GNU APL welcome message. Useful for scripts. |
| 770 |
</p> |
| 771 |
</li><li> <code>--safe</code> |
| 772 |
|
| 773 |
<p>disable shared variables and native functions |
| 774 |
</p> |
| 775 |
</li><li> <code>--show_bin_dir</code> |
| 776 |
|
| 777 |
<p>Display the binary directory where, according to ./configure, the programs |
| 778 |
apl, APserver, AP100, and AP210 are installed. Then exit. |
| 779 |
</p> |
| 780 |
</li><li> <code>--show_doc_dir</code> |
| 781 |
|
| 782 |
<p>Display the directory where, according to ./configure, documentation files |
| 783 |
for GNU APL are installed. Then exit. |
| 784 |
</p> |
| 785 |
</li><li> <code>--show_etc_dir</code> |
| 786 |
|
| 787 |
<p>Display the system configuration directory where, according to ./configure, |
| 788 |
the preferences file for GNU APL is installed. Then exit. |
| 789 |
</p> |
| 790 |
</li><li> <code>--show_lib_dir</code> |
| 791 |
|
| 792 |
<p>Display the library directory where, according to ./configure, shared library |
| 793 |
files and the workspaces shipped with GNU APL are installed. Then exit. |
| 794 |
</p> |
| 795 |
</li><li> <code>--show_src_dir</code> |
| 796 |
|
| 797 |
<p>display the source directory where, according to ./configure, GNU APL |
| 798 |
was compiled. Then exit. This can be used, for example, by native functions |
| 799 |
that are built outside the GNU APL source tree to find GNU APL header files |
| 800 |
that are needed to compile the native function. |
| 801 |
</p> |
| 802 |
</li><li> <code>--show_all_dirs</code> |
| 803 |
|
| 804 |
<p>Display all the directories above. Then exit. |
| 805 |
</p> |
| 806 |
</li><li> <code>-T testcases ...</code> |
| 807 |
run testcases. Testcases are text files that contain both input to the APL |
| 808 |
interpreter and the expected response from the interpreter. The output from |
| 809 |
the interpreter is compared with the expected output in the testcase file(s) |
| 810 |
and differences are marked. In addition a summary file is created that tells |
| 811 |
whether or not each of the testcases was successful. |
| 812 |
|
| 813 |
</li><li> <code>--TM mode</code> |
| 814 |
|
| 815 |
<p>Test mode. This option specifies how the interpreter shall behave |
| 816 |
when running a number of testcases (as specified with the <code>-T</code> option). |
| 817 |
</p> |
| 818 |
<p><code>--TM 0</code> (default) run all testcases and exit after the last testcase. |
| 819 |
</p> |
| 820 |
<p><code>--TM 1</code> like <code>--TM 0</code> if no error was detected. |
| 821 |
However, if one of the testcases has failed, then the interpreter |
| 822 |
does not exit so that the user can investigate the state of APL |
| 823 |
(SI, variable values, etc.). |
| 824 |
</p> |
| 825 |
<p><code>--TM 2</code> like <code>--TM 1</code>, but stay in the interpreter even if |
| 826 |
all testcases have passed. This can be useful for quickly bringing the |
| 827 |
interpreter into a specific state and continue manual troubleshooting |
| 828 |
from that state. |
| 829 |
</p> |
| 830 |
<p><code>--TM 3</code> like <code>--TM 1</code>, but stop testcase execution after the |
| 831 |
first failed testcase (i.e. do not exit). |
| 832 |
</p> |
| 833 |
<p><code>--TM 4</code> like <code>--TM 3</code>, but exit after the first failed |
| 834 |
testcase. This is useful for automatic regression tests, where no errors |
| 835 |
are expected. |
| 836 |
</p> |
| 837 |
</li><li> <code>--TR</code> |
| 838 |
|
| 839 |
<p>Executes test case files in random order. |
| 840 |
</p> |
| 841 |
</li><li> <code>--TS</code> |
| 842 |
|
| 843 |
<p>Normally, when the interpreter is run with the <code>T</code> option, |
| 844 |
an existing summary.log file is overwritten without notice. |
| 845 |
This option causes new test results to be appended to a possibly |
| 846 |
existing summary.log instead of overwriting it. |
| 847 |
</p> |
| 848 |
</li><li> <code>-v</code>, <code>--version</code>, |
| 849 |
|
| 850 |
<p>Show version information and exit. |
| 851 |
</p> |
| 852 |
</li><li> <code>-u UID</code> |
| 853 |
|
| 854 |
<p>Run as user with UID 0. This option can only be used by the root user (who |
| 855 |
then wants to run as a different user). |
| 856 |
</p> |
| 857 |
</li><li> <code>-w milli</code> |
| 858 |
|
| 859 |
<p>wait milli milliseconds at start-up. Useful to give other programs that are |
| 860 |
started together with this interpreter time to initialize themselves. |
| 861 |
</p> |
| 862 |
</li><li> <code>| +APPOPT|</code> |
| 863 |
</li><li> <code>| ++APPOPT ARG1|</code> |
| 864 |
</li><li> <code>|+++APPOPT ARG1 ARG2|</code> |
| 865 |
</li><li> ... |
| 866 |
|
| 867 |
<p>Those command line options above that start with + are understood by the |
| 868 |
GNU APL binary and their arguments must follow the description given for |
| 869 |
them. In addition the interpreter also accepts command line options that |
| 870 |
start with +. However, these options are not checked by the interpreter |
| 871 |
in any way, but are merely copied to <b>⎕ARG</b> (see below). In these options, |
| 872 |
APPOPT, ARG1, ARG2, ... are arbitrary strings that should not contain any |
| 873 |
whitespace characters. The purpose of these options is to control aspects |
| 874 |
of the APL application from the command line. |
| 875 |
</p> |
| 876 |
</li><li> <code>-</code> |
| 877 |
|
| 878 |
<p>End of command line options for the interpreter. GNU APL provides the system |
| 879 |
variable ⎕ARG that returns all command line options with which the GNU APL |
| 880 |
interpreter was invoked (similar to variable argv in main(int argc, |
| 881 |
char * argv[]) in C/C++). Option <code>-</code> can be used to separate command line |
| 882 |
options for the APL interpreter from command line options understood by APL |
| 883 |
applications. |
| 884 |
</p> |
| 885 |
<p>Thus, |
| 886 |
</p> |
| 887 |
<p><code>(⎕ARG ⍳ ⊂'--') ↑ ⎕ARG</code> returns the options for the APL interpreter, while |
| 888 |
</p> |
| 889 |
<p><code>(⎕ARG ⍳ ⊂'--') ↓ ⎕ARG</code> returns the options for the APL application. |
| 890 |
</p> |
| 891 |
<p>All command line options after <code>-</code> are ignored by the interpreter |
| 892 |
(except for including them in ⎕ARG). |
| 893 |
</p> |
| 894 |
</li></ul> |
| 895 |
|
| 896 |
<hr> |
| 897 |
</div> |
| 898 |
<div class="section" id="Configuration-File-for-GNU-APL"> |
| 899 |
<div class="header"> |
| 900 |
<p> |
| 901 |
Next: <a href="#File-Names-and-Paths" accesskey="n" rel="next">File Names and Paths</a>, Previous: <a href="#Command-Line-Options" accesskey="p" rel="prev">Command Line Options</a>, Up: <a href="#Installing-and-Starting-GNU-APL" accesskey="u" rel="up">Installing and Starting GNU APL</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 902 |
</div> |
| 903 |
<span id="Configuration-File-for-GNU-APL-1"></span><h3 class="section">1.4 Configuration File for GNU APL</h3> |
| 904 |
|
| 905 |
<p>The default values for some of the command line options discussed in the |
| 906 |
previous section can be set in a configuration file for GNU APL. The name |
| 907 |
of the configuration file is ’preferences’ and it should live in one of |
| 908 |
the following directories: |
| 909 |
</p> |
| 910 |
<ul> |
| 911 |
<li> in the sub-directory gnu-apl.d of the system configuration directory, or |
| 912 |
|
| 913 |
</li><li> in the sub-directory .config/gnu-apl of the user’s home directory (as per |
| 914 |
$HOME). |
| 915 |
|
| 916 |
</li></ul> |
| 917 |
|
| 918 |
<p>The system configuration directory is usually /etc or /usr/local/etc and is |
| 919 |
configurable via <samp>./configure --sysconfdir</samp>. An empty (i.e. most |
| 920 |
settings commented out) preferences file is also installed in the |
| 921 |
system configuration directory when GNU APL is installed. You can edit |
| 922 |
it, use it as a template or read it to see which options can be controlled. |
| 923 |
</p> |
| 924 |
<p>If file ’preferences’ exists in both directories, the settings in |
| 925 |
$HOME/.config/gnu-apl/preferences override settings in, for example, |
| 926 |
/etc/gnu-apl.d/preferences. |
| 927 |
</p> |
| 928 |
<p>Command line options in turn override settings in ’preferences’ files. |
| 929 |
</p> |
| 930 |
<hr> |
| 931 |
</div> |
| 932 |
<div class="section" id="File-Names-and-Paths"> |
| 933 |
<div class="header"> |
| 934 |
<p> |
| 935 |
Previous: <a href="#Configuration-File-for-GNU-APL" accesskey="p" rel="prev">Configuration File for GNU APL</a>, Up: <a href="#Installing-and-Starting-GNU-APL" accesskey="u" rel="up">Installing and Starting GNU APL</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 936 |
</div> |
| 937 |
<span id="File-Names-and-Paths-1"></span><h3 class="section">1.5 File Names and Paths</h3> |
| 938 |
|
| 939 |
<p>The GNU APL interpreter is a binary file named <b>apl</b>. It is usually |
| 940 |
installed in directory <b>/usr/bin/</b> or in <b>/usr/local/bin/</b>. The location |
| 941 |
where <b>apl</b> is installed can be changed via <b>./configure</b> options |
| 942 |
(see file <b>INSTALL</b>). |
| 943 |
</p> |
| 944 |
<p>GNU APL understands 4 file types: |
| 945 |
</p> |
| 946 |
<ol> |
| 947 |
<li> <i>APL workspaces</i> that can be manipulated with the <b>)LOAD</b>, <b>)SAVE</b>, |
| 948 |
<b>)COPY</b>, and <b>)DROP</b> commands. APL workspaces are XML files and shall |
| 949 |
have a file extension of <b>.xml</b> to be accepted by GNU APL. APL |
| 950 |
workspaces can only be exchanged between machines that all run GNU APL. |
| 951 |
|
| 952 |
</li><li> <i>APL exchange files</i> can be manipulated with the <b>)IN</b> and <b>)OUT</b> |
| 953 |
commands. APL exchange files are text files in <b>⎕TF</b> format defined |
| 954 |
by IBM (basically APL expressions that create variables or functions) |
| 955 |
and shall have a file extension of <b>.atf</b> to be accepted by GNU APL. |
| 956 |
APL exchange files can be exchanged between machines running APL |
| 957 |
interpreters from different vendors. The <b>⎕TF</b> format can be easily |
| 958 |
emulated on machines that do not not provide compatible <b>)IN</b> and |
| 959 |
<b>)OUT</b> commands. |
| 960 |
|
| 961 |
</li><li> <i>APL scripts</i> consist of APL commands and APL expressions (including |
| 962 |
function definition via <b>∇</b>) like they would be entered by the user. |
| 963 |
APL scripts should have a file extension of <b>.apl</b> but other extensions |
| 964 |
are also accepted by GNU APL. APL scripts are, for example, the files |
| 965 |
expected for the -f command line option. A workspace can be written in this |
| 966 |
format with the i<b>)DUMP</b> command and can become an active workspace |
| 967 |
using the <b>)LOAD</b> command. |
| 968 |
|
| 969 |
</li><li> <i>APL testcase files</i> are similar to APL scripts, but in addition to |
| 970 |
the APL commands and expressions they also contain the expected output |
| 971 |
from the commands. |
| 972 |
APL testcase files normally have a file extension of <b>.tc</b> for normal |
| 973 |
(functional) testcases and <b>.pt</b> for performance testcases. |
| 974 |
APL testcase files are, for example, the files expected for the |
| 975 |
<b>-T</b> command line option. |
| 976 |
</li></ol> |
| 977 |
|
| 978 |
<p>The following APL commands are related to file names: |
| 979 |
</p> |
| 980 |
<ul> |
| 981 |
<li> )LOAD [lib] name[.xml|.apl] |
| 982 |
</li><li> )SAVE [lib] [name[.xml]] |
| 983 |
</li><li> )COPY [lib] [name[.xml|.apl]] |
| 984 |
</li><li> )PCOPY [lib] [name[.xml|.apl]] |
| 985 |
</li><li> )DROP [lib] [name[.xml|.apl]] |
| 986 |
</li><li> )IN [lib] name[.atf] |
| 987 |
</li><li> )PIN [lib] name[.atf] |
| 988 |
</li><li> )OUT [lib] name[.atf] |
| 989 |
</li><li> )DUMP [lib] [name[.apl]] |
| 990 |
</li><li> )LIB [lib] |
| 991 |
</li><li> )LIBS [new-lib-root] |
| 992 |
</li><li> )WSID [name] |
| 993 |
</li></ul> |
| 994 |
|
| 995 |
<p>The rules for how file names are constructed from the argument(s) of an APL |
| 996 |
command above are: |
| 997 |
</p> |
| 998 |
<ol> |
| 999 |
<li> command arguments shown in brackets are optional. |
| 1000 |
</li><li> <b>lib</b> is a number from 0 to 9. If lib is not present then 0 is taken |
| 1001 |
as default. |
| 1002 |
</li><li> if the <b>name</b> is optional and missing then the workspace ID (the name |
| 1003 |
set with the <b>)WSID</b> command) is used. |
| 1004 |
</li><li> if the file extension (i.e. <b>.apl</b>, <b>.xml</b> or <b>.atf</b>) is missing |
| 1005 |
then it is appended automatically to name. |
| 1006 |
</li></ol> |
| 1007 |
|
| 1008 |
<p>If the <b>name</b> starts with ’/’ then it is taken as an absolute path to |
| 1009 |
the file (an absolute file name) and no further computation is done |
| 1010 |
with the name. |
| 1011 |
</p> |
| 1012 |
<p>Otherwise <b>name</b> is a relative path which is relative to some directory |
| 1013 |
library-root and a sub-directory of library-root that is determined by |
| 1014 |
the <b>lib</b> number. The library numbers 0-9 correspond to the following |
| 1015 |
directories: |
| 1016 |
</p> |
| 1017 |
<p>0: library-root/workspaces/ |
| 1018 |
</p> |
| 1019 |
<p>1: library-root/wslib1/ |
| 1020 |
</p> |
| 1021 |
<p>2: library-root/wslib2/ |
| 1022 |
</p> |
| 1023 |
<p>... |
| 1024 |
</p> |
| 1025 |
<p>9: library-root/wslib9/ |
| 1026 |
</p> |
| 1027 |
<p>The command <b>)LIBS</b> without arguments shows the mapping between library |
| 1028 |
numbers and paths. The command )LIBS with an argument sets a new lib-root. |
| 1029 |
</p> |
| 1030 |
<p>The command )LIB [lib] shows the files in library (i.e. directory) lib. |
| 1031 |
</p> |
| 1032 |
<p>The directory library-root is computed as follows when the interpreter starts: |
| 1033 |
</p> |
| 1034 |
<p>If environment variable <b>APL_LIB_ROOT</b> is defined, then its value is used |
| 1035 |
as the library-root. Otherwise the path from the current directory (".") up to |
| 1036 |
the root directory ("/") is searched until a directory containing two |
| 1037 |
sub-directories <b>workspaces</b> and <b>wslib1</b> is found. Normally <b>workspaces</b> |
| 1038 |
and <b>wslib1</b> are directories, but for the computation of library-root files |
| 1039 |
suffice. |
| 1040 |
</p> |
| 1041 |
<p>If such a directory is found, then it is used as library-root; otherwise the |
| 1042 |
current directory (i.e. ".") is used and converted to an absolute path. |
| 1043 |
</p> |
| 1044 |
<p>For example, if library-root is "." then the command |
| 1045 |
</p> |
| 1046 |
<div class="example"> |
| 1047 |
<pre class="example">)LOAD 2 test |
| 1048 |
</pre></div> |
| 1049 |
|
| 1050 |
<p>will try to load the workspace file |
| 1051 |
</p> |
| 1052 |
<p>./wslib2/test.xml |
| 1053 |
</p> |
| 1054 |
<p>Using a library root implies that all 10 library directories are contained |
| 1055 |
in the same directory. This is good enough for single-user environments but |
| 1056 |
is often not adequate for multi-user environments where some directories |
| 1057 |
are not writable by users and different users have different home directories. |
| 1058 |
</p> |
| 1059 |
<p>For that reason the above library root scheme can be overridden by the |
| 1060 |
GNU APL configuration files (named <b>preferences</b>). In these files you can |
| 1061 |
un-comment any of the <b>LIBREF-0</b> to <b>LIBREF-9</b> settings (which correspond |
| 1062 |
to library numbers 0 to 9) and provide your own paths. The library numbers |
| 1063 |
that are <b>NOT</b> overridden in a <b>preferences</b> file still follow the |
| 1064 |
library root scheme. |
| 1065 |
</p> |
| 1066 |
<hr> |
| 1067 |
</div> |
| 1068 |
</div> |
| 1069 |
<div class="chapter" id="Non_002dstandard-GNU-APL-Features"> |
| 1070 |
<div class="header"> |
| 1071 |
<p> |
| 1072 |
Next: <a href="#Limitations-and-Missing-Features" accesskey="n" rel="next">Limitations and Missing Features</a>, Previous: <a href="#Installing-and-Starting-GNU-APL" accesskey="p" rel="prev">Installing and Starting GNU APL</a>, Up: <a href="#Top" accesskey="u" rel="up">GNU APL Reference Manual</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 1073 |
</div> |
| 1074 |
<span id="Non_002dstandard-GNU-APL-Features-1"></span><h2 class="chapter">2 Non-standard GNU APL Features</h2> |
| 1075 |
|
| 1076 |
<p>There are a few hopefully useful features in GNU APL: |
| 1077 |
</p> |
| 1078 |
<ul class="section-toc"> |
| 1079 |
<li><a href="#APL-Scripting" accesskey="1">APL Scripting</a></li> |
| 1080 |
<li><a href="#Axis-argument-in-defined-functions" accesskey="2">Axis argument in defined functions</a></li> |
| 1081 |
<li><a href="#Function-Groups" accesskey="3">Function Groups</a></li> |
| 1082 |
<li><a href="#Colored-Output" accesskey="4">Colored Output</a></li> |
| 1083 |
<li><a href="#Comparison-Rules" accesskey="5">Comparison Rules</a></li> |
| 1084 |
<li><a href="#Complex-Numbers" accesskey="6">Complex Numbers</a></li> |
| 1085 |
<li><a href="#Debug-Commands" accesskey="7">Debug Commands</a></li> |
| 1086 |
<li><a href="#Direct-Functions-_0028Lambdas_0029" accesskey="8">Direct Functions (Lambdas)</a></li> |
| 1087 |
<li><a href="#Commands-_0029COPY_005fONCE-_0029DUMP-and-DUMP_002dHTML" accesskey="9">Commands )COPY_ONCE, )DUMP, and DUMP-HTML</a></li> |
| 1088 |
<li><a href="#g_t_005dDOXY-Command">]DOXY Command</a></li> |
| 1089 |
<li><a href="#g_t_005dKEYB-Command">]KEYB Command</a></li> |
| 1090 |
<li><a href="#g_t_005dNEXTFILE-and-_005dPUSHFILE-Commands">]NEXTFILE and ]PUSHFILE Commands</a></li> |
| 1091 |
<li><a href="#History-and-TAB-completion">History and TAB completion</a></li> |
| 1092 |
<li><a href="#Logging-Facilities">Logging Facilities</a></li> |
| 1093 |
<li><a href="#Rational-Numbers">Rational Numbers</a></li> |
| 1094 |
<li><a href="#Hex-Numbers">Hex Numbers</a></li> |
| 1095 |
<li><a href="#User_002ddefined-Commands">User-defined Commands</a></li> |
| 1096 |
<li><a href="#Structured-Variables-and-Associative-Arrays">Structured Variables and Associative Arrays</a></li> |
| 1097 |
<li><a href="#Monadic-_22a2-and-_22a3_003b-dyadic-_22a2-with-Axis">Monadic ⊢ and ⊣; dyadic ⊢ with Axis</a></li> |
| 1098 |
<li><a href="#Bit_002dwise-Logical-Functions_003a-_22a4_2227-_22a4_2228-_22a4_2372-_22a4_2371-_22a4_2260-and-_22a4_003d">Bit-wise Logical Functions ⊤∧, ⊤∨, ⊤⍲, ⊤⍱, ⊤≠, and ⊤=</a></li> |
| 1099 |
<li><a href="#g_t_22a4-_0028Encode_0029-with-Axis">⊤ (Encode) with Axis</a></li> |
| 1100 |
<li><a href="#Generalized-_2373">Generalized ⍳</a></li> |
| 1101 |
<li><a href="#g_t_2339_005bX_005d-_002d-Miscellaneous-Matrix-and-Vector-Operations">⌹[X] - Miscellaneous Matrix and Vector Operations</a></li> |
| 1102 |
<li><a href="#g_t_2395CC-_002d-Character-Classes">⎕CC - Character Classes</a></li> |
| 1103 |
<li><a href="#Dyadic-_2395CR">Dyadic ⎕CR</a></li> |
| 1104 |
<li><a href="#Dyadic-_2395FX-_0028Native-Functions_0029">Dyadic ⎕FX (Native Functions)</a></li> |
| 1105 |
<li><a href="#g_t_2395ARG-_002d-Interpreter-command-line-arguments">⎕ARG - Interpreter command line arguments</a></li> |
| 1106 |
<li><a href="#g_t_2395DLX-_002d-Knuth_0027s-Dancing-Links-Algorithm">⎕DLX - Knuth’s Dancing Links Algorithm</a></li> |
| 1107 |
<li><a href="#g_t_2395ENV-_002d-Environment-Variables">⎕ENV - Environment Variables</a></li> |
| 1108 |
<li><a href="#g_t_2395FIO-_002d-File-I_002fO-Functions">⎕FIO - File I/O Functions</a></li> |
| 1109 |
<li><a href="#g_t_2395FFT-_002d-Fast-Fourier-Transform">⎕FFT - Fast Fourier Transform</a></li> |
| 1110 |
<li><a href="#g_t_2395GTK-_002d-GTK-Interface">⎕GTK - GTK Interface</a></li> |
| 1111 |
<li><a href="#g_t_2395JSON-_002d-JSON-Parsing">⎕JSON - JSON Parsing</a></li> |
| 1112 |
<li><a href="#g_t_2395MAP-_002d-Map-Value">⎕MAP - Map Value</a></li> |
| 1113 |
<li><a href="#g_t_2395MX-_002d-Matrix_002fStatistics">⎕MX - Matrix/Statistics</a></li> |
| 1114 |
<li><a href="#g_t_2395PLOT-_002d-Plot-Data">⎕PLOT - Plot Data</a></li> |
| 1115 |
<li><a href="#g_t_2395PNG-_002d-Portable-Network-Graphics">⎕PNG - Portable Network Graphics</a></li> |
| 1116 |
<li><a href="#g_t_2395PS-_002d-Print-Style">⎕PS - Print Style</a></li> |
| 1117 |
<li><a href="#g_t_2395RE-_002d-Regular-Expressions">⎕RE - Regular Expressions</a></li> |
| 1118 |
<li><a href="#g_t_2395RVAL-_002d-Random-APL-value">⎕RVAL - Random APL value</a></li> |
| 1119 |
<li><a href="#g_t_2395SI-_002d-State-Indicator">⎕SI - State Indicator</a></li> |
| 1120 |
<li><a href="#g_t_2395SQL-_002d-SQL-Database-Interface">⎕SQL - SQL Database Interface</a></li> |
| 1121 |
<li><a href="#g_t_2395SYL-_002d-System-limits">⎕SYL - System limits</a></li> |
| 1122 |
<li><a href="#g_t_2395XML-_002d-XML-Parsing">⎕XML - XML Parsing</a></li> |
| 1123 |
<li><a href="#Conditionals">Conditionals</a></li> |
| 1124 |
<li><a href="#Matrix-Product">Matrix Product</a></li> |
| 1125 |
<li><a href="#Monadic-_2260-_0028Nub-Sieve_0029">Monadic ≠ (Nub Sieve)</a></li> |
| 1126 |
</ul> |
| 1127 |
<hr> |
| 1128 |
<div class="section" id="APL-Scripting"> |
| 1129 |
<div class="header"> |
| 1130 |
<p> |
| 1131 |
Next: <a href="#Axis-argument-in-defined-functions" accesskey="n" rel="next">Axis argument in defined functions</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 1132 |
</div> |
| 1133 |
<span id="APL-Scripting-1"></span><h3 class="section">2.1 APL Scripting</h3> |
| 1134 |
|
| 1135 |
<ul class="section-toc"> |
| 1136 |
<li><a href="#Introduction-and-Terminology" accesskey="1">Introduction and Terminology</a></li> |
| 1137 |
<li><a href="#Redirect-the-script-file-to-the-stdin-of-the-GNU-APL-interpreter" accesskey="2">Redirect the script file to the stdin of the GNU APL interpreter</a></li> |
| 1138 |
<li><a href="#Make-the-script-file-executable" accesskey="3">Make the script file executable</a></li> |
| 1139 |
<li><a href="#Starting-GNU-APL-Scripts_003a-a-Conclusion" accesskey="4">Starting GNU APL Scripts: a Conclusion</a></li> |
| 1140 |
<li><a href="#How-command-line-arguments-are-handled" accesskey="5">How command line arguments are handled</a></li> |
| 1141 |
<li><a href="#Helpful-Features-for-Scripting" accesskey="6">Helpful Features for Scripting</a></li> |
| 1142 |
<li><a href="#Double_002dquoted-Strings" accesskey="7">Double-quoted Strings</a></li> |
| 1143 |
<li><a href="#Multi_002dLine-Strings" accesskey="8">Multi-Line Strings</a></li> |
| 1144 |
<li><a href="#Multi_002dLine-Literals" accesskey="9">Multi-Line Literals</a></li> |
| 1145 |
<li><a href="#Automatic-_0029MORE">Automatic )MORE</a></li> |
| 1146 |
<li><a href="#Script-Example">Script Example</a></li> |
| 1147 |
</ul> |
| 1148 |
<hr> |
| 1149 |
<div class="subsection" id="Introduction-and-Terminology"> |
| 1150 |
<div class="header"> |
| 1151 |
<p> |
| 1152 |
Next: <a href="#Redirect-the-script-file-to-the-stdin-of-the-GNU-APL-interpreter" accesskey="n" rel="next">Redirect the script file to the stdin of the GNU APL interpreter</a>, Up: <a href="#APL-Scripting" accesskey="u" rel="up">APL Scripting</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 1153 |
</div> |
| 1154 |
<span id="Introduction-and-Terminology-1"></span><h4 class="subsection">2.1.1 Introduction and Terminology</h4> |
| 1155 |
|
| 1156 |
<p>A <i>script</i> is a text file that contains the source code of an interpreted |
| 1157 |
programming language. An <i>APL script</i> is a text file that contains <i>APL |
| 1158 |
commands</i> (like <b>)LOAD</b> or <b>)OFF</b>) and <i>APL expressions</i> like |
| 1159 |
<b>1 2 3+ 4 5 6</b>. In GNU APL a script can also contains instructions for |
| 1160 |
the well-known ∇-editor in order to create defines functions. |
| 1161 |
</p> |
| 1162 |
<p>On most platforms are the lines of a script separated by the single ASCII |
| 1163 |
character linefeed (<b>LF</b>, ASCII code 10); on Microsoft operating systems |
| 1164 |
the lines are separated by two characters carriage return (<b>CR</b>, ASCII |
| 1165 |
code 13) and (<b>LF</b>. ASCII code 10). GNU APL ignores <b>CR</b> in most contexts |
| 1166 |
so that the same APL script can be executed on both kinds of platforms. |
| 1167 |
</p> |
| 1168 |
<p>The first line of a script is called the <i>shebang line</i>. The shebang line |
| 1169 |
determines how and with which arguments the script shall be executed. When |
| 1170 |
the operating system (or, more precisely: a shell of the operating system) |
| 1171 |
executes a script then it parses the shebang line and calls a function |
| 1172 |
<b>execve</b> whose arguments are the result of that parsing. Much of how |
| 1173 |
GNU APL handles APL scripts can be learned by consulting the |
| 1174 |
<b>man</b> page for function <b>execve</b>. To quote that <b>man</b> page: |
| 1175 |
</p> |
| 1176 |
<div class="example -"> |
| 1177 |
<pre class="example"> ... |
| 1178 |
|
| 1179 |
Interpreter scripts |
| 1180 |
An interpreter script is a text file that has execute permission enabled and whose |
| 1181 |
first line is of the form: |
| 1182 |
|
| 1183 |
#!interpreter [optional-arg] |
| 1184 |
|
| 1185 |
The interpreter must be a valid pathname for an executable file. |
| 1186 |
|
| 1187 |
If the pathname argument of execve() specifies an interpreter script, |
| 1188 |
then interpreter will be invoked with the following arguments: |
| 1189 |
|
| 1190 |
interpreter [optional-arg] pathname arg... |
| 1191 |
|
| 1192 |
where pathname is the absolute pathname of the file specified as the |
| 1193 |
first argument of execve(), and arg... is the series of words pointed |
| 1194 |
to by the argv argument of execve(), starting at argv[1]. Note that |
| 1195 |
there is no way to get the argv[0] that was passed to the execve() |
| 1196 |
call. |
| 1197 |
|
| 1198 |
... |
| 1199 |
</pre></div> |
| 1200 |
|
| 1201 |
<p>It is important to note the <i>singular</i> in <b>[optional-arg]</b> above. |
| 1202 |
Traditionally the interpreter would have been <b>/usr/local/bin/apl</b> |
| 1203 |
(if GNU APL was installed in directory <b>/usr/local/bin/</b> or else |
| 1204 |
<b>/usr/bin/apl</b> (if GNU APL was installed in directory <b>/usr/bin/</b>). |
| 1205 |
These days, however, it has become common practice not to call the |
| 1206 |
interpreter directly, but to call the program <b>/usr/bin/env</b> as the |
| 1207 |
interpreter and passing the real interpreter (i.e. /usr/local/bin/apl or |
| 1208 |
apl) to <b>/bin/env</b>. For example: |
| 1209 |
</p> |
| 1210 |
<div class="example"> |
| 1211 |
<pre class="example">Traditional shebang line (full path to the interpreter): |
| 1212 |
|
| 1213 |
#!/usr/local/bin/apl --script |
| 1214 |
|
| 1215 |
Traditional shebang line (interpreter name only): |
| 1216 |
|
| 1217 |
#!apl --script |
| 1218 |
|
| 1219 |
Contemporary shebang line: |
| 1220 |
|
| 1221 |
#!/bin/env -S apl --script |
| 1222 |
</pre></div> |
| 1223 |
|
| 1224 |
<p>For a single argument the shebang lines above have essentially the same |
| 1225 |
effect. The long form (full path to the interpreter) is needed only if the |
| 1226 |
interpreter interpreter can not be found in one of the directories listed |
| 1227 |
in the environment variable <b>$PATH</b>, for example if a user installs GNU APL |
| 1228 |
in a non-standard directory (i.e. other than in <b>/bin</b>, <b>/usr/bin</b>, or |
| 1229 |
<b>/usr/local/bin</b>). |
| 1230 |
</p> |
| 1231 |
<p>A minor disadvantage of using <b>env</b> as the interpreter is that |
| 1232 |
<b>execve()</b> is called twice: first by the shell to run <b>env</b> and then |
| 1233 |
by <b>env</b> to run <b>apl</b>. |
| 1234 |
</p> |
| 1235 |
<p>A potential advantage of using <b>/bin/env</b> as the interpreter is the <b>-S</b> |
| 1236 |
option of <b>/bin/env</b> which works around the single argument limitation |
| 1237 |
of <b>execve</b>. However, this advantage only to programs other than |
| 1238 |
GNU APL because GNU APL comes with a built-in capability that is |
| 1239 |
essentially doing the same as the <b>-S</b> option of <b>/bin/env</b>. Another, |
| 1240 |
more important, aspect is portability. On a GNU/Linux system the standard |
| 1241 |
shells (<b>bash</b>, <b>dash</b>) seem to pass multiple arguments in the shebang |
| 1242 |
line to the interpreter in a way that GNU APL understands. Whether all |
| 1243 |
systems behave in the same way is, however, not known. Therefore using |
| 1244 |
<b>/bin/env</b> (with multiple arguments quoted) might be a more portable |
| 1245 |
approach than starting GNU APL directly. |
| 1246 |
</p> |
| 1247 |
<p>For multiple arguments the situation is more tricky and the |
| 1248 |
two methods differ slightly. The <b>/bin/env</b> |
| 1249 |
method requires that multiple arguments are being quoted in the shebang |
| 1250 |
line (so that they beconme a single argument which <b>env -S</b> splits into |
| 1251 |
several arguments passed to <b>execve</b>). the direct <b>apl</b> method does |
| 1252 |
the same, but without the need to quote multiple arguments in the |
| 1253 |
shebang line. For example: |
| 1254 |
</p> |
| 1255 |
<div class="example"> |
| 1256 |
<pre class="example"> #!apl --script --id 1010 |
| 1257 |
|
| 1258 |
#!/bin/env -S apl "--script --id 1010" |
| 1259 |
</pre></div> |
| 1260 |
|
| 1261 |
<p>A nasty pitfall of <b>/bin/env</b> is not to quote multiple arguments: |
| 1262 |
</p> |
| 1263 |
<div class="example"> |
| 1264 |
<pre class="example">$ cat SCRIPT2.apl |
| 1265 |
#!/usr/bin/env -S apl --id 1010 |
| 1266 |
|
| 1267 |
$ ./SCRIPT2.apl |
| 1268 |
unknown option './SCRIPT2.apl' |
| 1269 |
... |
| 1270 |
|
| 1271 |
$ cat SCRIPT3.apl |
| 1272 |
#!/usr/bin/env apl --id 1010 |
| 1273 |
|
| 1274 |
$ b./SCRIPT2.apl |
| 1275 |
/usr/bin/env: ‘apl --id 1010’: No such file or directory |
| 1276 |
/usr/bin/env: use -[v]S to pass options in shebang lines |
| 1277 |
</pre></div> |
| 1278 |
|
| 1279 |
<hr> |
| 1280 |
</div> |
| 1281 |
<div class="subsection" id="Redirect-the-script-file-to-the-stdin-of-the-GNU-APL-interpreter"> |
| 1282 |
<div class="header"> |
| 1283 |
<p> |
| 1284 |
Next: <a href="#Make-the-script-file-executable" accesskey="n" rel="next">Make the script file executable</a>, Previous: <a href="#Introduction-and-Terminology" accesskey="p" rel="prev">Introduction and Terminology</a>, Up: <a href="#APL-Scripting" accesskey="u" rel="up">APL Scripting</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 1285 |
</div> |
| 1286 |
<span id="Redirect-the-script-file-to-the-stdin-of-the-GNU-APL-interpreter-1"></span><h4 class="subsection">2.1.2 Redirect the script file to the stdin of the GNU APL interpreter</h4> |
| 1287 |
|
| 1288 |
<p>Another method to execute an APL script file, say <b>SCRIPT.apl</b>, is to |
| 1289 |
use the input redirection of the shall: |
| 1290 |
</p> |
| 1291 |
<div class="example"> |
| 1292 |
<pre class="example">$ apl < SCRIPT.apl # input redirection of SCRIPT.apl to stdin of apl |
| 1293 |
</pre></div> |
| 1294 |
|
| 1295 |
<p>Alternatively, the GNU APL command line option <b>-f</b> or <b>-s</b> can be used: |
| 1296 |
</p> |
| 1297 |
<div class="example"> |
| 1298 |
<pre class="example">$ apl -f SCRIPT.apl |
| 1299 |
$ apl -s SCRIPT.apl |
| 1300 |
</pre></div> |
| 1301 |
|
| 1302 |
<p>Both ways of redirecting the file are almost identical; in the first case |
| 1303 |
redirection was performed by the shell running apl, while in the second case |
| 1304 |
the redirecting of the file was performed by apl itself. |
| 1305 |
</p> |
| 1306 |
<hr> |
| 1307 |
</div> |
| 1308 |
<div class="subsection" id="Make-the-script-file-executable"> |
| 1309 |
<div class="header"> |
| 1310 |
<p> |
| 1311 |
Next: <a href="#Starting-GNU-APL-Scripts_003a-a-Conclusion" accesskey="n" rel="next">Starting GNU APL Scripts: a Conclusion</a>, Previous: <a href="#Redirect-the-script-file-to-the-stdin-of-the-GNU-APL-interpreter" accesskey="p" rel="prev">Redirect the script file to the stdin of the GNU APL interpreter</a>, Up: <a href="#APL-Scripting" accesskey="u" rel="up">APL Scripting</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 1312 |
</div> |
| 1313 |
<span id="Make-the-script-file-executable-1"></span><h4 class="subsection">2.1.3 Make the script file executable</h4> |
| 1314 |
|
| 1315 |
<p>Alternatively the script can be made executable, specifying apl as its |
| 1316 |
interpreter (see also <code>'man 2 execve'</code>). For this to work, the |
| 1317 |
first line of the script must have a special format: |
| 1318 |
</p> |
| 1319 |
<div class="example"> |
| 1320 |
<pre class="example"> #!/usr/bin/env apl --script |
| 1321 |
</pre></div> |
| 1322 |
|
| 1323 |
<p><code>--script</code> prevents: printing of a welcome banner, |
| 1324 |
echoing of stdin to stdout, automatic loading of a )CONTINUE workspace, |
| 1325 |
and prevents starting a thread for shared variable communication. |
| 1326 |
</p> |
| 1327 |
<p>If the path to the interpreter is relative (which might be useful if you |
| 1328 |
do not know in advance where the APL interpreter will be installed) then |
| 1329 |
it must be in <b>$PATH</b> of the shell that runs the script. |
| 1330 |
</p> |
| 1331 |
<hr> |
| 1332 |
</div> |
| 1333 |
<div class="subsection" id="Starting-GNU-APL-Scripts_003a-a-Conclusion"> |
| 1334 |
<div class="header"> |
| 1335 |
<p> |
| 1336 |
Next: <a href="#How-command-line-arguments-are-handled" accesskey="n" rel="next">How command line arguments are handled</a>, Previous: <a href="#Make-the-script-file-executable" accesskey="p" rel="prev">Make the script file executable</a>, Up: <a href="#APL-Scripting" accesskey="u" rel="up">APL Scripting</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 1337 |
</div> |
| 1338 |
<span id="Starting-GNU-APL-Scripts_003a-a-Conclusion-1"></span><h4 class="subsection">2.1.4 Starting GNU APL Scripts: a Conclusion</h4> |
| 1339 |
|
| 1340 |
<p>The different methods for starting a GNU APL described above have emerged |
| 1341 |
over time. They can be seen as different front-ends to the GNU APL |
| 1342 |
interpreter that slightly differ in how command line options are being passed |
| 1343 |
from the shell to GNU APL. However, sooner or later each of the methods wiil |
| 1344 |
call <b>execve(pathname, argv, envp)</b> where: |
| 1345 |
</p> |
| 1346 |
<ul> |
| 1347 |
<li> <b>pathname</b> is the name or absolute path to the GNU APL interpreter, |
| 1348 |
</li><li> <b>argv</b> is the command line arguments for the GNU APL interpreter, and |
| 1349 |
</li><li> <b>envp</b> is the environment variables for the GNU APL interpreter. |
| 1350 |
</li></ul> |
| 1351 |
|
| 1352 |
<p>The different front-ends differ slightly as to how <b>argv</b> and <b>envp</b> are |
| 1353 |
being constructed; <b>/bin/env</b> allows the user to modify the environment |
| 1354 |
before the GNU APL interpreter is called, input redirection allows the user |
| 1355 |
to modifu the apl script file before the GNU APL interpreter is called, and |
| 1356 |
<b>-f</b> allows the user to select the script file to be executed. One method |
| 1357 |
may be simpler to use in one situation and another method may be simpler to |
| 1358 |
use in another situation and the final verdict as to which method is the |
| 1359 |
best is left to the user. |
| 1360 |
</p> |
| 1361 |
<hr> |
| 1362 |
</div> |
| 1363 |
<div class="subsection" id="How-command-line-arguments-are-handled"> |
| 1364 |
<div class="header"> |
| 1365 |
<p> |
| 1366 |
Next: <a href="#Helpful-Features-for-Scripting" accesskey="n" rel="next">Helpful Features for Scripting</a>, Previous: <a href="#Starting-GNU-APL-Scripts_003a-a-Conclusion" accesskey="p" rel="prev">Starting GNU APL Scripts: a Conclusion</a>, Up: <a href="#APL-Scripting" accesskey="u" rel="up">APL Scripting</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 1367 |
</div> |
| 1368 |
<span id="How-command-line-arguments-are-handled-1"></span><h4 class="subsection">2.1.5 How command line arguments are handled</h4> |
| 1369 |
|
| 1370 |
<p>As we have seen, GNU APL can be started directly (by entering the name |
| 1371 |
of the GNU APL binary in the command line of a shell, or indirectly by |
| 1372 |
entering the name of a script that provides the name of the GNU APL binary |
| 1373 |
in the first line of the script. In the latter case, the shell uses function |
| 1374 |
execve() to start APL, and one can provide additional arguments that are |
| 1375 |
passed on to APL. We briefly discuss both cases: |
| 1376 |
</p> |
| 1377 |
<p>0. General Remark |
| 1378 |
</p> |
| 1379 |
<p>There is a convention in (not only) GNU APL, that the command line options |
| 1380 |
(and possibly an optional option argument) that occur left of <code>--</code> are |
| 1381 |
options directed to (and understood by) the APL interpreter while the options |
| 1382 |
right of <code>--</code> are passed to the APL application (and their exact format is |
| 1383 |
then defined by the APL application). All command line options that were used |
| 1384 |
to start APL can later be retrieved with the system variable <b>⎕ARG</b> in APL. |
| 1385 |
</p> |
| 1386 |
<p>Example 1: APL started directly |
| 1387 |
</p> |
| 1388 |
<p>We start APL with some command line options and display them with ⎕ARG. |
| 1389 |
The command line options for the interpreter are –silent, -l, and 37, |
| 1390 |
while the options app1 and app2 are for the APL application: |
| 1391 |
</p> |
| 1392 |
<div class="example"> |
| 1393 |
<pre class="example">$ apl --silent -l 37 -- app1 app2 |
| 1394 |
⊃⎕ARG |
| 1395 |
apl |
| 1396 |
--silent |
| 1397 |
-l |
| 1398 |
37 |
| 1399 |
-- |
| 1400 |
app1 |
| 1401 |
app2 |
| 1402 |
</pre></div> |
| 1403 |
|
| 1404 |
<p>Example 2: APL started indirectly |
| 1405 |
</p> |
| 1406 |
<p>A script is a text file which has execute permissions. The first line |
| 1407 |
of a script, commonly known as the <b>shebang</b> of the script, has a |
| 1408 |
special format which specifies how the subsequent lines of the script file |
| 1409 |
shall be processed, see <b>man execve</b> for details. |
| 1410 |
</p> |
| 1411 |
<p>A GNU APL script is then a script whose shebang indicates the apl binary as |
| 1412 |
the interpreter for the subsequent lines where those subsequent lines are |
| 1413 |
either APL commands or APL statements. With some limitations, executing such |
| 1414 |
an APL script yields the same result as entering the subsequent lines in |
| 1415 |
immediate execution mode. |
| 1416 |
</p> |
| 1417 |
<p>When APL is started directly, there is only one (possibly empty) set of |
| 1418 |
command line options, which are processed by the shell and then passed |
| 1419 |
to the apl binary. |
| 1420 |
</p> |
| 1421 |
<p>Starting APL indirectly refers to executing an APL script. In this case |
| 1422 |
there are two sets of command line options: |
| 1423 |
</p> |
| 1424 |
<ul> |
| 1425 |
<li> those passed to the script as command line arguments, and |
| 1426 |
</li><li> those in the shebang line of the script |
| 1427 |
</li></ul> |
| 1428 |
|
| 1429 |
<p>When the APL script is started, possibly with command line arguments, the |
| 1430 |
command line arguments entered by the user are combined with the arguments |
| 1431 |
in the shebang line of the script in a way that is described in ’man 2 execve’. |
| 1432 |
</p> |
| 1433 |
<p>Assume the script file SCRIPT.apl contains this (the file is shipped |
| 1434 |
with GNU APL): |
| 1435 |
</p> |
| 1436 |
<div class="example"> |
| 1437 |
<pre class="example"># !/usr/bin/env -S apl "--script --id 1010" |
| 1438 |
|
| 1439 |
⊃⎕ARG ⍝ show command line options |
| 1440 |
)OFF ⍝ leave the interpreter |
| 1441 |
</pre></div> |
| 1442 |
|
| 1443 |
<p>Assume further that the script is started like this: |
| 1444 |
</p> |
| 1445 |
<div class="example"> |
| 1446 |
<pre class="example">$ ./SCRIPT.apl -- sarg1 sarg2 |
| 1447 |
</pre></div> |
| 1448 |
|
| 1449 |
<p>Then the following output, which shows the order of command line options |
| 1450 |
as seen by ⎕ARG, is produced: |
| 1451 |
</p> |
| 1452 |
<div class="example"> |
| 1453 |
<pre class="example">--script |
| 1454 |
--id |
| 1455 |
1010 |
| 1456 |
./SCRIPT.apl |
| 1457 |
-- |
| 1458 |
sarg1 |
| 1459 |
sarg2 |
| 1460 |
</pre></div> |
| 1461 |
|
| 1462 |
<p>In the example above please note the following: |
| 1463 |
</p> |
| 1464 |
<ul> |
| 1465 |
<li> <b>–</b> separates the arguments passed to the interpreter (left of <b>–</b>) |
| 1466 |
from the arguments passed to the APL application, |
| 1467 |
</li><li> The first line of the text file <b>SCRIPT.apl</b> is commonly referred to |
| 1468 |
as the <i>shebang line</i>. If the shebang contains more than one argument |
| 1469 |
(like <b>–script</b>, <b>–id</b>, and <b>1010</b> above), then the arguments |
| 1470 |
need to be quoted, and |
| 1471 |
then the arguments must be quoted, and |
| 1472 |
</li><li> in contrast, multiple arguments in the command line (like <b>sarg1</b> and |
| 1473 |
<b>sarg2</b> above) must not be quoted (or else they will appear as a single |
| 1474 |
argument). |
| 1475 |
</li></ul> |
| 1476 |
|
| 1477 |
<p>⎕ARG shows the arguments in the shebang line and in the command line in |
| 1478 |
the following order: |
| 1479 |
</p> |
| 1480 |
<ol> |
| 1481 |
<li> Interpreter name (the first name in the shebang, here: <b>apl</b>) |
| 1482 |
</li><li> Optional Interpreter argument(s) (here: <b>–script</b>, <b>–id</b>, and |
| 1483 |
<b>1010</b>) |
| 1484 |
</li><li> Script filename (here: <b>./SCRIPT.apl</b>) |
| 1485 |
</li><li> Optional Script argument(s) (here: <b>–</b>, <b>sarg1</b>, and <b>sarg2</b>) |
| 1486 |
</li></ol> |
| 1487 |
|
| 1488 |
<p>CAUTION: as discussed in ’man 2 execve’ the interpretation of the optional |
| 1489 |
interpreter arguments (2. above) is system specific and possibly not portable. |
| 1490 |
For that reason the optional interpreter argument should not be omitted (you |
| 1491 |
can use – to provide at least one argument) and also not more than one |
| 1492 |
argument. On GNU/Linux systems the following shebang lines of the script are |
| 1493 |
understood: |
| 1494 |
</p> |
| 1495 |
<div class="example"> |
| 1496 |
<pre class="example">#!/usr/bin/env -S apl "--script --id 1010" |
| 1497 |
#! /usr/local/bin/apl |
| 1498 |
#! /usr/local/bin/apl -- |
| 1499 |
#! /usr/local/bin/apl -s |
| 1500 |
#! /usr/local/bin/apl --script |
| 1501 |
#! /usr/local/bin/apl -s -- |
| 1502 |
#! /usr/local/bin/apl --script -- |
| 1503 |
</pre></div> |
| 1504 |
|
| 1505 |
<p>The recommended form is: <code>|/usr/local/bin/apl --script|</code>. |
| 1506 |
</p> |
| 1507 |
<p>Note that <code>-</code> and any options that follow it in the shebang line |
| 1508 |
MAY OR MAY NOT be included in ⎕ARG (this depends on the platform used). |
| 1509 |
In contrast, options that follow <code>-</code> in the script command line |
| 1510 |
WILL BE shown since this is controlled by GNU APL and not by the platform. |
| 1511 |
There is normally no point in passing any application options in the shebang |
| 1512 |
line to APL because such parameters can more easily be provided directly |
| 1513 |
further down in the script. However, in cases where the script has only |
| 1514 |
application options it may be convenient to make <b><tt>--</tt></b> the last |
| 1515 |
option of the shebang so that the user of the script need not specify it |
| 1516 |
manually. |
| 1517 |
</p> |
| 1518 |
<p>Using <code>0-</code> in the shebang line of the script file usually prevents |
| 1519 |
subsequent options in the shebang line from being interpreted as APL command |
| 1520 |
line options (and, more importantly, from causing <b>unknown option</b> errors |
| 1521 |
when GNU APL starts). At least under GNU/Linux with <b>bash</b> the subsequent |
| 1522 |
options will be passed to the APL application via ⎕ARG. |
| 1523 |
</p> |
| 1524 |
<p>Depending on this exact behavior cannot be recommended. A cleaner approach |
| 1525 |
is to use options starting with - or <code>-</code> only for the interpreter |
| 1526 |
options, and options starting with + for application options. This should |
| 1527 |
work on all platforms because for strings, say, APLOPT, ARG1, ARG2, ..., |
| 1528 |
which contain no whitespace: |
| 1529 |
</p> |
| 1530 |
<ul> |
| 1531 |
<li> <b>+APLOPT</b> is ignored, although shown in ⎕ARG, |
| 1532 |
</li><li> <b>++APLOPT ARG1</b> is ignored, although shown in ⎕ARG, |
| 1533 |
</li><li> <b>+++APLOPT ARG1 ARG2</b> is ignored, although shown in ⎕ARG, |
| 1534 |
</li><li> <b>...</b> |
| 1535 |
</li></ul> |
| 1536 |
|
| 1537 |
<hr> |
| 1538 |
</div> |
| 1539 |
<div class="subsection" id="Helpful-Features-for-Scripting"> |
| 1540 |
<div class="header"> |
| 1541 |
<p> |
| 1542 |
Next: <a href="#Double_002dquoted-Strings" accesskey="n" rel="next">Double-quoted Strings</a>, Previous: <a href="#How-command-line-arguments-are-handled" accesskey="p" rel="prev">How command line arguments are handled</a>, Up: <a href="#APL-Scripting" accesskey="u" rel="up">APL Scripting</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 1543 |
</div> |
| 1544 |
<span id="Helpful-Features-for-Scripting-1"></span><h4 class="subsection">2.1.6 Helpful Features for Scripting</h4> |
| 1545 |
|
| 1546 |
<p>GNU APL provides three system variables and functions that are particularly |
| 1547 |
useful for scripting: |
| 1548 |
</p> |
| 1549 |
<ul> |
| 1550 |
<li> ⎕ARG: access to the command line arguments given to the interpreter, |
| 1551 |
</li><li> ⎕ENV: access to the environment variables of the process running the |
| 1552 |
interpreter, and |
| 1553 |
</li><li> ⎕INP: Here-Document-alike function for creating large text variables |
| 1554 |
</li></ul> |
| 1555 |
|
| 1556 |
<ul class="section-toc"> |
| 1557 |
<li><a href="#g_t_2395ARG" accesskey="1">⎕ARG</a></li> |
| 1558 |
<li><a href="#g_t_2395ENV" accesskey="2">⎕ENV</a></li> |
| 1559 |
<li><a href="#g_t_2395INP" accesskey="3">⎕INP</a></li> |
| 1560 |
</ul> |
| 1561 |
<hr> |
| 1562 |
<div class="subsubsection" id="g_t_2395ARG"> |
| 1563 |
<div class="header"> |
| 1564 |
<p> |
| 1565 |
Next: <a href="#g_t_2395ENV" accesskey="n" rel="next">⎕ENV</a>, Up: <a href="#Helpful-Features-for-Scripting" accesskey="u" rel="up">Helpful Features for Scripting</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 1566 |
</div> |
| 1567 |
<span id="g_t_005b_003f_005dARG"></span><h4 class="subsubsection">2.1.6.1 ⎕ARG</h4> |
| 1568 |
|
| 1569 |
<p>The system variable ⎕ARG contains all command line arguments passed to the |
| 1570 |
interpreter. In the initial example above this would be a nested 3-element |
| 1571 |
vector: |
| 1572 |
</p> |
| 1573 |
<div class="example"> |
| 1574 |
<pre class="example"> /usr/local/bin/apl --id 1010 |
| 1575 |
</pre></div> |
| 1576 |
|
| 1577 |
<hr> |
| 1578 |
</div> |
| 1579 |
<div class="subsubsection" id="g_t_2395ENV"> |
| 1580 |
<div class="header"> |
| 1581 |
<p> |
| 1582 |
Next: <a href="#g_t_2395INP" accesskey="n" rel="next">⎕INP</a>, Previous: <a href="#g_t_2395ARG" accesskey="p" rel="prev">⎕ARG</a>, Up: <a href="#Helpful-Features-for-Scripting" accesskey="u" rel="up">Helpful Features for Scripting</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 1583 |
</div> |
| 1584 |
<span id="g_t_005b_003f_005dENV"></span><h4 class="subsubsection">2.1.6.2 ⎕ENV</h4> |
| 1585 |
|
| 1586 |
<p>There are usually at least two ways of passing parameters to a script: |
| 1587 |
</p> |
| 1588 |
<ul> |
| 1589 |
<li> as command line options, and/or |
| 1590 |
</li><li> by means of environment variables |
| 1591 |
</li></ul> |
| 1592 |
|
| 1593 |
<p>Just as the system variable ⎕ARG makes the command line options used |
| 1594 |
available to APL, so does the system function ⎕ENV make the environment |
| 1595 |
variables available to APL. Since there normally exist far more |
| 1596 |
environment variables than command line options, ⎕ENV is a monadic function |
| 1597 |
whose argument is a filter for the name(s) of the variable(s) to be retrieved. |
| 1598 |
</p> |
| 1599 |
<p>⎕ENV B returns all environment variables whose name starts with B. |
| 1600 |
If ⍴B is 0, like: |
| 1601 |
</p> |
| 1602 |
<div class="example"> |
| 1603 |
<pre class="example"> ⎕ENV '' |
| 1604 |
</pre></div> |
| 1605 |
|
| 1606 |
<p>then <b>all</b> environment variables of the process running GNU APL are |
| 1607 |
returned. |
| 1608 |
</p> |
| 1609 |
<p>The result of ⎕ENV is a (possibly empty) N×2 matrix. The first column |
| 1610 |
contains the name(s) of the environment variable(s), while the second |
| 1611 |
column contains their value(s). The name and the value are both strings. |
| 1612 |
</p> |
| 1613 |
<p>The number N of environment variables returned by ⎕ENV obviously depends on |
| 1614 |
the number of environment variables whose name begins with the prefix |
| 1615 |
given in B; shorter prefixes B therefore result in higher counts N. B is case |
| 1616 |
sensitive; by convention the names of environment variables are all uppercase. |
| 1617 |
Note the subtle difference between shell variables and environment variables |
| 1618 |
in shells like <b>bash</b>: ⎕ENV returns only environment variables (which |
| 1619 |
are set with command <b>setenv</b> in bash), but not shell variables (which |
| 1620 |
are set with command <b>set</b> in bash). For a shell variable to occur |
| 1621 |
in ⎕ENV it must be <b>export</b>ed into the environment of the process |
| 1622 |
before the GNU APL interpreter is started. |
| 1623 |
</p> |
| 1624 |
<hr> |
| 1625 |
</div> |
| 1626 |
<div class="subsubsection" id="g_t_2395INP"> |
| 1627 |
<div class="header"> |
| 1628 |
<p> |
| 1629 |
Previous: <a href="#g_t_2395ENV" accesskey="p" rel="prev">⎕ENV</a>, Up: <a href="#Helpful-Features-for-Scripting" accesskey="u" rel="up">Helpful Features for Scripting</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 1630 |
</div> |
| 1631 |
<span id="g_t_005b_003f_005dINP"></span><h4 class="subsubsection">2.1.6.3 ⎕INP</h4> |
| 1632 |
|
| 1633 |
<p>If you need to create a longer static text, like the body of a web page, |
| 1634 |
then you would normally construct it in APL like this: |
| 1635 |
</p> |
| 1636 |
<div class="example"> |
| 1637 |
<pre class="example"> BODY ← ⊂ 'First line' |
| 1638 |
BODY ← BODY , ⊂ 'Second line' |
| 1639 |
BODY ← BODY , ⊂ 'Third line' |
| 1640 |
... |
| 1641 |
</pre></div> |
| 1642 |
|
| 1643 |
<p>The above is obviously not very handy for longer texts. Instead you may |
| 1644 |
write the following in a GNU APL script: |
| 1645 |
</p> |
| 1646 |
<div class="example"> |
| 1647 |
<pre class="example"> BODY←⎕INP 'END-OF-⎕INP' |
| 1648 |
First line |
| 1649 |
Second line |
| 1650 |
Third line |
| 1651 |
... |
| 1652 |
END-OF-⎕INP |
| 1653 |
</pre></div> |
| 1654 |
|
| 1655 |
<p>This works like "Here documents" in <b>bash</b>. The right argument of ⎕INP is |
| 1656 |
the end of text marker. |
| 1657 |
</p> |
| 1658 |
<p>⎕INP also has a dyadic form where the left argument specifies an escape |
| 1659 |
sequence from text to APL and back to the text, similar to PHP scripts. |
| 1660 |
For example: |
| 1661 |
</p> |
| 1662 |
<div class="example"> |
| 1663 |
<pre class="example"> Z←'<?apl' '?>' ⎕INP 'END-OF-⎕INP' |
| 1664 |
First line |
| 1665 |
Time is now: <?apl ⍕⎕TS ?> |
| 1666 |
Third line |
| 1667 |
... |
| 1668 |
END-OF-⎕INP |
| 1669 |
</pre></div> |
| 1670 |
|
| 1671 |
<p>This creates a mainly static text with a small dynamic plug-in computed by |
| 1672 |
APL: |
| 1673 |
</p> |
| 1674 |
<div class="example"> |
| 1675 |
<pre class="example"> ⊃Z |
| 1676 |
First line |
| 1677 |
Time is now: 2022 8 4 15 15 2 177 |
| 1678 |
Third line |
| 1679 |
... |
| 1680 |
</pre></div> |
| 1681 |
|
| 1682 |
<p>It should be noted that, while ⎕INP simplifies the construction of multi-line |
| 1683 |
strings compared to standard APL, it has come of age and these days an even |
| 1684 |
simpler feature - Multi-line strings as described below - is provided for the |
| 1685 |
same purpose. The monadic ⎕INP has therefore become obsolete. |
| 1686 |
</p> |
| 1687 |
<hr> |
| 1688 |
</div> |
| 1689 |
</div> |
| 1690 |
<div class="subsection" id="Double_002dquoted-Strings"> |
| 1691 |
<div class="header"> |
| 1692 |
<p> |
| 1693 |
Next: <a href="#Multi_002dLine-Strings" accesskey="n" rel="next">Multi-Line Strings</a>, Previous: <a href="#Helpful-Features-for-Scripting" accesskey="p" rel="prev">Helpful Features for Scripting</a>, Up: <a href="#APL-Scripting" accesskey="u" rel="up">APL Scripting</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 1694 |
</div> |
| 1695 |
<span id="Double_002dquoted-Strings-1"></span><h4 class="subsection">2.1.7 Double-quoted Strings</h4> |
| 1696 |
|
| 1697 |
<p>Standard APL literals (aka. strings) such as ’Hello’ are single quoted. As a |
| 1698 |
matter of convenience, GNU APL also provides double-quoted strings which |
| 1699 |
differ from single quoted strings in two ways: |
| 1700 |
</p> |
| 1701 |
<ul> |
| 1702 |
<li> A standard single quoted APL string is a vector if its length ≠ 1 but |
| 1703 |
a scalar if its length = 1. This is sometimes inconvenient and therefore |
| 1704 |
double-quoted strings are more consistent in always being vectors regardless |
| 1705 |
of their length. In other words, ’A’ is a scalar while "A" is a vector. |
| 1706 |
|
| 1707 |
</li><li> Double-quoted strings understand the standard C escape sequences for |
| 1708 |
control characters, such as <b>\n</b> for ASCII line feed, <b>\t</b> for ASCII TAB, |
| 1709 |
etc. |
| 1710 |
|
| 1711 |
</li></ul> |
| 1712 |
|
| 1713 |
<hr> |
| 1714 |
</div> |
| 1715 |
<div class="subsection" id="Multi_002dLine-Strings"> |
| 1716 |
<div class="header"> |
| 1717 |
<p> |
| 1718 |
Next: <a href="#Multi_002dLine-Literals" accesskey="n" rel="next">Multi-Line Literals</a>, Previous: <a href="#Double_002dquoted-Strings" accesskey="p" rel="prev">Double-quoted Strings</a>, Up: <a href="#APL-Scripting" accesskey="u" rel="up">APL Scripting</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 1719 |
</div> |
| 1720 |
<span id="Multi_002dLine-Strings-1"></span><h4 class="subsection">2.1.8 Multi-Line Strings</h4> |
| 1721 |
|
| 1722 |
<p>A substantial disadvantage of <b>⎕INP</b> is that it only works in immediate |
| 1723 |
execution mode (and consequently also in .apl scripts), but not the bodies of |
| 1724 |
defined functions. Multi-line strings fill this gap for string literals that |
| 1725 |
span several lines of text <b>inside</b> the body of defined functions (as well as |
| 1726 |
in immediate execution mode and in scripts). |
| 1727 |
Multi-Line strings have become more and more advanced (and elegant) over time. |
| 1728 |
For this reason they currently come in different flavors (of which the older |
| 1729 |
ones will eventually disappear). |
| 1730 |
</p> |
| 1731 |
<ul class="section-toc"> |
| 1732 |
<li><a href="#Old_002dstyle-Multi_002dLine-Strings" accesskey="1">Old-style Multi-Line Strings</a></li> |
| 1733 |
<li><a href="#New_002dstyle-Multi_002dLine-Strings" accesskey="2">New-style Multi-Line Strings</a></li> |
| 1734 |
<li><a href="#g_t_00ab-_00bb-Strings" accesskey="3">« » Strings</a></li> |
| 1735 |
<li><a href="#Multi_002dLine-Comments" accesskey="4">Multi-Line Comments</a></li> |
| 1736 |
</ul> |
| 1737 |
<hr> |
| 1738 |
<div class="subsubsection" id="Old_002dstyle-Multi_002dLine-Strings"> |
| 1739 |
<div class="header"> |
| 1740 |
<p> |
| 1741 |
Next: <a href="#New_002dstyle-Multi_002dLine-Strings" accesskey="n" rel="next">New-style Multi-Line Strings</a>, Up: <a href="#Multi_002dLine-Strings" accesskey="u" rel="up">Multi-Line Strings</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 1742 |
</div> |
| 1743 |
<span id="Old_002dstyle-Multi_002dLine-Strings-1"></span><h4 class="subsubsection">2.1.8.1 Old-style Multi-Line Strings</h4> |
| 1744 |
|
| 1745 |
<p>Old-style multi-line strings were the first attempt to provide long strings |
| 1746 |
for defined functions. The idea for the old-style multi-line strings was |
| 1747 |
adopted from shells like <b>bash</b> where, for example, |
| 1748 |
</p> |
| 1749 |
<div class="example"> |
| 1750 |
<pre class="example">echo "Line1 |
| 1751 |
Line2" |
| 1752 |
</pre></div> |
| 1753 |
|
| 1754 |
<p>prints: |
| 1755 |
</p> |
| 1756 |
<div class="example"> |
| 1757 |
<pre class="example">Line1 |
| 1758 |
Line2 |
| 1759 |
</pre></div> |
| 1760 |
|
| 1761 |
<p>In simple terms this means that as long as the number of <b>"</b> characters is |
| 1762 |
odd, the string remains open until the closing <b>"</b> is found (which makes |
| 1763 |
the number even again). |
| 1764 |
</p> |
| 1765 |
<p>Old-style multi-line strings are not allowed in immediate execution mode |
| 1766 |
because they could easily be entered by mistake (by simply forgetting the |
| 1767 |
terminating <b>"</b> or <b>’</b> of a standard string) and that would have |
| 1768 |
obscured the familiar behavior of immediate execution mode. In function |
| 1769 |
definition mode, the total number of function lines is known and it is |
| 1770 |
therefore possible to check if a multi-line string inside the function |
| 1771 |
is properly terminated. Immediate execution mode, however, is open-ended |
| 1772 |
and therefore a forgotten closing <b>"</b> can lead to a fatal misinterpretation |
| 1773 |
of (intended) string content as (unintended) APL code, with lots of |
| 1774 |
nonsense error messages. |
| 1775 |
</p> |
| 1776 |
<p>Like in <b>bash</b> and also other shells, an old-style multi-line string starts |
| 1777 |
at the last " on a line of a defined function that has an |
| 1778 |
<b>an odd number of " characters</b>. The string continues over the subsequent |
| 1779 |
function lines until the next " is found. The result is a nested |
| 1780 |
APL value containing one nested string per line involved. |
| 1781 |
</p> |
| 1782 |
<p>In immediate execution mode an old-style multi-line string yields, like |
| 1783 |
in standard APL: |
| 1784 |
</p> |
| 1785 |
<div class="example"> |
| 1786 |
<pre class="example">No string end found+ |
| 1787 |
</pre></div> |
| 1788 |
|
| 1789 |
<p>For example: |
| 1790 |
</p><div class="example"> |
| 1791 |
<pre class="example">∇Z←FOO |
| 1792 |
Z←"ABC |
| 1793 |
DEF |
| 1794 |
GHIJK" |
| 1795 |
∇ |
| 1796 |
|
| 1797 |
4 ⎕CR FOO |
| 1798 |
┏→━━━━━━━━━━━━━━━━━━━━┓ |
| 1799 |
┃┏→━━┓ ┏→━━━┓ ┏→━━━━━┓┃ |
| 1800 |
┃┃ABC┃ ┃ DEF┃ ┃ GHIJK┃┃ |
| 1801 |
┃┗━━━┛ ┗━━━━┛ ┗━━━━━━┛┃ |
| 1802 |
┗∊━━━━━━━━━━━━━━━━━━━━┛ |
| 1803 |
</pre></div> |
| 1804 |
|
| 1805 |
<p>If the first string is empty then the nested value starts with an empty |
| 1806 |
string, but completely empty lines in defined functions are ignored: |
| 1807 |
</p> |
| 1808 |
<div class="example"> |
| 1809 |
<pre class="example">∇Z←FOO |
| 1810 |
Z←" |
| 1811 |
ABC |
| 1812 |
DEF |
| 1813 |
|
| 1814 |
GHIJK" |
| 1815 |
∇ |
| 1816 |
|
| 1817 |
4 ⎕CR FOO |
| 1818 |
┏→━━━━━━━━━━━━━━━━━━━━━━━━━┓ |
| 1819 |
┃┏⊖┓ ┏→━━┓ ┏→━━━┓ ┏→━━━━━━┓┃ |
| 1820 |
┃┃ ┃ ┃ABC┃ ┃ DEF┃ ┃ GHIJK┃┃ |
| 1821 |
┃┗━┛ ┗━━━┛ ┗━━━━┛ ┗━━━━━━━┛┃ |
| 1822 |
┗∊━━━━━━━━━━━━━━━━━━━━━━━━━┛ |
| 1823 |
</pre></div> |
| 1824 |
|
| 1825 |
<hr> |
| 1826 |
</div> |
| 1827 |
<div class="subsubsection" id="New_002dstyle-Multi_002dLine-Strings"> |
| 1828 |
<div class="header"> |
| 1829 |
<p> |
| 1830 |
Next: <a href="#g_t_00ab-_00bb-Strings" accesskey="n" rel="next">« » Strings</a>, Previous: <a href="#Old_002dstyle-Multi_002dLine-Strings" accesskey="p" rel="prev">Old-style Multi-Line Strings</a>, Up: <a href="#Multi_002dLine-Strings" accesskey="u" rel="up">Multi-Line Strings</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 1831 |
</div> |
| 1832 |
<span id="New_002dstyle-Multi_002dLine-Strings-1"></span><h4 class="subsubsection">2.1.8.2 New-style Multi-Line Strings</h4> |
| 1833 |
|
| 1834 |
<p>The combination of <b>⎕INP</b> for immediate execution mode and multi-line |
| 1835 |
strings for defined functions achieved, at least in principle, the goal of |
| 1836 |
specifying large amounts of text in a simpler manner than in standard APL. |
| 1837 |
However, having different methods for creating multi-line string literals |
| 1838 |
in different APL modes could not convince entirely. |
| 1839 |
</p> |
| 1840 |
<p>The search for a more intuitive and more consistent solution then led to |
| 1841 |
new-style multi-line strings. These strings adopted the triple quote (""") |
| 1842 |
syntax known from e.g. the Python language. The syntax of new-style |
| 1843 |
multi-line strings is cleaner: empty lines are handled more consistently and |
| 1844 |
the string lines are completely separated from the APL code lines. |
| 1845 |
More importantly, new-style multi-line strings work alike in immediate |
| 1846 |
execution mode, in scripts, and in defined functions. New-style strings are a |
| 1847 |
little different and syntactically stricter than their old-style companions: |
| 1848 |
</p> |
| 1849 |
<ul> |
| 1850 |
<li> the starting """ must be placed at the end of an APL code line, i.e. |
| 1851 |
there is no more mixing of APL code and string content in the same line. |
| 1852 |
An old-style string starts with APL code and ends with the first line of |
| 1853 |
the string, while a new-style string starts with an APL code line and |
| 1854 |
the string itself begins at the following line. |
| 1855 |
|
| 1856 |
</li><li> the ending """ must be placed at the end of a separate line with only |
| 1857 |
spaces allowed before the """ (to horizontally indent-align it with the |
| 1858 |
leading """ if so desired). In old-style strings the text up to the |
| 1859 |
termination " is part of the string while in new-style strings it is not. |
| 1860 |
|
| 1861 |
</li><li> Neither the starting nor the ending line become nested strings of the |
| 1862 |
result, and every line can be clearly identified as being either APL code or |
| 1863 |
else string text. |
| 1864 |
</li></ul> |
| 1865 |
|
| 1866 |
<p>Example: |
| 1867 |
</p><div class="example"> |
| 1868 |
<pre class="example"> 4 ⎕CR """ |
| 1869 |
ABC |
| 1870 |
DEF |
| 1871 |
|
| 1872 |
GHIJK |
| 1873 |
""" |
| 1874 |
┏→━━━━━━━━━━━━━━━━━━━━━━━━━┓ |
| 1875 |
┃┏→━━┓ ┏→━━━┓ ┏⊖┓ ┏→━━━━━━┓┃ |
| 1876 |
┃┃ABC┃ ┃ DEF┃ ┃ ┃ ┃ GHIJK┃┃ |
| 1877 |
┃┗━━━┛ ┗━━━━┛ ┗━┛ ┗━━━━━━━┛┃ |
| 1878 |
┗∊━━━━━━━━━━━━━━━━━━━━━━━━━┛ |
| 1879 |
</pre></div> |
| 1880 |
|
| 1881 |
<p>When entering new-style multi-line strings, the prompt is prefixed by → to |
| 1882 |
indicate that a Multi-Line String is being entered. |
| 1883 |
</p> |
| 1884 |
<p>⎕INP and old-style strings will coexist for a while, but may eventually |
| 1885 |
disappear at some point in time. |
| 1886 |
</p> |
| 1887 |
<hr> |
| 1888 |
</div> |
| 1889 |
<div class="subsubsection" id="g_t_00ab-_00bb-Strings"> |
| 1890 |
<div class="header"> |
| 1891 |
<p> |
| 1892 |
Next: <a href="#Multi_002dLine-Comments" accesskey="n" rel="next">Multi-Line Comments</a>, Previous: <a href="#New_002dstyle-Multi_002dLine-Strings" accesskey="p" rel="prev">New-style Multi-Line Strings</a>, Up: <a href="#Multi_002dLine-Strings" accesskey="u" rel="up">Multi-Line Strings</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 1893 |
</div> |
| 1894 |
<span id="g_t_00ab-_00bb-Strings-1"></span><h4 class="subsubsection">2.1.8.3 « » Strings</h4> |
| 1895 |
|
| 1896 |
<p>When new-style multi-line strings are used in scripts the related error |
| 1897 |
reporting (if the syntax is used incorrectly) can become cumbersome. For |
| 1898 |
example, if one forgets the closing """ of a multi-line string then the next |
| 1899 |
""" (which was meant as the start of a new multi-line string) is mistaken as |
| 1900 |
the (forgotten) end of the previous one. The often long content of |
| 1901 |
the new string is then parsed as APL code and will usually produce many |
| 1902 |
error messages, all of them nonsense. Things get worse if the script itself |
| 1903 |
is long because the odd/even nature of the quotes will then persist until |
| 1904 |
the end of the string (or at least until the next forgotten quote, if any). |
| 1905 |
</p> |
| 1906 |
<p>To deal with this problem, GNU APL also allows strings whose contents are |
| 1907 |
enclosed in double angle quotation marks « and ». In inline strings ’...’ |
| 1908 |
and "...", as well as in multi-line strings """ ... """, there is no general |
| 1909 |
(and reliable) way to decide if a user has forgotten the ending quote(s), |
| 1910 |
which leads to the problems above. |
| 1911 |
</p> |
| 1912 |
<p>For this reason, GNU APL now also allows inline and multi-line strings |
| 1913 |
like, for example: |
| 1914 |
</p> |
| 1915 |
<div class="example"> |
| 1916 |
<pre class="example"> «Hello world» |
| 1917 |
Hello world |
| 1918 |
|
| 1919 |
8 ⎕CR ««« |
| 1920 |
→ Line 1 |
| 1921 |
→ Line 2 |
| 1922 |
→ »»» |
| 1923 |
┌→──────────────────┐ |
| 1924 |
│┌→─────┐ ┌→───────┐│ |
| 1925 |
││Line 1│ │ Line 2││ |
| 1926 |
│└──────┘ └────────┘│ |
| 1927 |
└ϵ──────────────────┘ |
| 1928 |
|
| 1929 |
⍝ provoke an error... |
| 1930 |
⍝ |
| 1931 |
8 ⎕CR ««« |
| 1932 |
→ Line 1 |
| 1933 |
→ Line 2 |
| 1934 |
→ ««« |
| 1935 |
|
| 1936 |
*** WARNING: unexpected triplet ««« in mult-line string. |
| 1937 |
Expected triplet: »»» (literal depth: 0). |
| 1938 |
The triplet was added to the multi-line string. |
| 1939 |
|
| 1940 |
→ »»» |
| 1941 |
┌→───────────────────────────────┐ |
| 1942 |
│┌→─────┐ ┌→────────┐ ┌→────────┐│ |
| 1943 |
││Line 1│ │ Line 2│ │ «««││ |
| 1944 |
│└──────┘ └─────────┘ └─────────┘│ |
| 1945 |
└ϵ───────────────────────────────┘ |
| 1946 |
</pre></div> |
| 1947 |
|
| 1948 |
<p>Another advantage of <b>«««</b> ... <b>»»»</b> over <b>"""</b> ... <b>"""</b> is that |
| 1949 |
a decent text editor (read: <b>vi/vim</b>) may jump back and forth between |
| 1950 |
the opening <b>«</b> and the corresponding closing <b>»</b> with a single key |
| 1951 |
stroke (character <b>%</b> in vi/vim). For this to work, add the following |
| 1952 |
line to <b>/etc/vim/vimrc</b> (or to <b>~/.vimrc</b>): |
| 1953 |
</p> |
| 1954 |
<div class="example"> |
| 1955 |
<pre class="example">set matchpairs+=«:» |
| 1956 |
</pre></div> |
| 1957 |
|
| 1958 |
<hr> |
| 1959 |
</div> |
| 1960 |
<div class="subsubsection" id="Multi_002dLine-Comments"> |
| 1961 |
<div class="header"> |
| 1962 |
<p> |
| 1963 |
Previous: <a href="#g_t_00ab-_00bb-Strings" accesskey="p" rel="prev">« » Strings</a>, Up: <a href="#Multi_002dLine-Strings" accesskey="u" rel="up">Multi-Line Strings</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 1964 |
</div> |
| 1965 |
<span id="Multi_002dLine-Comments-1"></span><h4 class="subsubsection">2.1.8.4 Multi-Line Comments</h4> |
| 1966 |
|
| 1967 |
<p>One of the badly missing features of standard APL are comments that span |
| 1968 |
multiple lines. However, in GNU APL one can use multi-line strings in |
| 1969 |
combination with monadic primitive <b>⊣</b> for that purpose: |
| 1970 |
</p> |
| 1971 |
<div class="example"> |
| 1972 |
<pre class="example"> ⊣««« ⍝⍝⍝ |
| 1973 |
Multi-line |
| 1974 |
Comment |
| 1975 |
... |
| 1976 |
»»» ⍝⍝⍝ |
| 1977 |
</pre></div> |
| 1978 |
|
| 1979 |
<p>The triplet <b>⍝⍝⍝</b> in the example above is optional and has no effect (since |
| 1980 |
it is part of the multi-line string, but is then suppressed by ⊣), but is |
| 1981 |
nevertheless recommended as an indication that the text between the <b>⍝⍝⍝</b> |
| 1982 |
is a comment. |
| 1983 |
</p> |
| 1984 |
<p>GNU APL is aware of this construct and optimizes it away entirely. Therefore |
| 1985 |
even long multi-line comments inside loops have, like normal APL comments, |
| 1986 |
no performance penalty at runtime. |
| 1987 |
</p> |
| 1988 |
<hr> |
| 1989 |
</div> |
| 1990 |
</div> |
| 1991 |
<div class="subsection" id="Multi_002dLine-Literals"> |
| 1992 |
<div class="header"> |
| 1993 |
<p> |
| 1994 |
Next: <a href="#Automatic-_0029MORE" accesskey="n" rel="next">Automatic )MORE</a>, Previous: <a href="#Multi_002dLine-Strings" accesskey="p" rel="prev">Multi-Line Strings</a>, Up: <a href="#APL-Scripting" accesskey="u" rel="up">APL Scripting</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 1995 |
</div> |
| 1996 |
<span id="Multi_002dLine-Literals-1"></span><h4 class="subsection">2.1.9 Multi-Line Literals</h4> |
| 1997 |
|
| 1998 |
<p>A limitation from the early days of APL is that literals like <b>1 2 3</b> |
| 1999 |
or <b>’abc’</b> can not stretch over several lines. As a consequence, the rank |
| 2000 |
of a literal can not be more than 1, and values with higher ranks require |
| 2001 |
the use of APL primitive (most likely dyadic <b>⍴</b>). A single line of input |
| 2002 |
can produce multiple lines of output, but these multiple lines of output can |
| 2003 |
not be fed back into the interpreter as literals. |
| 2004 |
</p> |
| 2005 |
<p>This limitation is rather natural when APL is used interactively (and screen |
| 2006 |
oriented editors like <b>vi</b> or <b>emacs</b>) were not very common at the time |
| 2007 |
when APL was invented. At that time, nobody (and in particular not APL |
| 2008 |
programmers who had the reputation of being lazy) would have entered, say, a |
| 2009 |
numeric 10 by 10 matrix interactively. |
| 2010 |
</p> |
| 2011 |
<p>However, for scripting the situation is quite different. An APL script is |
| 2012 |
typically created beforehand with a screen oriented editor, and screen |
| 2013 |
oriented editors like <b>vi</b> are available everywhere while its line oriented |
| 2014 |
predecessor (named <b>ex</b>) has died out in the meantime (more precisely, |
| 2015 |
<b>ex</b> has become a sub-mode of <b>vi</b>). |
| 2016 |
</p> |
| 2017 |
<p>GNU APL extends the idea of multi-line strings to <i>multi-line literals</i>. |
| 2018 |
The syntax that governs the output of APL values (i.e. in the APL → terminal |
| 2019 |
direction) is simply applied to the input of APL literals (i.e. in the |
| 2020 |
terminal → APL direction) as well: |
| 2021 |
</p> |
| 2022 |
<pre class="verbatim"> ┌─────────┐ |
| 2023 |
┌─────────┐ │ MULTI │ (text, |
| 2024 |
(text, │ LITERAL │ │ -LINE │ multi line) |
| 2025 |
single line) └────┬────┘ │ LITERAL │ |
| 2026 |
│ └────┬────┘ |
| 2027 |
│ │ |
| 2028 |
│ input │ |
| 2029 |
↓ rules ↓ |
| 2030 |
│ │ |
| 2031 |
╔══╧══╗ ╔════╧════╗ |
| 2032 |
(vectors, ║ APL ║ ║ GNU APL ║ |
| 2033 |
values) ╚══╤══╝ ╚════╤════╝ |
| 2034 |
│ │ |
| 2035 |
│ output │ |
| 2036 |
↓ rules ↓ |
| 2037 |
│ │ |
| 2038 |
┌──┴──┐ ┌──┴──┐ |
| 2039 |
(text, │ │ │ │ (text, |
| 2040 |
multi-line) │ OUT │ │ OUT │ milti-line) |
| 2041 |
│ │ │ │ |
| 2042 |
└─────┘ └─────┘ |
| 2043 |
</pre> |
| 2044 |
<p>The relevant formatting rules for APL output are: |
| 2045 |
</p> |
| 2046 |
<ul> |
| 2047 |
<li> one line of a APL output corresponds to one or more scalar items |
| 2048 |
of the APL value, |
| 2049 |
</li><li> the items in the <b>same</b> output line are the scalars along the |
| 2050 |
<b>last axis</b> of the APL value, where |
| 2051 |
<ul> |
| 2052 |
<li> a single quoted character is a character scalar, |
| 2053 |
</li><li> several characters inside a single pair of quotes are a character |
| 2054 |
vector (aka. string), |
| 2055 |
</li><li> unquoted characters are numeric scalars, |
| 2056 |
</li><li> nested items are two or more items enclosed in parentheses, and |
| 2057 |
</li><li> the APL scalars of an APL vector are separated by one or more blanks |
| 2058 |
</li></ul> |
| 2059 |
</li><li> the items in <b>different</b> output lines are the scalars along |
| 2060 |
<b>all except the last axis</b> of the APL value, where |
| 2061 |
<ul> |
| 2062 |
<li> two-dimensional values (i.e. matrices) are vertically adjacent |
| 2063 |
vectors. </li><li> three-dimensional values are vertically adjacent |
| 2064 |
matrices, separated by one blank line, |
| 2065 |
</li><li> four-dimensional values are vertically adjacent three-dimensional |
| 2066 |
values, separated by two blank lines, |
| 2067 |
</li><li> ... |
| 2068 |
</li><li> N-dimensional values are vertically adjacent N-1-dimensional values |
| 2069 |
separated by N-2 blank lines, |
| 2070 |
</li></ul> |
| 2071 |
</li></ul> |
| 2072 |
|
| 2073 |
<p>Now, the existing formatting rules for (single line) literals are: |
| 2074 |
</p> |
| 2075 |
<ul> |
| 2076 |
<li> one literal corresponds to one APL scalar or APL vector, where: |
| 2077 |
<ul> |
| 2078 |
<li> a single quoted character is one APL character scalar, |
| 2079 |
</li><li> several quoted characters are an APL character vector (aka. string), |
| 2080 |
</li><li> nested items are two or more items enclosed in blanks, and |
| 2081 |
</li><li> vertically adjacent scalars above are separated by blanks to create |
| 2082 |
vectors; this is called <i>vector notation</i> in Kenneth Iverson’s |
| 2083 |
APL book and in IBM APL2 documents and <i>strand notation</i> in other |
| 2084 |
places, |
| 2085 |
</li></ul> |
| 2086 |
</li></ul> |
| 2087 |
|
| 2088 |
<p>From these rules for single line literals, one can easily derive the rules |
| 2089 |
for multi line literals in a completely consistent fashion: |
| 2090 |
</p> |
| 2091 |
<ul> |
| 2092 |
<li> consistency: the rules for every line of a multi-line literal shall be |
| 2093 |
the same as for single line literals, |
| 2094 |
</li><li> matrix: (directly) vertically adjacent literals become |
| 2095 |
two-dimensional APL values, |
| 2096 |
</li><li> vertically adjacent two-dimensional literals, separated by one blank |
| 2097 |
line, become three-dimensional APL values, |
| 2098 |
</li><li> vertically adjacent three-dimensional literals, separated by two blank |
| 2099 |
line, become four-dimensional APL values, |
| 2100 |
</li><li> ... |
| 2101 |
</li><li> vertically adjacent <b>N-1</b>-dimensional literals separated by <b>N-2</b> |
| 2102 |
blank line become <b>N</b>-dimensional APL values, |
| 2103 |
</li></ul> |
| 2104 |
|
| 2105 |
<p>Similar to multi-line strings, a multi-line literal starts with the marker |
| 2106 |
<b><<<</b> at the end of one line and ends with the marker <b>>>></b> on a |
| 2107 |
subsequent line. The value of the multi line literal is contained in the lines |
| 2108 |
between these two markers (excluding the lines with the markers). In contrast |
| 2109 |
to multi-line strings, can multi line literals be used recursively. That is, |
| 2110 |
one multi line literal can contain other multi line literals (as well as |
| 2111 |
multi-line strings) to created nested sub-values of ranks > 1. |
| 2112 |
</p> |
| 2113 |
<p>Some examples may be worthwhile to explain the concept: |
| 2114 |
</p> |
| 2115 |
<div class="example"> |
| 2116 |
<pre class="example"> ⍝ two-dimensional multi-line literal |
| 2117 |
⍝ |
| 2118 |
⎕ ← <<< |
| 2119 |
1 2 3 |
| 2120 |
4 5 6 |
| 2121 |
7 8 9 |
| 2122 |
>>> |
| 2123 |
1 2 3 |
| 2124 |
4 5 6 |
| 2125 |
7 8 9 |
| 2126 |
</pre></div> |
| 2127 |
|
| 2128 |
<p>One blank line separates the matrix of a three dimensional value: |
| 2129 |
</p> |
| 2130 |
<div class="example"> |
| 2131 |
<pre class="example"> ⍝ three-dimensional multi-line literal |
| 2132 |
⍝ |
| 2133 |
⎕ ← <<< |
| 2134 |
1 2 3 |
| 2135 |
4 5 6 |
| 2136 |
7 8 9 |
| 2137 |
|
| 2138 |
11 12 13 |
| 2139 |
14 15 16 |
| 2140 |
17 18 19 |
| 2141 |
>>> |
| 2142 |
1 2 3 |
| 2143 |
4 5 6 |
| 2144 |
7 8 9 |
| 2145 |
|
| 2146 |
11 12 13 |
| 2147 |
14 15 16 |
| 2148 |
17 18 19 |
| 2149 |
</pre></div> |
| 2150 |
|
| 2151 |
<p>The start line of a literal may contain a comment; the comment does not |
| 2152 |
become part of the literal value: |
| 2153 |
</p> |
| 2154 |
<div class="example"> |
| 2155 |
<pre class="example"> ⍝ two-dimensional multi-line literal with comment |
| 2156 |
⍝ |
| 2157 |
⎕ ← <<< ⍝ same as 3 3⍴⍳9 |
| 2158 |
1 2 3 |
| 2159 |
4 5 6 |
| 2160 |
7 8 9 |
| 2161 |
>>> |
| 2162 |
1 2 3 |
| 2163 |
4 5 6 |
| 2164 |
7 8 9 |
| 2165 |
</pre></div> |
| 2166 |
|
| 2167 |
<p>The items of a multi-line literal can be nested: |
| 2168 |
</p> |
| 2169 |
<div class="example"> |
| 2170 |
<pre class="example"> 8 ⎕CR <<< ⍝ two-dimensional with nested 'abc' |
| 2171 |
1 2 3 |
| 2172 |
4 'abc' 6 |
| 2173 |
7 8 9 |
| 2174 |
>>> |
| 2175 |
┌→────────┐ |
| 2176 |
↓1 2 3│ |
| 2177 |
│4 ┌→──┐ 6│ |
| 2178 |
│ │abc│ │ |
| 2179 |
│ └───┘ │ |
| 2180 |
│7 8 9│ |
| 2181 |
└ϵ────────┘ |
| 2182 |
|
| 2183 |
8 ⎕CR <<< ⍝ two-dimensional with nested 10 11 12 |
| 2184 |
1 2 3 |
| 2185 |
4 (10 11 12) 6 |
| 2186 |
7 8 9 |
| 2187 |
>>> |
| 2188 |
┌→─────────────┐ |
| 2189 |
↓1 2 3│ |
| 2190 |
│4 ┌→───────┐ 6│ |
| 2191 |
│ │10 11 12│ │ |
| 2192 |
│ └────────┘ │ |
| 2193 |
│7 8 9│ |
| 2194 |
└ϵ─────────────┘ |
| 2195 |
</pre></div> |
| 2196 |
|
| 2197 |
<p>Multi-line literal can contain other Multi-line literals or strings: |
| 2198 |
</p> |
| 2199 |
<div class="example"> |
| 2200 |
<pre class="example"> 8 ⎕CR <<< ⍝ two-dimensional with sub-literal: |
| 2201 |
1 2 3 |
| 2202 |
4 <<< ⍝ sub-literal |
| 2203 |
10 11 12 |
| 2204 |
13 14 15 |
| 2205 |
16 17 18 |
| 2206 |
>>> 6 |
| 2207 |
7 8 9 |
| 2208 |
>>> |
| 2209 |
┌→─────────────┐ |
| 2210 |
↓1 2 3│ |
| 2211 |
│ │ |
| 2212 |
│4 ┌→───────┐ 6│ |
| 2213 |
│ ↓10 11 12│ │ |
| 2214 |
│ │13 14 15│ │ |
| 2215 |
│ │16 17 18│ │ |
| 2216 |
│ └────────┘ │ |
| 2217 |
│ │ |
| 2218 |
│7 8 9│ |
| 2219 |
└ϵ─────────────┘ |
| 2220 |
|
| 2221 |
8 ⎕CR <<< ⍝ two-dimensional with sub-string: |
| 2222 |
1 2 3 |
| 2223 |
4 ««« |
| 2224 |
Hello, |
| 2225 |
World |
| 2226 |
»»» 6 |
| 2227 |
7 8 9 |
| 2228 |
>>> |
| 2229 |
┌→─────────────────────────────────────────────┐ |
| 2230 |
↓1 2 3│ |
| 2231 |
│4 ┌→───────────────────────────────────────┐ 6│ |
| 2232 |
│ │┌→─────────────────┐ ┌→────────────────┐│ │ |
| 2233 |
│ ││ Hello,│ │ World││ │ |
| 2234 |
│ │└──────────────────┘ └─────────────────┘│ │ |
| 2235 |
│ └ϵ───────────────────────────────────────┘ │ |
| 2236 |
│7 8 9│ |
| 2237 |
└ϵϵ────────────────────────────────────────────┘ |
| 2238 |
</pre></div> |
| 2239 |
|
| 2240 |
<p>Nested multi-line literals can quickly become unreadable. It is therefore |
| 2241 |
recommended to use a clear indentation policy for the different nesting |
| 2242 |
levels. |
| 2243 |
</p> |
| 2244 |
<hr> |
| 2245 |
</div> |
| 2246 |
<div class="subsection" id="Automatic-_0029MORE"> |
| 2247 |
<div class="header"> |
| 2248 |
<p> |
| 2249 |
Next: <a href="#Script-Example" accesskey="n" rel="next">Script Example</a>, Previous: <a href="#Multi_002dLine-Literals" accesskey="p" rel="prev">Multi-Line Literals</a>, Up: <a href="#APL-Scripting" accesskey="u" rel="up">APL Scripting</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 2250 |
</div> |
| 2251 |
<span id="Automatic-_0029MORE-1"></span><h4 class="subsection">2.1.10 Automatic )MORE</h4> |
| 2252 |
|
| 2253 |
<p>The GNU APL command )MORE provides, in some cases, additional information |
| 2254 |
about a prior APL error. The availability of such additional information |
| 2255 |
is indicated by a + at the end of the error message. The additional |
| 2256 |
information is automatically discarded when the next non-empty line |
| 2257 |
is entered. For example: |
| 2258 |
</p> |
| 2259 |
<div class="example"> |
| 2260 |
<pre class="example"> "ABC"[4] |
| 2261 |
INDEX ERROR+ |
| 2262 |
'ABC'[4] |
| 2263 |
^ ^ |
| 2264 |
)MORE |
| 2265 |
min index=⎕IO (=1), offending index=4, max index=⎕IO+2 (=3) |
| 2266 |
◊ ⍝ clears )MORE |
| 2267 |
|
| 2268 |
)MORE |
| 2269 |
NO )MORE ERROR INFO |
| 2270 |
</pre></div> |
| 2271 |
|
| 2272 |
<p>This is rather useful in purely interactive mode where the user can issue |
| 2273 |
the )MORE command directly after an APL error has occurred to help figure |
| 2274 |
out what exactly went wrong. In a script, however, the standard )MORE command |
| 2275 |
(as inherited from IBM APL2) is fairly useless for two reasons: |
| 2276 |
</p> |
| 2277 |
<ul> |
| 2278 |
<li> A human user has a chance to issue the )MORE command interactively |
| 2279 |
after an error has occurred, while a script continues after displaying the |
| 2280 |
error message, and |
| 2281 |
</li><li> It is rather difficult to predict where the next errors will occur, |
| 2282 |
i.e. where to place the )MORE command in the script. |
| 2283 |
</li></ul> |
| 2284 |
|
| 2285 |
<p>To make the )MORE command more useful for scripts, in GNU APL it can be |
| 2286 |
augmented with an optional argument AUTO like this: |
| 2287 |
</p> |
| 2288 |
<div class="example"> |
| 2289 |
<pre class="example"> )MORE AUTO ON |
| 2290 |
Automatic )MORE is now: ON |
| 2291 |
|
| 2292 |
"ABC"[4] |
| 2293 |
min index=⎕IO (=1), offending index=4, max index=⎕IO+2 (=3) |
| 2294 |
INDEX ERROR+ |
| 2295 |
'ABC'[4] |
| 2296 |
^ ^ |
| 2297 |
</pre></div> |
| 2298 |
|
| 2299 |
<p>If ON/OFF is omitted then the automatic )MORE mode is toggled. The additional |
| 2300 |
)MORE information is displayed before the standard 3-line APL error message. |
| 2301 |
</p> |
| 2302 |
<hr> |
| 2303 |
</div> |
| 2304 |
<div class="subsection" id="Script-Example"> |
| 2305 |
<div class="header"> |
| 2306 |
<p> |
| 2307 |
Previous: <a href="#Automatic-_0029MORE" accesskey="p" rel="prev">Automatic )MORE</a>, Up: <a href="#APL-Scripting" accesskey="u" rel="up">APL Scripting</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 2308 |
</div> |
| 2309 |
<span id="Script-Example-1"></span><h4 class="subsection">2.1.11 Script Example</h4> |
| 2310 |
|
| 2311 |
<p>Note that the two different ways of running an APL script have an impact on |
| 2312 |
how ⎕ARG looks like. If stdin is redirected then there is only one (possibly |
| 2313 |
empty) set of command line options. Otherwise there are two sets of command |
| 2314 |
line options: command line options for the apl interpreter and command line |
| 2315 |
options for the script. |
| 2316 |
</p> |
| 2317 |
<p>Consider the following simple script called SCRIPT.apl in directory workspaces: |
| 2318 |
</p> |
| 2319 |
<div class="example"> |
| 2320 |
<pre class="example">#! /usr/local/bin/apl --script |
| 2321 |
|
| 2322 |
⊃⎕ARG ⍝ show command line options |
| 2323 |
)OFF ⍝ leave the interpreter |
| 2324 |
</pre></div> |
| 2325 |
|
| 2326 |
<p>If SCRIPT.apl is redirected to stdin of the APL interpreter: |
| 2327 |
</p> |
| 2328 |
<div class="example"> |
| 2329 |
<pre class="example"> /usr/local/bin/apl --silent < ../workspaces/SCRIPT.apl |
| 2330 |
|
| 2331 |
or |
| 2332 |
|
| 2333 |
/usr/local/bin/apl --silent -f ../workspaces/SCRIPT.apl |
| 2334 |
</pre></div> |
| 2335 |
|
| 2336 |
<p>then the first line <samp>#! /usr/local/bin/apl --script</samp> of file SCRIPT.apl |
| 2337 |
is merely a comment (GNU APL accepts both the traditional APL character |
| 2338 |
⍝ and the character # as start of a comment). The <code>-script</code> option |
| 2339 |
is therefore ignored and the following mix of input and output is |
| 2340 |
shown on the screen. The input from the script is indented by the |
| 2341 |
usual APL prompt of 6 blanks, while the output of the APL interpreter |
| 2342 |
is not indented. |
| 2343 |
</p> |
| 2344 |
<div class="example"> |
| 2345 |
<pre class="example"> #! /usr/local/bin/apl --script |
| 2346 |
|
| 2347 |
⊃⎕ARG ⍝ show command line options |
| 2348 |
)OFF ⍝ leave the interpreter |
| 2349 |
</pre></div> |
| 2350 |
|
| 2351 |
<p>If we run the same script directly: |
| 2352 |
</p> |
| 2353 |
<div class="example"> |
| 2354 |
<pre class="example">../workspaces/SCRIPT.apl |
| 2355 |
</pre></div> |
| 2356 |
|
| 2357 |
<p>Then we get: |
| 2358 |
</p> |
| 2359 |
<div class="example"> |
| 2360 |
<pre class="example"> /usr/local/bin/apl --script ../workspaces/SCRIPT.apl |
| 2361 |
</pre></div> |
| 2362 |
|
| 2363 |
<p>The <code>-script</code> implies <code>-noCIN</code> so that the |
| 2364 |
input lines for the interpreter are no longer echoed to the output. |
| 2365 |
This is most likely what you want when writing a script. |
| 2366 |
</p> |
| 2367 |
<p>Also, the first line of the script is no longer ignored as a comment, |
| 2368 |
but controls the command line argument (and thus ⎕ARG) of the interpreter. |
| 2369 |
The additional command line argument <samp>../workspaces/SCRIPT.apl</samp> |
| 2370 |
comes from function execve (see ’man 2 execve’). |
| 2371 |
</p> |
| 2372 |
<p>If we provide an argument, say SCRIPTARG, to SCRIPT.apl: |
| 2373 |
</p> |
| 2374 |
<div class="example"> |
| 2375 |
<pre class="example">../workspaces/SCRIPT.apl SCRIPTARG |
| 2376 |
</pre></div> |
| 2377 |
|
| 2378 |
<p>then it shows up at the end of ⎕ARG: |
| 2379 |
</p> |
| 2380 |
<div class="example"> |
| 2381 |
<pre class="example"> /usr/local/bin/apl --script ../workspaces/SCRIPT.apl SCRIPTARG |
| 2382 |
</pre></div> |
| 2383 |
|
| 2384 |
<p>A final note on scripting in GNU APL is that the ∇-editor works slightly |
| 2385 |
differently when it is used in a script. If a user edits an APL function |
| 2386 |
interactively then an attempt to open an existing function with a full |
| 2387 |
header gives a DEFN ERROR: |
| 2388 |
</p> |
| 2389 |
<div class="example"> |
| 2390 |
<pre class="example"> ∇Z←FOO B |
| 2391 |
[1] ∇ |
| 2392 |
|
| 2393 |
∇Z←FOO B |
| 2394 |
DEFN ERROR+ |
| 2395 |
∇Z←FOO B |
| 2396 |
^ |
| 2397 |
)MORE |
| 2398 |
attempt to ∇-open existing function with new function header |
| 2399 |
</pre></div> |
| 2400 |
|
| 2401 |
<p>In contrast to a user who can react to the DEFN ERROR, a script cannot detect |
| 2402 |
this situation and would continue to push lines (which were intended to be |
| 2403 |
the body of the defined function) into the APL interpreter. That would most |
| 2404 |
likely cause fairly undesirable behavior. For example, if the lines of a |
| 2405 |
defined function start with line numbers (like [1], [2], ...) then every |
| 2406 |
such line would give a SYNTAX ERROR, and other errors can be expected as |
| 2407 |
well. |
| 2408 |
</p> |
| 2409 |
<p>For that reason, if the ∇-editor is used in a script and attempts to redefine |
| 2410 |
an existing defined function then the existing function is simply overwritten |
| 2411 |
with the new one and no DEFN ERROR is raised. |
| 2412 |
</p> |
| 2413 |
|
| 2414 |
<hr> |
| 2415 |
</div> |
| 2416 |
</div> |
| 2417 |
<div class="section" id="Axis-argument-in-defined-functions"> |
| 2418 |
<div class="header"> |
| 2419 |
<p> |
| 2420 |
Next: <a href="#Function-Groups" accesskey="n" rel="next">Function Groups</a>, Previous: <a href="#APL-Scripting" accesskey="p" rel="prev">APL Scripting</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 2421 |
</div> |
| 2422 |
<span id="Axis-argument-in-defined-functions-1"></span><h3 class="section">2.2 Axis argument in defined functions</h3> |
| 2423 |
|
| 2424 |
<p>Defined functions and operators (including lambdas) accept an axis argument. |
| 2425 |
For example: |
| 2426 |
</p> |
| 2427 |
<div class="example"> |
| 2428 |
<pre class="example">∇Z←Average[X] B |
| 2429 |
Z←(+/[X]B) ÷ (⍴B)[X] |
| 2430 |
∇ |
| 2431 |
|
| 2432 |
Average[1] 5 5⍴⍳25 |
| 2433 |
11 12 13 14 15 |
| 2434 |
|
| 2435 |
Average[2] 5 5⍴⍳25 |
| 2436 |
3 8 13 18 23 |
| 2437 |
</pre></div> |
| 2438 |
|
| 2439 |
<p>Syntactically, the axis is used in the same way as for primitive functions |
| 2440 |
and operators. |
| 2441 |
</p> |
| 2442 |
<p>There are no constraints on the axis such as being integers. Therefore you |
| 2443 |
can use an axis as a third function argument. Keep in mind, however, that |
| 2444 |
doing so will make your APL code incompatible with other APL interpreters. |
| 2445 |
Use this feature carefully! |
| 2446 |
</p> |
| 2447 |
|
| 2448 |
<hr> |
| 2449 |
</div> |
| 2450 |
<div class="section" id="Function-Groups"> |
| 2451 |
<div class="header"> |
| 2452 |
<p> |
| 2453 |
Next: <a href="#Colored-Output" accesskey="n" rel="next">Colored Output</a>, Previous: <a href="#Axis-argument-in-defined-functions" accesskey="p" rel="prev">Axis argument in defined functions</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 2454 |
</div> |
| 2455 |
<span id="Function-Groups-1"></span><h3 class="section">2.3 Function Groups</h3> |
| 2456 |
|
| 2457 |
<p>In the old APL1 every function of the interpreter was represented by a single |
| 2458 |
APL character. More precisely, the character represented 1, 2, or 3 |
| 2459 |
sub-functions and the sub-function was selected by the number of arguments |
| 2460 |
provided: |
| 2461 |
</p> |
| 2462 |
<ul> |
| 2463 |
<li> 1 for monadic functions, |
| 2464 |
</li><li> 2 or monadic functions with axis, |
| 2465 |
</li><li> 2 for dyadic functions (w/o axis), or |
| 2466 |
</li><li> 3 for dyadic functions with axis. |
| 2467 |
</li></ul> |
| 2468 |
|
| 2469 |
<p>The APL character itself was designed in a way that made it easy to |
| 2470 |
remember which functions it represented. |
| 2471 |
</p> |
| 2472 |
<p>Unfortunately this 1:1 relationship between APL characters and interpreter |
| 2473 |
functions did not scale very well. As the number of functions increased, |
| 2474 |
a new and, at that time, better scalable concept was introduced: ⎕-functions |
| 2475 |
(and variables). The APL standards define only a small number (less than 20) |
| 2476 |
of them, but different APL vendors were eagerly adding more system functions |
| 2477 |
to represent their proprietary extensions to th APL language. And so did |
| 2478 |
GNU APL. With ⎕-functions the original visual appearance that helped to |
| 2479 |
remember the many functions was replaced by abbreviations. That is, for |
| 2480 |
example, <b>⎕AV</b> stands for the <b>A</b>tomic <b>V</b>ector, <b>⎕TS</b> for |
| 2481 |
<b>T</b>ime <b>S</b>tamp, and so forth. |
| 2482 |
</p> |
| 2483 |
<p>As of this writing, the GNU APL interpreter has more than 100 non-standard |
| 2484 |
functions for various purposes. For such a large number the ⎕-function |
| 2485 |
approach is no longer scalable (try to remember 100 abbreviations and |
| 2486 |
think about the readability of the code using them!). Rather than adding a |
| 2487 |
new ⎕-function for every new function, GNU APL tries to keep the number |
| 2488 |
of ⎕-functions as small as reasonable and by grouping several interpreter |
| 2489 |
functions into sub-function of a single top-level ⎕-function. |
| 2490 |
</p> |
| 2491 |
<p>We call such a top-level ⎕-function a <b>function group</b>. The sub-function |
| 2492 |
functions of a function group are somehow related by their |
| 2493 |
purpose. The function groups of GNU APL are: |
| 2494 |
</p> |
| 2495 |
<ul> |
| 2496 |
<li> <b>⌹</b>: a collection of matrix factorizations (aka. decompositions) |
| 2497 |
</li><li> <b>⎕CR</b>: a collection of data conversions (formerly known as monadic |
| 2498 |
<b>C</b>harater <b>R</b>epresentations |
| 2499 |
</li><li> <b>⎕FFT</b>: a collection of <b>F</b>ast <b>F</b>ourier <b>T</b>ransformations |
| 2500 |
</li><li> <b>⎕FIO</b>: a collection of <b>F</b>ile <b>I</b>/O functions |
| 2501 |
</li><li> <b>⎕MX</b>: a collection of <b>M</b>atri<b>x</b> functions |
| 2502 |
functions |
| 2503 |
</li><li> <b>⎕RVAL</b>: generation of <b>R</b>andom APL <b>Val</b>ues |
| 2504 |
</li><li> <b>SQL</b>: an interface to <b>SQL databases</b> |
| 2505 |
</li></ul> |
| 2506 |
|
| 2507 |
<p>The syntax for function groups has evolved in 3 phases as elucidated in the |
| 2508 |
following. |
| 2509 |
</p> |
| 2510 |
<ul class="section-toc"> |
| 2511 |
<li><a href="#Phase-1_003a-Numerical-Axis-Argument" accesskey="1">Phase 1: Numerical Axis Argument</a></li> |
| 2512 |
<li><a href="#Phase-2_003a-String-Axis-Argument" accesskey="2">Phase 2: String Axis Argument</a></li> |
| 2513 |
<li><a href="#Phase-3_003a-Member-Notation" accesskey="3">Phase 3: Member Notation</a></li> |
| 2514 |
<li><a href="#Subfunction-Lists" accesskey="4">Subfunction Lists</a></li> |
| 2515 |
</ul> |
| 2516 |
<hr> |
| 2517 |
<div class="subsection" id="Phase-1_003a-Numerical-Axis-Argument"> |
| 2518 |
<div class="header"> |
| 2519 |
<p> |
| 2520 |
Next: <a href="#Phase-2_003a-String-Axis-Argument" accesskey="n" rel="next">Phase 2: String Axis Argument</a>, Up: <a href="#Function-Groups" accesskey="u" rel="up">Function Groups</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 2521 |
</div> |
| 2522 |
<span id="Phase-1_003a-Numerical-Axis-Argument-1"></span><h4 class="subsection">2.3.1 Phase 1: Numerical Axis Argument</h4> |
| 2523 |
|
| 2524 |
<p>In the first phase, the number of functions per function group (at that time |
| 2525 |
<b>⎕CR</b> and <b>⎕FIO</b>) was fairly small. A sub-function of the function group |
| 2526 |
was selected as follows: |
| 2527 |
</p> |
| 2528 |
<ul> |
| 2529 |
<li> If all functions in the function group were monadic (as is |
| 2530 |
the case in <b>⎕CR</b>), then the sub-function was selected by |
| 2531 |
the left argument of the function group. |
| 2532 |
</li><li> Otherwise (as is the case in <b>⎕FIO</b>) the individual sub-function |
| 2533 |
could be monadic, dyadic, or nomadic and the sub-function was selected |
| 2534 |
by an axis argument of the function group. |
| 2535 |
</li></ul> |
| 2536 |
|
| 2537 |
<p>For example: |
| 2538 |
</p> |
| 2539 |
<div class="example"> |
| 2540 |
<pre class="example"> 4 ⎕CR B ⍝ format B in a "boxed" fashion |
| 2541 |
18 ⎕CR B ⍝ convert APL string B to an UTF8-encoded byte vector |
| 2542 |
|
| 2543 |
⎕FIO[3] B ⍝ fopen file B for reading |
| 2544 |
A ⎕FIO[3] B ⍝ fopen file B with mode A |
| 2545 |
</pre></div> |
| 2546 |
|
| 2547 |
<p>In both cases was the sub-function selector an integer scalar. |
| 2548 |
</p> |
| 2549 |
<hr> |
| 2550 |
</div> |
| 2551 |
<div class="subsection" id="Phase-2_003a-String-Axis-Argument"> |
| 2552 |
<div class="header"> |
| 2553 |
<p> |
| 2554 |
Next: <a href="#Phase-3_003a-Member-Notation" accesskey="n" rel="next">Phase 3: Member Notation</a>, Previous: <a href="#Phase-1_003a-Numerical-Axis-Argument" accesskey="p" rel="prev">Phase 1: Numerical Axis Argument</a>, Up: <a href="#Function-Groups" accesskey="u" rel="up">Function Groups</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 2555 |
</div> |
| 2556 |
<span id="Phase-2_003a-String-Axis-Argument-1"></span><h4 class="subsection">2.3.2 Phase 2: String Axis Argument</h4> |
| 2557 |
|
| 2558 |
<p>Shortly after introducing the syntax of phase 1, GNU APL users began to develop |
| 2559 |
an APL workspace named <b>FILE_IO</b>. This workspace contains one APL wrapper |
| 2560 |
function for each numerical <b>⎕FIO</b> sub-function selector. These wrappers |
| 2561 |
were trivial one-liners like these: |
| 2562 |
</p> |
| 2563 |
<div class="example"> |
| 2564 |
<pre class="example"> ∇Zh ← As FIO∆fopen Bs |
| 2565 |
⍝⍝ fopen(Bs, As) filename Bs |
| 2566 |
Zh ← As ⎕FIO[3] Bs |
| 2567 |
∇ |
| 2568 |
|
| 2569 |
∇Zh ← FIO∆fopen_ro Bs |
| 2570 |
⍝⍝ fopen(Bs, "r") filename Bs |
| 2571 |
Zh ← ⎕FIO[3] Bs |
| 2572 |
∇ |
| 2573 |
</pre></div> |
| 2574 |
|
| 2575 |
<p>APL programs would <b>)COPY</b> this workspace and then use its normal defined |
| 2576 |
functions instead of <b>⎕FIO</b> with an axis argument or <b>⎕CR</b> with a left |
| 2577 |
argument. The development of the <b>FILE_IO</b> suggested that APL users have |
| 2578 |
a preference of names over numbers to select a sub-function. |
| 2579 |
</p> |
| 2580 |
<p>GNU APL accommodated this preference by allowing sub-function names (APL strings) |
| 2581 |
as sub-function selectors. These names were usually the same as the C library |
| 2582 |
function that implemented them. |
| 2583 |
</p> |
| 2584 |
<p>The phase 1 example above would now become the slightly better readable: |
| 2585 |
</p> |
| 2586 |
<div class="example"> |
| 2587 |
<pre class="example"> 'style_boxed' ⎕CR B ⍝ format B in a "boxed" fashion |
| 2588 |
'string_to_UTF8' ⎕CR B ⍝ convert APL string B to UTF8 |
| 2589 |
|
| 2590 |
⎕FIO['fopen'] B ⍝ fopen file B for reading |
| 2591 |
A ⎕FIO['fopen'] B ⍝ fopen file B with mode A |
| 2592 |
</pre></div> |
| 2593 |
|
| 2594 |
<hr> |
| 2595 |
</div> |
| 2596 |
<div class="subsection" id="Phase-3_003a-Member-Notation"> |
| 2597 |
<div class="header"> |
| 2598 |
<p> |
| 2599 |
Next: <a href="#Subfunction-Lists" accesskey="n" rel="next">Subfunction Lists</a>, Previous: <a href="#Phase-2_003a-String-Axis-Argument" accesskey="p" rel="prev">Phase 2: String Axis Argument</a>, Up: <a href="#Function-Groups" accesskey="u" rel="up">Function Groups</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 2600 |
</div> |
| 2601 |
<span id="Phase-3_003a-Member-Notation-1"></span><h4 class="subsection">2.3.3 Phase 3: Member Notation</h4> |
| 2602 |
|
| 2603 |
<p>The third phase aims at further improving the readability. It replaces the |
| 2604 |
axis argument with a member notation. The phase 1 and 2 examples above would |
| 2605 |
now become: |
| 2606 |
</p> |
| 2607 |
<div class="example"> |
| 2608 |
<pre class="example"> ⎕CR.style_boxed B ⍝ format B in a "boxed" fashion |
| 2609 |
⎕CR.string_to_UTF8 B ⍝ convert APL string B to UTF8 |
| 2610 |
|
| 2611 |
⎕FIO.fopen B ⍝ fopen file B for reading |
| 2612 |
A ⎕FIO.fopen B ⍝ fopen file B with mode A |
| 2613 |
</pre></div> |
| 2614 |
|
| 2615 |
<hr> |
| 2616 |
</div> |
| 2617 |
<div class="subsection" id="Subfunction-Lists"> |
| 2618 |
<div class="header"> |
| 2619 |
<p> |
| 2620 |
Previous: <a href="#Phase-3_003a-Member-Notation" accesskey="p" rel="prev">Phase 3: Member Notation</a>, Up: <a href="#Function-Groups" accesskey="u" rel="up">Function Groups</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 2621 |
</div> |
| 2622 |
<span id="Subfunction-Lists-1"></span><h4 class="subsection">2.3.4 Subfunction Lists</h4> |
| 2623 |
|
| 2624 |
<p>If the number of sub-functions becomes large, then remembering all sub-function |
| 2625 |
names of a function group is still a problem. To avoid the need to consult |
| 2626 |
other documentation while programming, all function groups provide lists |
| 2627 |
that show their sub-functions and their syntax. |
| 2628 |
</p> |
| 2629 |
<p>Let <b>FOO</b> be a function group. Then: |
| 2630 |
</p> |
| 2631 |
<ul> |
| 2632 |
<li> <b>FOO ""</b> shows a list of sub-functions, and |
| 2633 |
</li><li> <b>FOO ⍬</b> shows the syntaces (as per phase 1, 2, or 3) of them. |
| 2634 |
</li></ul> |
| 2635 |
|
| 2636 |
<hr> |
| 2637 |
</div> |
| 2638 |
</div> |
| 2639 |
<div class="section" id="Colored-Output"> |
| 2640 |
<div class="header"> |
| 2641 |
<p> |
| 2642 |
Next: <a href="#Comparison-Rules" accesskey="n" rel="next">Comparison Rules</a>, Previous: <a href="#Function-Groups" accesskey="p" rel="prev">Function Groups</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 2643 |
</div> |
| 2644 |
<span id="Colored-Output-1"></span><h3 class="section">2.4 Colored Output</h3> |
| 2645 |
|
| 2646 |
<p>The APL interpreter gets its input from the standard input (stdin), |
| 2647 |
which is normally connected to the user’s keyboard, |
| 2648 |
but can also be a file if APL scripting, the <code>f</code> option, |
| 2649 |
or the <code>T</code> option is used. |
| 2650 |
</p> |
| 2651 |
<p>The APL interpreter prints its results on either the standard output (stdout) |
| 2652 |
for normal APL output, or to the error output (stderr) for additional |
| 2653 |
trouble-shooting information. |
| 2654 |
</p> |
| 2655 |
<p>You can print the 3 channels stdin, stdout, and stderr in different colors |
| 2656 |
by means of the debug command ]XTERM. Command ]XTERM ON enables colored |
| 2657 |
output while ]XTERM OFF disables it (for example to avoid annoying ANSI |
| 2658 |
Escape sequences when forwarding stdout or stderr to a file). |
| 2659 |
</p> |
| 2660 |
<p>Default colored output assumes a terminal (-emulation) that understands |
| 2661 |
ANSI (or VT100) Escape sequences. The xterm that comes with most recent |
| 2662 |
GNU/Linux distributions is a perfect choice supporting both colors and |
| 2663 |
UTF-8 (Unicode) encoded character I/O. |
| 2664 |
</p> |
| 2665 |
<p>Non-ANSI terminals, as well as other colors than the default ones, can be |
| 2666 |
configured in the ’preferences’ file. The ’preferences’ file also |
| 2667 |
contains a description of all possible color settings. |
| 2668 |
</p> |
| 2669 |
|
| 2670 |
<hr> |
| 2671 |
</div> |
| 2672 |
<div class="section" id="Comparison-Rules"> |
| 2673 |
<div class="header"> |
| 2674 |
<p> |
| 2675 |
Next: <a href="#Complex-Numbers" accesskey="n" rel="next">Complex Numbers</a>, Previous: <a href="#Colored-Output" accesskey="p" rel="prev">Colored Output</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 2676 |
</div> |
| 2677 |
<span id="Comparison-Rules-1"></span><h3 class="section">2.5 Comparison Rules</h3> |
| 2678 |
|
| 2679 |
<p>Both IBM APL2 and the ISO standard require that the arguments of <, ≤, ≥, |
| 2680 |
and > (but not of = or ≠) are integer or real numbers. As a consequence, |
| 2681 |
the argument(s) of ⍋ or ⍒ (which require comparison) must also be a vector |
| 2682 |
of integer or real numbers. |
| 2683 |
</p> |
| 2684 |
<p>In contrast, GNU APL also allows the comparison of characters and numbers or |
| 2685 |
the comparison of complex numbers according to the following, more general, |
| 2686 |
rules. |
| 2687 |
</p> |
| 2688 |
<p>Let A and B be two APL values to be compared. The final result of comparing |
| 2689 |
A and B is the first verdict (i.e. either A < B, or A > B, or A = B) |
| 2690 |
obtained when following the rules below in the indicated order: |
| 2691 |
</p> |
| 2692 |
<ol> |
| 2693 |
<li> Comparison by rank: if (⍴⍴A) < (⍴⍴B) then A < B and vice versa. |
| 2694 |
|
| 2695 |
</li><li> Comparison by shape: if (⍴A) < (⍴B) then A < B and vice versa. The |
| 2696 |
first differing shape item (from the left) decides. |
| 2697 |
|
| 2698 |
</li><li> Comparison of ravel elements: at this point (⍴A) ≡ (⍴B). If all |
| 2699 |
corresponding ravel elements of A and B are equal (i.e. tolerantly equal |
| 2700 |
within ⎕CT as defined in the ISO standard) then A = B. |
| 2701 |
|
| 2702 |
<p>Otherwise let A1 and B1 be the first corresponding ravel elements of A and B |
| 2703 |
with A1 ≠ B1. If A1 < B1 then A < B and vice versa. The comparison A1 < B1 |
| 2704 |
is made according to the following rules 4 - 8 below. |
| 2705 |
</p> |
| 2706 |
</li><li> Comparison by depth: |
| 2707 |
|
| 2708 |
<ul> |
| 2709 |
<li> If A1 and B1 are both nested: the rules 1 - 3 above are (recursively) |
| 2710 |
applied to corresponding ravel elements of ⊃A1 and ⊃B1 until a verdict is |
| 2711 |
obtained. |
| 2712 |
|
| 2713 |
</li><li> if A1 is simple and B1 is nested then A < B and vice versa. |
| 2714 |
|
| 2715 |
</li><li> otherwise (i.e. A1 and B1 are both simple): A < B if A1 < B1 according to |
| 2716 |
rules 5 - 8 below and vice versa. |
| 2717 |
</li></ul> |
| 2718 |
|
| 2719 |
</li><li> Comparison by Unicode: if A1 and B1 are both character values and |
| 2720 |
(⎕UCS A1) < (⎕UCS B1) then A < B and vice versa. |
| 2721 |
|
| 2722 |
</li><li> Comparison by type: If A1 is a character and B1 is numeric, then A < B |
| 2723 |
and vice versa. |
| 2724 |
|
| 2725 |
</li><li> Comparison by numeric value: if A1 and B1 are both numeric values then: |
| 2726 |
|
| 2727 |
<ul> |
| 2728 |
<li> Comparison by real part: if (9○A1) < (9○B1) then A < B and vice versa. |
| 2729 |
|
| 2730 |
</li><li> Comparison by imaginary part: otherwise if (11○A1) < (11○B1) then A < B |
| 2731 |
and vice versa. |
| 2732 |
</li></ul> |
| 2733 |
|
| 2734 |
</li><li> Otherwise: A = B. |
| 2735 |
</li></ol> |
| 2736 |
|
| 2737 |
<p>Another way of describing the rules above is that the comparison of two values |
| 2738 |
is comprised of sub-comparisons of certain properties of the values in the |
| 2739 |
following order: |
| 2740 |
</p> |
| 2741 |
<ul> |
| 2742 |
<li> the ranks of the values, |
| 2743 |
</li><li> the shapes of the values, |
| 2744 |
</li><li> the first differing ravel element (in row-major order) of the values, |
| 2745 |
</li><li> the depths of the differing ravel elements, |
| 2746 |
</li><li> the types (character vs. numeric) of the differing ravel elements, |
| 2747 |
</li><li> the Unicodes of the differing ravel elements (if applicable) |
| 2748 |
</li><li> the real parts of numeric values, |
| 2749 |
</li><li> the imaginary parts of numeric values, |
| 2750 |
</li></ul> |
| 2751 |
|
| 2752 |
<p>Note: Rules 1 and 2 above are only relevant for comparisons made in the |
| 2753 |
context of sorting (i.e. for ⍋ or ⍒). This is because for =, ≠, <, ≤, ≥, |
| 2754 |
or > either a RANK ERROR or a LENGTH ERROR is raised if the ranks or shapes |
| 2755 |
of A and B do not match: |
| 2756 |
</p> |
| 2757 |
<div class="example"> |
| 2758 |
<pre class="example"> (9 8) < (1 2 3) |
| 2759 |
LENGTH ERROR |
| 2760 |
9 8<1 2 3 |
| 2761 |
^ ^ |
| 2762 |
|
| 2763 |
⍋(9 8) (1 2 3) |
| 2764 |
1 2 |
| 2765 |
</pre></div> |
| 2766 |
|
| 2767 |
<p>The reason for comparing complex numbers first by their real parts and then |
| 2768 |
by their imaginary part and not, for example, first by their magnitude and |
| 2769 |
then by their angle is that the chosen order gives more consistent results |
| 2770 |
when comparing near-complex numbers or their true real companions. For |
| 2771 |
example, a magnitude first comparison of complex numbers would make |
| 2772 |
¯2 < ¯1 < ¯2J1E¯20 for the near-complex number ¯2J1E¯20. |
| 2773 |
</p> |
| 2774 |
<p><b>CAUTION</b>: The comparison of two strings (i.e. nested character |
| 2775 |
vectors) may give unexpected results because shorter strings come before |
| 2776 |
longer strings. For example, ’Zoo’ comes <b>before</b> ’Adam’ even |
| 2777 |
though one might expect the opposite. |
| 2778 |
</p> |
| 2779 |
<div class="example"> |
| 2780 |
<pre class="example"> Z[⍋Z ← 'Adam' 'Zoo'] |
| 2781 |
Zoo Adam |
| 2782 |
|
| 2783 |
Z[⍋Z ← 'Adam' 'Zora'] |
| 2784 |
Adam Zora |
| 2785 |
</pre></div> |
| 2786 |
|
| 2787 |
<p>This pitfall can be avoided by enforcing the same length for all strings |
| 2788 |
being compared or sorted. A simple way to achieve that is the use of |
| 2789 |
<b>⊂[2]⊃</b> like this (assuming ⎕IO←1): |
| 2790 |
</p> |
| 2791 |
<div class="example"> |
| 2792 |
<pre class="example"> Z[⍋Z ← ⊂[2]⊃ 'Adam' 'Zoo'] |
| 2793 |
Adam Zoo |
| 2794 |
|
| 2795 |
Z[⍋Z ← ⊂[2]⊃ 'Adam' 'Zora'] |
| 2796 |
Adam Zora |
| 2797 |
</pre></div> |
| 2798 |
|
| 2799 |
|
| 2800 |
<hr> |
| 2801 |
</div> |
| 2802 |
<div class="section" id="Complex-Numbers"> |
| 2803 |
<div class="header"> |
| 2804 |
<p> |
| 2805 |
Next: <a href="#Debug-Commands" accesskey="n" rel="next">Debug Commands</a>, Previous: <a href="#Comparison-Rules" accesskey="p" rel="prev">Comparison Rules</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 2806 |
</div> |
| 2807 |
<span id="Complex-Numbers-1"></span><h3 class="section">2.6 Complex Numbers</h3> |
| 2808 |
|
| 2809 |
<p>Complex numbers are fully supported. |
| 2810 |
</p> |
| 2811 |
|
| 2812 |
<hr> |
| 2813 |
</div> |
| 2814 |
<div class="section" id="Debug-Commands"> |
| 2815 |
<div class="header"> |
| 2816 |
<p> |
| 2817 |
Next: <a href="#Direct-Functions-_0028Lambdas_0029" accesskey="n" rel="next">Direct Functions (Lambdas)</a>, Previous: <a href="#Complex-Numbers" accesskey="p" rel="prev">Complex Numbers</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 2818 |
</div> |
| 2819 |
<span id="Debug-Commands-1"></span><h3 class="section">2.7 Debug Commands</h3> |
| 2820 |
|
| 2821 |
<p>In addition to the classical APL commands like )LOAD or )SAVE, GNU APL |
| 2822 |
has a number of debug commands for debugging purposes. |
| 2823 |
Regular APL commands start with ) and print their output on stdout. |
| 2824 |
Debug commands start with ] and print their output on stderr. Normally |
| 2825 |
you cannot easily distinguish between stdout and stderr, but another |
| 2826 |
GNU APL feature, colored output, uses different colors for stdout and stderr. |
| 2827 |
</p> |
| 2828 |
<p>Type )HELP or ]HELP in the interpreter for a list of all commands available. |
| 2829 |
</p> |
| 2830 |
|
| 2831 |
<hr> |
| 2832 |
</div> |
| 2833 |
<div class="section" id="Direct-Functions-_0028Lambdas_0029"> |
| 2834 |
<div class="header"> |
| 2835 |
<p> |
| 2836 |
Next: <a href="#Commands-_0029COPY_005fONCE-_0029DUMP-and-DUMP_002dHTML" accesskey="n" rel="next">Commands )COPY_ONCE, )DUMP, and DUMP-HTML</a>, Previous: <a href="#Debug-Commands" accesskey="p" rel="prev">Debug Commands</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 2837 |
</div> |
| 2838 |
<span id="Direct-Functions-_0028Lambdas_0029-1"></span><h3 class="section">2.8 Direct Functions (Lambdas)</h3> |
| 2839 |
|
| 2840 |
<p>GNU APL supports direct functions (aka. lambdas), but only in a rather |
| 2841 |
limited form. |
| 2842 |
</p> |
| 2843 |
<ul class="section-toc"> |
| 2844 |
<li><a href="#Named-Lambdas" accesskey="1">Named Lambdas</a></li> |
| 2845 |
<li><a href="#Unnamed-Lambdas" accesskey="2">Unnamed Lambdas</a></li> |
| 2846 |
<li><a href="#Limitations-of-GNU-APL-Lambdas" accesskey="3">Limitations of GNU APL Lambdas</a></li> |
| 2847 |
</ul> |
| 2848 |
<hr> |
| 2849 |
<div class="subsection" id="Named-Lambdas"> |
| 2850 |
<div class="header"> |
| 2851 |
<p> |
| 2852 |
Next: <a href="#Unnamed-Lambdas" accesskey="n" rel="next">Unnamed Lambdas</a>, Up: <a href="#Direct-Functions-_0028Lambdas_0029" accesskey="u" rel="up">Direct Functions (Lambdas)</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 2853 |
</div> |
| 2854 |
<span id="Named-Lambdas-1"></span><h4 class="subsection">2.8.1 Named Lambdas</h4> |
| 2855 |
|
| 2856 |
<p>A statement of the form |
| 2857 |
</p> |
| 2858 |
<div class="example"> |
| 2859 |
<pre class="example"> FUN ← { body_statement } |
| 2860 |
</pre></div> |
| 2861 |
|
| 2862 |
<p>creates a <i>named lambda</i>. The single <i>body_statement</i> may contain the |
| 2863 |
special variable names <b>⍺</b> and <b>⍵</b> as well as the special function |
| 2864 |
names <b>⍶</b> and <b>⍹</b> which are replaced by the actual arguments of the |
| 2865 |
lambda when the lambda is executed. The valence of the lambda is determined |
| 2866 |
as follows: |
| 2867 |
</p> |
| 2868 |
<ul> |
| 2869 |
<li> If <b>⍶</b> and <b>⍹</b> are present then the lambda is a <i>dyadic operator</i>. |
| 2870 |
</li><li> If only <b>⍶</b> is present then the lambda is a <i>monadic operator</i>. |
| 2871 |
</li><li> If neither <b>⍶</b> nor <b>⍹</b> is present then the lambda is a normal |
| 2872 |
defined function. |
| 2873 |
</li><li> If both <b>⍺</b> and <b>⍵</b> are present in the body_statement then the |
| 2874 |
operator or defined function is dyadic. |
| 2875 |
</li><li> If only <b>⍵</b> is present then the operator or defined is monadic. |
| 2876 |
</li><li> If neither <b>⍺</b> nor <b>⍵</b> is present then the lambda is niladic. |
| 2877 |
</li><li> Lambdas with the left value argument <b>⍺</b> but without the right |
| 2878 |
value argument <b>⍵</b> are invalid (SYNTAX ERROR). |
| 2879 |
</li></ul> |
| 2880 |
|
| 2881 |
<p>There is a noteworthy pitfall related to niladic named lambdas. Recalling |
| 2882 |
to the fundamental APL evaluation rule: |
| 2883 |
</p> |
| 2884 |
<p><i>All functions execute according to their position in an expression. |
| 2885 |
The rightmost function whose arguments are available is evaluated |
| 2886 |
first</i> |
| 2887 |
</p> |
| 2888 |
<p>implies that a niladic function is evaluated first (because it has no |
| 2889 |
arguments and consequently no arguments that are not available). Therefore |
| 2890 |
in an expression such as: |
| 2891 |
</p> |
| 2892 |
<div class="example"> |
| 2893 |
<pre class="example">NAME ← { statement } |
| 2894 |
</pre></div> |
| 2895 |
|
| 2896 |
<p>will the niladic lambda <b>{ statement }</b> be evaluated before the |
| 2897 |
assignment, The name <b>NAME</b> is therefore the result of the niladic lambda |
| 2898 |
and not the niladic lambda itself. IOW: the example above <i>does not</i> |
| 2899 |
create a niladic named lambda, but rather a normal variable <b>NAME</b> whose |
| 2900 |
value is the result of evaluating <b>statement</b>. Creating niladic named |
| 2901 |
lambdas is impossible. |
| 2902 |
</p> |
| 2903 |
<p>GNU APL supports an axis argument in normal defined functions and |
| 2904 |
operators. In lambda expressions the Greek letter <b>χ</b> (Chi) is the |
| 2905 |
variable name for an axis argument. |
| 2906 |
</p> |
| 2907 |
<p>The way a named lambda is implemented in GNU APL is that the assignment of |
| 2908 |
the form: |
| 2909 |
</p> |
| 2910 |
<div class="example"> |
| 2911 |
<pre class="example"> FUN ← { body_expression } |
| 2912 |
</pre></div> |
| 2913 |
|
| 2914 |
<p>is translated to a two-line function ⎕FX ’lambda_header’ ’body_expression’. |
| 2915 |
</p> |
| 2916 |
<p>For example: |
| 2917 |
</p> |
| 2918 |
<div class="example"> |
| 2919 |
<pre class="example"> )FNS |
| 2920 |
|
| 2921 |
SUM ← { ⍺ + ⍵ } |
| 2922 |
</pre></div> |
| 2923 |
|
| 2924 |
<p>is translated to a two-line function ⎕FX ’lambda_header’ ’body_expression’. |
| 2925 |
</p> |
| 2926 |
<p>For example: |
| 2927 |
</p> |
| 2928 |
<div class="example"> |
| 2929 |
<pre class="example"> )FNS |
| 2930 |
|
| 2931 |
SUM ← { ⍺ + ⍵ } |
| 2932 |
)FNS |
| 2933 |
SUM |
| 2934 |
|
| 2935 |
∇SUM[⎕]∇ |
| 2936 |
DEFN ERROR+ |
| 2937 |
∇SUM[⎕]∇ |
| 2938 |
^ |
| 2939 |
)MORE |
| 2940 |
function is a lambda |
| 2941 |
</pre></div> |
| 2942 |
|
| 2943 |
<p>Named lambdas are included in function lists like <b>)FNS</b> along with other |
| 2944 |
defined functions. They can not be edited with the ∇-edidor, but can be |
| 2945 |
displayed using <b>⎕CR ’name’</b>: |
| 2946 |
</p> |
| 2947 |
<div class="example"> |
| 2948 |
<pre class="example"> ⎕CR 'SUM' |
| 2949 |
λ←⍺ λ1 ⍵ |
| 2950 |
λ← ⍺ + ⍵ |
| 2951 |
</pre></div> |
| 2952 |
|
| 2953 |
<p>The lambda_header is automatically deduced from the presence or absence |
| 2954 |
of the variable names (⍺, ⍵, and χ) and function names (⍶ and ⍹) in the |
| 2955 |
body_expression and from whether the body_expression is empty (no λ←) or |
| 2956 |
not (i.e. with λ←). |
| 2957 |
</p> |
| 2958 |
<p>It is possible to specify local variables that work exactly like their |
| 2959 |
companions in normal defined functions. Please note that this is different |
| 2960 |
from some other APL interpreters which treat all variables in lambda bodies |
| 2961 |
as local variables. The syntax for specifying local variables is the same |
| 2962 |
as for the header in normal defined functions: they are added at the end |
| 2963 |
with semicolons as separators. In the above example one could add local |
| 2964 |
variables C and D like this: |
| 2965 |
</p> |
| 2966 |
<div class="example"> |
| 2967 |
<pre class="example"> SUM ← { ⍺ + ⍵ ;C;D } |
| 2968 |
|
| 2969 |
⎕CR 'SUM' |
| 2970 |
λ←⍺ λ1 ⍵;C;D |
| 2971 |
λ← ⍺ + ⍵ |
| 2972 |
</pre></div> |
| 2973 |
|
| 2974 |
<p>If a named lambda is created inside a defined function, then the name of the |
| 2975 |
lambda (i.e. the name left of ← { ... }) can be made a local variable of |
| 2976 |
the function in which the named lambda is created. This creates a lambda with |
| 2977 |
local scope. |
| 2978 |
</p> |
| 2979 |
<p>Please note that the above only describes the current implementation of named |
| 2980 |
lambda in GNU APL. A consequence of that implementation is that the symbols |
| 2981 |
⍺, ⍵, χ, ⍶, ⍹, and λ are pretty much behaving like user defined variables. In |
| 2982 |
particular, they can be used outside named or unnamed lambdas. However, that |
| 2983 |
may change in the future and therefore such use of ⍺, ⍵, χ, ⍶, ⍹, and λ outside |
| 2984 |
is certainly a bad idea. |
| 2985 |
</p> |
| 2986 |
<p>As of this writing, GNU APL lambdas allow multiple statements, separated |
| 2987 |
by <b>◊</b>. This feature is experimental, not portable, and should be avoided |
| 2988 |
where possible. In GNU APL, the value of a multi-statement lambda is the |
| 2989 |
value of the last statement and this differs from the semantics of |
| 2990 |
multi-statements in other APL interpreters! |
| 2991 |
</p> |
| 2992 |
<hr> |
| 2993 |
</div> |
| 2994 |
<div class="subsection" id="Unnamed-Lambdas"> |
| 2995 |
<div class="header"> |
| 2996 |
<p> |
| 2997 |
Next: <a href="#Limitations-of-GNU-APL-Lambdas" accesskey="n" rel="next">Limitations of GNU APL Lambdas</a>, Previous: <a href="#Named-Lambdas" accesskey="p" rel="prev">Named Lambdas</a>, Up: <a href="#Direct-Functions-_0028Lambdas_0029" accesskey="u" rel="up">Direct Functions (Lambdas)</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 2998 |
</div> |
| 2999 |
<span id="Unnamed-Lambdas-1"></span><h4 class="subsection">2.8.2 Unnamed Lambdas</h4> |
| 3000 |
|
| 3001 |
<p>An unnamed lambda is an expression inside { and } but without assigning |
| 3002 |
it to a name. This is often used together with the EACH operator. |
| 3003 |
For example: |
| 3004 |
</p> |
| 3005 |
<div class="example"> |
| 3006 |
<pre class="example"> { ⍴ , ⍵ } ¨ 'a' 'ab' 'abc' |
| 3007 |
1 2 3 |
| 3008 |
</pre></div> |
| 3009 |
|
| 3010 |
<p>Unnamed lambdas are automatically local in scope (similar to labels). They can |
| 3011 |
be passed as function arguments to operators. However, unnamed lambdas are NOT |
| 3012 |
inserted into the symbol table of the interpreter. They are therefore not |
| 3013 |
visible to functions like ⎕CR or by the ∇-editor. Occasionally the names λ1, |
| 3014 |
λ2, ... may show up in commands like )SIS. These names are automatically |
| 3015 |
generated for unnamed lambdas in order to provide a name in places where a |
| 3016 |
function name is needed. |
| 3017 |
</p> |
| 3018 |
<hr> |
| 3019 |
</div> |
| 3020 |
<div class="subsection" id="Limitations-of-GNU-APL-Lambdas"> |
| 3021 |
<div class="header"> |
| 3022 |
<p> |
| 3023 |
Previous: <a href="#Unnamed-Lambdas" accesskey="p" rel="prev">Unnamed Lambdas</a>, Up: <a href="#Direct-Functions-_0028Lambdas_0029" accesskey="u" rel="up">Direct Functions (Lambdas)</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 3024 |
</div> |
| 3025 |
<span id="Limitations-of-GNU-APL-Lambdas-1"></span><h4 class="subsection">2.8.3 Limitations of GNU APL Lambdas</h4> |
| 3026 |
|
| 3027 |
<p>There are a number of features related to lambdas that are present in other |
| 3028 |
APL interpreters but that are <b>NOT</b> implemented in GNU APL. This includes |
| 3029 |
multiple statements, guards, lexical scoping, and probably more. |
| 3030 |
</p> |
| 3031 |
<p>The primary reason for these limitations in not the lazyness of the GNU APL |
| 3032 |
author, but the fact that the lambdas in other APL dialects introduce a |
| 3033 |
execution semantics that is very different from the execution semantics of |
| 3034 |
<i>properly</i> defined functions (i.e. those created with the ∇-editor or |
| 3035 |
with <b>⎕FX</b>. For example, a properly defined function returns with <b>→0</b> |
| 3036 |
or after its last line was executed, while the lambdas in other dialects |
| 3037 |
also returns after the first non-committed value was computed (i.e. in the |
| 3038 |
middle of a multi-line function and without any <b>→0</b> (and without any |
| 3039 |
warnings). The GNU APL author is an old-fashioned programmer from the APL1 |
| 3040 |
aera who considers it outright dangerous to have two kinds of functions that |
| 3041 |
very much look the same (the only difference being the argument names <b>⍺</b> |
| 3042 |
and <b>⍵</b>), but that behave fundamentally different. |
| 3043 |
</p> |
| 3044 |
<p>In contrast, GNU APL tries to keep the same execution semantics for lambdas |
| 3045 |
and for properly defined functions. As one of the consequences, you |
| 3046 |
<i>should not</i> create or modify a lambdas with <b>⎕FX</b> or with the ∇-editor |
| 3047 |
(it may be possible for debugging purposes, but then it is asking for trouble). |
| 3048 |
</p> |
| 3049 |
|
| 3050 |
<hr> |
| 3051 |
</div> |
| 3052 |
</div> |
| 3053 |
<div class="section" id="Commands-_0029COPY_005fONCE-_0029DUMP-and-DUMP_002dHTML"> |
| 3054 |
<div class="header"> |
| 3055 |
<p> |
| 3056 |
Next: <a href="#g_t_005dDOXY-Command" accesskey="n" rel="next">]DOXY Command</a>, Previous: <a href="#Direct-Functions-_0028Lambdas_0029" accesskey="p" rel="prev">Direct Functions (Lambdas)</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 3057 |
</div> |
| 3058 |
<span id="Commands-_0029COPY_005fONCE_002c-_0029DUMP_002c-and-DUMP_002dHTML"></span><h3 class="section">2.9 Commands )COPY_ONCE, )DUMP, and DUMP-HTML</h3> |
| 3059 |
|
| 3060 |
<p>In standard APL, workspaces are processed with the standard commands )LOAD, |
| 3061 |
)COPY, and )SAVE. GNU APL provides additional commands to process workspaces. |
| 3062 |
</p> |
| 3063 |
<ul class="section-toc"> |
| 3064 |
<li><a href="#g_t_0029DUMP-Command" accesskey="1">)DUMP Command</a></li> |
| 3065 |
<li><a href="#g_t_0029DUMP_002dHTML-Command" accesskey="2">)DUMP-HTML Command</a></li> |
| 3066 |
<li><a href="#g_t_0029COPY_005fONCE-Command" accesskey="3">)COPY_ONCE Command</a></li> |
| 3067 |
</ul> |
| 3068 |
<hr> |
| 3069 |
<div class="subsection" id="g_t_0029DUMP-Command"> |
| 3070 |
<div class="header"> |
| 3071 |
<p> |
| 3072 |
Next: <a href="#g_t_0029DUMP_002dHTML-Command" accesskey="n" rel="next">)DUMP-HTML Command</a>, Up: <a href="#Commands-_0029COPY_005fONCE-_0029DUMP-and-DUMP_002dHTML" accesskey="u" rel="up">Commands )COPY_ONCE, )DUMP, and DUMP-HTML</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 3073 |
</div> |
| 3074 |
<span id="g_t_0029DUMP-Command-1"></span><h4 class="subsection">2.9.1 )DUMP Command</h4> |
| 3075 |
|
| 3076 |
<p>GNU APL has a command )DUMP that saves a workspace to disk, similar to the |
| 3077 |
)OUT command. The difference between them is the file format being produced. |
| 3078 |
While )OUT produces a file in IBM’s workspace interchange format (aka. an |
| 3079 |
.atf file), )DUMP produces a file in GNU APL’s script format (i.e. readable |
| 3080 |
APL statements). Files written with )DUMP can be edited with normal text |
| 3081 |
editors (vi, Emacs), read back with "apl -f", or made executable (see |
| 3082 |
scripting). |
| 3083 |
</p> |
| 3084 |
<hr> |
| 3085 |
</div> |
| 3086 |
<div class="subsection" id="g_t_0029DUMP_002dHTML-Command"> |
| 3087 |
<div class="header"> |
| 3088 |
<p> |
| 3089 |
Next: <a href="#g_t_0029COPY_005fONCE-Command" accesskey="n" rel="next">)COPY_ONCE Command</a>, Previous: <a href="#g_t_0029DUMP-Command" accesskey="p" rel="prev">)DUMP Command</a>, Up: <a href="#Commands-_0029COPY_005fONCE-_0029DUMP-and-DUMP_002dHTML" accesskey="u" rel="up">Commands )COPY_ONCE, )DUMP, and DUMP-HTML</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 3090 |
</div> |
| 3091 |
<span id="g_t_0029DUMP_002dHTML-Command-1"></span><h4 class="subsection">2.9.2 )DUMP-HTML Command</h4> |
| 3092 |
|
| 3093 |
<p>The )DUMP-HTML command is similar to the )DUMP command and the output format |
| 3094 |
is similar as well. The difference is that those characters that need |
| 3095 |
HTML-escaping (e.g. ’<’ becomes &lt; and ’>’ becomes ’&gt; etc.) are |
| 3096 |
HTML-escaped. The output of the )DUMP-HTML command can therefore be directly |
| 3097 |
used by a web browser to display workspace listings (to share the code). |
| 3098 |
</p> |
| 3099 |
<p>The files written with the )DUMP-HTML command have the extension <b>.html</b>. |
| 3100 |
</p> |
| 3101 |
<p>In addition to the APL code, the .html files produced have a short HTML |
| 3102 |
<head> section template. The user should replace the fields marked |
| 3103 |
with <b>??????</b> with proper values (for the author, the copyright owner, |
| 3104 |
and a short description) before publishing the page. |
| 3105 |
</p> |
| 3106 |
<hr> |
| 3107 |
</div> |
| 3108 |
<div class="subsection" id="g_t_0029COPY_005fONCE-Command"> |
| 3109 |
<div class="header"> |
| 3110 |
<p> |
| 3111 |
Previous: <a href="#g_t_0029DUMP_002dHTML-Command" accesskey="p" rel="prev">)DUMP-HTML Command</a>, Up: <a href="#Commands-_0029COPY_005fONCE-_0029DUMP-and-DUMP_002dHTML" accesskey="u" rel="up">Commands )COPY_ONCE, )DUMP, and DUMP-HTML</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 3112 |
</div> |
| 3113 |
<span id="g_t_0029COPY_005fONCE-Command-1"></span><h4 class="subsection">2.9.3 )COPY_ONCE Command</h4> |
| 3114 |
|
| 3115 |
<p>Command )COPY_ONCE copies all objects (variables, functions and operators) |
| 3116 |
from some other workspace into the current workspace similar to )COPY. |
| 3117 |
However, )COPY_ONCE does this only once; a second invocation of |
| 3118 |
)COPY_ONCE with the same workspace (and the same library reference number) |
| 3119 |
is silently ignored. This speeds up the )COPYing of libraries that occur |
| 3120 |
in several )DUMP-ed or )SAVE-ed workspaces. |
| 3121 |
</p> |
| 3122 |
|
| 3123 |
<hr> |
| 3124 |
</div> |
| 3125 |
</div> |
| 3126 |
<div class="section" id="g_t_005dDOXY-Command"> |
| 3127 |
<div class="header"> |
| 3128 |
<p> |
| 3129 |
Next: <a href="#g_t_005dKEYB-Command" accesskey="n" rel="next">]KEYB Command</a>, Previous: <a href="#Commands-_0029COPY_005fONCE-_0029DUMP-and-DUMP_002dHTML" accesskey="p" rel="prev">Commands )COPY_ONCE, )DUMP, and DUMP-HTML</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 3130 |
</div> |
| 3131 |
<span id="g_t_005dDOXY-Command-1"></span><h3 class="section">2.10 ]DOXY Command</h3> |
| 3132 |
|
| 3133 |
<p>A particularly useful debug command is ]DOXY. It dumps the current workspace |
| 3134 |
in brows-able HTML format with listings of defined functions and hyperlinks |
| 3135 |
between them. |
| 3136 |
</p> |
| 3137 |
<div class="example"> |
| 3138 |
<pre class="example">]DOXY ⍝ write documentation to /tmp/WSNAME/* |
| 3139 |
]DOXY dest ⍝ write documentation to dest/WSNAME/* |
| 3140 |
</pre></div> |
| 3141 |
|
| 3142 |
<p>The starting point for browsing the documentation are the files: |
| 3143 |
</p> |
| 3144 |
<div class="example"> |
| 3145 |
<pre class="example">/tmp/WSNAME/index.html ⍝ for ]DOXY without arguments, or |
| 3146 |
dest/WSNAME/index.html ⍝ for e.g. ]DOXY dest |
| 3147 |
</pre></div> |
| 3148 |
|
| 3149 |
<p>The index.html files above usually correspond to the following URIs in your |
| 3150 |
browser: |
| 3151 |
</p> |
| 3152 |
<div class="example"> |
| 3153 |
<pre class="example">file:///tmp/WSNAME or |
| 3154 |
file:///absolute-path-to-dest/WSNAME respectively. |
| 3155 |
</pre></div> |
| 3156 |
|
| 3157 |
<p>In the above examples WSNAME is the )WSID of the workspace in which the ]DOXY |
| 3158 |
command was executed. |
| 3159 |
</p> |
| 3160 |
<p>One can (and should make it a habit to) insert special comments into defined |
| 3161 |
functions which are copied into proper places inside the documentation that is |
| 3162 |
generated by the ]DOXY command. These "doxy" comments begin with ⍝⍝ (as opposed |
| 3163 |
to "normal" APL comments that start with a single ⍝. Doxy comments are |
| 3164 |
typically one-liners that briefly explain what a function is supposed to do. |
| 3165 |
</p> |
| 3166 |
<p>For example: |
| 3167 |
</p> |
| 3168 |
<div class="example"> |
| 3169 |
<pre class="example">∇Z←A SUM B |
| 3170 |
⍝⍝ Return the sum of A and B ← ]DOXY comment: (double ⍝) |
| 3171 |
⍝ A: numeric ← "normal" APL comments (single ⍝) ... |
| 3172 |
⍝ B: numeric |
| 3173 |
Z←A + B |
| 3174 |
∇ |
| 3175 |
</pre></div> |
| 3176 |
|
| 3177 |
<p>But please <b>note the following</b>: in the original <b>doxygen</b> program |
| 3178 |
(for C, C++, or other languages) source code lines may be a mix of code |
| 3179 |
and comments (including doxygen comments). In the <b>]DOXY</b> command of GNU |
| 3180 |
APL a line of a defined function shall be either APL code or else a doxygen |
| 3181 |
comment (i.e. starting with ⍝⍝). Doxygen comments indented with blanks are |
| 3182 |
allowed (for the sake of readability). |
| 3183 |
</p> |
| 3184 |
<p>Since a doxygen comment is also a valid APL comment, it is perfectly legal |
| 3185 |
to put a doxygen comment at the end of a line that starts with APL code. |
| 3186 |
However, such lines will be ignored by the <b>]DOXY</b> command. |
| 3187 |
</p> |
| 3188 |
<p>The parser generates no extra code from the doxygen comments, and therefore |
| 3189 |
the use of many doxygen comments causes no performance problem (and neither |
| 3190 |
do regular APL comments). |
| 3191 |
</p> |
| 3192 |
|
| 3193 |
<hr> |
| 3194 |
</div> |
| 3195 |
<div class="section" id="g_t_005dKEYB-Command"> |
| 3196 |
<div class="header"> |
| 3197 |
<p> |
| 3198 |
Next: <a href="#g_t_005dNEXTFILE-and-_005dPUSHFILE-Commands" accesskey="n" rel="next">]NEXTFILE and ]PUSHFILE Commands</a>, Previous: <a href="#g_t_005dDOXY-Command" accesskey="p" rel="prev">]DOXY Command</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 3199 |
</div> |
| 3200 |
<span id="g_t_005dKEYB-Command-1"></span><h3 class="section">2.11 ]KEYB Command</h3> |
| 3201 |
|
| 3202 |
<p>In the early days of APL the user was typically faced with three problems: |
| 3203 |
APL keyboards, APL screens, and APL printers. |
| 3204 |
</p> |
| 3205 |
<p>The advent of Unicode has soved the last two problems rather eleqantly: |
| 3206 |
the Uncode character set contains all APL characters, and screens (i.e CRT tubes |
| 3207 |
in the old days and screen windows these days) and printers display them |
| 3208 |
properly. What remains is the keyboard problem. The keyboard problem has two |
| 3209 |
sub-problems: Keyboard caps that show APL symbols in addition to the normal |
| 3210 |
ASCII characters, and generating proiper Unicodes when the keys are being |
| 3211 |
pressed (typically with the ALT or CTRL keys held down). |
| 3212 |
</p> |
| 3213 |
<p>GNU APL provides the debug command <b>]KEYB</b> to help resolving these issues. |
| 3214 |
There are two cases where <b>]KEYB</b> may be useful: |
| 3215 |
</p> |
| 3216 |
<ul> |
| 3217 |
<li> One can buy so called ’APL keyboards’ or APL stickers that can be |
| 3218 |
glued on the key caps of a regular keyboard. As a matter of fact, APL |
| 3219 |
keyboards are simply regular keyboards with differen key caps. The keycodes |
| 3220 |
sent by APL keyboards do not differ from the keycodes of regular keyboards. |
| 3221 |
One the other hand, many programmers type blindly; for them the keycaps are |
| 3222 |
mostly irrelevant, and the substantial surcharge for APL keyboards may be |
| 3223 |
unreasonable. A related problem is national keyboards: most APL keyboards |
| 3224 |
have a US layout for their keycaps although a user may prefer a national |
| 3225 |
layout. Most of this can be helped with a keuboard layout that is printed |
| 3226 |
on the screen. A user that types bindly most of the time, but cannot |
| 3227 |
remember the position of all APL symbols (in particular of rarely used ones) |
| 3228 |
may find it useful to display the keyboard layout on the screen. |
| 3229 |
|
| 3230 |
</li><li> The other use case for <b>]KEYB</b> is troubleshooting the transformation |
| 3231 |
of keys pressed on the keyboard to Unicodes sent to the APL interpreter. This |
| 3232 |
transformation (which is explained in more detail below) is highly |
| 3233 |
conficurable. The good news is that these days any keyboard can be configured |
| 3234 |
to send any Unicode on any key as preferered by the user. The bad news is |
| 3235 |
that this configuration differs a lot between different platforms and can |
| 3236 |
be faily cumbersome. The <b>]KEYB</b> command is intended to help figuring |
| 3237 |
why pressing a partiicular key does not produce the APL character that it |
| 3238 |
should. It maybe wothwhile to note that even an APL keyboard can (and most |
| 3239 |
likely will) not produce the characters shown on its keypad if the |
| 3240 |
transformation from key presses to Unicdes is misconfigured. In that respect |
| 3241 |
APL keyboards are no better than keybiard stickers: Glueing a <b>⍴</b> sticker |
| 3242 |
onto the <b>R</b> does not make the <b>R</b> send the Unicode for <b>⍴</b>. Likewise, |
| 3243 |
an APL keyboard with <b>⍴</b> printed in addition to <b>R</b> does not make that |
| 3244 |
keyboard send the Unicode for <b>⍴</b>. Both cases only work as expected if |
| 3245 |
the transformation from keys to Unicdes is configured properly. |
| 3246 |
</li></ul> |
| 3247 |
|
| 3248 |
<ul class="section-toc"> |
| 3249 |
<li><a href="#The-transformation-of-Keycodes-to-Unicodes" accesskey="1">The transformation of Keycodes to Unicodes</a></li> |
| 3250 |
<li><a href="#xmodmap-and-friends" accesskey="2">xmodmap and friends</a></li> |
| 3251 |
<li><a href="#The-_005dKEYB-command" accesskey="3">The ]KEYB command</a></li> |
| 3252 |
</ul> |
| 3253 |
<hr> |
| 3254 |
<div class="subsection" id="The-transformation-of-Keycodes-to-Unicodes"> |
| 3255 |
<div class="header"> |
| 3256 |
<p> |
| 3257 |
Next: <a href="#xmodmap-and-friends" accesskey="n" rel="next">xmodmap and friends</a>, Up: <a href="#g_t_005dKEYB-Command" accesskey="u" rel="up">]KEYB Command</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 3258 |
</div> |
| 3259 |
<span id="The-transformation-of-Keycodes-to-Unicodes-1"></span><h4 class="subsection">2.11.1 The transformation of Keycodes to Unicodes</h4> |
| 3260 |
|
| 3261 |
<p>In a nutshell, on a GNU/Linux (or other X-based) platform, |
| 3262 |
a key pressed or realeased is processed as follows: |
| 3263 |
</p> |
| 3264 |
<ol> |
| 3265 |
<li> The user presses or releases a key on the keyboard. This creates a |
| 3266 |
<b>key-event</b> in the operating system. This key-event contains three |
| 3267 |
items: |
| 3268 |
<ul> |
| 3269 |
<li> a <b>keycode</b> which is a number between 0 and 255 that uniquely |
| 3270 |
identidies the key. The keys in the main keyboard area (i.e. |
| 3271 |
where all the alkphabetic keys are located), have keycodes between |
| 3272 |
8 and 64, |
| 3273 |
</li><li> a <b>state</b> which tells if the key was pressed or released, and |
| 3274 |
</li><li> a <b>timestanp</b> which tells when key was pressed or released. |
| 3275 |
</li></ul> |
| 3276 |
</li><li> The operating system processes the event: |
| 3277 |
<ul> |
| 3278 |
<li> It remembers the new state of the key. If the key is a |
| 3279 |
<b>modifier key</b> such as SHIFT, CTRL, or ALT, the the processing |
| 3280 |
is done. |
| 3281 |
</li><li> Otherwise the key is a normal key and the operating system |
| 3282 |
computes a <b>keysymbol</b> from the <b>keycode</b>. In this computation |
| 3283 |
the modifier keys whose states were remembered in the previous steps |
| 3284 |
are taken into account. For that reason, e.g. pressing <b>R</b> when |
| 3285 |
(only) the SHIFT modifier key is pressed produces <b>R</b> and if SHIFT |
| 3286 |
is released then it produces <b>r</b>. Every Unicode has a keysymbol (with |
| 3287 |
the same value) but some keysymbols doe not correspond to a Unicode |
| 3288 |
but o an action that the oprating system shall perform (e.g. cursor |
| 3289 |
home in a termina window). A particularly important keysymbol is |
| 3290 |
<b>0x0000</b> aka. <b>NoSymbol</b> which indicates that (for a given |
| 3291 |
combination of modifer keys) no Unicode shall be generated. |
| 3292 |
</li></ul> |
| 3293 |
|
| 3294 |
</li><li> The operating system forwards the keysymbol towards the application |
| 3295 |
(in our case GNU APL). On the way from the operating system to the |
| 3296 |
application there may be other mappings applied to the keysymbol. For |
| 3297 |
example, the window manager may bind functions to function the keys |
| 3298 |
of the keyboard and call the function when the keysymbol for the |
| 3299 |
function key was received from the operating system. Every such |
| 3300 |
mapping can be a cause of trouble if keys needed by GNU APL are |
| 3301 |
involved. |
| 3302 |
</li></ol> |
| 3303 |
|
| 3304 |
<hr> |
| 3305 |
</div> |
| 3306 |
<div class="subsection" id="xmodmap-and-friends"> |
| 3307 |
<div class="header"> |
| 3308 |
<p> |
| 3309 |
Next: <a href="#The-_005dKEYB-command" accesskey="n" rel="next">The ]KEYB command</a>, Previous: <a href="#The-transformation-of-Keycodes-to-Unicodes" accesskey="p" rel="prev">The transformation of Keycodes to Unicodes</a>, Up: <a href="#g_t_005dKEYB-Command" accesskey="u" rel="up">]KEYB Command</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 3310 |
</div> |
| 3311 |
<span id="xmodmap-and-friends-1"></span><h4 class="subsection">2.11.2 xmodmap and friends</h4> |
| 3312 |
|
| 3313 |
<p>The installation of an operating system installs a Keycodes to Unicodes |
| 3314 |
mapping according to the language choices made by the user during the |
| 3315 |
installation. for example, in the US keycode <b>29</b> will be mapped to <b>y</b>, |
| 3316 |
while in Germany keycode <b>29</b> will be mapped to <b>z</b>. At this point most |
| 3317 |
mappings for modifier ALT pressed, and most settings for CTRL pressed are |
| 3318 |
set to <b>NoSymbol</b> so that pressing these keys together with CTRL or ALT |
| 3319 |
have no effect. To generate APL characteres instead of nothing, |
| 3320 |
the user has to modify the mapping as to produce APL Unicodes. This |
| 3321 |
modification is lost after rebooting the computer; therefore the mapping |
| 3322 |
is usually performed in a script that is run at login time of the user (i.e. |
| 3323 |
in ~/.bashrc). |
| 3324 |
</p> |
| 3325 |
<p>The modification is made with a program. Unfortunately there exist several |
| 3326 |
such programs, e.g. <b>xmodmap</b>, <b>setxkbmap</b>, or <b>loadkeys</b>. See |
| 3327 |
<b>README-3-keyboard</b> for details. More is not always better |
| 3328 |
and the different programs for the same purpose have undesirable side effects |
| 3329 |
when used in parallel. An important lesson after experimenting with several |
| 3330 |
of these programs was: <i>Use one and only one of these programs on your |
| 3331 |
platform</i>. |
| 3332 |
</p> |
| 3333 |
<p>Each of these programs has its own set of pitfalls. For example with |
| 3334 |
<b>xmodmap</b>, pressing <b>ALT-SHIFT-L</b> (in that order produces ⌷. Pressing |
| 3335 |
<b>SHIFT-ALT-L</b> produces nothing. |
| 3336 |
</p> |
| 3337 |
<p>Despite of this, <b>xmodmap</b> seems to be the simplest and most reliable |
| 3338 |
of the modidication programs. It may have less capabilities than the others, |
| 3339 |
but has everything needed to run GNU APL. For this reason, GNU APL is |
| 3340 |
shipped with a configuration file for US keyboards |
| 3341 |
(<b>support-files/Juergen-Mint-21/xmodmap.apl</b>) and a file to undo the |
| 3342 |
mapping (<b>support-files/Juergen-Mint-21/xmodmap.ascii</b>). The latter is |
| 3343 |
redundant since <b>xmodmap</b> provides a way to save the current mapping |
| 3344 |
(see <b>man xmodmap</b>). There was a short period where <b>xmodmap</b> did not |
| 3345 |
work in Linux Mint several yeras ago, but this has been fixed in the meantime. |
| 3346 |
</p> |
| 3347 |
<p>It is impossible for the author to explain all available mapping programs |
| 3348 |
and therefore this manual focuses on <b>xmodmap</b> and, as an alternative, |
| 3349 |
<b>setxkbmap/xkbcomp</b>. <b>xmodmap</b> is considerably simpler to configure |
| 3350 |
than <b>setxkbmap/xkbcomp</b> but not available on all platforms. |
| 3351 |
</p> |
| 3352 |
<p>Suppose we run: |
| 3353 |
</p> |
| 3354 |
<p><b>$ xmodmap xmodmap.apl</b> |
| 3355 |
</p> |
| 3356 |
<p>and suppose pressing key <b>R</b> does <i><b>not</b></i> produce <b>⍴</b>. This can have |
| 3357 |
the following reasons: |
| 3358 |
</p> |
| 3359 |
<ol> |
| 3360 |
<li> incorrect keycode for key <b>R</b>, |
| 3361 |
</li><li> correct keycode, but incorrect keysymbol(s), or |
| 3362 |
</li></ol> |
| 3363 |
|
| 3364 |
<p>Both cases can be identified with the <b>]KEYB</b> command. |
| 3365 |
</p> |
| 3366 |
<hr> |
| 3367 |
</div> |
| 3368 |
<div class="subsection" id="The-_005dKEYB-command"> |
| 3369 |
<div class="header"> |
| 3370 |
<p> |
| 3371 |
Previous: <a href="#xmodmap-and-friends" accesskey="p" rel="prev">xmodmap and friends</a>, Up: <a href="#g_t_005dKEYB-Command" accesskey="u" rel="up">]KEYB Command</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 3372 |
</div> |
| 3373 |
<span id="The-_005dKEYB-command-1"></span><h4 class="subsection">2.11.3 The ]KEYB command</h4> |
| 3374 |
|
| 3375 |
<ul class="section-toc"> |
| 3376 |
<li><a href="#g_t_005dKEYB-Syntax" accesskey="1">]KEYB Syntax</a></li> |
| 3377 |
<li><a href="#g_t_005dKEYB-without-a-mode" accesskey="2">]KEYB without a mode</a></li> |
| 3378 |
<li><a href="#g_t_005dKEYB-XMOD" accesskey="3">]KEYB XMOD</a></li> |
| 3379 |
<li><a href="#g_t_005dKEYB-USER" accesskey="4">]KEYB USER</a></li> |
| 3380 |
<li><a href="#g_t_005dKEYB-GUESS" accesskey="5">]KEYB GUESS</a></li> |
| 3381 |
<li><a href="#Optional-_005dKEYB-arguments" accesskey="6">Optional ]KEYB arguments</a></li> |
| 3382 |
</ul> |
| 3383 |
<hr> |
| 3384 |
<div class="subsubsection" id="g_t_005dKEYB-Syntax"> |
| 3385 |
<div class="header"> |
| 3386 |
<p> |
| 3387 |
Next: <a href="#g_t_005dKEYB-without-a-mode" accesskey="n" rel="next">]KEYB without a mode</a>, Up: <a href="#The-_005dKEYB-command" accesskey="u" rel="up">The ]KEYB command</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 3388 |
</div> |
| 3389 |
<span id="g_t_005dKEYB-Syntax-1"></span><h4 class="subsubsection">2.11.3.1 ]KEYB Syntax</h4> |
| 3390 |
|
| 3391 |
<p>The syntax of the <b>]KEYB</b> command is: |
| 3392 |
</p> |
| 3393 |
<div class="example"> |
| 3394 |
<pre class="example"> <b>]KEYB [mode] [arguments]</b> |
| 3395 |
</pre></div> |
| 3396 |
|
| 3397 |
<p>where the optional <b>mode</b> determines how the output shall be generated, and |
| 3398 |
the optional arguments specify additional details for the output. There are |
| 3399 |
3 different modes: |
| 3400 |
</p> |
| 3401 |
<ul> |
| 3402 |
<li> Mode <b>XMOD</b> uses the program <b>xmodmap</b> to figure the keyboard layout. |
| 3403 |
This mode, if it works, produces an output that is closest to reality. |
| 3404 |
</li><li> Mode <b>XKBD</b> uses the X extension <b>Xkbd</b> which is typically configured |
| 3405 |
with the programs <b>setxkbmap</b> and <b>xkbcomp</b>. GNU APL reads the result |
| 3406 |
of that configuration back with function <b>XkbKeycodeToKeysym</b>. This |
| 3407 |
mode, if it works, produces an output that is also closest to reality. |
| 3408 |
</li><li> Mode <b>USER</b> display a keyboard layout provided by the user. The output |
| 3409 |
of this mode is as correct as its input. |
| 3410 |
</li><li> mode <b>GUESS</b> displays a typical APL keyboard layout (which may differ |
| 3411 |
considerably from the true keyboard layout). |
| 3412 |
</li></ul> |
| 3413 |
|
| 3414 |
<p><b>WARNING</b>: In theory one could map some keys with <b>xmodmap</b> and others |
| 3415 |
with <b>xkbcomp</b>. Even though one might be able to achieve a desired mapping |
| 3416 |
in this way (and maybe quicker than with either of the methods alone), |
| 3417 |
<b>]KEYB</b> will not be able to display it properly. This is because the |
| 3418 |
<b>xmodmap -pke </b> does not see the <b>xkbcomp</b> mapping and the <b>X</b> function |
| 3419 |
<b>XkbKeycodeToKeysym()</b> does not see the <b>xmodmap</b> mapping. |
| 3420 |
</p> |
| 3421 |
<hr> |
| 3422 |
</div> |
| 3423 |
<div class="subsubsection" id="g_t_005dKEYB-without-a-mode"> |
| 3424 |
<div class="header"> |
| 3425 |
<p> |
| 3426 |
Next: <a href="#g_t_005dKEYB-XMOD" accesskey="n" rel="next">]KEYB XMOD</a>, Previous: <a href="#g_t_005dKEYB-Syntax" accesskey="p" rel="prev">]KEYB Syntax</a>, Up: <a href="#The-_005dKEYB-command" accesskey="u" rel="up">The ]KEYB command</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 3427 |
</div> |
| 3428 |
<span id="g_t_005dKEYB-without-a-mode-1"></span><h4 class="subsubsection">2.11.3.2 ]KEYB without a mode</h4> |
| 3429 |
|
| 3430 |
<p>Command i<b>]KEYB</b> without a mode is for the normal day to day use (as |
| 3431 |
opposed to troubleshooting). It displays an APL keyboard on the screen, |
| 3432 |
which is very useful if the keyboard has no APL stickers or key caps. |
| 3433 |
</p> |
| 3434 |
<p><b>]KEYB</b> without a mode tries (in that order): |
| 3435 |
</p> |
| 3436 |
<ol> |
| 3437 |
<li> <b>]KEYB XMOD</b> |
| 3438 |
</li><li> <b>]KEYB USER</b> |
| 3439 |
</li><li> <b>]KEYB GUESS</b> |
| 3440 |
</li></ol> |
| 3441 |
|
| 3442 |
<p>The command stops after the first mode that was successful. Mode <b>GUESS</b> |
| 3443 |
always succeeds, therefore <b>]KEYB</b> will always produce an output. If that |
| 3444 |
output is correct is a different question, though. |
| 3445 |
</p> |
| 3446 |
<p>The first line of the keyboard displayed shows which of the 3 methods above |
| 3447 |
was used to generate the output. |
| 3448 |
</p> |
| 3449 |
<p>As may have become clear from the explanations above and/or from reading |
| 3450 |
<b>README-3-keyboard</b> in the top-level GNU APL directory, <b>]KEYB XMOD</b> |
| 3451 |
will fail if either <b>xmodmap</b> is not used at all, or if <b>xmodmap</b> is |
| 3452 |
combined with other keyboard mapping programs. For these cases, the user can |
| 3453 |
disable the automatic use of <b>xmodmap</b> in one of her preferences files. |
| 3454 |
The option to do so is <b>NO-XMODMAP</b> and ii is effective only of |
| 3455 |
]KEYB is calle without a mode. That is, <b>]KEYB XMOD</b> will use <b>xmodmap</b> |
| 3456 |
even if <b>xmodmap</b> was disabled by <b>NO-XMODMAP</b> in a preferences file. |
| 3457 |
</p> |
| 3458 |
|
| 3459 |
<hr> |
| 3460 |
</div> |
| 3461 |
<div class="subsubsection" id="g_t_005dKEYB-XMOD"> |
| 3462 |
<div class="header"> |
| 3463 |
<p> |
| 3464 |
Next: <a href="#g_t_005dKEYB-USER" accesskey="n" rel="next">]KEYB USER</a>, Previous: <a href="#g_t_005dKEYB-without-a-mode" accesskey="p" rel="prev">]KEYB without a mode</a>, Up: <a href="#The-_005dKEYB-command" accesskey="u" rel="up">The ]KEYB command</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 3465 |
</div> |
| 3466 |
<span id="g_t_005dKEYB-XMOD-1"></span><h4 class="subsubsection">2.11.3.3 ]KEYB XMOD</h4> |
| 3467 |
|
| 3468 |
<p><b>]KEYB XMOD</b> runs, under the hood, <b>xmodmap -pke</b> to read the current |
| 3469 |
keycode to keysymbol mapping and displays the result in form of a |
| 3470 |
keyboard layout on the screen. For example: |
| 3471 |
</p> |
| 3472 |
<div class="example"> |
| 3473 |
<pre class="example"> ]KEYB XMOD |
| 3474 |
US Keyboard Layout. Source: xmodmap -pke |
| 3475 |
|
| 3476 |
╔════╦════╦════╦════╦════╦════╦════╦════╦════╦════╦════╦════╦════╦═════════╗ |
| 3477 |
║ ~ ║ !⌶ ║ @⍫ ║ #⍒ ║ $⍋ ║ %⌽ ║ ^⍉ ║ &⊖ ║ *⍟ ║ (⍱ ║ )⍲ ║ _! ║ +⌹ ║ ║ |
| 3478 |
║ `◊ ║ 1¨ ║ 2¯ ║ 3< ║ 4≤ ║ 5= ║ 6≥ ║ 7> ║ 8≠ ║ 9∨ ║ 0∧ ║ -× ║ =÷ ║ BACKSPC ║ |
| 3479 |
╠════╩══╦═╩══╦═╩══╦═╩══╦═╩══╦═╩══╦═╩══╦═╩══╦═╩══╦═╩══╦═╩══╦═╩══╦═╩══╦══════╣ |
| 3480 |
║ ║ Q ║ W⍹ ║ E⋸ ║ R ║ T⍨ ║ Y¥ ║ U ║ I⍸ ║ O⍥ ║ P⍣ ║ {⍞ ║ }⍬ ║ |⊣ ║ |
| 3481 |
║ TAB ║ q? ║ w⍵ ║ e∈ ║ r⍴ ║ t∼ ║ y↑ ║ u↓ ║ i⍳ ║ o○ ║ p⋆ ║ [← ║ ]→ ║ \⊢ ║ |
| 3482 |
╠═══════╩═╦══╩═╦══╩═╦══╩═╦══╩═╦══╩═╦══╩═╦══╩═╦══╩═╦══╩═╦══╩═╦══╩═╦══╩══════╣ |
| 3483 |
║ (CAPS ║ A⍶ ║ S ║ D ║ F ║ G ║ H⍙ ║ J⍤ ║ K ║ L⌷ ║ :≡ ║ "≢ ║ ║ |
| 3484 |
║ LOCK) ║ a⍺ ║ s⌈ ║ d⌊ ║ f_ ║ g∇ ║ h∆ ║ j∘ ║ kλ ║ l⎕ ║ ;⍎ ║ '⍕ ║ RETURN ║ |
| 3485 |
╠═════════╩═══╦╩═══╦╩═══╦╩═══╦╩═══╦╩═══╦╩═══╦╩═══╦╩═══╦╩═══╦╩═══╦╩═════════╣ |
| 3486 |
║ ║ Z ║ Xχ ║ C¢ ║ V ║ B£ ║ N ║ Mμ ║ <⍪ ║ >⍙ ║ ?⍠ ║ ║ |
| 3487 |
║ SHIFT ║ z⊂ ║ x⊃ ║ c∩ ║ v∪ ║ b⊥ ║ n⊤ ║ m∣ ║ ,⍝ ║ .⍀ ║ /⌿ ║ SHIFT ║ |
| 3488 |
╚═════════════╩════╩════╩════╩════╩════╩════╩════╩════╩════╩════╩══════════╝ |
| 3489 |
</pre></div> |
| 3490 |
|
| 3491 |
<p>Naturally, this only works, iff: |
| 3492 |
</p> |
| 3493 |
<ul> |
| 3494 |
<li> <b>xmodmap</b> is installed and working, |
| 3495 |
</li><li> the current keyboard mapping was installed with <b>xmodmap</b>, |
| 3496 |
</li><li> no other keyboard mappings are in effect, and |
| 3497 |
</li><li> the keycodes are correct (see below). |
| 3498 |
</li></ul> |
| 3499 |
|
| 3500 |
<p>IOW: <b>]KEYB XMOD</b> troubleshoots the case |
| 3501 |
<i>correct keycode, but incorrect keysymbol(s)</i> above. |
| 3502 |
</p> |
| 3503 |
<hr> |
| 3504 |
</div> |
| 3505 |
<div class="subsubsection" id="g_t_005dKEYB-USER"> |
| 3506 |
<div class="header"> |
| 3507 |
<p> |
| 3508 |
Next: <a href="#g_t_005dKEYB-GUESS" accesskey="n" rel="next">]KEYB GUESS</a>, Previous: <a href="#g_t_005dKEYB-XMOD" accesskey="p" rel="prev">]KEYB XMOD</a>, Up: <a href="#The-_005dKEYB-command" accesskey="u" rel="up">The ]KEYB command</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 3509 |
</div> |
| 3510 |
<span id="g_t_005dKEYB-USER-1"></span><h4 class="subsubsection">2.11.3.4 ]KEYB USER</h4> |
| 3511 |
|
| 3512 |
<p><b>]KEYB USER</b> does not try to figure the current keyboard mapping but rather |
| 3513 |
displays a static file provided by the user. This mode is a fallback for the |
| 3514 |
case where the other modes are not able to produce a correct keyboard layout. |
| 3515 |
The user can take the output of <b>]KEYB GUESS</b> as a starting point and correct |
| 3516 |
the deviations from the actual keyboard layout. |
| 3517 |
</p> |
| 3518 |
<p>The name of file shown with <b>]KEYB USER</b> can be configured in one of the |
| 3519 |
<b>preferences</b> files. |
| 3520 |
</p> |
| 3521 |
<hr> |
| 3522 |
</div> |
| 3523 |
<div class="subsubsection" id="g_t_005dKEYB-GUESS"> |
| 3524 |
<div class="header"> |
| 3525 |
<p> |
| 3526 |
Next: <a href="#Optional-_005dKEYB-arguments" accesskey="n" rel="next">Optional ]KEYB arguments</a>, Previous: <a href="#g_t_005dKEYB-USER" accesskey="p" rel="prev">]KEYB USER</a>, Up: <a href="#The-_005dKEYB-command" accesskey="u" rel="up">The ]KEYB command</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 3527 |
</div> |
| 3528 |
<span id="g_t_005dKEYB-GUESS-1"></span><h4 class="subsubsection">2.11.3.5 ]KEYB GUESS</h4> |
| 3529 |
|
| 3530 |
<p><b>]KEYB GUESS</b> does not try to figure the current keyboard mapping but rather |
| 3531 |
displays the layout that the various keyboard configuration files that are |
| 3532 |
shipped with GNU APL are likely to produce. The layout is a standard US APL |
| 3533 |
keyboard. |
| 3534 |
</p> |
| 3535 |
<hr> |
| 3536 |
</div> |
| 3537 |
<div class="subsubsection" id="Optional-_005dKEYB-arguments"> |
| 3538 |
<div class="header"> |
| 3539 |
<p> |
| 3540 |
Previous: <a href="#g_t_005dKEYB-GUESS" accesskey="p" rel="prev">]KEYB GUESS</a>, Up: <a href="#The-_005dKEYB-command" accesskey="u" rel="up">The ]KEYB command</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 3541 |
</div> |
| 3542 |
<span id="Optional-_005dKEYB-arguments-1"></span><h4 class="subsubsection">2.11.3.6 Optional ]KEYB arguments</h4> |
| 3543 |
|
| 3544 |
<p><b>]KEYB XMOD KEYS</b> runs <b>xmodmap -pke</b>, but first shows the assumed |
| 3545 |
physical layout of the keyboard. By comparing the first half of the output |
| 3546 |
with the second half, one can see how <b>xmodmap</b> mapes keycodes to |
| 3547 |
Unicode characters. For example: |
| 3548 |
</p> |
| 3549 |
<div class="example"> |
| 3550 |
<pre class="example"> ]KEYB XMOD KEYS |
| 3551 |
Physical Keyboard: Source: GNU APL builtin |
| 3552 |
|
| 3553 |
╔════╦════╦════╦════╦════╦════╦════╦════╦════╦════╦════╦════╦════╦═════════╗ |
| 3554 |
║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ |
| 3555 |
║ 49 ║ 10 ║ 11 ║ 12 ║ 13 ║ 14 ║ 15 ║ 16 ║ 17 ║ 18 ║ 19 ║ 20 ║ 21 ║ 22 ║ |
| 3556 |
╠════╩══╦═╩══╦═╩══╦═╩══╦═╩══╦═╩══╦═╩══╦═╩══╦═╩══╦═╩══╦═╩══╦═╩══╦═╩══╦══════╣ |
| 3557 |
║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ |
| 3558 |
║ 23 ║ 24 ║ 25 ║ 26 ║ 27 ║ 28 ║ 29 ║ 30 ║ 31 ║ 32 ║ 33 ║ 34 ║ 35 ║ 51 ║ |
| 3559 |
╠═══════╩═╦══╩═╦══╩═╦══╩═╦══╩═╦══╩═╦══╩═╦══╩═╦══╩═╦══╩═╦══╩═╦══╩═╦══╩══════╣ |
| 3560 |
║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ |
| 3561 |
║ 66 ║ 38 ║ 39 ║ 40 ║ 41 ║ 42 ║ 43 ║ 44 ║ 45 ║ 46 ║ 47 ║ 48 ║ 36 ║ |
| 3562 |
╠═════════╩═══╦╩═══╦╩═══╦╩═══╦╩═══╦╩═══╦╩═══╦╩═══╦╩═══╦╩═══╦╩═══╦╩═════════╣ |
| 3563 |
║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ |
| 3564 |
║ 50 ║ 52 ║ 53 ║ 54 ║ 55 ║ 56 ║ 57 ║ 58 ║ 59 ║ 60 ║ 61 ║ 62 ║ |
| 3565 |
╠════╦═════╦══╩══╦═╩════╩════╩════╩════╩════╩════╩══╦═╩═══╦╩════╬═════╦════╣ |
| 3566 |
║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ |
| 3567 |
║ 37 ║115 ║ 64 ║ 65 ║113 ║116 ║ 109 ║105 ║ |
| 3568 |
╚════╩═════╩═════╩══════════════════════════════════╩═════╩═════╩═════╩════╝ |
| 3569 |
|
| 3570 |
Keyboard Layout. Source: xmodmap -pke |
| 3571 |
|
| 3572 |
╔════╦════╦════╦════╦════╦════╦════╦════╦════╦════╦════╦════╦════╦═════════╗ |
| 3573 |
║ ~ ║ !⌶ ║ " ║ #⍒ ║ $⍋ ║ %⌽ ║ ^⍉ ║ &⊖ ║ *⍟ ║ (⍱ ║ )⍲ ║ _! ║ +⌹ ║ ║ |
| 3574 |
║ `◊ ║ 1¨ ║ 2⍫ ║ 3< ║ 4≤ ║ 5= ║ 6≥ ║ 7> ║ 8≠ ║ 9∨ ║ 0∧ ║ -× ║ =÷ ║ BACKSP ║ |
| 3575 |
╠════╩══╦═╩══╦═╩══╦═╩══╦═╩══╦═╩══╦═╩══╦═╩══╦═╩══╦═╩══╦═╩══╦═╩══╦═╩══╦══════╣ |
| 3576 |
║ ║ Q ║ W⍹ ║ E⋸ ║ R ║ T⍨ ║ Y¥ ║ U ║ I⍸ ║ O⍥ ║ P⍣ ║ {⍞ ║ }⍬ ║ |⊣ ║ |
| 3577 |
║ TAB ║ q? ║ w⍵ ║ e∈ ║ r⍴ ║ t∼ ║ y↑ ║ u↓ ║ i⍳ ║ o○ ║ p⋆ ║ [← ║ ]→ ║ \⊢ ║ |
| 3578 |
╠═══════╩═╦══╩═╦══╩═╦══╩═╦══╩═╦══╩═╦══╩═╦══╩═╦══╩═╦══╩═╦══╩═╦══╩═╦══╩══════╣ |
| 3579 |
║ (CAPS ║ A⍶ ║ S ║ D ║ F ║ G ║ H⍙ ║ J⍤ ║ K ║ L⌷ ║ *≡ ║ "≢ ║ ║ |
| 3580 |
║ LOCK) ║ a⍺ ║ s⌈ ║ d⌊ ║ f_ ║ g∇ ║ h∆ ║ j∘ ║ kλ ║ l⎕ ║ +⍎ ║ '⍕ ║ RETURN ║ |
| 3581 |
╠═════════╩═══╦╩═══╦╩═══╦╩═══╦╩═══╦╩═══╦╩═══╦╩═══╦╩═══╦╩═══╦╩═══╦╩═════════╣ |
| 3582 |
║ ║ Z ║ Xχ ║ C¢ ║ V ║ B£ ║ N ║ Mμ ║ <⍪ ║ >⍙ ║ ?⍠ ║ ║ |
| 3583 |
║ SHIFT ║ z⊂ ║ x⊃ ║ c∩ ║ v∪ ║ b⊥ ║ n⊤ ║ m∣ ║ ,⍝ ║ .⍀ ║ /⌿ ║ SHIFT ║ |
| 3584 |
╠════╦═════╦══╩══╦═╩════╩════╩════╩════╩════╩════╩══╦═╩═══╦╩════╬═════╦════╣ |
| 3585 |
║ ║ ║ ║ ║ ║ ║ !⌶ ║ ║ |
| 3586 |
║CTRL║ Win ║ ALT ║ SPACE ║ ALT ║ Win ║ 1¨9 ║CTRL║ |
| 3587 |
╚════╩═════╩═════╩══════════════════════════════════╩═════╩═════╩═════╩════╝ |
| 3588 |
</pre></div> |
| 3589 |
|
| 3590 |
<p>Argument <b>KPAD</b> also shows the keypad of the keyboard. The keypad is normally |
| 3591 |
hidden so that the output fits into a 80-column terminal window. With <b>KPAD</b> |
| 3592 |
the terminal should have at least 101 columns. The standard GNU APL layout puts |
| 3593 |
line graphics characters onto the keypad, as well as « and » and some |
| 3594 |
currency symbols. |
| 3595 |
</p> |
| 3596 |
<p>Argument <b>FUNK</b> also shows the function key row of the keyboard, but |
| 3597 |
only for <b>]KEYB XMOD KEYS</b>: |
| 3598 |
</p> |
| 3599 |
<div class="example"> |
| 3600 |
<pre class="example"> ]KEYB XMOD KEYS FUNK KPAD |
| 3601 |
US Keyboard Layout. Source: GNU APL builtin |
| 3602 |
|
| 3603 |
╔════╗ ╔════╦════╦════╦════╗ ╔════╦════╦════╦════╗ ╔════╦════╦════╦════╗ ╔════╦════╦════╗ |
| 3604 |
║ Kc ║ ║ Kc ║ Kc ║ Kc ║ Kc ║ ║ Kc ║ Kc ║ Kc ║ Kc ║ ║ Kc ║ Kc ║ Kc ║ Kc ║ ║ ║ Kc ║ Kc ║ |
| 3605 |
║ 09 ║ ║ 67 ║ 68 ║ 69 ║ 70 ║ ║ 71 ║ 72 ║ 73 ║ 74 ║ ║ 75 ║ 76 ║ 95 ║ 96 ║ ║ ║ 78 ║ 77 ║ |
| 3606 |
╚════╝ ╚════╩════╩════╩════╝ ╚════╩════╩════╩════╝ ╚════╩════╩════╩════╝ ╚════╩════╩════╝ |
| 3607 |
|
| 3608 |
╔════╦════╦════╦════╦════╦════╦════╦════╦════╦════╦════╦════╦════╦═════════╗ ╔════╦════╦════╦════╗ |
| 3609 |
║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ ║ Kc ║ ║ Kc ║ Kc ║ |
| 3610 |
║ 49 ║ 10 ║ 11 ║ 12 ║ 13 ║ 14 ║ 15 ║ 16 ║ 17 ║ 18 ║ 19 ║ 20 ║ 21 ║ 22 ║ ║ 77 ║ ║ 82 ║ 82 ║ |
| 3611 |
╠════╩══╦═╩══╦═╩══╦═╩══╦═╩══╦═╩══╦═╩══╦═╩══╦═╩══╦═╩══╦═╩══╦═╩══╦═╩══╦══════╣ ╠════╬════╬════╬════╣ |
| 3612 |
║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ ║ Kc ║ Kc ║ Kc ║ ║ |
| 3613 |
║ 23 ║ 24 ║ 25 ║ 26 ║ 27 ║ 28 ║ 29 ║ 30 ║ 31 ║ 32 ║ 33 ║ 34 ║ 35 ║ 51 ║ ║ 79 ║ 80 ║ 81 ║ Kc ║ |
| 3614 |
╠═══════╩═╦══╩═╦══╩═╦══╩═╦══╩═╦══╩═╦══╩═╦══╩═╦══╩═╦══╩═╦══╩═╦══╩═╦══╩══════╣ ╠════╬════╬════╣ 86 ║ |
| 3615 |
║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ ║ Kc ║ Kc ║ Kc ║ ║ |
| 3616 |
║ 66 ║ 38 ║ 39 ║ 40 ║ 41 ║ 42 ║ 43 ║ 44 ║ 45 ║ 46 ║ 47 ║ 48 ║ 36 ║ ║ 83 ║ 84 ║ 85 ║ ║ |
| 3617 |
╠═════════╩═══╦╩═══╦╩═══╦╩═══╦╩═══╦╩═══╦╩═══╦╩═══╦╩═══╦╩═══╦╩═══╦╩═════════╣ ╠════╬════╬════╬════╣ |
| 3618 |
║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ ║ Kc ║ Kc ║ Kc ║ ║ |
| 3619 |
║ 50 ║ 52 ║ 53 ║ 54 ║ 55 ║ 56 ║ 57 ║ 58 ║ 59 ║ 60 ║ 61 ║ 62 ║ ║ 87 ║ 88 ║ 89 ║ Kc ║ |
| 3620 |
╠════╦═════╦══╩══╦═╩════╩════╩════╩════╩════╩════╩══╦═╩═══╦╩════╬═════╦════╣ ╠════╩════╬════╣108 ║ |
| 3621 |
║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ Kc ║ ║ Kc ║ ║ ║ |
| 3622 |
║ 37 ║115 ║ 64 ║ 65 ║113 ║116 ║ 109 ║105 ║ ║ 90 ║ ║ ║ |
| 3623 |
╚════╩═════╩═════╩══════════════════════════════════╩═════╩═════╩═════╩════╝ ╚═════════╩════╩════╝ |
| 3624 |
|
| 3625 |
</pre></div> |
| 3626 |
|
| 3627 |
<p>As the <b>Source: GNU APL builtin</b> in the example above indicates, this is |
| 3628 |
the layout assumed by GNU APL, which may differ from the true layout of your |
| 3629 |
keybord. For example, say key <b>R</b> with ALT pressed does not produce <b>⍴</b>. |
| 3630 |
The Unicode for <b>⍴</b> is : |
| 3631 |
</p> |
| 3632 |
<div class="example"> |
| 3633 |
<pre class="example"> ⎕UCS "⍴" ⍝ Unicode for ⍴ |
| 3634 |
9076 |
| 3635 |
,5 ⎕CR 256 256 ⊤ ⎕UCS "⍴" ⍝ Unicode for ⍴ in hex |
| 3636 |
2374 |
| 3637 |
</pre></div> |
| 3638 |
|
| 3639 |
<p>One can check if the keycodes displayed by <b>]KEYB XMOD KEYS</b> are |
| 3640 |
correct with a programm called <b>xev</b> (which is normally pre-installed in |
| 3641 |
most GNU/Linux distributions. After starting <b>xev</b> and hitting the <b>R</b> |
| 3642 |
key several times (because it also shows many other unrelated events), |
| 3643 |
one can see the corresponding key events: |
| 3644 |
</p> |
| 3645 |
<div class="example"> |
| 3646 |
<pre class="example"> ... |
| 3647 |
KeyPress event, serial 38, synthetic NO, window 0x3c00001, |
| 3648 |
root 0x75c, subw 0x0, time 35629183, (-590,275), root:(284,737), |
| 3649 |
state 0x0, keycode 27 (keysym 0x72, r), same_screen YES, |
| 3650 |
XLookupString gives 1 bytes: (72) "r" |
| 3651 |
XmbLookupString gives 1 bytes: (72) "r" |
| 3652 |
XFilterEvent returns: False |
| 3653 |
</pre></div> |
| 3654 |
|
| 3655 |
<p>So we see that the <b>R</b> key does indeed have the keycode <b>27</b>. |
| 3656 |
Next we look at the line for key keycode <b>27</b> in the <b>xmodmap.apl</b> |
| 3657 |
file: |
| 3658 |
</p> |
| 3659 |
<div class="example"> |
| 3660 |
<pre class="example">keycode 27 = r R U2374 |
| 3661 |
</pre></div> |
| 3662 |
|
| 3663 |
<p>This line tells us that, when the <b>R</b> is hit, the following |
| 3664 |
Unicodes shall be emitted: |
| 3665 |
</p> |
| 3666 |
<ul> |
| 3667 |
<li> the Unicode for (lowercase) <b>r</b> if neither SHIFT nor ALT is held down, |
| 3668 |
</li><li> the Unicode for (uppercase) <b>R</b> if SHIFT is pressed and ALT is not, |
| 3669 |
</li><li> the Unicode for <b>⍴</b> = $2374 if ALT is pressed and SHIFT is not. |
| 3670 |
</li></ul> |
| 3671 |
|
| 3672 |
<p>The line could have had a fourth entry (for SHIFT and ALT pressed); if that |
| 3673 |
entry is, like above, missing then the same Unicode is emitted for both |
| 3674 |
ALT and SHIFT+ALT. Likewise, if the second entry is missing then the same |
| 3675 |
code is used for SHIFT and no SHIFT. This is, for example, the case for |
| 3676 |
keycode 36 with keysym <b>Return</b> (the key that is sometimes labelled |
| 3677 |
<b>Enter</b> and sometimes <b>Return</b> and whose keysym is independent of the |
| 3678 |
state of the SHIFT and ALT keys. In the xmodmap the keysyms can be specified |
| 3679 |
in multiple ways: as ASCII characters (like <b>r</b> and <b>R</b> above, as |
| 3680 |
Unicodes like <b>U2374</b> above, or as symbols like <b>NoSymbol</b> or <b>Return</b>, |
| 3681 |
which are defined in files <b>/usr/include/X11/X.h</b> and |
| 3682 |
<b>/usr/include/X11/keysymdef.h</b>: |
| 3683 |
</p> |
| 3684 |
<div class="example"> |
| 3685 |
<pre class="example">#define NoSymbol 0L /* special KeySym */ |
| 3686 |
#define XK_Return 0xff0d /* Return, enter */ |
| 3687 |
</pre></div> |
| 3688 |
|
| 3689 |
<p>Given the explanations above, the troubleshooting of keyboard mappings |
| 3690 |
becomes simple (though somewhat tedious in the details): |
| 3691 |
</p> |
| 3692 |
<ol> |
| 3693 |
<li> do <b>]KEYB XMOD KEYS</b> in GNU APL to display the keycodes, then |
| 3694 |
</li><li> run <b>xev</b> in a different window and verify, for every key on |
| 3695 |
the keyboard, that the keycode shown by <b>xev</b> is the one shown by |
| 3696 |
<b>]KEYB XMOD KEYS</b>, then |
| 3697 |
</li><li> do <b>]KEYB XMOD</b> in GNU APL to display the keysyms, then |
| 3698 |
</li><li> edit the <b>xmodmap.apl</b> file (or whatever other file ws used |
| 3699 |
as the argument for the <b>xmondmap</b> command) to see if the Unicodes |
| 3700 |
for every keycode line are correct. In that test: |
| 3701 |
<ul> |
| 3702 |
<li> the first keysym is used for the lowercase character, i.e. if |
| 3703 |
neither SHIFT nor ALT are pressed, |
| 3704 |
</li><li> the second keysym is used for the uppercase character, i.e. if |
| 3705 |
SHIFT is pressed and ALT is not. If no second keysym is present, |
| 3706 |
then the first keysym is used instead, |
| 3707 |
</li><li> the third keysym is used for the character that shall be emitted |
| 3708 |
when the ALT key is pressed and the SHIFT is not. If no third |
| 3709 |
keysym is present then nothing is emitted, and |
| 3710 |
</li><li> the fourth keysym is used for the character that shall be emitted |
| 3711 |
when both the ALT key and the SHIFT are pressed. If no fourth |
| 3712 |
keysym is present then the behavior is the same as for ALT |
| 3713 |
without SHIFT. |
| 3714 |
</li></ul> |
| 3715 |
</li></ol> |
| 3716 |
|
| 3717 |
<hr> |
| 3718 |
</div> |
| 3719 |
</div> |
| 3720 |
</div> |
| 3721 |
<div class="section" id="g_t_005dNEXTFILE-and-_005dPUSHFILE-Commands"> |
| 3722 |
<div class="header"> |
| 3723 |
<p> |
| 3724 |
Next: <a href="#History-and-TAB-completion" accesskey="n" rel="next">History and TAB completion</a>, Previous: <a href="#g_t_005dKEYB-Command" accesskey="p" rel="prev">]KEYB Command</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 3725 |
</div> |
| 3726 |
<span id="g_t_005dNEXTFILE-and-_005dPUSHFILE-Commands-1"></span><h3 class="section">2.12 ]NEXTFILE and ]PUSHFILE Commands</h3> |
| 3727 |
|
| 3728 |
<ul class="section-toc"> |
| 3729 |
<li><a href="#g_t_005dNEXTFILE" accesskey="1">]NEXTFILE</a></li> |
| 3730 |
<li><a href="#g_t_005dPUSHFILE" accesskey="2">]PUSHFILE</a></li> |
| 3731 |
</ul> |
| 3732 |
<hr> |
| 3733 |
<div class="subsection" id="g_t_005dNEXTFILE"> |
| 3734 |
<div class="header"> |
| 3735 |
<p> |
| 3736 |
Next: <a href="#g_t_005dPUSHFILE" accesskey="n" rel="next">]PUSHFILE</a>, Up: <a href="#g_t_005dNEXTFILE-and-_005dPUSHFILE-Commands" accesskey="u" rel="up">]NEXTFILE and ]PUSHFILE Commands</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 3737 |
</div> |
| 3738 |
<span id="g_t_005dNEXTFILE-1"></span><h4 class="subsection">2.12.1 ]NEXTFILE</h4> |
| 3739 |
|
| 3740 |
<p>The debug command ]NEXTFILE, when used in an APL script file, terminates |
| 3741 |
the processing of that file and continues processing in the next script file |
| 3742 |
(if any) or else enters immediate execution mode. Unlike )OFF (which terminates |
| 3743 |
the interpreter), ]NEXTFILE does not terminate the interpreter but only changes |
| 3744 |
its input source to the next script file (if there is one remaining) and enters |
| 3745 |
immediate execution only if all scripts were processed. |
| 3746 |
</p> |
| 3747 |
<p>The user may, for example, want to use the space near the end of the script |
| 3748 |
to add longer comments (as to what the script does, how it works, how it is |
| 3749 |
used, etc.) without the need to prepend every line with ⍝ or #. |
| 3750 |
</p> |
| 3751 |
<p>For example: |
| 3752 |
</p> |
| 3753 |
<div class="example"> |
| 3754 |
<pre class="example">#!/usr/local/bin/apl |
| 3755 |
|
| 3756 |
⍝ see documentation at the end of this file |
| 3757 |
|
| 3758 |
<APL CODE...> |
| 3759 |
|
| 3760 |
]NEXTFILE |
| 3761 |
|
| 3762 |
This workspace does the following... |
| 3763 |
</pre></div> |
| 3764 |
|
| 3765 |
|
| 3766 |
<hr> |
| 3767 |
</div> |
| 3768 |
<div class="subsection" id="g_t_005dPUSHFILE"> |
| 3769 |
<div class="header"> |
| 3770 |
<p> |
| 3771 |
Previous: <a href="#g_t_005dNEXTFILE" accesskey="p" rel="prev">]NEXTFILE</a>, Up: <a href="#g_t_005dNEXTFILE-and-_005dPUSHFILE-Commands" accesskey="u" rel="up">]NEXTFILE and ]PUSHFILE Commands</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 3772 |
</div> |
| 3773 |
<span id="g_t_005dPUSHFILE-1"></span><h4 class="subsection">2.12.2 ]PUSHFILE</h4> |
| 3774 |
|
| 3775 |
<p>The debug command ]PUSHFILE is similar to ]NEXTFILE in that it terminates |
| 3776 |
the processing of the current script file. Unlike ]NEXTFILE, ]PUSHFILE does |
| 3777 |
not proceed to the next script file but enters a new immediate execution |
| 3778 |
context in which the user can interact with the interpreter. This context |
| 3779 |
processes user input until a ]NEXTFILE command is given. After a ]NEXTFILE |
| 3780 |
command, the immediate execution context processing proceeds at the next |
| 3781 |
line after the ]PUSHFILE command. |
| 3782 |
</p> |
| 3783 |
<hr> |
| 3784 |
</div> |
| 3785 |
</div> |
| 3786 |
<div class="section" id="History-and-TAB-completion"> |
| 3787 |
<div class="header"> |
| 3788 |
<p> |
| 3789 |
Next: <a href="#Logging-Facilities" accesskey="n" rel="next">Logging Facilities</a>, Previous: <a href="#g_t_005dNEXTFILE-and-_005dPUSHFILE-Commands" accesskey="p" rel="prev">]NEXTFILE and ]PUSHFILE Commands</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 3790 |
</div> |
| 3791 |
<span id="History-and-TAB-completion-1"></span><h3 class="section">2.13 History and TAB completion</h3> |
| 3792 |
|
| 3793 |
<p>Until GNU APL 1.4 / SVN 465, GNU APL used libreadline for interactive user |
| 3794 |
input. libreadline did provide two useful features: tab expansion (the tab |
| 3795 |
key would expand file names) and history (the cursor up/down keys would recall |
| 3796 |
previously entered lines). |
| 3797 |
</p> |
| 3798 |
<p>Since SVN 465 libreadline was removed and the standard TAB expansion and |
| 3799 |
history of libreadline were replaced by more context sensitive (i.e. APL |
| 3800 |
aware) implementations: |
| 3801 |
</p> |
| 3802 |
<p>1. Instead of simply recalling the last line entered by the user, there are |
| 3803 |
now different histories for different input contexts: |
| 3804 |
</p> |
| 3805 |
<p>1a. The input history in immediate execution recalls the last line entered |
| 3806 |
in immediate execution (and not, for example, lines entered in function |
| 3807 |
editing mode or ⍞ input. |
| 3808 |
</p> |
| 3809 |
<p>1b. Likewise, ⍞ recalls the last line entered for ⍞-input |
| 3810 |
</p> |
| 3811 |
<p>1c. ⎕ recalls the last line entered for ⎕-input |
| 3812 |
</p> |
| 3813 |
<p>1d. In the ∇-editor, the other function lines of the function being edited |
| 3814 |
can be recalled. This is far more handy than the ∇-editor commands for |
| 3815 |
recalling function lines (which are not fully supported in GNU APL). |
| 3816 |
</p> |
| 3817 |
<p>2. Instead of always TAB-completing file names, the tab character now |
| 3818 |
understands different TAB-completion contexts: |
| 3819 |
</p> |
| 3820 |
<p>2a. Input starting with . or / is completed as a filename like readline did. |
| 3821 |
</p> |
| 3822 |
<p>2b. Input starting with ) or ] is completed as command-name name or, to some |
| 3823 |
extent, as command arguments. |
| 3824 |
</p> |
| 3825 |
<p>2c. Input starting with ⎕ is completed as a system function name or a |
| 3826 |
system variable name. |
| 3827 |
</p> |
| 3828 |
<p>2d. Input starting with letters, ∆, or ⍙ is completed as a user defined |
| 3829 |
function or variable name. |
| 3830 |
</p> |
| 3831 |
|
| 3832 |
<hr> |
| 3833 |
</div> |
| 3834 |
<div class="section" id="Logging-Facilities"> |
| 3835 |
<div class="header"> |
| 3836 |
<p> |
| 3837 |
Next: <a href="#Rational-Numbers" accesskey="n" rel="next">Rational Numbers</a>, Previous: <a href="#History-and-TAB-completion" accesskey="p" rel="prev">History and TAB completion</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 3838 |
</div> |
| 3839 |
<span id="Logging-Facilities-1"></span><h3 class="section">2.14 Logging Facilities</h3> |
| 3840 |
|
| 3841 |
<p>The APL interpreter has over 30 logging facilities. Each logging facility |
| 3842 |
can be ON (and then produces some logging output on stderr) or OFF. The |
| 3843 |
decision which logging facility shall be ON and which shall be OFF can be |
| 3844 |
made at compile time (of the APL interpreter) or at run-time. |
| 3845 |
</p> |
| 3846 |
<p>If the decision is made at compile time - we call that static logging - then |
| 3847 |
it cannot be changed later on. Otherwise - we call that dynamic logging - |
| 3848 |
there is a debug command ]LOG that allows logging facilities to be turned |
| 3849 |
ON or OFF. |
| 3850 |
</p> |
| 3851 |
<ul class="section-toc"> |
| 3852 |
<li><a href="#Static-Logging" accesskey="1">Static Logging</a></li> |
| 3853 |
<li><a href="#Dynamic-Logging" accesskey="2">Dynamic Logging</a></li> |
| 3854 |
</ul> |
| 3855 |
<hr> |
| 3856 |
<div class="subsection" id="Static-Logging"> |
| 3857 |
<div class="header"> |
| 3858 |
<p> |
| 3859 |
Next: <a href="#Dynamic-Logging" accesskey="n" rel="next">Dynamic Logging</a>, Up: <a href="#Logging-Facilities" accesskey="u" rel="up">Logging Facilities</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 3860 |
</div> |
| 3861 |
<span id="Static-Logging-1"></span><h4 class="subsection">2.14.1 Static Logging</h4> |
| 3862 |
|
| 3863 |
<p>By default the logging facilities that shall be turned ON are defined |
| 3864 |
statically. To change the logging facilities that shall be turned ON, |
| 3865 |
you can edit the file src/Logging.def which defines the different logging |
| 3866 |
facilities. The first argument of macro log_def() specifies that the |
| 3867 |
indicated logging facility shall be ON (1) or OFF (0). |
| 3868 |
</p> |
| 3869 |
<p>Static logging results in a faster interpreter than dynamic logging because |
| 3870 |
the decision to log something is made at compile time and not at run-time. |
| 3871 |
</p> |
| 3872 |
<p>If you benchmark the APL interpreter, then ./configure Static Logging by |
| 3873 |
NOT setting DYNAMIC_LOG_WANTED=yes. |
| 3874 |
</p> |
| 3875 |
<hr> |
| 3876 |
</div> |
| 3877 |
<div class="subsection" id="Dynamic-Logging"> |
| 3878 |
<div class="header"> |
| 3879 |
<p> |
| 3880 |
Previous: <a href="#Static-Logging" accesskey="p" rel="prev">Static Logging</a>, Up: <a href="#Logging-Facilities" accesskey="u" rel="up">Logging Facilities</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 3881 |
</div> |
| 3882 |
<span id="Dynamic-Logging-1"></span><h4 class="subsection">2.14.2 Dynamic Logging</h4> |
| 3883 |
|
| 3884 |
<p>Dynamic Logging is intended for trouble-shooters of GNU APL, but also for |
| 3885 |
those who are interested in the internals of GNU APL. Dynamic Logging is |
| 3886 |
enabled by setting DYNAMIC_LOG_WANTED=yes when running ./configure. |
| 3887 |
</p> |
| 3888 |
<p>If Dynamic Logging is enabled, then the already mentioned file |
| 3889 |
src/Logging.def determines the initial setting of each logging facility. |
| 3890 |
</p> |
| 3891 |
<p>The command |
| 3892 |
</p> |
| 3893 |
<p>]LOG |
| 3894 |
</p> |
| 3895 |
<p>(without arguments) then shows all logging facilities and their current |
| 3896 |
state. The command |
| 3897 |
</p> |
| 3898 |
<p>]LOG N |
| 3899 |
</p> |
| 3900 |
<p>toggles the state of logging facility N from OFF to ON and back. |
| 3901 |
</p> |
| 3902 |
|
| 3903 |
<hr> |
| 3904 |
</div> |
| 3905 |
</div> |
| 3906 |
<div class="section" id="Rational-Numbers"> |
| 3907 |
<div class="header"> |
| 3908 |
<p> |
| 3909 |
Next: <a href="#Hex-Numbers" accesskey="n" rel="next">Hex Numbers</a>, Previous: <a href="#Logging-Facilities" accesskey="p" rel="prev">Logging Facilities</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 3910 |
</div> |
| 3911 |
<span id="Rational-Numbers-1"></span><h3 class="section">2.15 Rational Numbers</h3> |
| 3912 |
|
| 3913 |
<p>GNU APL has limited support for rational numbers. Instead of dividing integers |
| 3914 |
(and possibly causing rounding errors), integer quotients are kept undivided |
| 3915 |
internally until some function requires a conversion to a floating point |
| 3916 |
(double) value. |
| 3917 |
</p> |
| 3918 |
<p>Currently only +, -, ×, and ÷ preserve rational numbers where possible, but |
| 3919 |
this list may grow in the future. Monadic + (a no-op for non-complex numbers) |
| 3920 |
explicitly converts rational numbers to floating point numbers. |
| 3921 |
</p> |
| 3922 |
<p>A quotient is internally stored as a 64-bit numerator and a 64-bit denominator. |
| 3923 |
In some cases arithmetic with rational numbers is faster than with doubles, but |
| 3924 |
in most cases it is slower. |
| 3925 |
</p> |
| 3926 |
<p>For that reason support for rational numbers is disabled by default and must |
| 3927 |
be enabled via ./configure (see README-2-configure). |
| 3928 |
</p> |
| 3929 |
|
| 3930 |
<hr> |
| 3931 |
</div> |
| 3932 |
<div class="section" id="Hex-Numbers"> |
| 3933 |
<div class="header"> |
| 3934 |
<p> |
| 3935 |
Next: <a href="#User_002ddefined-Commands" accesskey="n" rel="next">User-defined Commands</a>, Previous: <a href="#Rational-Numbers" accesskey="p" rel="prev">Rational Numbers</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 3936 |
</div> |
| 3937 |
<span id="Hex-Numbers-1"></span><h3 class="section">2.16 Hex Numbers</h3> |
| 3938 |
|
| 3939 |
<p>GNU APL supports sedecimal numbers. They start with $ and can be uppercase or |
| 3940 |
lowercase: |
| 3941 |
</p> |
| 3942 |
<div class="example"> |
| 3943 |
<pre class="example"> $2a |
| 3944 |
42 |
| 3945 |
|
| 3946 |
$2A |
| 3947 |
42 |
| 3948 |
</pre></div> |
| 3949 |
|
| 3950 |
|
| 3951 |
<hr> |
| 3952 |
</div> |
| 3953 |
<div class="section" id="User_002ddefined-Commands"> |
| 3954 |
<div class="header"> |
| 3955 |
<p> |
| 3956 |
Next: <a href="#Structured-Variables-and-Associative-Arrays" accesskey="n" rel="next">Structured Variables and Associative Arrays</a>, Previous: <a href="#Hex-Numbers" accesskey="p" rel="prev">Hex Numbers</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 3957 |
</div> |
| 3958 |
<span id="User_002ddefined-Commands-1"></span><h3 class="section">2.17 User-defined Commands</h3> |
| 3959 |
|
| 3960 |
<p>There is a simple mechanism to define additional APL commands. This mechanism |
| 3961 |
is intended to introduce new commands by APL libraries. Like system commands, |
| 3962 |
user-define commands can only be executed in immediate execution mode and not |
| 3963 |
from user-defined functions or from ⍎. It is not intended to extend the |
| 3964 |
functionality of user-defined commands beyond what is being described in the |
| 3965 |
following. |
| 3966 |
</p> |
| 3967 |
<p>A user-defined command ]NEW_COMMAND is created with the debug command |
| 3968 |
]USERCMD like this: |
| 3969 |
</p> |
| 3970 |
<div class="example"> |
| 3971 |
<pre class="example"> ]USERCMD ]NEW_COMMAND APL_FUNCTION [mode] |
| 3972 |
</pre></div> |
| 3973 |
|
| 3974 |
<p>APL_FUNCTION is an APL function that will be called when the command is |
| 3975 |
entered in immediate execution mode. The entire line entered by the user, |
| 3976 |
starting at ]NEW_COMMAND, is the right argument of APL_FUNCTION. If mode is |
| 3977 |
missing (or 0) then APL_FUNCTION is called monadically. If mode is 1 then |
| 3978 |
APL_FUNCTION is called dyadically; the left argument is a vector of strings |
| 3979 |
that is the left argument broken down into individual argument strings. |
| 3980 |
</p> |
| 3981 |
<p>The function APL_FUNCTION that implements a command need not exist when the |
| 3982 |
command is created. |
| 3983 |
</p> |
| 3984 |
<p>A single user-defined command ]UCMD, or all user-defined commands can |
| 3985 |
be deleted like this: |
| 3986 |
</p> |
| 3987 |
<div class="example"> |
| 3988 |
<pre class="example"> ]USERCMD REMOVE ]UCMD |
| 3989 |
]USERCMD REMOVE-ALL |
| 3990 |
</pre></div> |
| 3991 |
|
| 3992 |
<hr> |
| 3993 |
</div> |
| 3994 |
<div class="section" id="Structured-Variables-and-Associative-Arrays"> |
| 3995 |
<div class="header"> |
| 3996 |
<p> |
| 3997 |
Next: <a href="#Monadic-_22a2-and-_22a3_003b-dyadic-_22a2-with-Axis" accesskey="n" rel="next">Monadic ⊢ and ⊣; dyadic ⊢ with Axis</a>, Previous: <a href="#User_002ddefined-Commands" accesskey="p" rel="prev">User-defined Commands</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 3998 |
</div> |
| 3999 |
<span id="Structured-Variables-and-Associative-Arrays-1"></span><h3 class="section">2.18 Structured Variables and Associative Arrays</h3> |
| 4000 |
|
| 4001 |
<p>GNU APL has implemented two features that are closely related because, under |
| 4002 |
the hood, they share the same implementation: <b>structured variables</b> and |
| 4003 |
<b>associative arrays</b>. |
| 4004 |
</p> |
| 4005 |
<ul class="section-toc"> |
| 4006 |
<li><a href="#Structured-Variables" accesskey="1">Structured Variables</a></li> |
| 4007 |
<li><a href="#Associative-Arrays" accesskey="2">Associative Arrays</a></li> |
| 4008 |
</ul> |
| 4009 |
<hr> |
| 4010 |
<div class="subsection" id="Structured-Variables"> |
| 4011 |
<div class="header"> |
| 4012 |
<p> |
| 4013 |
Next: <a href="#Associative-Arrays" accesskey="n" rel="next">Associative Arrays</a>, Up: <a href="#Structured-Variables-and-Associative-Arrays" accesskey="u" rel="up">Structured Variables and Associative Arrays</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 4014 |
</div> |
| 4015 |
<span id="Structured-Variables-1"></span><h4 class="subsection">2.18.1 Structured Variables</h4> |
| 4016 |
|
| 4017 |
<p>A structured variable is an APL variable that contains several related but |
| 4018 |
otherwise independent sub-variables aka. <b>members</b>. Such structured variables |
| 4019 |
can be convenient for passing many related arguments to a function, or |
| 4020 |
for returning multiple results from a function. |
| 4021 |
</p> |
| 4022 |
<p>The different sub-variables of a structured variable are accessed by the |
| 4023 |
(top-level) name of the variable followed by a non-empty sequence of member |
| 4024 |
names, separated by ’.’. In the following we will use uppercase names for |
| 4025 |
structured variables and lowercase names for their members. For example: |
| 4026 |
</p> |
| 4027 |
<div class="example"> |
| 4028 |
<pre class="example"> PERSON.address.street |
| 4029 |
</pre></div> |
| 4030 |
|
| 4031 |
<p>is a structured variable <b>PERSON</b>, which has a member <b>address</b>, |
| 4032 |
and <b>PERSON.address</b> is a structured (sub-)variable of PERSON which has |
| 4033 |
a member <b>street</b>. |
| 4034 |
</p> |
| 4035 |
<p>For a structured variable and all its sub-variables, the usual rules for |
| 4036 |
normal variables apply. They can be created, erased, and even passed as |
| 4037 |
arguments to functions. <b>Nota bene</b>: Some GNU APL operators are implemented |
| 4038 |
as macros (i.e. internal defined APL functions). The macros may call APL |
| 4039 |
primitives that invalidate the fact that a value is structured and, as a |
| 4040 |
consequence, the operator results may become plain APL values. If this happens, |
| 4041 |
the structured nature of a plain APL value can be restored with 38 ⎕CR. |
| 4042 |
</p> |
| 4043 |
<p>A structured variable is created by assigning a value to one of its members. |
| 4044 |
For example: |
| 4045 |
</p> |
| 4046 |
<div class="example"> |
| 4047 |
<pre class="example"> PERSON.firstname ← 'Jane' ⍝ create variable PERSON with member 'firstname' |
| 4048 |
PERSON.lastname ← 'Doe' ⍝ add a second member 'lastname' to PERSON |
| 4049 |
</pre></div> |
| 4050 |
|
| 4051 |
<p>The depth of a newly created member can be more than one. In this case the |
| 4052 |
intermediate members are created automatically. For example: |
| 4053 |
</p> |
| 4054 |
<div class="example"> |
| 4055 |
<pre class="example"> PERSON.address.street ← '42 Main Street' ⍝ implicitly creates PERSON.address |
| 4056 |
</pre></div> |
| 4057 |
|
| 4058 |
<p>Empty structured variables can be created with <b>38 ⎕CR</b>: |
| 4059 |
</p> |
| 4060 |
<div class="example"> |
| 4061 |
<pre class="example"> EMPTY ← 38 ⎕CR CAPACITY ← 32 |
| 4062 |
</pre></div> |
| 4063 |
|
| 4064 |
<p>Note: A structured variable is automatically expanded when new members are |
| 4065 |
added to it. From time to time this expansion exceeds the space allocated |
| 4066 |
for the members of the variable and then the existing members need to be |
| 4067 |
copied into a new, larger structure. The overhead caused by this reorganization |
| 4068 |
can be avoided by specifying a sufficiently large capacity when the structure |
| 4069 |
is created (with <b>38 ⎕CR</b>). |
| 4070 |
</p> |
| 4071 |
<p>An entire structured variable can be erased with <b>⎕EX</b> or with |
| 4072 |
<b>)ERASE</b> just like other variables. They erase the variable along |
| 4073 |
with all its members. In addition to erasing an entire structured variable, |
| 4074 |
individual members at any depth can also be erased with <b>⎕EX</b> or |
| 4075 |
<b>)ERASE</b>: |
| 4076 |
</p> |
| 4077 |
<div class="example"> |
| 4078 |
<pre class="example"> )ERASE PERSON.address ⍝ OK, PERSON.address exists |
| 4079 |
)ERASE PERSON.address ⍝ error: PERSON.address does not exist anymore |
| 4080 |
NOT ERASED: PERSON.address |
| 4081 |
</pre></div> |
| 4082 |
|
| 4083 |
<p>After having been created, the members of a structured variable can be |
| 4084 |
referenced and overwritten just like normal variables: |
| 4085 |
</p> |
| 4086 |
<div class="example"> |
| 4087 |
<pre class="example"> PERSON.address.street ← '42 Main Street' ⍝ create member address.street |
| 4088 |
PERSON.address.street ⍝ reference member address.street of PERSON |
| 4089 |
42 Main Street |
| 4090 |
|
| 4091 |
PERSON.address.street ← '44 Main Street' ⍝ overwrite address.street |
| 4092 |
PERSON.address.street |
| 4093 |
44 Main Street |
| 4094 |
</pre></div> |
| 4095 |
|
| 4096 |
<p>The members of a structured variable form a tree of (sub-) variables, similar |
| 4097 |
to the file system on a computer. This tree has: |
| 4098 |
</p> |
| 4099 |
<ul> |
| 4100 |
<li> one root (which is the structured variable itself), |
| 4101 |
|
| 4102 |
</li><li> zero or more non-leafs (like sub-directories of the top-level root |
| 4103 |
directory), and |
| 4104 |
|
| 4105 |
</li><li> zero or more leafs. The case of zero non-leafs occurs, for example, |
| 4106 |
directly after a new empty variable was created with <b>38 ⎕CR</b>. |
| 4107 |
</li></ul> |
| 4108 |
|
| 4109 |
<p>Due to their tree-like structure, structured variables need to be printed |
| 4110 |
somewhat differently than normal APL variables. For example: |
| 4111 |
</p> |
| 4112 |
<div class="example"> |
| 4113 |
<pre class="example"> PERSON |
| 4114 |
.firstname: ┌→───┐ |
| 4115 |
│Jane│ |
| 4116 |
└────┘ |
| 4117 |
|
| 4118 |
.lastname: ┌→──┐ |
| 4119 |
│Doe│ |
| 4120 |
└───┘ |
| 4121 |
|
| 4122 |
.address: |
| 4123 |
.address.street: ┌→─────────────┐ |
| 4124 |
│44 Main Street│ |
| 4125 |
└──────────────┘ |
| 4126 |
</pre></div> |
| 4127 |
|
| 4128 |
<p>Only the leafs of a deeply structured variable can have values and, as a |
| 4129 |
precaution, assigning a value to a non-leaf (including the root) raises |
| 4130 |
a DOMAIN ERROR: |
| 4131 |
</p> |
| 4132 |
<div class="example"> |
| 4133 |
<pre class="example"> B.b.c←'leaf-Abc' ⍝ OK, since B.b.c will be a leaf |
| 4134 |
B.b←42 ⍝ will fail since B.b is not a leaf |
| 4135 |
DOMAIN ERROR+ |
| 4136 |
B.b←42 |
| 4137 |
^ ^ |
| 4138 |
)MORE |
| 4139 |
member access: cannot override non-leaf member A.b |
| 4140 |
)ERASE or ⎕EX that member first. |
| 4141 |
|
| 4142 |
)ERASE B.b |
| 4143 |
B.b ← 'leaf-Ab' ⍝ now OK, since B.b will now become a (new) leaf |
| 4144 |
|
| 4145 |
)SIC |
| 4146 |
</pre></div> |
| 4147 |
|
| 4148 |
<p>On the other hand, assigning a structured variable to the leaf of another |
| 4149 |
structured variable is valid and concatenates the members: |
| 4150 |
</p> |
| 4151 |
<div class="example"> |
| 4152 |
<pre class="example"> )ERASE A |
| 4153 |
A.b.c ← 'leaf-Abc' ⍝ variable A with leaf A.b.c |
| 4154 |
C.d.e ← 'leaf-cde' ⍝ variable C with leaf C.d.e |
| 4155 |
A.b.c ← C ⍝ overwrite leaf A.b.c of A |
| 4156 |
A.b.c.d.e |
| 4157 |
leaf-cde |
| 4158 |
</pre></div> |
| 4159 |
|
| 4160 |
<p>The file <b>src/testcases/Structured_variable.tc</b> contains the examples |
| 4161 |
above (and more) |
| 4162 |
</p> |
| 4163 |
<hr> |
| 4164 |
</div> |
| 4165 |
<div class="subsection" id="Associative-Arrays"> |
| 4166 |
<div class="header"> |
| 4167 |
<p> |
| 4168 |
Previous: <a href="#Structured-Variables" accesskey="p" rel="prev">Structured Variables</a>, Up: <a href="#Structured-Variables-and-Associative-Arrays" accesskey="u" rel="up">Structured Variables and Associative Arrays</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 4169 |
</div> |
| 4170 |
<span id="Associative-Arrays-1"></span><h4 class="subsection">2.18.2 Associative Arrays</h4> |
| 4171 |
|
| 4172 |
<p>APL arrays are primarily indexed with numbers (or arrays of numbers), which |
| 4173 |
is also the most efficient method. Many other languages provide, either in |
| 4174 |
addition or else alternatively, a method to index arrays by <b>keys</b>, where |
| 4175 |
the keys are frequently character strings. Such arrays are commonly referred |
| 4176 |
to as <b>associative arrays</b>. |
| 4177 |
</p> |
| 4178 |
<p>APL has no associative array per se, but the structured variables in GNU APL |
| 4179 |
can be used for the same purpose. The only limitation is (currently) that the |
| 4180 |
keys need to be character strings (as opposed to arbitrary APL values). |
| 4181 |
</p> |
| 4182 |
<p>That is, in GNU APL an associative array |
| 4183 |
</p> |
| 4184 |
<ul> |
| 4185 |
<li> is a structured variable, and |
| 4186 |
</li><li> can be indexed with arbitrary (!) strings |
| 4187 |
</li></ul> |
| 4188 |
|
| 4189 |
<p>As long as the strings that are used as keys follow the same rules as APL |
| 4190 |
variable names (no leading digit, no ’.’ etc.), a structured variable can |
| 4191 |
also be indexed with a string. That can be useful if keys are being computed |
| 4192 |
or passed as function arguments. However, unlike indexing of APL arrays with |
| 4193 |
numbers, only one key per (bracket-) index is permitted. |
| 4194 |
</p> |
| 4195 |
<div class="example"> |
| 4196 |
<pre class="example"> A.key ← 42 |
| 4197 |
A.key |
| 4198 |
42 |
| 4199 |
A['key'] |
| 4200 |
42 |
| 4201 |
A['key']←24 |
| 4202 |
A.key |
| 4203 |
24 |
| 4204 |
A['key' 'key'] ⍝ not allowed even though 'key' is a valid member |
| 4205 |
DOMAIN ERROR |
| 4206 |
D['key' 'key'] |
| 4207 |
</pre></div> |
| 4208 |
|
| 4209 |
<p>Strings that do not follow the rules for variable names can be used with |
| 4210 |
bracket index, but not with the .member syntax: |
| 4211 |
</p> |
| 4212 |
<div class="example"> |
| 4213 |
<pre class="example"> ASSOC ← 38 ⎕CR 8 |
| 4214 |
KEY←'key.dot' ⍝ works, but avoid such keys |
| 4215 |
ASSOC[KEY]←42 |
| 4216 |
ASSOC[KEY] |
| 4217 |
42 |
| 4218 |
ASSOC[KEY]←43 |
| 4219 |
ASSOC[KEY] |
| 4220 |
43 |
| 4221 |
ASSOC.key.dot ⍝ won't work: 'key.dot' is a single key, but key.dot is 2 keys |
| 4222 |
VALUE ERROR+ |
| 4223 |
ASSOC.key.dot |
| 4224 |
^ |
| 4225 |
)MORE |
| 4226 |
member access: structure ASSOC has no member key |
| 4227 |
|
| 4228 |
ASSOC.key.dot←44 ⍝ works: 2 (nested) keys |
| 4229 |
ASSOC.key.dot |
| 4230 |
44 |
| 4231 |
ASSOC['key.dot'] ⍝ works: one key containing '.' |
| 4232 |
43 |
| 4233 |
</pre></div> |
| 4234 |
|
| 4235 |
<p>This is because ASSOC.key.dot above is being tokenized by the APL parser into |
| 4236 |
[ASSOC] [key] [dot], while ’key.dot’ is a single key. The example above (with |
| 4237 |
different values for ASSOC.key.dot and for ASSOC[’key.dot’] demonstrates why |
| 4238 |
such keys are better avoided. |
| 4239 |
</p> |
| 4240 |
<p>Even though (one) bracket index can only access the top-level members of a |
| 4241 |
structured variable, repeated bracket index (or dyadic PICK) can be used to |
| 4242 |
access deeper nesting levels: |
| 4243 |
</p> |
| 4244 |
<div class="example"> |
| 4245 |
<pre class="example"> D.b.c←42 |
| 4246 |
D['b.c'] ⍝ will fail |
| 4247 |
INDEX ERROR+ |
| 4248 |
D['b.c'] |
| 4249 |
^^ |
| 4250 |
)MORE |
| 4251 |
member access: member b.c was not found. The valid members are: |
| 4252 |
b |
| 4253 |
|
| 4254 |
D['b']['c'] ⍝ will work |
| 4255 |
42 |
| 4256 |
|
| 4257 |
⍝ alternatively: use PICK |
| 4258 |
⍝ |
| 4259 |
'b' 'c' ⊃ D ⍝ fails: 'b' 'c' is 'bc' |
| 4260 |
"b" "c" ⊃ D ⍝ works |
| 4261 |
42 |
| 4262 |
</pre></div> |
| 4263 |
|
| 4264 |
<p>In the above examples each bracket index (or each element of PICK) discards the |
| 4265 |
current top-level structure and descends into the structured sub-variable of |
| 4266 |
the chosen member. In this case PICK is more efficient since repeated bracket |
| 4267 |
index creates copies of the intermediate structured sub-variables. |
| 4268 |
</p> |
| 4269 |
<p>If a variable is used as a structured variable then the number of its members |
| 4270 |
is typically small (since every member name occurs explicitly in the APL code |
| 4271 |
that uses it). If a variable is used as an associative array, then the member |
| 4272 |
names are typically being computed and the number of members can become rather |
| 4273 |
large (like the different key values in a database). When such a variable |
| 4274 |
(i.e. with many members) reaches its capacity, then finding a member (when |
| 4275 |
the array is indexed), or finding an unused place in the variable (when a new |
| 4276 |
member is added) becomes slower and slower. The GNU APL implementation has |
| 4277 |
addressed this by hashing into the variable (based on the member name) |
| 4278 |
instead of, for example, sequentially allocating the members. This is very |
| 4279 |
fast under normal circumstances, but becomes as slow as sequential allocation |
| 4280 |
when the number of members in the variable reaches its current capacity. |
| 4281 |
For this reason, if a structured variable is used as an associative array, |
| 4282 |
e.g. as a database, then it is better to not rely on the (automatic) |
| 4283 |
reorganization of the variable, but to create a large enough variable |
| 4284 |
(with 38 ⎕CR) from the beginning. |
| 4285 |
</p> |
| 4286 |
<p>If that is not possible (because the (performance-) problem has occurred after |
| 4287 |
the variable was created, then one can manually increase the capacity like this: |
| 4288 |
</p> |
| 4289 |
<div class="example"> |
| 4290 |
<pre class="example"> TMP ← 39 ⎕CR ASSOC_ARRAY ⍝ save ASSOC_ARRAY as normal APL array |
| 4291 |
⊣ ⎕EX 'ASSOC_ARRAY' ⍝ erase it so that it can be assigned |
| 4292 |
ASSOC_ARRAY ← 38 ⎕CR TMP ⍝ new associative array with ≥ twice the size |
| 4293 |
</pre></div> |
| 4294 |
|
| 4295 |
<p>As a rule of thumb, associative arrays will be fast as long their capacity is |
| 4296 |
more than twice the number of their members. The expression ASSOC_ARRAY[;1] |
| 4297 |
returns all keys (= members) of ASSOC_ARRAY, therefore the number of members |
| 4298 |
is ⍴ASSOC_ARRAY[;1] and the capacity is ↑⍴ASSOC_ARRAY. |
| 4299 |
</p> |
| 4300 |
|
| 4301 |
<hr> |
| 4302 |
</div> |
| 4303 |
</div> |
| 4304 |
<div class="section" id="Monadic-_22a2-and-_22a3_003b-dyadic-_22a2-with-Axis"> |
| 4305 |
<div class="header"> |
| 4306 |
<p> |
| 4307 |
Next: <a href="#Bit_002dwise-Logical-Functions_003a-_22a4_2227-_22a4_2228-_22a4_2372-_22a4_2371-_22a4_2260-and-_22a4_003d" accesskey="n" rel="next">Bit-wise Logical Functions ⊤∧, ⊤∨, ⊤⍲, ⊤⍱, ⊤≠, and ⊤=</a>, Previous: <a href="#Structured-Variables-and-Associative-Arrays" accesskey="p" rel="prev">Structured Variables and Associative Arrays</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 4308 |
</div> |
| 4309 |
<span id="Monadic-_005b_003f_005d-and-_22a3_003b-dyadic-_005b_003f_005d-with-Axis"></span><h3 class="section">2.19 Monadic ⊢ and ⊣; dyadic ⊢ with Axis</h3> |
| 4310 |
|
| 4311 |
<p>Monadic ⊢ is the identity function. It returns its (committed or non-committed) |
| 4312 |
right argument as a non-committed value. |
| 4313 |
</p> |
| 4314 |
<p>Conversely, monadic ⊣ (called <b>Hide</b> in GNU APL) discards its (committed or |
| 4315 |
non-committed) right argument and returns a committed integer scalar 0. |
| 4316 |
</p> |
| 4317 |
<p>For the most part there is no difference between a committed value (= a value |
| 4318 |
that was assigned to a variable, including ⎕ and ⍞) and a non-committed value. |
| 4319 |
The point where it does make a difference is when the value is the final result |
| 4320 |
of a statement (as opposed to an intermediate result inside a statement). In |
| 4321 |
that situation (and only there) a non-committed value is printed but a |
| 4322 |
committed value is not. |
| 4323 |
</p> |
| 4324 |
<p>You can use ⊢ in a similar fashion as ⎕← at the left end of a statement, |
| 4325 |
to print a value even though it was previously assigned to a variable. |
| 4326 |
</p> |
| 4327 |
<p>The main motivation for ⊣ is that, at least in GNU APL, lambdas always return |
| 4328 |
a value. However, if a lambda is used only for the sake of its side effects, |
| 4329 |
say to print something, then the value returned by the lambda is often of no |
| 4330 |
interest and only messes up the APL output. In that situation ⊣ can be used |
| 4331 |
to suppress the printing of undesired return values from lambdas. |
| 4332 |
</p> |
| 4333 |
<p>In earlier GNU APL versions, ⊣B and ⊢B would both return B; with ⊣ as committed |
| 4334 |
value and with ⊢ as non-committed value. But since the only real-life purpose |
| 4335 |
of ⊣ is to suppress the printing of B, the implementation of ⊣ was changed to |
| 4336 |
returning a committed integer scalar 0 instead of committed B. That reduced |
| 4337 |
the run-time of ⊣B from O(,B) to O(1). Also, ⊢B is marginally faster than ⎕←B. |
| 4338 |
</p> |
| 4339 |
<p>Dyadic ⊢ with axis is a selection function that generalizes ⊣ and ⊢. |
| 4340 |
</p> |
| 4341 |
<p>Let <b>Z←A ⊢[X] B</b>. Then: |
| 4342 |
</p> |
| 4343 |
<ul> |
| 4344 |
<li> if X is a one-element vector and ↑X is 0 then Z ≡ A, |
| 4345 |
</li><li> if X is a one-element vector and ↑X is 1 then Z ≡ B, |
| 4346 |
</li><li> otherwise X selects items of A or B if the corresponding elements of |
| 4347 |
X are 0 or 1 respectively. In that case, the shapes of A and B must match |
| 4348 |
the shape of X, but one-element A or B are scalar extended to the shape of X. |
| 4349 |
</li></ul> |
| 4350 |
|
| 4351 |
<p>Example: |
| 4352 |
</p><div class="example"> |
| 4353 |
<pre class="example"> A←2 3⍴'abcdef' |
| 4354 |
B←2 3⍴⍳6 |
| 4355 |
X←2 3⍴0 1 0 1 0 1 |
| 4356 |
A ⊢[X] B |
| 4357 |
a 2 c |
| 4358 |
4 e 6 |
| 4359 |
|
| 4360 |
A ⊢[X] '*' |
| 4361 |
a*c |
| 4362 |
*e* |
| 4363 |
|
| 4364 |
'*' ⊢[X] B |
| 4365 |
* 2 * |
| 4366 |
4 * 6 |
| 4367 |
</pre></div> |
| 4368 |
|
| 4369 |
|
| 4370 |
<hr> |
| 4371 |
</div> |
| 4372 |
<div class="section" id="Bit_002dwise-Logical-Functions_003a-_22a4_2227-_22a4_2228-_22a4_2372-_22a4_2371-_22a4_2260-and-_22a4_003d"> |
| 4373 |
<div class="header"> |
| 4374 |
<p> |
| 4375 |
Next: <a href="#g_t_22a4-_0028Encode_0029-with-Axis" accesskey="n" rel="next">⊤ (Encode) with Axis</a>, Previous: <a href="#Monadic-_22a2-and-_22a3_003b-dyadic-_22a2-with-Axis" accesskey="p" rel="prev">Monadic ⊢ and ⊣; dyadic ⊢ with Axis</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 4376 |
</div> |
| 4377 |
<span id="Bit_002dwise-Logical-Functions-_005b_003f_005d_005b_003f_005d_002c-_005b_003f_005d_005b_003f_005d_002c-_005b_003f_005d_005b_003f_005d_002c-_005b_003f_005d_005b_003f_005d_002c-_005b_003f_005d_005b_003f_005d_002c-and-_005b_003f_005d_003d"></span><h3 class="section">2.20 Bit-wise Logical Functions ⊤∧, ⊤∨, ⊤⍲, ⊤⍱, ⊤≠, and ⊤=</h3> |
| 4378 |
|
| 4379 |
<p>The APL functions And (∧), Or (∨), Nand (⍲), and Nor (⍱) operate primarily on |
| 4380 |
Boolean integers. Primarily means that the LCM variant for ∧ and the GCD |
| 4381 |
variant for ∨ are not considered in this context. (The LCM and GCD variants |
| 4382 |
are defined in the ISO standard and supported in GNU APL but not in IBM APL2). |
| 4383 |
</p> |
| 4384 |
<p>However, probably more often than not one needs to compute Boolean functions |
| 4385 |
between the bits of arbitrary (non-Boolean) integers and not between entire |
| 4386 |
Boolean integers 0 or 1. Although that is possible to do in standard APL, |
| 4387 |
the procedure is fairly awkward and, more importantly, inefficient: |
| 4388 |
</p> |
| 4389 |
<ul> |
| 4390 |
<li> convert every integer argument X to a 64-item Boolean vector X←(64⍴2)⊤X, |
| 4391 |
</li><li> call the Boolean function ∧, ∨, ⍲, ⍱, =, or ≠ with the converted arguments, |
| 4392 |
and |
| 4393 |
</li><li> convert the Boolean result vector R back to the integer result Z←2⊥R |
| 4394 |
</li></ul> |
| 4395 |
|
| 4396 |
<p>Note: for Boolean arguments the APL functions ≠ and = can be used to compute |
| 4397 |
the more customary Boolean functions XOR and XNOR respectively. In this context |
| 4398 |
= and ≠ are treated as Boolean functions even though they accept non-Boolean |
| 4399 |
arguments, |
| 4400 |
</p> |
| 4401 |
<p>For example, using 5 ⎕CR (4⍴256)⊤X to display X in hex: |
| 4402 |
</p> |
| 4403 |
<div class="example"> |
| 4404 |
<pre class="example"> 5 ⎕CR (4⍴256)⊤ A←$ABBADEAD |
| 4405 |
ABBADEAD |
| 4406 |
5 ⎕CR (4⍴256)⊤ B←$00FF00FF |
| 4407 |
00FF00FF |
| 4408 |
|
| 4409 |
5 ⎕CR (4⍴256)⊤ 2⊥ ((64⍴2)⊤A) ∧ (64⍴2)⊤B |
| 4410 |
00BA00AD |
| 4411 |
</pre></div> |
| 4412 |
|
| 4413 |
<p>With the bit-wise <b>And</b> (⊤∧) the same can be achieved in a simpler fashion |
| 4414 |
and far more efficiently: |
| 4415 |
</p> |
| 4416 |
<div class="example"> |
| 4417 |
<pre class="example"> ⍝ Traditional AND |
| 4418 |
5 ⎕CR (4⍴256)⊤ A←$ABBADEAD |
| 4419 |
ABBADEAD |
| 4420 |
5 ⎕CR (4⍴256)⊤ B←$00FF00FF |
| 4421 |
00FF00FF |
| 4422 |
|
| 4423 |
⍝ bit-wise AND |
| 4424 |
5 ⎕CR (4⍴256)⊤ A ⊤∧ B |
| 4425 |
00BA00AD |
| 4426 |
</pre></div> |
| 4427 |
|
| 4428 |
<ul class="section-toc"> |
| 4429 |
<li><a href="#Dyadic-_22a4_2227-_22a4_2228-_22a4_2372-_22a4_2371-_22a4_003d-and-_22a4_2260" accesskey="1">Dyadic ⊤∧, ⊤∨, ⊤⍲, ⊤⍱, ⊤=, and ⊤≠</a></li> |
| 4430 |
<li><a href="#Monadic-_22a4_2228-and-_22a4_2371" accesskey="2">Monadic ⊤∨ and ⊤⍱</a></li> |
| 4431 |
<li><a href="#Monadic-_22a4_2227" accesskey="3">Monadic ⊤∧</a></li> |
| 4432 |
<li><a href="#Character-Arguments-for-Monadic-_22a4_2371-and-Dyadic-_22a4_2227-_22a4_2228-_003d_003d-and-_2260_2260" accesskey="4">Character Arguments for Monadic ⊤⍱ and Dyadic ⊤∧, ⊤∨, ==, and ≠≠</a></li> |
| 4433 |
</ul> |
| 4434 |
<hr> |
| 4435 |
<div class="subsection" id="Dyadic-_22a4_2227-_22a4_2228-_22a4_2372-_22a4_2371-_22a4_003d-and-_22a4_2260"> |
| 4436 |
<div class="header"> |
| 4437 |
<p> |
| 4438 |
Next: <a href="#Monadic-_22a4_2228-and-_22a4_2371" accesskey="n" rel="next">Monadic ⊤∨ and ⊤⍱</a>, Up: <a href="#Bit_002dwise-Logical-Functions_003a-_22a4_2227-_22a4_2228-_22a4_2372-_22a4_2371-_22a4_2260-and-_22a4_003d" accesskey="u" rel="up">Bit-wise Logical Functions ⊤∧, ⊤∨, ⊤⍲, ⊤⍱, ⊤≠, and ⊤=</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 4439 |
</div> |
| 4440 |
<span id="Dyadic-_005b_003f_005d_005b_003f_005d_002c-_005b_003f_005d_005b_003f_005d_002c-_005b_003f_005d_005b_003f_005d_002c-_005b_003f_005d_005b_003f_005d_002c-_005b_003f_005d_003d_002c-and-_005b_003f_005d_005b_003f_005d"></span><h4 class="subsection">2.20.1 Dyadic ⊤∧, ⊤∨, ⊤⍲, ⊤⍱, ⊤=, and ⊤≠</h4> |
| 4441 |
|
| 4442 |
<p>The dyadic forms of <b>⊤∧</b>, <b>⊤∨</b>, <b>⊤⍲</b>, and <b>⊤⍱</b> are simply the bit-wise |
| 4443 |
variants of their Boolean counterparts: |
| 4444 |
</p> |
| 4445 |
<div class="example"> |
| 4446 |
<pre class="example"> A ⊤∧ B ←→ 2⊥ ((64⍴2)⊤A) ∧ (64⍴2)⊤B ⍝ aka. AND |
| 4447 |
A ⊤∨ B ←→ 2⊥ ((64⍴2)⊤A) ∨ (64⍴2)⊤B ⍝ aka. OR |
| 4448 |
A ⊤⍲ B ←→ 2⊥ ((64⍴2)⊤A) ⍲ (64⍴2)⊤B ⍝ aka. NAND |
| 4449 |
A ⊤⍱ B ←→ 2⊥ ((64⍴2)⊤A) ⍱ (64⍴2)⊤B ⍝ aka. NOR |
| 4450 |
A ⊤≠ B ←→ 2⊥ ((64⍴2)⊤A) ≠ (64⍴2)⊤B ⍝ aka. XOR |
| 4451 |
A ⊤= B ←→ 2⊥ ((64⍴2)⊤A) = (64⍴2)⊤B ⍝ aka. NXOR or XNOR |
| 4452 |
</pre></div> |
| 4453 |
|
| 4454 |
<hr> |
| 4455 |
</div> |
| 4456 |
<div class="subsection" id="Monadic-_22a4_2228-and-_22a4_2371"> |
| 4457 |
<div class="header"> |
| 4458 |
<p> |
| 4459 |
Next: <a href="#Monadic-_22a4_2227" accesskey="n" rel="next">Monadic ⊤∧</a>, Previous: <a href="#Dyadic-_22a4_2227-_22a4_2228-_22a4_2372-_22a4_2371-_22a4_003d-and-_22a4_2260" accesskey="p" rel="prev">Dyadic ⊤∧, ⊤∨, ⊤⍲, ⊤⍱, ⊤=, and ⊤≠</a>, Up: <a href="#Bit_002dwise-Logical-Functions_003a-_22a4_2227-_22a4_2228-_22a4_2372-_22a4_2371-_22a4_2260-and-_22a4_003d" accesskey="u" rel="up">Bit-wise Logical Functions ⊤∧, ⊤∨, ⊤⍲, ⊤⍱, ⊤≠, and ⊤=</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 4460 |
</div> |
| 4461 |
<span id="Monadic-_005b_003f_005d_005b_003f_005d-and-_005b_003f_005d_005b_003f_005d"></span><h4 class="subsection">2.20.2 Monadic ⊤∨ and ⊤⍱</h4> |
| 4462 |
|
| 4463 |
<p><b>⊤=</b>, <b>⊤≠</b>, and <b>⊤⍲</b> do not have a monadic form, but <b>⊤∧</b>, <b>⊤∨</b>, |
| 4464 |
and <b>⊤⍱</b> do. |
| 4465 |
Formally monadic <b>⊤∨</b> and <b>⊤⍱</b> are dyadic <b>⊤∨</b> and <b>⊤⍱</b> with |
| 4466 |
a left argument of 0: |
| 4467 |
</p> |
| 4468 |
<div class="example"> |
| 4469 |
<pre class="example"> ⊤∨ B ←→ 0 ⊤∨ B ⍝ real B to nearby integer |
| 4470 |
⊤⍱ B ←→ 0 ⊤⍱ B ⍝ bit-wise Not |
| 4471 |
</pre></div> |
| 4472 |
|
| 4473 |
<p>Even though Or-ing a Boolean vector with 0 itself has no effect, the |
| 4474 |
monadic ⊤∨ and ⊤⍱ are still useful due to their side effects: conversion |
| 4475 |
from near-integer float values to integers (monadic <b>⊤∨</b> and inversion |
| 4476 |
of the bits (monadic <b>⊤⍱</b>, The latter is needed since ∼ has a monadic |
| 4477 |
form and, as a consequence, ⊤∼ was not an option for a bit-wise <b>Not</b> |
| 4478 |
function. |
| 4479 |
</p> |
| 4480 |
<p>Monadic <b>⊤⍱ B</b> is the bit-wise <b>Not</b> function of its argument: |
| 4481 |
</p> |
| 4482 |
<p>⊤⍱ B ←→ 2⊥ ~(64⍴2)⊤B |
| 4483 |
</p> |
| 4484 |
<p>Monadic <b>⊤∨ B</b> converts near-integer values B into true integers: |
| 4485 |
</p> |
| 4486 |
<div class="example"> |
| 4487 |
<pre class="example"> 26 ⎕CR 1 ⍝ integer |
| 4488 |
16 |
| 4489 |
26 ⎕CR 1.1 ⍝ real |
| 4490 |
32 |
| 4491 |
26 ⎕CR 1÷1 ⍝ integer |
| 4492 |
16 |
| 4493 |
26 ⎕CR 1.1÷1.1 ⍝ real |
| 4494 |
32 |
| 4495 |
26 ⎕CR ⊤∨ 1.1÷1.1 ⍝ integer |
| 4496 |
16 |
| 4497 |
</pre></div> |
| 4498 |
|
| 4499 |
<p>That also works for complex numbers with a near-zero imaginary part: |
| 4500 |
</p> |
| 4501 |
<div class="example"> |
| 4502 |
<pre class="example"> 26 ⎕CR 1.1J0÷1.1 ⍝ real |
| 4503 |
32 |
| 4504 |
26 ⎕CR ⊤∨ 1.1J0÷1.1 ⍝ integer |
| 4505 |
16 |
| 4506 |
</pre></div> |
| 4507 |
|
| 4508 |
<p>As a matter of fact, <b>⊤∨</b> works for all near-Gaussian complex numbers, |
| 4509 |
but the effect is not visible with 26 ⎕CR since Gaussian and non-Gaussian |
| 4510 |
complex numbers have the same cell type in GNU APL. |
| 4511 |
</p> |
| 4512 |
<hr> |
| 4513 |
</div> |
| 4514 |
<div class="subsection" id="Monadic-_22a4_2227"> |
| 4515 |
<div class="header"> |
| 4516 |
<p> |
| 4517 |
Next: <a href="#Character-Arguments-for-Monadic-_22a4_2371-and-Dyadic-_22a4_2227-_22a4_2228-_003d_003d-and-_2260_2260" accesskey="n" rel="next">Character Arguments for Monadic ⊤⍱ and Dyadic ⊤∧, ⊤∨, ==, and ≠≠</a>, Previous: <a href="#Monadic-_22a4_2228-and-_22a4_2371" accesskey="p" rel="prev">Monadic ⊤∨ and ⊤⍱</a>, Up: <a href="#Bit_002dwise-Logical-Functions_003a-_22a4_2227-_22a4_2228-_22a4_2372-_22a4_2371-_22a4_2260-and-_22a4_003d" accesskey="u" rel="up">Bit-wise Logical Functions ⊤∧, ⊤∨, ⊤⍲, ⊤⍱, ⊤≠, and ⊤=</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 4518 |
</div> |
| 4519 |
<span id="Monadic-_005b_003f_005d_005b_003f_005d"></span><h4 class="subsection">2.20.3 Monadic ⊤∧</h4> |
| 4520 |
|
| 4521 |
<p>The ISO standard defines two different concepts to decide if a real number R |
| 4522 |
is close to an integer I, |
| 4523 |
</p><ul> |
| 4524 |
<li> the real number R is said to be <b>near</b> to integer I if the absolute |
| 4525 |
value of I-R is smaller than some small constant called the <b>integer |
| 4526 |
tolerance</b> in ISO and <b>system tolerance</b> in IBM APL2. The <b>integer |
| 4527 |
tolerance</b> is typically platform dependent (1E¯10 in GNU APL). |
| 4528 |
|
| 4529 |
</li><li> the real number R is said to be <b>equal to integer I within ⎕CT</b> if the |
| 4530 |
absolute value of (I-R)/I is smaller than ⎕CT. |
| 4531 |
</li></ul> |
| 4532 |
|
| 4533 |
<p>The first concept is an absolute distance from a real R to a nearby integer I |
| 4534 |
while the second concept is a relative distance (larger numbers are allowed to |
| 4535 |
be farther away from a nearby integer than smaller numbers). The two concepts |
| 4536 |
differ in the same way that absolute and relative errors do. |
| 4537 |
</p> |
| 4538 |
<p>Now, all bit-wise functions described so far use the first concept, i,e, |
| 4539 |
if their arguments are real or complex, then the smallest distance to |
| 4540 |
a (nearby) integer must not exceed the <b>integer tolerance</b>. In some contexts |
| 4541 |
that could be difficult to achieve and for that reason GNU APL provides |
| 4542 |
monadic ⊤∧ which works like ⊤∨ except that the permitted distance from a |
| 4543 |
nearby integer is now controlled by ⎕CT rather than by the integer tolerance. |
| 4544 |
</p> |
| 4545 |
<p>All bit-wise logical functions throw a DOMAIN ERROR if an argument is not close |
| 4546 |
enough to an integer. The <b>integer tolerance</b> is typically smaller than ⎕CT |
| 4547 |
and in that case ⊤∧ is a little more tolerant than ⊤∨ regarding the distance |
| 4548 |
to nearby integers. In addition ⊤∧ gives the user (via ⎕CT) more control over |
| 4549 |
the permitted tolerance for real numbers in the neighborhood of integers. |
| 4550 |
</p> |
| 4551 |
<hr> |
| 4552 |
</div> |
| 4553 |
<div class="subsection" id="Character-Arguments-for-Monadic-_22a4_2371-and-Dyadic-_22a4_2227-_22a4_2228-_003d_003d-and-_2260_2260"> |
| 4554 |
<div class="header"> |
| 4555 |
<p> |
| 4556 |
Previous: <a href="#Monadic-_22a4_2227" accesskey="p" rel="prev">Monadic ⊤∧</a>, Up: <a href="#Bit_002dwise-Logical-Functions_003a-_22a4_2227-_22a4_2228-_22a4_2372-_22a4_2371-_22a4_2260-and-_22a4_003d" accesskey="u" rel="up">Bit-wise Logical Functions ⊤∧, ⊤∨, ⊤⍲, ⊤⍱, ⊤≠, and ⊤=</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 4557 |
</div> |
| 4558 |
<span id="Character-Arguments-for-Monadic-_005b_003f_005d_005b_003f_005d-and-Dyadic-_005b_003f_005d_005b_003f_005d_002c-_005b_003f_005d_005b_003f_005d_002c-_003d_003d_002c-and-_005b_003f_005d_005b_003f_005d"></span><h4 class="subsection">2.20.4 Character Arguments for Monadic ⊤⍱ and Dyadic ⊤∧, ⊤∨, ==, and ≠≠</h4> |
| 4559 |
|
| 4560 |
<p>Some of the bit-wise operations are allowed to have characters as their right |
| 4561 |
argument. If the right argument is a character then the result is a character |
| 4562 |
as well. This can be useful for masking purposes such as extracting the lower |
| 4563 |
7 bits of 8-bit bytes containing ASCII characters. |
| 4564 |
</p> |
| 4565 |
<p>The characters involved are treated as 32 bit quantities: |
| 4566 |
</p> |
| 4567 |
<div class="example"> |
| 4568 |
<pre class="example"> 5⎕CR 'A' |
| 4569 |
41 |
| 4570 |
5⎕CR ⊤⍱'A' ⍝ Note that 5⎕CR aka. ⎕CR.to_HEX ANDs with $FF |
| 4571 |
BE |
| 4572 |
|
| 4573 |
256 256 256 256⊤ ⎕UCS ⊤⍱ 'A' ⍝ ⊤⍱ 'A' is FFFFFFBE |
| 4574 |
255 255 255 190 |
| 4575 |
256 256 256 256⊤$FFFFFFBE |
| 4576 |
255 255 255 190 |
| 4577 |
</pre></div> |
| 4578 |
|
| 4579 |
|
| 4580 |
<hr> |
| 4581 |
</div> |
| 4582 |
</div> |
| 4583 |
<div class="section" id="g_t_22a4-_0028Encode_0029-with-Axis"> |
| 4584 |
<div class="header"> |
| 4585 |
<p> |
| 4586 |
Next: <a href="#Generalized-_2373" accesskey="n" rel="next">Generalized ⍳</a>, Previous: <a href="#Bit_002dwise-Logical-Functions_003a-_22a4_2227-_22a4_2228-_22a4_2372-_22a4_2371-_22a4_2260-and-_22a4_003d" accesskey="p" rel="prev">Bit-wise Logical Functions ⊤∧, ⊤∨, ⊤⍲, ⊤⍱, ⊤≠, and ⊤=</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 4587 |
</div> |
| 4588 |
<span id="g_t_005b_003f_005d-_0028Encode_0029-with-Axis"></span><h3 class="section">2.21 ⊤ (Encode) with Axis</h3> |
| 4589 |
|
| 4590 |
<p>The dyadic primitive function <b>A ⊥ B</b> (Decode) computes the <b>values</b> |
| 4591 |
of <b>B</b> in a number system with radices <b>A</b>. The most common case is |
| 4592 |
a homogeneous radix, i.e. all items of <b>A</b> are the same. In that case |
| 4593 |
the radix <b>A</b> can be specified as a scalar <b>A</b> which will be |
| 4594 |
scalar-extended to the length of <b>B</b> (more precisely: to <b>↑⍴B</b>). |
| 4595 |
For example: |
| 4596 |
</p> |
| 4597 |
<div class="example"> |
| 4598 |
<pre class="example"> 2 2 2 2 ⊥ 1 1 0 1 |
| 4599 |
13 |
| 4600 |
|
| 4601 |
2⊥1 1 0 1 ⍝ scalar extension of 2 to length 4 |
| 4602 |
13 |
| 4603 |
|
| 4604 |
((⍴B)⍴2) ⊤ B←1 1 0 1 ⍝ scalar extension of 2 to ↑⍴B |
| 4605 |
13 |
| 4606 |
</pre></div> |
| 4607 |
|
| 4608 |
<p>The dyadic primitive function <b>A ⊤ B</b> (Encode) computes the <i>representation</i> |
| 4609 |
of <b>B</b> in a number system whose radices are <b>A</b>. The most common case is |
| 4610 |
again a homogeneous radix <b>A</b>. In this sense, Encode is the inverse function |
| 4611 |
of Decode. Unfortunately Encode can not scalar extend the radix <b>A</b>. This |
| 4612 |
is because the shapes of its arguments do not provide sufficient information |
| 4613 |
to determine the radix length that shall be used. As a consequence: |
| 4614 |
</p> |
| 4615 |
<ul> |
| 4616 |
<li> the user needs to provide the radix <b>A</b> as a vector with identical |
| 4617 |
items and with a length that is suitable for the items in <b>B</b>, |
| 4618 |
</li><li> if more radix items than needed are provided, then the result contains |
| 4619 |
leading 0s (which is sort of OK because no information is lost), but |
| 4620 |
</li><li> if less radix items than needed are provided, then an oberflow |
| 4621 |
occurs and the result is truncated. This is awkward because, for example |
| 4622 |
|
| 4623 |
<div class="example"> |
| 4624 |
<pre class="example"> 2 2 2 2 2 2 2 2 ⊤ 1000 ⍝ radix too short for 1000 |
| 4625 |
1 1 1 0 1 0 0 0 |
| 4626 |
|
| 4627 |
2 ⊥ 1 1 1 0 1 0 0 0 ⍝ therefore not 1000 !!! |
| 4628 |
232 |
| 4629 |
232 + (2⋆8) + (2⋆9) ⍝ add missing items |
| 4630 |
1000 |
| 4631 |
</pre></div> |
| 4632 |
|
| 4633 |
</li><li> The IBM APL2 language reference manual proposes to use the APL expression |
| 4634 |
<b>⌊1∣+A⍟(∣B)+A=0</b> for the optimal length of the radix <b>A</b>. |
| 4635 |
</li></ul> |
| 4636 |
|
| 4637 |
<p>We call a radix length <b>⍴A</b> <i>optimal</i> if it is neither too long nor to short. |
| 4638 |
In that case the result has no leading zeros and <b>B ≡ A⊥A⊤N</b>. For an optimal |
| 4639 |
radix length are <b>A⊤</b> and <b>A⊥</b> the inverse functions of each other. |
| 4640 |
</p> |
| 4641 |
<p>In order to improve on this, GNU APL offers the possibility to automatically |
| 4642 |
(and without using <b>A⍟B</b>) compute the optimal radix length from <b>A</b> |
| 4643 |
and <b>B</b>. The solution implemented in GNU APL is to provide the optimal |
| 4644 |
radix length as an axis argument. There are two different cases for the axis |
| 4645 |
argument: |
| 4646 |
</p> |
| 4647 |
<ul> |
| 4648 |
<li> If the optimal radix length is known, say <b>N > 0</b>, then the radix length |
| 4649 |
is given as axis argument <b>N>0</b>. In this case the left argument of <b>A⊤B</b> is |
| 4650 |
slightly simplified: |
| 4651 |
|
| 4652 |
<div class="example"> |
| 4653 |
<pre class="example"> (N⍴↑A) ⊤ B ←→ A ⊤[N] B ⍝ optimal radix length N>0 is known |
| 4654 |
</pre></div> |
| 4655 |
|
| 4656 |
<p>This case frequently occurs when integer(s) <b>B</b> are encoded into hexadecimal |
| 4657 |
8-bit (i.e. radix length = 2 hex digits), 16-bit words (i.e. radix |
| 4658 |
length = 4 hex digits), 32-bit longs (i.e. radix length = 8 hex digits), |
| 4659 |
or 64-bit long longs (i.e. radix length = 16 hex digits). |
| 4660 |
</p> |
| 4661 |
</li><li> Otherwise the radix length is not known; this case is specified as axis |
| 4662 |
argument <b>0</b>. This is also the case where <b>⌊1∣+A⍟(∣B)+A=0</b> would be needed, |
| 4663 |
and it simplifies <b>A⊤B</b> considerably: |
| 4664 |
|
| 4665 |
<div class="example"> |
| 4666 |
<pre class="example"> ((⌊1∣+A⍟(∣B)+A=0)⍴↑A) ⊤ B ←→ A ⊤ [0]B ⍝ unknown radix length |
| 4667 |
</pre></div> |
| 4668 |
</li></ul> |
| 4669 |
|
| 4670 |
<p>Please note the following: |
| 4671 |
</p> |
| 4672 |
<ul> |
| 4673 |
<li> Obviously the case <b>N>0</b> is faster than the case <b>N=0</b> because the |
| 4674 |
user has taken over radix length computation. However, <b>A⊤[N]B</b> is still |
| 4675 |
faster than the classical <b>(N⍴↑A)⊤B</b>. |
| 4676 |
|
| 4677 |
</li><li> If all items in <b>B</b> are non-negative, then the case <b>N=0</b> uses |
| 4678 |
the optimal radix length for unsigned numbers, i.e. <i>without a sign</i>. |
| 4679 |
The result can be used in what is known as <i>unsigned base-A arithmetic</i>. |
| 4680 |
|
| 4681 |
</li><li> If some item of <b>B</b> is negative, then the case <b>N=0</b> uses a radix |
| 4682 |
length that <i>includes</i> a sign (aka. <i>two’s complement arithmetic</i> if |
| 4683 |
<b>A=2</b>). The sign is <b>0</b> for the non-negative items of <b>B</b> and |
| 4684 |
<b>A-1</b> for the negative items of <b>B</b> (= 1 for binary encodings). |
| 4685 |
</li></ul> |
| 4686 |
|
| 4687 |
<p>Examples: |
| 4688 |
</p><div class="example"> |
| 4689 |
<pre class="example"> 2⊤[4] 13 ⍝ 4 digit radix, positive B |
| 4690 |
1 1 0 1 |
| 4691 |
|
| 4692 |
2⊥1 1 0 1 ⍝ proof |
| 4693 |
13 |
| 4694 |
|
| 4695 |
2⊤[5] ¯13 ⍝ 5 digit radix, negative B |
| 4696 |
1 0 0 1 1 |
| 4697 |
|
| 4698 |
32 - 2⊥1 0 0 1 1 ⍝ proof |
| 4699 |
13 |
| 4700 |
|
| 4701 |
</pre></div> |
| 4702 |
|
| 4703 |
|
| 4704 |
<hr> |
| 4705 |
</div> |
| 4706 |
<div class="section" id="Generalized-_2373"> |
| 4707 |
<div class="header"> |
| 4708 |
<p> |
| 4709 |
Next: <a href="#g_t_2339_005bX_005d-_002d-Miscellaneous-Matrix-and-Vector-Operations" accesskey="n" rel="next">⌹[X] - Miscellaneous Matrix and Vector Operations</a>, Previous: <a href="#g_t_22a4-_0028Encode_0029-with-Axis" accesskey="p" rel="prev">⊤ (Encode) with Axis</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 4710 |
</div> |
| 4711 |
<span id="Generalized-_005b_003f_005d"></span><h3 class="section">2.22 Generalized ⍳</h3> |
| 4712 |
|
| 4713 |
<ul class="section-toc"> |
| 4714 |
<li><a href="#Generalized-monadic-_2373" accesskey="1">Generalized monadic ⍳</a></li> |
| 4715 |
<li><a href="#Generalized-dyadic-_2373" accesskey="2">Generalized dyadic ⍳</a></li> |
| 4716 |
</ul> |
| 4717 |
<hr> |
| 4718 |
<div class="subsection" id="Generalized-monadic-_2373"> |
| 4719 |
<div class="header"> |
| 4720 |
<p> |
| 4721 |
Next: <a href="#Generalized-dyadic-_2373" accesskey="n" rel="next">Generalized dyadic ⍳</a>, Up: <a href="#Generalized-_2373" accesskey="u" rel="up">Generalized ⍳</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 4722 |
</div> |
| 4723 |
<span id="Generalized-monadic-_005b_003f_005d"></span><h4 class="subsection">2.22.1 Generalized monadic ⍳</h4> |
| 4724 |
|
| 4725 |
<p>The standard function <b>Interval</b> (Z←⍳B) requires its argument B to be a |
| 4726 |
positive integer scalar or a length 1 integer vector. The result Z←⍳B then |
| 4727 |
contains all possible consecutive integer values having shape B. |
| 4728 |
</p> |
| 4729 |
<p>Generalized monadic ⍳ extends this concept to integer vectors B with more |
| 4730 |
than 1 element. The result Z←⍳B again contains all possible indices of a |
| 4731 |
value which has shape B, but the rank of B can now be more than 1. The items |
| 4732 |
of Z are nested integer vectors consecutive along each axis of B as opposed |
| 4733 |
to integer scalars in the standard case. |
| 4734 |
</p> |
| 4735 |
<hr> |
| 4736 |
</div> |
| 4737 |
<div class="subsection" id="Generalized-dyadic-_2373"> |
| 4738 |
<div class="header"> |
| 4739 |
<p> |
| 4740 |
Previous: <a href="#Generalized-monadic-_2373" accesskey="p" rel="prev">Generalized monadic ⍳</a>, Up: <a href="#Generalized-_2373" accesskey="u" rel="up">Generalized ⍳</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 4741 |
</div> |
| 4742 |
<span id="Generalized-dyadic-_005b_003f_005d"></span><h4 class="subsection">2.22.2 Generalized dyadic ⍳</h4> |
| 4743 |
|
| 4744 |
<p>The standard function <b>Index Of</b> (Z←A⍳B) requires its left argument A to be |
| 4745 |
a scalar or a vector of rank 1. The items of the result Z are the (first) |
| 4746 |
positions (= indices) of the matching items of B in A (for the items found |
| 4747 |
in A) or else ⎕IO+⍴A (which is an invalid index of A) for the items of B that |
| 4748 |
are not found in A. |
| 4749 |
</p> |
| 4750 |
<p>Generalized dyadic ⍳ extends this concept to find the (first) indices of the |
| 4751 |
corresponding items of B in A (in ravel order) where the rank of A is > 1. |
| 4752 |
Each item of the result Z is then either a nested integer vector (if the item |
| 4753 |
was found) or <b>- different from the standard case (!) -</b> the empty vector ⍬ |
| 4754 |
if the item was not found). |
| 4755 |
</p> |
| 4756 |
|
| 4757 |
<hr> |
| 4758 |
</div> |
| 4759 |
</div> |
| 4760 |
<div class="section" id="g_t_2339_005bX_005d-_002d-Miscellaneous-Matrix-and-Vector-Operations"> |
| 4761 |
<div class="header"> |
| 4762 |
<p> |
| 4763 |
Next: <a href="#g_t_2395CC-_002d-Character-Classes" accesskey="n" rel="next">⎕CC - Character Classes</a>, Previous: <a href="#Generalized-_2373" accesskey="p" rel="prev">Generalized ⍳</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 4764 |
</div> |
| 4765 |
<span id="g_t_005b_003f_005d_005bX_005d-_002d-Miscellaneous-Matrix-and-Vector-Operations"></span><h3 class="section">2.23 ⌹[X] - Miscellaneous Matrix and Vector Operations</h3> |
| 4766 |
|
| 4767 |
<ul class="section-toc"> |
| 4768 |
<li><a href="#g_t_2339_005b1_005d-and-_2339_005b2_005d-_002d-QR-Factorizations" accesskey="1">⌹[1] and ⌹[2] - QR Factorizations</a></li> |
| 4769 |
<li><a href="#The-Impact-of-_2395CT-for-_2339" accesskey="2">The Impact of ⎕CT for ⌹</a></li> |
| 4770 |
</ul> |
| 4771 |
<hr> |
| 4772 |
<div class="subsection" id="g_t_2339_005b1_005d-and-_2339_005b2_005d-_002d-QR-Factorizations"> |
| 4773 |
<div class="header"> |
| 4774 |
<p> |
| 4775 |
Next: <a href="#The-Impact-of-_2395CT-for-_2339" accesskey="n" rel="next">The Impact of ⎕CT for ⌹</a>, Up: <a href="#g_t_2339_005bX_005d-_002d-Miscellaneous-Matrix-and-Vector-Operations" accesskey="u" rel="up">⌹[X] - Miscellaneous Matrix and Vector Operations</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 4776 |
</div> |
| 4777 |
<span id="g_t_005b_003f_005d_005b1_005d-and-_005b_003f_005d_005b2_005d-_002d-QR-Factorizations"></span><h4 class="subsection">2.23.1 ⌹[1] and ⌹[2] - QR Factorizations</h4> |
| 4778 |
|
| 4779 |
<p><b>Z←⌹[1] B</b> and <b>Z←⌹[2] B</b> compute a QR factorization of the real or |
| 4780 |
complex matrix B. The results of <b>Z←⌹[1] B</b> and <b>Z←⌹[2] B</b> are |
| 4781 |
conceptually identical, while the algorithms used to compute the results |
| 4782 |
differ. Also, <b>Z←⌹[1] B</b> always exist, while <b>Z←⌹[2] B</b> requires |
| 4783 |
<b>libgsl</b> to be installed when GNU APL is compiled. |
| 4784 |
</p> |
| 4785 |
<p>The axis argument <b>X</b> is used to either clear near-0 matrix items to |
| 4786 |
exactly 0.0 during the computation (in Garry Helzer’s algorithm), or else |
| 4787 |
to select a different algorithm for computing the factorization. Set |
| 4788 |
<b>X←⎕CT</b> if unsure. |
| 4789 |
</p> |
| 4790 |
<p>The result Z is a triple (Q R Ri)←Z with the following properties. |
| 4791 |
Let ⍴B=(M, N). |
| 4792 |
</p> |
| 4793 |
<p>* <b>Q</b> is an orthogonal M×M matrix, i.e Q<sup>-1</sup> = Q<sup>T</sup>, and Q +.× ⍉Q |
| 4794 |
is the M×M identity matrix I<sub>M</sub> (with I<sub>M</sub>←∘.=⍨⍳M). |
| 4795 |
</p> |
| 4796 |
<p>* <b>R</b> is an upper triangular N×N matrix, i.e. R[m;n] = 0 for all n < m. |
| 4797 |
Note that if M>N then, following a convention in other libraries (read: |
| 4798 |
libgsl), the triangular matrices R and Ri have shape (N N) and not (M N). |
| 4799 |
This is because the rows below row N are always 0 in R and in Ri, and |
| 4800 |
are therefore not of interest. As a consequence, in order to restore |
| 4801 |
B from Q and R one has to either use <b>Q+.×M N↑R</b> or else Q∘R (the latter |
| 4802 |
accepts arguments R with fewer rows than columns of Q. |
| 4803 |
</p> |
| 4804 |
<p>* <b>Ri</b> is the inverse of <b>R</b>, i.e. <b>Ri +.× R</b> is the N×N identity |
| 4805 |
matrix I<sub>N</sub>. |
| 4806 |
</p> |
| 4807 |
<p>* <b>B = Q +.× M N↑R</b>. |
| 4808 |
</p> |
| 4809 |
<p>Example 1 (real B) |
| 4810 |
</p><div class="example"> |
| 4811 |
<pre class="example"> ⊢B←3 3⍴ 1 1 3 2 4 2 4 8 7 |
| 4812 |
1 1 3 |
| 4813 |
2 4 2 |
| 4814 |
4 8 7 |
| 4815 |
|
| 4816 |
(Q R Ri)←⌹[⎕CT]B |
| 4817 |
|
| 4818 |
4⎕CR 4⍕Q |
| 4819 |
┏→━━━━━━━━━━━━━━━━━━━┓ |
| 4820 |
↓ .2182 .9759 .0000┃ |
| 4821 |
┃ .4364 ¯.0976 ¯.8944┃ |
| 4822 |
┃ .8729 ¯.1952 .4472┃ |
| 4823 |
┗━━━━━━━━━━━━━━━━━━━━┛ |
| 4824 |
|
| 4825 |
4⎕CR 4⍕Q+.×⍉Q ⍝ verify that Q is orthogonal |
| 4826 |
┏→━━━━━━━━━━━━━━━━━━━━┓ |
| 4827 |
↓ 1.0000 .0000 .0000┃ |
| 4828 |
┃ .0000 1.0000 .0000┃ |
| 4829 |
┃ .0000 .0000 1.0000┃ |
| 4830 |
┗━━━━━━━━━━━━━━━━━━━━━┛ |
| 4831 |
|
| 4832 |
4⎕CR0 4⍕R ⍝ verify that R is upper triangle |
| 4833 |
┏→━━━━━━━━━━━━━━━━━━━━┓ |
| 4834 |
↓ 4.5826 8.9469 7.6376┃ |
| 4835 |
┃ .0000 ¯.9759 1.3663┃ |
| 4836 |
┃ .0000 .0000 1.3416┃ |
| 4837 |
┗━━━━━━━━━━━━━━━━━━━━━┛ |
| 4838 |
|
| 4839 |
Q+.×R ⍝ verify that B is Q+.×R (i.e. B is (⍉Q)+.×R) |
| 4840 |
1 1 3 |
| 4841 |
2 4 2 |
| 4842 |
4 8 7 |
| 4843 |
|
| 4844 |
4⎕CR0 4⍕Ri+.×R ⍝ verify that Ri is the inverse of R |
| 4845 |
┏→━━━━━━━━━━━━━━━━━━━━┓ |
| 4846 |
↓ 1.0000 .0000 .0000┃ |
| 4847 |
┃ .0000 1.0000 .0000┃ |
| 4848 |
┃ .0000 .0000 1.0000┃ |
| 4849 |
┗━━━━━━━━━━━━━━━━━━━━━┛ |
| 4850 |
</pre></div> |
| 4851 |
|
| 4852 |
<p>Example 2 (complex over-determined B) |
| 4853 |
</p> |
| 4854 |
<div class="example"> |
| 4855 |
<pre class="example"> B←5 4⍴4J6 6J3 5J10 3J2 8J10 3J4 5J10 5J8 3J1 2J3 4J5 1J3 1J4 9J9 9J6 2J7 2J10 7J6 9J8 10J10 |
| 4856 |
|
| 4857 |
(Q R Ri)←⌹[⎕CT]B |
| 4858 |
|
| 4859 |
4⎕CR 4⍕Q∘⍉Q ⍝ verify that Q is orthogonal |
| 4860 |
┏→━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ |
| 4861 |
↓ 1.0000J.0000 .0000J.0000 .0000J.0000 .0000J.0000 .0000J.0000┃ |
| 4862 |
┃ .0000J.0000 1.0000J.0000 .0000J.0000 .0000J.0000 .0000J.0000┃ |
| 4863 |
┃ .0000J.0000 .0000J.0000 1.0000J.0000 .0000J.0000 .0000J.0000┃ |
| 4864 |
┃ .0000J.0000 .0000J.0000 .0000J.0000 1.0000J.0000 .0000J.0000┃ |
| 4865 |
┃ .0000J.0000 .0000J.0000 .0000J.0000 .0000J.0000 1.0000J.0000┃ |
| 4866 |
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ |
| 4867 |
|
| 4868 |
4⎕CR 4⍕R ⍝ verify that R is upper triangle |
| 4869 |
┏→━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ |
| 4870 |
↓ 8.5870J15.2557 10.1035J10.9309 13.5055J18.7452 10.0961J15.2530┃ |
| 4871 |
┃ .0000J.0000 8.7353J5.5589 9.2429J.4120 2.5086J.7539 ┃ |
| 4872 |
┃ .0000J.0000 .0000J.0000 ¯2.4869J4.4115 ¯5.9788J¯6.0801┃ |
| 4873 |
┃ .0000J.0000 .0000J.0000 .0000J.0000 7.4038J¯3.9492┃ |
| 4874 |
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ |
| 4875 |
|
| 4876 |
Q∘5 4↑R ⍝ verify that B is Q+.×R (i.e. B is (⍉Q)+.×R) |
| 4877 |
4J6 6J3 5J10 3J2 |
| 4878 |
8J10 3J4 5J10 5J8 |
| 4879 |
3J1 2J3 4J5 1J3 |
| 4880 |
1J4 9J9 9J6 2J7 |
| 4881 |
2J10 7J6 9J8 10J10 |
| 4882 |
</pre></div> |
| 4883 |
|
| 4884 |
<p>Please note as well that QR factorization is currently experimental. So |
| 4885 |
please double-check its results before using it in production code. |
| 4886 |
</p> |
| 4887 |
<hr> |
| 4888 |
</div> |
| 4889 |
<div class="subsection" id="The-Impact-of-_2395CT-for-_2339"> |
| 4890 |
<div class="header"> |
| 4891 |
<p> |
| 4892 |
Previous: <a href="#g_t_2339_005b1_005d-and-_2339_005b2_005d-_002d-QR-Factorizations" accesskey="p" rel="prev">⌹[1] and ⌹[2] - QR Factorizations</a>, Up: <a href="#g_t_2339_005bX_005d-_002d-Miscellaneous-Matrix-and-Vector-Operations" accesskey="u" rel="up">⌹[X] - Miscellaneous Matrix and Vector Operations</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 4893 |
</div> |
| 4894 |
<span id="The-Impact-of-_005b_003f_005dCT-for-_005b_003f_005d"></span><h4 class="subsection">2.23.2 The Impact of ⎕CT for ⌹</h4> |
| 4895 |
|
| 4896 |
<p>Due to the lack of a better place we describe here how <b>⎕CT</b> is used |
| 4897 |
in the various <b>⌹</b> functions. |
| 4898 |
</p> |
| 4899 |
<ul class="section-toc"> |
| 4900 |
<li><a href="#A_2339B-and-_2339B" accesskey="1">A⌹B and ⌹B</a></li> |
| 4901 |
<li><a href="#g_t_2339_005bX_005d-B_003a-Various-Factorizations-of-B" accesskey="2">⌹[X] B: Various Factorizations of B</a></li> |
| 4902 |
<li><a href="#Matrix-Inverse" accesskey="3">Matrix Inverse</a></li> |
| 4903 |
<li><a href="#g_t_2339_005b7_005d-B_003a-Print-Polynomial-B" accesskey="4">⌹[7] B: Print Polynomial B</a></li> |
| 4904 |
<li><a href="#A-_2339_005b8_005d-B_003a-Multiply-Polynomials-A-and-B" accesskey="5">A ⌹[8] B: Multiply Polynomials A and B</a></li> |
| 4905 |
<li><a href="#A-_2339_005b9_005d-B_003a-Divide-Polynomial-A-by-Polynomial-B-_0028univariate_0029" accesskey="6">A ⌹[9] B: Divide Polynomial A by Polynomial B (univariate)</a></li> |
| 4906 |
<li><a href="#A-_2339_005b10_005d-B_003a-Divide-Polynomial-A-by-Polynomial-B-_0028multivariate_0029" accesskey="7">A ⌹[10] B: Divide Polynomial A by Polynomial B (multivariate)</a></li> |
| 4907 |
<li><a href="#A-_2339_005b11_005d-B_003a-Divide-Polynomial-A-by-Polynomial-B-_0028with-order_0029" accesskey="8">A ⌹[11] B: Divide Polynomial A by Polynomial B (with order)</a></li> |
| 4908 |
<li><a href="#g_t_2339_005b11_005d-B-Scan-Polynomial-B" accesskey="9">⌹[11] B: Scan Polynomial B</a></li> |
| 4909 |
<li><a href="#A-_2339_005b20_005d-B_003a-Integral-B">A ⌹[20] B: Integral B</a></li> |
| 4910 |
</ul> |
| 4911 |
<hr> |
| 4912 |
<div class="subsubsection" id="A_2339B-and-_2339B"> |
| 4913 |
<div class="header"> |
| 4914 |
<p> |
| 4915 |
Next: <a href="#g_t_2339_005bX_005d-B_003a-Various-Factorizations-of-B" accesskey="n" rel="next">⌹[X] B: Various Factorizations of B</a>, Up: <a href="#The-Impact-of-_2395CT-for-_2339" accesskey="u" rel="up">The Impact of ⎕CT for ⌹</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 4916 |
</div> |
| 4917 |
<span id="A_005b_003f_005dB-and-_005b_003f_005dB"></span><h4 class="subsubsection">2.23.2.1 A⌹B and ⌹B</h4> |
| 4918 |
|
| 4919 |
<p>The first step in the computation of <b>A⌹B</b> or <b>⌹B</b> is the estimation |
| 4920 |
of the number of linearly independent columns of <b>B</b>. If that number is |
| 4921 |
smaller than the total number of columns (IOW some columns of <b>B</b> are |
| 4922 |
linearly dependent) then a <b>DOMAIN ERROR</b> is raised before the computation |
| 4923 |
of <b>⌹B</b> starts. Although <b>B</b> may be over-determined (so it may have more |
| 4924 |
rows than columns and in that case the rows of <b>B</b> cannot be linearly |
| 4925 |
independent) it may <i>not</i> have linearly dependent columns. |
| 4926 |
</p> |
| 4927 |
<p>Now, for every real or complex number <b>⍺</b> does <b>⎕CT</b> define a range |
| 4928 |
of nearby numbers that are considered equal to <b>⍺</b> even though they are, |
| 4929 |
computationally speaking, different? |
| 4930 |
</p> |
| 4931 |
<p>In the same fashion, let <b>B</b> be a matrix with linearly dependent columns. |
| 4932 |
For every such <b>B</b> does <b>⎕CT</b> define a range of nearby matrices that |
| 4933 |
are also considered linearly dependent even though they are, strictly |
| 4934 |
speaking, linearly independent? As a matter of fact, the probability |
| 4935 |
that the columns of <b>B</b> are strictly linearly independent decreases |
| 4936 |
as the size of the matrix grows. If a matrix has linearly dependent |
| 4937 |
columns, then every new row added to the matrix can make it linearly |
| 4938 |
independent, but not the other way around. |
| 4939 |
</p> |
| 4940 |
<p>The consequence for the user of GNU APL is the following. If GNU APL raises |
| 4941 |
a <b>DOMAIN ERROR</b> caused by the supposedly linearly dependent columns of some |
| 4942 |
matrix <b>B</b> then there are two possibilities: |
| 4943 |
</p> |
| 4944 |
<ol> |
| 4945 |
<li> the columns of <b>B</b> are indeed linearly dependent, e.g. <b>⌹B←2 2⍴3 4</b>. |
| 4946 |
In this case there is no way to compute <b>⌹B</b>. |
| 4947 |
</li><li> the columns of <b>B</b> are only close (as controlled by <b>⎕CT</b>) to |
| 4948 |
some other strictly linearly dependent matrix. In this case (which |
| 4949 |
is far more likely than the other), one may decrease <b>⎕CT</b> |
| 4950 |
until the matrix becomes linearly independent. For example, <b>⌹B</b> |
| 4951 |
may raise a DOMAIN ERROR with the default <b>⎕CT←1E¯13</b> but not |
| 4952 |
with <b>⎕CT←1E¯15</b>. |
| 4953 |
However, one should use this technique with great care because |
| 4954 |
matrices that are nearly linearly dependent tend to produce |
| 4955 |
significant rounding errors in the result. |
| 4956 |
</li></ol> |
| 4957 |
|
| 4958 |
<hr> |
| 4959 |
</div> |
| 4960 |
<div class="subsubsection" id="g_t_2339_005bX_005d-B_003a-Various-Factorizations-of-B"> |
| 4961 |
<div class="header"> |
| 4962 |
<p> |
| 4963 |
Next: <a href="#Matrix-Inverse" accesskey="n" rel="next">Matrix Inverse</a>, Previous: <a href="#A_2339B-and-_2339B" accesskey="p" rel="prev">A⌹B and ⌹B</a>, Up: <a href="#The-Impact-of-_2395CT-for-_2339" accesskey="u" rel="up">The Impact of ⎕CT for ⌹</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 4964 |
</div> |
| 4965 |
<span id="g_t_005b_003f_005d_005bX_005d-B_003a-Various-Factorizations-of-B"></span><h4 class="subsubsection">2.23.2.2 ⌹[X] B: Various Factorizations of B</h4> |
| 4966 |
|
| 4967 |
<p>The numeric scalar <b>X</b> chooses one of several algorithms that computes a |
| 4968 |
factorization (aka. decomposition) of a matrix <b>B</b>: |
| 4969 |
</p> |
| 4970 |
<ul> |
| 4971 |
<li> <b>⌹[1]B</b> computes a QR-factorization of <b>B</b>. It uses the algorithm |
| 4972 |
published by Garry Helzer in APL Quote Quad in 1990. This algorithm is |
| 4973 |
always available. |
| 4974 |
|
| 4975 |
</li><li> <b>⌹[2]B</b> also computes a QR-factorization of <b>B</b>. However, it uses a |
| 4976 |
<b>libgsl</b> based algorithm and is therefore only available |
| 4977 |
if <b>libgsl</b> was installed when GNU APL was ./configure’d.. |
| 4978 |
|
| 4979 |
</li><li> <b>⌹[3]B</b> computes a RQ-factoriztion of <b>B</b>. |
| 4980 |
It also requires <b>libgsl</b>. |
| 4981 |
|
| 4982 |
</li><li> <b>⌹[4]B</b> computes a LQ-factoriztion of <b>B</b>. |
| 4983 |
It also requires <b>libgsl</b>. |
| 4984 |
|
| 4985 |
</li><li> <b>⌹[5]B</b> computes a QL-factoriztion of <b>B</b>. |
| 4986 |
It also requires <b>libgsl</b>. |
| 4987 |
|
| 4988 |
</li><li> <b>⌹[6]B</b> computes a LU-factoriztion of <b>B</b>. |
| 4989 |
It also requires <b>libgsl</b>. |
| 4990 |
|
| 4991 |
</li><li> <b>⌹[TOL]B</b> with a small real <b>TOL</b>. This variant is obsolete and |
| 4992 |
only provided for backward compatibility with older versions of GNU APL |
| 4993 |
(and is subject to being removed at some point in time). It uses the Helzer |
| 4994 |
algorithm with <b>TOL</b> instead of <b>⎕CT</b>. New code should not use <b>⌹[TOL]</b> |
| 4995 |
but rather <b>⌹[1]</b> or <b>⌹[2]</b> after setting <b>⎕CT←TOL</b>. |
| 4996 |
</li></ul> |
| 4997 |
|
| 4998 |
<p>The Helzer algorithm recursively factors a N×N matrix, a (N-1)×(N-1) matrix, |
| 4999 |
a (N-2)×(N-2) matrix, and so forth. After every step of that recursion, |
| 5000 |
all matrix items that are <i>close</i> to <b>0.0</b> are set to exactly <b>0.0</b>. |
| 5001 |
The meaning of <i>close</i> is defined by <b>⎕CT</b> in <b>⌹[1]B</b> (resp. <b>TOL</b> in |
| 5002 |
the obsolete case above). |
| 5003 |
</p> |
| 5004 |
<p>In the Helzer algorithm, GNU APL uses <b>⎕CT</b> as the tolerance <b>TOL</b> |
| 5005 |
which decides if a matrix item close to <b>0.0</b> shall be set to <b>0.0</b> |
| 5006 |
or not (APL functions <b>A TOL X</b> and <b>A CPR B</b> in the Helzer paper). |
| 5007 |
The Helzer paper leaves it open how to implement <b>A TOL X</b> and <b>A CPR B</b>). |
| 5008 |
GNU APL uses the example implementation given in the Helzer paper. |
| 5009 |
The <b>TOL</b> and <b>CPR</b> functions seem to be related to what is elsewhere |
| 5010 |
known as the <i>condition number</i> of the matrix that is being factorized. |
| 5011 |
In the libgsl based algotithms is <b>⎕CT</b> not used. |
| 5012 |
</p> |
| 5013 |
<p>The factorizations <b>⌹[1]</b>, <b>⌹[2]</b>, <b>⌹[3]</b>, <b>⌹[4]</b>, and <b>⌹[5]</b> |
| 5014 |
return a (nested) vector <b>(Q T Ti)</b> where <b>Q</b> is orthogonal, |
| 5015 |
<b>T</b> is (upper or lower) triangular, and <b>Ti</b> is <b>T<sup>-1</sup></b>. |
| 5016 |
</p> |
| 5017 |
<p>Let <b>⍴B = (M N)</b> and let <b>min_MN = min(M, N)</b>. Then the |
| 5018 |
factorization <b>⌹[6]</b> returns a nested vector <b>(P U L)</b> where: |
| 5019 |
</p><ul> |
| 5020 |
<li> vector <b>P</b> is a permutation of <b>⍳M</b>, |
| 5021 |
</li><li> matrix <b>L</b> is lower triangular with shape <b>(M min_MN)</b> and all |
| 5022 |
of its diagonal items equal to <b>1.0</b>., |
| 5023 |
</li><li> matrix <b>U</b> is upper triangular with shape <b>(min_MN N)</b>, and, |
| 5024 |
most importantly, |
| 5025 |
</li><li> <b>B[P;] = L∘U</b>. |
| 5026 |
</li></ul> |
| 5027 |
|
| 5028 |
<hr> |
| 5029 |
</div> |
| 5030 |
<div class="subsubsection" id="Matrix-Inverse"> |
| 5031 |
<div class="header"> |
| 5032 |
<p> |
| 5033 |
Next: <a href="#g_t_2339_005b7_005d-B_003a-Print-Polynomial-B" accesskey="n" rel="next">⌹[7] B: Print Polynomial B</a>, Previous: <a href="#g_t_2339_005bX_005d-B_003a-Various-Factorizations-of-B" accesskey="p" rel="prev">⌹[X] B: Various Factorizations of B</a>, Up: <a href="#The-Impact-of-_2395CT-for-_2339" accesskey="u" rel="up">The Impact of ⎕CT for ⌹</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 5034 |
</div> |
| 5035 |
<span id="Matrix-Inverse-1"></span><h4 class="subsubsection">2.23.2.3 Matrix Inverse</h4> |
| 5036 |
|
| 5037 |
<p>The matrix <b>Ti</b> returned by <b>⌹[1]</b> or <b>⌹[2]</b> provides an alternative |
| 5038 |
to <b>⌹B</b> for computing the inverse of a matrix <b>B</b>, in particular if the |
| 5039 |
QR-factorization of <b>B</b> was already computed. |
| 5040 |
</p> |
| 5041 |
<p>Since <b>B = Q∘T</b>, it follows that <b>B⁻¹ = T⁻¹∘Q⁻¹ = Ti∘⍉Q</b>. |
| 5042 |
</p> |
| 5043 |
<p>Indeed: |
| 5044 |
</p> |
| 5045 |
<div class="example"> |
| 5046 |
<pre class="example"> B←?5 5⍴100 ⍝ a random matrix B |
| 5047 |
(Q T Ti)←⌹[2]B |
| 5048 |
(⌹B) = Ti∘⍉Q |
| 5049 |
1 1 1 1 1 |
| 5050 |
1 1 1 1 1 |
| 5051 |
1 1 1 1 1 |
| 5052 |
1 1 1 1 1 |
| 5053 |
1 1 1 1 1 |
| 5054 |
</pre></div> |
| 5055 |
|
| 5056 |
<p>The computation of <b>⍉Q</b> and <b>Ti∘⍉Q</b> is considerably faster than the |
| 5057 |
computation of <b>⌹B</b> if <b>B</b> is large. |
| 5058 |
</p> |
| 5059 |
|
| 5060 |
<hr> |
| 5061 |
</div> |
| 5062 |
<div class="subsubsection" id="g_t_2339_005b7_005d-B_003a-Print-Polynomial-B"> |
| 5063 |
<div class="header"> |
| 5064 |
<p> |
| 5065 |
Next: <a href="#A-_2339_005b8_005d-B_003a-Multiply-Polynomials-A-and-B" accesskey="n" rel="next">A ⌹[8] B: Multiply Polynomials A and B</a>, Previous: <a href="#Matrix-Inverse" accesskey="p" rel="prev">Matrix Inverse</a>, Up: <a href="#The-Impact-of-_2395CT-for-_2339" accesskey="u" rel="up">The Impact of ⎕CT for ⌹</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 5066 |
</div> |
| 5067 |
<span id="g_t_005b_003f_005d_005b7_005d-B_003a-Print-Polynomial-B"></span><h4 class="subsubsection">2.23.2.4 ⌹[7] B: Print Polynomial B</h4> |
| 5068 |
|
| 5069 |
<p>Let <b>B ← b₀ b₁ b₂ ... bₙ</b>. The standard interpretation of this vector |
| 5070 |
<b>B</b> in APL is that <b>B</b> is an element of a vector space over the |
| 5071 |
field <b>ℝ</b> or <b>ℂ</b>. The elementary APL primitives <b>+</b>, <b>-</b>, <b>×</b> |
| 5072 |
and <b>÷</b>, but also the more powerful primitives <b>+.×</b> and <b>⌹</b>, |
| 5073 |
and last but not least the scalar extension mechanism of several primitive |
| 5074 |
are tailored for this interpretation. |
| 5075 |
</p> |
| 5076 |
<p>However, another and less common interpretation of <b>B</b> is this: |
| 5077 |
vector <b>B</b> is a polynomial of (a single) indeterminant <b>X</b>: |
| 5078 |
</p> |
| 5079 |
<p>B ←→ b₀ + b₁X + b₂X² + ... + bₙXⁿ |
| 5080 |
</p> |
| 5081 |
<p>This interpretation easily extends to APL values of higher rank, i.e. |
| 5082 |
matrices are polynomials of two indeterminants <b>X</b> and <b>Y</b>, values of |
| 5083 |
rank 3 are polynomials of three indeterminants <b>X</b>, <b>Y</b>, and <b>Z</b>, |
| 5084 |
and so on. In this case, assuming <b>⎕IO←0</b>: |
| 5085 |
</p> |
| 5086 |
<ul> |
| 5087 |
<li> An APL value <b>P</b> with rank <b>r←⍴⍴P</b> represents a polynomial with |
| 5088 |
<b>r</b> indeterminants. |
| 5089 |
</li><li> The item <b>P[k;m;n;...]</b> is the coefficient of the polynomial term |
| 5090 |
that has the indeterminant powers <b>XᵏYᵐZⁿ</b>... |
| 5091 |
</li><li> The vector <b>P[;0;0;...]</b> are the coefficients of the polynomial terms |
| 5092 |
with only powers of <b>X</b>, |
| 5093 |
</li><li> The vector <b>P[0;;0;...]</b> are the coefficients of the polynomial terms |
| 5094 |
with only powers of <b>Y</b>, |
| 5095 |
</li><li> The vector <b>P[0;0;;...]</b> are the coefficients of the polynomial terms |
| 5096 |
with only powers of <b>Z</b>, |
| 5097 |
</li><li> and so on. The other items of <b>P</b> are coeffiecients of the polynomial |
| 5098 |
terms with mixed powers of the different indeterminants. |
| 5099 |
</li><li> The item <b>P[[0;0;0;...</b> aka. <b>↑P</b> is the constant term of the |
| 5100 |
polinomial. |
| 5101 |
</li></ul> |
| 5102 |
|
| 5103 |
<p>Function <b>⌹[7] B</b>, aka. <b>⌹.poly_print B</b> returns a string with this |
| 5104 |
interpretation. In its monadic form <b>⌹[7] B</b> it uses the names |
| 5105 |
<b>x</b>, <b>y</b>, <b>z</b>, ... for the indeterminants of the polynomial. |
| 5106 |
In its dyadic form <b>A ⌹[7] B</b> does i<b>A</b> specify the names that shall |
| 5107 |
be used. Two forms are supported for <b>A</b>: the characters of a plain APL |
| 5108 |
string <b>(⍴A == ⍴⍴B)</b> is understood as a list of single character |
| 5109 |
indeterminants. iAlternatively A list of nested strings <b>A</b> (again with |
| 5110 |
<b>(⍴A == ⍴⍴B)</b>) is understood as N different indeterminant names. For example: |
| 5111 |
</p> |
| 5112 |
<div class="example"> |
| 5113 |
<pre class="example"> ⍝ monadic, 1 indeterminant |
| 5114 |
⌹.poly_print ⎕←POLY←3 2 1 |
| 5115 |
3 2 1 |
| 5116 |
x² + 2x + 3 |
| 5117 |
|
| 5118 |
⍝ monadic, 2 indeterminants |
| 5119 |
⌹.poly_print ⎕←POLY←2 3⍴⍳6 |
| 5120 |
1 2 3 |
| 5121 |
4 5 6 |
| 5122 |
6x²y + 5xy + 4y + 3x² + 2x + 1 |
| 5123 |
|
| 5124 |
⍝ monadic, 3 indeterminants |
| 5125 |
⌹.poly_print ⎕←POLY←3 3⍴⍳9 |
| 5126 |
1 2 3 |
| 5127 |
4 5 6 |
| 5128 |
7 8 9 |
| 5129 |
9x²y² + 8xy² + 7y² + 6x²y + 5xy + 4y + 3x² + 2x + 1 |
| 5130 |
|
| 5131 |
⍝ dyadic, two 1-character indeterminants X and Y |
| 5132 |
'XY' ⌹.poly_print ⎕←POLY←2 3⍴⍳6 |
| 5133 |
1 2 3 |
| 5134 |
4 5 6 |
| 5135 |
6X²Y + 5XY + 4Y + 3X² + 2X + 1 |
| 5136 |
|
| 5137 |
⍝ dyadic, two named indeterminants _Foo and _Bar |
| 5138 |
'_Foo' '_Bar' ⌹.poly_print ⎕←POLY←2 3⍴⍳6 |
| 5139 |
1 2 3 |
| 5140 |
4 5 6 |
| 5141 |
6_Foo²_Bar + 5_Foo_Bar + 4_Bar + 3_Foo² + 2_Foo + 1 |
| 5142 |
|
| 5143 |
</pre></div> |
| 5144 |
|
| 5145 |
<hr> |
| 5146 |
</div> |
| 5147 |
<div class="subsubsection" id="A-_2339_005b8_005d-B_003a-Multiply-Polynomials-A-and-B"> |
| 5148 |
<div class="header"> |
| 5149 |
<p> |
| 5150 |
Next: <a href="#A-_2339_005b9_005d-B_003a-Divide-Polynomial-A-by-Polynomial-B-_0028univariate_0029" accesskey="n" rel="next">A ⌹[9] B: Divide Polynomial A by Polynomial B (univariate)</a>, Previous: <a href="#g_t_2339_005b7_005d-B_003a-Print-Polynomial-B" accesskey="p" rel="prev">⌹[7] B: Print Polynomial B</a>, Up: <a href="#The-Impact-of-_2395CT-for-_2339" accesskey="u" rel="up">The Impact of ⎕CT for ⌹</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 5151 |
</div> |
| 5152 |
<span id="A-_005b_003f_005d_005b8_005d-B_003a-Multiply-Polynomials-A-and-B"></span><h4 class="subsubsection">2.23.2.5 A ⌹[8] B: Multiply Polynomials A and B</h4> |
| 5153 |
|
| 5154 |
<p>The scalar APL primitives <b>+</b> and <b>-</b> can be used for vectors |
| 5155 |
and for polynomials alike. In contrast, the multiplication of two polynomials |
| 5156 |
<b>A</b> and <b>B</b> is different from the scalar multiplication <b>A×B</b> and is |
| 5157 |
also different from the vector multiplication <b>A +.× B</b>. |
| 5158 |
</p> |
| 5159 |
<p>Dyadic <b>A ⌹[8] B</b> aka. <b>A ⌹.poly_multiply B</b> fills this gap and computes |
| 5160 |
the product of two polynomials. For example: |
| 5161 |
</p> |
| 5162 |
<div class="example"> |
| 5163 |
<pre class="example"> ⍝ single indeterminant x |
| 5164 |
⍝ |
| 5165 |
"A:" (⌹.poly_print A ← 4 0 0 6 3 1) |
| 5166 |
A: x⁵ + 3x⁴ + 6x³ + 4 |
| 5167 |
|
| 5168 |
"B:" (⌹.poly_print B ← 5 0 2) |
| 5169 |
B: 2x² + 5 |
| 5170 |
|
| 5171 |
"PROD:" (⌹.poly_print PROD ← A ⌹.poly_multiply B) |
| 5172 |
PROD: 2x⁷ + 6x⁶ + 17x⁵ + 15x⁴ + 30x³ + 8x² + 20 |
| 5173 |
|
| 5174 |
⍝ two indeterminants x and y |
| 5175 |
⍝ |
| 5176 |
"A:" (⌹.poly_print A ← 2 2⍴0 1 1 0) |
| 5177 |
A: x + y |
| 5178 |
|
| 5179 |
"B:" (⌹.poly_print B ← 2 2⍴0 ¯1 1 0) |
| 5180 |
B: x - y |
| 5181 |
|
| 5182 |
"PROD:" (⌹.poly_print PROD ← A ⌹.poly_multiply B) |
| 5183 |
PROD: x² - y² |
| 5184 |
</pre></div> |
| 5185 |
|
| 5186 |
<hr> |
| 5187 |
</div> |
| 5188 |
<div class="subsubsection" id="A-_2339_005b9_005d-B_003a-Divide-Polynomial-A-by-Polynomial-B-_0028univariate_0029"> |
| 5189 |
<div class="header"> |
| 5190 |
<p> |
| 5191 |
Next: <a href="#A-_2339_005b10_005d-B_003a-Divide-Polynomial-A-by-Polynomial-B-_0028multivariate_0029" accesskey="n" rel="next">A ⌹[10] B: Divide Polynomial A by Polynomial B (multivariate)</a>, Previous: <a href="#A-_2339_005b8_005d-B_003a-Multiply-Polynomials-A-and-B" accesskey="p" rel="prev">A ⌹[8] B: Multiply Polynomials A and B</a>, Up: <a href="#The-Impact-of-_2395CT-for-_2339" accesskey="u" rel="up">The Impact of ⎕CT for ⌹</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 5192 |
</div> |
| 5193 |
<span id="A-_005b_003f_005d_005b9_005d-B_003a-Divide-Polynomial-A-by-Polynomial-B-_0028univariate_0029"></span><h4 class="subsubsection">2.23.2.6 A ⌹[9] B: Divide Polynomial A by Polynomial B (univariate)</h4> |
| 5194 |
|
| 5195 |
<p>The scalar APL primitives <b>+</b> and <b>-</b> can be used for vectors |
| 5196 |
and for polynomials alike. In contrast, the division of a polynomial |
| 5197 |
<b>A</b> by a polynomial <b>B</b> is different from the scalar division <b>A÷B</b> |
| 5198 |
and is also different from the matrix division <b>A ⌹.× B</b>. |
| 5199 |
</p> |
| 5200 |
<p>Dyadic <b>A ⌹[9] B</b> aka. <b>A ⌹.poly_divide B</b> fills this gap and computes |
| 5201 |
the quotient of two polynomials. Since polynomials form a ring (and not a |
| 5202 |
field) the quotient is not always a polynomial (at least not one with |
| 5203 |
non-negative exponents). For this reason <b>A ⌹.poly_divide B</b> performs |
| 5204 |
a division with remainder and the result is a pair <b>(Quotient, Remainder)</b> |
| 5205 |
where <b>Remainder</b> is a polynomial with a degree smaller that the degree |
| 5206 |
of polynomial <b>B</b>. That is, <b>⍴Remainder = ¯1+⍴B</b>. |
| 5207 |
</p> |
| 5208 |
<p><b>NOTE:</b> <b>A ⌹[9] B</b> is limited to polynomials with 1 indeterminant. |
| 5209 |
</p> |
| 5210 |
<hr> |
| 5211 |
</div> |
| 5212 |
<div class="subsubsection" id="A-_2339_005b10_005d-B_003a-Divide-Polynomial-A-by-Polynomial-B-_0028multivariate_0029"> |
| 5213 |
<div class="header"> |
| 5214 |
<p> |
| 5215 |
Next: <a href="#A-_2339_005b11_005d-B_003a-Divide-Polynomial-A-by-Polynomial-B-_0028with-order_0029" accesskey="n" rel="next">A ⌹[11] B: Divide Polynomial A by Polynomial B (with order)</a>, Previous: <a href="#A-_2339_005b9_005d-B_003a-Divide-Polynomial-A-by-Polynomial-B-_0028univariate_0029" accesskey="p" rel="prev">A ⌹[9] B: Divide Polynomial A by Polynomial B (univariate)</a>, Up: <a href="#The-Impact-of-_2395CT-for-_2339" accesskey="u" rel="up">The Impact of ⎕CT for ⌹</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 5216 |
</div> |
| 5217 |
<span id="A-_005b_003f_005d_005b10_005d-B_003a-Divide-Polynomial-A-by-Polynomial-B-_0028multivariate_0029"></span><h4 class="subsubsection">2.23.2.7 A ⌹[10] B: Divide Polynomial A by Polynomial B (multivariate)</h4> |
| 5218 |
|
| 5219 |
<p>The limitiation of <b>A ⌹[10] B</b> to handle only polynomials with one |
| 5220 |
indeterminan is lifted with <b>A ⌹[10]</b> aka. <b>A ⌹.poly_divideN B</b>. |
| 5221 |
The suffix <b>N</b> shall indicate that the number off indefinites is > 1. |
| 5222 |
However, some caution needs to be exercized when using this function, |
| 5223 |
as described in the following. |
| 5224 |
</p> |
| 5225 |
<p>A <i>polynomial</i> is the sum of zero or more <i>terms</i>. The terms of a |
| 5226 |
polynomial are commonly called <i>monomials</i>. |
| 5227 |
</p> |
| 5228 |
<p><b>Tip</b>: to list, for example, all possible monomials of a polymomial with |
| 5229 |
three indeterminants x, y, and z and at most powers of 3: |
| 5230 |
</p> |
| 5231 |
<div class="example"> |
| 5232 |
<pre class="example"> ⍝ show all monomials of indeterminants x, y, z |
| 5233 |
⍝ and max.powers 0, 1, and 2 (in lexicographic order) |
| 5234 |
⍝ |
| 5235 |
⌹.poly_print 3 3 3⍴1 |
| 5236 |
x²y²z² + x²y²z + x²y² + x²yz² + x²yz + x²y + x²z² + x²z + x² + xy²z² + xy²z + |
| 5237 |
xy² + xyz² + xyz + xy + xz² + xz + x + y²z² + y²z + y² + yz² + yz + y + |
| 5238 |
z² + z + 1 |
| 5239 |
</pre></div> |
| 5240 |
|
| 5241 |
<p>In the set of all <i>monomials</i> an <i>order</i>, that is a relation <b><</b> between |
| 5242 |
any two elements of the set needs to be defined. In the |
| 5243 |
simple cases of dividing integers or polynomials with only one indeterminant |
| 5244 |
the order <b><</b> is canonical: |
| 5245 |
</p> |
| 5246 |
<ul> |
| 5247 |
<li> order of integer: 0 < 1 < 2 < 3 ... |
| 5248 |
</li><li> order of polynomials: x⁰ < x¹ < x² < x³ ... |
| 5249 |
</li></ul> |
| 5250 |
|
| 5251 |
<p>An order between <i>monomials</i> need not only satisfy the general requirements |
| 5252 |
of an order (i.e. being reflexive, antisymmetric, and transitive), but also |
| 5253 |
the following: |
| 5254 |
</p> |
| 5255 |
<ul> |
| 5256 |
<li> if x<sup>⍺</sup> < x<sup>β</sup> then x<sup>γ</sup>x<sup>⍺</sup> < x<sup>γ</sup>x<sup>β</sup> |
| 5257 |
for all γ, and |
| 5258 |
</li><li> M ≥ 0 for every monomial M |
| 5259 |
</li></ul> |
| 5260 |
|
| 5261 |
<p>The general problem with multivariate polynomials (i.e. polynomials with more |
| 5262 |
than one indeterminant, such as <b>x² + y²</b>) is then that the quotient and |
| 5263 |
remainder of two multivariate polinomials is not unique but depend on |
| 5264 |
the order defined between its monomials. The division of integers and |
| 5265 |
of polynomials with one indeterminant is based on their canonical order, |
| 5266 |
which results in a unique quotient and a unique remainder in these cases. |
| 5267 |
In contrast there can be several different orders between the monomials |
| 5268 |
of a multivariate polynomial, and these different orders leads to different |
| 5269 |
quotients and remainders. |
| 5270 |
</p> |
| 5271 |
<p>For example: |
| 5272 |
</p><div class="example"> |
| 5273 |
<pre class="example">Let |
| 5274 |
f = x2y + xy2 + y2, |
| 5275 |
g₁ = xy − 1, and |
| 5276 |
g₂ = y² − 1. |
| 5277 |
|
| 5278 |
Dividing f by g₁ and then by g₂ gives: |
| 5279 |
|
| 5280 |
f = (x + y)(xy − 1) + (y² − 1) + (x + y + 1) |
| 5281 |
= (x + y) g₁ + g₂ + (x + y + 1) |
| 5282 |
|
| 5283 |
However, dividing f by g₂ and then by g₁ gives: |
| 5284 |
|
| 5285 |
f = x(xy − 1) + (x + 1)(y² − 1) + (2x + 1) |
| 5286 |
= x g₁ + ((x + 1) g₂ + (2x + 1) |
| 5287 |
|
| 5288 |
</pre></div> |
| 5289 |
|
| 5290 |
<p>This ambiguity is resolved by always dividing a polynomial by |
| 5291 |
its <i>largest term</i>, where the largest term is in turn defined |
| 5292 |
by the order of the mononomials that was chosen. IOW: a monomial order |
| 5293 |
defines the which of the monomials of a polynomial is its largest monomials, |
| 5294 |
and in every iteration of the division the largest monomial is being |
| 5295 |
annihilated (by subtracting a multiple of the divisor from it). |
| 5296 |
</p> |
| 5297 |
<p>Now, a commonly used order in the division of polynomials, and also the order |
| 5298 |
used by <b>A ⌹[10] B</b>, is the <i>lexicographic order</i> of the polynomials. |
| 5299 |
See <a href="#g_t_2339_005b11_005d-B-Scan-Polynomial-B">⌹[11] B: Scan Polynomial B</a>. |
| 5300 |
</p> |
| 5301 |
<p>For example: <b>x < x²</b>, <b>xy < xyz</b>, <b>y < x⁸</b>, and <b>y⁸ < x</b> in the |
| 5302 |
lexicographic order. |
| 5303 |
</p> |
| 5304 |
<p>With these prerequisites, the division algorithm of GNU APL (which was |
| 5305 |
inspired by <a href="https://lall.stanford.edu/ee464/lectures/groebner_bases.pdf">https://lall.stanford.edu/ee464/lectures/groebner_bases.pdf</a>) |
| 5306 |
is this: |
| 5307 |
</p> |
| 5308 |
<div class="example"> |
| 5309 |
<pre class="example"> Let LT(p) denote the largest term in polynomial p, and let (1) |
| 5310 |
|
| 5311 |
q₁ = q₂ = ... = qₙ = 0 ⍝ quotient (1a) |
| 5312 |
r = 0 ⍝ remainder (1b) |
| 5313 |
p = f ⍝ dividend (1c) |
| 5314 |
|
| 5315 |
while p ≠ 0: (2) |
| 5316 |
let i be the smallest i such that LT(gᵢ) divides LT(p). (3) |
| 5317 |
if such an i exists then: (3a) |
| 5318 |
qᵢ = qᵢ + LT(p) ÷ LT(gᵢ) (4a) |
| 5319 |
p = p - gᵢ × LT(r) ÷ LT(gᵢ) (4b) |
| 5320 |
otherwise: (3b) |
| 5321 |
r = r + LT(p) (5a) |
| 5322 |
p = p - LT(gᵢ) (5b) |
| 5323 |
</pre></div> |
| 5324 |
|
| 5325 |
<p>The algorithm divides polynomial <b>f</b> by polynomial |
| 5326 |
<b>g = g₁ + g₂ + ... + gₙ</b> and yields a quotient <b>q = q₁ + q₂ + ... + qₘ</b> |
| 5327 |
and a remainder <b>r = r₁ + r₂ + ... + rₖ</b>. In every iteration the largest |
| 5328 |
term in <b>p</b> is annihilated by "moving" it to either i<b>q</b> (after |
| 5329 |
dividing it by <b>LT(gᵢ)</b> if that is possible) or else to <b>r</b> |
| 5330 |
(if not). Obviously: |
| 5331 |
</p> |
| 5332 |
<ul> |
| 5333 |
<li> The divisor <b>g</b> does not change at all, |
| 5334 |
</li><li> <b>p</b> gets shorter and shorter in each iteration and therefore the |
| 5335 |
algorithm terminates after at most <b>n</b> iterations. In addition the |
| 5336 |
subtraction in <b>4b</b> certainly annihilates the leading term of <b>p</b>, |
| 5337 |
but <i>could</i> also annihilate other monomials of <b>p</b> (which then also |
| 5338 |
reduces the number of iterations performed). |
| 5339 |
</li><li> The quotient <b>q</b> grows as new quotients are being added in |
| 5340 |
step <b>4b</b>. |
| 5341 |
</li><li> The remainder <b>r</b> also grows as new items are added in step <b>5a</b>. |
| 5342 |
In the integer and polynomial with one indeterminant cases is the length |
| 5343 |
of the remainder limited by the degree of the dividend (so the |
| 5344 |
remainder of dividing e.g. <b>x³ + ax² + bx + c</b> by anything has always |
| 5345 |
no more than 3 momomials). In contrast a polynomial with a max. power |
| 5346 |
of, say, 3 but 4 indeterminants can have up to 4⁴ = 256 momomials. |
| 5347 |
</li></ul> |
| 5348 |
|
| 5349 |
<hr> |
| 5350 |
</div> |
| 5351 |
<div class="subsubsection" id="A-_2339_005b11_005d-B_003a-Divide-Polynomial-A-by-Polynomial-B-_0028with-order_0029"> |
| 5352 |
<div class="header"> |
| 5353 |
<p> |
| 5354 |
Next: <a href="#g_t_2339_005b11_005d-B-Scan-Polynomial-B" accesskey="n" rel="next">⌹[11] B: Scan Polynomial B</a>, Previous: <a href="#A-_2339_005b10_005d-B_003a-Divide-Polynomial-A-by-Polynomial-B-_0028multivariate_0029" accesskey="p" rel="prev">A ⌹[10] B: Divide Polynomial A by Polynomial B (multivariate)</a>, Up: <a href="#The-Impact-of-_2395CT-for-_2339" accesskey="u" rel="up">The Impact of ⎕CT for ⌹</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 5355 |
</div> |
| 5356 |
<span id="A-_005b_003f_005d_005b11_005d-B_003a-Divide-Polynomial-A-by-Polynomial-B-_0028with-order_0029"></span><h4 class="subsubsection">2.23.2.8 A ⌹[11] B: Divide Polynomial A by Polynomial B (with order)</h4> |
| 5357 |
|
| 5358 |
<p>As explained above, different monomial orders of a polynomial can lead |
| 5359 |
to different quotients and remainders when dividing them. This iproblem |
| 5360 |
is addressed by <b>A ⌹[11] B</b> aka. <b>A ⌹.poly_divideNO B</b>. |
| 5361 |
The suffix <b>NO</b> shall indicate that the number off indefinites is > 1, |
| 5362 |
and that a user defined monomial order shall be used. |
| 5363 |
</p> |
| 5364 |
<p>Let <b>P</b> be a polynimial. An monomial order <b>O</b> for <b>P</b> is then |
| 5365 |
a matrix with the following properties: |
| 5366 |
</p> |
| 5367 |
<ul> |
| 5368 |
<li> O has the same shape as P: (⍴P) ≡ (⍴O). |
| 5369 |
</li><li> ↑O (the order value of the contant term of the polynomial) is 0 |
| 5370 |
</li></ul> |
| 5371 |
|
| 5372 |
<p>In addition, as already mentioned above, the order defined by <b>O</b> shall be |
| 5373 |
consistent: if x<sup>⍺</sup> < x<sup>β</sup> then x<sup>γ</sup>x<sup>⍺</sup> < x<sup>γ</sup>x<sup>β</sup> |
| 5374 |
for all γ in <b>O</b>. <b>A ⌹.poly_divideNO B</b> checks that <b>↑O = 0</b> but not |
| 5375 |
the consistency of <b>O</b>. If the consistency condition is violated, then |
| 5376 |
in the best case the results are incorrect, and in the worst case the division |
| 5377 |
algorithm may not terminate. |
| 5378 |
</p> |
| 5379 |
<p>For example, given a Polynomial <b>P</b>, the lexicographic order of <b>P</b> can |
| 5380 |
be constrocted as follows: |
| 5381 |
</p> |
| 5382 |
<div class="example"> |
| 5383 |
<pre class="example"> ⍝ construct the lexicographical order of all possible monom in P |
| 5384 |
⍝ |
| 5385 |
ORDER←-⎕IO-(⍴P)⍴⍳×/⍴P |
| 5386 |
</pre></div> |
| 5387 |
|
| 5388 |
<p>After an order <b>O</b> has been created for a polynomial <b>P</b>, both can be |
| 5389 |
appended to create an argument for <b>A ⌹.poly_divideNO B</b>: |
| 5390 |
</p> |
| 5391 |
<div class="example"> |
| 5392 |
<pre class="example"> ⍝ append the desired monomial order O to a polynomial P. |
| 5393 |
⍝ |
| 5394 |
PO ← (2,⍴P)⍴(,P),,O |
| 5395 |
</pre></div> |
| 5396 |
|
| 5397 |
<p>Putting the pieces together: |
| 5398 |
</p> |
| 5399 |
<div class="example"> |
| 5400 |
<pre class="example"> ⍝ create the dividend |
| 5401 |
⍝ |
| 5402 |
"A:" A←⌹.poly_scan "x³ - x² - xy² - 2x + y² + 4" |
| 5403 |
A: 4 0 1 |
| 5404 |
¯2 0 ¯1 |
| 5405 |
¯1 0 0 |
| 5406 |
1 0 0 |
| 5407 |
|
| 5408 |
⍝ create the divisor |
| 5409 |
⍝ |
| 5410 |
"B:" B←⌹.poly_scan "x - y" |
| 5411 |
B: 0 ¯1 |
| 5412 |
1 0 |
| 5413 |
|
| 5414 |
⍝ create the monomial orders for A and B |
| 5415 |
⍝ |
| 5416 |
ORDER_A←-⎕IO-(⍴A)⍴⍳×/⍴A |
| 5417 |
ORDER_B←-⎕IO-(⍴B)⍴⍳×/⍴B |
| 5418 |
|
| 5419 |
⍝ append the orders to their polynomial |
| 5420 |
⍝ |
| 5421 |
ARG_A ← (2,⍴A)⍴(,A),,ORDER_A |
| 5422 |
ARG_B ← (2,⍴B)⍴(,B),,ORDER_B |
| 5423 |
|
| 5424 |
⍝ call ⌹.poly_divideN and poly_divideNO |
| 5425 |
⍝ |
| 5426 |
(Q1 R1) ← A ⌹.poly_divideN B |
| 5427 |
(Q2 R2) ← ARG_A ⌹.poly_divideNO ARG_B |
| 5428 |
|
| 5429 |
⍝ the result should be the same, because |
| 5430 |
⍝ ORDER_A is what ⌹.poly_divideN uses. |
| 5431 |
⍝ |
| 5432 |
(Q1 R1) ≡ (Q2 R2) |
| 5433 |
1 |
| 5434 |
</pre></div> |
| 5435 |
|
| 5436 |
<hr> |
| 5437 |
</div> |
| 5438 |
<div class="subsubsection" id="g_t_2339_005b11_005d-B-Scan-Polynomial-B"> |
| 5439 |
<div class="header"> |
| 5440 |
<p> |
| 5441 |
Next: <a href="#A-_2339_005b20_005d-B_003a-Integral-B" accesskey="n" rel="next">A ⌹[20] B: Integral B</a>, Previous: <a href="#A-_2339_005b11_005d-B_003a-Divide-Polynomial-A-by-Polynomial-B-_0028with-order_0029" accesskey="p" rel="prev">A ⌹[11] B: Divide Polynomial A by Polynomial B (with order)</a>, Up: <a href="#The-Impact-of-_2395CT-for-_2339" accesskey="u" rel="up">The Impact of ⎕CT for ⌹</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 5442 |
</div> |
| 5443 |
<span id="g_t_005b_003f_005d_005b11_005d-B_003a-Scan-Polynomial-B"></span><h4 class="subsubsection">2.23.2.9 ⌹[11] B: Scan Polynomial B</h4> |
| 5444 |
|
| 5445 |
<p><b>⌹[11] B</b> aka. <b>⌹.poly_scan B</b> is the inverse function of <b>⌹[7] B</b>. |
| 5446 |
It converts a string <b>B</b> (in the format produced by <b>⌹poly_print B</b> and |
| 5447 |
returns the corresponding APL value. |
| 5448 |
</p> |
| 5449 |
<div class="example"> |
| 5450 |
<pre class="example"> ⊢Z←⌹.poly_scan "1 + 2xy + 3y²" |
| 5451 |
1 0 3 |
| 5452 |
0 2 0 |
| 5453 |
|
| 5454 |
⌹.poly_print Z |
| 5455 |
2xy + 3y² + 1 |
| 5456 |
</pre></div> |
| 5457 |
|
| 5458 |
<p><b>NOTE</b> that the terms of a polynomial are commutative. The same set of terms, |
| 5459 |
summed up in different orders, defines the same polynomial. Therefore: |
| 5460 |
</p> |
| 5461 |
<p><b>M ≡ ⌹.poly_scan ⌹.poly_print M</b> |
| 5462 |
</p> |
| 5463 |
<p>however: |
| 5464 |
</p> |
| 5465 |
<p><b>P ≡ ⌹.poly_print ⌹.poly_scan P</b> |
| 5466 |
</p> |
| 5467 |
<p>holds only if the terms in <b>P</b> occur in the same order as produced |
| 5468 |
by <b>⌹.poly_print</b>. The order in which <b>⌹.poly_print B</b> prints the terms |
| 5469 |
of a polynimial <b>B</b> is what is known as the <b>lexicographic order</b>, |
| 5470 |
which can, in this context, be defined as follows: |
| 5471 |
</p> |
| 5472 |
<p>A sequence of vectors is in lexicographic order (or: |
| 5473 |
<i>ordered lexicographically</i>), if every smaller item i<b>a</b> in the sequence |
| 5474 |
comes before every larger item <b>b</b> in the sequence. Where <b>smaller</b> |
| 5475 |
resp, <b>larger</b> is defined as follows: |
| 5476 |
</p> |
| 5477 |
<ul> |
| 5478 |
<li> Let <b>a = a₀ a₁ ... aₙ</b>, |
| 5479 |
</li><li> let <b>b = b₀ b₁ ... bₙ</b>, |
| 5480 |
</li><li> let <b>∆ = ∆₀ ∆₁ ... ∆ₙ</b> with <b>∆ⱼ = bⱼ - aⱼ</b>, and |
| 5481 |
</li><li> let <b>j</b> be the smallest <b>j</b> such that <b>∆ⱼ ≠ 0</b>. |
| 5482 |
That is: the first <b>j-1</b> items of <b>a</b> and <b>b</b> are equal) |
| 5483 |
and <b>j</b> is the first position at which vectors <b>a</b> and <b>b</b> differ. |
| 5484 |
</li><li> Then: |
| 5485 |
<ul> |
| 5486 |
<li> If <b>∆ⱼ > 0</b> then <b>a <<sub>lex</sub> b</b> (i.e. <b>a</b> is smaller than <b>b</b> |
| 5487 |
and <b>b</b> is larger than <b>a</b>). |
| 5488 |
</li><li> Otherwise <b>∆ⱼ < 0</b> and then <b>b <<sub>lex</sub> a</b> (i.e. <b>a</b> is |
| 5489 |
larger than <b>b</b> and <b>b</b> is smaller than <b>a</b>). |
| 5490 |
</li></ul> |
| 5491 |
</li></ul> |
| 5492 |
|
| 5493 |
<p>The lexicographic order is also defined for vectors of different lengths, |
| 5494 |
but in this context all vectors compared have the same length (number of |
| 5495 |
indeterminants). |
| 5496 |
</p> |
| 5497 |
<hr> |
| 5498 |
</div> |
| 5499 |
<div class="subsubsection" id="A-_2339_005b20_005d-B_003a-Integral-B"> |
| 5500 |
<div class="header"> |
| 5501 |
<p> |
| 5502 |
Previous: <a href="#g_t_2339_005b11_005d-B-Scan-Polynomial-B" accesskey="p" rel="prev">⌹[11] B: Scan Polynomial B</a>, Up: <a href="#The-Impact-of-_2395CT-for-_2339" accesskey="u" rel="up">The Impact of ⎕CT for ⌹</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 5503 |
</div> |
| 5504 |
<span id="A-_005b_003f_005d_005b20_005d-B_003a-Integral-B"></span><h4 class="subsubsection">2.23.2.10 A ⌹[20] B: Integral B</h4> |
| 5505 |
|
| 5506 |
<p>Function <b>A ⌹[20] B</b> aka. <b>A ⌹.integral B</b> computes the integral of |
| 5507 |
expression <b>B</b>. For example: |
| 5508 |
</p> |
| 5509 |
<div class="example"> |
| 5510 |
<pre class="example"> ⍝ monadic (same as A=1) |
| 5511 |
⍝ |
| 5512 |
⌹.integral "sqrt(x³)" |
| 5513 |
2*x*sqrt(x³)/5 |
| 5514 |
|
| 5515 |
⍝ A=1 : vector result |
| 5516 |
⍝ |
| 5517 |
1 ⌹.integral "sqrt(x³)" |
| 5518 |
2*x*sqrt(x³)/5 |
| 5519 |
|
| 5520 |
⍝ A=2 : matrix result |
| 5521 |
⍝ |
| 5522 |
2 ⌹.integral "sqrt(x³)" |
| 5523 |
_____ |
| 5524 |
2⋅x⋅╲╱ x³ |
| 5525 |
─────────── |
| 5526 |
5 |
| 5527 |
</pre></div> |
| 5528 |
|
| 5529 |
<p><b>NOTE</b>: The implementation of <b>⌹.integral</b> depends on <b>python</b>. It also |
| 5530 |
depends on the python package <b>sympy</b> which does the actual computation |
| 5531 |
of the integral. Normally the GNU APL <b>./configure</b> script determines which |
| 5532 |
optional libraries for GNU APL are present and compiles GNU APL accordingly. |
| 5533 |
In the python case this is not possible because python and its packages |
| 5534 |
can be installed globally (by a privilreged user such as <b>root</b>) or by |
| 5535 |
a unprivilreged user (e.g. below her home directory). It could therefore |
| 5536 |
happen that e.g. python is available for the user that installs GNU APL, |
| 5537 |
but not for a user that uses the installed GNU APL. The GNU APL |
| 5538 |
<b>./configure</b> has no way to detect such a situation. For this reason |
| 5539 |
GNU APL checks at runtime (i.e. when <b>⌹.integral</b> is used) if python and |
| 5540 |
<b>sympy</b> are installed (and raises a <b>DOMAIN ERROR</b> if not). |
| 5541 |
</p> |
| 5542 |
<p>Now to the arguments of <b>⌹.integral</b>. The right argument <b>B</b> is a string |
| 5543 |
with the expression for which the integral shall be computed. The syntax |
| 5544 |
of <b>B</b> ia pretty much defined by <b>sympy</b>. A maybe noteworthy difference |
| 5545 |
between strings understood by <b>⌹.integral</b> and strings understood by |
| 5546 |
<b>sympy</b> is that powers in <b>sympy</b> cwhave to be written as e.g. <b>a**n</b>, |
| 5547 |
while <b>⌹.integral</b> also understands <b>aⁿ</b>. |
| 5548 |
</p> |
| 5549 |
<p>The left argument <b>A</b> is a vector of options. Currently only one option |
| 5550 |
is defined which defines the format of the result: |
| 5551 |
</p> |
| 5552 |
<ul> |
| 5553 |
<li> <b>A[1]=1</b> : the result is a string (see example above) |
| 5554 |
</li><li> <b>A[1]=2</b> : the result is a character matrix (see example above). The |
| 5555 |
matrix is primarily created by the sympy function <b>pretty()</b> |
| 5556 |
(which is unfortunately not formally specified). For this reason |
| 5557 |
is <b>A[1]=2</b> somewhat experimental and may produce a garbled output in |
| 5558 |
some cases. |
| 5559 |
</li><li> <b>A[1]=3</b> : the result is a string in a simple to parse |
| 5560 |
format. |
| 5561 |
</li><li> <b>A[1]=4</b> : the result is a string in LATEX format. |
| 5562 |
</li><li> <b>A[1]=5</b> : the result is a character matrix in Math_ML format. |
| 5563 |
</li><li> <b>A[1]=6</b> : the result is a character matrix in Dot format. |
| 5564 |
</li></ul> |
| 5565 |
|
| 5566 |
<p><b>MathML</b> is an XML-based industry standard for mathematical expressions. |
| 5567 |
</p> |
| 5568 |
<p><b>Dot</b> is a program for printing directed graphs. |
| 5569 |
</p> |
| 5570 |
<hr> |
| 5571 |
</div> |
| 5572 |
</div> |
| 5573 |
</div> |
| 5574 |
<div class="section" id="g_t_2395CC-_002d-Character-Classes"> |
| 5575 |
<div class="header"> |
| 5576 |
<p> |
| 5577 |
Next: <a href="#Dyadic-_2395CR" accesskey="n" rel="next">Dyadic ⎕CR</a>, Previous: <a href="#g_t_2339_005bX_005d-_002d-Miscellaneous-Matrix-and-Vector-Operations" accesskey="p" rel="prev">⌹[X] - Miscellaneous Matrix and Vector Operations</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 5578 |
</div> |
| 5579 |
<span id="g_t_005b_003f_005dCC-_002d-Character-Classes"></span><h3 class="section">2.24 ⎕CC - Character Classes</h3> |
| 5580 |
|
| 5581 |
<p>Some older APL interpreters (e.g. APL68000) had system variables for |
| 5582 |
character classes, such as <b>⎕D</b> for digits 0..9 or <b>⎕A</b> for letters |
| 5583 |
A..Z. GNU APL provides a single system function <b>⎕CC</b> for that |
| 5584 |
purpose. |
| 5585 |
</p> |
| 5586 |
<ul class="section-toc"> |
| 5587 |
<li><a href="#monadic-_2395CC-B_003a-Return-character-class" accesskey="1">monadic ⎕CC B: Return character class</a></li> |
| 5588 |
<li><a href="#dyadic-A-_2395CC-B_003a-Test-character-class" accesskey="2">dyadic A ⎕CC B: Test character class</a></li> |
| 5589 |
</ul> |
| 5590 |
<hr> |
| 5591 |
<div class="subsection" id="monadic-_2395CC-B_003a-Return-character-class"> |
| 5592 |
<div class="header"> |
| 5593 |
<p> |
| 5594 |
Next: <a href="#dyadic-A-_2395CC-B_003a-Test-character-class" accesskey="n" rel="next">dyadic A ⎕CC B: Test character class</a>, Up: <a href="#g_t_2395CC-_002d-Character-Classes" accesskey="u" rel="up">⎕CC - Character Classes</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 5595 |
</div> |
| 5596 |
<span id="monadic-_005b_003f_005dCC-B_003a-Return-character-class"></span><h4 class="subsection">2.24.1 monadic ⎕CC B: Return character class</h4> |
| 5597 |
|
| 5598 |
<p><b>⎕CC B</b> returns all characters of character class(es) <b>B</b>. If <b>B</b> is an |
| 5599 |
integer scalar then the result is a character vector, If <b>B</b> is an integer |
| 5600 |
vector then the result is a nested vector of integer vectors, with one item |
| 5601 |
per character class. |
| 5602 |
</p> |
| 5603 |
<div class="example"> |
| 5604 |
<pre class="example"> ⍝ character class 1: digits (old ⎕D) |
| 5605 |
⍝ |
| 5606 |
⎕CC 1 |
| 5607 |
0123456789 |
| 5608 |
|
| 5609 |
⍝ character class 2: uppercase letters A..Z (old ⎕A) |
| 5610 |
ABCDEFGHIJKLMNOPQRSTUVWXYZ |
| 5611 |
|
| 5612 |
⍝ character class 3: lowercase letters a..z |
| 5613 |
abcdefghijklmnopqrstuvwxyz |
| 5614 |
|
| 5615 |
... |
| 5616 |
|
| 5617 |
⍝ Line drawing characters |
| 5618 |
⎕CC 7 |
| 5619 |
┌─┬─┐╒═╤═╕ |
| 5620 |
├─┼─┤╞═╪═╡ |
| 5621 |
└─┴─┘╘═╧═╛ |
| 5622 |
╓─╥─╖╔═╦═╗ |
| 5623 |
╟─╫─╢╠═╬═╣ |
| 5624 |
╙─╨─╜╚═╩═╝ |
| 5625 |
|
| 5626 |
⍝ Some mathematical symbols |
| 5627 |
⎕CC 8 |
| 5628 |
⎲⎛⎞⎡⎤⎧⎫ |
| 5629 |
⎳⎜⎟⎢⎥⎨⎬ |
| 5630 |
↔⎝⎠⎣⎦⎮⎮ |
| 5631 |
ℕℤℚℝℂ⎩⎭ |
| 5632 |
</pre></div> |
| 5633 |
|
| 5634 |
<p>A special case is <b>⎕CC ⍬</b> (or <b>⎕CC ⍳0</b>: it prints the available |
| 5635 |
character classes for ⎕CC: |
| 5636 |
</p> |
| 5637 |
<div class="example"> |
| 5638 |
<pre class="example"> ⎕CC ⍬ |
| 5639 |
⎕CC 1: digits 0-9 (same as ⎕CC 10) |
| 5640 |
⎕CC 2: uppercase characters A-Z (same as ⎕CC 26) |
| 5641 |
⎕CC 3: lowercase characters a-z (same as ⎕CC ¯26) |
| 5642 |
⎕CC 4: ASCII characters (same as ⎕CC 127) |
| 5643 |
⎕CC 5: superscripts ( ²³¹ʲᵏᵐᵗ⁰ⁱ⁴⁵⁶⁷⁸⁹⁺⁻⁼⁽⁾ⁿ ) |
| 5644 |
⎕CC 6: subscripts ( ᵢ₀₁₂₃₄₅₆₇₈₉₊₋₌₍₎ₖₘₙⱼ ) |
| 5645 |
⎕CC 7: line drawing chatacters |
| 5646 |
⎕CC 8: octal digits 0-7 |
| 5647 |
⎕CC 9: some mathematical symbols |
| 5648 |
⎕CC 10: decimal digits 0-9 |
| 5649 |
⎕CC 16: UPPERCASE HEXADECIMAL DIGITS 0-9 A-F |
| 5650 |
⎕CC ¯16: lowercase hexadecimal digits 0-9 A-F a-f |
| 5651 |
⎕CC 17: Hexadecimal Digits 0-9 A-F a-f |
| 5652 |
⎕CC 26: UPPERCASE CHARACTERS A-Z |
| 5653 |
⎕CC ¯26: lowercase characters A-Z |
| 5654 |
⎕CC 33: base32 encoding (RFC 4648) |
| 5655 |
⎕CC 48: greek characters A-Ω α-ω |
| 5656 |
⎕CC 52: characters A-Z a-z |
| 5657 |
⎕CC 65: base64 encoding (RFC 4648) |
| 5658 |
⎕CC 95: printable characters 0x20 ... 0x7E |
| 5659 |
⎕CC 128: ASCII characters |
| 5660 |
</pre></div> |
| 5661 |
|
| 5662 |
<p>In many cases is the character class number easy to remember because: |
| 5663 |
</p> |
| 5664 |
<ul> |
| 5665 |
<li> the character class number is equal to the number of characters in |
| 5666 |
the class, e.g. <b>26</b> for <b>A-Z</b>, <b>52</b> for <b>A-Z and a-z</b>, |
| 5667 |
</li><li> negative numbers are the lowercase variants of the uppercase class, |
| 5668 |
e.g. <b>26</b> for <b>A-Z</b> and <b>¯26</b> for <b>a-z</b>, and |
| 5669 |
</li><li> <b>2*class</b> is the mixed case of the uppercase <b>class</b>. |
| 5670 |
</li></ul> |
| 5671 |
|
| 5672 |
<hr> |
| 5673 |
</div> |
| 5674 |
<div class="subsection" id="dyadic-A-_2395CC-B_003a-Test-character-class"> |
| 5675 |
<div class="header"> |
| 5676 |
<p> |
| 5677 |
Previous: <a href="#monadic-_2395CC-B_003a-Return-character-class" accesskey="p" rel="prev">monadic ⎕CC B: Return character class</a>, Up: <a href="#g_t_2395CC-_002d-Character-Classes" accesskey="u" rel="up">⎕CC - Character Classes</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 5678 |
</div> |
| 5679 |
<span id="dyadic-A-_005b_003f_005dCC-B_003a-Test-character-class"></span><h4 class="subsection">2.24.2 dyadic A ⎕CC B: Test character class</h4> |
| 5680 |
|
| 5681 |
<p>The dyadic <b>A ⎕CC B</b> returns, for every item in A, integer <b>1</b> if the item |
| 5682 |
is contained in one of the character classes <b>B</b> and <b>0</b> if not. |
| 5683 |
</p> |
| 5684 |
<div class="example"> |
| 5685 |
<pre class="example"> 'a45Y' ⎕CC 1 |
| 5686 |
0 1 1 0 |
| 5687 |
|
| 5688 |
'a45Y' ⎕CC 1 2 |
| 5689 |
0 1 1 1 |
| 5690 |
|
| 5691 |
(⎕CC 7) ⎕CC 7 |
| 5692 |
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 |
| 5693 |
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 |
| 5694 |
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 |
| 5695 |
</pre></div> |
| 5696 |
|
| 5697 |
<p>For most classes this lookup is an optimized constant time operation (for |
| 5698 |
every item of <b>A</b> and faster than e.g. <b>(⎕CC n) ⍳ A</b>. |
| 5699 |
</p> |
| 5700 |
<hr> |
| 5701 |
</div> |
| 5702 |
</div> |
| 5703 |
<div class="section" id="Dyadic-_2395CR"> |
| 5704 |
<div class="header"> |
| 5705 |
<p> |
| 5706 |
Next: <a href="#Dyadic-_2395FX-_0028Native-Functions_0029" accesskey="n" rel="next">Dyadic ⎕FX (Native Functions)</a>, Previous: <a href="#g_t_2395CC-_002d-Character-Classes" accesskey="p" rel="prev">⎕CC - Character Classes</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 5707 |
</div> |
| 5708 |
<span id="Dyadic-_005b_003f_005dCR"></span><h3 class="section">2.25 Dyadic ⎕CR</h3> |
| 5709 |
|
| 5710 |
<p>The <b>⎕CR</b> function has now an optional left argument that selects one of |
| 5711 |
several formatting styles and conversion functions in addition to the |
| 5712 |
well-known monadic form. |
| 5713 |
</p> |
| 5714 |
<p>Calling <b>⎕CR</b> monadically without an axis and with an empty right argument |
| 5715 |
shows a list of all functions provided by <b>⎕CR</b>: |
| 5716 |
</p> |
| 5717 |
<div class="example"> |
| 5718 |
<pre class="example"> ⎕CR '' |
| 5719 |
</pre></div> |
| 5720 |
|
| 5721 |
<p><b>Definition</b>: A <i>byte vector</i> is an integer (!) vector with numbers |
| 5722 |
having a (signed or unsigned) 8-bit value (i.e. a value from -128 to 255 |
| 5723 |
inclusive). Such byte vectors are frequently used arguments and results |
| 5724 |
of <b>⎕FIO</b> functions. |
| 5725 |
</p> |
| 5726 |
<p>Let <b>Z←A ⎕CR B</b>. |
| 5727 |
</p> |
| 5728 |
<p>Then the left argument <b>A</b> of <b>⎕CR</b> selects one of several sub-functions |
| 5729 |
of <b>⎕CR</b>: |
| 5730 |
</p> |
| 5731 |
<ul> |
| 5732 |
<li> <b>A∈0 1 2 3 4 7 8 9 29</b>: various formatting styles (boxed, |
| 5733 |
APL input/output, etc.). Just try them out. |
| 5734 |
|
| 5735 |
</li><li> <b>A∈5 6</b>: convert byte vector B to a string of uppercase or lowercase |
| 5736 |
i hex digits respectively. Every byte in <b>B</b> becomes 2 characters |
| 5737 |
in <b>Z</b>. |
| 5738 |
|
| 5739 |
</li><li> <b>A=10</b>: convert variable named in <b>B</b> to an APL expression |
| 5740 |
producing it. |
| 5741 |
|
| 5742 |
</li><li> <b>A=11</b>: convert value <b>B</b> to byte vector <b>Z</b> in CDR ("Common Data |
| 5743 |
Representation", an IBM standard) format (similar to <b>3 ⎕TF</b>). |
| 5744 |
|
| 5745 |
</li><li> <b>A=12</b>: convert byte vector <b>B</b> in CDR format to value <b>Z</b>. |
| 5746 |
|
| 5747 |
</li><li> <b>A=13</b>: convert hex string <b>B</b> to byte vector <b>Z</b>. |
| 5748 |
|
| 5749 |
<p>If a conversion has an inverse conversion (like 12 being the inverse of 11) |
| 5750 |
then the inverse conversion can be expressed as the negative of the conversion |
| 5751 |
number. For example, <b>12 ⎕CR B</b> is the same as <b>¯11 ⎕CR B</b>. |
| 5752 |
</p> |
| 5753 |
</li><li> <b>A=14</b>: conversion 11 followed by conversion 13 (Value to hex string |
| 5754 |
in CDR format) |
| 5755 |
|
| 5756 |
</li><li> <b>A=15</b>: conversion 13 followed by conversion 12 (hex string in CDR |
| 5757 |
format to Value) |
| 5758 |
|
| 5759 |
</li><li> <b>A=16</b>: encode byte vector B into <b>Z</b> (base64 encoding, <b>RFC 4648</b>) |
| 5760 |
|
| 5761 |
</li><li> <b>A=17</b>: decode base64 vector <b>B</b> into byte vector <b>Z</b> (base64 |
| 5762 |
encoding, <b>RFC 4648</b>) |
| 5763 |
|
| 5764 |
</li><li> <b>A=18</b>: convert text vector <b>B</b> into byte vector <b>Z</b> (UTF8 encoding, |
| 5765 |
<b>RFC 3629</b>) |
| 5766 |
|
| 5767 |
</li><li> <b>A=19</b>: convert byte vector B into text vector <b>Z</b> (UTF8 encoding, |
| 5768 |
<b>RFC 3629</b>) |
| 5769 |
|
| 5770 |
</li><li> <b>A=20-25</b>: like 3,4,i or 7-9 but using a formatting similar to |
| 5771 |
NARS APL <b>⎕FMT</b> (showing the axis lengths as numbers instead of |
| 5772 |
<b>→</b> and <b>↓</b>) |
| 5773 |
|
| 5774 |
</li><li> <b>A=26</b>: <b>Z</b> is the cell types of the ravel elements of <b>B</b>, i.e. |
| 5775 |
<ul> |
| 5776 |
<li> <b>2</b>: character, |
| 5777 |
</li><li> <b>16</b>: integer, |
| 5778 |
</li><li> <b>32</b>: real number, |
| 5779 |
</li><li> <b>64</b>: complex number. |
| 5780 |
</li></ul> |
| 5781 |
|
| 5782 |
</li><li> <b>A=27</b>: Z[I] is the primary data representation (for example the |
| 5783 |
real part of a complex number, or the numerator of a rational number) |
| 5784 |
of B[I]. |
| 5785 |
|
| 5786 |
</li><li> <b>A=28</b>: Z[I] is the additional data representation (for example |
| 5787 |
the imaginary part of a complex number, or the denominator of a |
| 5788 |
rational number) of B[I]. |
| 5789 |
|
| 5790 |
</li><li> <b>A=30</b>: <b>Z</b> is B with all top-level elements conformed to a common |
| 5791 |
rank and shape (as required by the <b>⍤</b> operator). This conversion is |
| 5792 |
primarily used internally by the GNU APL interpreter. |
| 5793 |
|
| 5794 |
</li><li> <b>A∈31 32</b>: These conversions are used internally by <b>⎕INP</b>. |
| 5795 |
|
| 5796 |
</li><li> <b>A=33</b>: convert tagged byte vector to a TLV (Tag/Length/Value) |
| 5797 |
buffer. The TLV buffer can be sent over a byte stream (socket) and |
| 5798 |
easily decoded at the other end. Say <b>B = B[1], B[2], ..., B[n]</b> such |
| 5799 |
that <b>B1</b> is an Integer (the tag) and <b>B[j]</b> is a character in the |
| 5800 |
range 0-255 for j > 1. |
| 5801 |
Let <b>Z←33 ⎕CR B</b> with <b>Z = Z[1], Z[2], ... Z[m]</b>. Then <b>Z[1 2 3 4]</b> |
| 5802 |
is the 4 byte tag, <b>Z[5 6 7 8]</b> is the 4 byte data length |
| 5803 |
(n-1) = (m - 8), and <b>1↓B == 8 ↓ Z</b>. In other words, the first 4 bytes |
| 5804 |
of <b>Z</b> are the tag in big endian byte order, the next 4 bytes are the |
| 5805 |
length of <b>B</b> except the tag, and the rest of <b>Z</b> is <b>B</b> except |
| 5806 |
the tag. |
| 5807 |
|
| 5808 |
<p>Example: |
| 5809 |
</p><div class="example"> |
| 5810 |
<pre class="example"> Tag←55 ⍝ hex 37 |
| 5811 |
5 ⎕CR 33 ⎕CR Tag,'Value' |
| 5812 |
000000370000000556616C7565 |
| 5813 |
</pre></div> |
| 5814 |
|
| 5815 |
</li><li> <b>A=34</b>: this is the inverse of <b>33 ⎕CR</b>. The intended use for |
| 5816 |
<b>33 ⎕CR</b> and <b>34 ⎕CR</b> is the transmission of a tagged byte vector over |
| 5817 |
e.g a TCP socket: |
| 5818 |
|
| 5819 |
<pre class="verbatim"> Sender Receiver |
| 5820 |
────── ──────── |
| 5821 |
T,Data →→→ 33 ⎕CR T,Data →→→ TCP connection →→→ 34 ⎕CR T,Data →→→ T,Data |
| 5822 |
</pre> |
| 5823 |
<p>Example: |
| 5824 |
</p><div class="example"> |
| 5825 |
<pre class="example"> 34 ⎕CR ¯5 ⎕CR '000000370000000556616C7565' |
| 5826 |
55 Value |
| 5827 |
</pre></div> |
| 5828 |
|
| 5829 |
<p>The TLVs constructed by <b>33 ⎕CR</b> by the sender and decoded with |
| 5830 |
<b>34 ⎕CR</b> by the receiver can be sent back-to-back over a TCP connection |
| 5831 |
or similar in such a way that the receiver knows exactly after which byte |
| 5832 |
a TLV ends (and possibly the next TLV, if any, starts). This is perfect |
| 5833 |
for connections over which data is sent sporadically. <b>33 ⎕CR</b> and |
| 5834 |
<b>34 ⎕CR</b> are particularly useful for encoding and decoding TLV byte |
| 5835 |
buffers exchanged between GNU APL and processes that were forked by |
| 5836 |
GNU APL with <b>⎕FIO[57]</b> (aka. <b>fork()</b> and <b>execve()</b>). |
| 5837 |
</p> |
| 5838 |
</li><li> <b>A=35</b>: convert a string of lines (containing LF characters as line |
| 5839 |
delimiters) to a nested vector of lines. |
| 5840 |
|
| 5841 |
</li><li> <b>A=36</b>: the inverse of <b>⎕CR[35]</b>. Convert a nested vector of lines |
| 5842 |
to a string with lines terminated with LF characxters. |
| 5843 |
|
| 5844 |
</li><li> <b>A=37</b>: Same as <b>⎕CR B</b> but without removing any indentation. |
| 5845 |
|
| 5846 |
</li><li> <b>A=38</b>: Return an empty structured variable with (integer) |
| 5847 |
capacity <b>Bi</b>, or convert an N×2 matrix <b>B</b> to a structured variable. |
| 5848 |
|
| 5849 |
</li><li> <b>A=39</b>: convert a strucured variable <b>B</b> to an N×2 variable. |
| 5850 |
|
| 5851 |
</li><li> <b>A=40</b>: pack a boolean variable Bi (experimental). |
| 5852 |
|
| 5853 |
</li><li> <b>A=41</b>: unpack a boolean variable Bi (experimental). |
| 5854 |
|
| 5855 |
</li><li> <b>A=42</b>: tokenize the APL statement Bs. |
| 5856 |
|
| 5857 |
</li><li> <b>A=43</b>: parse the APL statement Bs. |
| 5858 |
|
| 5859 |
</li><li> <b>A=44</b>: decode the (integer) token tag B or the (nested) token B. |
| 5860 |
</li></ul> |
| 5861 |
|
| 5862 |
<p>Most dyadic <b>⎕CR</b> variants whose argument <b>B</b> is expected to be a byte |
| 5863 |
vector throw: |
| 5864 |
</p> |
| 5865 |
<ul> |
| 5866 |
<li> RANK ERROR if 1≠⍴⍴B |
| 5867 |
</li><li> DOMAIN ERROR if one of the B[j] is not a proper byte value |
| 5868 |
</li></ul> |
| 5869 |
|
| 5870 |
<p>A proper byte value is either an integer in the range -128...255 inclusive, |
| 5871 |
or a (Unicode) character with a code point between U+FF80 and U+FFFF |
| 5872 |
(inclusive, corresponding to a negative signed char in C/C++) or between |
| 5873 |
U+0000...U+00FF (inclusive, corresponding to an unsigned char or to a signed |
| 5874 |
positive char in C/C++). Real, Complex, or rational numbers are never proper |
| 5875 |
byte values even if their value is close to an integer. Nor are nested APL |
| 5876 |
values or values being assigned. |
| 5877 |
</p> |
| 5878 |
<p><b>⎕CR</b> is a function group, therefore its sub-functions can be selected with |
| 5879 |
a name. For example: monadic <b>⎕CR.hex_to_bytes</b> is the same as monadic |
| 5880 |
<b>⎕CR[13]</b> or dyadic <b>13 ⎕CR</b>. |
| 5881 |
</p> |
| 5882 |
<hr> |
| 5883 |
</div> |
| 5884 |
<div class="section" id="Dyadic-_2395FX-_0028Native-Functions_0029"> |
| 5885 |
<div class="header"> |
| 5886 |
<p> |
| 5887 |
Next: <a href="#g_t_2395ARG-_002d-Interpreter-command-line-arguments" accesskey="n" rel="next">⎕ARG - Interpreter command line arguments</a>, Previous: <a href="#Dyadic-_2395CR" accesskey="p" rel="prev">Dyadic ⎕CR</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 5888 |
</div> |
| 5889 |
<span id="Dyadic-_005b_003f_005dFX-_0028Native-Functions_0029"></span><h3 class="section">2.26 Dyadic ⎕FX (Native Functions)</h3> |
| 5890 |
|
| 5891 |
<p>A Native Function is a function that can be called in APL like a normal user |
| 5892 |
defined APL function, but is implemented in C++. |
| 5893 |
</p> |
| 5894 |
<p>A native function is created with A ⎕FX B. A is a string that is the |
| 5895 |
path of a shared library and B is the name of the function in APL. |
| 5896 |
</p> |
| 5897 |
<p>The GNU APL package contains a shared library file_io.so that contains the |
| 5898 |
implementation of a native function for reading and writing files (fopen(), |
| 5899 |
fclose(), ...), For example: |
| 5900 |
</p> |
| 5901 |
<div class="example"> |
| 5902 |
<pre class="example"> ⍝ fix native function in lib_file_io.so as FILE_IO |
| 5903 |
⍝ |
| 5904 |
'lib_file_io.so' ⎕FX 'FILE_IO' |
| 5905 |
FILE_IO |
| 5906 |
|
| 5907 |
⍝ show overview of sub-functions in FILE_IO |
| 5908 |
⍝ |
| 5909 |
FILE_IO '' |
| 5910 |
Functions provided by this library. |
| 5911 |
Assumes 'lib_file_io.so' ⎕FX 'FUN' |
| 5912 |
|
| 5913 |
Legend: e - error code |
| 5914 |
i - integer |
| 5915 |
h - file handle (integer) |
| 5916 |
s - string |
| 5917 |
A1, A2, ... nested vector with elements A1, A2, ... |
| 5918 |
|
| 5919 |
FUN '' print this text on stderr |
| 5920 |
'' FUN '' print this text on stdout |
| 5921 |
FUN[ 0] '' print this text on stderr |
| 5922 |
'' FUN[ 0] '' print this text on stdout |
| 5923 |
|
| 5924 |
Zi ← FUN[ 1] '' errno (of last call) |
| 5925 |
Zs ← FUN[ 2] Be strerror(Be) |
| 5926 |
Zh ← As FUN[ 3] Bs fopen(Bs, As) filename Bs mode As |
| 5927 |
Zh ← FUN[ 3] Bs fopen(Bs, "r") filename Bs |
| 5928 |
... |
| 5929 |
</pre></div> |
| 5930 |
|
| 5931 |
<p>Recent versions of GNU APL have replaced the native FILE_IO function above by |
| 5932 |
the system function ⎕FIO. ⎕FIO need not be ⎕FX’ed and is otherwise backward |
| 5933 |
compatible to the native function. New function numbers are, however, only |
| 5934 |
added to ⎕FIO and not to the old native function FILE_IO. The parameters of |
| 5935 |
the functions are described in the man pages for, e.g. strerror, fopen, ... |
| 5936 |
and are fairly obvious. |
| 5937 |
</p> |
| 5938 |
<p>Many functions in FILE_IO have byte vectors as arguments or return byte |
| 5939 |
vectors. A byte vector is an integer vector whose numbers fit into a byte |
| 5940 |
(so they are integers between -128 and 255). Often ⎕UCS and the functions in |
| 5941 |
dyadic ⎕CR are used to convert such byte vectors to/from, for example, |
| 5942 |
Unicode strings. |
| 5943 |
</p> |
| 5944 |
<p>The GNU APL package also contains other shared libraries as templates |
| 5945 |
for your own native functions. Copy one of the files |
| 5946 |
src/native/template_F0.cc (for niladic native functions), |
| 5947 |
src/native/template_F12.cc (for nomadic native functions), |
| 5948 |
src/native/template_OP1.cc (for monadic native operators), |
| 5949 |
or src/native/template_OP2/cc (for dyadic native operators) to your own |
| 5950 |
.cc file and adjust src/native/Makefile.am accordingly. |
| 5951 |
</p> |
| 5952 |
<p>Note: The )IN and )OUT commands of GNU APL support native functions, but |
| 5953 |
to do so they have to use dyadic ⎕FX. This renders the workspace |
| 5954 |
interchange file (.atf files) written by )OUT incompatible with all other |
| 5955 |
APL interpreters if the workspace contains native functions. The )OUT |
| 5956 |
command prints a warning when it is used with a workspace that contains |
| 5957 |
native functions. |
| 5958 |
</p> |
| 5959 |
<p>Note: As of GNU APL 1.6, the native function FILE_IO has been turned into the |
| 5960 |
system function ⎕FIO. The syntax of ⎕FIO is the same as for FILE_IO. The |
| 5961 |
)CLEAR workspace command will close all open files. |
| 5962 |
</p> |
| 5963 |
|
| 5964 |
<hr> |
| 5965 |
</div> |
| 5966 |
<div class="section" id="g_t_2395ARG-_002d-Interpreter-command-line-arguments"> |
| 5967 |
<div class="header"> |
| 5968 |
<p> |
| 5969 |
Next: <a href="#g_t_2395DLX-_002d-Knuth_0027s-Dancing-Links-Algorithm" accesskey="n" rel="next">⎕DLX - Knuth’s Dancing Links Algorithm</a>, Previous: <a href="#Dyadic-_2395FX-_0028Native-Functions_0029" accesskey="p" rel="prev">Dyadic ⎕FX (Native Functions)</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 5970 |
</div> |
| 5971 |
<span id="g_t_005b_003f_005dARG-_002d-Interpreter-command-line-arguments"></span><h3 class="section">2.27 ⎕ARG - Interpreter command line arguments</h3> |
| 5972 |
|
| 5973 |
<p><b>⎕ARG</b> contains the command line arguments with which GNU APL was invoked. |
| 5974 |
See <a href="#APL-Scripting">APL Scripting</a>. |
| 5975 |
</p> |
| 5976 |
<hr> |
| 5977 |
</div> |
| 5978 |
<div class="section" id="g_t_2395DLX-_002d-Knuth_0027s-Dancing-Links-Algorithm"> |
| 5979 |
<div class="header"> |
| 5980 |
<p> |
| 5981 |
Next: <a href="#g_t_2395ENV-_002d-Environment-Variables" accesskey="n" rel="next">⎕ENV - Environment Variables</a>, Previous: <a href="#g_t_2395ARG-_002d-Interpreter-command-line-arguments" accesskey="p" rel="prev">⎕ARG - Interpreter command line arguments</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 5982 |
</div> |
| 5983 |
<span id="g_t_005b_003f_005dDLX-_002d-Knuth_0027s-Dancing-Links-Algorithm"></span><h3 class="section">2.28 ⎕DLX - Knuth’s Dancing Links Algorithm</h3> |
| 5984 |
|
| 5985 |
<p>⎕DLX is an implementation of Donald Knuth’s Dancing Links Algorithm (called |
| 5986 |
DLX by Knuth himself, but is sometimes also referred to as Knuth’s Algorithm X). |
| 5987 |
⎕DLX is a generic backtracking machine that can be used to dramatically |
| 5988 |
simplify problems like the 8 queens problem on a chess board or sudokus. |
| 5989 |
</p> |
| 5990 |
<p>The monadic form of ⎕DLX, i.e. ⎕DLX B, is a shortcut for 0 ⎕DLX B. It |
| 5991 |
computes the first solution for the constraint matrix B. |
| 5992 |
</p> |
| 5993 |
<p>The dyadic form of ⎕DLX, i.e. A ⎕DLX B, has an integer scalar A as left |
| 5994 |
argument which determines the details of the computation as follows: |
| 5995 |
</p> |
| 5996 |
<p>A > 0: The algorithm tries to find all solutions, but stops when A solutions |
| 5997 |
have been found. This is handy while debugging code using ⎕DLX. The |
| 5998 |
result is a nested vector with one vector item per solution. |
| 5999 |
</p> |
| 6000 |
<p>A = 0: The algorithm stops when the first solution was found. In this case |
| 6001 |
the solution is a simple (non-nested) numeric vector. |
| 6002 |
</p> |
| 6003 |
<p>A = ¯1: like A > 0 but finding all solutions |
| 6004 |
</p> |
| 6005 |
<p>A = ¯2: like A = 0 but instead of returning the first solution, the number of |
| 6006 |
solutions (i.e. 0 or 1), the number of backtracks, and the number of |
| 6007 |
link dances is returned as a 3-element numeric vector. |
| 6008 |
</p> |
| 6009 |
<p>A = ¯3: like A = ¯1 but instead of returning all solutions, the number of |
| 6010 |
solutions, the number of backtracks, and the number of link dances is |
| 6011 |
returned as a 3-element numeric vector. |
| 6012 |
</p> |
| 6013 |
<p>A = ¯4: A number of single steps in Knuth’s Algorithm are performed. Let e.g. |
| 6014 |
A←¯4 r1 r2 r3. Then Z←A ⎕DLX B is the matrix B after 3 steps r1, r2, and r3 |
| 6015 |
have been performed. r1, r2, and r3 are valid (as per ⎕IO) row numbers of B, |
| 6016 |
and a step with a given row changes B as follows: |
| 6017 |
</p><ul> |
| 6018 |
<li> the given row is set to 0 (this row becomes part of the final result), |
| 6019 |
</li><li> all other rows that have a 1 or a 2 in the same column as B are set to 0 |
| 6020 |
(these 1s or 2s in the other rows conflict with the 1 or 2 in the given row |
| 6021 |
and are therefore removed from B), and |
| 6022 |
</li><li> all columns that have no 1s or 2s left are removed from B (these columns have |
| 6023 |
a 1 or 2 in B and the constraint is therefore satisfied). |
| 6024 |
</li></ul> |
| 6025 |
<p>The purpose of ¯4 ⎕DLX is: |
| 6026 |
</p><ul> |
| 6027 |
<li> To demonstrate how Knuth’s algorithm works, and/or |
| 6028 |
</li><li> To preset some initial values in B. For example, one can first initialize |
| 6029 |
the constraints for an empty Sudoku (which is the same matrix for all Sudokus) |
| 6030 |
and then enter the initial digits of a particular Sudoku using 4 ⎕DLX. If there are, say, 20 initial digits in the Sudoku then A has 21 elements (¯4 plus the |
| 6031 |
20 rows representing the 20 initial digits. The result of ¯4 ⎕DLX B has the |
| 6032 |
same number of rows as B (with some rows now cleared), but fewer columns than B. |
| 6033 |
</li></ul> |
| 6034 |
|
| 6035 |
<p>The right argument B of ⎕DLX B or A ⎕DLX B is a constraints matrix whose |
| 6036 |
columns consist of either 0s and 1s (called a primary column) or 0s and 2s |
| 6037 |
(called secondary columns). The 0s, 1s and 2s can be the integers 0, 1, or 2, |
| 6038 |
characters ’0’, ’1’, or ’2’ respectively, or ’ ’ meaning ’0’. The character |
| 6039 |
representation is useful when B becomes large and shall be printed because |
| 6040 |
the spaces in the numerical variant will not be printed. In the following, |
| 6041 |
B is assumed to be numeric. |
| 6042 |
</p> |
| 6043 |
<p>Let Z←A ⎕DLX B, and let R be a solution in Z, that is, Z itself (A = 0) or |
| 6044 |
R is Z[k] for some k if A ≠ 0. And let S←+⌿B[R]. |
| 6045 |
</p> |
| 6046 |
<p>Then S = s1 s2 s3, ... sN where N is the number of columns in B and sj=1 |
| 6047 |
if j is a primary column of B and sj∈0 1 if j is a secondary column of B. |
| 6048 |
</p> |
| 6049 |
<p>In other words, ⎕DLX B computes a subset of the rows of B in such a way that |
| 6050 |
for every column j of B exactly one (for primary column j) or at most one |
| 6051 |
(for a secondary column) of the rows in a solution has its j’th element set |
| 6052 |
to 1 and all other words set their j’th element set to 0. |
| 6053 |
</p> |
| 6054 |
<p>In yet other words, for every solution returned by ⎕DLX B, a 1 in one row |
| 6055 |
prevents all other rows that also have a 1 in that column, and all rows |
| 6056 |
together have exactly one 1 in every primary column and at most one 1 in |
| 6057 |
every secondary column. In the absence of secondary columns, the problem |
| 6058 |
solved by ⎕DLX is also known as the "exact cover problem" |
| 6059 |
</p> |
| 6060 |
<p>If all that sounds weird and useless, consider the following APL program |
| 6061 |
for finding all solutions of the 8 Queens problem on a chess board (which |
| 6062 |
probably every programmer has programmed at some point in time): |
| 6063 |
</p> |
| 6064 |
<div class="example"> |
| 6065 |
<pre class="example"> RC←8↑'1' ◊ D←15↑¯8↑'2' ⍝ helpers for constructing Q8 |
| 6066 |
⍝ rows cols diag1 diag2 |
| 6067 |
Q8←⊃{(R⌽RC),(C⌽RC),((C-R)⌽D),((¯7-R+C)⌽D)⊣(R C)←-8 8⊤⍵-⎕IO} ¨ ⍳64 |
| 6068 |
Z←¯1 ⎕DLX Q8 |
| 6069 |
{⎕UCS (65+⌊⍵÷8)(49+8∣⍵←⍵-⎕IO)} ¨ ⊃Z[1 2 3 92] ⍝ solutions 1, 2, 3, and 92 |
| 6070 |
A1 B5 C8 D6 G2 E3 F7 H4 |
| 6071 |
A1 B6 C8 D3 E7 F4 G2 H5 |
| 6072 |
A1 B7 C4 E8 D6 G5 F2 H3 |
| 6073 |
A8 B4 C1 D3 G7 E6 F2 H5 |
| 6074 |
|
| 6075 |
8 8⍴("+" "Q")[⎕IO+(⍳64)∈⊃Z[1]] ⍝ visualize solution Z[1] |
| 6076 |
Q + + + + + + + |
| 6077 |
+ + + + Q + + + |
| 6078 |
+ + + + + + + Q |
| 6079 |
+ + + + + Q + + |
| 6080 |
+ + Q + + + + + |
| 6081 |
+ + + + + + Q + |
| 6082 |
+ Q + + + + + + |
| 6083 |
+ + + Q + + + + |
| 6084 |
</pre></div> |
| 6085 |
|
| 6086 |
<p>Obviously Z contains solutions for the 8 Queens problem; the total number of |
| 6087 |
solutions is well known to be 92 and we showed only the first three and the |
| 6088 |
last solution above. |
| 6089 |
</p> |
| 6090 |
<p>The constraint matrix Q8 is the key to success. The matrix has 64 rows - one |
| 6091 |
row for every field of the chess board. And it has 8 + 8 + 15 + 15 columns. |
| 6092 |
The first 8 columns of Q8 are constraints that prevent more than one Queen |
| 6093 |
from being placed in the same row of the chess board (the argument ⍵ is the |
| 6094 |
field number counting from left to right and from bottom to top). |
| 6095 |
The next 8 columns of Q8 are constraints that prevent more than one Queen |
| 6096 |
from being placed in the same column of the chess board. |
| 6097 |
</p> |
| 6098 |
<p>If we would call ⎕DLX with only these constraints, i.e. ⎕DLX T8←64 16↑Q8, |
| 6099 |
then we would get the solutions of the 8 tower problem. However, we continue |
| 6100 |
and add 15 more constraints for each of the two diagonals. The resulting |
| 6101 |
constraint matrix Q8 is this: |
| 6102 |
</p> |
| 6103 |
<div class="example"> |
| 6104 |
<pre class="example"> Q8 |
| 6105 |
|
| 6106 |
1 1 2 2 |
| 6107 |
1 1 2 2 |
| 6108 |
1 1 2 2 |
| 6109 |
1 1 2 2 |
| 6110 |
1 1 2 2 |
| 6111 |
1 1 2 2 |
| 6112 |
1 1 2 2 |
| 6113 |
1 1 2 2 |
| 6114 |
1 1 2 2 |
| 6115 |
1 1 2 2 |
| 6116 |
1 1 2 2 |
| 6117 |
1 1 2 2 |
| 6118 |
1 1 2 2 |
| 6119 |
1 1 2 2 |
| 6120 |
1 1 2 2 |
| 6121 |
1 1 2 2 |
| 6122 |
1 1 2 2 |
| 6123 |
1 1 2 2 |
| 6124 |
1 1 2 2 |
| 6125 |
1 1 2 2 |
| 6126 |
1 1 2 2 |
| 6127 |
1 1 2 2 |
| 6128 |
1 1 2 2 |
| 6129 |
1 1 2 2 |
| 6130 |
1 1 2 2 |
| 6131 |
1 1 2 2 |
| 6132 |
1 1 2 2 |
| 6133 |
1 1 2 2 |
| 6134 |
1 1 2 2 |
| 6135 |
1 1 2 2 |
| 6136 |
1 1 2 2 |
| 6137 |
1 1 2 2 |
| 6138 |
1 1 2 2 |
| 6139 |
1 1 2 2 |
| 6140 |
1 1 2 2 |
| 6141 |
1 1 2 2 |
| 6142 |
1 1 2 2 |
| 6143 |
1 1 2 2 |
| 6144 |
1 1 2 2 |
| 6145 |
1 1 2 2 |
| 6146 |
1 1 2 2 |
| 6147 |
1 1 2 2 |
| 6148 |
1 1 2 2 |
| 6149 |
1 1 2 2 |
| 6150 |
1 1 2 2 |
| 6151 |
1 1 2 2 |
| 6152 |
1 1 2 2 |
| 6153 |
1 1 2 2 |
| 6154 |
1 1 2 2 |
| 6155 |
1 1 2 2 |
| 6156 |
1 1 2 2 |
| 6157 |
1 1 2 2 |
| 6158 |
1 1 2 2 |
| 6159 |
1 1 2 2 |
| 6160 |
1 1 2 2 |
| 6161 |
1 1 2 2 |
| 6162 |
11 2 2 |
| 6163 |
1 1 2 2 |
| 6164 |
1 1 2 2 |
| 6165 |
1 1 2 2 |
| 6166 |
1 1 2 2 |
| 6167 |
1 1 2 2 |
| 6168 |
1 1 2 2 |
| 6169 |
1 1 2 2 |
| 6170 |
</pre></div> |
| 6171 |
|
| 6172 |
<p>To see what, for example, the first solution looks like and how it relates |
| 6173 |
to the constraints matrix Q8: |
| 6174 |
</p> |
| 6175 |
<div class="example"> |
| 6176 |
<pre class="example"> ⍝ the rows in Q8 of the first solution |
| 6177 |
⍝ |
| 6178 |
Z[1] |
| 6179 |
1 14 24 27 39 44 50 61 |
| 6180 |
|
| 6181 |
⍝ the first solution translated back into the problem domain |
| 6182 |
⍝ |
| 6183 |
{⎕UCS (65+⌊⍵÷8)(49+8∣⍵←⍵-⎕IO)} ¨ ⊃Z[1] |
| 6184 |
A1 B6 C8 D3 E7 F4 G2 H5 |
| 6185 |
|
| 6186 |
⍝ the constraints of the rows of the first solution |
| 6187 |
⍝ |
| 6188 |
Q8[⊃Z[1];] |
| 6189 |
1 1 2 2 |
| 6190 |
1 1 2 2 |
| 6191 |
1 1 2 2 |
| 6192 |
1 1 2 2 |
| 6193 |
1 1 2 2 |
| 6194 |
1 1 2 2 |
| 6195 |
1 1 2 2 |
| 6196 |
1 1 2 2 |
| 6197 |
|
| 6198 |
⍝ all primary constraints met? |
| 6199 |
⍝ |
| 6200 |
+⌿ ' '≠ Q8[⊃Z[1];] |
| 6201 |
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 0 1 1 1 1 0 1 0 1 1 0 0 0 0 0 1 1 1 1 1 1 |
| 6202 |
1 0 0 0 0 1 |
| 6203 |
</pre></div> |
| 6204 |
|
| 6205 |
<p>And that’s it: call ⎕DLX to get the solution(s). In general all problems that |
| 6206 |
can be solved by ⎕DLX contain 3 steps: |
| 6207 |
</p> |
| 6208 |
<ul> |
| 6209 |
<li> translate the problem into a constraints matrix B, |
| 6210 |
</li><li> Z←⎕DLX B, and |
| 6211 |
</li><li> translate the result Z back into the problem domain. |
| 6212 |
</li></ul> |
| 6213 |
|
| 6214 |
<p>Another application of ⎕DLX is solving sudokus. The constraints matrix is |
| 6215 |
a little more complicated, but the principle is the same. GNU APL is shipped |
| 6216 |
with two workspaces: sudoku.apl (which solves sudokus without using ⎕DLX) and |
| 6217 |
sudoku_DLX.apl (which solves sudokus using ⎕DLX). |
| 6218 |
</p> |
| 6219 |
|
| 6220 |
<hr> |
| 6221 |
</div> |
| 6222 |
<div class="section" id="g_t_2395ENV-_002d-Environment-Variables"> |
| 6223 |
<div class="header"> |
| 6224 |
<p> |
| 6225 |
Next: <a href="#g_t_2395FIO-_002d-File-I_002fO-Functions" accesskey="n" rel="next">⎕FIO - File I/O Functions</a>, Previous: <a href="#g_t_2395DLX-_002d-Knuth_0027s-Dancing-Links-Algorithm" accesskey="p" rel="prev">⎕DLX - Knuth’s Dancing Links Algorithm</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 6226 |
</div> |
| 6227 |
<span id="g_t_005b_003f_005dENV-_002d-Environment-Variables"></span><h3 class="section">2.29 ⎕ENV - Environment Variables</h3> |
| 6228 |
|
| 6229 |
<p>⎕ENV contains the environment variables of the process that is running |
| 6230 |
GNU APL. See <a href="#APL-Scripting">APL Scripting</a>. |
| 6231 |
</p> |
| 6232 |
<hr> |
| 6233 |
</div> |
| 6234 |
<div class="section" id="g_t_2395FIO-_002d-File-I_002fO-Functions"> |
| 6235 |
<div class="header"> |
| 6236 |
<p> |
| 6237 |
Next: <a href="#g_t_2395FFT-_002d-Fast-Fourier-Transform" accesskey="n" rel="next">⎕FFT - Fast Fourier Transform</a>, Previous: <a href="#g_t_2395ENV-_002d-Environment-Variables" accesskey="p" rel="prev">⎕ENV - Environment Variables</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 6238 |
</div> |
| 6239 |
<span id="g_t_005b_003f_005dFIO-_002d-File-I_002fO-Functions"></span><h3 class="section">2.30 ⎕FIO - File I/O Functions</h3> |
| 6240 |
|
| 6241 |
<p>As of GNU APL 1.6, the native function FILE_IO has been replaced by the |
| 6242 |
system function ⎕FIO. ⎕FIO normally takes a numeric axis argument which |
| 6243 |
selects one of many different functions, most of which are contained in |
| 6244 |
the standard C library. The arguments for these functions are usually the same |
| 6245 |
as the corresponding C functions and the man page for each function describes |
| 6246 |
the meaning of the arguments. |
| 6247 |
</p> |
| 6248 |
<p>For example, ⎕FIO[3] corresponds to fopen() and ’man fopen’ explains what fopen does (opening a file). |
| 6249 |
</p> |
| 6250 |
<p>Calling ⎕FIO monadically without an axis and with an empty right argument |
| 6251 |
shows a list of all functions provided by ⎕FIO: |
| 6252 |
</p> |
| 6253 |
<div class="example"> |
| 6254 |
<pre class="example"> ⎕FIO '' |
| 6255 |
Functions provided by ⎕FIO... |
| 6256 |
|
| 6257 |
Legend: a - address family, IPv4 address, port (or errno) |
| 6258 |
d - table of dirent structs |
| 6259 |
e - error code (integer as per errno.h) |
| 6260 |
h - file handle (integer) |
| 6261 |
i - integer |
| 6262 |
n - names (nested vector of strings) |
| 6263 |
s - string |
| 6264 |
u - time divisor: 1 - second |
| 6265 |
1000 - milli second |
| 6266 |
1000000 - micro second |
| 6267 |
y4 - seconds, wday, yday, dst ( |
| 6268 |
y67- year, mon, day, hour, minute, second, [dst] |
| 6269 |
y9 - year, mon, day, hour, minute, second, wday, yday, dst |
| 6270 |
A1, A2, ... nested vector with elements A1, A2, ... |
| 6271 |
|
| 6272 |
⎕FIO '' print this text on stderr |
| 6273 |
'' ⎕FIO '' print this text on stdout |
| 6274 |
⎕FIO[ 0] '' print this text on stderr |
| 6275 |
'' ⎕FIO[ 0] '' print this text on stdout |
| 6276 |
|
| 6277 |
Zi ← ⎕FIO[ 1] '' errno (of last call) |
| 6278 |
Zs ← ⎕FIO[ 2] Be strerror(Be) |
| 6279 |
Zh ← As ⎕FIO[ 3] Bs fopen(Bs, As) filename Bs mode As |
| 6280 |
Zh ← ⎕FIO[ 3] Bs fopen(Bs, "r") filename Bs |
| 6281 |
|
| 6282 |
File I/O functions: |
| 6283 |
|
| 6284 |
Ze ← ⎕FIO[ 4] Bh fclose(Bh) |
| 6285 |
Ze ← ⎕FIO[ 5] Bh errno (of last call on Bh) |
| 6286 |
Zi ← ⎕FIO[ 6] Bh fread(Zi, 1, 5000, Bh) 1 byte per Zi |
| 6287 |
Zi ← Ai ⎕FIO[ 6] Bh fread(Zi, 1, Ai, Bh) 1 byte per Zi |
| 6288 |
Zi ← Ai ⎕FIO[ 7] Bh fwrite(Ai, 1, ⍴Ai, Bh) 1 byte per Ai |
| 6289 |
Zi ← ⎕FIO[ 8] Bh fgets(Zi, 5000, Bh) 1 byte per Zi |
| 6290 |
Zi ← Ai ⎕FIO[ 8] Bh fgets(Zi, Ai, Bh) 1 byte per Zi |
| 6291 |
Zi ← ⎕FIO[ 9] Bh fgetc(Zi, Bh) 1 byte |
| 6292 |
Zi ← ⎕FIO[10] Bh feof(Bh) |
| 6293 |
Zi ← ⎕FIO[11] Bh ferror(Bh) |
| 6294 |
Zi ← ⎕FIO[12] Bh ftell(Bh) |
| 6295 |
Zi ← Ai ⎕FIO[13] Bh fseek(Bh, Ai, SEEK_SET) |
| 6296 |
Zi ← Ai ⎕FIO[14] Bh fseek(Bh, Ai, SEEK_CUR) |
| 6297 |
Zi ← Ai ⎕FIO[15] Bh fseek(Bh, Ai, SEEK_END) |
| 6298 |
Zi ← ⎕FIO[16] Bh fflush(Bh) |
| 6299 |
Zi ← ⎕FIO[17] Bh fsync(Bh) |
| 6300 |
Zi ← ⎕FIO[18] Bh fstat(Bh) |
| 6301 |
Zi ← ⎕FIO[19] Bh unlink(Bc) |
| 6302 |
Zi ← ⎕FIO[20] Bh mkdir(Bc, 0777) |
| 6303 |
Zi ← Ai ⎕FIO[20] Bh mkdir(Bc, AI) |
| 6304 |
Zi ← ⎕FIO[21] Bh rmdir(Bc) |
| 6305 |
Zi ← A ⎕FIO[22] 1 printf( A1, A2...) format A1 |
| 6306 |
Zi ← A ⎕FIO[22] 2 fprintf(stderr, A1, A2...) format A1 |
| 6307 |
Zi ← A ⎕FIO[22] Bh fprintf(Bh, A1, A2...) format A1 |
| 6308 |
Zi ← Ac ⎕FIO[23] Bh fwrite(Ac, 1, ⍴Ac, Bh) 1 Unicode per Ac, Output UTF8 |
| 6309 |
Zh ← As ⎕FIO[24] Bs popen(Bs, As) command Bs mode As |
| 6310 |
Zh ← ⎕FIO[24] Bs popen(Bs, "r") command Bs |
| 6311 |
Ze ← ⎕FIO[25] Bh pclose(Bh) |
| 6312 |
Zs ← ⎕FIO[26] Bs return entire file Bs as byte vector |
| 6313 |
Zs ← As ⎕FIO[27] Bs rename file As to Bs |
| 6314 |
Zd ← ⎕FIO[28] Bs return content of directory Bs |
| 6315 |
Zn ← ⎕FIO[29] Bs return file names in directory Bs |
| 6316 |
Zs ← ⎕FIO 30 getcwd() |
| 6317 |
Zn ← As ⎕FIO[31] Bs access(As, Bs) As ∈ 'RWXF' |
| 6318 |
Zh ← ⎕FIO[32] Bi socket(Bi=AF_INET, SOCK_STREAM, 0) |
| 6319 |
Ze ← Aa ⎕FIO[33] Bh bind(Bh, Aa) |
| 6320 |
Ze ← ⎕FIO[34] Bh listen(Bh, 10) |
| 6321 |
Ze ← Ai ⎕FIO[34] Bh listen(Bh, Ai) |
| 6322 |
Za ← ⎕FIO[35] Bh accept(Bh) |
| 6323 |
Ze ← Aa ⎕FIO[36] Bh connect(Bh, Aa) |
| 6324 |
Zi ← ⎕FIO[37] Bh recv(Bh, Zi, 5000, 0) 1 byte per Zi |
| 6325 |
Zi ← Ai ⎕FIO[37] Bh recv(Bh, Zi, Ai, 0) 1 byte per Zi |
| 6326 |
Zi ← Ai ⎕FIO[38] Bh send(Bh, Ai, ⍴Ai, 0) 1 byte per Ai |
| 6327 |
Zi ← Ac ⎕FIO[39] Bh send(Bh, Ac, ⍴Ac, 0) 1 Unicode per Ac, Output UTF8 |
| 6328 |
Zi ← ⎕FIO[40] B select(B_read, B_write, B_exception, B_timeout) |
| 6329 |
Zi ← ⎕FIO[41] Bh read(Bh, Zi, 5000) 1 byte per Zi |
| 6330 |
Zi ← Ai ⎕FIO[41] Bh read(Bh, Zi, Ai) 1 byte per Zi |
| 6331 |
Zi ← Ai ⎕FIO[42] Bh write(Bh, Ai, ⍴Ai) 1 byte per Ai |
| 6332 |
Zi ← Ac ⎕FIO[43] Bh write(Bh, Ac, ⍴Ac) 1 Unicode per Ac, Output UTF8 |
| 6333 |
Za ← ⎕FIO[44] Bh getsockname(Bh) |
| 6334 |
Za ← ⎕FIO[45] Bh getpeername(Bh) |
| 6335 |
Zi ← Ai ⎕FIO[46] Bh getsockopt(Bh, A_level, A_optname, Zi) |
| 6336 |
Ze ← Ai ⎕FIO[47] Bh setsockopt(Bh, A_level, A_optname, A_optval) |
| 6337 |
Ze ← As ⎕FIO[48] Bh fscanf(Bh, As) |
| 6338 |
Zs ← ⎕FIO[49] Bs return entire file Bs as nested lines |
| 6339 |
Zs ← LO ⎕FIO[49] Bs ⎕FIO[49] Bs and pipe each line through LO. |
| 6340 |
Zi ← ⎕FIO[50] Bu gettimeofday() |
| 6341 |
Zy4← ⎕FIO[51] By67 mktime(By67) Note: Jan 2, 2017 is: 2017 1 2 ... |
| 6342 |
Zy9← ⎕FIO[52] Bi localtime(Bi) Note: Jan 2, 2017 is: 2017 1 2 ... |
| 6343 |
Zy9← ⎕FIO[53] Bi gmtime(Bi) Note: Jan 2, 2017 is: 2017 1 2 ... |
| 6344 |
Zi ← ⎕FIO[54] Bs chdir(Bs) |
| 6345 |
Ze ← As ⎕FIO[55] Bh sscanf(Bs, As) As is the format string |
| 6346 |
Zs ← As ⎕FIO[56] Bs write nested lines As to file named Bs |
| 6347 |
|
| 6348 |
Benchmarking functions: |
| 6349 |
|
| 6350 |
⎕FIO[200] Bi clear statistics with ID Bi |
| 6351 |
Zn ← ⎕FIO[201] Bi get statistics with ID Bi |
| 6352 |
⎕FIO[202] Bs get monadic parallel threshold for primitive Bs |
| 6353 |
Ai ⎕FIO[202] Bs set monadic parallel threshold for primitive Bs |
| 6354 |
⎕FIO[203] Bs get dyadic parallel threshold for primitive Bs |
| 6355 |
Ai ⎕FIO[203] Bs set dyadic parallel threshold for primitive Bs |
| 6356 |
</pre></div> |
| 6357 |
|
| 6358 |
<p>A new feature of ⎕FIO (which is not available with the native function FILE_IO) |
| 6359 |
is ⎕FIO[49]. ⎕FIO[49] is a monadic operator which takes a monadic conversion |
| 6360 |
function as function argument. For example: |
| 6361 |
</p> |
| 6362 |
<div class="example"> |
| 6363 |
<pre class="example">Z←F ⎕FIO[49] 'filename' |
| 6364 |
</pre></div> |
| 6365 |
|
| 6366 |
<p>reads the file named filename line by line. For every line read, the conversion |
| 6367 |
function F is called and the result returned by F is enclosed and stored in Z. |
| 6368 |
In other words, |
| 6369 |
</p> |
| 6370 |
<div class="example"> |
| 6371 |
<pre class="example">Z←F ⎕FIO[49] 'filename' |
| 6372 |
</pre></div> |
| 6373 |
|
| 6374 |
<p>does: |
| 6375 |
</p> |
| 6376 |
<div class="example"> |
| 6377 |
<pre class="example">Z F¨Z←⎕FIO[49] 'filename' |
| 6378 |
</pre></div> |
| 6379 |
|
| 6380 |
|
| 6381 |
<hr> |
| 6382 |
</div> |
| 6383 |
<div class="section" id="g_t_2395FFT-_002d-Fast-Fourier-Transform"> |
| 6384 |
<div class="header"> |
| 6385 |
<p> |
| 6386 |
Next: <a href="#g_t_2395GTK-_002d-GTK-Interface" accesskey="n" rel="next">⎕GTK - GTK Interface</a>, Previous: <a href="#g_t_2395FIO-_002d-File-I_002fO-Functions" accesskey="p" rel="prev">⎕FIO - File I/O Functions</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 6387 |
</div> |
| 6388 |
<span id="g_t_005b_003f_005dFFT-_002d-Fast-Fourier-Transform"></span><h3 class="section">2.31 ⎕FFT - Fast Fourier Transform</h3> |
| 6389 |
|
| 6390 |
<p>For those interested in signal processing and the like, GNU APL provides ⎕FFT: |
| 6391 |
</p> |
| 6392 |
<p>The monadic form ⎕FFT B is a shortcut for the dyadic form 0 ⎕FFT B. It computes |
| 6393 |
the FFT of complex or real B without applying a window function. |
| 6394 |
</p> |
| 6395 |
<p>The dyadic form A ⎕FFT B provides more control over what ⎕FFT computes. A is |
| 6396 |
an integer scalar which falls into one of three ranges. |
| 6397 |
</p> |
| 6398 |
<p>The first range from ¯15 to ¯10 does not compute an FFT, but returns the result |
| 6399 |
of multiplying B with one of several window functions, that are frequently |
| 6400 |
used in the context of FFTs. The result has same shape as B and can be used for |
| 6401 |
analyzing or troubleshooting FFTs: |
| 6402 |
</p> |
| 6403 |
<ul> |
| 6404 |
<li> A=¯10: no FFT, return the Hann window applied to B |
| 6405 |
</li><li> A=¯11: no FFT, return the Hamming window applied to B |
| 6406 |
</li><li> A=¯12: no FFT, return the Blackman window applied to B |
| 6407 |
</li><li> A=¯13: no FFT, return the Blackman-Harris window applied to B |
| 6408 |
</li><li> A=¯14: no FFT, return the Blackman-Nuttal window applied to B |
| 6409 |
</li><li> A=¯15: no FFT, return the Flat-Top window applied to B |
| 6410 |
</li></ul> |
| 6411 |
|
| 6412 |
<p>The second range around 0 contains the computation of the forward and inverse |
| 6413 |
FFTs: |
| 6414 |
</p> |
| 6415 |
<ul> |
| 6416 |
<li> 0 ⎕FFT B returns the "normal" (aka. forward) FFT of the numeric array B. |
| 6417 |
</li><li> ¯1 ⎕FFT B returns the inverse FFT of the numeric array B. |
| 6418 |
</li></ul> |
| 6419 |
|
| 6420 |
<p>The third range from 10 to 15 corresponds to the first range and first |
| 6421 |
multiplies B with a window function and then computes the FFT: |
| 6422 |
</p> |
| 6423 |
<ul> |
| 6424 |
<li> A=10: FFT(B × Hann window) |
| 6425 |
</li><li> A=11: FFT(B × Hamming window) |
| 6426 |
</li><li> A=12: FFT(B × Blackman window) |
| 6427 |
</li><li> A=13: FFT(B × Blackman-Harris window) |
| 6428 |
</li><li> A=14: FFT(B × Blackman-Nuttal window) |
| 6429 |
</li><li> A=15: FFT(B × Flat-Top window) |
| 6430 |
</li></ul> |
| 6431 |
|
| 6432 |
<p>⍴⍴B can be 1 (one-dimensional FFT, the most common case) or more. The |
| 6433 |
implementation of ⎕FFT uses libfftw3, aka. "The fastest Fourier Transform in |
| 6434 |
the West." GNU APL checks the presence of libfftw3 when it is ./configure’d. |
| 6435 |
If libfftw3 is present then ⎕FFT will hopefully return the expected result; |
| 6436 |
if not then a SYNTAX ERROR will be raised when ⎕FFT is used. |
| 6437 |
</p> |
| 6438 |
<p>⎕FFT honors the presence of /etc/fftw/wisdom (see man fftw-wisdom) to speed |
| 6439 |
up the computations performed by ⎕FFT. Creating /etc/fftw/wisdom will take a |
| 6440 |
few hours, though, so that creating it will not pay off for most mortals. |
| 6441 |
</p> |
| 6442 |
|
| 6443 |
<hr> |
| 6444 |
</div> |
| 6445 |
<div class="section" id="g_t_2395GTK-_002d-GTK-Interface"> |
| 6446 |
<div class="header"> |
| 6447 |
<p> |
| 6448 |
Next: <a href="#g_t_2395JSON-_002d-JSON-Parsing" accesskey="n" rel="next">⎕JSON - JSON Parsing</a>, Previous: <a href="#g_t_2395FFT-_002d-Fast-Fourier-Transform" accesskey="p" rel="prev">⎕FFT - Fast Fourier Transform</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 6449 |
</div> |
| 6450 |
<span id="g_t_005b_003f_005dGTK-_002d-GTK-Interface"></span><h3 class="section">2.32 ⎕GTK - GTK Interface</h3> |
| 6451 |
|
| 6452 |
<p>GTK (Gimp ToolKit) is a rather powerful library for creating graphical user |
| 6453 |
interfaces (GUIs). ⎕GTK makes a subset of the almost 10000 functions in the |
| 6454 |
different GTK libraries available to GNU APL programs. With ⎕GTK a GNU APL |
| 6455 |
program can, for example, replace the somewhat crude ⎕ or ⍞ input methods |
| 6456 |
of standard APL with a more intuitive GUI. |
| 6457 |
</p> |
| 6458 |
<p>The details of using ⎕GTK would go far beyond the scope of this info manual |
| 6459 |
and has therefore been put into a separate document. |
| 6460 |
See: <b>HOWTOs/Quad-GTK.html</b>. |
| 6461 |
</p> |
| 6462 |
<hr> |
| 6463 |
</div> |
| 6464 |
<div class="section" id="g_t_2395JSON-_002d-JSON-Parsing"> |
| 6465 |
<div class="header"> |
| 6466 |
<p> |
| 6467 |
Next: <a href="#g_t_2395MAP-_002d-Map-Value" accesskey="n" rel="next">⎕MAP - Map Value</a>, Previous: <a href="#g_t_2395GTK-_002d-GTK-Interface" accesskey="p" rel="prev">⎕GTK - GTK Interface</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 6468 |
</div> |
| 6469 |
<span id="g_t_005b_003f_005dJSON-_002d-JSON-Parsing"></span><h3 class="section">2.33 ⎕JSON - JSON Parsing</h3> |
| 6470 |
|
| 6471 |
<p>GNU APL provides ⎕JSON for decoding and encoding JSON strings and files. |
| 6472 |
A (valid) JSON string is mapped to an APL value as follows: |
| 6473 |
</p> |
| 6474 |
<ul> |
| 6475 |
<li> JSON value ←→ structured or non-structured APL value |
| 6476 |
</li><li> JSON number ←→ APL number |
| 6477 |
</li><li> JSON string ←→ APL string |
| 6478 |
</li><li> JSON literal ←→ enclosed APL string (one of either ⊂’null’, ⊂’true’, |
| 6479 |
or ⊂’false’ ) |
| 6480 |
</li><li> JSON array ←→ APL vector |
| 6481 |
</li><li> JSON object ←→ structured APL value (associative array) |
| 6482 |
</li></ul> |
| 6483 |
|
| 6484 |
<ul class="section-toc"> |
| 6485 |
<li><a href="#Monadic-_2395JSON" accesskey="1">Monadic ⎕JSON</a></li> |
| 6486 |
<li><a href="#Dyadic-_2395JSON" accesskey="2">Dyadic ⎕JSON</a></li> |
| 6487 |
</ul> |
| 6488 |
<hr> |
| 6489 |
<div class="subsection" id="Monadic-_2395JSON"> |
| 6490 |
<div class="header"> |
| 6491 |
<p> |
| 6492 |
Next: <a href="#Dyadic-_2395JSON" accesskey="n" rel="next">Dyadic ⎕JSON</a>, Up: <a href="#g_t_2395JSON-_002d-JSON-Parsing" accesskey="u" rel="up">⎕JSON - JSON Parsing</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 6493 |
</div> |
| 6494 |
<span id="Monadic-_005b_003f_005dJSON"></span><h4 class="subsection">2.33.1 Monadic ⎕JSON</h4> |
| 6495 |
|
| 6496 |
<p>Z←⎕JSON B converts the string B into an APL value according to the mapping |
| 6497 |
above. If that fails then command )MORE provides information about the error |
| 6498 |
and where in B the error was detected. |
| 6499 |
</p> |
| 6500 |
<hr> |
| 6501 |
</div> |
| 6502 |
<div class="subsection" id="Dyadic-_2395JSON"> |
| 6503 |
<div class="header"> |
| 6504 |
<p> |
| 6505 |
Previous: <a href="#Monadic-_2395JSON" accesskey="p" rel="prev">Monadic ⎕JSON</a>, Up: <a href="#g_t_2395JSON-_002d-JSON-Parsing" accesskey="u" rel="up">⎕JSON - JSON Parsing</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 6506 |
</div> |
| 6507 |
<span id="Dyadic-_005b_003f_005dJSON"></span><h4 class="subsection">2.33.2 Dyadic ⎕JSON</h4> |
| 6508 |
|
| 6509 |
<p>Z←A ⎕JSON B performs one of the following conversions: |
| 6510 |
</p> |
| 6511 |
<ul> |
| 6512 |
<li> <b>Z←0 ⎕JSON B</b> is the same as monadic Z←⎕JSON B. |
| 6513 |
|
| 6514 |
</li><li> <b>Z←1 ⎕JSON B</b> is like Z←0 ⎕XML B, except that B is not the JSON |
| 6515 |
string itself but the name of a file from which a JSON string is read. |
| 6516 |
|
| 6517 |
</li><li> <b>Z←2 ⎕JSON B</b> is the inverse of Z←0 ⎕XML B. It converts an APL |
| 6518 |
value to a JSON string. |
| 6519 |
|
| 6520 |
</li><li> <b>Z←3 ⎕JSON B</b> is like 2 ⎕JSON B, except that the member names |
| 6521 |
(keys) of all JSON objects are sorted alphabetically. That is of little use |
| 6522 |
(but costs performance) if Z is not displayed but processed further, but |
| 6523 |
it could help troubleshooting when Z is displayed and the number of keys in Z |
| 6524 |
is large. |
| 6525 |
</li></ul> |
| 6526 |
|
| 6527 |
|
| 6528 |
<hr> |
| 6529 |
</div> |
| 6530 |
</div> |
| 6531 |
<div class="section" id="g_t_2395MAP-_002d-Map-Value"> |
| 6532 |
<div class="header"> |
| 6533 |
<p> |
| 6534 |
Next: <a href="#g_t_2395MX-_002d-Matrix_002fStatistics" accesskey="n" rel="next">⎕MX - Matrix/Statistics</a>, Previous: <a href="#g_t_2395JSON-_002d-JSON-Parsing" accesskey="p" rel="prev">⎕JSON - JSON Parsing</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 6535 |
</div> |
| 6536 |
<span id="g_t_005b_003f_005dMAP-_002d-Map-Value"></span><h3 class="section">2.34 ⎕MAP - Map Value</h3> |
| 6537 |
|
| 6538 |
<p>⎕MAP changes the ravel items of its right argument according to a mapping |
| 6539 |
table provided as its left argument. Let Z←A ⎕MAP B. |
| 6540 |
</p> |
| 6541 |
<p>The left argument A of Z←A ⎕MAP B shall be a N×2 matrix. Each 2-element row of |
| 6542 |
A, say A[J;], specifies a separate mapping A[J;1] → A[J;2]. The result Z has |
| 6543 |
the same shape as the right argument B. The items Z[...] of their result are |
| 6544 |
constructed from their corresponding items B[...] in B as follows: |
| 6545 |
</p> |
| 6546 |
<ul> |
| 6547 |
<li> if B[...] ≡ A[J;1] for some J then Z[...] is A[J;2]. |
| 6548 |
|
| 6549 |
</li><li> otherwise B[...] is different from all A[1;J] and then Z[...] is B[...] |
| 6550 |
|
| 6551 |
</li></ul> |
| 6552 |
|
| 6553 |
<p>In other words, Z is B, but with items of B found in A[;1] replaced by their |
| 6554 |
mapped item A[;2]. |
| 6555 |
</p> |
| 6556 |
<p>In practice the left argument A is frequently created from a literal APL value |
| 6557 |
such as 5 2⍴’eEwWaAzZ92’ in the example below. To simplify these cases, |
| 6558 |
A ⎕MAP B also accepts a vector instead of a N×2 matrix: |
| 6559 |
</p> |
| 6560 |
<p>A ⎕MAP B ←→ ((N 2)⍴A) ⎕MAP B if (2×N) ←→ ⍴A |
| 6561 |
</p> |
| 6562 |
<p>Examples: |
| 6563 |
</p> |
| 6564 |
<div class="example"> |
| 6565 |
<pre class="example"> ⍝ the map A |
| 6566 |
⊢A←5 2⍴'eEwWaAzZ92' |
| 6567 |
eE ⍝ map 'e' → 'E' |
| 6568 |
wW ⍝ map 'w' → 'W' |
| 6569 |
aA ⍝ map 'a' → 'A' |
| 6570 |
zZ ⍝ map 'z' → 'Z' |
| 6571 |
92 ⍝ map '9' → '2' |
| 6572 |
|
| 6573 |
⍝ the value B being mapped |
| 6574 |
⊢B←'Halloween' |
| 6575 |
Halloween |
| 6576 |
|
| 6577 |
⍝ the result of A ⎕MAP B |
| 6578 |
A ⎕MAP B |
| 6579 |
HAlloWEEn |
| 6580 |
|
| 6581 |
A←'eEwWaAzZ92' ⍝ vector A instead of N×2 matrix |
| 6582 |
A ⎕MAP B |
| 6583 |
HAlloWEEn |
| 6584 |
</pre></div> |
| 6585 |
|
| 6586 |
<p>NOTES: |
| 6587 |
</p><ul> |
| 6588 |
<li> The keys of the mapping A (i.e. the elements in column A[;1]) must be |
| 6589 |
unique. If they are not then the mapping is ambiguous and a DOMAIN ERROR |
| 6590 |
is raised. |
| 6591 |
|
| 6592 |
</li><li> Nested items in B: if an item of B is nested, then it is either equal to some |
| 6593 |
(also nested) key, say A[N;1], (in that case it is being mapped to A[N;2] in |
| 6594 |
the result), or it is different from all keys in A[;1] (and in that case the |
| 6595 |
corresponding item in the result is the item in B. |
| 6596 |
|
| 6597 |
</li><li> Nested items in A: if a key, say A[N;1], is nested and matches an equal (hence |
| 6598 |
also nested) item in B, then the corresponding item in the result will be |
| 6599 |
A[N;2] (which may or may not be nested). If a (nested or not nested) key A[N;1] |
| 6600 |
is equal to an item in B, then the corresponding item in the result will be |
| 6601 |
nested if A[N;2] is nested. If, for some N, the depths of A[N;1] and A[N;2] |
| 6602 |
differ, then depths of B and A ⎕MAP B may differ as well. That is, ⎕MAP |
| 6603 |
conserves the shape of B, but not necessarily the depth of B. |
| 6604 |
|
| 6605 |
</li><li> By default the mapping of B is non-recursive, i.e. the top-level items of |
| 6606 |
B are compared with the top-level keys A[;1], and nested keys and items of B |
| 6607 |
are handled as described above. |
| 6608 |
|
| 6609 |
<p>Sometimes, however, it is desirable to recursively descend into the nested |
| 6610 |
sub-values of B (though never of A). This can be achieved by enclosing A as |
| 6611 |
shown in the examples below. |
| 6612 |
</p></li></ul> |
| 6613 |
|
| 6614 |
<div class="example"> |
| 6615 |
<pre class="example"> A←5 2⍴'eEwWaAzZ92' |
| 6616 |
B←'Hal' 'low' 'een' ⍝ nested B |
| 6617 |
4 ⎕CR A ⎕MAP B ⍝ non-recursive (none of the keys in A[;1] matches) |
| 6618 |
┏→━━━━━━━━━━━━━━━━┓ |
| 6619 |
┃┏→━━┓ ┏→━━┓ ┏→━━┓┃ |
| 6620 |
┃┃Hal┃ ┃low┃ ┃een┃┃ |
| 6621 |
┃┗━━━┛ ┗━━━┛ ┗━━━┛┃ |
| 6622 |
┗∊━━━━━━━━━━━━━━━━┛ |
| 6623 |
|
| 6624 |
4 ⎕CR (⊂A) ⎕MAP B ⍝ recursive (some simple keys in A[;1] match) |
| 6625 |
┏→━━━━━━━━━━━━━━━━┓ |
| 6626 |
┃┏→━━┓ ┏→━━┓ ┏→━━┓┃ |
| 6627 |
┃┃HAl┃ ┃loW┃ ┃EEn┃┃ |
| 6628 |
┃┗━━━┛ ┗━━━┛ ┗━━━┛┃ |
| 6629 |
┗∊━━━━━━━━━━━━━━━━┛ |
| 6630 |
</pre></div> |
| 6631 |
|
| 6632 |
|
| 6633 |
<hr> |
| 6634 |
</div> |
| 6635 |
<div class="section" id="g_t_2395MX-_002d-Matrix_002fStatistics"> |
| 6636 |
<div class="header"> |
| 6637 |
<p> |
| 6638 |
Next: <a href="#g_t_2395PLOT-_002d-Plot-Data" accesskey="n" rel="next">⎕PLOT - Plot Data</a>, Previous: <a href="#g_t_2395MAP-_002d-Map-Value" accesskey="p" rel="prev">⎕MAP - Map Value</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 6639 |
</div> |
| 6640 |
<span id="g_t_005b_003f_005dMX-_002d-Matrix_002fStatistics"></span><h3 class="section">2.35 ⎕MX - Matrix/Statistics</h3> |
| 6641 |
|
| 6642 |
<p>⎕MX was kindly contributed by Henrik Moller |
| 6643 |
</p> |
| 6644 |
<p>⎕MX[x] is a system function that provides a collection of matrix and |
| 6645 |
statistical operations such as covariance, eigensystems, and so on, along |
| 6646 |
with random number generation in several statistical distributions. Particular |
| 6647 |
operations are selected through the use of the axis specifier <b>x</b>: |
| 6648 |
</p> |
| 6649 |
<div class="example"> |
| 6650 |
<pre class="example"> ⎕MX[1] B (monadic) Determinant |
| 6651 |
(A) ⎕MX[2] B (nomadic) Cross product |
| 6652 |
A ⎕MX[3] B (dyadic) Vector angle |
| 6653 |
⎕MX[4] B (monadic) Eigenvector |
| 6654 |
⎕MX[5] B (monadic) Eigenvalue |
| 6655 |
⎕MX[6] B (monadic) Ident |
| 6656 |
⎕MX[7] B (monadic) Rotation matrix |
| 6657 |
A ⎕MX[8] B (dyadic) Homogeneous transform |
| 6658 |
⎕MX[9] B (monadic) Norm |
| 6659 |
(A) ⎕MX[10] B (nomadic) Randoms |
| 6660 |
(A) ⎕MX[11] B (nomadic) Covariance |
| 6661 |
A ⎕MX[12] B (dyadic) Histogram |
| 6662 |
A ⎕MX[13] B (dyadic) Print |
| 6663 |
⎕MX[14] B (monadic) Set RNG seed |
| 6664 |
</pre></div> |
| 6665 |
|
| 6666 |
<p>(These may by shown by entering ⎕MX ” or ⎕MX[0]0 on the APL command line.) |
| 6667 |
In the function list above, <b>A</b> indicates a mandatory left argument, |
| 6668 |
while (<b>A</b>) indicates an optional left argument. The right argument <b>B</b> |
| 6669 |
of <b>⎕MX[X]</b> is always mandatory. |
| 6670 |
</p> |
| 6671 |
<ul class="section-toc"> |
| 6672 |
<li><a href="#Determinant" accesskey="1">Determinant</a></li> |
| 6673 |
<li><a href="#Cross-Product" accesskey="2">Cross Product</a></li> |
| 6674 |
<li><a href="#Vector-Angle" accesskey="3">Vector Angle</a></li> |
| 6675 |
<li><a href="#Eigenvector" accesskey="4">Eigenvector</a></li> |
| 6676 |
<li><a href="#Eigenvalue" accesskey="5">Eigenvalue</a></li> |
| 6677 |
<li><a href="#Ident" accesskey="6">Ident</a></li> |
| 6678 |
<li><a href="#Rotation" accesskey="7">Rotation</a></li> |
| 6679 |
<li><a href="#Homogeneous-transform" accesskey="8">Homogeneous transform</a></li> |
| 6680 |
<li><a href="#Norm" accesskey="9">Norm</a></li> |
| 6681 |
<li><a href="#Randoms">Randoms</a></li> |
| 6682 |
<li><a href="#Covariance">Covariance</a></li> |
| 6683 |
<li><a href="#Histograms">Histograms</a></li> |
| 6684 |
<li><a href="#Print">Print</a></li> |
| 6685 |
</ul> |
| 6686 |
<hr> |
| 6687 |
<div class="subsection" id="Determinant"> |
| 6688 |
<div class="header"> |
| 6689 |
<p> |
| 6690 |
Next: <a href="#Cross-Product" accesskey="n" rel="next">Cross Product</a>, Up: <a href="#g_t_2395MX-_002d-Matrix_002fStatistics" accesskey="u" rel="up">⎕MX - Matrix/Statistics</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 6691 |
</div> |
| 6692 |
<span id="Determinant-1"></span><h4 class="subsection">2.35.1 Determinant</h4> |
| 6693 |
|
| 6694 |
<p>The determinant operation, ⎕MX[1], is monadic and is valid only for |
| 6695 |
numeric arguments (real or complex) where ⍴⍴B = 2 and (1↑⍴B) = (¯1↑⍴B) |
| 6696 |
(i.e. a square matrix). For Example: |
| 6697 |
</p> |
| 6698 |
<div class="example"> |
| 6699 |
<pre class="example"> mx[1] 3 3⍴5 3 1 9 7j2 6 2 8 4j5 |
| 6700 |
¯164J76 |
| 6701 |
</pre></div> |
| 6702 |
|
| 6703 |
<hr> |
| 6704 |
</div> |
| 6705 |
<div class="subsection" id="Cross-Product"> |
| 6706 |
<div class="header"> |
| 6707 |
<p> |
| 6708 |
Next: <a href="#Vector-Angle" accesskey="n" rel="next">Vector Angle</a>, Previous: <a href="#Determinant" accesskey="p" rel="prev">Determinant</a>, Up: <a href="#g_t_2395MX-_002d-Matrix_002fStatistics" accesskey="u" rel="up">⎕MX - Matrix/Statistics</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 6709 |
</div> |
| 6710 |
<span id="Cross-Product-1"></span><h4 class="subsection">2.35.2 Cross Product</h4> |
| 6711 |
|
| 6712 |
<p>The cross product operation, ⎕MX[2], is nomadic. In monadic form, it |
| 6713 |
requires a numeric argument (real or complex) where ⍴⍴B = 2 and |
| 6714 |
(↑⍴B)+1 = (1↓⍴B), (i.e. a matrix of N-1 rows of length-N vectors). |
| 6715 |
For Example: |
| 6716 |
</p> |
| 6717 |
<div class="example"> |
| 6718 |
<pre class="example"> ⊢B←3 4⍴ 1 2 3j6 4 5 6 7 8 9 10 11 12 |
| 6719 |
1 2 3J6 4 |
| 6720 |
5 6 7 8 |
| 6721 |
9 10 11 12 |
| 6722 |
⎕MX[2] B |
| 6723 |
0J48 0J¯72 0 0J24 |
| 6724 |
</pre></div> |
| 6725 |
|
| 6726 |
<p>For reasons I’m not enough of a mathematician to understand, cross |
| 6727 |
products are only valid in 3-space and 7-space, so the only valid monadic |
| 6728 |
arguments are matrices of shapes [2 3] or [6 7]. However, ⎕MX, doesn’t |
| 6729 |
check this and will happily give you a result in any dimensionality thus |
| 6730 |
leaving it to your imagination what it may mean. I’m also not enough of a |
| 6731 |
mathematician to know what the significance may be of cross products |
| 6732 |
involving complex numbers and thus I can’t guarantee I’m using an |
| 6733 |
appropriate method to compute them. |
| 6734 |
</p> |
| 6735 |
<p>In dyadic form <b>A ⎕MX[2] B</b>, cross-product requires left and right |
| 6736 |
arguments to be numeric and ⍴⍴A = 1, ⍴⍴B = 1, ⍴A = 3, and ⍴B = 3: |
| 6737 |
</p> |
| 6738 |
<div class="example"> |
| 6739 |
<pre class="example"> 1 2 3j6 ⎕MX[2] 4 5 6 |
| 6740 |
¯3J¯30 6J24 ¯3 |
| 6741 |
</pre></div> |
| 6742 |
|
| 6743 |
<hr> |
| 6744 |
</div> |
| 6745 |
<div class="subsection" id="Vector-Angle"> |
| 6746 |
<div class="header"> |
| 6747 |
<p> |
| 6748 |
Next: <a href="#Eigenvector" accesskey="n" rel="next">Eigenvector</a>, Previous: <a href="#Cross-Product" accesskey="p" rel="prev">Cross Product</a>, Up: <a href="#g_t_2395MX-_002d-Matrix_002fStatistics" accesskey="u" rel="up">⎕MX - Matrix/Statistics</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 6749 |
</div> |
| 6750 |
<span id="Vector-Angle-1"></span><h4 class="subsection">2.35.3 Vector Angle</h4> |
| 6751 |
|
| 6752 |
<p>The vector angle operation ⎕MX[3] is dyadic and returns the angle between |
| 6753 |
two isomorphic real or complex vectors where ⍴⍴A = 1, ⍴⍴B = 1, and ⍴A = ⍴B: |
| 6754 |
</p> |
| 6755 |
<div class="example"> |
| 6756 |
<pre class="example"> (⍳8) ⎕MX[3] 4j4+⍳8 |
| 6757 |
0.2515670406J0.09930859532 |
| 6758 |
</pre></div> |
| 6759 |
|
| 6760 |
<hr> |
| 6761 |
</div> |
| 6762 |
<div class="subsection" id="Eigenvector"> |
| 6763 |
<div class="header"> |
| 6764 |
<p> |
| 6765 |
Next: <a href="#Eigenvalue" accesskey="n" rel="next">Eigenvalue</a>, Previous: <a href="#Vector-Angle" accesskey="p" rel="prev">Vector Angle</a>, Up: <a href="#g_t_2395MX-_002d-Matrix_002fStatistics" accesskey="u" rel="up">⎕MX - Matrix/Statistics</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 6766 |
</div> |
| 6767 |
<span id="Eigenvector-1"></span><h4 class="subsection">2.35.4 Eigenvector</h4> |
| 6768 |
|
| 6769 |
<p>The eigenvector operation, ⎕MX[4], is monadic and returns the complex |
| 6770 |
eigenvectors of real non-symetric square matrices: |
| 6771 |
</p> |
| 6772 |
<div class="example"> |
| 6773 |
<pre class="example"> B |
| 6774 |
¯1 1 ¯1 1 |
| 6775 |
¯8 4 ¯2 1 |
| 6776 |
27 9 3 1 |
| 6777 |
64 16 4 1 |
| 6778 |
⎕PP←4 |
| 6779 |
⎕MX[4] B |
| 6780 |
0.09988 0.1113 ¯0.2925 ¯0.9445 |
| 6781 |
0.04308J0.009687 ¯0.07091J0.1389 0.5166J¯0.01601 0.8396J0.04139 |
| 6782 |
0.04308J¯0.009687 ¯0.07091J¯0.1389 0.5166J0.01601 0.8396J¯0.04139 |
| 6783 |
¯0.1449 0.3566 0.9194 0.08118 |
| 6784 |
</pre></div> |
| 6785 |
|
| 6786 |
<p>where each row represents an eigenvector: |
| 6787 |
</p> |
| 6788 |
<div class="example"> |
| 6789 |
<pre class="example"> E←⎕MX[4] B |
| 6790 |
E[⎕IO;] ⍝ first vector |
| 6791 |
0.09988 0.1113 ¯0.2925 ¯0.9445 |
| 6792 |
E[⎕IO+1;] ⍝ second vector |
| 6793 |
0.04308J0.009687 ¯0.07091J0.1389 0.5166J¯0.01601 0.8396J0.04139 |
| 6794 |
etc. |
| 6795 |
</pre></div> |
| 6796 |
|
| 6797 |
<p>The eigenvalues are computed concurrently and the eignenvector matrix |
| 6798 |
is sorted according to the descending magnitude of the corresponding |
| 6799 |
eigenvalues. |
| 6800 |
</p> |
| 6801 |
<hr> |
| 6802 |
</div> |
| 6803 |
<div class="subsection" id="Eigenvalue"> |
| 6804 |
<div class="header"> |
| 6805 |
<p> |
| 6806 |
Next: <a href="#Ident" accesskey="n" rel="next">Ident</a>, Previous: <a href="#Eigenvector" accesskey="p" rel="prev">Eigenvector</a>, Up: <a href="#g_t_2395MX-_002d-Matrix_002fStatistics" accesskey="u" rel="up">⎕MX - Matrix/Statistics</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 6807 |
</div> |
| 6808 |
<span id="Eigenvalue-1"></span><h4 class="subsection">2.35.5 Eigenvalue</h4> |
| 6809 |
|
| 6810 |
<p>The eigenvalue operation, ⎕MX[5], is also monadic with an argument of |
| 6811 |
the same shape as that of the argument of the eigenvector operation. It |
| 6812 |
returns a sorted complex vector of eigenvalues of the matrix argument: |
| 6813 |
</p> |
| 6814 |
<div class="example"> |
| 6815 |
<pre class="example"> ⊢F←⎕MX[5] B |
| 6816 |
¯6.414 5.546J3.085 5.546J¯3.085 2.323 |
| 6817 |
</pre></div> |
| 6818 |
|
| 6819 |
<p>The order of eigen vectors, <b>E</b> from above, is related to the order of |
| 6820 |
the eigenvalues, <b>F</b>, by the relationship: |
| 6821 |
</p> |
| 6822 |
<div class="example"> |
| 6823 |
<pre class="example"> E[k;] ⬄ F[k] |
| 6824 |
</pre></div> |
| 6825 |
|
| 6826 |
<p>(Note that, from the above example: |
| 6827 |
</p> |
| 6828 |
<div class="example"> |
| 6829 |
<pre class="example"> |F |
| 6830 |
6.41391 6.346285607 6.346285607 2.3228 |
| 6831 |
</pre></div> |
| 6832 |
|
| 6833 |
<p>the order of the magnitude of the elements is descending, making the |
| 6834 |
initial eigenvector, <b>E[⎕IO;]</b>, the dominant eigenvector and each |
| 6835 |
successive eigenvector successively less significant.) |
| 6836 |
</p> |
| 6837 |
<p>Accordingly: |
| 6838 |
</p> |
| 6839 |
<div class="example"> |
| 6840 |
<pre class="example"> 4 ⎕CR (⊂⍉(1,⍴F)⍴F),(⊂E) |
| 6841 |
┏→━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ |
| 6842 |
┃┏→━━━━━━━━━━━━┓ ┏→━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓┃ |
| 6843 |
┃↓¯6.414 ┃ ↓ 0.09988 0.1113 ¯0.2925 ¯0.9445 ┃┃ |
| 6844 |
┃┃ 5.546J3.085 ┃ ┃ 0.04308J0.00969 ¯0.07091J0.139 0.5166J¯0.01601 0.8396J0.04139 ┃┃ |
| 6845 |
┃┃ 5.546J¯3.085┃ ┃ 0.04308J¯0.00969 ¯0.07091J¯0.139 0.5166J0.01601 0.8396J¯0.04139 ┃┃ |
| 6846 |
┃┃ 2.323 ┃ ┃ ¯0.1449 0.3566 0.9194 0.08118 ┃┃ |
| 6847 |
┃┗━━━━━━━━━━━━━┛ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛┃ |
| 6848 |
┗ϵ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ |
| 6849 |
Values Vectors |
| 6850 |
</pre></div> |
| 6851 |
|
| 6852 |
<hr> |
| 6853 |
</div> |
| 6854 |
<div class="subsection" id="Ident"> |
| 6855 |
<div class="header"> |
| 6856 |
<p> |
| 6857 |
Next: <a href="#Rotation" accesskey="n" rel="next">Rotation</a>, Previous: <a href="#Eigenvalue" accesskey="p" rel="prev">Eigenvalue</a>, Up: <a href="#g_t_2395MX-_002d-Matrix_002fStatistics" accesskey="u" rel="up">⎕MX - Matrix/Statistics</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 6858 |
</div> |
| 6859 |
<span id="Ident-1"></span><h4 class="subsection">2.35.6 Ident</h4> |
| 6860 |
|
| 6861 |
<p>The monadic ident operation, ⎕MX[6], takes a scalar real integer argument |
| 6862 |
and returns a square identity matrix of that size: |
| 6863 |
</p> |
| 6864 |
<div class="example"> |
| 6865 |
<pre class="example"> ⎕MX[6] 4 |
| 6866 |
1 0 0 0 |
| 6867 |
0 1 0 0 |
| 6868 |
0 0 1 0 |
| 6869 |
0 0 0 1 |
| 6870 |
</pre></div> |
| 6871 |
|
| 6872 |
<hr> |
| 6873 |
</div> |
| 6874 |
<div class="subsection" id="Rotation"> |
| 6875 |
<div class="header"> |
| 6876 |
<p> |
| 6877 |
Next: <a href="#Homogeneous-transform" accesskey="n" rel="next">Homogeneous transform</a>, Previous: <a href="#Ident" accesskey="p" rel="prev">Ident</a>, Up: <a href="#g_t_2395MX-_002d-Matrix_002fStatistics" accesskey="u" rel="up">⎕MX - Matrix/Statistics</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 6878 |
</div> |
| 6879 |
<span id="Rotation-1"></span><h4 class="subsection">2.35.7 Rotation</h4> |
| 6880 |
|
| 6881 |
<p>The rotation operation, ⎕MX[7], is monadic and takes a real or complex |
| 6882 |
scalar angle and returns a 2-space rotation matrix: |
| 6883 |
</p> |
| 6884 |
<div class="example"> |
| 6885 |
<pre class="example"> ⎕MX[7] ○30÷180 |
| 6886 |
0.866 ¯0.5 |
| 6887 |
0.5 0.866 |
| 6888 |
</pre></div> |
| 6889 |
|
| 6890 |
<hr> |
| 6891 |
</div> |
| 6892 |
<div class="subsection" id="Homogeneous-transform"> |
| 6893 |
<div class="header"> |
| 6894 |
<p> |
| 6895 |
Next: <a href="#Norm" accesskey="n" rel="next">Norm</a>, Previous: <a href="#Rotation" accesskey="p" rel="prev">Rotation</a>, Up: <a href="#g_t_2395MX-_002d-Matrix_002fStatistics" accesskey="u" rel="up">⎕MX - Matrix/Statistics</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 6896 |
</div> |
| 6897 |
<span id="Homogeneous-transform-1"></span><h4 class="subsection">2.35.8 Homogeneous transform</h4> |
| 6898 |
|
| 6899 |
<p>The homogeneous operation ⎕MX[8] is dyadic and takes as its left argument |
| 6900 |
a 3-space displacement vector and, as its right argument, a 3-space |
| 6901 |
elemental rotation (i.e., independent rotations around the X, Y, and Z axes |
| 6902 |
respectively) and returns the corresponding homogeneous matrix: |
| 6903 |
</p> |
| 6904 |
<div class="example"> |
| 6905 |
<pre class="example"> 1 2 3 ⎕MX[8] ○(30 45 60)÷180 |
| 6906 |
0.6124 0.2803 0.7392 0 |
| 6907 |
0.3536 0.7392 ¯0.5732 0 |
| 6908 |
¯0.7071 0.6124 0.3536 0 |
| 6909 |
1 2 3 1 |
| 6910 |
</pre></div> |
| 6911 |
|
| 6912 |
<hr> |
| 6913 |
</div> |
| 6914 |
<div class="subsection" id="Norm"> |
| 6915 |
<div class="header"> |
| 6916 |
<p> |
| 6917 |
Next: <a href="#Randoms" accesskey="n" rel="next">Randoms</a>, Previous: <a href="#Homogeneous-transform" accesskey="p" rel="prev">Homogeneous transform</a>, Up: <a href="#g_t_2395MX-_002d-Matrix_002fStatistics" accesskey="u" rel="up">⎕MX - Matrix/Statistics</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 6918 |
</div> |
| 6919 |
<span id="Norm-1"></span><h4 class="subsection">2.35.9 Norm</h4> |
| 6920 |
|
| 6921 |
<p>The monadic norm operation, ⎕MX[9], takes a real or complex non-scalar |
| 6922 |
numeric argument and returns a result of the same shape such that the sum |
| 6923 |
of the squares of the elements equals 1: |
| 6924 |
</p> |
| 6925 |
<div class="example"> |
| 6926 |
<pre class="example"> ⎕PP←10 |
| 6927 |
⎕MX[9] 1 2 3 4 |
| 6928 |
0.1825741858 0.3651483717 0.5477225575 0.7302967433 |
| 6929 |
(⎕MX[9] 1 2 3 4)*2 |
| 6930 |
0.03333333333 0.1333333333 0.3 0.5333333333 |
| 6931 |
+/(⎕MX[9] 1 2 3 4)*2 |
| 6932 |
1 |
| 6933 |
|
| 6934 |
⊢B←(3 3⍴⍳9)-⎕IO |
| 6935 |
0 1 2 |
| 6936 |
3 4 5 |
| 6937 |
6 7 8 |
| 6938 |
⎕MX[9] B |
| 6939 |
0 0.0700140042 0.1400280084 |
| 6940 |
0.2100420126 0.2800560168 0.350070021 |
| 6941 |
0.4200840252 0.4900980294 0.5601120336 |
| 6942 |
+/,(⎕MX[9] B)*2 |
| 6943 |
1 |
| 6944 |
</pre></div> |
| 6945 |
|
| 6946 |
<p>If the magnitude of the argument is zero, the operation returns an all-zero |
| 6947 |
result with the same shape as the argument. |
| 6948 |
</p> |
| 6949 |
|
| 6950 |
<hr> |
| 6951 |
</div> |
| 6952 |
<div class="subsection" id="Randoms"> |
| 6953 |
<div class="header"> |
| 6954 |
<p> |
| 6955 |
Next: <a href="#Covariance" accesskey="n" rel="next">Covariance</a>, Previous: <a href="#Norm" accesskey="p" rel="prev">Norm</a>, Up: <a href="#g_t_2395MX-_002d-Matrix_002fStatistics" accesskey="u" rel="up">⎕MX - Matrix/Statistics</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 6956 |
</div> |
| 6957 |
<span id="Randoms-1"></span><h4 class="subsection">2.35.10 Randoms</h4> |
| 6958 |
|
| 6959 |
<p>The nomadic randoms operation, <b>⎕MX[10]</b> or <b>⎕MX[10 x]</b> where <b>x</b> |
| 6960 |
is an integer specifying the distribution of the randoms generated. |
| 6961 |
At present, the distibutions supported are: |
| 6962 |
</p> |
| 6963 |
<ul> |
| 6964 |
<li> <b>x=0</b>: Normal distribution (default) |
| 6965 |
</li><li> <b>x=1</b>: Lognormal distribution |
| 6966 |
</li><li> <b>x=2</b>: Chi Squared distribution |
| 6967 |
</li><li> <b>x=3</b>: Student T distribution |
| 6968 |
</li></ul> |
| 6969 |
|
| 6970 |
<p>If <b>x</b> is not specified then the normal distribution is used. |
| 6971 |
</p> |
| 6972 |
<p>The right argument <b>B</b> of <b>⎕MX B</b> is a real or complex scalar |
| 6973 |
that specifies the desired standard deviation. If <b>B</b> is complex, |
| 6974 |
the value returned is also complex with random real and imaginary components. |
| 6975 |
</p> |
| 6976 |
<p>If the optional left argument <b>A</b> is specified, then <b>A</b> must be a |
| 6977 |
scalar integer and <b>Z←A ⎕MX B</b> and the operation returns a random vector |
| 6978 |
<b>Z</b> with <b>A = ⍴Z</b>. |
| 6979 |
</p> |
| 6980 |
<p>If a mean value is applicable for the selected distribution, then it is |
| 6981 |
set to <b>0</b>. |
| 6982 |
</p> |
| 6983 |
<div class="example"> |
| 6984 |
<pre class="example"> ⎕MX[10] 2 |
| 6985 |
¯1.0504575511 |
| 6986 |
⎕MX[10] 2 |
| 6987 |
¯2.9337180373 |
| 6988 |
5 ⎕MX[10] 2 |
| 6989 |
0.05154476627 3.80631021 2.455474045 3.165260688 0.6792784063 |
| 6990 |
⎕PP←4 |
| 6991 |
3 ⎕MX[10] 1j1 |
| 6992 |
¯1.134J¯1.453 1.111J¯0.1916 ¯1.106J¯0.9383 |
| 6993 |
</pre></div> |
| 6994 |
|
| 6995 |
<img src="MX_distributions.png" alt="MX_distributions"> |
| 6996 |
|
| 6997 |
<p>(This image is a plot of three 200-bucket histograms of 200000 samples |
| 6998 |
each of a normal distribution, a chi-square distribution, and a |
| 6999 |
Student T distribution. See Histograms below.) |
| 7000 |
</p> |
| 7001 |
<p>An initial seed may be specified with |
| 7002 |
</p> |
| 7003 |
<div class="example"> |
| 7004 |
<pre class="example"> ⎕MX[14] <seed> |
| 7005 |
</pre></div> |
| 7006 |
|
| 7007 |
<p>where <seed> is a single integer. This allows repeatable random sequences: |
| 7008 |
</p> |
| 7009 |
<div class="example"> |
| 7010 |
<pre class="example"> ⊣⎕MX[14] 3 |
| 7011 |
4 ⎕MX[10] 1 |
| 7012 |
¯1.358348261 ¯1.75175064 ¯2.009430519 ¯0.5167968281 |
| 7013 |
⊣⎕MX[14] 3 |
| 7014 |
4 ⎕MX[10] 1 |
| 7015 |
¯1.358348261 ¯1.75175064 ¯2.009430519 ¯0.5167968281 |
| 7016 |
</pre></div> |
| 7017 |
|
| 7018 |
<hr> |
| 7019 |
</div> |
| 7020 |
<div class="subsection" id="Covariance"> |
| 7021 |
<div class="header"> |
| 7022 |
<p> |
| 7023 |
Next: <a href="#Histograms" accesskey="n" rel="next">Histograms</a>, Previous: <a href="#Randoms" accesskey="p" rel="prev">Randoms</a>, Up: <a href="#g_t_2395MX-_002d-Matrix_002fStatistics" accesskey="u" rel="up">⎕MX - Matrix/Statistics</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 7024 |
</div> |
| 7025 |
<span id="Covariance-1"></span><h4 class="subsection">2.35.11 Covariance</h4> |
| 7026 |
|
| 7027 |
<p>The covariance operation, ⎕MX[11], is nomadic. In monadic form, it |
| 7028 |
interprets each row of a matrix argument as samples of a given |
| 7029 |
variable, computes the covariance of each sample set with respect to |
| 7030 |
every other sample set, and presents the covariances as a matrix. For |
| 7031 |
example: |
| 7032 |
</p> |
| 7033 |
<div class="example"> |
| 7034 |
<pre class="example"> ⊢B←3 4⍴?12⍴10 |
| 7035 |
5 8 1 9 |
| 7036 |
7 6 2 9 |
| 7037 |
6 5 10 4 |
| 7038 |
⎕PP←10 |
| 7039 |
⎕MX[11] B |
| 7040 |
12.91666667 9.333333333 ¯9.25 |
| 7041 |
9.333333333 8.666666667 ¯7.333333333 |
| 7042 |
¯9.25 ¯7.333333333 6.916666667 |
| 7043 |
</pre></div> |
| 7044 |
|
| 7045 |
<p>In dyadic form, it computes the covariance of the argument vectors: |
| 7046 |
</p> |
| 7047 |
<div class="example"> |
| 7048 |
<pre class="example"> 1 2j6 3 4 ⎕MX[11] 4 3 2j5 1 |
| 7049 |
¯1.666666667J¯2.5 |
| 7050 |
</pre></div> |
| 7051 |
|
| 7052 |
<p>In dyadic form, ⍴⍴A = 1, ⍴⍴B = 1, and ⍴A = ⍴B. |
| 7053 |
</p> |
| 7054 |
<p>Sample variance can be computed by supplying the same argument on the |
| 7055 |
left and right: |
| 7056 |
</p> |
| 7057 |
<div class="example"> |
| 7058 |
<pre class="example"> A← 6 7 10 13 14 14 18 19 22 24 |
| 7059 |
A ⎕MX[11] A ⍝ or ⎕MX[11]⍨ A |
| 7060 |
36.67777778 |
| 7061 |
</pre></div> |
| 7062 |
|
| 7063 |
<hr> |
| 7064 |
</div> |
| 7065 |
<div class="subsection" id="Histograms"> |
| 7066 |
<div class="header"> |
| 7067 |
<p> |
| 7068 |
Next: <a href="#Print" accesskey="n" rel="next">Print</a>, Previous: <a href="#Covariance" accesskey="p" rel="prev">Covariance</a>, Up: <a href="#g_t_2395MX-_002d-Matrix_002fStatistics" accesskey="u" rel="up">⎕MX - Matrix/Statistics</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 7069 |
</div> |
| 7070 |
<span id="Histograms-1"></span><h4 class="subsection">2.35.12 Histograms</h4> |
| 7071 |
|
| 7072 |
<p>The histogram operation, ⎕MX[12], is dyadic and requires a single integer |
| 7073 |
left argument (the number of buckets) and a real or complex vector as a |
| 7074 |
right argument (the samples). It then creates an equal-width-partition |
| 7075 |
histogram of the samples contained in the right-argument vector. The width |
| 7076 |
of each bucket is equal to the range of the samples, max - min, divided by |
| 7077 |
the number of buckets. If the samples are complex, the imaginary components |
| 7078 |
are ignored. As examples: |
| 7079 |
</p> |
| 7080 |
<div class="example"> |
| 7081 |
<pre class="example"> 4 ⎕MX[12] (⍳101)-⎕IO |
| 7082 |
25 25 25 26 |
| 7083 |
</pre></div> |
| 7084 |
|
| 7085 |
<p>The distribution curves above were the result of expressions like: |
| 7086 |
</p> |
| 7087 |
<div class="example"> |
| 7088 |
<pre class="example"> 200 ⎕MX[12] 200000 ⎕MX[10 0] 1 |
| 7089 |
</pre></div> |
| 7090 |
|
| 7091 |
<p>I.e. a 200-bucket histogram of a 200 thousand-member vector of |
| 7092 |
normally distributed samples with a standard deviation of 1. |
| 7093 |
</p> |
| 7094 |
<hr> |
| 7095 |
</div> |
| 7096 |
<div class="subsection" id="Print"> |
| 7097 |
<div class="header"> |
| 7098 |
<p> |
| 7099 |
Previous: <a href="#Histograms" accesskey="p" rel="prev">Histograms</a>, Up: <a href="#g_t_2395MX-_002d-Matrix_002fStatistics" accesskey="u" rel="up">⎕MX - Matrix/Statistics</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 7100 |
</div> |
| 7101 |
<span id="Print-1"></span><h4 class="subsection">2.35.13 Print</h4> |
| 7102 |
|
| 7103 |
<p>The print operation, ⎕MX[13], is dyadic and provides an easy way to |
| 7104 |
dump large quantities of data to files. It’s left argument is a |
| 7105 |
string containing the file name to be created or, if the name starts |
| 7106 |
with a “>”, appended to. The right argument may be a scalar, a |
| 7107 |
vector, a matrix, or a string. For example: |
| 7108 |
</p> |
| 7109 |
<div class="example"> |
| 7110 |
<pre class="example"> "samples.txt" ⎕MX[13] 34 |
| 7111 |
">samples.txt" ⎕MX[13] 3 4 |
| 7112 |
">samples.txt" ⎕MX[13] 3 4⍴⍳12 |
| 7113 |
">samples.txt" ⎕MX[13] "example line" |
| 7114 |
">samples.txt" ⎕MX[13] "example\nline" |
| 7115 |
</pre></div> |
| 7116 |
|
| 7117 |
<p>will create a file “samples.txt” containing: |
| 7118 |
</p> |
| 7119 |
<div class="example"> |
| 7120 |
<pre class="example">34 |
| 7121 |
3 4 |
| 7122 |
1 2 3 4 |
| 7123 |
5 6 7 8 |
| 7124 |
9 10 11 12 |
| 7125 |
example line |
| 7126 |
example |
| 7127 |
line |
| 7128 |
</pre></div> |
| 7129 |
|
| 7130 |
<p>Referring again to the distribution example, the plot data for that |
| 7131 |
was created by: |
| 7132 |
</p> |
| 7133 |
<div class="example"> |
| 7134 |
<pre class="example"> ∇ |
| 7135 |
[0] distro;v |
| 7136 |
[1] v←⍉1 200⍴200 ⎕MX[12] 200000 ⎕MX[10 0] 1 |
| 7137 |
[2] v←v,⍉1 200⍴200 ⎕MX[12] 200000 ⎕MX[10 2] 8 |
| 7138 |
[3] v←v,⍉1 200⍴200 ⎕MX[12] 200000 ⎕MX[10 3] 8 |
| 7139 |
[4] v ⎕MX[13] 'MX_distribution.data' |
| 7140 |
∇ |
| 7141 |
</pre></div> |
| 7142 |
|
| 7143 |
<p>which created a 200-by-3 matrix, v, and printed it to the file |
| 7144 |
MX_distribution.data, that being the format required for use by |
| 7145 |
gnuplot: |
| 7146 |
</p> |
| 7147 |
<div class="example"> |
| 7148 |
<pre class="example"> 1 48 0 |
| 7149 |
0 119 0 |
| 7150 |
0 187 0 |
| 7151 |
1 331 0 |
| 7152 |
0 500 0 |
| 7153 |
1 728 0 |
| 7154 |
0 977 0 |
| 7155 |
2 1161 0 |
| 7156 |
1 1475 0 |
| 7157 |
. |
| 7158 |
. |
| 7159 |
. |
| 7160 |
for 200 lines |
| 7161 |
</pre></div> |
| 7162 |
|
| 7163 |
<p>Instead of a filename, <b>⎕MX[13]</b> also accepts an integer scalar which should |
| 7164 |
be a file handle as returned by <b>⎕FIO[3]</b> aka. <b>⎕FIO.fopen</b>. This allows |
| 7165 |
e.g. for texts before and/or after the value(s) printed by <b>⎕MX[13]</b>. |
| 7166 |
For example: |
| 7167 |
</p> |
| 7168 |
<div class="example"> |
| 7169 |
<pre class="example"> Heading←⎕CR.string_to_UTF8 "Print: 10+⍳10\n\n" ⍝ a heading |
| 7170 |
Value←10 + ⍳10 ⍝ a value |
| 7171 |
Handle←"w" ⎕FIO.fopen "/tmp/test" ⍝ open file for writing |
| 7172 |
Heading ⎕FIO.fwrite Handle ⍝ write the heading |
| 7173 |
Handle ⎕MX.print Value ⍝ write the value |
| 7174 |
⎕FIO.fclose Handle ⍝ close the file |
| 7175 |
</pre></div> |
| 7176 |
|
| 7177 |
<p>which produces file <b>/tmp/test</b> with the following 3-line content: |
| 7178 |
</p> |
| 7179 |
<div class="example"> |
| 7180 |
<pre class="example">Print: 10+⍳10 |
| 7181 |
|
| 7182 |
11 12 13 14 15 16 17 18 19 20 |
| 7183 |
</pre></div> |
| 7184 |
|
| 7185 |
<hr> |
| 7186 |
</div> |
| 7187 |
</div> |
| 7188 |
<div class="section" id="g_t_2395PLOT-_002d-Plot-Data"> |
| 7189 |
<div class="header"> |
| 7190 |
<p> |
| 7191 |
Next: <a href="#g_t_2395PNG-_002d-Portable-Network-Graphics" accesskey="n" rel="next">⎕PNG - Portable Network Graphics</a>, Previous: <a href="#g_t_2395MX-_002d-Matrix_002fStatistics" accesskey="p" rel="prev">⎕MX - Matrix/Statistics</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 7192 |
</div> |
| 7193 |
<span id="g_t_005b_003f_005dPLOT-_002d-Plot-Data"></span><h3 class="section">2.36 ⎕PLOT - Plot Data</h3> |
| 7194 |
|
| 7195 |
<p>⎕PLOT is a function for visualizing numerical APL values. The values to be |
| 7196 |
plotted are provided as the right argument of ⎕PLOT while the optional |
| 7197 |
left argument controls details of the output, such as the plot window size, |
| 7198 |
colors for plot lines, points, and grids, etc. |
| 7199 |
</p> |
| 7200 |
<p>The general syntax of ⎕PLOT is: |
| 7201 |
</p> |
| 7202 |
<div class="example"> |
| 7203 |
<pre class="example"> ⎕PLOT ⍬ ⍝ show a list of attributes and their default values |
| 7204 |
H←⎕PLOT B ⍝ plot B with all attributes set to their default values |
| 7205 |
H←A ⎕PLOT B ⍝ plot B with specified default attributes overridden |
| 7206 |
⎕PLOT H ⍝ close the plot window with handle H |
| 7207 |
⎕PLOT 0 ⍝ verbosity: OFF (no debug output) |
| 7208 |
⎕PLOT ¯1 ⍝ verbosity: ON (print attribute values before plotting) |
| 7209 |
⎕PLOT ¯2 ⍝ verbosity: DEBUG (also print debug information) |
| 7210 |
⎕PLOT ¯3 ⍝ close all plot windows |
| 7211 |
⎕PLOT ¯6 ⍝ return all open plot window handles H |
| 7212 |
</pre></div> |
| 7213 |
|
| 7214 |
<ul class="section-toc"> |
| 7215 |
<li><a href="#The-Plot-Data-B" accesskey="1">The Plot Data B</a></li> |
| 7216 |
<li><a href="#The-Plot-Attributes-A" accesskey="2">The Plot Attributes A</a></li> |
| 7217 |
<li><a href="#Plot-Window-Handling" accesskey="3">Plot Window Handling</a></li> |
| 7218 |
<li><a href="#Output-File-Format" accesskey="4">Output File Format</a></li> |
| 7219 |
<li><a href="#GUI-driver" accesskey="5">GUI driver</a></li> |
| 7220 |
</ul> |
| 7221 |
<hr> |
| 7222 |
<div class="subsection" id="The-Plot-Data-B"> |
| 7223 |
<div class="header"> |
| 7224 |
<p> |
| 7225 |
Next: <a href="#The-Plot-Attributes-A" accesskey="n" rel="next">The Plot Attributes A</a>, Up: <a href="#g_t_2395PLOT-_002d-Plot-Data" accesskey="u" rel="up">⎕PLOT - Plot Data</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 7226 |
</div> |
| 7227 |
<span id="The-Plot-Data-B-1"></span><h4 class="subsection">2.36.1 The Plot Data B</h4> |
| 7228 |
|
| 7229 |
<p>The plot data <b>B</b> can be a vector (for a single plot line to be drawn) |
| 7230 |
or a matrix (in that case one plot line per matrix row is drawn, by default |
| 7231 |
in different colors). Each data item has to be numeric and represents one |
| 7232 |
point in the plot. The points that are adjacent in a row of the matrix are |
| 7233 |
connected by lines. By default plotted points are black and the lines |
| 7234 |
connecting them are green (for the first plot line). However, all colors |
| 7235 |
used, all diameters of points, and all thicknesses of the lines can be |
| 7236 |
fine-tuned by overriding the default values (see dyadic A ⎕PLOT B below). |
| 7237 |
</p> |
| 7238 |
<ul class="section-toc"> |
| 7239 |
<li><a href="#Complex-Plot-Data-B" accesskey="1">Complex Plot Data B</a></li> |
| 7240 |
<li><a href="#Real-Plot-Data-B" accesskey="2">Real Plot Data B</a></li> |
| 7241 |
</ul> |
| 7242 |
<hr> |
| 7243 |
<div class="subsubsection" id="Complex-Plot-Data-B"> |
| 7244 |
<div class="header"> |
| 7245 |
<p> |
| 7246 |
Next: <a href="#Real-Plot-Data-B" accesskey="n" rel="next">Real Plot Data B</a>, Up: <a href="#The-Plot-Data-B" accesskey="u" rel="up">The Plot Data B</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 7247 |
</div> |
| 7248 |
<span id="Complex-Plot-Data-B-1"></span><h4 class="subsubsection">2.36.1.1 Complex Plot Data B</h4> |
| 7249 |
|
| 7250 |
<p>If a data item B[N] or B[row;N] is <b>complex</b>, say B[N] = x + iy. then it is |
| 7251 |
placed (after some scaling) at position (x, y) of the plot. The X-range |
| 7252 |
[Xmin ... Xmax] of the plot is then determined by the real parts of B, |
| 7253 |
and the Y-range [Ymin ... Ymax] of the plot is determined by the imaginary |
| 7254 |
parts of B. That is: |
| 7255 |
</p> |
| 7256 |
<div class="example"> |
| 7257 |
<pre class="example">Xmin ← ⌊/,9○B ⍝ smallest real part of B |
| 7258 |
Xmax ← ⌈/,9○B ⍝ largest real part of B |
| 7259 |
Ymin ← ⌊/,11○B ⍝ smallest imaginary part of B |
| 7260 |
Ymax ← ⌈/,11○B ⍝ largest imaginary part of B |
| 7261 |
</pre></div> |
| 7262 |
|
| 7263 |
<p>Example (plot a circle (actually: a regular 20-gon)): |
| 7264 |
</p> |
| 7265 |
<div class="example"> |
| 7266 |
<pre class="example"> ⎕PLOT +⌿1 0J1×[1]1 2 ∘.○ (0,⍳2×N) × ○÷N←10 |
| 7267 |
</pre></div> |
| 7268 |
|
| 7269 |
<p>produces this plot window (only visible in the HTML version of this document; |
| 7270 |
in text mode see file <b>doc/PLOT_circle.png</b>): |
| 7271 |
</p> |
| 7272 |
<img src="PLOT_circle.png" alt="PLOT_circle"> |
| 7273 |
|
| 7274 |
<hr> |
| 7275 |
</div> |
| 7276 |
<div class="subsubsection" id="Real-Plot-Data-B"> |
| 7277 |
<div class="header"> |
| 7278 |
<p> |
| 7279 |
Previous: <a href="#Complex-Plot-Data-B" accesskey="p" rel="prev">Complex Plot Data B</a>, Up: <a href="#The-Plot-Data-B" accesskey="u" rel="up">The Plot Data B</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 7280 |
</div> |
| 7281 |
<span id="Real-Plot-Data-B-1"></span><h4 class="subsubsection">2.36.1.2 Real Plot Data B</h4> |
| 7282 |
|
| 7283 |
<p>On the other hand, if a data item B[N] or B[row;N] is <b>real</b>, then it is |
| 7284 |
placed at position (N, x) of the plot. The X-range is then |
| 7285 |
[⎕IO ... ⎕IO + ¯1↑⍴B] and the Y-range [Y<sub>min</sub> ... Y<sub>max</sub>] of the |
| 7286 |
plot is determined by the values of B. That is: |
| 7287 |
</p> |
| 7288 |
<div class="example"> |
| 7289 |
<pre class="example">Xmin ← ⎕IO ⍝ smallest real part of B |
| 7290 |
Xmax ← ¯1 + ⎕IO + ⍴B ⍝ largest real part of B |
| 7291 |
Ymin ← ⌊/,B ⍝ smallest value in B |
| 7292 |
Ymax ← ⌈/,B ⍝ largest value in B |
| 7293 |
</pre></div> |
| 7294 |
|
| 7295 |
<p>Example: |
| 7296 |
</p> |
| 7297 |
<div class="example"> |
| 7298 |
<pre class="example"> ⎕PLOT 0 1 ¯1 2 ¯2 3 ¯3 |
| 7299 |
</pre></div> |
| 7300 |
|
| 7301 |
<p>produces this plot window (only visible in the HTML version of this document; |
| 7302 |
in text mode see file <b>doc/PLOT_zigzag.png</b>): |
| 7303 |
</p> |
| 7304 |
<img src="PLOT_zigzag.png" alt="PLOT_zigzag"> |
| 7305 |
|
| 7306 |
<p>NOTE: In theory one can also mix real and complex values, even though doing so |
| 7307 |
makes little sense. If at least one item of the plot data B is complex, then |
| 7308 |
all real items in B are taken as complex with imaginary part 0. |
| 7309 |
</p> |
| 7310 |
<hr> |
| 7311 |
</div> |
| 7312 |
</div> |
| 7313 |
<div class="subsection" id="The-Plot-Attributes-A"> |
| 7314 |
<div class="header"> |
| 7315 |
<p> |
| 7316 |
Next: <a href="#Plot-Window-Handling" accesskey="n" rel="next">Plot Window Handling</a>, Previous: <a href="#The-Plot-Data-B" accesskey="p" rel="prev">The Plot Data B</a>, Up: <a href="#g_t_2395PLOT-_002d-Plot-Data" accesskey="u" rel="up">⎕PLOT - Plot Data</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 7317 |
</div> |
| 7318 |
<span id="The-Plot-Attributes-A-1"></span><h4 class="subsection">2.36.2 The Plot Attributes A</h4> |
| 7319 |
|
| 7320 |
<p>There are a number of attributes like colors, point sizes, line widths, |
| 7321 |
etc. that control how the resulting plot will look like. |
| 7322 |
</p> |
| 7323 |
<p>Similar to function groups like <b>⎕CR</b> or <b>⎕FIO</b>, an empty argument |
| 7324 |
<b>B</b> in monadic <b>⎕PLOT B</b> displays a list of the arguments. The list of |
| 7325 |
arguments grows over time and therefore the list displayed by <b>⎕PLOT ⍬</b> |
| 7326 |
may be more up-to-date than this description. For example: |
| 7327 |
</p> |
| 7328 |
<div class="example"> |
| 7329 |
<pre class="example"> ⎕PLOT '' |
| 7330 |
|
| 7331 |
⎕PLOT Usage: |
| 7332 |
|
| 7333 |
⎕PLOT B with ⍴⍴B > 0: plot B with default attribute values |
| 7334 |
⎕PLOT B with integer scalar B: special ⎕PLOT functions |
| 7335 |
A ⎕PLOT B plot B with attribute overrides specified by A |
| 7336 |
├──────── 0: verbosity OFF |
| 7337 |
├──────── ¯1: show X events |
| 7338 |
├──────── ¯2: show data |
| 7339 |
├──────── ¯3: close all windows |
| 7340 |
├──────── ¯4: show rendering |
| 7341 |
├─────── ¯6: show open handles |
| 7342 |
└──── N > 0: close window N |
| 7343 |
|
| 7344 |
A is a nested vector of strings. |
| 7345 |
Each string A[i] has the form "Attribute: Value" |
| 7346 |
Colors are specified either as #RGB or as #RRGGBB or as RR GG BB) |
| 7347 |
|
| 7348 |
The attributes understood by ⎕PLOT and their default values are: |
| 7349 |
|
| 7350 |
1. Global (plot window) Attributes: |
| 7351 |
|
| 7352 |
caption: ⎕PLOT (plot window caption) |
| 7353 |
output_filename: (output file name) |
| 7354 |
gui_driver: (GUI driver: GTK, XCB, or ASCII) |
| 7355 |
auto_close: 0 (= do not close X window automatically) |
| 7356 |
(1) (= close if file was written successfully) |
| 7357 |
(2) (= always close X window automatically) |
| 7358 |
with_border: 1 (= write plot area and window borders) |
| 7359 |
(0) (= write only plot area to output file) |
| 7360 |
pw_pos_X: 50 pixel (plot window position X) |
| 7361 |
pw_pos_Y: 50 pixel (plot window position Y) |
| 7362 |
border_width: 10 pixel (width of the window border) |
| 7363 |
pa_width: 600 pixel (plotarea width) |
| 7364 |
pa_height: 400 pixel (plotarea height) |
| 7365 |
pa_border_L: 50 pixel (pixels left of the plotarea) |
| 7366 |
pa_border_R: 20 pixel (pixels right of the plotarea) |
| 7367 |
pa_border_T: 25 pixel (pixels above the plotarea) |
| 7368 |
pa_border_B: 25 pixel (pixels below the plotarea) |
| 7369 |
gridX_style: 1 (X grid style = ──────── ) |
| 7370 |
(2) ( = ╴╴╴╴╴╴╴╴ ) |
| 7371 |
(3) ( = ─╴─╴─╴─╴ ) |
| 7372 |
axisX_arrow: 0 (X-axis arrow) |
| 7373 |
axisX_label: X (X-axis label) |
| 7374 |
axisY_arrow: 0 (Yaxis arrow) |
| 7375 |
axisY_label: Y (Y-axis label) |
| 7376 |
axisZ_arrow: 0 (Z-axis arrow) |
| 7377 |
axisZ_label: Z (Z-axis label) |
| 7378 |
gridX_pixels: 44 pixel (pixels between X grid lines) |
| 7379 |
gridX_variable: 0 (draw X grid (only) at plot points) |
| 7380 |
gridX_line_width: 1 pixel (thickness of the X-grid lines) |
| 7381 |
gridX_color: #000000 (color of the X-grid lines) |
| 7382 |
gridY_style: 1 (Y grid style, see gridX_style above) |
| 7383 |
gridY_pixels: 33 pixel (pixels between Y grid lines) |
| 7384 |
gridY_line_width: 1 pixel (thickness of the Y-grid lines) |
| 7385 |
gridY_color: #000000 (color of the Y-grid lines) |
| 7386 |
gridZ_style: 1 (Z grid style, see gridX_style above) |
| 7387 |
gridZ_pixels: 33 pixel (pixels between Z grid lines) |
| 7388 |
gridZ_line_width: 1 pixel (thickness of the Z-grid lines) |
| 7389 |
gridZ_color: #000000 (color of the Z-grid lines) |
| 7390 |
canvas_color: #FFFFFF (background color of the plot window) |
| 7391 |
legend_color: #F0F0F0 (background color of the legend) |
| 7392 |
legend_X: 50 pixel (the X position of the legend) |
| 7393 |
legend_Y: 50 pixel (the Y position of the legend) |
| 7394 |
legend_dY: 15 pixel (the distance between legend lines) |
| 7395 |
legend_lX: 50 pixel (the length of the legend lines) |
| 7396 |
rangeX_min: 0.0 (the start of the X range to be plotted) |
| 7397 |
rangeX_max: 0.0 (the end of the X range to be plotted) |
| 7398 |
rangeY_min: 0.0 (the start of the Y range to be plotted) |
| 7399 |
rangeY_max: 0.0 (the end of the Y range to be plotted) |
| 7400 |
rangeZ_min: 0.0 (the start of the Z range to be plotted) |
| 7401 |
rangeZ_max: 0.0 (the end of the Z range to be plotted) |
| 7402 |
origin_X: 100 pixel (X position offset of the origin) |
| 7403 |
origin_Y: 100 pixel (Y position offset of the origin) |
| 7404 |
format_X: (format for X-axis ticks (GTK only)) |
| 7405 |
%sT1%T2...%Tn (static texts for ticks) |
| 7406 |
%G, %g grid line number (starting at 1 or ) |
| 7407 |
%v value |
| 7408 |
%S seconds (SS) |
| 7409 |
%I minutes (MM) |
| 7410 |
%H, %h hours (HH or h/hh) |
| 7411 |
%D, %d day (DD or d/dd) |
| 7412 |
%M, %m month (MM or m/mm) |
| 7413 |
%q quarter (0..3) |
| 7414 |
%Q quarter (1..4) |
| 7415 |
%Y, %y year (YYYY or yy) |
| 7416 |
format_Y: (format for Y-axis (dito)) |
| 7417 |
format_Z: (format for Z-axis (dito)) |
| 7418 |
|
| 7419 |
color_level-P: (none) (color gradient at P% (surface plots only)) |
| 7420 |
|
| 7421 |
2. Local (plot line N) Attributes: |
| 7422 |
|
| 7423 |
line_color-N: #00FF00 (the color of plot line N) |
| 7424 |
line_style-N: 1 (line style, see gridX_style above) |
| 7425 |
line_width-N: 3 pixel (the thickness of plot line N) |
| 7426 |
point_color-N: #000000 (the color of the plot points) |
| 7427 |
point_style-N: 1 (= plot_points: ● ) |
| 7428 |
(2) (= plot_points: ▲ ) |
| 7429 |
(3) (= plot_points: ▼ ) |
| 7430 |
(4) (= plot_points: ◆ ) |
| 7431 |
(5) (= plot_points: ■ ) |
| 7432 |
(6) (= plot_points: ✚ (GTK only) |
| 7433 |
(7) (= plot_points: ✖ (GTK only) |
| 7434 |
point_size-N: 8 pixel (the outer diameter of the plot points) |
| 7435 |
point_size2-N: 0 pixel (the inner diameter of the plot points) |
| 7436 |
legend_name-N: (the name of plot line N in the legend) |
| 7437 |
</pre></div> |
| 7438 |
|
| 7439 |
<p>There are 2 kinds of attributes: <b>window attributes</b> that affect the entire |
| 7440 |
plot, and <b>line attributes</b> that affect one of the plot lines |
| 7441 |
(which correspond to one row of <b>B</b>). For example, the background color |
| 7442 |
of the plot is a window attribute, while the line color is a line attribute. |
| 7443 |
Line attributes have a <b>-N</b> suffix, where <b>N</b> starts at <b>⎕IO</b>. |
| 7444 |
</p> |
| 7445 |
<p>One way to specify |
| 7446 |
multiple attributes in one go is to use multi-line strings. |
| 7447 |
</p> |
| 7448 |
<p>For example (plot 2 lines of 10 random numbers each, named "random row 1" and |
| 7449 |
"random row 2"): |
| 7450 |
</p> |
| 7451 |
<div class="example"> |
| 7452 |
<pre class="example"> Data ← ?2 10⍴10 ⍝ two rows of random data |
| 7453 |
Attributes ← """ |
| 7454 |
legend_name-1: Random Row 1 |
| 7455 |
legend_name-2: Random Row 2 |
| 7456 |
""" |
| 7457 |
Attributes ⎕PLOT Data |
| 7458 |
</pre></div> |
| 7459 |
|
| 7460 |
<p>While specifying the plot attributes A in one place is most convenient for |
| 7461 |
a single plot window or when the attributes are read from some external |
| 7462 |
test file, it is sometimes simpler to specify the plot attributes |
| 7463 |
individually. This can be done by using a structured APL variable as left |
| 7464 |
argument A: |
| 7465 |
</p> |
| 7466 |
<div class="example"> |
| 7467 |
<pre class="example">Attributes.legend_name_1 ← "Random Row 1" |
| 7468 |
Attributes.legend_name_2 ← "Random Row 2" |
| 7469 |
Attributes ⎕PLOT Data |
| 7470 |
</pre></div> |
| 7471 |
|
| 7472 |
<p><b>PITFALL:</b> if <b>A</b> is specified as a structured APL Value then: |
| 7473 |
</p><ul> |
| 7474 |
<li> attribute names must follow the GNU APL member name syntax, and therefore |
| 7475 |
</li><li> the (line-) attribute name is separated from its line number by an |
| 7476 |
<b>_</b> (underscore), and |
| 7477 |
</li><li> string values must be quoted. |
| 7478 |
</li></ul> |
| 7479 |
|
| 7480 |
<ul> |
| 7481 |
<li> the (line-) attribute name is separated from its line number by a |
| 7482 |
<b>-</b> (minus), and |
| 7483 |
</li><li> string values must not be quoted. |
| 7484 |
</li></ul> |
| 7485 |
|
| 7486 |
<p>For example: |
| 7487 |
</p><div class="example"> |
| 7488 |
<pre class="example"> DATA ← 1○.1×⍳100 |
| 7489 |
⍝ structured variable A1 |
| 7490 |
⍝ |
| 7491 |
A1.point_style_1 ← 2 ⍝ separator: _ (underscore) |
| 7492 |
A1.gui_driver ← 'ASCII' ⍝ string value quoted |
| 7493 |
A1 ⎕PLOT DATA |
| 7494 |
|
| 7495 |
|
| 7496 |
⍝ multi-line string A2 |
| 7497 |
A2←««« |
| 7498 |
point_style-1: 2 ⍝ separator: - (minus) |
| 7499 |
gui_driver: ASCII ⍝ string value not quited |
| 7500 |
»»» |
| 7501 |
A2 ⎕PLOT DATA |
| 7502 |
|
| 7503 |
A2 ⎕PLOT 1○.1×⍳100 |
| 7504 |
A ⎕PLOT 1○.1×⍳100 |
| 7505 |
</pre></div> |
| 7506 |
|
| 7507 |
<p>If the global attribute <b>output_filename</b> is given, then the plot is |
| 7508 |
not only displayed in a window on the screen, but also written to a file |
| 7509 |
with the name of the file provided as the value of the attribute. |
| 7510 |
See <a href="#Eigenvector">Eigenvector</a> below. |
| 7511 |
</p> |
| 7512 |
<p>For example: |
| 7513 |
</p> |
| 7514 |
<div class="example"> |
| 7515 |
<pre class="example"> ⊣ ( ⊂ "output_filename: /tmp/bitmap.png" ) ⎕PLOT 1 3 1 4 2 |
| 7516 |
</pre></div> |
| 7517 |
|
| 7518 |
<p>writes the plot of a a zigzag curve to file <b>/tmp/bitmap.png</b>. |
| 7519 |
</p> |
| 7520 |
<p><b>Caution</b>: ⎕PLOT with attribute <b>output_filename</b> overwrites existing |
| 7521 |
files without any warning). Errors, most likely lack of permissions to write |
| 7522 |
the output file, raises a DOMAIN ERROR with )MORE possibly providing details |
| 7523 |
as to why the file could not be written. |
| 7524 |
</p> |
| 7525 |
<p>Some line attributes such as <b>line_width</b> or <b>point_size</b> are |
| 7526 |
frequently the same for several or even all plot lines. In that case one can |
| 7527 |
use the line attribute without a -N or _N suffix which is then used as the |
| 7528 |
default for all lines (unless overridden by the same attribute with -N or |
| 7529 |
_N suffix. |
| 7530 |
</p> |
| 7531 |
<p>For example: |
| 7532 |
</p> |
| 7533 |
<div class="example"> |
| 7534 |
<pre class="example">Attributes.line_width ← 2 ⍝ all plot lines: 2 pixels thick, |
| 7535 |
Attributes.line_width_2 ← 4 ⍝ except plot line 2: 4 pixels thick |
| 7536 |
</pre></div> |
| 7537 |
|
| 7538 |
<p>As of GNU APL 1.9, ⎕PLOT legends may be dragged to other locations within a |
| 7539 |
plot window using the usual click and drag GUI technique. |
| 7540 |
</p> |
| 7541 |
<ul class="section-toc"> |
| 7542 |
<li><a href="#Tick-formatting-_0028GTK-only_0029" accesskey="1">Tick formatting (GTK only)</a></li> |
| 7543 |
</ul> |
| 7544 |
<div class="subsubsection" id="Tick-formatting-_0028GTK-only_0029"> |
| 7545 |
<h4 class="subsubsection">2.36.2.1 Tick formatting (GTK only)</h4> |
| 7546 |
|
| 7547 |
<p>By default, the ticks on the X, Y, and Z axes show the naked value |
| 7548 |
of their corresponding coordinates. Sometimes you may want them to look a |
| 7549 |
little different, e.g. by adding units to the numbers. This can be achieved |
| 7550 |
with window properties <b>format_X/Y/Z</b>, possibly accompanied by property |
| 7551 |
<b>gridX_variable</b>. |
| 7552 |
</p> |
| 7553 |
<p>The properties <b>format_X/Y/Z</b> may be set to a format string that allows |
| 7554 |
the value that is being displayed at the ticks. The format is a string that |
| 7555 |
is a mix of static text and <b>tick items</b>. A <b>tick item</b> is computed |
| 7556 |
from the displayed value or from its position on the axis. There are |
| 7557 |
two different types of tick items: static and dynamic. |
| 7558 |
</p> |
| 7559 |
<p>A <b>static tick item</b> starts with <b>%s</b>, followed by one or more texts, |
| 7560 |
separated by %. The texts are displayed in the same order starting from |
| 7561 |
the origin and proceeding along the axis. For example: |
| 7562 |
</p> |
| 7563 |
<p>ATT.format_X ← ’%sT1%T2%T3’ |
| 7564 |
</p> |
| 7565 |
<p>will name X-axis ticks <b>T1</b>, <b>T2</b>, and <b>T3</b>, regardless of the X |
| 7566 |
coordinate. <b>static tick items</b> are the fallbacks for those cases where |
| 7567 |
<b>dynamic tick items</b> cannot produce the desired result. In other |
| 7568 |
words, <b>static tick items</b> must be constructed in APL beforehand. |
| 7569 |
</p> |
| 7570 |
<p>In contrast, <b>dynamic tick items</b> are computed from the value at the |
| 7571 |
axis, which is often simpler than computing them beforehand in APL. A |
| 7572 |
format string may contain 0 or more tick items which are used in a printf() |
| 7573 |
like manner. |
| 7574 |
</p> |
| 7575 |
<p>Most of the <b>dynamic tick items</b> (see <b>⎕PLOT ⍬</b> for a complete list) |
| 7576 |
are related to points in time (years, quarters, months, days, hours, minutes, |
| 7577 |
and seconds). For them the X coordinate (time) is, according to the *nix time |
| 7578 |
conventions, seconds since midnight 1970. Since this number of seconds is not |
| 7579 |
easy to compute in APL, <b>⎕FIO.secs_epoch</b> comes to rescue: |
| 7580 |
</p> |
| 7581 |
<div class="example"> |
| 7582 |
<pre class="example">Q1 ← ⎕FIO.secs_epoch 2023 2 15 ⍝ Feb. 15 (middle of Q1) 00:00:00 |
| 7583 |
</pre></div> |
| 7584 |
|
| 7585 |
<p>An example for plotting the quarterly values <b>1 3 4 2</b> is: |
| 7586 |
</p> |
| 7587 |
<div class="example"> |
| 7588 |
<pre class="example"> )CLEAR |
| 7589 |
|
| 7590 |
SPQ ← 91×24×60×60 ⍝ seconds per quarter |
| 7591 |
Q1 ← ⎕FIO.secs_epoch 2023 2 15 ⍝ Feb. 15 (middle of Q1) 00:00:00 |
| 7592 |
|
| 7593 |
X ← Q1 + SPQ×0 1 2 3 ⍝ middles of Q1, Q2, Q3, and Q4 |
| 7594 |
Y ← 1 3 2 4 ⍝ values for Q1, Q2, Q3, and Q4 |
| 7595 |
|
| 7596 |
ATT.format_X ← "Q-%Q/%y" ⍝ X-axis ticks: quarter and year |
| 7597 |
|
| 7598 |
ATT ⎕PLOT X + 0J1×Y |
| 7599 |
</pre></div> |
| 7600 |
|
| 7601 |
<p>Sometimes it is more convenient to display the exact X coordinates of the |
| 7602 |
plot points along the X axis instead of drawing an X-grid and visually |
| 7603 |
guessing the X-values between the vertical grid lines. This can be achieved |
| 7604 |
with setting <b>gridX_variable</b> to 1. Usually the X-coordinates are evenly |
| 7605 |
distributed along their axis while the Y and Z-coordinates are not. For this |
| 7606 |
reason there is no <b>gridY_variable</b> or <b>gridZ_variable</b>. |
| 7607 |
</p> |
| 7608 |
|
| 7609 |
<hr> |
| 7610 |
</div> |
| 7611 |
</div> |
| 7612 |
<div class="subsection" id="Plot-Window-Handling"> |
| 7613 |
<div class="header"> |
| 7614 |
<p> |
| 7615 |
Next: <a href="#Output-File-Format" accesskey="n" rel="next">Output File Format</a>, Previous: <a href="#The-Plot-Attributes-A" accesskey="p" rel="prev">The Plot Attributes A</a>, Up: <a href="#g_t_2395PLOT-_002d-Plot-Data" accesskey="u" rel="up">⎕PLOT - Plot Data</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 7616 |
</div> |
| 7617 |
<span id="Plot-Window-Handling-1"></span><h4 class="subsection">2.36.3 Plot Window Handling</h4> |
| 7618 |
|
| 7619 |
<p>Each call of ⎕PLOT with some plot data <b>B</b> opens a separate window in the X |
| 7620 |
server (which implies that ⎕PLOT requires X). That window runs in its own |
| 7621 |
thread until it is closed. A plot window can be closed in different ways: |
| 7622 |
</p> |
| 7623 |
<ul> |
| 7624 |
<li> interactively by clicking on the close button (often located near the |
| 7625 |
top-right corner) of the plot window, |
| 7626 |
</li><li> interactively by opening the drop down menu (if any) of the window |
| 7627 |
(near the top left-of the window) and selecting the menu option named |
| 7628 |
<b>Close</b>, |
| 7629 |
</li><li> programmatically from APL by calling <b>⎕PLOT ¯3</b> (which closes <b>all</b> |
| 7630 |
open plot windows), or |
| 7631 |
</li><li> programmatically from APL by calling <b>⎕PLOT H</b> (which closes a |
| 7632 |
specific plot window), where H is the plot window handle returned by |
| 7633 |
monadic <b>⎕PLOT B</b>, or by dyadic <b>A ⎕PLOT B</b> with plot attributes |
| 7634 |
<b>A</b> and plot data <b>B</b>. |
| 7635 |
</li></ul> |
| 7636 |
|
| 7637 |
<p>Note that the exact method for closing a plot window interactively with the |
| 7638 |
mouse or the keyboard (as opposed to programmatically with <b>⎕PLOT ¯3</b> or |
| 7639 |
<b>⎕PLOT H</b> from APL) differs between different window managers. The above |
| 7640 |
corresponds to the typical method(s) for closing windows on most systems. |
| 7641 |
</p> |
| 7642 |
<hr> |
| 7643 |
</div> |
| 7644 |
<div class="subsection" id="Output-File-Format"> |
| 7645 |
<div class="header"> |
| 7646 |
<p> |
| 7647 |
Next: <a href="#GUI-driver" accesskey="n" rel="next">GUI driver</a>, Previous: <a href="#Plot-Window-Handling" accesskey="p" rel="prev">Plot Window Handling</a>, Up: <a href="#g_t_2395PLOT-_002d-Plot-Data" accesskey="u" rel="up">⎕PLOT - Plot Data</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 7648 |
</div> |
| 7649 |
<span id="Output-File-Format-1"></span><h4 class="subsection">2.36.4 Output File Format</h4> |
| 7650 |
|
| 7651 |
<p>Early versions of ⎕PLOT were using <b>libxcb</b> to display the results of |
| 7652 |
⎕PLOT while recent versions use <b>libgtk-3</b>. The primary driver for this |
| 7653 |
change was the lack of full Unicode support in <b>libxcb</b> which made it, |
| 7654 |
for example, difficult to properly display APL characters in window captions |
| 7655 |
or in plot line legends. |
| 7656 |
</p> |
| 7657 |
<p>Writing the pixels of a plot to a file uses functions provided by either |
| 7658 |
<b>libxcb</b> or <b>libgtk-3</b>, and these functions generate different |
| 7659 |
file formats. |
| 7660 |
</p> |
| 7661 |
<p><b>libxcb</b> is the older of the two libraries and it therefore produces the |
| 7662 |
older file format <b>.bmp</b> (bitmaps). <b>libgtk-3</b> is the newer library and |
| 7663 |
it produces the somewhat newer file format <b>.png</b> (portable network |
| 7664 |
graphics). There are tools like <b>convert</b> from package <b>imagemagick</b> |
| 7665 |
that can be used to convert different image file formats into each other |
| 7666 |
and therefore this incompatibility should not cause too much trouble. |
| 7667 |
</p> |
| 7668 |
<p>For backward compatibility, the <b>libxcb</b> option for ⎕PLOT will continue |
| 7669 |
to exist for some time, but bug fixes and new features will only be made for |
| 7670 |
the <b>libgtk-3</b> option. |
| 7671 |
</p> |
| 7672 |
|
| 7673 |
<hr> |
| 7674 |
</div> |
| 7675 |
<div class="subsection" id="GUI-driver"> |
| 7676 |
<div class="header"> |
| 7677 |
<p> |
| 7678 |
Previous: <a href="#Output-File-Format" accesskey="p" rel="prev">Output File Format</a>, Up: <a href="#g_t_2395PLOT-_002d-Plot-Data" accesskey="u" rel="up">⎕PLOT - Plot Data</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 7679 |
</div> |
| 7680 |
<span id="GUI-driver-1"></span><h4 class="subsection">2.36.5 GUI driver</h4> |
| 7681 |
|
| 7682 |
<p><b>⎕PLOT</b> provides 3 different ways to generate its output, called |
| 7683 |
<i>GUI drivers</i>. Two of these drivers (<b>GTK and XCB</b>) are optional, |
| 7684 |
while third third driver <b>ASCII</b> is not. Optional means that the |
| 7685 |
<b>./configure</b> script, which is executed as the first step in the |
| 7686 |
compilation of GNU APL, determines if the prerequisite for an optional |
| 7687 |
driver are satisfied. IOW an optional driver is only available for <b>⎕PLOT</b> |
| 7688 |
if the libraries and C/C++ header files needed to compile the driver are |
| 7689 |
installed at the time where GNU APL is being compiled. The <b>ASCII</b> driver |
| 7690 |
merely generates ESC squences for VT100 terminals and does therefore not |
| 7691 |
depend on additional libraries. |
| 7692 |
</p> |
| 7693 |
<p>For the monadic <b>⎕PLOT B</b>, the driver used by <b>⎕PLOT</b> is chosen as follows: |
| 7694 |
</p> |
| 7695 |
<ul> |
| 7696 |
<li> GTK if available, otherwise |
| 7697 |
</li><li> XCB if available, otherwise |
| 7698 |
</li><li> ASCII |
| 7699 |
</li></ul> |
| 7700 |
|
| 7701 |
<p>For the dyadic <b>A ⎕PLOT B</b>, the driver used is the same, but the choice made |
| 7702 |
by <b>./configure</b> can be overridden by the plot window attribute |
| 7703 |
<b>gui_driver</b>. The default for this plot window attribute is empty, which |
| 7704 |
means that the decision of <b>./configure</b> shall be used (like in the monadic |
| 7705 |
case where no plot attributes can be specified). |
| 7706 |
</p> |
| 7707 |
<p>The plot driver also affects the type of result returned by <b>⎕PLOT</b>: |
| 7708 |
</p> |
| 7709 |
<ul> |
| 7710 |
<li> drivers <b>GTK</b> and <b>XCB</b> return an integer scalar <b>H</b> (a plot |
| 7711 |
window handle) that can later be used from APL to programmatically |
| 7712 |
close the plot window (i.e. with <b>⎕PLOT H</b>) with that handle. |
| 7713 |
(Alternatively a GTK or XCB plot window can be closed by clicking |
| 7714 |
the close button of the plot window). |
| 7715 |
|
| 7716 |
</li><li> driver <b>ASCII</b> returns a 3-dimensional APL value <b>Z</b>, where: |
| 7717 |
<ul> |
| 7718 |
<li> <b>Z[1;;]</b> is a character matrix with the Unicode characters used |
| 7719 |
to draw the plot window, |
| 7720 |
</li><li> <b>Z[2;;]</b> is an integer matrix with the the forground colors |
| 7721 |
(in terms of <b>VT100</b> terminal colors), and |
| 7722 |
</li><li> <b>Z[3;;]</b> is an integer matrix with the the backround colors |
| 7723 |
(again in terms of <b>VT100</b> terminal colors). |
| 7724 |
</li></ul> |
| 7725 |
</li></ul> |
| 7726 |
|
| 7727 |
<p>The <b>VT100</b> colors returnd by the ASCII driver are essentially 4-bit RGB |
| 7728 |
values with the following integer encoding: |
| 7729 |
</p> |
| 7730 |
<ul> |
| 7731 |
<li> <b>0 = 0b000</b>: (dark) black, |
| 7732 |
</li><li> <b>1 = 0b001</b>: (dark) red, |
| 7733 |
</li><li> <b>2 = 0b010</b>: (dark) green, |
| 7734 |
</li><li> <b>3 = 0b011</b>: (dark) yellow, |
| 7735 |
</li><li> <b>4 = 0b100</b>: (dark) blue, |
| 7736 |
</li><li> <b>5 = 0b101</b>: (dark) magenta, |
| 7737 |
</li><li> <b>6 = 0b110</b>: (dark) cyan, |
| 7738 |
</li><li> <b>7 = 0b111</b>: (dark) white (kind of grey), |
| 7739 |
<pre class="verbatim"></pre></li><li> <b>60 = 60 + 0b000</b>: bright black (another kind of grey), |
| 7740 |
</li><li> <b>61 = 60 + 0b001</b>: bright red, |
| 7741 |
</li><li> <b>62 = 60 + 0b010</b>: bright green, |
| 7742 |
</li><li> <b>63 = 60 + 0b011</b>: bright yellow, |
| 7743 |
</li><li> <b>64 = 60 + 0b100</b>: bright blue, |
| 7744 |
</li><li> <b>65 = 60 + 0b101</b>: bright magenta, |
| 7745 |
</li><li> <b>66 = 60 + 0b110</b>: bright cyan, and |
| 7746 |
</li><li> <b>67 = 60 + 0b111</b>: bright white |
| 7747 |
</li></ul> |
| 7748 |
|
| 7749 |
<p>The <b>ASCII</b> driver returns its result as a committed value (so that the |
| 7750 |
plot window is not drawn twice if the value is not assigned to a variable). |
| 7751 |
Naturally the <b>ASCII</b> driver can not support most of the <b>⎕PLOT</b> atrributes |
| 7752 |
like a true graphical driver like <b>GTK</b> or <b>XCB</b>. But at least the color |
| 7753 |
attributes are honored by rounding 3×8-bit RGB values to their nearest 4-bit |
| 7754 |
<b>VT100</b> color. |
| 7755 |
</p> |
| 7756 |
<p>Some terminal emulators have issues when characters are printed on the last |
| 7757 |
column of the terminal. This is addressed by a user preference named |
| 7758 |
<b>plot-ASCII-columns</b>, which should be set to one less the number of columns |
| 7759 |
of the terminal (so that the last columns in not written). |
| 7760 |
</p> |
| 7761 |
<p>Another preferencefor the ASCII driver that might be of interest is |
| 7762 |
<b>plot-ASCII-background</b>. It sets the background color for the terminal |
| 7763 |
if the Plot attribute canvas-color is not provided (e.g. in monadic ⎕PLOT |
| 7764 |
which has no plot attributes). |
| 7765 |
</p> |
| 7766 |
<p>The <b>XCB</b> driver was the first driver for <b>⎕PLOT</b> but has since become |
| 7767 |
somewhat obsolete. It has limitation when it comes to the display of texts |
| 7768 |
(in particular for APL characters). The long-term GNU APL design strategy |
| 7769 |
is therefore <b>GTK</b> in favor of the good old <b>XCB</b>. <b>XCB</b> will still |
| 7770 |
be supported for a while, but new features will only be added to the |
| 7771 |
<b>GTK</b> driver. |
| 7772 |
</p> |
| 7773 |
<hr> |
| 7774 |
</div> |
| 7775 |
</div> |
| 7776 |
<div class="section" id="g_t_2395PNG-_002d-Portable-Network-Graphics"> |
| 7777 |
<div class="header"> |
| 7778 |
<p> |
| 7779 |
Next: <a href="#g_t_2395PS-_002d-Print-Style" accesskey="n" rel="next">⎕PS - Print Style</a>, Previous: <a href="#g_t_2395PLOT-_002d-Plot-Data" accesskey="p" rel="prev">⎕PLOT - Plot Data</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 7780 |
</div> |
| 7781 |
<span id="g_t_005b_003f_005dPNG-_002d-Portable-Network-Graphics"></span><h3 class="section">2.37 ⎕PNG - Portable Network Graphics</h3> |
| 7782 |
|
| 7783 |
<p>Portable Network Graphics is a file format for images, defined in |
| 7784 |
<strong>RFC 2083</strong>. To quote the RFC: |
| 7785 |
</p> |
| 7786 |
<p><cite>The PNG format provides a portable, legally unencumbered, |
| 7787 |
well-compressed, well-specified standard for lossless bitmapped image files.</cite> |
| 7788 |
</p> |
| 7789 |
<ul class="section-toc"> |
| 7790 |
<li><a href="#The-GNU-APL-Color-Model" accesskey="1">The GNU APL Color Model</a></li> |
| 7791 |
<li><a href="#Monadic-_2395PNG" accesskey="2">Monadic ⎕PNG</a></li> |
| 7792 |
<li><a href="#Dyadic-_2395PNG" accesskey="3">Dyadic ⎕PNG</a></li> |
| 7793 |
<li><a href="#APL-Examples" accesskey="4">APL Examples</a></li> |
| 7794 |
</ul> |
| 7795 |
<hr> |
| 7796 |
<div class="subsection" id="The-GNU-APL-Color-Model"> |
| 7797 |
<div class="header"> |
| 7798 |
<p> |
| 7799 |
Next: <a href="#Monadic-_2395PNG" accesskey="n" rel="next">Monadic ⎕PNG</a>, Up: <a href="#g_t_2395PNG-_002d-Portable-Network-Graphics" accesskey="u" rel="up">⎕PNG - Portable Network Graphics</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 7800 |
</div> |
| 7801 |
<span id="The-GNU-APL-Color-Model-1"></span><h4 class="subsection">2.37.1 The GNU APL Color Model</h4> |
| 7802 |
|
| 7803 |
<p>An image is a rectangular matrix of <strong>Pixels</strong> which makes APL the |
| 7804 |
perfect language for manipulating images. In GNU APL (and also in the PNG |
| 7805 |
standard) a single pixel may have one, two, three, or four color components, |
| 7806 |
or short colors, as follows: |
| 7807 |
</p> |
| 7808 |
<ul> |
| 7809 |
<li> a pixel with <strong>one</strong> color defines an uncolored (grayscale) |
| 7810 |
pixel between black and white, |
| 7811 |
</li><li> a pixel with <strong>two</strong> colors defines a grayscale pixel between |
| 7812 |
black and white, and its opacity (see below), |
| 7813 |
</li><li> a pixel with <strong>three</strong> colors defines a colored pixel whose colors |
| 7814 |
are red, green and blue (or RGB for short), and |
| 7815 |
</li><li> a pixel with <strong>four</strong> colors defines an RGB pixel and its opacity |
| 7816 |
(RGBA for short). |
| 7817 |
</li></ul> |
| 7818 |
|
| 7819 |
<p>The opacity (sometimes called the "alpha channel" and abbreviated A in the |
| 7820 |
RGBA format) defines how transparent a pixel is; lower values cause the |
| 7821 |
background of a pixel to shine through while larger values make the pixel |
| 7822 |
more opaque. One important use of the alpha channel is images that shall |
| 7823 |
not appear rectangular (even though their underlying color matrix is). |
| 7824 |
For example, to display a red circle on top of something else, one can set |
| 7825 |
the opacity of the pixels inside the circle to their maximum (as to making |
| 7826 |
them fully opaque and completely hiding the background or some other image |
| 7827 |
below) and the pixels outside the circle to 0 (making them fully transparent). |
| 7828 |
</p> |
| 7829 |
<p>Since every pixel of an image may have 1, 2, 3, or 4 color components, the |
| 7830 |
representation of an image in APL is a three dimensional array |
| 7831 |
<strong>Image</strong> where: |
| 7832 |
</p> |
| 7833 |
<ul> |
| 7834 |
<li> <strong>(COLORS HEIGHT WIDTH) ← ⍴ IMAGE</strong>, |
| 7835 |
</li><li> <strong>COLORS</strong> is a number that determines <strong><em>general |
| 7836 |
format</em></strong> of the image (and, by chance, the number of its color components): |
| 7837 |
<ul> |
| 7838 |
<li> <strong>COLORS = 1</strong>: a grayscale image, |
| 7839 |
</li><li> <strong>COLORS = 2</strong>: a grayscale image with an alpha channel, |
| 7840 |
</li><li> <strong>COLORS = 3</strong>: a colored RGB (red/green/blue) image, or |
| 7841 |
</li><li> <strong>COLORS = 4</strong>: a colored RGB image with an alpha channel, |
| 7842 |
aka. RGBA) |
| 7843 |
</li></ul> |
| 7844 |
</li><li> <strong>Height</strong> is the number of pixels of the image in the vertical |
| 7845 |
direction, and |
| 7846 |
</li><li> <strong>Width</strong> is the number of pixels of the image in the horizontal |
| 7847 |
direction. |
| 7848 |
</li></ul> |
| 7849 |
|
| 7850 |
<p>Above is: <strong>WIDTH</strong> the number of pixels in the horizontal direction, |
| 7851 |
<strong>HEIGHT</strong> the number of the pixels in the vertical direction, and |
| 7852 |
<strong>COLORS</strong> the number of color components as above. For simplicity we |
| 7853 |
can treat the opacity as yet another color although, strictly speaking, it |
| 7854 |
is not. |
| 7855 |
</p> |
| 7856 |
<p>For an image I, the horizontal pixel position I[;;x] increases from left to |
| 7857 |
right and the vertical pixel position I[;y;] increases from top to bottom. |
| 7858 |
</p> |
| 7859 |
<p>In addition to the 4 general image formats above, the PNG standard allows |
| 7860 |
each format to have different resolutions (of 1-bit, 2-bit, 4-bit, 8-bit, |
| 7861 |
and 16-bit, even though not all combinations of image format and resolution |
| 7862 |
are permitted. For example, the lower resolutions (of 1-bit, 2-bit, or 4-bit) |
| 7863 |
are only permitted for grayscale images without alpha channel, 16-bit is |
| 7864 |
allowed for all images except those with a color table, and so on. |
| 7865 |
</p> |
| 7866 |
<p>In theory there are 20 different combinations of 4 general image formats and |
| 7867 |
5 resolutions of the color components. However, the PNG standard allows only |
| 7868 |
15 of them, in particular by permitting 1-bit, 2-bit, 4-bit resolutions only |
| 7869 |
for grayscale images without alpha channel. The GNU APL color model reduces |
| 7870 |
these 15 combinations further to the 4 general types with the following rules: |
| 7871 |
</p> |
| 7872 |
<ul> |
| 7873 |
<li> On input, i.e. when reading a PNG image file and producing the APL |
| 7874 |
array described above, the different resolutions allowed by the PNG standard |
| 7875 |
are normalized to a single range of real numbers between 0.0 and 1.0 (this |
| 7876 |
is by chance also the range used in the GTK standard used in ⎕PNG and ⎕PLOT). |
| 7877 |
</li><li> Also on input, images that use color tables (for compressing the |
| 7878 |
image to reduce the file size) are automatically expanded. The resulting |
| 7879 |
APL value is therefore independent of the use of color tables. |
| 7880 |
</li><li> On output, i.e. when storing the APL array in a PNG file, the |
| 7881 |
resolution is 8-bit by default. 8-bit is the only resolution which is valid |
| 7882 |
for all image formats in the PNG standard. |
| 7883 |
</li><li> Also on output, one may optionally specify a different resolution. |
| 7884 |
</li></ul> |
| 7885 |
|
| 7886 |
<p>In GNU APL, integers and floating point numbers take the same space in |
| 7887 |
memory. The advantage of smaller PNG files with lower resolutions would |
| 7888 |
therefore disappear as soon as converted to APL. On the other hand, the |
| 7889 |
disadvantage (primarily different max. values for different resolutions) |
| 7890 |
would remain. In the GNU APL color model a purely red RGB pixel has the same |
| 7891 |
value <strong>I[;y[x] ← 1.0 0.0 0.0</strong> regardless of resolution, which |
| 7892 |
simplifies matters considerably. In a PNG file that same red RGB pixel |
| 7893 |
would instead have either: |
| 7894 |
</p> |
| 7895 |
<ul> |
| 7896 |
<li> the value $01 0 0 in a 1-bit RGB image, or |
| 7897 |
</li><li> the value $03 0 0 in a 2-bit RGB image, or |
| 7898 |
</li><li> the value $07 0 0 in a 4-bit RGB image, or |
| 7899 |
</li><li> the value $FF 0 0 in a 8-bit RGB image, or |
| 7900 |
</li><li> the value $FFFF 0 0 in a 16-bit RGB image. |
| 7901 |
</li></ul> |
| 7902 |
|
| 7903 |
<p>It may be useful to note that the human eye can only distinguish around 120 |
| 7904 |
different colors, i.e. about 7 bits (for all color planes together). For this |
| 7905 |
reason 16-bit color components are quite an overkill and the 8-bit default |
| 7906 |
therefore should be more than sufficient for most purposes. |
| 7907 |
</p> |
| 7908 |
<hr> |
| 7909 |
</div> |
| 7910 |
<div class="subsection" id="Monadic-_2395PNG"> |
| 7911 |
<div class="header"> |
| 7912 |
<p> |
| 7913 |
Next: <a href="#Dyadic-_2395PNG" accesskey="n" rel="next">Dyadic ⎕PNG</a>, Previous: <a href="#The-GNU-APL-Color-Model" accesskey="p" rel="prev">The GNU APL Color Model</a>, Up: <a href="#g_t_2395PNG-_002d-Portable-Network-Graphics" accesskey="u" rel="up">⎕PNG - Portable Network Graphics</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 7914 |
</div> |
| 7915 |
<span id="Monadic-_005b_003f_005dPNG"></span><h4 class="subsection">2.37.2 Monadic ⎕PNG</h4> |
| 7916 |
|
| 7917 |
<p>Monadic ⎕PNG, i.e. ⎕PNG B is used for 3 purposes: |
| 7918 |
</p> |
| 7919 |
<ol> |
| 7920 |
<li> Conversion of PNG files into the GNU APL color model, |
| 7921 |
</li><li> Display of an APL array (in the GNU APL color model) in a window on |
| 7922 |
the screen (interactive use of PNG), and |
| 7923 |
</li><li> Controlling of ⎕PNG itself. |
| 7924 |
</li></ol> |
| 7925 |
|
| 7926 |
<p>The desired purpose is dictated by the properties of <strong>B</strong>: |
| 7927 |
</p> |
| 7928 |
<ol> |
| 7929 |
<li> Any APL text vector (i.e. a string) <strong>B</strong> is taken as the name of |
| 7930 |
a file that supposedly contains an image in the PNG format. ⎕PNG will |
| 7931 |
read the file and return the pixels in it as a numeric APL array of rank 3. |
| 7932 |
The array contains the color components of the image in the file as |
| 7933 |
described above. |
| 7934 |
</li><li> Any array <strong>B</strong> with rank 3 must be numeric (with values from |
| 7935 |
0.0 to 1.0) and is then assumed to be an array in the GNU APL color model |
| 7936 |
(such as the result of the case above). This image is displayed in a new |
| 7937 |
window on the screen; the window survives even after ⎕PNG has returned. |
| 7938 |
The result returned by ⎕PNG is a window handle (a positive integer |
| 7939 |
identifying the window) which may later be used (in the case described |
| 7940 |
below) to close the window programmatically from APL. Alternatively the |
| 7941 |
window can also be closed interactively by the user via its close button. |
| 7942 |
</li><li> Finally, if <strong>B</strong> is a numeric scalar it fine-tunes the ⎕PNG |
| 7943 |
behaviour: |
| 7944 |
|
| 7945 |
<ul> |
| 7946 |
<li> ⎕PNG N with N ≥ 1 (as returned in the case above) closes the window |
| 7947 |
with handle N programmatically. |
| 7948 |
|
| 7949 |
</li><li> ⎕PNG 0 disables all debug printouts related to ⎕PNG. |
| 7950 |
</li><li> ⎕PNG ¯1 turns on a debug printout related to ⎕PNG (X events). |
| 7951 |
</li><li> ⎕PNG ¯2 turns on a debug printout related to ⎕PNG (image data). |
| 7952 |
</li><li> ⎕PNG ¯3 closes all open ⎕PNG windows. |
| 7953 |
</li><li> ⎕PNG ¯4 turns on a debug printout related to ⎕PNG (GTK drawing). |
| 7954 |
</li><li> ⎕PNG ¯5 turns on a debug printout related to ⎕PNG (function calls). |
| 7955 |
</li><li> ⎕PNG ¯6 returns a vector of all open ⎕PNG window handles. |
| 7956 |
</li></ul> |
| 7957 |
</li></ol> |
| 7958 |
|
| 7959 |
<hr> |
| 7960 |
</div> |
| 7961 |
<div class="subsection" id="Dyadic-_2395PNG"> |
| 7962 |
<div class="header"> |
| 7963 |
<p> |
| 7964 |
Next: <a href="#APL-Examples" accesskey="n" rel="next">APL Examples</a>, Previous: <a href="#Monadic-_2395PNG" accesskey="p" rel="prev">Monadic ⎕PNG</a>, Up: <a href="#g_t_2395PNG-_002d-Portable-Network-Graphics" accesskey="u" rel="up">⎕PNG - Portable Network Graphics</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 7965 |
</div> |
| 7966 |
<span id="Dyadic-_005b_003f_005dPNG"></span><h4 class="subsection">2.37.3 Dyadic ⎕PNG</h4> |
| 7967 |
|
| 7968 |
<p>Dyadic <strong>A ⎕PNG B</strong> has only one purpose: to store an APL array in |
| 7969 |
the GNU APL color model into a PNG file. |
| 7970 |
</p> |
| 7971 |
<ul> |
| 7972 |
<li> If <strong>A</strong> is a text vector then it is taken as the name of a PNG |
| 7973 |
file into which the image <strong>B</strong> shall be written. In this case the |
| 7974 |
resolution is 8 bits for each color component. |
| 7975 |
</li><li> If <strong>A</strong> is a 2-element vector, say <strong>(A1 A2) ← A</strong>, |
| 7976 |
then the nested <strong>A1</strong> is the name of a PNG file as before and |
| 7977 |
<strong>A2</strong> is the resolution (1, 2, 4, 8, or 16) to be used for the |
| 7978 |
output file. In this case the combination of the general image format |
| 7979 |
(as implied by <strong>↑⍴B</strong>) and resolution <strong>A2</strong> must be a valid |
| 7980 |
one in the PNG standard. |
| 7981 |
</li></ul> |
| 7982 |
|
| 7983 |
<hr> |
| 7984 |
</div> |
| 7985 |
<div class="subsection" id="APL-Examples"> |
| 7986 |
<div class="header"> |
| 7987 |
<p> |
| 7988 |
Previous: <a href="#Dyadic-_2395PNG" accesskey="p" rel="prev">Dyadic ⎕PNG</a>, Up: <a href="#g_t_2395PNG-_002d-Portable-Network-Graphics" accesskey="u" rel="up">⎕PNG - Portable Network Graphics</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 7989 |
</div> |
| 7990 |
<span id="APL-Examples-1"></span><h4 class="subsection">2.37.4 APL Examples</h4> |
| 7991 |
|
| 7992 |
<div class="example"> |
| 7993 |
<pre class="example"> ⍝ load PNG file image.png |
| 7994 |
Image ← ⎕PNG 'image.png' |
| 7995 |
|
| 7996 |
⍝ display the image |
| 7997 |
Handle ← ⎕PNG Image |
| 7998 |
|
| 7999 |
⍝ close the window that displays the image |
| 8000 |
⎕PNG Handle |
| 8001 |
|
| 8002 |
⍝ display PNG file image.png without storing it in a variable |
| 8003 |
⎕PNG ⎕PNG 'image.png' |
| 8004 |
|
| 8005 |
⍝ Simple color conversions... |
| 8006 |
|
| 8007 |
⍝ convert a monochrome image into the equivalent RGB image |
| 8008 |
RGB_Gray ← 3 ⌿ Mono |
| 8009 |
|
| 8010 |
⍝ paint all pixels of a monochrome image red |
| 8011 |
RGB_Red ← 1 0 0 ⍀ Mono |
| 8012 |
|
| 8013 |
⍝ paint all pixels of a monochrome image green |
| 8014 |
RGB_Green ← 0 1 0 ⍀ Mono |
| 8015 |
|
| 8016 |
⍝ paint all pixels of a monochrome image blue |
| 8017 |
RGB_Blue ← 0 0 1 ⍀ Mono |
| 8018 |
</pre></div> |
| 8019 |
|
| 8020 |
|
| 8021 |
<hr> |
| 8022 |
</div> |
| 8023 |
</div> |
| 8024 |
<div class="section" id="g_t_2395PS-_002d-Print-Style"> |
| 8025 |
<div class="header"> |
| 8026 |
<p> |
| 8027 |
Next: <a href="#g_t_2395RE-_002d-Regular-Expressions" accesskey="n" rel="next">⎕RE - Regular Expressions</a>, Previous: <a href="#g_t_2395PNG-_002d-Portable-Network-Graphics" accesskey="p" rel="prev">⎕PNG - Portable Network Graphics</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 8028 |
</div> |
| 8029 |
<span id="g_t_005b_003f_005dPS-_002d-Print-Style"></span><h3 class="section">2.38 ⎕PS - Print Style</h3> |
| 8030 |
|
| 8031 |
<p>⎕PS is an integer vector that currently (read: as of SVN 982) contains |
| 8032 |
two integers which control some details of how APL values are printed. |
| 8033 |
The default value of ⎕PS is 0 0. ⎕PS is a session variable which survives |
| 8034 |
the <strong>)LOAD</strong>ing of workspaces. |
| 8035 |
</p> |
| 8036 |
<p>⎕PS[1] = 0: print rational quotients as normal floating point numbers |
| 8037 |
(digits, fractional point, possibly an exponent). |
| 8038 |
</p> |
| 8039 |
<p>⎕PS[1] = 1: print rational quotients as Numerator÷Denominator. |
| 8040 |
</p> |
| 8041 |
<p>Note: ⎕PS[1] has no effect if rational numbers were not ./configure’d. |
| 8042 |
</p> |
| 8043 |
<p>⎕PS[2] = 0: no "boxing" of APL values |
| 8044 |
</p> |
| 8045 |
<p>⎕PS[2] > 0: "boxing" of APL values according to ⎕PS[2]. |
| 8046 |
</p> |
| 8047 |
<p>Setting ⎕PS[2] has the same effect as the debug command ]BOXING and uses |
| 8048 |
the same values. |
| 8049 |
</p> |
| 8050 |
<p>Note: For compatibility with older workspaces, assigning a single value to |
| 8051 |
⎕PS assigns that value to ⎕PS[2] and sets ⎕PS[1] to 0. |
| 8052 |
</p> |
| 8053 |
|
| 8054 |
<hr> |
| 8055 |
</div> |
| 8056 |
<div class="section" id="g_t_2395RE-_002d-Regular-Expressions"> |
| 8057 |
<div class="header"> |
| 8058 |
<p> |
| 8059 |
Next: <a href="#g_t_2395RVAL-_002d-Random-APL-value" accesskey="n" rel="next">⎕RVAL - Random APL value</a>, Previous: <a href="#g_t_2395PS-_002d-Print-Style" accesskey="p" rel="prev">⎕PS - Print Style</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 8060 |
</div> |
| 8061 |
<span id="g_t_005b_003f_005dRE-_002d-Regular-Expressions"></span><h3 class="section">2.39 ⎕RE - Regular Expressions</h3> |
| 8062 |
|
| 8063 |
<p>⎕RE is a function that provides access to a subset of libpcre2, which is a |
| 8064 |
powerful regular expression matching library. "pcre" is an acronym for "Perl |
| 8065 |
compatible regular expressions". libpcre2 is Copyright (c) 1997-2017 |
| 8066 |
University of Cambridge, England. |
| 8067 |
</p> |
| 8068 |
<ul class="section-toc"> |
| 8069 |
<li><a href="#Preconditions" accesskey="1">Preconditions</a></li> |
| 8070 |
<li><a href="#g_t_2395RE-Syntax" accesskey="2">⎕RE Syntax</a></li> |
| 8071 |
<li><a href="#The-Regular-Expression-A" accesskey="3">The Regular Expression A</a></li> |
| 8072 |
<li><a href="#The-String_0028s_0029-B-Being-Matched" accesskey="4">The String(s) B Being Matched</a></li> |
| 8073 |
<li><a href="#The-Flags-X" accesskey="5">The Flags X</a></li> |
| 8074 |
<li><a href="#Complex-Matches" accesskey="6">Complex Matches</a></li> |
| 8075 |
</ul> |
| 8076 |
<hr> |
| 8077 |
<div class="subsection" id="Preconditions"> |
| 8078 |
<div class="header"> |
| 8079 |
<p> |
| 8080 |
Next: <a href="#g_t_2395RE-Syntax" accesskey="n" rel="next">⎕RE Syntax</a>, Up: <a href="#g_t_2395RE-_002d-Regular-Expressions" accesskey="u" rel="up">⎕RE - Regular Expressions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 8081 |
</div> |
| 8082 |
<span id="Preconditions-1"></span><h4 class="subsection">2.39.1 Preconditions</h4> |
| 8083 |
|
| 8084 |
<p>libpcre2 is NOT shipped with GNU APL but must be installed before the GNU APL |
| 8085 |
./configure script is executed. The ./configure script tries to locate |
| 8086 |
libpcre2 and enables ⎕RE if the library (and its header files) are found. |
| 8087 |
</p> |
| 8088 |
<p>If ./configure does not find libpcre2, then ⎕RE will raise a SYNTAX ERROR when |
| 8089 |
⎕RE is used in an APL program. |
| 8090 |
</p> |
| 8091 |
<hr> |
| 8092 |
</div> |
| 8093 |
<div class="subsection" id="g_t_2395RE-Syntax"> |
| 8094 |
<div class="header"> |
| 8095 |
<p> |
| 8096 |
Next: <a href="#The-Regular-Expression-A" accesskey="n" rel="next">The Regular Expression A</a>, Previous: <a href="#Preconditions" accesskey="p" rel="prev">Preconditions</a>, Up: <a href="#g_t_2395RE-_002d-Regular-Expressions" accesskey="u" rel="up">⎕RE - Regular Expressions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 8097 |
</div> |
| 8098 |
<span id="g_t_005b_003f_005dRE-Syntax"></span><h4 class="subsection">2.39.2 ⎕RE Syntax</h4> |
| 8099 |
|
| 8100 |
<p>⎕RE has two forms. The short form (without an axis argument) is intended to |
| 8101 |
cover the most likely use cases of ⎕RE, while the long form gives more control |
| 8102 |
over the format of the result produced by ⎕RE: |
| 8103 |
</p> |
| 8104 |
<div class="example"> |
| 8105 |
<pre class="example">Z ← A ⎕RE B (short form, no axis) |
| 8106 |
Z ← A ⎕RE[X] B (long form, with axis X) |
| 8107 |
</pre></div> |
| 8108 |
|
| 8109 |
<p>The short form is equivalent to the long form with an empty axis: |
| 8110 |
</p> |
| 8111 |
<div class="example"> |
| 8112 |
<pre class="example"> A ⎕RE B ←→ A ⎕RE[''] B |
| 8113 |
</pre></div> |
| 8114 |
|
| 8115 |
<p>It therefore suffices to explain the long form. The long form has 3 different |
| 8116 |
arguments A, B, and X. |
| 8117 |
</p> |
| 8118 |
<hr> |
| 8119 |
</div> |
| 8120 |
<div class="subsection" id="The-Regular-Expression-A"> |
| 8121 |
<div class="header"> |
| 8122 |
<p> |
| 8123 |
Next: <a href="#The-String_0028s_0029-B-Being-Matched" accesskey="n" rel="next">The String(s) B Being Matched</a>, Previous: <a href="#g_t_2395RE-Syntax" accesskey="p" rel="prev">⎕RE Syntax</a>, Up: <a href="#g_t_2395RE-_002d-Regular-Expressions" accesskey="u" rel="up">⎕RE - Regular Expressions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 8124 |
</div> |
| 8125 |
<span id="The-Regular-Expression-A-1"></span><h4 class="subsection">2.39.3 The Regular Expression A</h4> |
| 8126 |
|
| 8127 |
<p>A is a simple character vector which is expected to be a regular expression |
| 8128 |
as defined for the libpcre2 library. ⎕RE passes its left argument A unmodified |
| 8129 |
to libpcre2. The format of A ranges from very simple REs to very complex REs. |
| 8130 |
In fact, regular expressions are a language of their own, and it is unnecessary |
| 8131 |
to describe them here. The user of ⎕RE is referred to the description that |
| 8132 |
comes with libpcre2. |
| 8133 |
</p> |
| 8134 |
<p>See in particular: <b>man pcre2pattern</b> |
| 8135 |
</p> |
| 8136 |
<hr> |
| 8137 |
</div> |
| 8138 |
<div class="subsection" id="The-String_0028s_0029-B-Being-Matched"> |
| 8139 |
<div class="header"> |
| 8140 |
<p> |
| 8141 |
Next: <a href="#The-Flags-X" accesskey="n" rel="next">The Flags X</a>, Previous: <a href="#The-Regular-Expression-A" accesskey="p" rel="prev">The Regular Expression A</a>, Up: <a href="#g_t_2395RE-_002d-Regular-Expressions" accesskey="u" rel="up">⎕RE - Regular Expressions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 8142 |
</div> |
| 8143 |
<span id="The-String_0028s_0029-B-Being-Matched-1"></span><h4 class="subsection">2.39.4 The String(s) B Being Matched</h4> |
| 8144 |
|
| 8145 |
<p>B is either: |
| 8146 |
</p> |
| 8147 |
<ol> |
| 8148 |
<li> a simple character vector (which is then also passed unmodified |
| 8149 |
to libpcre2), or |
| 8150 |
|
| 8151 |
</li><li> a (nested) APL array consisting of simple character vectors. |
| 8152 |
</li></ol> |
| 8153 |
|
| 8154 |
<p>In the second case above, the result of ⎕RE is conceptually the same as if |
| 8155 |
the EACH operator had been applied to ⎕RE: |
| 8156 |
</p> |
| 8157 |
<div class="example"> |
| 8158 |
<pre class="example"> A ⎕RE B ←→ A ⎕RE ¨ B |
| 8159 |
</pre></div> |
| 8160 |
|
| 8161 |
<p>The libpcre2 first compiles A into an internal representation that improves |
| 8162 |
the speed of matching B. As a consequence, if several strings shall be matched |
| 8163 |
with the same regular expression A, then it is (sometimes considerably) faster |
| 8164 |
to A ⎕RE B once with several items of a nested B, than to A ⎕RE B multiple |
| 8165 |
times with the same A but different Bs. This is especially true when longer |
| 8166 |
text files with many lines will be matched. |
| 8167 |
</p> |
| 8168 |
<p>If multiple (nested) strings B are used then A is compiled once and after that |
| 8169 |
the different ⊃B[i] in B are passed unmodified to libpcre2. In that case the |
| 8170 |
result Z is nested and (⍴B) ≡ (⍴Z←A ⎕RE[X] B). We can therefore limit the |
| 8171 |
description to the case where B is a simple character vector. |
| 8172 |
</p> |
| 8173 |
<p>Any string B that is passed to libpcre2 is called "Subject" in the |
| 8174 |
libpcre2 documentation. |
| 8175 |
</p> |
| 8176 |
<hr> |
| 8177 |
</div> |
| 8178 |
<div class="subsection" id="The-Flags-X"> |
| 8179 |
<div class="header"> |
| 8180 |
<p> |
| 8181 |
Next: <a href="#Complex-Matches" accesskey="n" rel="next">Complex Matches</a>, Previous: <a href="#The-String_0028s_0029-B-Being-Matched" accesskey="p" rel="prev">The String(s) B Being Matched</a>, Up: <a href="#g_t_2395RE-_002d-Regular-Expressions" accesskey="u" rel="up">⎕RE - Regular Expressions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 8182 |
</div> |
| 8183 |
<span id="The-Flags-X-1"></span><h4 class="subsection">2.39.5 The Flags X</h4> |
| 8184 |
|
| 8185 |
<p>By default, i.e. without an axis argument X or - equivalently - with an empty |
| 8186 |
string X←<b>""</b> as axis argument, ⎕RE returns the first match of the regular |
| 8187 |
expression A in the string B as an APL string. |
| 8188 |
</p> |
| 8189 |
<p>By means of the optional axis argument <b>X ≢ ""</b> (called flags below) one may |
| 8190 |
override the default behavior to adapt various aspects of the matching to |
| 8191 |
satisfy the requirements that the user of ⎕RE may have. |
| 8192 |
</p> |
| 8193 |
<p>The X argument of <b>A⎕RE[X] B</b> is a character vector where each character |
| 8194 |
is a flag. Each flag is either understood by (and then passed unmodified to) |
| 8195 |
libpcre2 or else understood by ⎕RE itself (and then not passed to libpcre2). |
| 8196 |
</p> |
| 8197 |
<ul class="section-toc"> |
| 8198 |
<li><a href="#The-libpcre2-flags_003a-i-m-s-and-x" accesskey="1">The libpcre2 flags: i, m, s, and x</a></li> |
| 8199 |
<li><a href="#The-_2395RE-_0028APL-output-format_0029-flags-_2193-_2282-and-_002f" accesskey="2">The ⎕RE (APL output format) flags ↓, ⊂, and /</a></li> |
| 8200 |
<li><a href="#the-_2395RE-global-flag-g" accesskey="3">the ⎕RE global flag g</a></li> |
| 8201 |
<li><a href="#the-_2395RE-error-flag-E" accesskey="4">the ⎕RE error flag E</a></li> |
| 8202 |
</ul> |
| 8203 |
<hr> |
| 8204 |
<div class="subsubsection" id="The-libpcre2-flags_003a-i-m-s-and-x"> |
| 8205 |
<div class="header"> |
| 8206 |
<p> |
| 8207 |
Next: <a href="#The-_2395RE-_0028APL-output-format_0029-flags-_2193-_2282-and-_002f" accesskey="n" rel="next">The ⎕RE (APL output format) flags ↓, ⊂, and /</a>, Up: <a href="#The-Flags-X" accesskey="u" rel="up">The Flags X</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 8208 |
</div> |
| 8209 |
<span id="The-libpcre2-flags_003a-i_002c-m_002c-s_002c-and-x"></span><h4 class="subsubsection">2.39.5.1 The libpcre2 flags: i, m, s, and x</h4> |
| 8210 |
|
| 8211 |
<p>The libpcre2 flags accepted by ⎕RE are: i, m, s, and x. They correspond to the |
| 8212 |
following libpcre2 flags: |
| 8213 |
</p> |
| 8214 |
<ul> |
| 8215 |
<li> i: PCRE2_CASELESS (perform case insensitive matching) |
| 8216 |
</li><li> m: PCRE2_MULTILINE (perform matching across multiple lines) |
| 8217 |
</li><li> s: PCRE2_DOTALL (dot (.) in A also matches CR/LF) |
| 8218 |
</li><li> x: PCRE2_EXTENDED (see ’man pcre2pattern’) |
| 8219 |
</li></ul> |
| 8220 |
|
| 8221 |
<p>Please consult the libpcre2 documentation for a more detailed description |
| 8222 |
of these flags. |
| 8223 |
</p> |
| 8224 |
<hr> |
| 8225 |
</div> |
| 8226 |
<div class="subsubsection" id="The-_2395RE-_0028APL-output-format_0029-flags-_2193-_2282-and-_002f"> |
| 8227 |
<div class="header"> |
| 8228 |
<p> |
| 8229 |
Next: <a href="#the-_2395RE-global-flag-g" accesskey="n" rel="next">the ⎕RE global flag g</a>, Previous: <a href="#The-libpcre2-flags_003a-i-m-s-and-x" accesskey="p" rel="prev">The libpcre2 flags: i, m, s, and x</a>, Up: <a href="#The-Flags-X" accesskey="u" rel="up">The Flags X</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 8230 |
</div> |
| 8231 |
<span id="The-_005b_003f_005dRE-_0028APL-output-format_0029-flags-_007c_002c-_005b_003f_005d_002c-and-_002f"></span><h4 class="subsubsection">2.39.5.2 The ⎕RE (APL output format) flags ↓, ⊂, and /</h4> |
| 8232 |
|
| 8233 |
<p>⎕RE provides different output formats, some of which are tailored to different |
| 8234 |
APL functions, so that these other APL functions can use the result of ⎕RE |
| 8235 |
without major conversions. There are currently 4 different output formats: |
| 8236 |
</p> |
| 8237 |
<ul> |
| 8238 |
<li> no ⎕RE flag: ⎕RE returns the matching sub-string(s) of B. |
| 8239 |
|
| 8240 |
</li><li> ↓ flag: ⎕RE returns the position(s) and the length(s) of the matched |
| 8241 |
sub-string of B, Like other left arguments of ↑ or ↓, the string position(s) |
| 8242 |
in the result start at 0 (i.e. not at ⎕IO) and can therefore be used directly |
| 8243 |
by dyadic ↓ and ↑. For instance to cut out the matched pieces. |
| 8244 |
|
| 8245 |
</li><li> ⊂ flag: ⎕RE returns an integer vector suitable as the left argument of |
| 8246 |
partition (dyadic ⊂). |
| 8247 |
|
| 8248 |
</li><li> / flag: ⎕RE returns a Boolean vector suitable as the left argument of |
| 8249 |
compress (dyadic /). |
| 8250 |
</li></ul> |
| 8251 |
|
| 8252 |
<p>The following examples may better explain the nature of the output flags: |
| 8253 |
</p> |
| 8254 |
<div class="example"> |
| 8255 |
<pre class="example"> ⍝ return (first) matched string |
| 8256 |
4 ⎕CR 'f..' ⎕RE[''] '__foo___fun____fox' |
| 8257 |
┏→━━┓ |
| 8258 |
┃foo┃ |
| 8259 |
┗━━━┛ |
| 8260 |
|
| 8261 |
⍝ return (first) pair (position, length) |
| 8262 |
4 ⎕CR 'f..' ⎕RE['↓'] '__foo___fun____fox' |
| 8263 |
┏→━━┓ |
| 8264 |
┃2 3┃ |
| 8265 |
┗━━━┛ |
| 8266 |
|
| 8267 |
⍝ return left argument A of A ⊂ B |
| 8268 |
4 ⎕CR 'f..' ⎕RE['⊂'] '__foo___fun____fox' |
| 8269 |
┏→━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ |
| 8270 |
┃0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0┃ |
| 8271 |
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ |
| 8272 |
|
| 8273 |
⍝ return left argument A of A / B |
| 8274 |
4 ⎕CR 'f..' ⎕RE['/'] '__foo___fun____fox' |
| 8275 |
┏→━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ |
| 8276 |
┃0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0┃ |
| 8277 |
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ |
| 8278 |
</pre></div> |
| 8279 |
|
| 8280 |
<p>In the absence of a ’g’ flag (see below) the results of output formats |
| 8281 |
⊂ and / are identical; if ’g’ is present, however, then they may differ. |
| 8282 |
</p> |
| 8283 |
<hr> |
| 8284 |
</div> |
| 8285 |
<div class="subsubsection" id="the-_2395RE-global-flag-g"> |
| 8286 |
<div class="header"> |
| 8287 |
<p> |
| 8288 |
Next: <a href="#the-_2395RE-error-flag-E" accesskey="n" rel="next">the ⎕RE error flag E</a>, Previous: <a href="#The-_2395RE-_0028APL-output-format_0029-flags-_2193-_2282-and-_002f" accesskey="p" rel="prev">The ⎕RE (APL output format) flags ↓, ⊂, and /</a>, Up: <a href="#The-Flags-X" accesskey="u" rel="up">The Flags X</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 8289 |
</div> |
| 8290 |
<span id="the-_005b_003f_005dRE-global-flag-g"></span><h4 class="subsubsection">2.39.5.3 the ⎕RE global flag g</h4> |
| 8291 |
|
| 8292 |
<p>The default behavior of ⎕RE is to return only the first match of A in B. |
| 8293 |
The ’g’ flag causes ⎕RE to return all matches instead. For example: |
| 8294 |
</p> |
| 8295 |
<div class="example"> |
| 8296 |
<pre class="example"> ⍝ return first match as string |
| 8297 |
4 ⎕CR 'f..' ⎕RE[''] '__foo___fun____fox' |
| 8298 |
┏→━━┓ |
| 8299 |
┃foo┃ |
| 8300 |
┗━━━┛ |
| 8301 |
|
| 8302 |
⍝ return all matches as strings |
| 8303 |
4 ⎕CR 'f..' ⎕RE['g'] '__foo___fun____fox' |
| 8304 |
┏→━━━━━k━━━━━━━━━━━┓ |
| 8305 |
┃┏→━━┓ ┏→━━┓ ┏→━━┓┃ |
| 8306 |
┃┃foo┃ ┃fun┃ ┃fox┃┃ |
| 8307 |
┃┗━━━┛ ┗━━━┛ ┗━━━┛┃ |
| 8308 |
┗∊━━━━━━━━━━━━━━━━┛ |
| 8309 |
|
| 8310 |
⍝ return first match as pair (position, length) |
| 8311 |
4 ⎕CR 'f..' ⎕RE['↓'] '__foo___fun____fox' |
| 8312 |
┏→━━┓ |
| 8313 |
┃2 3┃ |
| 8314 |
┗━━━┛ |
| 8315 |
|
| 8316 |
⍝ return all matches as pair (position, length) |
| 8317 |
4 ⎕CR 'f..' ⎕RE['↓g'] '__foo___fun____fox' |
| 8318 |
┏→━━━━━━━━━━━━━━━━━┓ |
| 8319 |
┃┏→━━┓ ┏→━━┓ ┏→━━━┓┃ |
| 8320 |
┃┃2 3┃ ┃8 3┃ ┃15 3┃┃ |
| 8321 |
┃┗━━━┛ ┗━━━┛ ┗━━━━┛┃ |
| 8322 |
┗∊━━━━━━━━━━━━━━━━━┛ |
| 8323 |
|
| 8324 |
⍝ return first match as left argument of ⊂ (aka. partition) |
| 8325 |
4 ⎕CR 'f..' ⎕RE['⊂'] '__foo___fun____fox' |
| 8326 |
┏→━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ |
| 8327 |
┃0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0┃ |
| 8328 |
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ |
| 8329 |
|
| 8330 |
⍝ return all matches as left argument of ⊂ (aka. partition) |
| 8331 |
4 ⎕CR 'f..' ⎕RE['⊂g'] '__foo___fun____fox' |
| 8332 |
┏→━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ |
| 8333 |
┃0 0 1 1 1 0 0 0 2 2 2 0 0 0 0 3 3 3┃ |
| 8334 |
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ |
| 8335 |
|
| 8336 |
⍝ return first match as left argument of / (aka. compress) |
| 8337 |
4 ⎕CR 'f..' ⎕RE['/'] '__foo___fun____fox' |
| 8338 |
┏→━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ |
| 8339 |
┃0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0┃ |
| 8340 |
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ |
| 8341 |
|
| 8342 |
⍝ return all matches as left argument of / (aka. compress) |
| 8343 |
4 ⎕CR 'f..' ⎕RE['/g'] '__foo___fun____fox' |
| 8344 |
┏→━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ |
| 8345 |
┃0 0 1 1 1 0 0 0 1 1 1 0 0 0 0 1 1 1┃ |
| 8346 |
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ |
| 8347 |
</pre></div> |
| 8348 |
|
| 8349 |
<p>Please note that the ’g’ flag increments the depth of the result of the output |
| 8350 |
formats ’string’ and ’position/length’, but not of the result of output formats |
| 8351 |
’partition’ and ’compress’. |
| 8352 |
</p> |
| 8353 |
<p>The output formats ⊂ and / are related like this: |
| 8354 |
</p> |
| 8355 |
<div class="example"> |
| 8356 |
<pre class="example"> A ⌷RE['/'] B ←→ 0 ≠ A A ⌷RE['⊂'] B |
| 8357 |
</pre></div> |
| 8358 |
|
| 8359 |
|
| 8360 |
<hr> |
| 8361 |
</div> |
| 8362 |
<div class="subsubsection" id="the-_2395RE-error-flag-E"> |
| 8363 |
<div class="header"> |
| 8364 |
<p> |
| 8365 |
Previous: <a href="#the-_2395RE-global-flag-g" accesskey="p" rel="prev">the ⎕RE global flag g</a>, Up: <a href="#The-Flags-X" accesskey="u" rel="up">The Flags X</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 8366 |
</div> |
| 8367 |
<span id="the-_005b_003f_005dRE-error-flag-E"></span><h4 class="subsubsection">2.39.5.4 the ⎕RE error flag E</h4> |
| 8368 |
|
| 8369 |
<p>The default behavior of ⎕RE is to return an empty result if no match of |
| 8370 |
the regular expression A is found in B. It is sometimes more convenient to |
| 8371 |
raise an error if no match is found. This can be achieved with the E flag: |
| 8372 |
</p> |
| 8373 |
<div class="example"> |
| 8374 |
<pre class="example"> 4 ⎕CR 'g..' ⎕RE[''] '__foo___fun____fox' |
| 8375 |
┏⊖┓ |
| 8376 |
┃0┃ |
| 8377 |
┗━┛ |
| 8378 |
'g..' ⎕RE['E'] '__foo___fun____fox' |
| 8379 |
DOMAIN ERROR+ |
| 8380 |
'g..' ⎕RE['E']'__foo___fun____fox' |
| 8381 |
^ ^ |
| 8382 |
)MORE |
| 8383 |
No match |
| 8384 |
</pre></div> |
| 8385 |
|
| 8386 |
<p>The ’E’ flag has no effect if the ’g’ flag is also given because in that case |
| 8387 |
it is natural to check the length of the result: |
| 8388 |
</p> |
| 8389 |
<div class="example"> |
| 8390 |
<pre class="example"> 4 ⎕CR 'g..' ⎕RE['Eg'] '__foo___fun____fox' |
| 8391 |
┏⊖┓ |
| 8392 |
┃0┃ |
| 8393 |
┗━┛ |
| 8394 |
</pre></div> |
| 8395 |
|
| 8396 |
<hr> |
| 8397 |
</div> |
| 8398 |
</div> |
| 8399 |
<div class="subsection" id="Complex-Matches"> |
| 8400 |
<div class="header"> |
| 8401 |
<p> |
| 8402 |
Previous: <a href="#The-Flags-X" accesskey="p" rel="prev">The Flags X</a>, Up: <a href="#g_t_2395RE-_002d-Regular-Expressions" accesskey="u" rel="up">⎕RE - Regular Expressions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 8403 |
</div> |
| 8404 |
<span id="Complex-Matches-1"></span><h4 class="subsection">2.39.6 Complex Matches</h4> |
| 8405 |
|
| 8406 |
<p>The regular expressions considered so far were simple, which means that they |
| 8407 |
did not have (regular) sub-expressions. In other words, the regular expression |
| 8408 |
A did not contain non-literal (unquoted) parentheses. However, the libpcre2 |
| 8409 |
allows sub-expressions and ⎕RE follows suit to a certain extent. If A contains |
| 8410 |
sub-expressions, the result of A ⎕RE B becomes deeper and the structure of the |
| 8411 |
result is determined by the structure of the parentheses in A. |
| 8412 |
</p> |
| 8413 |
<p>The result of a general regular expression A is recursively constructed by ⎕RE |
| 8414 |
as follows: |
| 8415 |
</p> |
| 8416 |
<p>1. If A contains no sub-expressions then the result is constructed as described |
| 8417 |
in the previous sections. |
| 8418 |
</p> |
| 8419 |
<p>2. If A contains sub-expressions, say A1, ... An, then the result is a (nested) |
| 8420 |
vector with N+1 elements where the first element is the entire match (which |
| 8421 |
contains the sub-matches) and the following elements are the next-level |
| 8422 |
sub-matches. |
| 8423 |
</p> |
| 8424 |
<p>Since the sub-matches are contained in their parent matches, it makes no sense |
| 8425 |
to handle sub-matches in the partition and compress output formats. For the |
| 8426 |
string and pos+len formats, the following examples may give some insight into |
| 8427 |
how the results look. |
| 8428 |
</p> |
| 8429 |
<p>The regular expression A ← ’f(.)(.)’ used in the example below is a top-level |
| 8430 |
regular expression which contains two 1-character sub-expressions (.). |
| 8431 |
The result is therefore the top-level match plus two 1-character sub-matches: |
| 8432 |
</p> |
| 8433 |
<div class="example"> |
| 8434 |
<pre class="example"> 4 ⎕CR 'f(.)(.)' ⎕RE[''] '__foo___fun____fox' |
| 8435 |
┏→━━━━━━━━━━━━┓ |
| 8436 |
┃┏→━━┓ ┏→┓ ┏→┓┃ |
| 8437 |
┃┃foo┃ ┃o┃ ┃o┃┃ |
| 8438 |
┃┗━━━┛ ┗━┛ ┗━┛┃ |
| 8439 |
┗∊━━━━━━━━━━━━┛ |
| 8440 |
</pre></div> |
| 8441 |
|
| 8442 |
<p>Matching all instead of only the first then gives: |
| 8443 |
</p> |
| 8444 |
<div class="example"> |
| 8445 |
<pre class="example"> 4 ⎕CR 'f(.)(.)' ⎕RE['g'] '__foo___fun____fox' |
| 8446 |
┏→━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ |
| 8447 |
┃┏→━━━━━━━━━━━━┓ ┏→━━━━━━━━━━━━┓ ┏→━━━━━━━━━━━━┓┃ |
| 8448 |
┃┃┏→━━┓ ┏→┓ ┏→┓┃ ┃┏→━━┓ ┏→┓ ┏→┓┃ ┃┏→━━┓ ┏→┓ ┏→┓┃┃ |
| 8449 |
┃┃┃foo┃ ┃o┃ ┃o┃┃ ┃┃fun┃ ┃u┃ ┃n┃┃ ┃┃fox┃ ┃o┃ ┃x┃┃┃ |
| 8450 |
┃┃┗━━━┛ ┗━┛ ┗━┛┃ ┃┗━━━┛ ┗━┛ ┗━┛┃ ┃┗━━━┛ ┗━┛ ┗━┛┃┃ |
| 8451 |
┃┗∊━━━━━━━━━━━━┛ ┗∊━━━━━━━━━━━━┛ ┗∊━━━━━━━━━━━━┛┃ |
| 8452 |
┗∊∊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ |
| 8453 |
</pre></div> |
| 8454 |
|
| 8455 |
<p>The same for the pos+len output format: |
| 8456 |
</p> |
| 8457 |
<div class="example"> |
| 8458 |
<pre class="example"> 4 ⎕CR 'f(.)(.)' ⎕RE['↓'] '__foo___fun____fox' |
| 8459 |
┏→━━━━━━━━━━━━━━┓ |
| 8460 |
┃2 3 ┏→━━┓ ┏→━━┓┃ |
| 8461 |
┃ ┃3 1┃ ┃4 1┃┃ |
| 8462 |
┃ ┗━━━┛ ┗━━━┛┃ |
| 8463 |
┗∊━━━━━━━━━━━━━━┛ |
| 8464 |
4 ⎕CR 'f(.)(.)' ⎕RE['↓g'] '__foo___fun____fox' |
| 8465 |
┏→━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ |
| 8466 |
┃┏→━━━━━━━━━━━━━━┓ ┏→━━━━━━━━━━━━━━━┓ ┏→━━━━━━━━━━━━━━━━━┓┃ |
| 8467 |
┃┃2 3 ┏→━━┓ ┏→━━┓┃ ┃8 3 ┏→━━┓ ┏→━━━┓┃ ┃15 3 ┏→━━━┓ ┏→━━━┓┃┃ |
| 8468 |
┃┃ ┃3 1┃ ┃4 1┃┃ ┃ ┃9 1┃ ┃10 1┃┃ ┃ ┃16 1┃ ┃17 1┃┃┃ |
| 8469 |
┃┃ ┗━━━┛ ┗━━━┛┃ ┃ ┗━━━┛ ┗━━━━┛┃ ┃ ┗━━━━┛ ┗━━━━┛┃┃ |
| 8470 |
┃┗∊━━━━━━━━━━━━━━┛ ┗∊━━━━━━━━━━━━━━━┛ ┗∊━━━━━━━━━━━━━━━━━┛┃ |
| 8471 |
┗∊∊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ |
| 8472 |
</pre></div> |
| 8473 |
|
| 8474 |
|
| 8475 |
<hr> |
| 8476 |
</div> |
| 8477 |
</div> |
| 8478 |
<div class="section" id="g_t_2395RVAL-_002d-Random-APL-value"> |
| 8479 |
<div class="header"> |
| 8480 |
<p> |
| 8481 |
Next: <a href="#g_t_2395SI-_002d-State-Indicator" accesskey="n" rel="next">⎕SI - State Indicator</a>, Previous: <a href="#g_t_2395RE-_002d-Regular-Expressions" accesskey="p" rel="prev">⎕RE - Regular Expressions</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 8482 |
</div> |
| 8483 |
<span id="g_t_005b_003f_005dRVAL-_002d-Random-APL-value"></span><h3 class="section">2.40 ⎕RVAL - Random APL value</h3> |
| 8484 |
|
| 8485 |
<p>The standard way to produce random numbers is the primitive function ? |
| 8486 |
aka. <b>Roll</b>. Roll returns a simple random array whose ravel elements are |
| 8487 |
positive integers chosen in a (pseudo-) random fashion. While this is sufficient |
| 8488 |
for many applications, one sometimes needs APL values whose randomness not |
| 8489 |
only affects the ravel elements themselves, but also other aspects like: |
| 8490 |
</p> |
| 8491 |
<ul> |
| 8492 |
<li> the rank of the value, |
| 8493 |
</li><li> the shape of the value, |
| 8494 |
</li><li> the data type of the ravel elements, and |
| 8495 |
</li><li> the depth (nesting) of the values. |
| 8496 |
</li></ul> |
| 8497 |
|
| 8498 |
<p>Such values can be produced with system function ⎕RVAL. The main use case for |
| 8499 |
⎕RVAL is the production of test data for the interpreter, but ⎕RVAL might be |
| 8500 |
useful for other purposes as well. |
| 8501 |
</p> |
| 8502 |
<ul class="section-toc"> |
| 8503 |
<li><a href="#General" accesskey="1">General</a></li> |
| 8504 |
<li><a href="#Dyadic-_2395RVAL" accesskey="2">Dyadic ⎕RVAL</a></li> |
| 8505 |
</ul> |
| 8506 |
<hr> |
| 8507 |
<div class="subsection" id="General"> |
| 8508 |
<div class="header"> |
| 8509 |
<p> |
| 8510 |
Next: <a href="#Dyadic-_2395RVAL" accesskey="n" rel="next">Dyadic ⎕RVAL</a>, Up: <a href="#g_t_2395RVAL-_002d-Random-APL-value" accesskey="u" rel="up">⎕RVAL - Random APL value</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 8511 |
</div> |
| 8512 |
<span id="General-1"></span><h4 class="subsection">2.40.1 General</h4> |
| 8513 |
|
| 8514 |
<p>In general, monadic ⎕RVAL B, returns a single random APL value Z, |
| 8515 |
while dyadic A RVAL B is used to control the properties of |
| 8516 |
subsequently generated random APL values returned by monadic ⎕RVAL. |
| 8517 |
</p> |
| 8518 |
<p>The typical use of ⎕RVAL is to first call A ⎕RVAL B zero or more times to |
| 8519 |
override individual default properties of the subsequently produced values, |
| 8520 |
followed by one or more calls of monadic ⎕RVAL B. |
| 8521 |
</p> |
| 8522 |
<p>The default properties, i.e. the properties used unless they were overridden |
| 8523 |
by dyadic A ⎕RVAL B, are: |
| 8524 |
</p> |
| 8525 |
<div class="example"> |
| 8526 |
<pre class="example">Rank: 0 |
| 8527 |
Shape: 1 1 1 1 1 1 1 1 (initially irrelevant since Rank = 0) |
| 8528 |
Type: 0 1 0 0 0 (only integer random values) |
| 8529 |
Max. Depth: 4 (initially irrelevant since type = 0 1 0 0 0) |
| 8530 |
</pre></div> |
| 8531 |
|
| 8532 |
<p>With these default properties, every call of monadic ⎕RVAL B returns an |
| 8533 |
integer scalar. |
| 8534 |
</p> |
| 8535 |
<hr> |
| 8536 |
</div> |
| 8537 |
<div class="subsection" id="Dyadic-_2395RVAL"> |
| 8538 |
<div class="header"> |
| 8539 |
<p> |
| 8540 |
Previous: <a href="#General" accesskey="p" rel="prev">General</a>, Up: <a href="#g_t_2395RVAL-_002d-Random-APL-value" accesskey="u" rel="up">⎕RVAL - Random APL value</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 8541 |
</div> |
| 8542 |
<span id="Dyadic-_005b_003f_005dRVAL"></span><h4 class="subsection">2.40.2 Dyadic ⎕RVAL</h4> |
| 8543 |
|
| 8544 |
<p>The left argument A of A ⎕RVAL B determines which aspect of the |
| 8545 |
subsequent random APL values shall be controlled. A is an integer scalar: |
| 8546 |
</p> |
| 8547 |
<ul> |
| 8548 |
<li> A=0 controls the state of the underlying random number generator, |
| 8549 |
|
| 8550 |
</li><li> A=1 controls the ranks of the subsequent random APL values, |
| 8551 |
|
| 8552 |
</li><li> A=2 controls the shapes of the subsequent random APL values, |
| 8553 |
|
| 8554 |
</li><li> A=3 controls the data types in the ravels of the subsequent random APL values, |
| 8555 |
and |
| 8556 |
|
| 8557 |
</li><li> A=4 controls a maximum depth of the subsequent random APL values. |
| 8558 |
|
| 8559 |
</li></ul> |
| 8560 |
|
| 8561 |
<ul class="section-toc"> |
| 8562 |
<li><a href="#Control-of-the-underlying-random-number-generator_003a-0-_2395RVAL-B" accesskey="1">Control of the underlying random number generator: 0 ⎕RVAL B</a></li> |
| 8563 |
<li><a href="#Control-of-the-ranks_003a-1-_2395RVAL-B" accesskey="2">Control of the ranks: 1 ⎕RVAL B</a></li> |
| 8564 |
<li><a href="#Control-of-the-shapes_003a-2-_2395RVAL-B" accesskey="3">Control of the shapes: 2 ⎕RVAL B</a></li> |
| 8565 |
<li><a href="#Control-of-the-data-types_003a-3-_2395RVAL-B" accesskey="4">Control of the data types: 3 ⎕RVAL B</a></li> |
| 8566 |
<li><a href="#Control-of-a-maximum-depth_003a-4-_2395RVAL-B" accesskey="5">Control of a maximum depth: 4 ⎕RVAL B</a></li> |
| 8567 |
<li><a href="#monadic-_2395RVAL-B" accesskey="6">monadic ⎕RVAL B</a></li> |
| 8568 |
<li><a href="#Syntax-Alternatives" accesskey="7">Syntax Alternatives</a></li> |
| 8569 |
</ul> |
| 8570 |
<hr> |
| 8571 |
<div class="subsubsection" id="Control-of-the-underlying-random-number-generator_003a-0-_2395RVAL-B"> |
| 8572 |
<div class="header"> |
| 8573 |
<p> |
| 8574 |
Next: <a href="#Control-of-the-ranks_003a-1-_2395RVAL-B" accesskey="n" rel="next">Control of the ranks: 1 ⎕RVAL B</a>, Up: <a href="#Dyadic-_2395RVAL" accesskey="u" rel="up">Dyadic ⎕RVAL</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 8575 |
</div> |
| 8576 |
<span id="Control-of-the-underlying-random-number-generator_003a-0-_005b_003f_005dRVAL-B"></span><h4 class="subsubsection">2.40.2.1 Control of the underlying random number generator: 0 ⎕RVAL B</h4> |
| 8577 |
|
| 8578 |
<p>Every random number generator has a state (similar to <b>⎕RL</b> for <b>’?’</b>). |
| 8579 |
While the primitive <b>?</b> keeps its state in <b>⎕RL</b>, i.e. in the workspace, |
| 8580 |
⎕RVAL has no associated system variable like i<b>⎕RL</b> which keeps its state. |
| 8581 |
Instead, the user needs to store the state of i<b>⎕RVAL</b> in a workspace |
| 8582 |
variable if the workspace shall be stored and continued at a later point. |
| 8583 |
This rarely happens, therefore no effort was spent on implementing another |
| 8584 |
system variable. For the same reasonxi does, the state of <b>⎕RVAL</b> |
| 8585 |
survive <b>)CLEAR</b>. |
| 8586 |
</p> |
| 8587 |
<p>The current state of <b>⎕RVAL</b>’s random number generator can be retrieved |
| 8588 |
with: |
| 8589 |
</p> |
| 8590 |
<div class="example"> |
| 8591 |
<pre class="example"> STATE ← 0 ⎕RVAL '' |
| 8592 |
</pre></div> |
| 8593 |
|
| 8594 |
<p>The state changes with every call of monadic ⎕RVAL. The random number generator |
| 8595 |
can later be restored to the same state like this: |
| 8596 |
</p> |
| 8597 |
<div class="example"> |
| 8598 |
<pre class="example"> 0 ⎕RVAL STATE |
| 8599 |
</pre></div> |
| 8600 |
|
| 8601 |
<p>Restoring the state is needed when the same sequence of random values shall |
| 8602 |
be generated again. The random number generators of ? and ⎕RVAL are |
| 8603 |
independent; generating a random number or random value with one does not |
| 8604 |
change the state of the other. |
| 8605 |
</p> |
| 8606 |
<hr> |
| 8607 |
</div> |
| 8608 |
<div class="subsubsection" id="Control-of-the-ranks_003a-1-_2395RVAL-B"> |
| 8609 |
<div class="header"> |
| 8610 |
<p> |
| 8611 |
Next: <a href="#Control-of-the-shapes_003a-2-_2395RVAL-B" accesskey="n" rel="next">Control of the shapes: 2 ⎕RVAL B</a>, Previous: <a href="#Control-of-the-underlying-random-number-generator_003a-0-_2395RVAL-B" accesskey="p" rel="prev">Control of the underlying random number generator: 0 ⎕RVAL B</a>, Up: <a href="#Dyadic-_2395RVAL" accesskey="u" rel="up">Dyadic ⎕RVAL</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 8612 |
</div> |
| 8613 |
<span id="Control-of-the-ranks_003a-1-_005b_003f_005dRVAL-B"></span><h4 class="subsubsection">2.40.2.2 Control of the ranks: 1 ⎕RVAL B</h4> |
| 8614 |
|
| 8615 |
<p>The rank of subsequently generated random values can be controlled with |
| 8616 |
1 ⎕RVAL B as follows: |
| 8617 |
</p> |
| 8618 |
<ul> |
| 8619 |
<li> If B is a non-negative scalar with 0 ≤ B < MAX_RANK then the subsequently |
| 8620 |
generated random values will have the fixed rank B. MAX_RANK is a |
| 8621 |
./configurable constant with a default of 8. |
| 8622 |
|
| 8623 |
</li><li> If B is a negative scalar with 0 > B > -MAX_RANK then the ranks of the |
| 8624 |
subsequently generated random values will be chosen at random between |
| 8625 |
0 and -B (inclusive). All possible ranks 0 ... B will have the same |
| 8626 |
probability P = 100÷1-B %. |
| 8627 |
|
| 8628 |
</li><li> Otherwise B must be a vector of positive integers. The integers are the |
| 8629 |
relative frequencies of the ranks 0, 1, ... MAX_RANK respectively. Too many |
| 8630 |
integers (i.e. MAX_RANK > ⍴B) will raise a LENGTH ERROR while fewer (than |
| 8631 |
MAX_RANK) are set to 0. |
| 8632 |
|
| 8633 |
</li></ul> |
| 8634 |
|
| 8635 |
<p>1 ⎕RVAL always returns its previous setting (i.e. before applying B). |
| 8636 |
An empty B, e.g. 1 ⎕RVAL ⍬ will not change anything and can be used to |
| 8637 |
query the current setting for 1 ⎕RVAL. |
| 8638 |
</p> |
| 8639 |
<p>Examples: |
| 8640 |
</p> |
| 8641 |
<ul> |
| 8642 |
<li> 1 ⎕RVAL 2 will produce only matrices, |
| 8643 |
|
| 8644 |
</li><li> 1 ⎕RVAL ¯2 will produce scalars, vectors or matrices, each with a |
| 8645 |
probability of 100÷3 %, and |
| 8646 |
|
| 8647 |
</li><li> 1 ⎕RVAL 50 30 20 will produce scalars with probability 50%, vectors |
| 8648 |
with probability 30%, and matrices with probability 20%. The numbers |
| 8649 |
need not add up to 100, but will be scaled accordingly. |
| 8650 |
</li></ul> |
| 8651 |
|
| 8652 |
<hr> |
| 8653 |
</div> |
| 8654 |
<div class="subsubsection" id="Control-of-the-shapes_003a-2-_2395RVAL-B"> |
| 8655 |
<div class="header"> |
| 8656 |
<p> |
| 8657 |
Next: <a href="#Control-of-the-data-types_003a-3-_2395RVAL-B" accesskey="n" rel="next">Control of the data types: 3 ⎕RVAL B</a>, Previous: <a href="#Control-of-the-ranks_003a-1-_2395RVAL-B" accesskey="p" rel="prev">Control of the ranks: 1 ⎕RVAL B</a>, Up: <a href="#Dyadic-_2395RVAL" accesskey="u" rel="up">Dyadic ⎕RVAL</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 8658 |
</div> |
| 8659 |
<span id="Control-of-the-shapes_003a-2-_005b_003f_005dRVAL-B"></span><h4 class="subsubsection">2.40.2.3 Control of the shapes: 2 ⎕RVAL B</h4> |
| 8660 |
|
| 8661 |
<p>The shapes of subsequently generated random values can be controlled with |
| 8662 |
2 ⎕RVAL B as follows. |
| 8663 |
</p> |
| 8664 |
<p>B must be a vector of positive or negative integers. Vectors longer than |
| 8665 |
MAX_RANK + 1 will give a LENGTH ERROR while vectors shorter than MAX_RANK + 1 |
| 8666 |
will be filled with 1 until the length of B becomes MAX_RANK + 1. |
| 8667 |
</p> |
| 8668 |
<p>If an element B<sub>i</sub> of the resulting shape B = B<sub>1</sub> ... B<sub>MAXRANK</sub> |
| 8669 |
is ≥ 0 then the corresponding axis i will have a fixed length of B<sub>i</sub>. |
| 8670 |
If B<sub>i</sub> < 0 then the length of that axis will be chosen at random with |
| 8671 |
a probability of 1÷B<sub>i</sub>. Note that the same B can still produce different |
| 8672 |
shapes even if all B<sub>i</sub> are ≥ 0 (i.e. if the rank is also chosen at |
| 8673 |
random). |
| 8674 |
</p> |
| 8675 |
<p>2 ⎕RVAL always returns its previous setting (i.e. before applying B). |
| 8676 |
An empty B, e.g. 2 ⎕RVAL ⍬, will not change anything and can be used to |
| 8677 |
query the current setting for 2 ⎕RVAL. |
| 8678 |
</p> |
| 8679 |
<p>Example: |
| 8680 |
</p> |
| 8681 |
<div class="example"> |
| 8682 |
<pre class="example">1 ⎕RVAL 2 ⍝ produce matrices |
| 8683 |
2 ⎕RVAL 3 ¯10 ⍝ the first axis of every matrix will have length 3, and |
| 8684 |
⍝ the last axis of every matrix will vary between 0 and 10 |
| 8685 |
</pre></div> |
| 8686 |
|
| 8687 |
<p>This will produce scalars, vectors with a fixed length of 3 and matrices |
| 8688 |
with 3 rows and between 0 and 10 columns. |
| 8689 |
</p> |
| 8690 |
<hr> |
| 8691 |
</div> |
| 8692 |
<div class="subsubsection" id="Control-of-the-data-types_003a-3-_2395RVAL-B"> |
| 8693 |
<div class="header"> |
| 8694 |
<p> |
| 8695 |
Next: <a href="#Control-of-a-maximum-depth_003a-4-_2395RVAL-B" accesskey="n" rel="next">Control of a maximum depth: 4 ⎕RVAL B</a>, Previous: <a href="#Control-of-the-shapes_003a-2-_2395RVAL-B" accesskey="p" rel="prev">Control of the shapes: 2 ⎕RVAL B</a>, Up: <a href="#Dyadic-_2395RVAL" accesskey="u" rel="up">Dyadic ⎕RVAL</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 8696 |
</div> |
| 8697 |
<span id="Control-of-the-data-types_003a-3-_005b_003f_005dRVAL-B"></span><h4 class="subsubsection">2.40.2.4 Control of the data types: 3 ⎕RVAL B</h4> |
| 8698 |
|
| 8699 |
<p>The types (i.e. CHARACTER, INTEGER, REAL, COMPLEX, or NESTED) of subsequently |
| 8700 |
generated random values can be controlled with 3 ⎕RVAL B as follows. |
| 8701 |
</p> |
| 8702 |
<p>B must be a vector with up to 5 positive numbers, corresponding to the types. |
| 8703 |
Shorter vectors are filled with 0 (the corresponding types will not occur) and |
| 8704 |
longer vectors will raise a LENGTH error. |
| 8705 |
</p> |
| 8706 |
<p>Once the type was chosen, the ravel item will be: |
| 8707 |
</p> |
| 8708 |
<ul> |
| 8709 |
<li> for type CHARACTER: a random character with ⎕UCS between 0 and $3000 |
| 8710 |
(exclusive). Larger Unicodes typically cause display problems. If you need |
| 8711 |
larger Unicodes, use ⎕UCS with random integers. |
| 8712 |
|
| 8713 |
</li><li> for type INTEGER: a random integer with ⎕UCS between -$80000000 and |
| 8714 |
$7FFFFFFF. |
| 8715 |
|
| 8716 |
</li><li> for type REAL: a floating point number between 0.0 and 1.0 (exclusive) |
| 8717 |
|
| 8718 |
</li><li> for type COMPLEX: a complex point number with real and imaginaty part |
| 8719 |
between 0.0 and 1.0 (exclusive), and |
| 8720 |
|
| 8721 |
</li><li> for type NESTED: a nested APL value with the same properties (rank, shape, |
| 8722 |
and type) as their parent. |
| 8723 |
</li></ul> |
| 8724 |
|
| 8725 |
<p>3 ⎕RVAL always returns its previous setting (i.e. before applying B). |
| 8726 |
An empty B, e.g. 3 ⎕RVAL ⍬ will not change anything and can be used to |
| 8727 |
query the current setting for 3 ⎕RVAL. |
| 8728 |
</p> |
| 8729 |
<p>Example: |
| 8730 |
</p> |
| 8731 |
<div class="example"> |
| 8732 |
<pre class="example"> 1 ⎕RVAL 2 ⍝ produce matrices |
| 8733 |
2 ⎕RVAL 3 3 ⍝ produce 3×3 matrices |
| 8734 |
3 ⎕RVAL 0 50 50 ⍝ produce a mix of integer and real values |
| 8735 |
⎕RVAL 0 |
| 8736 |
¯975954163190248487 0.5892132425 |
| 8737 |
7677327503669503253 2152001972871424768 |
| 8738 |
</pre></div> |
| 8739 |
|
| 8740 |
<hr> |
| 8741 |
</div> |
| 8742 |
<div class="subsubsection" id="Control-of-a-maximum-depth_003a-4-_2395RVAL-B"> |
| 8743 |
<div class="header"> |
| 8744 |
<p> |
| 8745 |
Next: <a href="#monadic-_2395RVAL-B" accesskey="n" rel="next">monadic ⎕RVAL B</a>, Previous: <a href="#Control-of-the-data-types_003a-3-_2395RVAL-B" accesskey="p" rel="prev">Control of the data types: 3 ⎕RVAL B</a>, Up: <a href="#Dyadic-_2395RVAL" accesskey="u" rel="up">Dyadic ⎕RVAL</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 8746 |
</div> |
| 8747 |
<span id="Control-of-a-maximum-depth_003a-4-_005b_003f_005dRVAL-B"></span><h4 class="subsubsection">2.40.2.5 Control of a maximum depth: 4 ⎕RVAL B</h4> |
| 8748 |
|
| 8749 |
<p>If the probability of generating a nested value is > 0 then the depth of |
| 8750 |
random values can become arbitrarily large and could therefore exceed the |
| 8751 |
system limit for the depth of the random value being produced. This can be |
| 8752 |
prevented by setting a maximum depth for every value generated. ⎕RVAL sets |
| 8753 |
the probability of the deepest allowed depth to 0. |
| 8754 |
</p> |
| 8755 |
<p>4 ⎕RVAL B expects B to be a positive integer which is deepest allowed depth; |
| 8756 |
</p> |
| 8757 |
<p>An empty B, e.g. 4 ⎕RVAL ⍬, will not change anything and can be used to |
| 8758 |
query the current setting for 4 ⎕RVAL. |
| 8759 |
</p> |
| 8760 |
<hr> |
| 8761 |
</div> |
| 8762 |
<div class="subsubsection" id="monadic-_2395RVAL-B"> |
| 8763 |
<div class="header"> |
| 8764 |
<p> |
| 8765 |
Next: <a href="#Syntax-Alternatives" accesskey="n" rel="next">Syntax Alternatives</a>, Previous: <a href="#Control-of-a-maximum-depth_003a-4-_2395RVAL-B" accesskey="p" rel="prev">Control of a maximum depth: 4 ⎕RVAL B</a>, Up: <a href="#Dyadic-_2395RVAL" accesskey="u" rel="up">Dyadic ⎕RVAL</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 8766 |
</div> |
| 8767 |
<span id="monadic-_005b_003f_005dRVAL-B"></span><h4 class="subsubsection">2.40.2.6 monadic ⎕RVAL B</h4> |
| 8768 |
|
| 8769 |
<p>Calling ⎕RVAL monadically either produces one new random APL value or displays |
| 8770 |
a list of arguments for dyadic <b>⎕RVAL</b>: |
| 8771 |
</p> |
| 8772 |
<ul> |
| 8773 |
<li> <b>⎕RVAL ⍬</b> shows the valid left arguments of <b>A ⎕RVAL B</b> with a brief |
| 8774 |
description, |
| 8775 |
</li><li> <b>⎕RVAL ”</b> shows the valid syntaces of <b>A ⎕RVAL B</b> |
| 8776 |
(see also See <a href="#Function-Groups">Function Groups</a>. |
| 8777 |
</li><li> <b>⎕RVAL 0</b> returns the next random value according to the properties set with dyadic <b>⎕RVAL</b>. |
| 8778 |
</li></ul> |
| 8779 |
|
| 8780 |
<p>The properties of that next value can be controlled by the dyadic calls |
| 8781 |
of ⎕RVAL as described above. If no prior dyadic call of ⎕RVAL was made then |
| 8782 |
the properties have the following defaults: |
| 8783 |
</p> |
| 8784 |
<div class="example"> |
| 8785 |
<pre class="example"> 1 ⎕RVAL ⍬ ⍝ rank (scalar) |
| 8786 |
0 |
| 8787 |
|
| 8788 |
2 ⎕RVAL ⍬ ⍝ shape (not used since rank = 0) |
| 8789 |
1 1 1 1 1 1 1 1 |
| 8790 |
|
| 8791 |
3 ⎕RVAL ⍬ ⍝ types (integer) |
| 8792 |
0 1 0 0 0 |
| 8793 |
|
| 8794 |
4 ⎕RVAL ⍬ ⍝ max. depth (not used since probability of NESTED = 0) |
| 8795 |
4 |
| 8796 |
</pre></div> |
| 8797 |
|
| 8798 |
<p>That is, by default, ⎕RVAL ⍬ produces random integer scalars. |
| 8799 |
</p> |
| 8800 |
<p>It is sometimes convenient to be able to change the properties of the next |
| 8801 |
random value without modifying (and later restoring) the properties with |
| 8802 |
dyadic ⎕RVAL. This can be achieved with monadic ⎕RVAL with non-empty B. |
| 8803 |
</p> |
| 8804 |
<p>Let 4=⍴B. Then |
| 8805 |
</p> |
| 8806 |
<div class="example"> |
| 8807 |
<pre class="example"> Z←⎕RVAL B does essentially: |
| 8808 |
|
| 8809 |
B[1]←1 ⎕RVAL B[1] |
| 8810 |
B[2]←2 ⎕RVAL B[2] |
| 8811 |
B[3]←3 ⎕RVAL B[3] |
| 8812 |
B[4]←4 ⎕RVAL B[4] |
| 8813 |
|
| 8814 |
Z←⎕RVAL 0 |
| 8815 |
|
| 8816 |
B[1]←1 ⎕RVAL B[1] |
| 8817 |
B[2]←2 ⎕RVAL B[2] |
| 8818 |
B[3]←3 ⎕RVAL B[3] |
| 8819 |
B[4]←4 ⎕RVAL B[4] |
| 8820 |
</pre></div> |
| 8821 |
|
| 8822 |
<p>If 4 > ⍴B then the missing properties are not changed. |
| 8823 |
</p> |
| 8824 |
<p>Examples: |
| 8825 |
</p> |
| 8826 |
<div class="example"> |
| 8827 |
<pre class="example">⎕RVAL 1 (,¯4) (0 1) ⍝ return a random 0-4 element integer vector |
| 8828 |
⎕RVAL 2 (2 2) (1 0) ⍝ return a random 2×2 character array |
| 8829 |
</pre></div> |
| 8830 |
|
| 8831 |
<hr> |
| 8832 |
</div> |
| 8833 |
<div class="subsubsection" id="Syntax-Alternatives"> |
| 8834 |
<div class="header"> |
| 8835 |
<p> |
| 8836 |
Previous: <a href="#monadic-_2395RVAL-B" accesskey="p" rel="prev">monadic ⎕RVAL B</a>, Up: <a href="#Dyadic-_2395RVAL" accesskey="u" rel="up">Dyadic ⎕RVAL</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 8837 |
</div> |
| 8838 |
<span id="Syntax-Alternatives-1"></span><h4 class="subsubsection">2.40.2.7 Syntax Alternatives</h4> |
| 8839 |
|
| 8840 |
<p>For an improved readability, ⎕RVAL also accepts string arguments for its left |
| 8841 |
argument A and also the sub-function notation: |
| 8842 |
</p> |
| 8843 |
<div class="example"> |
| 8844 |
<pre class="example"> 0 ⎕RVAL B ←→ 'state' ⎕RVAL B ←→ ⎕RVAL.state B |
| 8845 |
1 ⎕RVAL B ←→ 'rank' ⎕RVAL B ←→ ⎕RVAL.rank B |
| 8846 |
2 ⎕RVAL B ←→ 'shape' ⎕RVAL B ←→ ⎕RVAL.shape B |
| 8847 |
3 ⎕RVAL B ←→ 'type' ⎕RVAL B ←→ ⎕RVAL.type B |
| 8848 |
4 ⎕RVAL B ←→ 'depth' ⎕RVAL B ←→ ⎕RVAL.depth B |
| 8849 |
</pre></div> |
| 8850 |
|
| 8851 |
<hr> |
| 8852 |
</div> |
| 8853 |
</div> |
| 8854 |
</div> |
| 8855 |
<div class="section" id="g_t_2395SI-_002d-State-Indicator"> |
| 8856 |
<div class="header"> |
| 8857 |
<p> |
| 8858 |
Next: <a href="#g_t_2395SQL-_002d-SQL-Database-Interface" accesskey="n" rel="next">⎕SQL - SQL Database Interface</a>, Previous: <a href="#g_t_2395RVAL-_002d-Random-APL-value" accesskey="p" rel="prev">⎕RVAL - Random APL value</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 8859 |
</div> |
| 8860 |
<span id="g_t_005b_003f_005dSI-_002d-State-Indicator"></span><h3 class="section">2.41 ⎕SI - State Indicator</h3> |
| 8861 |
|
| 8862 |
<p>⎕SI returns aspects of the current State Indicator, similar to the standard |
| 8863 |
command )SI. This can be used, for example, to create debug functions similar |
| 8864 |
to the assert() macro in C/C++: |
| 8865 |
</p> |
| 8866 |
<div class="example"> |
| 8867 |
<pre class="example">∇Assert B;COND;LOC;VAR |
| 8868 |
→(1≡B)⍴0 |
| 8869 |
' ' |
| 8870 |
COND←7↓,¯2 ⎕SI 4 |
| 8871 |
LOC←,¯2 ⎕SI 3 |
| 8872 |
'************************************************' |
| 8873 |
' ' |
| 8874 |
'*** Assertion (', COND, ') failed at ',LOC |
| 8875 |
'' |
| 8876 |
|
| 8877 |
⍝ show stack |
| 8878 |
⍝ |
| 8879 |
' ' |
| 8880 |
'Stack:' |
| 8881 |
7 ⎕CR ⊃¯1↓⎕SI 3 |
| 8882 |
' ' |
| 8883 |
'************************************************</pre>' |
| 8884 |
→ |
| 8885 |
∇ |
| 8886 |
</pre></div> |
| 8887 |
|
| 8888 |
<p>The right argument of ⎕SI specifies which aspect of the State Indicator |
| 8889 |
shall be returned: |
| 8890 |
</p> |
| 8891 |
<ul> |
| 8892 |
<li> ⎕SI 1: The name of the context. That name is either: |
| 8893 |
<ul> |
| 8894 |
<li> the name of a defined function, or |
| 8895 |
</li><li> ◊ for an immediate execution context, or |
| 8896 |
</li><li> ⍎ for an execute context. |
| 8897 |
</li></ul> |
| 8898 |
|
| 8899 |
</li><li> ⎕SI 2: The line number (of a defined function) or 0 for immediate execution |
| 8900 |
and execute contexts. |
| 8901 |
|
| 8902 |
</li><li> ⎕SI 3: The function name and line number in square brackets, for example: |
| 8903 |
<b>"FOO[3]"</b> |
| 8904 |
|
| 8905 |
</li><li> ⎕SI 4: Either the statement text of the function line or the error text of |
| 8906 |
an error that has occurred on the line |
| 8907 |
|
| 8908 |
</li><li> ⎕SI 5: The program counter (= token number counted from the start of the |
| 8909 |
function text) |
| 8910 |
|
| 8911 |
</li><li> ⎕SI 6: the parse mode of the context (immediate execution, execute, or |
| 8912 |
defined function). |
| 8913 |
|
| 8914 |
</li></ul> |
| 8915 |
|
| 8916 |
<p>If no left argument is provided then the result of ⎕SI is a vector with |
| 8917 |
one entry per State Indicator level (and hence ⍴⎕SI B is the depth of the SI |
| 8918 |
stack). |
| 8919 |
</p> |
| 8920 |
<p>If the optional left argument A is provided then it specifies a particular |
| 8921 |
level of the SI instead of the entire SI. A should be an integer scalar. |
| 8922 |
If A is positive then the level is counted from the oldest entry to the latest, |
| 8923 |
while negative A counts from the latest to the oldest level. |
| 8924 |
</p> |
| 8925 |
<p>For example, ¯1 ⎕SI refers to the currently executing context, ¯2 ⎕SI is |
| 8926 |
the caller, and so on. |
| 8927 |
</p> |
| 8928 |
|
| 8929 |
<hr> |
| 8930 |
</div> |
| 8931 |
<div class="section" id="g_t_2395SQL-_002d-SQL-Database-Interface"> |
| 8932 |
<div class="header"> |
| 8933 |
<p> |
| 8934 |
Next: <a href="#g_t_2395SYL-_002d-System-limits" accesskey="n" rel="next">⎕SYL - System limits</a>, Previous: <a href="#g_t_2395SI-_002d-State-Indicator" accesskey="p" rel="prev">⎕SI - State Indicator</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 8935 |
</div> |
| 8936 |
<span id="g_t_005b_003f_005dSQL-_002d-SQL-Database-Interface"></span><h3 class="section">2.42 ⎕SQL - SQL Database Interface</h3> |
| 8937 |
|
| 8938 |
<p>⎕SQL was kindly contributed by Elias Mårtenson. |
| 8939 |
</p> |
| 8940 |
<p>As of GNU APL 1.6, the native function SQL has been replaced by the |
| 8941 |
system function ⎕SQL, described below. ⎕SQL has an axis argument that |
| 8942 |
selects a sub-function of ⎕SQL. |
| 8943 |
</p> |
| 8944 |
<ul class="section-toc"> |
| 8945 |
<li><a href="#g_t_2395SQL_005b0_005d-_236c-_003a-display-sub_002dfunction-numbers" accesskey="1">⎕SQL[0] ⍬ : display sub-function numbers</a></li> |
| 8946 |
<li><a href="#g_t_2395SQL_005b0_005d-_0027_0027-_003a-display-sub_002dfunction-names" accesskey="2">⎕SQL[0] <code>''</code> : display sub-function names</a></li> |
| 8947 |
<li><a href="#ref-_2190-A-_2395SQL_005b1_005d-B-_003a-open-database" accesskey="3">ref ← A ⎕SQL[1] B : open database</a></li> |
| 8948 |
<li><a href="#g_t_2395SQL_005b2_005d-B-_003a-close-database" accesskey="4">⎕SQL[2] B : close database</a></li> |
| 8949 |
<li><a href="#Z-_2190-A-_2395SQL_005b3-ref_005d-B-_003a-database-query-_0028with-result_0029" accesskey="5">Z ← A ⎕SQL[3, ref] B : database query (with result)</a></li> |
| 8950 |
<li><a href="#Z-_2190-A-_2395SQL_005b4-ref_005d-B-_003a-database-query-_0028w_002fo-result_0029" accesskey="6">Z ← A ⎕SQL[4, ref] B : database query (w/o result)</a></li> |
| 8951 |
<li><a href="#g_t_2395SQL_005b5_005d-B-_003a-start-transaction" accesskey="7">⎕SQL[5] B : start transaction</a></li> |
| 8952 |
<li><a href="#g_t_2395SQL_005b6_005d-B-_003a-commit-transaction" accesskey="8">⎕SQL[6] B : commit transaction</a></li> |
| 8953 |
<li><a href="#g_t_2395SQL_005b7_005d-B-_003a-rollback-transaction" accesskey="9">⎕SQL[7] B : rollback transaction</a></li> |
| 8954 |
<li><a href="#Z_2190_2395SQL_005b8_005d-B-_003a-table-names">Z←⎕SQL[8] B : table names</a></li> |
| 8955 |
<li><a href="#Z_2190_2395SQL_005b9_005d-B-_003a-column-names">Z←⎕SQL[9] B : column names</a></li> |
| 8956 |
<li><a href="#Z-_2190-_2395SQL_005b10_005d-B-_003a-library-version-number">Z ← ⎕SQL[10] B : library version number</a></li> |
| 8957 |
<li><a href="#Z-_2190-_2395SQL_005b11_005d-B-_003a-library-version-string">Z ← ⎕SQL[11] B : library version string</a></li> |
| 8958 |
<li><a href="#SQLite-Quickstart">SQLite Quickstart</a></li> |
| 8959 |
<li><a href="#Deleting-Rows-From-a-Database-Table">Deleting Rows From a Database Table</a></li> |
| 8960 |
</ul> |
| 8961 |
<hr> |
| 8962 |
<div class="subsection" id="g_t_2395SQL_005b0_005d-_236c-_003a-display-sub_002dfunction-numbers"> |
| 8963 |
<div class="header"> |
| 8964 |
<p> |
| 8965 |
Next: <a href="#g_t_2395SQL_005b0_005d-_0027_0027-_003a-display-sub_002dfunction-names" accesskey="n" rel="next">⎕SQL[0] <code>''</code> : display sub-function names</a>, Up: <a href="#g_t_2395SQL-_002d-SQL-Database-Interface" accesskey="u" rel="up">⎕SQL - SQL Database Interface</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 8966 |
</div> |
| 8967 |
<span id="g_t_005b_003f_005dSQL_005b0_005d-_005b_003f_005d-_003a-display-sub_002dfunction-numbers"></span><h4 class="subsection">2.42.1 ⎕SQL[0] ⍬ : display sub-function numbers</h4> |
| 8968 |
|
| 8969 |
<p>The system function ⎕SQL is divided into a number of sub-functions. The |
| 8970 |
desired sub-function of ⎕SQL is selected by means of a numeric axis argument: |
| 8971 |
</p> |
| 8972 |
<div class="example"> |
| 8973 |
<pre class="example"> Valid (sub-)function numbers for ⎕SQL: |
| 8974 |
|
| 8975 |
Legend: Fs - database file name (path) |
| 8976 |
Ty - database type ('sqlite' or 'postgres') |
| 8977 |
Db - database handle (small integer) |
| 8978 |
Qs - SQL query string |
| 8979 |
Pv - query parameters (APL values, to be bound to Qs) |
| 8980 |
Ts - name of a table in the database (string) |
| 8981 |
Vi - DB provider (library) version (integer) |
| 8982 |
Vs - DB provider (library) version (string) |
| 8983 |
|
| 8984 |
⎕SQL[0] '' list the ⎕SQL (sub-)function names |
| 8985 |
⎕SQL[0] ⍬ list the ⎕SQL (sub-)function numbers |
| 8986 |
Db ← Ty ⎕SQL[1] Fs open database Fs & return a handle for it |
| 8987 |
⎕SQL[2] Db close database handle Db |
| 8988 |
Qs ⎕SQL[3, Db] Pv perform SQL query Qs |
| 8989 |
Qs ⎕SQL[4, Db] Pv perform SQL update Qs |
| 8990 |
⎕SQL[5] Db begin a transaction |
| 8991 |
⎕SQL[6] Db commit the current transaction |
| 8992 |
⎕SQL[7] Db roll the current transaction back |
| 8993 |
⎕SQL[8] Db list the tables in database Db |
| 8994 |
Db ⎕SQL[9] Ts list the column names and types of table Tn |
| 8995 |
Vi ← ⎕SQL[10] Ty the provider version number for type Ty |
| 8996 |
Vs ← ⎕SQL[11] Ty the provider version string for type Ty |
| 8997 |
</pre></div> |
| 8998 |
|
| 8999 |
<p>The axis argument [0] is optional; one can also use <b>⎕SQL ⍬</b>. |
| 9000 |
</p> |
| 9001 |
<hr> |
| 9002 |
</div> |
| 9003 |
<div class="subsection" id="g_t_2395SQL_005b0_005d-_0027_0027-_003a-display-sub_002dfunction-names"> |
| 9004 |
<div class="header"> |
| 9005 |
<p> |
| 9006 |
Next: <a href="#ref-_2190-A-_2395SQL_005b1_005d-B-_003a-open-database" accesskey="n" rel="next">ref ← A ⎕SQL[1] B : open database</a>, Previous: <a href="#g_t_2395SQL_005b0_005d-_236c-_003a-display-sub_002dfunction-numbers" accesskey="p" rel="prev">⎕SQL[0] ⍬ : display sub-function numbers</a>, Up: <a href="#g_t_2395SQL-_002d-SQL-Database-Interface" accesskey="u" rel="up">⎕SQL - SQL Database Interface</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 9007 |
</div> |
| 9008 |
<span id="g_t_005b_003f_005dSQL_005b0_005d-_0027_0027-_003a-display-sub_002dfunction-names"></span><h4 class="subsection">2.42.2 ⎕SQL[0] <code>''</code> : display sub-function names</h4> |
| 9009 |
|
| 9010 |
<p>As of <b>SVN version 1901</b>, ⎕SQL has been promoted to be a function group. |
| 9011 |
Instead of the function nunbers above, one can therefore also use function |
| 9012 |
names with the following syntax: |
| 9013 |
</p> |
| 9014 |
<div class="example"> |
| 9015 |
<pre class="example"> With a small performance penalty, ⎕SQL also accepts the following |
| 9016 |
sub-function names instead of sub-function numbers as axis argument: |
| 9017 |
|
| 9018 |
Legend: Fs - database file name (path) |
| 9019 |
Ty - database type ('sqlite' or 'postgres') |
| 9020 |
Db - database handle (small integer) |
| 9021 |
Qs - SQL query string |
| 9022 |
Pv - query parameters (APL values, to be bound to Qs) |
| 9023 |
Ts - name of a table in the database (string) |
| 9024 |
Vi - DB provider (library) version (integer) |
| 9025 |
Vs - DB provider (library) version (string) |
| 9026 |
|
| 9027 |
⎕SQL[5] ←→ ⎕SQL.begin ⍝ begin a transaction |
| 9028 |
⎕SQL[9] ←→ ⎕SQL.columns ⍝ show the columns of a table |
| 9029 |
⎕SQL[6] ←→ ⎕SQL.commit ⍝ end a transaction |
| 9030 |
⎕SQL[2] ←→ ⎕SQL.close ⍝ close a database handle |
| 9031 |
⎕SQL[0] ←→ ⎕SQL.list '' ⍝ ⎕SQL function names/numbers |
| 9032 |
⎕SQL[1] Fs ←→ ⎕SQL.open ⍝ open the database file |
| 9033 |
⎕SQL[3, Db] Pv ←→ ⎕SQL.query Db Pv ⍝ SQL database query |
| 9034 |
⎕SQL[7] Db ←→ ⎕SQL.rollback ⍝ roll a transaction back |
| 9035 |
⎕SQL[8] Db ←→ ⎕SQL.tables ⍝ show all tables |
| 9036 |
Qs ⎕SQL[4, Db] Pv ←→ ⎕SQL.update Db Pv ⍝ SQL database update |
| 9037 |
⎕SQL[10] ←→ ⎕SQL.version ⍝ SQL provider version number |
| 9038 |
⎕SQL[11] ←→ ⎕SQL.vstring ⍝ SQL provider version string |
| 9039 |
</pre></div> |
| 9040 |
|
| 9041 |
<p><b>NOTE:</b> The mapping from function numbers to function names of a function |
| 9042 |
group does not allow for non-scalar axis arguments (such as <b>[3, Db]</b>) |
| 9043 |
for <b>query</b> or <b>[4, Db]</b> for <b>update</b>. For that reason, the <b>Db</b> |
| 9044 |
argument of functions <b>query</b> and <b>update</b> had to be moved from the |
| 9045 |
second item in the axis argument to the first item of the right value argument, |
| 9046 |
and the right argument <b>Pv</b> (aka. query parameters) of the function axis |
| 9047 |
is now the (nested) second argument of the right argument in the named |
| 9048 |
function symtax. |
| 9049 |
</p> |
| 9050 |
<p>Like for <b>⎕SQL[0] ⍬</b> above is the axis argument [0] optional; one can |
| 9051 |
therefore also use <b>⎕SQL ”</b> instead of <b>⎕SQL[0] ”</b>. |
| 9052 |
</p> |
| 9053 |
<hr> |
| 9054 |
</div> |
| 9055 |
<div class="subsection" id="ref-_2190-A-_2395SQL_005b1_005d-B-_003a-open-database"> |
| 9056 |
<div class="header"> |
| 9057 |
<p> |
| 9058 |
Next: <a href="#g_t_2395SQL_005b2_005d-B-_003a-close-database" accesskey="n" rel="next">⎕SQL[2] B : close database</a>, Previous: <a href="#g_t_2395SQL_005b0_005d-_0027_0027-_003a-display-sub_002dfunction-names" accesskey="p" rel="prev">⎕SQL[0] <code>''</code> : display sub-function names</a>, Up: <a href="#g_t_2395SQL-_002d-SQL-Database-Interface" accesskey="u" rel="up">⎕SQL - SQL Database Interface</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 9059 |
</div> |
| 9060 |
<span id="ref-_002d-A-_005b_003f_005dSQL_005b1_005d-B-_003a-open-database"></span><h4 class="subsection">2.42.3 ref ← A ⎕SQL[1] B : open database</h4> |
| 9061 |
|
| 9062 |
<div class="example"> |
| 9063 |
<pre class="example"> type ⎕SQL[1] file |
| 9064 |
</pre></div> |
| 9065 |
|
| 9066 |
<p>Connect to database of type A using connection arguments B. The result is a |
| 9067 |
database handle <b>ref</b> to be used in the other ⎕SQL functions. |
| 9068 |
</p> |
| 9069 |
<p><b>A</b> must be a string indicating the database type. Currently supported |
| 9070 |
values are ’postgresql’ and ’sqlite’. |
| 9071 |
</p> |
| 9072 |
<p><b>B</b> is the connection parameters which depends on the type of |
| 9073 |
database: |
| 9074 |
</p> |
| 9075 |
<p>- For type≡’sqlite’: the argument is string pointing to the |
| 9076 |
database file. |
| 9077 |
</p> |
| 9078 |
<p>- For type≡’postgresql’, the argument is a standard connect |
| 9079 |
string as described in the PostgreSQL documentation. |
| 9080 |
</p> |
| 9081 |
<p>This function returns a database handle that should be used when |
| 9082 |
using other SQL functions. This value should be seen as an opaque |
| 9083 |
handle. It is, however, guaranteed that the handle is a scalar |
| 9084 |
value. |
| 9085 |
</p> |
| 9086 |
<hr> |
| 9087 |
</div> |
| 9088 |
<div class="subsection" id="g_t_2395SQL_005b2_005d-B-_003a-close-database"> |
| 9089 |
<div class="header"> |
| 9090 |
<p> |
| 9091 |
Next: <a href="#Z-_2190-A-_2395SQL_005b3-ref_005d-B-_003a-database-query-_0028with-result_0029" accesskey="n" rel="next">Z ← A ⎕SQL[3, ref] B : database query (with result)</a>, Previous: <a href="#ref-_2190-A-_2395SQL_005b1_005d-B-_003a-open-database" accesskey="p" rel="prev">ref ← A ⎕SQL[1] B : open database</a>, Up: <a href="#g_t_2395SQL-_002d-SQL-Database-Interface" accesskey="u" rel="up">⎕SQL - SQL Database Interface</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 9092 |
</div> |
| 9093 |
<span id="g_t_005b_003f_005dSQL_005b2_005d-B-_003a-close-database"></span><h4 class="subsection">2.42.4 ⎕SQL[2] B : close database</h4> |
| 9094 |
|
| 9095 |
<div class="example"> |
| 9096 |
<pre class="example"> ⎕SQL[2] ref |
| 9097 |
</pre></div> |
| 9098 |
|
| 9099 |
<p>Disconnect from database <b>ref</b>. |
| 9100 |
</p> |
| 9101 |
<p>B is the database handle that should be disconnected. After this |
| 9102 |
function has been called, no further operations are to be performed |
| 9103 |
on this handle. Future calls to ⎕SQL[1] may reuse previously |
| 9104 |
disconnected handles. |
| 9105 |
</p> |
| 9106 |
<hr> |
| 9107 |
</div> |
| 9108 |
<div class="subsection" id="Z-_2190-A-_2395SQL_005b3-ref_005d-B-_003a-database-query-_0028with-result_0029"> |
| 9109 |
<div class="header"> |
| 9110 |
<p> |
| 9111 |
Next: <a href="#Z-_2190-A-_2395SQL_005b4-ref_005d-B-_003a-database-query-_0028w_002fo-result_0029" accesskey="n" rel="next">Z ← A ⎕SQL[4, ref] B : database query (w/o result)</a>, Previous: <a href="#g_t_2395SQL_005b2_005d-B-_003a-close-database" accesskey="p" rel="prev">⎕SQL[2] B : close database</a>, Up: <a href="#g_t_2395SQL-_002d-SQL-Database-Interface" accesskey="u" rel="up">⎕SQL - SQL Database Interface</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 9112 |
</div> |
| 9113 |
<span id="Z-_002d-A-_005b_003f_005dSQL_005b3_002c-ref_005d-B-_003a-database-query-_0028with-result_0029"></span><h4 class="subsection">2.42.5 Z ← A ⎕SQL[3, ref] B : database query (with result)</h4> |
| 9114 |
|
| 9115 |
<div class="example"> |
| 9116 |
<pre class="example"> query ⎕SQL[3, ref] params |
| 9117 |
</pre></div> |
| 9118 |
|
| 9119 |
<p>Execute a select statement and return the result table. |
| 9120 |
</p> |
| 9121 |
<p>The axis parameter indicates the database handle. |
| 9122 |
</p> |
| 9123 |
<p>A is a select statement to be executed. Positional parameters can |
| 9124 |
be supplied by specifying a question mark "?" in the statement. |
| 9125 |
</p> |
| 9126 |
<p>B is an array containing the values for the positional parameters. |
| 9127 |
If the array is of rank 2, the statement will be executed multiple |
| 9128 |
times with each row being the values for each call. |
| 9129 |
</p> |
| 9130 |
<p>The return value Z is a rank-2 array representing the result of the |
| 9131 |
select statement. Null values are returned as ⍬ and empty strings |
| 9132 |
are returned as ”. |
| 9133 |
</p> |
| 9134 |
<hr> |
| 9135 |
</div> |
| 9136 |
<div class="subsection" id="Z-_2190-A-_2395SQL_005b4-ref_005d-B-_003a-database-query-_0028w_002fo-result_0029"> |
| 9137 |
<div class="header"> |
| 9138 |
<p> |
| 9139 |
Next: <a href="#g_t_2395SQL_005b5_005d-B-_003a-start-transaction" accesskey="n" rel="next">⎕SQL[5] B : start transaction</a>, Previous: <a href="#Z-_2190-A-_2395SQL_005b3-ref_005d-B-_003a-database-query-_0028with-result_0029" accesskey="p" rel="prev">Z ← A ⎕SQL[3, ref] B : database query (with result)</a>, Up: <a href="#g_t_2395SQL-_002d-SQL-Database-Interface" accesskey="u" rel="up">⎕SQL - SQL Database Interface</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 9140 |
</div> |
| 9141 |
<span id="Z-_002d-A-_005b_003f_005dSQL_005b4_002c-ref_005d-B-_003a-database-query-_0028w_002fo-result_0029"></span><h4 class="subsection">2.42.6 Z ← A ⎕SQL[4, ref] B : database query (w/o result)</h4> |
| 9142 |
|
| 9143 |
<div class="example"> |
| 9144 |
<pre class="example"> query ⎕SQL[4, ref] params |
| 9145 |
</pre></div> |
| 9146 |
|
| 9147 |
<p>Execute an SQL statement that does not return a result. |
| 9148 |
</p> |
| 9149 |
<p>This function is identical to SQL∆Select with the exception that it |
| 9150 |
is used on statements which do not return a result table. |
| 9151 |
</p> |
| 9152 |
<hr> |
| 9153 |
</div> |
| 9154 |
<div class="subsection" id="g_t_2395SQL_005b5_005d-B-_003a-start-transaction"> |
| 9155 |
<div class="header"> |
| 9156 |
<p> |
| 9157 |
Next: <a href="#g_t_2395SQL_005b6_005d-B-_003a-commit-transaction" accesskey="n" rel="next">⎕SQL[6] B : commit transaction</a>, Previous: <a href="#Z-_2190-A-_2395SQL_005b4-ref_005d-B-_003a-database-query-_0028w_002fo-result_0029" accesskey="p" rel="prev">Z ← A ⎕SQL[4, ref] B : database query (w/o result)</a>, Up: <a href="#g_t_2395SQL-_002d-SQL-Database-Interface" accesskey="u" rel="up">⎕SQL - SQL Database Interface</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 9158 |
</div> |
| 9159 |
<span id="g_t_005b_003f_005dSQL_005b5_005d-B-_003a-start-transaction"></span><h4 class="subsection">2.42.7 ⎕SQL[5] B : start transaction</h4> |
| 9160 |
|
| 9161 |
<div class="example"> |
| 9162 |
<pre class="example"> ⎕SQL[5] ref |
| 9163 |
</pre></div> |
| 9164 |
|
| 9165 |
<p>Begin a transaction. |
| 9166 |
</p> |
| 9167 |
<hr> |
| 9168 |
</div> |
| 9169 |
<div class="subsection" id="g_t_2395SQL_005b6_005d-B-_003a-commit-transaction"> |
| 9170 |
<div class="header"> |
| 9171 |
<p> |
| 9172 |
Next: <a href="#g_t_2395SQL_005b7_005d-B-_003a-rollback-transaction" accesskey="n" rel="next">⎕SQL[7] B : rollback transaction</a>, Previous: <a href="#g_t_2395SQL_005b5_005d-B-_003a-start-transaction" accesskey="p" rel="prev">⎕SQL[5] B : start transaction</a>, Up: <a href="#g_t_2395SQL-_002d-SQL-Database-Interface" accesskey="u" rel="up">⎕SQL - SQL Database Interface</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 9173 |
</div> |
| 9174 |
<span id="g_t_005b_003f_005dSQL_005b6_005d-B-_003a-commit-transaction"></span><h4 class="subsection">2.42.8 ⎕SQL[6] B : commit transaction</h4> |
| 9175 |
|
| 9176 |
<div class="example"> |
| 9177 |
<pre class="example"> ⎕SQL[6] ref |
| 9178 |
</pre></div> |
| 9179 |
|
| 9180 |
<p>Commit a transaction. |
| 9181 |
</p> |
| 9182 |
<hr> |
| 9183 |
</div> |
| 9184 |
<div class="subsection" id="g_t_2395SQL_005b7_005d-B-_003a-rollback-transaction"> |
| 9185 |
<div class="header"> |
| 9186 |
<p> |
| 9187 |
Next: <a href="#Z_2190_2395SQL_005b8_005d-B-_003a-table-names" accesskey="n" rel="next">Z←⎕SQL[8] B : table names</a>, Previous: <a href="#g_t_2395SQL_005b6_005d-B-_003a-commit-transaction" accesskey="p" rel="prev">⎕SQL[6] B : commit transaction</a>, Up: <a href="#g_t_2395SQL-_002d-SQL-Database-Interface" accesskey="u" rel="up">⎕SQL - SQL Database Interface</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 9188 |
</div> |
| 9189 |
<span id="g_t_005b_003f_005dSQL_005b7_005d-B-_003a-rollback-transaction"></span><h4 class="subsection">2.42.9 ⎕SQL[7] B : rollback transaction</h4> |
| 9190 |
|
| 9191 |
<div class="example"> |
| 9192 |
<pre class="example"> ⎕SQL[7] ref |
| 9193 |
</pre></div> |
| 9194 |
|
| 9195 |
<p>Rolls back the current transaction. |
| 9196 |
</p> |
| 9197 |
<hr> |
| 9198 |
</div> |
| 9199 |
<div class="subsection" id="Z_2190_2395SQL_005b8_005d-B-_003a-table-names"> |
| 9200 |
<div class="header"> |
| 9201 |
<p> |
| 9202 |
Next: <a href="#Z_2190_2395SQL_005b9_005d-B-_003a-column-names" accesskey="n" rel="next">Z←⎕SQL[9] B : column names</a>, Previous: <a href="#g_t_2395SQL_005b7_005d-B-_003a-rollback-transaction" accesskey="p" rel="prev">⎕SQL[7] B : rollback transaction</a>, Up: <a href="#g_t_2395SQL-_002d-SQL-Database-Interface" accesskey="u" rel="up">⎕SQL - SQL Database Interface</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 9203 |
</div> |
| 9204 |
<span id="Z_002d_005b_003f_005dSQL_005b8_005d-B-_003a-table-names"></span><h4 class="subsection">2.42.10 Z←⎕SQL[8] B : table names</h4> |
| 9205 |
|
| 9206 |
<div class="example"> |
| 9207 |
<pre class="example"> ⎕SQL[8] ref |
| 9208 |
</pre></div> |
| 9209 |
|
| 9210 |
<p>Return an array containing the name of all tables. |
| 9211 |
</p> |
| 9212 |
<hr> |
| 9213 |
</div> |
| 9214 |
<div class="subsection" id="Z_2190_2395SQL_005b9_005d-B-_003a-column-names"> |
| 9215 |
<div class="header"> |
| 9216 |
<p> |
| 9217 |
Next: <a href="#Z-_2190-_2395SQL_005b10_005d-B-_003a-library-version-number" accesskey="n" rel="next">Z ← ⎕SQL[10] B : library version number</a>, Previous: <a href="#Z_2190_2395SQL_005b8_005d-B-_003a-table-names" accesskey="p" rel="prev">Z←⎕SQL[8] B : table names</a>, Up: <a href="#g_t_2395SQL-_002d-SQL-Database-Interface" accesskey="u" rel="up">⎕SQL - SQL Database Interface</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 9218 |
</div> |
| 9219 |
<span id="Z_002d_005b_003f_005dSQL_005b9_005d-B-_003a-column-names"></span><h4 class="subsection">2.42.11 Z←⎕SQL[9] B : column names</h4> |
| 9220 |
|
| 9221 |
<div class="example"> |
| 9222 |
<pre class="example"> ref ⎕SQL[9] table |
| 9223 |
</pre></div> |
| 9224 |
|
| 9225 |
<p>Return an array containing information about the columns in the |
| 9226 |
given table. Currently, the column layout is as follows: |
| 9227 |
</p> |
| 9228 |
<p>Name |
| 9229 |
Type |
| 9230 |
</p> |
| 9231 |
<p>More columns containing additional information may be added in a future |
| 9232 |
release. |
| 9233 |
</p> |
| 9234 |
|
| 9235 |
<hr> |
| 9236 |
</div> |
| 9237 |
<div class="subsection" id="Z-_2190-_2395SQL_005b10_005d-B-_003a-library-version-number"> |
| 9238 |
<div class="header"> |
| 9239 |
<p> |
| 9240 |
Next: <a href="#Z-_2190-_2395SQL_005b11_005d-B-_003a-library-version-string" accesskey="n" rel="next">Z ← ⎕SQL[11] B : library version string</a>, Previous: <a href="#Z_2190_2395SQL_005b9_005d-B-_003a-column-names" accesskey="p" rel="prev">Z←⎕SQL[9] B : column names</a>, Up: <a href="#g_t_2395SQL-_002d-SQL-Database-Interface" accesskey="u" rel="up">⎕SQL - SQL Database Interface</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 9241 |
</div> |
| 9242 |
<span id="Z-_002d-_005b_003f_005dSQL_005b10_005d-B-_003a-library-version-number"></span><h4 class="subsection">2.42.12 Z ← ⎕SQL[10] B : library version number</h4> |
| 9243 |
|
| 9244 |
<p>Return the version number (integer scalar) of the library that was used |
| 9245 |
to implement the database type <b>B</b>. Depending on the SQL libraries |
| 9246 |
detected by ./configure, ⎕SQL may support no, one, or more than one |
| 9247 |
kind of SQL database type (the database type is sometimes refered to as |
| 9248 |
"SQL provider). |
| 9249 |
</p> |
| 9250 |
<hr> |
| 9251 |
</div> |
| 9252 |
<div class="subsection" id="Z-_2190-_2395SQL_005b11_005d-B-_003a-library-version-string"> |
| 9253 |
<div class="header"> |
| 9254 |
<p> |
| 9255 |
Next: <a href="#SQLite-Quickstart" accesskey="n" rel="next">SQLite Quickstart</a>, Previous: <a href="#Z-_2190-_2395SQL_005b10_005d-B-_003a-library-version-number" accesskey="p" rel="prev">Z ← ⎕SQL[10] B : library version number</a>, Up: <a href="#g_t_2395SQL-_002d-SQL-Database-Interface" accesskey="u" rel="up">⎕SQL - SQL Database Interface</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 9256 |
</div> |
| 9257 |
<span id="Z-_002d-_005b_003f_005dSQL_005b11_005d-B-_003a-library-version-string"></span><h4 class="subsection">2.42.13 Z ← ⎕SQL[11] B : library version string</h4> |
| 9258 |
|
| 9259 |
<p>Return the version string of the library that was used to implement the |
| 9260 |
database type <b>B</b>. Depending on the SQL libraries |
| 9261 |
detected by ./configure, ⎕SQL may support no, one, or more than one |
| 9262 |
kind of SQL database type (the database type is sometimes refered to as |
| 9263 |
"SQL provider). |
| 9264 |
</p> |
| 9265 |
<hr> |
| 9266 |
</div> |
| 9267 |
<div class="subsection" id="SQLite-Quickstart"> |
| 9268 |
<div class="header"> |
| 9269 |
<p> |
| 9270 |
Next: <a href="#Deleting-Rows-From-a-Database-Table" accesskey="n" rel="next">Deleting Rows From a Database Table</a>, Previous: <a href="#Z-_2190-_2395SQL_005b11_005d-B-_003a-library-version-string" accesskey="p" rel="prev">Z ← ⎕SQL[11] B : library version string</a>, Up: <a href="#g_t_2395SQL-_002d-SQL-Database-Interface" accesskey="u" rel="up">⎕SQL - SQL Database Interface</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 9271 |
</div> |
| 9272 |
<span id="SQLite-Quickstart-1"></span><h4 class="subsection">2.42.14 SQLite Quickstart</h4> |
| 9273 |
|
| 9274 |
<p><b>SQL</b> is a powerful query language with many functions for manipulating |
| 9275 |
the data that is stored in the tables of databases. Similarly, APL is |
| 9276 |
a powerful language with many functions for manipulating the data stored |
| 9277 |
in matrices (the APL conterpart of SQL database tables). The overlap in |
| 9278 |
functionality between SQL and APL is considerable. That means that an APL |
| 9279 |
programmer always has the follwing options: |
| 9280 |
</p> |
| 9281 |
<ul> |
| 9282 |
<li> Manipulate SQL database tables directly. This requires a detailed |
| 9283 |
understanding of the SQL query lannguage. |
| 9284 |
|
| 9285 |
</li><li> Manipulate the data in APL. That means: |
| 9286 |
<ul> |
| 9287 |
<li> Reading SQL database tables (or parts of them) into APL matrices, |
| 9288 |
</li><li> manipulate the matrices in APL, and |
| 9289 |
</li><li> write the result back into the SQL tables. |
| 9290 |
</li></ul> |
| 9291 |
<p>This approach requires only rather basic knowledge of the SQL query |
| 9292 |
lannguage. It might have a small performance panalty, but that performance |
| 9293 |
penalty will only be noticable if the databases involved are huge. |
| 9294 |
</p></li><li> A mix of the options above, e.g if performance matters. |
| 9295 |
</li></ul> |
| 9296 |
|
| 9297 |
<p>This SQLite Quickstart follows the second option. The basic SQL operations |
| 9298 |
explained in this Quickstart are: |
| 9299 |
</p> |
| 9300 |
<ul> |
| 9301 |
<li> deleting a database, |
| 9302 |
</li><li> creating a new database, |
| 9303 |
</li><li> creating a database table, |
| 9304 |
</li><li> writing an APL matrix into a database table, |
| 9305 |
</li><li> reading a database table into an APL matrix, |
| 9306 |
</li><li> updating a database table, and |
| 9307 |
</li><li> deleting rows from a database table. |
| 9308 |
</li></ul> |
| 9309 |
|
| 9310 |
<ul class="section-toc"> |
| 9311 |
<li><a href="#Deleting-a-Database" accesskey="1">Deleting a Database</a></li> |
| 9312 |
<li><a href="#Creating-a-new-Database" accesskey="2">Creating a new Database</a></li> |
| 9313 |
<li><a href="#Creating-a-Database-Table" accesskey="3">Creating a Database Table</a></li> |
| 9314 |
<li><a href="#Excursus_003a-Dynamic-Query-Strings" accesskey="4">Excursus: Dynamic Query Strings</a></li> |
| 9315 |
<li><a href="#Writing-an-APL-matrix-into-a-Database-Table" accesskey="5">Writing an APL matrix into a Database Table</a></li> |
| 9316 |
<li><a href="#Reading-a-Database-Table-into-an-APL-Matrix" accesskey="6">Reading a Database Table into an APL Matrix</a></li> |
| 9317 |
<li><a href="#Updating-a-Database-Table" accesskey="7">Updating a Database Table</a></li> |
| 9318 |
</ul> |
| 9319 |
<hr> |
| 9320 |
<div class="subsubsection" id="Deleting-a-Database"> |
| 9321 |
<div class="header"> |
| 9322 |
<p> |
| 9323 |
Next: <a href="#Creating-a-new-Database" accesskey="n" rel="next">Creating a new Database</a>, Up: <a href="#SQLite-Quickstart" accesskey="u" rel="up">SQLite Quickstart</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 9324 |
</div> |
| 9325 |
<span id="Deleting-a-Database-1"></span><h4 class="subsubsection">2.42.14.1 Deleting a Database</h4> |
| 9326 |
|
| 9327 |
<p>In order to have a well-defined starting point we delete any |
| 9328 |
already existing database. In SQLite every database is contained |
| 9329 |
in a single file, frequently named <b>db.sqlite</b>. |
| 9330 |
</p> |
| 9331 |
<p><b>CAUTION:</b> The <b>⎕FIO.unlink</b> command below will erase any existing |
| 9332 |
database without a warning. |
| 9333 |
</p> |
| 9334 |
<div class="example"> |
| 9335 |
<pre class="example"> )CLEAR |
| 9336 |
CLEAR WS |
| 9337 |
|
| 9338 |
⍝ delete any existing database |
| 9339 |
⍝ |
| 9340 |
Filename ← "db.sqlite" ⍝ name of the database to be deleted |
| 9341 |
⎕FIO.strerror ⎕FIO.unlink Filename |
| 9342 |
Success |
| 9343 |
|
| 9344 |
⍝ verify that it was deleted |
| 9345 |
⍝ |
| 9346 |
⎕FIO.strerror ⎕FIO.unlink Filename |
| 9347 |
No such file or directory |
| 9348 |
</pre></div> |
| 9349 |
|
| 9350 |
<p><b>NOTES:</b> An SQLite database can be closed in two ways: using <b>⎕FIO.unlink</b> |
| 9351 |
as shown above, or with an SQL query such as |
| 9352 |
<b>"DROP DATABASE IF EXISTS db.sqlite"</b>. However, to issue an SQL query we |
| 9353 |
would need to create an SQL connection to a database that we do not yet have |
| 9354 |
at this point. |
| 9355 |
</p> |
| 9356 |
<p>For databases that are more complex than <b>SQLite</b>, an SQL query or a utility |
| 9357 |
program shipped with the database might be required. For example, postgreSQL |
| 9358 |
comes with a program named <b>dropdb</b> that deletes a database. Such programs |
| 9359 |
can be called from APL with the <b>)HOST</b> command or with <b>⎕FIO.fork_daemon</b>. |
| 9360 |
</p> |
| 9361 |
<hr> |
| 9362 |
</div> |
| 9363 |
<div class="subsubsection" id="Creating-a-new-Database"> |
| 9364 |
<div class="header"> |
| 9365 |
<p> |
| 9366 |
Next: <a href="#Creating-a-Database-Table" accesskey="n" rel="next">Creating a Database Table</a>, Previous: <a href="#Deleting-a-Database" accesskey="p" rel="prev">Deleting a Database</a>, Up: <a href="#SQLite-Quickstart" accesskey="u" rel="up">SQLite Quickstart</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 9367 |
</div> |
| 9368 |
<span id="Creating-a-new-Database-1"></span><h4 class="subsubsection">2.42.14.2 Creating a new Database</h4> |
| 9369 |
|
| 9370 |
<p>To read from or write into a database we need a database handle (sometimes |
| 9371 |
called a database connection) for it: |
| 9372 |
</p> |
| 9373 |
<div class="example"> |
| 9374 |
<pre class="example"> )CLEAR |
| 9375 |
CLEAR WS |
| 9376 |
|
| 9377 |
⍝ create a new (and empty) database |
| 9378 |
⍝ |
| 9379 |
Filename ← 'db.sqlite' ⍝ name of the database to be created |
| 9380 |
Type ← 'sqlite' ⍝ database type |
| 9381 |
DB ← Type ⎕SQL.open Filename ⍝ create the database |
| 9382 |
|
| 9383 |
⎕SQL.close DB ⍝ and close it |
| 9384 |
</pre></div> |
| 9385 |
|
| 9386 |
<p><b>NOTES:</b> If a file with the given <b>Filename</b> already exists, then |
| 9387 |
<b>⎕SQL.open</b> simply connects to it and returns a handle (a small integer) |
| 9388 |
for the connection. The handle is used like a file descri[tor for an open |
| 9389 |
file in the operating system. The handle is later used for subsequent database |
| 9390 |
operations of ⎕SQL (until the connection is closed). |
| 9391 |
</p> |
| 9392 |
<p>If no file with the given <b>Filename</b> exists, then <b>⎕SQL.open</b> |
| 9393 |
creates a file with than name and then connects to it. It is possible to have |
| 9394 |
several such connections to different databases at the same time. It is also |
| 9395 |
possible to have several connections to the same database at the same time |
| 9396 |
(and then one should use database transactions to avoid conflicts with the |
| 9397 |
data written to the same database via different connections). |
| 9398 |
</p> |
| 9399 |
<p><b>postgreSQL</b> is shipped with programs <b>createdb</b> for creating databases, |
| 9400 |
<b>createuser</b> for creating database users, and <b>psql</b> for various other |
| 9401 |
database administration tasks. These programs can be called from APL with |
| 9402 |
the <b>)HOST</b> command or with <b>⎕FIO.fork_daemon</b>. |
| 9403 |
</p> |
| 9404 |
<hr> |
| 9405 |
</div> |
| 9406 |
<div class="subsubsection" id="Creating-a-Database-Table"> |
| 9407 |
<div class="header"> |
| 9408 |
<p> |
| 9409 |
Next: <a href="#Excursus_003a-Dynamic-Query-Strings" accesskey="n" rel="next">Excursus: Dynamic Query Strings</a>, Previous: <a href="#Creating-a-new-Database" accesskey="p" rel="prev">Creating a new Database</a>, Up: <a href="#SQLite-Quickstart" accesskey="u" rel="up">SQLite Quickstart</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 9410 |
</div> |
| 9411 |
<span id="Creating-a-Database-Table-1"></span><h4 class="subsubsection">2.42.14.3 Creating a Database Table</h4> |
| 9412 |
|
| 9413 |
<p>An SQL database is a set of tables. The next step after a new database was |
| 9414 |
created and a connection to it was opened is to define one or more tables |
| 9415 |
in the database. Every table has one or more named columns and zero or more |
| 9416 |
rows. Every column has attributes, some of which are mandatory (e.g. the |
| 9417 |
column name and in some SQL dialects the data type) while others are optional |
| 9418 |
(e.g. the data type in other SQL dialects or the size of the items in the |
| 9419 |
column). Creating a database table means to specify a name for a table and |
| 9420 |
to specify the attributes of the table columns. |
| 9421 |
</p> |
| 9422 |
<p>In this quickstart we create a table named <b>EMPLOYEES</b> with 5 columns named |
| 9423 |
<b>ID</b>, <b>NAME</b>, <b>ADDRESS</b>, <b>AGE</b>, and <b>SALARY</b>. |
| 9424 |
</p> |
| 9425 |
<div class="example"> |
| 9426 |
<pre class="example"> )CLEAR |
| 9427 |
CLEAR WS |
| 9428 |
|
| 9429 |
Filename ← 'db.sqlite' ⍝ name of the database to be used |
| 9430 |
Type ← 'sqlite' ⍝ database type |
| 9431 |
DB ← Type ⎕SQL.open Filename ⍝ open the database |
| 9432 |
|
| 9433 |
⍝ define an SQL Query string Qs that creates a table |
| 9434 |
⍝ |
| 9435 |
Qs ← ,⊃««« |
| 9436 |
CREATE TABLE EMPLOYEES( |
| 9437 |
ID INT NOT NULL PRIMARY KEY, |
| 9438 |
NAME TEXT NOT NULL, |
| 9439 |
AGE INT NOT NULL, |
| 9440 |
ADDRESS CHAR(50), |
| 9441 |
SALARY REAL); |
| 9442 |
»»» |
| 9443 |
|
| 9444 |
⍝ perform the SQL query according to query string Qs. |
| 9445 |
⍝ |
| 9446 |
Qs ⎕SQL.query DB ⍬ |
| 9447 |
|
| 9448 |
⍝ show the tables in the database |
| 9449 |
⍝ |
| 9450 |
⎕SQL.tables DB |
| 9451 |
EMPLOYEES |
| 9452 |
|
| 9453 |
DB ⎕SQL.columns 'EMPLOYEES' |
| 9454 |
ID INT |
| 9455 |
NAME TEXT |
| 9456 |
AGE INT |
| 9457 |
ADDRESS CHAR(50) |
| 9458 |
SALARY REAL |
| 9459 |
|
| 9460 |
⎕SQL.close DB ⍝ and close DB |
| 9461 |
</pre></div> |
| 9462 |
|
| 9463 |
<p><b>NOTES:</b> As we see above, SQL query strings tend to be quite long. We could |
| 9464 |
have removed most of the blanks and all of the linefeeds in the query string |
| 9465 |
above, but readability of the SQL query would have suffered a lot by doing |
| 9466 |
that. Instead we used a multi-line GNU APL script ««« ... »»» for the query |
| 9467 |
text, disclose it (which turns the APL vector of strings into an APL matrix, |
| 9468 |
and finally ravel it (to make it a string). |
| 9469 |
</p> |
| 9470 |
<p>Many SQL query strings contain strings themselves, e.g. for column names that |
| 9471 |
contain blanks or for string values in columns. IOW, the query string is a |
| 9472 |
string that contains other strings. To avoid the need to escape the SQL quotes |
| 9473 |
inside (quoted) APL strings we have quoted the multi-line query string with |
| 9474 |
««« ... »»» instead of """ ... """ or ”’ ... ”’. |
| 9475 |
</p> |
| 9476 |
<p>The right argument of <b>⎕SQL.query</b> is <b>DB ⍬</b> (and not simply <b>DB</b> as |
| 9477 |
in other ⎕SQL functions). This is because an SQL query string can have |
| 9478 |
parameters as we will see below. The query string above has no parameters and |
| 9479 |
therefore the parameter list for the query string is <b>⍬</b> aka. <b>⍳0</b>. |
| 9480 |
</p> |
| 9481 |
<p>Finally, SQL table columns have names, but SQL table rows do not. It is |
| 9482 |
therefore common practice (though not required) that the first column of a |
| 9483 |
table is a unique integer ID that identifies the row and can later be used |
| 9484 |
to quickly locate the row in a large database. |
| 9485 |
</p> |
| 9486 |
<hr> |
| 9487 |
</div> |
| 9488 |
<div class="subsubsection" id="Excursus_003a-Dynamic-Query-Strings"> |
| 9489 |
<div class="header"> |
| 9490 |
<p> |
| 9491 |
Next: <a href="#Writing-an-APL-matrix-into-a-Database-Table" accesskey="n" rel="next">Writing an APL matrix into a Database Table</a>, Previous: <a href="#Creating-a-Database-Table" accesskey="p" rel="prev">Creating a Database Table</a>, Up: <a href="#SQLite-Quickstart" accesskey="u" rel="up">SQLite Quickstart</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 9492 |
</div> |
| 9493 |
<span id="Excursus_003a-Dynamic-Query-Strings-1"></span><h4 class="subsubsection">2.42.14.4 Excursus: Dynamic Query Strings</h4> |
| 9494 |
|
| 9495 |
<p>The SQL query strings <b>(Qs)</b> used so far were <b>static</b>, which means that |
| 9496 |
they are sent verbatim to the database machinery. In the following we will |
| 9497 |
also use SQL query strings that are are a mix of static text and the character <b>%</b> in the query string. In other SQL dialects the placeholders |
| 9498 |
may be different. For example in <b>postgreSQL</b> the placeholders in a query |
| 9499 |
string are <b>$1</b>, <b>$2</b>, <b>$3</b>, and so forth. |
| 9500 |
</p> |
| 9501 |
<p>The placeholders in a dynamic query string are replaced by |
| 9502 |
string is to the database machinery. For example: |
| 9503 |
</p> |
| 9504 |
<div class="example"> |
| 9505 |
<pre class="example"> ⍝ dynamic query string Qs |
| 9506 |
⍝ |
| 9507 |
Qs ← ,⊃««« |
| 9508 |
INSERT INTO EMPLOYEES(ID, NAME, AGE, ADDRESS, SALARY |
| 9509 |
VALUES(?, ?, ?, ?, ?); |
| 9510 |
»»» |
| 9511 |
|
| 9512 |
⍝ query string parameters |
| 9513 |
⍝ |
| 9514 |
PARAMS ← 1 "Paul" 32 "California" 20000 |
| 9515 |
|
| 9516 |
⍝ number of placeholders in Qs |
| 9517 |
⍝ |
| 9518 |
+/Qs = '?' |
| 9519 |
5 |
| 9520 |
|
| 9521 |
⍝ number of parameters (shall be equal to the number of placeholders) |
| 9522 |
⍝ |
| 9523 |
⍴PARAMS |
| 9524 |
5 |
| 9525 |
|
| 9526 |
⍝ the (intermediate) result of replacing the placeholders in the dynamic |
| 9527 |
⍝ query string Qs would then be this static query string: |
| 9528 |
⍝ |
| 9529 |
RESULT ← ,⊃««« |
| 9530 |
INSERT INTO EMPLOYEES(ID, NAME, AGE, ADDRESS, SALARY |
| 9531 |
VALUES(1, "Paul", 32, "California", 20000); |
| 9532 |
»»» |
| 9533 |
</pre></div> |
| 9534 |
|
| 9535 |
<p>The example above shows the binding of query string parameters to query |
| 9536 |
strings for the case where the rank of the parameters is ≤ 1. <b>⎕SQL</b> also |
| 9537 |
supports parameters with rank 2; in that case the query is repeated for |
| 9538 |
every row of the parameter matrix. I.e. the placeholders in same query |
| 9539 |
string <b>Qs</b> are being replaced with every row of the parameter matrix |
| 9540 |
before the result of each replacement is sent as a (static) query to the |
| 9541 |
database machinery. This feature makes it rather simple to write an APL |
| 9542 |
matrix (= query parameter) to the database. |
| 9543 |
</p> |
| 9544 |
<p>Dynamic query strings are allowed in two ⎕SQL sub-functions: in function 3 |
| 9545 |
(⎕SQL.query) and in function 4 (⎕SQL.update). The syntax differs slightly |
| 9546 |
beween ⎕SQL function numbers and ⎕SQL function names: |
| 9547 |
</p> |
| 9548 |
<div class="example"> |
| 9549 |
<pre class="example"> Qs ⎕SQL.query DB PARAMS ⍝ ⎕SQL sub-function name |
| 9550 |
Qs ⎕SQL[3, DB] PARAMS ⍝ ⎕SQL sub-function number |
| 9551 |
|
| 9552 |
Qs ⎕SQL.update DB PARAMS ⍝ ⎕SQL sub-function name |
| 9553 |
Qs ⎕SQL[4, DB] PARAMS ⍝ ⎕SQL sub-function number |
| 9554 |
</pre></div> |
| 9555 |
|
| 9556 |
<p>For rank 2 parameters shall the number of placeholders be equal to the |
| 9557 |
number of colums of the APL matrix. If a query string contains no placeholders |
| 9558 |
then the parameters shall be ⍬ (aka. ⍳0). |
| 9559 |
</p> |
| 9560 |
<hr> |
| 9561 |
</div> |
| 9562 |
<div class="subsubsection" id="Writing-an-APL-matrix-into-a-Database-Table"> |
| 9563 |
<div class="header"> |
| 9564 |
<p> |
| 9565 |
Next: <a href="#Reading-a-Database-Table-into-an-APL-Matrix" accesskey="n" rel="next">Reading a Database Table into an APL Matrix</a>, Previous: <a href="#Excursus_003a-Dynamic-Query-Strings" accesskey="p" rel="prev">Excursus: Dynamic Query Strings</a>, Up: <a href="#SQLite-Quickstart" accesskey="u" rel="up">SQLite Quickstart</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 9566 |
</div> |
| 9567 |
<span id="Writing-an-APL-matrix-into-a-Database-Table-1"></span><h4 class="subsubsection">2.42.14.5 Writing an APL matrix into a Database Table</h4> |
| 9568 |
|
| 9569 |
<p>Now suppose that we have an APL matrix with the same columns as our |
| 9570 |
SQL table created above. |
| 9571 |
</p> |
| 9572 |
<div class="example"> |
| 9573 |
<pre class="example"> )CLEAR |
| 9574 |
CLEAR WS |
| 9575 |
|
| 9576 |
MATRIX ← 4 5⍴0 |
| 9577 |
MATRIX[1;] ← 1 'Paul' 32 'California' 20000.00 |
| 9578 |
MATRIX[2;] ← 2 'Allan' 25 'Texas' 15000.00 |
| 9579 |
MATRIX[3;] ← 3 'Teddy' 23 'Norway' 20000.00 |
| 9580 |
MATRIX[4;] ← 4 'Gunnar' 26 'Sweden' 18000.00 |
| 9581 |
|
| 9582 |
⍝ show MATRXIX |
| 9583 |
⍝ |
| 9584 |
8 ⎕CR MATRIX |
| 9585 |
┌→─────────────────────────────┐ |
| 9586 |
↓┌→───┐ 32 ┌→─────────┐ 20000│ |
| 9587 |
││Paul│ │California│ │ |
| 9588 |
│└────┘ └──────────┘ │ |
| 9589 |
│┌→────┐ 25 ┌→────┐ 15000│ |
| 9590 |
││Allan│ │Texas│ │ |
| 9591 |
│└─────┘ └─────┘ │ |
| 9592 |
│┌→────┐ 23 ┌→─────┐ 20000│ |
| 9593 |
││Teddy│ │Norway│ │ |
| 9594 |
│└─────┘ └──────┘ │ |
| 9595 |
│┌→─────┐ 26 ┌→─────┐ 18000│ |
| 9596 |
││Gunnar│ │Sweden│ │ |
| 9597 |
│└──────┘ └──────┘ │ |
| 9598 |
└ϵ─────────────────────────────┘ |
| 9599 |
</pre></div> |
| 9600 |
|
| 9601 |
<p>This <b>MATRIX</b> can then be written (more precisely: appended) to the |
| 9602 |
database table <b>EMPLOYEES</b> like this: |
| 9603 |
</p> |
| 9604 |
<div class="example"> |
| 9605 |
<pre class="example"> )CLEAR |
| 9606 |
CLEAR WS |
| 9607 |
|
| 9608 |
Filename ← 'db.sqlite' ⍝ name of the database to be used |
| 9609 |
Type ← 'sqlite' ⍝ database type |
| 9610 |
DB ← Type ⎕SQL.open Filename ⍝ open the database |
| 9611 |
|
| 9612 |
Qs ← ,⊃««« |
| 9613 |
INSERT INTO EMPLOYEES(ID, NAME, AGE, ADDRESS, SALARY) |
| 9614 |
VALUES(?, ?, ?, ?, ?); |
| 9615 |
»»» |
| 9616 |
Qs ⎕SQL.query DB MATRIX |
| 9617 |
|
| 9618 |
⎕SQL.close DB ⍝ and close DB |
| 9619 |
</pre></div> |
| 9620 |
|
| 9621 |
<hr> |
| 9622 |
</div> |
| 9623 |
<div class="subsubsection" id="Reading-a-Database-Table-into-an-APL-Matrix"> |
| 9624 |
<div class="header"> |
| 9625 |
<p> |
| 9626 |
Next: <a href="#Updating-a-Database-Table" accesskey="n" rel="next">Updating a Database Table</a>, Previous: <a href="#Writing-an-APL-matrix-into-a-Database-Table" accesskey="p" rel="prev">Writing an APL matrix into a Database Table</a>, Up: <a href="#SQLite-Quickstart" accesskey="u" rel="up">SQLite Quickstart</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 9627 |
</div> |
| 9628 |
<span id="Reading-a-Database-Table-into-an-APL-Matrix-1"></span><h4 class="subsubsection">2.42.14.6 Reading a Database Table into an APL Matrix</h4> |
| 9629 |
|
| 9630 |
<p>Reading a matrix back from a database table uses a <b>SELECT</b> query. <b>SELECT</b> |
| 9631 |
is the counterpart of indexed reference or indexed assignment in APL and works, |
| 9632 |
like in APL, in both directions (i.e. reading from tables and writing to |
| 9633 |
tables). In a <b>SELECT</b> query one can select specific rows and columns of the |
| 9634 |
table, which is left as an exercise for the reader. In this quickstart we want |
| 9635 |
to keep things simple and read an entire table back: |
| 9636 |
</p> |
| 9637 |
<p>Due to the absence of a binding mechanism is reading back of an SQL table |
| 9638 |
into an APL matrix even simpler: |
| 9639 |
</p> |
| 9640 |
<div class="example"> |
| 9641 |
<pre class="example"> )CLEAR |
| 9642 |
CLEAR WS |
| 9643 |
|
| 9644 |
Filename ← 'db.sqlite' ⍝ name of the database to be used |
| 9645 |
Type ← 'sqlite' ⍝ database type |
| 9646 |
DB ← Type ⎕SQL.open Filename ⍝ open the database |
| 9647 |
|
| 9648 |
Qs ← ,⊃««« |
| 9649 |
SELECT * FROM EMPLOYEES; |
| 9650 |
»»» |
| 9651 |
|
| 9652 |
RESULT ← Qs ⎕SQL.query DB ⍬ |
| 9653 |
RESULT |
| 9654 |
1 Paul 32 California 20000 |
| 9655 |
2 Allan 25 Texas 15000 |
| 9656 |
3 Teddy 23 Norway 20000 |
| 9657 |
4 Gunnar 26 Sweden 18000 |
| 9658 |
|
| 9659 |
⍴RESULT |
| 9660 |
4 5 |
| 9661 |
|
| 9662 |
⎕SQL.close DB ⍝ and close DB |
| 9663 |
</pre></div> |
| 9664 |
|
| 9665 |
<p><b>NOTES:</b> The <b>*</b> in the query string stands for <b>all columns</b> of the |
| 9666 |
table. <b>*</b> is NOT a placeholder because it is not replaced with a parameter. |
| 9667 |
One can also retrieve a only subset of columns by using a comma separated list |
| 9668 |
of column names instead of <b>*</b> (similar to indexed reference in APL). |
| 9669 |
</p> |
| 9670 |
|
| 9671 |
<hr> |
| 9672 |
</div> |
| 9673 |
<div class="subsubsection" id="Updating-a-Database-Table"> |
| 9674 |
<div class="header"> |
| 9675 |
<p> |
| 9676 |
Previous: <a href="#Reading-a-Database-Table-into-an-APL-Matrix" accesskey="p" rel="prev">Reading a Database Table into an APL Matrix</a>, Up: <a href="#SQLite-Quickstart" accesskey="u" rel="up">SQLite Quickstart</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 9677 |
</div> |
| 9678 |
<span id="Updating-a-Database-Table-1"></span><h4 class="subsubsection">2.42.14.7 Updating a Database Table</h4> |
| 9679 |
|
| 9680 |
<p>The ⎕SQL sub-function introduced so far suffice, at least in principle. The |
| 9681 |
APL programmer can read a table from the database into APL, analyse and/or |
| 9682 |
modify it in APL, and optionally write it back into the database. |
| 9683 |
</p> |
| 9684 |
<p>There is, however, one case where this approach becomes arbitrarily |
| 9685 |
inefficient: a large database with only a small change. In that case it |
| 9686 |
is far more efficient to make a change directly in the database, i.e. without |
| 9687 |
transferring the entire database back and forth between APL and SQL. |
| 9688 |
This is achieved with an SQL UPDATE query, and <b>⎕SQL.update</b> does |
| 9689 |
exactly that. |
| 9690 |
</p> |
| 9691 |
<p>Suppose we want to increase Teddy’s salary from 20000 to 22000. Then: |
| 9692 |
</p> |
| 9693 |
<div class="example"> |
| 9694 |
<pre class="example"> )CLEAR |
| 9695 |
CLEAR WS |
| 9696 |
|
| 9697 |
Filename ← 'db.sqlite' ⍝ name of the database to be used |
| 9698 |
Type ← 'sqlite' ⍝ database type |
| 9699 |
DB ← Type ⎕SQL.open Filename ⍝ open the database |
| 9700 |
|
| 9701 |
Qs ← ,⊃««« |
| 9702 |
UPDATE EMPLOYEES SET SALARY=? WHERE ID=?; |
| 9703 |
»»» |
| 9704 |
|
| 9705 |
Qs ⎕SQL.query DB (22000 3) ⍝ update column SALARY in row 3 |
| 9706 |
|
| 9707 |
⍝ check result |
| 9708 |
Qs ← ,⊃««« |
| 9709 |
SELECT * FROM EMPLOYEES; |
| 9710 |
»»» |
| 9711 |
|
| 9712 |
RESULT ← Qs ⎕SQL.query DB ⍬ |
| 9713 |
RESULT |
| 9714 |
1 Paul 32 California 20000 |
| 9715 |
2 Allan 25 Texas 15000 |
| 9716 |
3 Teddy 23 Norway 22000 |
| 9717 |
4 Gunnar 26 Sweden 18000 |
| 9718 |
|
| 9719 |
⍴RESULT |
| 9720 |
4 5 |
| 9721 |
|
| 9722 |
⎕SQL.close DB ⍝ and close DB |
| 9723 |
</pre></div> |
| 9724 |
|
| 9725 |
<p><b>NOTES:</b> an <b>UPDATE</b> query in SQL is pretty much what an indexed |
| 9726 |
assignment in APL. In the example above we changed a single column <b>SALARY</b> |
| 9727 |
in a single row <b>ID</b> in the database table <b>COMPANY</b>. The placeholder |
| 9728 |
<b>%</b> in <b>SET SALARY=%</b> was set to parameter 22000 and the place holder in |
| 9729 |
<b>where ID=?</b> was set to Terry’s row with <b>ID</b>. Like in APL one can, |
| 9730 |
however, also change multiple rows and/or multiple columns in a database table. |
| 9731 |
To change multiple columns one can set a comma separated list of column names |
| 9732 |
in the <b>SET</b> clause (or <b>*</b> for all columns). For multiple rows one can |
| 9733 |
set multiple rows in the <b>WHERE</b> clause. Omitting the <b>WHERE</b> clause |
| 9734 |
updates all rows (similar to <b>*</b> for columns) in the database. |
| 9735 |
For example: |
| 9736 |
</p> |
| 9737 |
<div class="example"> |
| 9738 |
<pre class="example"> UPDATE COMPANY SET AGE=?, SALARY=? WHERE ID IN (?, ?, ?); |
| 9739 |
</pre></div> |
| 9740 |
|
| 9741 |
<p>The shape of a parameter matrix for an SQL <b>UPDATE</b> must, of course, |
| 9742 |
match the number of selected rows and columns. |
| 9743 |
</p> |
| 9744 |
|
| 9745 |
<hr> |
| 9746 |
</div> |
| 9747 |
</div> |
| 9748 |
<div class="subsection" id="Deleting-Rows-From-a-Database-Table"> |
| 9749 |
<div class="header"> |
| 9750 |
<p> |
| 9751 |
Previous: <a href="#SQLite-Quickstart" accesskey="p" rel="prev">SQLite Quickstart</a>, Up: <a href="#g_t_2395SQL-_002d-SQL-Database-Interface" accesskey="u" rel="up">⎕SQL - SQL Database Interface</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 9752 |
</div> |
| 9753 |
<span id="Deleting-Rows-From-a-Database-Table-1"></span><h4 class="subsection">2.42.15 Deleting Rows From a Database Table</h4> |
| 9754 |
|
| 9755 |
<p>Like <b>UPDATE</b> queries are efficient for changing large tables of a database, |
| 9756 |
there is also an SQL query for deleting one or more rows of a database: |
| 9757 |
</p> |
| 9758 |
<div class="example"> |
| 9759 |
<pre class="example"> Qs←«DELETE FROM COMPANY WHERE ID=?;» ⍝ delete one row |
| 9760 |
Qs←«DELETE FROM COMPANY WHERE ID IN (?, ?, ?);» ⍝ delete 3 rows |
| 9761 |
Qs←«DELETE FROM COMPANY;» ⍝ delete all (!) rows |
| 9762 |
|
| 9763 |
Qs ⎕SQL.query DB B |
| 9764 |
</pre></div> |
| 9765 |
|
| 9766 |
<p>As usual, the number of rows must match the number of placeholders in the |
| 9767 |
query parameter <b>B</b> (an APL vector). |
| 9768 |
</p> |
| 9769 |
<hr> |
| 9770 |
</div> |
| 9771 |
</div> |
| 9772 |
<div class="section" id="g_t_2395SYL-_002d-System-limits"> |
| 9773 |
<div class="header"> |
| 9774 |
<p> |
| 9775 |
Next: <a href="#g_t_2395XML-_002d-XML-Parsing" accesskey="n" rel="next">⎕XML - XML Parsing</a>, Previous: <a href="#g_t_2395SQL-_002d-SQL-Database-Interface" accesskey="p" rel="prev">⎕SQL - SQL Database Interface</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 9776 |
</div> |
| 9777 |
<span id="g_t_005b_003f_005dSYL-_002d-System-limits"></span><h3 class="section">2.43 ⎕SYL - System limits</h3> |
| 9778 |
|
| 9779 |
<p>System variable ⎕SYL shows a number of system limits when referenced: |
| 9780 |
</p> |
| 9781 |
<div class="example"> |
| 9782 |
<pre class="example"> ⎕SYL |
| 9783 |
SI depth limit (0 = no limit) 0 |
| 9784 |
number of values limit (0 = no limit) 0 |
| 9785 |
total ravel bytes limit (0 = no limit) 0 |
| 9786 |
current SI depth 1 |
| 9787 |
current number of values 54 |
| 9788 |
current total ravel bytes 9072 |
| 9789 |
max. rank for APL values 8 |
| 9790 |
min. ⎕PW 30 |
| 9791 |
max. ⎕PW 1000 |
| 9792 |
min. ⎕PP 1 |
| 9793 |
max. ⎕PP 16 |
| 9794 |
max. input line length 2000 |
| 9795 |
hash table size (obsolete) 65536 |
| 9796 |
max. shared variable name length 64 |
| 9797 |
max. length of filenames (paths) 4096 |
| 9798 |
max. # of shared variables (obsolete) 64 |
| 9799 |
max. number of APs 16 |
| 9800 |
max. operators per statement 16 |
| 9801 |
largest integer 9000000000000000000 |
| 9802 |
smallest integer ¯9000000000000000000 |
| 9803 |
largest numeric exponent 308 |
| 9804 |
max. shared variable size (bytes) 65000 |
| 9805 |
max. cores (per ./configure) 0 |
| 9806 |
max. cores (per max_cores()) 1 |
| 9807 |
current cores (per core_count()) 1 |
| 9808 |
print length limit (0 = no limit) 0 |
| 9809 |
</pre></div> |
| 9810 |
|
| 9811 |
<p>Most system limits are read-only; attempting to assign ⎕SYL will result |
| 9812 |
in a SYNTAX ERROR. Indexed assignment to ⎕SYL will result in an |
| 9813 |
INDEX ERROR unless the limit is writable. Some read-only limits can |
| 9814 |
be changed at compile-time via ./configure |
| 9815 |
</p> |
| 9816 |
<ul class="section-toc"> |
| 9817 |
<li><a href="#g_t_2395SYL_005b1-2-3-4-5-6_003b_005d" accesskey="1">⎕SYL[1 2 3 4 5 6;]</a></li> |
| 9818 |
<li><a href="#g_t_2395SYL_005b7-8-9-10-11-12-13-14-15-16-17-18-19-20-21-22-23_003b_005d" accesskey="2">⎕SYL[7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23;]</a></li> |
| 9819 |
<li><a href="#g_t_2395SYL_005b24-25-26_003b_005d" accesskey="3">⎕SYL[24 25 26;]</a></li> |
| 9820 |
<li><a href="#g_t_2395SYL_005b27_003b_005d" accesskey="4">⎕SYL[27;]</a></li> |
| 9821 |
</ul> |
| 9822 |
<hr> |
| 9823 |
<div class="subsection" id="g_t_2395SYL_005b1-2-3-4-5-6_003b_005d"> |
| 9824 |
<div class="header"> |
| 9825 |
<p> |
| 9826 |
Next: <a href="#g_t_2395SYL_005b7-8-9-10-11-12-13-14-15-16-17-18-19-20-21-22-23_003b_005d" accesskey="n" rel="next">⎕SYL[7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23;]</a>, Up: <a href="#g_t_2395SYL-_002d-System-limits" accesskey="u" rel="up">⎕SYL - System limits</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 9827 |
</div> |
| 9828 |
<span id="g_t_005b_003f_005dSYL_005b1-2-3-4-5-6_003b_005d"></span><h4 class="subsection">2.43.1 ⎕SYL[1 2 3 4 5 6;]</h4> |
| 9829 |
|
| 9830 |
<p>The first three limits are writable; their purpose is to stop execution |
| 9831 |
if: |
| 9832 |
</p> |
| 9833 |
<ol> |
| 9834 |
<li> The SI stack of the interpreter reaches a limit, or |
| 9835 |
</li><li> The number of APL values created reaches a limit, or |
| 9836 |
</li><li> The memory size of APL values created reaches a limit. |
| 9837 |
</li></ol> |
| 9838 |
|
| 9839 |
<p>Whenever a writable limit is reached, a corresponding LIMIT ERROR |
| 9840 |
is reported and the limit is reset to 0 (meaning no limit) in order |
| 9841 |
to prevent the interpreter from locking up. |
| 9842 |
</p> |
| 9843 |
<p>The main use of ⎕SYL is to troubleshoot infinite recursion in user-defined |
| 9844 |
function that would otherwise cause the machine to start swapping or to |
| 9845 |
become non-responding. |
| 9846 |
</p> |
| 9847 |
<p>Example (stop execution if function call stack exceeds 20): |
| 9848 |
</p> |
| 9849 |
<div class="example"> |
| 9850 |
<pre class="example"> ⎕SYL[1;2]←20 |
| 9851 |
</pre></div> |
| 9852 |
|
| 9853 |
<p>Note that small APL values (up to a configurable number of ravel elements) |
| 9854 |
count as values (in the number of values limit), but not in the total ravel |
| 9855 |
bytes limit (the ravel does not allocate memory in addition to the |
| 9856 |
space already in the number of values limit). It is therefore typical to |
| 9857 |
set the number of values limit and the total ravel bytes limit together. |
| 9858 |
</p> |
| 9859 |
<p>An attempt to set a too small limit, for example one that is close to the |
| 9860 |
current value, is rejected with a DOMAIN ERROR. |
| 9861 |
</p> |
| 9862 |
<hr> |
| 9863 |
</div> |
| 9864 |
<div class="subsection" id="g_t_2395SYL_005b7-8-9-10-11-12-13-14-15-16-17-18-19-20-21-22-23_003b_005d"> |
| 9865 |
<div class="header"> |
| 9866 |
<p> |
| 9867 |
Next: <a href="#g_t_2395SYL_005b24-25-26_003b_005d" accesskey="n" rel="next">⎕SYL[24 25 26;]</a>, Previous: <a href="#g_t_2395SYL_005b1-2-3-4-5-6_003b_005d" accesskey="p" rel="prev">⎕SYL[1 2 3 4 5 6;]</a>, Up: <a href="#g_t_2395SYL-_002d-System-limits" accesskey="u" rel="up">⎕SYL - System limits</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 9868 |
</div> |
| 9869 |
<span id="g_t_005b_003f_005dSYL_005b7-8-9-10-11-12-13-14-15-16-17-18-19-20-21-22-23_003b_005d"></span><h4 class="subsection">2.43.2 ⎕SYL[7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23;]</h4> |
| 9870 |
|
| 9871 |
<p>These system limits are read-only. Some of them can be changed at |
| 9872 |
compile time via ./configure. Most others can be changed in the source code |
| 9873 |
of GNU APL, but doing so is not recommended. |
| 9874 |
</p> |
| 9875 |
<hr> |
| 9876 |
</div> |
| 9877 |
<div class="subsection" id="g_t_2395SYL_005b24-25-26_003b_005d"> |
| 9878 |
<div class="header"> |
| 9879 |
<p> |
| 9880 |
Next: <a href="#g_t_2395SYL_005b27_003b_005d" accesskey="n" rel="next">⎕SYL[27;]</a>, Previous: <a href="#g_t_2395SYL_005b7-8-9-10-11-12-13-14-15-16-17-18-19-20-21-22-23_003b_005d" accesskey="p" rel="prev">⎕SYL[7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23;]</a>, Up: <a href="#g_t_2395SYL-_002d-System-limits" accesskey="u" rel="up">⎕SYL - System limits</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 9881 |
</div> |
| 9882 |
<span id="g_t_005b_003f_005dSYL_005b24-25-26_003b_005d"></span><h4 class="subsection">2.43.3 ⎕SYL[24 25 26;]</h4> |
| 9883 |
|
| 9884 |
<p>These system limits have been added in preparation for multi-core GNU APL. |
| 9885 |
They are currently not used. |
| 9886 |
</p> |
| 9887 |
<hr> |
| 9888 |
</div> |
| 9889 |
<div class="subsection" id="g_t_2395SYL_005b27_003b_005d"> |
| 9890 |
<div class="header"> |
| 9891 |
<p> |
| 9892 |
Previous: <a href="#g_t_2395SYL_005b24-25-26_003b_005d" accesskey="p" rel="prev">⎕SYL[24 25 26;]</a>, Up: <a href="#g_t_2395SYL-_002d-System-limits" accesskey="u" rel="up">⎕SYL - System limits</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 9893 |
</div> |
| 9894 |
<span id="g_t_005b_003f_005dSYL_005b27_003b_005d"></span><h4 class="subsection">2.43.4 ⎕SYL[27;]</h4> |
| 9895 |
|
| 9896 |
<p>This is not a limit that raises a limit error. Instead it limits the |
| 9897 |
size of APL values when printed as statement results. It is fairly easy |
| 9898 |
in APL to create huge APL values by mistake. During development it can |
| 9899 |
be useful to limit the amount of data printed. If the ravel length of, |
| 9900 |
say, VALUE exceeds ⎕SYL[27;2] (i.e. if ⎕SYL[27;2] ≤ ⍴,VALUE) then SH↑VALUE |
| 9901 |
is printed instead of VALUE. The shape SH is computed like this: |
| 9902 |
</p> |
| 9903 |
<div class="example"> |
| 9904 |
<pre class="example"> SH←⍴VALUE |
| 9905 |
while (ravel-length(SH) ≥ ⎕SYL[27;2]) { divide longest axis in SH by 2 } |
| 9906 |
</pre></div> |
| 9907 |
|
| 9908 |
<hr> |
| 9909 |
</div> |
| 9910 |
</div> |
| 9911 |
<div class="section" id="g_t_2395XML-_002d-XML-Parsing"> |
| 9912 |
<div class="header"> |
| 9913 |
<p> |
| 9914 |
Next: <a href="#Conditionals" accesskey="n" rel="next">Conditionals</a>, Previous: <a href="#g_t_2395SYL-_002d-System-limits" accesskey="p" rel="prev">⎕SYL - System limits</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 9915 |
</div> |
| 9916 |
<span id="g_t_005b_003f_005dXML-_002d-XML-Parsing"></span><h3 class="section">2.44 ⎕XML - XML Parsing</h3> |
| 9917 |
|
| 9918 |
<ul class="section-toc"> |
| 9919 |
<li><a href="#Purpose" accesskey="1">Purpose</a></li> |
| 9920 |
<li><a href="#Some-XML-Terminology" accesskey="2">Some XML Terminology</a></li> |
| 9921 |
<li><a href="#How-_2395XML-maps-XML-documents-to-APL-Values" accesskey="3">How ⎕XML maps XML documents to APL Values</a></li> |
| 9922 |
<li><a href="#Monadic-_2395XML" accesskey="4">Monadic ⎕XML</a></li> |
| 9923 |
<li><a href="#Dyadic-_2395XML" accesskey="5">Dyadic ⎕XML</a></li> |
| 9924 |
<li><a href="#XML-Queries" accesskey="6">XML Queries</a></li> |
| 9925 |
</ul> |
| 9926 |
<hr> |
| 9927 |
<div class="subsection" id="Purpose"> |
| 9928 |
<div class="header"> |
| 9929 |
<p> |
| 9930 |
Next: <a href="#Some-XML-Terminology" accesskey="n" rel="next">Some XML Terminology</a>, Up: <a href="#g_t_2395XML-_002d-XML-Parsing" accesskey="u" rel="up">⎕XML - XML Parsing</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 9931 |
</div> |
| 9932 |
<span id="Purpose-1"></span><h4 class="subsection">2.44.1 Purpose</h4> |
| 9933 |
|
| 9934 |
<p>GNU APL provides ⎕XML as a means of performing <b>elementary</b> |
| 9935 |
manipulations of APL character strings that are formatted according |
| 9936 |
to the XML standard. The anticipated procedure for such modifications |
| 9937 |
is something like: |
| 9938 |
</p> |
| 9939 |
<div class="example"> |
| 9940 |
<pre class="example"> XML_string ← "<A><B><C>Hello</C></B></A>" ⍝ input data (usually from an .xml file) |
| 9941 |
APL ← ⎕XML XML_string ⍝ convert XML_string to associative array APL |
| 9942 |
ABC ← APL.a.b.c ⍝ retrieve node a.b.c in APL |
| 9943 |
APL.a.b.c ← ABC, " World" ⍝ modify node a.b.c in APL |
| 9944 |
Z ← ⎕XML APL ⍝ convert associative array APL to XML string Z |
| 9945 |
|
| 9946 |
ABC ⍝ the original value of XML.a.b.c |
| 9947 |
Hello |
| 9948 |
Z ⍝ the modified XML string |
| 9949 |
<A><B><C>Hello World</C></B></A>" |
| 9950 |
</pre></div> |
| 9951 |
|
| 9952 |
<p>The scope (functionality) of ⎕XML is then: |
| 9953 |
</p> |
| 9954 |
<ul> |
| 9955 |
<li> Conversion of (valid) XML strings to associative APL arrays that can be |
| 9956 |
more easily processed in APL than the XML strings, |
| 9957 |
</li><li> Conversion of associative APL arrays back to valid XML strings, |
| 9958 |
</li><li> Simple (at APL level) access to the data contained in XML strings, and |
| 9959 |
</li><li> Transparent access to those (mostly XML specific) portions of the XML |
| 9960 |
string that are not (yet) handled by ⎕XML; this means that the user of ⎕XML |
| 9961 |
shall be able to handle advanced XML aspects (like document type |
| 9962 |
declarations (DTDs), document validation, etc.) in APL without much overhead. |
| 9963 |
</li></ul> |
| 9964 |
|
| 9965 |
<hr> |
| 9966 |
</div> |
| 9967 |
<div class="subsection" id="Some-XML-Terminology"> |
| 9968 |
<div class="header"> |
| 9969 |
<p> |
| 9970 |
Next: <a href="#How-_2395XML-maps-XML-documents-to-APL-Values" accesskey="n" rel="next">How ⎕XML maps XML documents to APL Values</a>, Previous: <a href="#Purpose" accesskey="p" rel="prev">Purpose</a>, Up: <a href="#g_t_2395XML-_002d-XML-Parsing" accesskey="u" rel="up">⎕XML - XML Parsing</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 9971 |
</div> |
| 9972 |
<span id="Some-XML-Terminology-1"></span><h4 class="subsection">2.44.2 Some XML Terminology</h4> |
| 9973 |
|
| 9974 |
<p>An XML document is a character string with a standardized format. |
| 9975 |
The characters must be valid XML characters as defined in the XML |
| 9976 |
standard (almost all Unicode characters except most of the ASCII control |
| 9977 |
characters). GNU APL raises a DOMAIN ERROR when an XML document contains |
| 9978 |
invalid XML characters. |
| 9979 |
</p> |
| 9980 |
<p>The XML document is a sequence of adjacent sub-strings, where each sub-string |
| 9981 |
is: |
| 9982 |
</p> |
| 9983 |
<ul> |
| 9984 |
<li> either markup (-string), |
| 9985 |
</li><li> or non-markup (-string). |
| 9986 |
</li></ul> |
| 9987 |
|
| 9988 |
<p>A markup (sub-)string: |
| 9989 |
</p> |
| 9990 |
<ul> |
| 9991 |
<li> starts with character ’<’, and |
| 9992 |
</li><li> ends with character ’>’, and |
| 9993 |
</li><li> all other characters in the markup string differ from ’<’ and ’>’. |
| 9994 |
</li></ul> |
| 9995 |
|
| 9996 |
<p>A non-markup (sub-)string: |
| 9997 |
</p> |
| 9998 |
<ul> |
| 9999 |
<li> starts either at the beginning of the XML document or else directly |
| 10000 |
after a markup string, |
| 10001 |
</li><li> end at the end of the document or else directly before a markup |
| 10002 |
string, and therefore |
| 10003 |
</li><li> cannot be adjacent to another non-markup string. |
| 10004 |
</li></ul> |
| 10005 |
|
| 10006 |
<p>Non-markup is sometimes referred to as "unstructured text". The producer of |
| 10007 |
an XML document has a principal choice about where to locate the information |
| 10008 |
that the document contains: in the unstructured text or in the attribute |
| 10009 |
values inside the tags. For that reason the XML standard is somewhat picky |
| 10010 |
about keeping the unstructured text as well as attribute values intact |
| 10011 |
and requires that whitespace in non-markup (the only allowed whitespace |
| 10012 |
characters in XML being TAB, CR, LF, and SPACE) is preserved in non-markup |
| 10013 |
strings. |
| 10014 |
</p> |
| 10015 |
<p>As a consequence, many non-markup strings begin with LF because the |
| 10016 |
preceeding markup was on the previous line and therefore the LF after the |
| 10017 |
preceeding markup is whitespace of the non-markup and therefore needs to be |
| 10018 |
preserved. |
| 10019 |
</p> |
| 10020 |
<p>Every markup belongs to one of 4 categories: |
| 10021 |
</p> |
| 10022 |
<ul> |
| 10023 |
<li> Processing instructions: "<? ... ?>", |
| 10024 |
</li><li> Comments: "<!— ... —>", |
| 10025 |
</li><li> Declarations "<! ... !>", and |
| 10026 |
</li><li> Tags, which are either: |
| 10027 |
<ul> |
| 10028 |
<li> Empty tags (leaf tags): "<tagname attributes... /> |
| 10029 |
</li><li> Start tags: "<tagname attributes... >, or |
| 10030 |
</li><li> End tags: "</tagname> |
| 10031 |
</li></ul> |
| 10032 |
</li></ul> |
| 10033 |
|
| 10034 |
<p>The XML tags recursively define a tree structure where: |
| 10035 |
</p> |
| 10036 |
<ul> |
| 10037 |
<li> the nodes of the trees are either Empty Tags or else a start tag, |
| 10038 |
followed by a (possibly empty) sequence of non-markup, comments, and |
| 10039 |
sub-nodes (of the tree), followed by an end tag (with the same name |
| 10040 |
as the start tag), |
| 10041 |
</li><li> the leafs of the trees are either Empty Tags or else a start tag, |
| 10042 |
followed by a (possibly empty) sequence of non-markup and comments, |
| 10043 |
followed by an end tag (with the same name as the start tag). The difference |
| 10044 |
between a leaf node and a non-leaf is therefore the absence of sub-nodes |
| 10045 |
between a start and an end tag. |
| 10046 |
</li><li> optionally non-markup and comments before, after, and between the nodes. |
| 10047 |
</li></ul> |
| 10048 |
|
| 10049 |
<p>Processing instructions and declarations are typically located at the |
| 10050 |
beginning of the XML document and at the same level as the root of the tree |
| 10051 |
defined by the document. Document type declarations are preserved (so that |
| 10052 |
they can be processed in APL), but are currently ignored by ⎕XML. As a |
| 10053 |
consequence, entity declarations have no effect and only the predefined XML |
| 10054 |
entities (i.e. &, <, >, ’, and ") are recognized (and translated) by ⎕XML. |
| 10055 |
</p> |
| 10056 |
<hr> |
| 10057 |
</div> |
| 10058 |
<div class="subsection" id="How-_2395XML-maps-XML-documents-to-APL-Values"> |
| 10059 |
<div class="header"> |
| 10060 |
<p> |
| 10061 |
Next: <a href="#Monadic-_2395XML" accesskey="n" rel="next">Monadic ⎕XML</a>, Previous: <a href="#Some-XML-Terminology" accesskey="p" rel="prev">Some XML Terminology</a>, Up: <a href="#g_t_2395XML-_002d-XML-Parsing" accesskey="u" rel="up">⎕XML - XML Parsing</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 10062 |
</div> |
| 10063 |
<span id="How-_005b_003f_005dXML-maps-XML-documents-to-APL-Values"></span><h4 class="subsection">2.44.3 How ⎕XML maps XML documents to APL Values</h4> |
| 10064 |
|
| 10065 |
<p>The principal mapping between XML strings and APL values is: |
| 10066 |
</p> |
| 10067 |
<ul> |
| 10068 |
<li> <b>XML document</b> ←→ structured (top-level) APL value or variable |
| 10069 |
(= an associative array) |
| 10070 |
</li><li> <b>XML node</b> ←→ structured APL (sub-) value (= an associative (sub-) |
| 10071 |
array of either the top-level value or of another XML node) |
| 10072 |
</li><li> <b>XML name</b> ←→ name of a member in a structured APL value |
| 10073 |
</li><li> <b>Other</b> ←→ member value |
| 10074 |
</li></ul> |
| 10075 |
|
| 10076 |
<p>Every valid name in XML is also a valid name for an APL variable or structure |
| 10077 |
member. Unfortunately, mapping XML names directly to APL member names cannot |
| 10078 |
work because: |
| 10079 |
</p> |
| 10080 |
<ul> |
| 10081 |
<li> In any associative array the names of the members are necessarily |
| 10082 |
distinct. Assigning a value to an already existing member of a structured |
| 10083 |
value overwrites the current value of that member instead of creating a |
| 10084 |
second member with that value. On the other hand, in XML nodes tags may (and |
| 10085 |
frequently do) occur repeatedly. If an XML document contains several nodes |
| 10086 |
with the same tag, then the applications usually knows how to interpret the |
| 10087 |
order in which the tags occur, but this order may not be detectable at the XML |
| 10088 |
level (i.e. the nodes may not only have the same tag names, but also the same |
| 10089 |
attributes and attribute values). |
| 10090 |
|
| 10091 |
<p>The applications that use the XML document frequently require that the order |
| 10092 |
of XML nodes with the same name remain intact when the document is modified. |
| 10093 |
For example, the entries of a telephone book may be sorted alphabetically |
| 10094 |
without XML being aware of that. Reading, modifying, and writing back the |
| 10095 |
data in the telephone book must therefore not destroy that order. |
| 10096 |
</p> |
| 10097 |
</li><li> Likewise, at least for readability reasons, the order of node |
| 10098 |
attributes should not be changed. XML documents are frequently processed |
| 10099 |
with text tools like <b>diff</b> which would incorrectly show differences |
| 10100 |
between XML documents that are equivalent from an XML perspective. |
| 10101 |
|
| 10102 |
</li><li> Conflicts between tag names and attribute names. In XML, the same name |
| 10103 |
can designate an attribute in one node and a tag in another node. ⎕XML keeps |
| 10104 |
all information from the < of a start tag to the > of an end tag in a single |
| 10105 |
associative array, therefore the attribute names must somehow differ from |
| 10106 |
the (sub-) tag names. |
| 10107 |
|
| 10108 |
</li><li> Every XML node has a tag name that can be used to derive a |
| 10109 |
corresponding APL member name. However, the text segments between an XML |
| 10110 |
tag and its corresponding end tag, are a mixture of unstructured text, XML |
| 10111 |
subnodes and comments of which only the XML subnodes have tags of their own. |
| 10112 |
These untagged segments may, however, contain relevant information and, |
| 10113 |
from an XML standard perspective, both their content and their order must |
| 10114 |
be preserved. |
| 10115 |
</li></ul> |
| 10116 |
|
| 10117 |
<p>⎕XML solves these issues with a simple naming convention for all member names |
| 10118 |
in the (recursive) associative array that is produced by monadic ⎕XML. Every |
| 10119 |
member name consists of 3 components that together yield a valid APL variable |
| 10120 |
name (and therefore a valid member name that is understood by the APL parser): |
| 10121 |
</p> |
| 10122 |
<ul> |
| 10123 |
<li> A single character ⍙, ∆, or _, that indicates the role of the name in |
| 10124 |
the XML document as follows: |
| 10125 |
<ul> |
| 10126 |
<li> the character ⍙ characterizes an attribute name, i.e. a name that |
| 10127 |
was used <b>inside</b> (i.e. between < and >) of an XML start or leaf tag. |
| 10128 |
The character ⍙ alone is the name of a special member which is present |
| 10129 |
in every associative array below the top-level and whose value is the |
| 10130 |
original XML tag name of a tag, or |
| 10131 |
|
| 10132 |
</li><li> the character ∆ characterizes a name that was synthesized by ⎕XML |
| 10133 |
itself to tag a text (sub-) segment that has no tag of its own. The |
| 10134 |
corresponding XML entity was not a tag (and therefore had no tag name), or |
| 10135 |
|
| 10136 |
</li><li> the character _ characterizes the name of an XML entity, i.e. a CML |
| 10137 |
name that occurred <b>between</b> the start tag and the corresponding end tag |
| 10138 |
(if any: leaf tags have no such entities) |
| 10139 |
</li></ul> |
| 10140 |
|
| 10141 |
</li><li> a position prefix of the form <b>NN</b>, where NN is the position |
| 10142 |
of the member in relation to the tag to which it belongs. The numbering |
| 10143 |
starts at ⎕IO and restarts at every XML start or leaf tag. |
| 10144 |
|
| 10145 |
</li><li> the attribute name or tag name. For those parts of an XML entity that |
| 10146 |
do not have a tag name, the member name is synthesized by ⎕XML and the |
| 10147 |
member value will be the text in the XML document with predefined XML |
| 10148 |
entities replaced by their single characters, i.e.: |
| 10149 |
<ul> |
| 10150 |
<li> & for &amp, |
| 10151 |
</li><li> < for &lt, |
| 10152 |
</li><li> > for &gt, |
| 10153 |
</li><li> ’ for &apos, |
| 10154 |
</li><li> " for &quot, |
| 10155 |
</li><li> ⎕UCS nnn for &#nnn, and |
| 10156 |
</li><li> ⎕UCS $xxx for &#xxx |
| 10157 |
</li></ul> |
| 10158 |
</li></ul> |
| 10159 |
|
| 10160 |
<p>Let NN be a sequence of decimal digits. Then only the following 4 |
| 10161 |
synthesized names are produced by ⎕XML: |
| 10162 |
</p> |
| 10163 |
<ul> |
| 10164 |
<li> <b>∆NNcomment</b> for XML comments, i.e. <!— ... —> in XML, |
| 10165 |
</li><li> <b>∆NNdeclaration</b> for XML declarations, i.e. <? ... ?> in XML, |
| 10166 |
</li><li> <b>∆NNdoctype</b> for document type declarations, i.e. |
| 10167 |
<!DOCTYPE ... > in XML |
| 10168 |
</li><li> <b>∆NNtext</b> for unstructured (and hence untagged) text segments in XML. |
| 10169 |
</li></ul> |
| 10170 |
|
| 10171 |
<p>Every XML name (of a tag or attribute) is also a valid APL name, but |
| 10172 |
valid APL names may also contain the characters _, ∆, and ⍙ which are not |
| 10173 |
valid in XML and used in the naming convention above to clearly separate |
| 10174 |
the member names used in APL from the names used in the XML document. |
| 10175 |
</p> |
| 10176 |
<p>The essence of all this is that <b>everything</b> that belongs to an XML |
| 10177 |
node or document, i.e. the attributes inside a tag, the sub-nodes between a |
| 10178 |
start tag and its corresponding end tag (if any), declarations, etc. will |
| 10179 |
be contained in a single associative array. |
| 10180 |
</p> |
| 10181 |
<p>Examples of APL member names (assuming ⎕IO←1): |
| 10182 |
</p> |
| 10183 |
<div class="example"> |
| 10184 |
<pre class="example"> ⍙1 ⍝ the first member in every XML node. Its value is the node tag. |
| 10185 |
∆1declaration ⍝ the first member in most XML documents. E.g. <?xml version= ...> |
| 10186 |
∆2text ⍝ whitespace (LF) between _1∆declaration and _3∆doctype |
| 10187 |
∆3doctype ⍝ DTD in XML documents that have one. E.g. <!DOCTYPE ... |
| 10188 |
_6Workspace ⍝ Sub-array for <Workspace ... at position 6. |
| 10189 |
⍙1wsid ⍝ first attribute wsid from e.g. <Workspace wsid=... |
| 10190 |
⍙2year ⍝ second attribute year |
| 10191 |
</pre></div> |
| 10192 |
|
| 10193 |
<hr> |
| 10194 |
</div> |
| 10195 |
<div class="subsection" id="Monadic-_2395XML"> |
| 10196 |
<div class="header"> |
| 10197 |
<p> |
| 10198 |
Next: <a href="#Dyadic-_2395XML" accesskey="n" rel="next">Dyadic ⎕XML</a>, Previous: <a href="#How-_2395XML-maps-XML-documents-to-APL-Values" accesskey="p" rel="prev">How ⎕XML maps XML documents to APL Values</a>, Up: <a href="#g_t_2395XML-_002d-XML-Parsing" accesskey="u" rel="up">⎕XML - XML Parsing</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 10199 |
</div> |
| 10200 |
<span id="Monadic-_005b_003f_005dXML"></span><h4 class="subsection">2.44.4 Monadic ⎕XML</h4> |
| 10201 |
|
| 10202 |
<p><b>Z ← ⎕XML B</b> converts APL string B that contains a valid XML document |
| 10203 |
to an associative APL array Z and vice versa. |
| 10204 |
</p> |
| 10205 |
<p><b>Note</b>: If you convert an associative APL array back to a an XML document, |
| 10206 |
the result is a possibly very long string containing several linefeed |
| 10207 |
characters. That is OK if the string is written to a file, but causes problems |
| 10208 |
when the string is displayed and longer than ⎕PW. The standard APL |
| 10209 |
folding of output near ⎕PW make the string then look somewhat garbled. |
| 10210 |
This effect can be suppressed in 2 ways: |
| 10211 |
</p> |
| 10212 |
<ol> |
| 10213 |
<li> set ⎕PW large enough, or |
| 10214 |
</li><li> prefix the string with ⊃35⎕CR as in the examples below. |
| 10215 |
</li></ol> |
| 10216 |
|
| 10217 |
<hr> |
| 10218 |
</div> |
| 10219 |
<div class="subsection" id="Dyadic-_2395XML"> |
| 10220 |
<div class="header"> |
| 10221 |
<p> |
| 10222 |
Next: <a href="#XML-Queries" accesskey="n" rel="next">XML Queries</a>, Previous: <a href="#Monadic-_2395XML" accesskey="p" rel="prev">Monadic ⎕XML</a>, Up: <a href="#g_t_2395XML-_002d-XML-Parsing" accesskey="u" rel="up">⎕XML - XML Parsing</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 10223 |
</div> |
| 10224 |
<span id="Dyadic-_005b_003f_005dXML"></span><h4 class="subsection">2.44.5 Dyadic ⎕XML</h4> |
| 10225 |
|
| 10226 |
<p><b>Z ← A ⎕XML B</b> provides a number of convenience functions. Its left |
| 10227 |
argument A is an integer function number, possibly followed by arguments |
| 10228 |
of the function number ↑A. |
| 10229 |
</p> |
| 10230 |
<p>In the following examples, let |
| 10231 |
</p> |
| 10232 |
<div class="example"> |
| 10233 |
<pre class="example"> XML←36 ⎕CR """ |
| 10234 |
<?xml version='1.0' encoding='UTF-8'?> |
| 10235 |
<Document> |
| 10236 |
<Tag1 name='tag1'> <!-- first tag --> |
| 10237 |
TEXT1 |
| 10238 |
<Subtag name='subag1.1'> <!-- first subtag --> |
| 10239 |
SUBTEXT1_1 |
| 10240 |
</Subtag> |
| 10241 |
</Tag1> |
| 10242 |
</Document> |
| 10243 |
""" |
| 10244 |
|
| 10245 |
APL←⎕XML XML |
| 10246 |
</pre></div> |
| 10247 |
|
| 10248 |
<p>Then |
| 10249 |
</p> |
| 10250 |
<ul> |
| 10251 |
<li> <b>Z←0 ⎕XML B</b> is the same as monadic Z←⎕XML B. |
| 10252 |
|
| 10253 |
</li><li> <b>Z←1 ⎕XML B</b> is like 0 ⎕XML B, except that B is not the XML |
| 10254 |
document (string) itself but the name of a file from which an XML document |
| 10255 |
is read. |
| 10256 |
|
| 10257 |
</li><li> <b>Z←2 ⎕XML B</b> splits an APL member path (a sequence of member names) |
| 10258 |
into a vector P of (nested) member names. This vector P is understood by |
| 10259 |
the APL primitive PICK (i.e. Z←P⊃APL or (P⊃APL)←value and can be used to |
| 10260 |
address the data in an XML node. |
| 10261 |
|
| 10262 |
</li><li> <b>Z←3 ⎕XML B</b> splits an APL member name (as produced by e.g. |
| 10263 |
monadic ⎕XML into a 3-item vector Z. Z[1] is a single character indicating |
| 10264 |
the category (i.e. a character scalar ∆, ⍙, or _). Z[2] is the position (an |
| 10265 |
integer scalar ≥ ⎕IO). Z[3] is a (nested) APL string. 3 ⎕XML has an |
| 10266 |
inverse function ¯3 ⎕XML which converts a 3-item vector as produced by 3 ⎕XML |
| 10267 |
back into an APL member name indicating the category (i.e. _, ∆, or ⍙) |
| 10268 |
and the name from the XML tag: |
| 10269 |
|
| 10270 |
<div class="example"> |
| 10271 |
<pre class="example"> 8 ⎕CR (C P N)←3 ⎕XML "∆2comment" |
| 10272 |
┌→────────────┐ |
| 10273 |
│∆ 2 ┌→──────┐│ |
| 10274 |
│ │comment││ |
| 10275 |
│ └───────┘│ |
| 10276 |
└∊────────────┘ |
| 10277 |
|
| 10278 |
C ⍝ category |
| 10279 |
∆ |
| 10280 |
P ⍝ position |
| 10281 |
2 |
| 10282 |
N ⍝ (XML-) name |
| 10283 |
comment |
| 10284 |
|
| 10285 |
¯3 ⎕XML C P N ⍝ inverse of 3 ⎕XML |
| 10286 |
∆2comment |
| 10287 |
</pre></div> |
| 10288 |
|
| 10289 |
</li><li> <b>Z←4 ⎕XML B</b> is a string that shows the member names of the |
| 10290 |
associative array B in a tree-like fashion. For example: |
| 10291 |
|
| 10292 |
<div class="example"> |
| 10293 |
<pre class="example"> ⊃35⎕CR 4 ⎕XML APL |
| 10294 |
XML |
| 10295 |
│ |
| 10296 |
└─── Document |
| 10297 |
│ |
| 10298 |
└─── Tag1 |
| 10299 |
│ |
| 10300 |
└─── Subtag |
| 10301 |
</pre></div> |
| 10302 |
|
| 10303 |
</li><li> <b>Z←5 ⎕XML B</b> is like 4 ⎕XML but displays not only the XML tags but |
| 10304 |
also other XML nodes (declarations, attributes, etc.): |
| 10305 |
|
| 10306 |
<div class="example"> |
| 10307 |
<pre class="example"> ⊃35⎕CR 5 ⎕XML APL |
| 10308 |
XML |
| 10309 |
│ |
| 10310 |
├─── _1∆declaration |
| 10311 |
├─── _2∆text |
| 10312 |
└─── _3_Document |
| 10313 |
│ |
| 10314 |
├─── _1∆text |
| 10315 |
├─── _2_Tag1 |
| 10316 |
│ │ |
| 10317 |
│ ├─── _1∆text |
| 10318 |
│ ├─── _2∆comment |
| 10319 |
│ ├─── _3∆text |
| 10320 |
│ ├─── _4_Subtag |
| 10321 |
│ │ │ |
| 10322 |
│ │ ├─── _1∆text |
| 10323 |
│ │ ├─── _2∆comment |
| 10324 |
│ │ └─── _3∆text |
| 10325 |
│ └─── _5∆text |
| 10326 |
└─── _3∆text |
| 10327 |
</pre></div> |
| 10328 |
|
| 10329 |
</li><li> <b>Z←6 ⎕XML B</b> is like 4 ⎕XML but displays not only the member |
| 10330 |
name but the entire path to the member: |
| 10331 |
|
| 10332 |
<div class="example"> |
| 10333 |
<pre class="example"> ⊃35⎕CR 6 ⎕XML APL |
| 10334 |
XML |
| 10335 |
│ |
| 10336 |
└─── ._3_Document |
| 10337 |
│ |
| 10338 |
└─── ._3_Document._2_Tag1 |
| 10339 |
│ |
| 10340 |
└─── ._3_Document._2_Tag1._4_Subtag |
| 10341 |
</pre></div> |
| 10342 |
|
| 10343 |
</li><li> <b>Z←7 ⎕XML B</b> returns a list of all members in a depth-first order. |
| 10344 |
This list can be used as an iterator to traverse the entire tree (and possibly |
| 10345 |
filter out items along the way). |
| 10346 |
|
| 10347 |
<div class="example"> |
| 10348 |
<pre class="example"> ⊃7 ⎕XML APL |
| 10349 |
._1∆declaration |
| 10350 |
._2∆text |
| 10351 |
._18∆text |
| 10352 |
._3_Document |
| 10353 |
._3_Document._1⍙ |
| 10354 |
._3_Document._1∆text |
| 10355 |
._3_Document._3∆text |
| 10356 |
._3_Document._2_Tag1 |
| 10357 |
._3_Document._2_Tag1._1⍙ |
| 10358 |
._3_Document._2_Tag1._2⍙name |
| 10359 |
._3_Document._2_Tag1._1∆text |
| 10360 |
._3_Document._2_Tag1._2∆comment |
| 10361 |
._3_Document._2_Tag1._3∆text |
| 10362 |
._3_Document._2_Tag1._5∆text |
| 10363 |
._3_Document._2_Tag1._4_Subtag |
| 10364 |
._3_Document._2_Tag1._4_Subtag._1⍙ |
| 10365 |
._3_Document._2_Tag1._4_Subtag._2⍙name |
| 10366 |
._3_Document._2_Tag1._4_Subtag._1∆text |
| 10367 |
._3_Document._2_Tag1._4_Subtag._2∆comment |
| 10368 |
._3_Document._2_Tag1._4_Subtag._3∆text |
| 10369 |
</pre></div> |
| 10370 |
|
| 10371 |
</li><li> <b>Z←8 ⎕XML B</b> is like Z←7 ⎕XML B, except that only the subset of |
| 10372 |
those members that are related to tags (the tag name ⍙ and tag attributes) |
| 10373 |
are returned: |
| 10374 |
|
| 10375 |
<div class="example"> |
| 10376 |
<pre class="example"> ⊃8 ⎕XML APL ⍝ all tag related member names (tag names and attributes) |
| 10377 |
._3Document.⍙1···················· |
| 10378 |
._3Document._2Tag1.⍙1············· |
| 10379 |
._3Document._2Tag1.⍙2name········· |
| 10380 |
._3Document._2Tag1._4Subtag.⍙1···· |
| 10381 |
._3Document._2Tag1._4Subtag.⍙2name |
| 10382 |
</pre></div> |
| 10383 |
|
| 10384 |
</li><li> <b>Z←9 ⎕XML B</b> is like Z←7 ⎕XML B, except that only the subset of |
| 10385 |
synthesized members other than ∆text are returned: |
| 10386 |
|
| 10387 |
<div class="example"> |
| 10388 |
<pre class="example"> ⊃9 ⎕XML APL ⍝ all synthetic member names (except unstructured text) |
| 10389 |
.∆1declaration······················· |
| 10390 |
._3Document._2Tag1.∆2comment········· |
| 10391 |
._3Document._2Tag1._4Subtag.∆2comment |
| 10392 |
</pre></div> |
| 10393 |
|
| 10394 |
</li><li> <b>Z←10 ⎕XML B</b> is like Z←7 ⎕XML B, except that only the subset of |
| 10395 |
synthesized ∆text members are returned: |
| 10396 |
|
| 10397 |
<div class="example"> |
| 10398 |
<pre class="example">.∆2text··························· |
| 10399 |
._3Document.∆1text················ |
| 10400 |
._3Document._2Tag1.∆1text········· |
| 10401 |
._3Document._2Tag1.∆3text········· |
| 10402 |
._3Document._2Tag1._4Subtag.∆1text |
| 10403 |
._3Document._2Tag1._4Subtag.∆3text |
| 10404 |
._3Document._2Tag1.∆5text········· |
| 10405 |
._3Document.∆3text················ |
| 10406 |
.∆18text·························· |
| 10407 |
</pre></div> |
| 10408 |
|
| 10409 |
</li><li> <b>Z←11 ⎕XML B</b> is like Z←7 ⎕XML B, except that only the tag |
| 10410 |
names are returned: |
| 10411 |
|
| 10412 |
<div class="example"> |
| 10413 |
<pre class="example"> ⊃11 ⎕XML APL ⍝ all tag member names |
| 10414 |
._3Document················ |
| 10415 |
._3Document._2Tag1········· |
| 10416 |
._3Document._2Tag1._4Subtag |
| 10417 |
</pre></div> |
| 10418 |
|
| 10419 |
</li><li> <b>Z←12 ⎕XML B</b> is like Z←7 ⎕XML B, except that all member |
| 10420 |
names of B are returned without descending into the sub-tree: |
| 10421 |
|
| 10422 |
<div class="example"> |
| 10423 |
<pre class="example"> ⊃12 ⎕XML APL ⍝ all member names (7 ⎕XML, but non-recursive) |
| 10424 |
.∆1declaration |
| 10425 |
.∆2text······· |
| 10426 |
._3Document··· |
| 10427 |
.∆18text······ |
| 10428 |
</pre></div> |
| 10429 |
|
| 10430 |
<p>This variant may also be useful for structured variables that were not |
| 10431 |
created by ⎕XML. |
| 10432 |
</p> |
| 10433 |
</li><li> <b>Z←13 ⎕XML B</b> shows the (flat) tag names in B, but but does |
| 10434 |
not descend into any sub-tree of B. |
| 10435 |
|
| 10436 |
<div class="example"> |
| 10437 |
<pre class="example"> ⊃13 ⎕XML APL ⍝ all tag members (8 ⎕XML, but non-recursive) |
| 10438 |
._3Document |
| 10439 |
</pre></div> |
| 10440 |
|
| 10441 |
</li><li> <b>Z←(14 "member-name") ⎕XML B</b> shows the next member in B |
| 10442 |
after "member-name". It can be used as an iterator that walks through |
| 10443 |
the tags. An empty member name returns the first member: |
| 10444 |
|
| 10445 |
<div class="example"> |
| 10446 |
<pre class="example"> APL ← ⎕XML XML←"<ROOT><A/><B/><C/></ROOT>" |
| 10447 |
|
| 10448 |
(14 "") ⎕XML APL._1ROOT ⍝ get first member in APL._1ROOT |
| 10449 |
⍙1 |
| 10450 |
(14 "⍙1") ⎕XML APL._1ROOT ⍝ next member after APL._1ROOT.⍙1 |
| 10451 |
_1A |
| 10452 |
(14 "_1A") ⎕XML APL._1ROOT ⍝ next member after APL._1ROOT._1A |
| 10453 |
_2B |
| 10454 |
(14 "_2B") ⎕XML APL._1ROOT ⍝ next member after APL._1ROOT._2B |
| 10455 |
_3C |
| 10456 |
(14 "_3C") ⎕XML APL._1ROOT ⍝ last member: will be empty |
| 10457 |
</pre></div> |
| 10458 |
</li></ul> |
| 10459 |
|
| 10460 |
<hr> |
| 10461 |
</div> |
| 10462 |
<div class="subsection" id="XML-Queries"> |
| 10463 |
<div class="header"> |
| 10464 |
<p> |
| 10465 |
Previous: <a href="#Dyadic-_2395XML" accesskey="p" rel="prev">Dyadic ⎕XML</a>, Up: <a href="#g_t_2395XML-_002d-XML-Parsing" accesskey="u" rel="up">⎕XML - XML Parsing</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 10466 |
</div> |
| 10467 |
<span id="XML-Queries-1"></span><h4 class="subsection">2.44.6 XML Queries</h4> |
| 10468 |
|
| 10469 |
<p>The different functions in dyadic ⎕XML are intended to construct XML queries. |
| 10470 |
An XML query extracts information from, or modifies information in, an XML |
| 10471 |
document. XML queries may differ considerably in their details, but usually |
| 10472 |
follow these top-level steps: |
| 10473 |
</p> |
| 10474 |
<ol> |
| 10475 |
<li> Read an XML document into, say, APL (APL←0 ⎕XML B or APL←1 ⎕XML B) |
| 10476 |
</li><li> Optionally, display the structure of the document (3, 4, or 5 ⎕XML APL) |
| 10477 |
</li><li> Select a subset of XML nodes (= GNU APL member names, 6 ⎕XML APL) |
| 10478 |
</li><li> retrieve or modify the data in the selected XML nodes |
| 10479 |
(with something like MEMBERS←(⊂APL) FUN¨6⎕XML APL←⎕XML followed by MEMBER⊃ ) |
| 10480 |
</li><li> Optionally, convert the modified XML document back to XML (0 ⎕XML APL) |
| 10481 |
</li></ol> |
| 10482 |
|
| 10483 |
<hr> |
| 10484 |
</div> |
| 10485 |
</div> |
| 10486 |
<div class="section" id="Conditionals"> |
| 10487 |
<div class="header"> |
| 10488 |
<p> |
| 10489 |
Next: <a href="#Matrix-Product" accesskey="n" rel="next">Matrix Product</a>, Previous: <a href="#g_t_2395XML-_002d-XML-Parsing" accesskey="p" rel="prev">⎕XML - XML Parsing</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 10490 |
</div> |
| 10491 |
<span id="Conditionals-1"></span><h3 class="section">2.45 Conditionals</h3> |
| 10492 |
|
| 10493 |
<p><b>WARNING</b>: GNU APL conditionals are experimental. Use them with care and |
| 10494 |
avoid them, wherever possible, in favor of portability. Neither the ISO |
| 10495 |
APL standard, nor IBM APL2 provide conditionals. |
| 10496 |
</p> |
| 10497 |
<ul class="section-toc"> |
| 10498 |
<li><a href="#Design-considerations_002e" accesskey="1">Design considerations.</a></li> |
| 10499 |
<li><a href="#Syntax" accesskey="2">Syntax</a></li> |
| 10500 |
<li><a href="#A-Possible-Pitfall" accesskey="3">A Possible Pitfall</a></li> |
| 10501 |
</ul> |
| 10502 |
<hr> |
| 10503 |
<div class="subsection" id="Design-considerations_002e"> |
| 10504 |
<div class="header"> |
| 10505 |
<p> |
| 10506 |
Next: <a href="#Syntax" accesskey="n" rel="next">Syntax</a>, Up: <a href="#Conditionals" accesskey="u" rel="up">Conditionals</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 10507 |
</div> |
| 10508 |
<span id="Design-considerations_002e-1"></span><h4 class="subsection">2.45.1 Design considerations.</h4> |
| 10509 |
|
| 10510 |
<p>The author of GNU APL has, for a long time, hesitated to implement |
| 10511 |
conditionals in GNU APL. Primarily for the following reasons: |
| 10512 |
</p> |
| 10513 |
<ul> |
| 10514 |
<li> the lack of standardization of conditionals, |
| 10515 |
</li><li> the lack of an elegant syntax that fits well into the typical |
| 10516 |
(brief) APL programming style, and in particular |
| 10517 |
</li><li> the large number of keywords for flow control used in some other APL |
| 10518 |
interpreters. See below. |
| 10519 |
</li></ul> |
| 10520 |
|
| 10521 |
<p>The C language has six keywords for flow control: <b>if</b> <b>else</b>, <b>for</b>, |
| 10522 |
<b>while</b>, <b>do</b>, <b>switch</b> and <b>goto</b>. Two of them (<b>do</b> and <b>while</b>) |
| 10523 |
are redundant and rarely used, leaving only 4 base cases. A quick <b>grep -c</b> |
| 10524 |
over the 130,000 top-level C++ source code lines of GNU APL reveals the |
| 10525 |
following statistics: |
| 10526 |
</p> |
| 10527 |
<ul> |
| 10528 |
<li> 7000 <b>if</b> statements, 5400 of them <i>one-sided</i> (i.e. |
| 10529 |
if-then-endif), and the other 1600 of them <i>two-sided</i> (i.e. |
| 10530 |
if-then-else-endif, |
| 10531 |
</li><li> 2000 <b>for</b> statements, 1200 of them trivial iterations over some |
| 10532 |
array (aka. <i>for (int i = 0; i < size; ++i) ... </i>, |
| 10533 |
</li><li> 200 <b>switch</b> statements with an averge of 8 case clauses per switch, |
| 10534 |
</li><li> 250 <b>while</b> statements, and |
| 10535 |
</li><li> 70 <b>do while</b> statements |
| 10536 |
</li></ul> |
| 10537 |
|
| 10538 |
<p>In contrast, a popular non-free APL interpreter came up with a zoo of 30 |
| 10539 |
or so keywords for the purpose of flow control in one way or another: |
| 10540 |
</p> |
| 10541 |
<p><b>:If</b> <b>:While</b> <b>:Repeat</b> <b>:For</b> <b>:In</b> <b>:InEach</b> <b>:Select</b> |
| 10542 |
<b>:With</b> <b>:Trap</b> <b>:Hold</b> <b>:Disposable</b> |
| 10543 |
<b>:Else</b> <b>:ElseIf</b> <b>:AndIf</b> <b>:OrIf</b> <b>:Until</b> <b>:Case</b> <b>:CaseList</b> |
| 10544 |
<b>:EndIf</b> <b>:EndWhile</b> <b>:EndRepeat</b> <b>:EndFor</b> <b>:EndSelect</b> <b>:EndWith</b> |
| 10545 |
<b>:EndTrap</b> <b>:EndHold</b> <b>:EndDisposable</b> <b>:GoTo</b>, <b>:Return</b>, |
| 10546 |
<b>:Leave</b> <b>:Continue</b> |
| 10547 |
</p> |
| 10548 |
<p>This approach, its implementation, and its constraints raise a number of |
| 10549 |
serious problems. To name a few: |
| 10550 |
</p> |
| 10551 |
<ul> |
| 10552 |
<li> A rather common APL design practice is to first debug non-trivial |
| 10553 |
APL statements in immediate execution mode and only transfer them into |
| 10554 |
the body of defined functions when they work properly. However, the keywords |
| 10555 |
above seem to work only in the bodies of defined functions but <b>not</b> in |
| 10556 |
immediate execution mode. The reason for this limitation might be that |
| 10557 |
their implementation depends, under the hood, on APL labels (which are not |
| 10558 |
available in immediate execution mode). |
| 10559 |
|
| 10560 |
</li><li> Another rather common design practice is to limit the length of |
| 10561 |
lines to less than 80 characters (e.g. in the GNU coding conventions, |
| 10562 |
<b>https://gcc.gnu.org/codingconventions.html#Line</b>). |
| 10563 |
Even if it were possible to squeeze an :If :Then :Else :Endif into an 80 |
| 10564 |
character line, and using a single whitespace around the keywords for |
| 10565 |
readability, wastes almost 1/3 of the precious 80 characters for keywords. |
| 10566 |
In this example, each of the COND, THEN, and ELSE parts must then be < 20 |
| 10567 |
characters on average. Not to talk about indentation to clarify the code. |
| 10568 |
|
| 10569 |
</li><li> Each of the keywords has rather specific constraints as to how and |
| 10570 |
where it can be used. For example (to quote a simple one from a reference |
| 10571 |
manual): |
| 10572 |
|
| 10573 |
<p><i>Control words, including qualifiers such as :Else and :ElseIf, may occur |
| 10574 |
only at the beginning of a line or expression in a diamond-separated |
| 10575 |
statement. The only exceptions are :In and :InEach which must appear on |
| 10576 |
the same line within a :For expression.</i> |
| 10577 |
</p> |
| 10578 |
<p>These constraints suggest that the keywords mentioned are merely syntactic |
| 10579 |
sugar that covers the underlying APL structure, i.e. labels and computed |
| 10580 |
branches. GNU APL does not claim to be fundamentally different in that |
| 10581 |
regard, but the syntax of the syntactic sugar is somewhat simpler. |
| 10582 |
</p></li></ul> |
| 10583 |
|
| 10584 |
<p>Learning from the above, the conclusions for the syntax of GNU APL condionals |
| 10585 |
were these: |
| 10586 |
</p> |
| 10587 |
<ol> |
| 10588 |
<li> the syntax shall be easy to understand and consistent, |
| 10589 |
</li><li> the syntax shall not only work in defined functions, but also in |
| 10590 |
immediate execution mode (provided, of course, that the entire |
| 10591 |
conditional fits into a single input line), |
| 10592 |
</li><li> in order to support 2., lengthy keywords shall be avoided in |
| 10593 |
favor of the original APL style, and |
| 10594 |
</li><li> the syntax needs to only support those cases where the standard APL |
| 10595 |
flow control (i.e. <b>→N</b>) becomes cumbersome. There is no obvious |
| 10596 |
benefit in introducing a new (and redundant) syntax when the |
| 10597 |
standard APL syntax is already completely adequate. IOW: in which |
| 10598 |
universe would <b><i>:Goto Label</i></b> be any better than the good old |
| 10599 |
<b><i>→Label</i></b>? |
| 10600 |
</li></ol> |
| 10601 |
|
| 10602 |
<p>As to the last point, almost every flow control case (in a standards compliant |
| 10603 |
APL program) falls into one of the following categories (sorted by |
| 10604 |
increasing complexity): |
| 10605 |
</p> |
| 10606 |
<ol> |
| 10607 |
<li> <b>one-sided if</b>: if COND then THEN endif |
| 10608 |
</li><li> <b>two-sided if/else</b>: if COND then THEN else ELSE endif |
| 10609 |
</li><li> <b>loop</b>: while COND do BODY (or its less frequently used twin do BODY |
| 10610 |
while COND) |
| 10611 |
</li><li> <b>switch/case</b>: switch ARG case CASE1 case CASE2 case ... CASEn endswitch |
| 10612 |
</li></ol> |
| 10613 |
|
| 10614 |
<p>where THEN, ELSE, CASE1, CASE2, CASEn, and BODY are sequences of one or more |
| 10615 |
statements, while COND or ARG determine which of these sequences (if any) |
| 10616 |
shall be executed. |
| 10617 |
</p> |
| 10618 |
<p>Interestingly, the complexity of the above cases, when coded in APL, |
| 10619 |
increases in amost the reverse order (compared to other languages). |
| 10620 |
For example, |
| 10621 |
</p> |
| 10622 |
<ol> |
| 10623 |
<li> <b>switch/case</b>: |
| 10624 |
<div class="example"> |
| 10625 |
<pre class="example"> →(ARG) / L1 L2 ... Ln ⍝ switch(ARG) |
| 10626 |
L1: CASE1 ◊ →L_endcase ⍝ case 1: |
| 10627 |
L2: CASE2 ◊ →L_endcase ⍝ case 2: |
| 10628 |
... |
| 10629 |
LN: CASEn ⍝ case N: |
| 10630 |
L_endcase: |
| 10631 |
</pre></div> |
| 10632 |
|
| 10633 |
</li><li> <b>loop</b>: |
| 10634 |
<div class="example"> |
| 10635 |
<pre class="example"> Loop: BODY ◊ →(COND) / Loop ⍝ repeat BODY while COND |
| 10636 |
</pre></div> |
| 10637 |
|
| 10638 |
</li><li> <b>one-sided if</b>: |
| 10639 |
<div class="example"> |
| 10640 |
<pre class="example"> →(!COND) / L_endif ⍝ jump over the THEN clause |
| 10641 |
THEN |
| 10642 |
L_endif: |
| 10643 |
</pre></div> |
| 10644 |
|
| 10645 |
<p>or, not uncommon and shorter, but less portable and less readable: |
| 10646 |
</p> |
| 10647 |
<div class="example"> |
| 10648 |
<pre class="example"> →(!COND) / ↑1+⎕LC ◊ THEN ⍝ jump over the THEN clause to the next line |
| 10649 |
</pre></div> |
| 10650 |
|
| 10651 |
</li><li> <b>two-sided if/else</b>: |
| 10652 |
<div class="example"> |
| 10653 |
<pre class="example"> →COND ↓ L_else L_then |
| 10654 |
L_then: THEN ◊ →L_endif |
| 10655 |
L_else: ELSE |
| 10656 |
L_endif: |
| 10657 |
</pre></div> |
| 10658 |
</li></ol> |
| 10659 |
|
| 10660 |
<p>A closer look at these cases reveals that there is not much room for |
| 10661 |
syntax improvements in cases 1. (switch) and 2. (loop). The introduction of |
| 10662 |
a new syntax like :Select / :Case for switches or :For / :Endfor for loops |
| 10663 |
would therefore only make matters different and incompatible, but not better. |
| 10664 |
</p> |
| 10665 |
<p>In case 3. (one-sided if) there is also not much to gain. However, case 3. |
| 10666 |
can be seen as a special case of case 4. (with an empty ELSE clause). For |
| 10667 |
the sake of consistency, a new syntax for case 4. should also cover case 3. |
| 10668 |
</p> |
| 10669 |
<p>The only cases where a new syntax could improve matters are therefore |
| 10670 |
cases 3. and 4. |
| 10671 |
</p> |
| 10672 |
<p>Another consideration relates to the end marker <b>L_endif</b> (and would |
| 10673 |
likewise relate to <b>L_endcase</b> if we hadn’t already ruled that case out). |
| 10674 |
There are two reasonable syntax alternatives to handle the branch to the |
| 10675 |
end of the conditional: |
| 10676 |
</p> |
| 10677 |
<ol> |
| 10678 |
<li> allow multiple statements in the THEN and ELSE clauses and mark the end |
| 10679 |
of the <b>ELSE</b> clause (or, in the one-sided case 3. of the <b>THEN</b> clause |
| 10680 |
above) with some kind of <b>ENDIF</b> marker, or |
| 10681 |
</li><li> allow only single statement clauses (which implies the <b>ENDIF</b> and |
| 10682 |
makes it obsolete. |
| 10683 |
</li></ol> |
| 10684 |
|
| 10685 |
<p>The design decision made in GNU APL was to go for multiple statements because |
| 10686 |
the advantage in 2. (shorter code) looks much smaller than the advantages |
| 10687 |
of 1. (e.g. insertion of debug printouts into a clause). |
| 10688 |
</p> |
| 10689 |
<hr> |
| 10690 |
</div> |
| 10691 |
<div class="subsection" id="Syntax"> |
| 10692 |
<div class="header"> |
| 10693 |
<p> |
| 10694 |
Next: <a href="#A-Possible-Pitfall" accesskey="n" rel="next">A Possible Pitfall</a>, Previous: <a href="#Design-considerations_002e" accesskey="p" rel="prev">Design considerations.</a>, Up: <a href="#Conditionals" accesskey="u" rel="up">Conditionals</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 10695 |
</div> |
| 10696 |
<span id="Syntax-1"></span><h4 class="subsection">2.45.2 Syntax</h4> |
| 10697 |
|
| 10698 |
<p>With the above considerations in mind, GNU APL decided in favor of the |
| 10699 |
following syntax for APL conditionals: |
| 10700 |
</p> |
| 10701 |
<ul> |
| 10702 |
<li> <b>one-sided if/else</b>: |
| 10703 |
<div class="example"> |
| 10704 |
<pre class="example"> COND →→ THEN-statement(s) ←← |
| 10705 |
</pre></div> |
| 10706 |
|
| 10707 |
</li><li> <b>two-sided if/else</b>: |
| 10708 |
<div class="example"> |
| 10709 |
<pre class="example"> COND →→ THEN-statement(s) ←→ ELSE-statement(s) ←← |
| 10710 |
</pre></div> |
| 10711 |
|
| 10712 |
</li></ul> |
| 10713 |
|
| 10714 |
<p>The following rules govern this syntax: |
| 10715 |
</p> |
| 10716 |
<ul> |
| 10717 |
<li> The <b>→→</b>, <b>←→</b>, and <b>←←</b> markers must be single tokens (2 |
| 10718 |
adjacent Unicode characters). No whitespace (and in particular |
| 10719 |
no line feed) is permitted between the first and the second arrow. |
| 10720 |
A single <b>→</b> is a valid APL statement (named Escape). A linefeed |
| 10721 |
between two <b>→</b> turns the single token <b>→→</b> into two valid (though |
| 10722 |
most of the time useless) Escape statements. |
| 10723 |
|
| 10724 |
</li><li> The <b>COND</b>, <b>THEN</b>, and <b>ELSE</b> clauses shall be sequences |
| 10725 |
of valid APL statements. In particular: |
| 10726 |
<ul> |
| 10727 |
<li> The condition <b>COND</b> shall be a <i>single statement</i> that |
| 10728 |
evaluates to a 1-item Boolean array (of any rank). |
| 10729 |
The statement result of <b>COND</b> is a committed value and is |
| 10730 |
therefore not being displayed. |
| 10731 |
|
| 10732 |
</li><li> The <b>THEN</b> clause shall be <i>one or more valid statements</i>, |
| 10733 |
possibly separated by <b>◊</b> for more than one statement. |
| 10734 |
|
| 10735 |
</li><li> Likewise, the <b>ELSE</b> clause (if present) shall be |
| 10736 |
<i>one or more valid statements</i>, separated by <b>◊</b> for |
| 10737 |
more than one statement. |
| 10738 |
</li></ul> |
| 10739 |
</li></ul> |
| 10740 |
|
| 10741 |
<p>Examples: |
| 10742 |
</p><div class="example"> |
| 10743 |
<pre class="example"> ⍝ short format. Valid in immediate execution and in defined functions |
| 10744 |
⍝ |
| 10745 |
X←5 ◊ X≥0 →→ X 'is positive' ←→ X 'is negative' ←← |
| 10746 |
5 is positive |
| 10747 |
|
| 10748 |
|
| 10749 |
⍝ long format. Only possible in defined functions because immediate |
| 10750 |
⍝ execution works line by line (and parsing the first line would fail). |
| 10751 |
|
| 10752 |
⍝ valid split into several lines (in a defined function) |
| 10753 |
⍝ |
| 10754 |
∇FOO X |
| 10755 |
X≥0 →→ |
| 10756 |
X 'is positive' ←→ |
| 10757 |
X 'is negative' ←← |
| 10758 |
∇ |
| 10759 |
FOO 5 |
| 10760 |
5 is positive |
| 10761 |
FOO ¯5 |
| 10762 |
¯5 is negative |
| 10763 |
|
| 10764 |
|
| 10765 |
⍝ invalid split into several lines: ←→ spread over 2 lines. |
| 10766 |
⍝ FOO can be properly parsed, but calling FOO fails. |
| 10767 |
⍝ |
| 10768 |
∇FOO X |
| 10769 |
X≥0 →→ X 'is positive' ← |
| 10770 |
→ X 'is negative' ←← |
| 10771 |
∇ |
| 10772 |
FOO 5 |
| 10773 |
SYNTAX ERROR+ |
| 10774 |
FOO[1] X 'is positive'← |
| 10775 |
* * |
| 10776 |
</pre></div> |
| 10777 |
|
| 10778 |
<p>The recommended usage of the corresponding <b>→→</b>, <b>←→</b>, and <b>←←</b> |
| 10779 |
token of the same conditional is to: |
| 10780 |
</p> |
| 10781 |
<ul> |
| 10782 |
<li> either put all of them on the same line (short format), or |
| 10783 |
</li><li> else align all of them on the same column (long form), but |
| 10784 |
</li><li> never mix the short and long forms |
| 10785 |
</li></ul> |
| 10786 |
|
| 10787 |
<p>In theory one could place (and align) the token <i>before</i> or <i>after</i> |
| 10788 |
their statement(s). However, placing them <i>after</i> their statement(s), |
| 10789 |
like shown in the examples above, makes them arguably more visible and |
| 10790 |
is therefore the recommended way. In particular when conditionals are |
| 10791 |
being nested. |
| 10792 |
</p> |
| 10793 |
<hr> |
| 10794 |
</div> |
| 10795 |
<div class="subsection" id="A-Possible-Pitfall"> |
| 10796 |
<div class="header"> |
| 10797 |
<p> |
| 10798 |
Previous: <a href="#Syntax" accesskey="p" rel="prev">Syntax</a>, Up: <a href="#Conditionals" accesskey="u" rel="up">Conditionals</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 10799 |
</div> |
| 10800 |
<span id="A-Possible-Pitfall-1"></span><h4 class="subsection">2.45.3 A Possible Pitfall</h4> |
| 10801 |
|
| 10802 |
<p>In APL, as well as in C/C++ (and most other languages), an expression is also |
| 10803 |
a statement, but not vice versa. Expressions yield a value, while statements |
| 10804 |
may not. |
| 10805 |
</p> |
| 10806 |
<p>The <b>C/C++</b> language knows <i>conditional statements</i> and |
| 10807 |
<i>conditional expressions</i>: |
| 10808 |
</p> |
| 10809 |
<div class="example"> |
| 10810 |
<pre class="example"> if (COND) { IF-statements } // conditional C/C++ statement |
| 10811 |
else { ELSE-statements } |
| 10812 |
|
| 10813 |
(COND) ? IF-value : ELSE-value // conditional C/C++ expression |
| 10814 |
</pre></div> |
| 10815 |
|
| 10816 |
<p>Likewise, GNU APL also has <i>conditional statements</i> and |
| 10817 |
<i>conditional expressions</i>: |
| 10818 |
</p> |
| 10819 |
<div class="example"> |
| 10820 |
<pre class="example"> COND →→ IF-statements ←→ ELSE-statements ←← ⍝ conditional APL statement |
| 10821 |
|
| 10822 |
IF-value ⊢[COND] ELSE-value ⍝ conditional APL expression |
| 10823 |
</pre></div> |
| 10824 |
|
| 10825 |
<p>If a value is needed, e.g. for assigning it to a variable, but the expression |
| 10826 |
becomes too long to fit in a single line, then one can replicate the |
| 10827 |
assignment in both of the <b>IF</b> and the <b>ELSE</b> clauses: |
| 10828 |
</p> |
| 10829 |
<div class="example"> |
| 10830 |
<pre class="example"> // C/C++ |
| 10831 |
x = -5; |
| 10832 |
Result = (x < 0) ? "negative" : "positive"; // OK |
| 10833 |
Result = if (x < 0) { "negative"; } else { "positive"; } // syntax error |
| 10834 |
if (x < 0) { Result = "negative"; } else { Result = "positive"; } // OK |
| 10835 |
|
| 10836 |
⍝ GNU APL conditional expression, aka. ⊢[] |
| 10837 |
X←¯5 |
| 10838 |
Result ← "positive" ⊢[X < 0] "negative" ⍝ OK |
| 10839 |
Result ← (X < 0) →→ ⊣"negative" ←→ ⊣"positive" ←← ⍝ ??? |
| 10840 |
Result |
| 10841 |
1 |
| 10842 |
|
| 10843 |
(X < 0) →→ Result ← "negative" ←→ Result ← "positive" ←← ⍝ OK |
| 10844 |
Result |
| 10845 |
negative |
| 10846 |
</pre></div> |
| 10847 |
|
| 10848 |
<p>The correct, although possibly unexpected, result <b>1</b> of the APL conditional |
| 10849 |
in the line with comment <b>⍝ ???</b> above was evaluated as follows: |
| 10850 |
</p> |
| 10851 |
<ol> |
| 10852 |
<li> APL computes different statements from right to left. |
| 10853 |
</li><li> The conditional tokens <b>→→</b>, <b>←→</b>, and <b>←←</b> are statement |
| 10854 |
separators like <b>◊</b>, but with the additional capability to jump |
| 10855 |
over their <b>THEN</b> and/or <b>ELSE</b> clauses according to the value |
| 10856 |
of their <b>COND</b> clause. |
| 10857 |
</li><li> The first statement in the example above is <code>Result ← (X < 0)</code> |
| 10858 |
i.e. <code>Result←1</code>. |
| 10859 |
</li><li> The statement result of <b>COND</b> is always a committed value, regardless |
| 10860 |
of whether it is assigned to a variable (like in the example above) |
| 10861 |
or not. Therefore the <b>COND</b> clause does not produce any output. |
| 10862 |
</li><li> The next statement that is being executed it either <code>⊣"negative"</code> |
| 10863 |
or else <code>⊣"positive"</code>, depending on the value of variable <b>X</b>. |
| 10864 |
Normally it would be displayed, but due to <b>⊣</b> the display is |
| 10865 |
suppressed. The entire conditional does therefore produce no output. |
| 10866 |
</li><li> As a consequence, <code>Result ← 1</code> (and not, for example, |
| 10867 |
<code>"negative"</code> !). |
| 10868 |
</li><li> The <code>⊣"negative"</code> and <code>⊣"positive"</code> are separate statements |
| 10869 |
which do not assign anything to <b>Result</b> in the previous <b>COND</b> |
| 10870 |
clause. The pitfall in the example is that the conditional looks like |
| 10871 |
it would assign either <b>"negative"</b> or <b>"positive"</b> to <b>Result</b>, |
| 10872 |
but in fact assigns <b>1</b>. |
| 10873 |
</li></ol> |
| 10874 |
|
| 10875 |
<p>Needless to say that, as in the example above, the assignment of a APL |
| 10876 |
conditional statement to a variable is, although possible, a dubious |
| 10877 |
programming style that should be avoided for the sake of readability. The |
| 10878 |
key takeaway here is that <i>the clauses of a GNU APL conditional are (two or |
| 10879 |
three) different statements, and that an assignment of the conditional |
| 10880 |
to a variable assigns only the first of these statements to the variable</i>. |
| 10881 |
</p> |
| 10882 |
<p>In C/C++, the condition of a conditional statement MUST be put in parentheses, |
| 10883 |
while the condition of a conditional expression MAY be put in parentheses. |
| 10884 |
</p> |
| 10885 |
<p>In GNU APL the condition of a conditional statement MAY be put in parentheses, |
| 10886 |
while the condition of conditional expression MUST be put in brackets (since it |
| 10887 |
is the axis argument <b>X</b> of <b>A ⊢[X] B.</b>. A good programming practice |
| 10888 |
in C/C++ and in GNU APL is to always put the condition into parentheses even if |
| 10889 |
that if not syntactically required. Some people even use double parentheses to |
| 10890 |
emphasize the condition of a conditional statement or expression. |
| 10891 |
</p> |
| 10892 |
<hr> |
| 10893 |
</div> |
| 10894 |
</div> |
| 10895 |
<div class="section" id="Matrix-Product"> |
| 10896 |
<div class="header"> |
| 10897 |
<p> |
| 10898 |
Next: <a href="#Monadic-_2260-_0028Nub-Sieve_0029" accesskey="n" rel="next">Monadic ≠ (Nub Sieve)</a>, Previous: <a href="#Conditionals" accesskey="p" rel="prev">Conditionals</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 10899 |
</div> |
| 10900 |
<span id="Matrix-Product-1"></span><h3 class="section">2.46 Matrix Product</h3> |
| 10901 |
|
| 10902 |
<p>In standard APL, the inner product Z of two matrices A and B as known from |
| 10903 |
linear algebra, is: |
| 10904 |
</p> |
| 10905 |
<div class="example"> |
| 10906 |
<pre class="example"> Z←A +.× B ⍝ the most frequent special case of A f.g B |
| 10907 |
</pre></div> |
| 10908 |
|
| 10909 |
<p>However, the inner product in APL is more general than the inner product in |
| 10910 |
linear algebra. In the general case <b>A f.g B</b> may the functions <b>f</b> |
| 10911 |
and <b>g</b> also be non-scalar APL primitives or even defined functions. |
| 10912 |
This generality may occasionally be helpful, but it comes with a performance |
| 10913 |
penalty since many argument checks are duplicated. At the same time |
| 10914 |
<b>A +.× B</b> is by far the most frequent use of the inner product operator |
| 10915 |
<b>’.’</b>. |
| 10916 |
</p> |
| 10917 |
<p>For this reason GNU APL also provides a slightly more efficient dyadic |
| 10918 |
function <b>∘</b> (Matrix Product) for the special case <b>+.×</b> of the dyadic |
| 10919 |
operator ’.’. This function ∘ has been optimized for numeric arguments |
| 10920 |
and computes the matrix product as known from linear algebra. |
| 10921 |
</p> |
| 10922 |
<p>For two-dimensional matrices <b>A</b> and <b>B</b> is function <b>∘</b> conceptually |
| 10923 |
the same as <b>+.×</b>: |
| 10924 |
</p> |
| 10925 |
<p><b>A∘B ←→ A +.× B</b> |
| 10926 |
</p> |
| 10927 |
<p>However, there are some subtle differences between the function <b>∘</b> and |
| 10928 |
the operator <b>+.×</b>: |
| 10929 |
</p> |
| 10930 |
<ul> |
| 10931 |
<li> <b>A +.× B</b> allows <b>A</b> and <b>B</b> to be of any rank, while <b>A∘B</b> |
| 10932 |
raises a RANK ERROR if the rank of <b>A</b> or <b>B</b> is more than 2. |
| 10933 |
|
| 10934 |
</li><li> The product <b>A +.× B</b> can be a vector (e.g. if <b>A</b> is a vector |
| 10935 |
and <b>B</b> is a matrix), usually understood as row-vector. |
| 10936 |
In contrast (and more similar to linear algebra) <b>A∘B</b> is always a matrix. |
| 10937 |
</li><li> In order to preserve the distinction between row vectors and column |
| 10938 |
vectors the arguments <b>A</b> and <b>B</b> of <b>∘</b> are possibly reshaped |
| 10939 |
according to the following rules: |
| 10940 |
|
| 10941 |
<ul> |
| 10942 |
<li> if <b>A</b> and/or <b>B</b> is a scalar then the normal (element-wise) |
| 10943 |
product of <b>A</b> and <b>B</b> is computed. That is, <b>A∘B ←→ A×B</b>. |
| 10944 |
</li><li> if <b>A</b> is a APL vector of length <b>N</b> then it is reshaped to a |
| 10945 |
row-vector before <b>A∘B</b> is computed. In this context, |
| 10946 |
the term <i>row-vector</i> shall refer to a matrix of shape <b>(1 N)</b>. |
| 10947 |
</li><li> if <b>B</b> is a APL vector of length <b>N</b> then it is reshaped to a |
| 10948 |
column-vector before <b>A∘B</b> is computed. In this context, the term |
| 10949 |
<i>column-vector</i> shall refer to a matrix of shape <b>(N 1)</b>. |
| 10950 |
</li></ul> |
| 10951 |
|
| 10952 |
<p>Examples: |
| 10953 |
</p> |
| 10954 |
<div class="example"> |
| 10955 |
<pre class="example"> M←2 2⍴1 2 3 4 ⍝ a matrix |
| 10956 |
V←10 11 ⍝ a vector |
| 10957 |
|
| 10958 |
M +.× V |
| 10959 |
32 74 |
| 10960 |
|
| 10961 |
M∘V |
| 10962 |
32 |
| 10963 |
74 |
| 10964 |
|
| 10965 |
V +.× M |
| 10966 |
43 64 |
| 10967 |
|
| 10968 |
V∘M |
| 10969 |
43 64 |
| 10970 |
|
| 10971 |
⍴M +.× V ⍝ the result is an (APL-) vector of length 2 |
| 10972 |
2 |
| 10973 |
⍴V +.× M ⍝ the result is an (APL-) vector of length 2 |
| 10974 |
2 |
| 10975 |
⍴V∘M ⍝ the result is row vector |
| 10976 |
1 2 |
| 10977 |
⍴M∘V ⍝ the result is column vector |
| 10978 |
2 1 |
| 10979 |
</pre></div> |
| 10980 |
|
| 10981 |
</li><li> <b>A +.× B</b> requires that the number of columns in <b>A</b> is equal to |
| 10982 |
the number of rows in <b>B</b>. In contrast, <b>A∘B</b> has no such requirement |
| 10983 |
and will add 0-columns to <b>A</b> resp. 0-rows to <b>B</b> to match the shapes |
| 10984 |
of <b>A</b> and <b>B</b>. Naturally, the multiplications of these 0-columns or |
| 10985 |
0-rows is not in fact performed, but optimized away. |
| 10986 |
|
| 10987 |
</li></ul> |
| 10988 |
|
| 10989 |
<hr> |
| 10990 |
</div> |
| 10991 |
<div class="section" id="Monadic-_2260-_0028Nub-Sieve_0029"> |
| 10992 |
<div class="header"> |
| 10993 |
<p> |
| 10994 |
Previous: <a href="#Matrix-Product" accesskey="p" rel="prev">Matrix Product</a>, Up: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="u" rel="up">Non-standard GNU APL Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 10995 |
</div> |
| 10996 |
<span id="Monadic-_005b_003f_005d-_0028Nub-Sieve_0029"></span><h3 class="section">2.47 Monadic ≠ (Nub Sieve)</h3> |
| 10997 |
|
| 10998 |
<p>The nub sieve <b>Z←≠B</b> of a value <b>B</b> is a Boolean vector <b>Z</b> with the |
| 10999 |
same shape as <b>B</b> and: |
| 11000 |
</p> |
| 11001 |
<p><b>Z[i]</b> is 1 if <b>B[i]</b> is the first occurrence of <b>B[i]</b> in <b>B</b> and |
| 11002 |
0 otherwise. For vectors <b>B</b> this can also be expressed as: |
| 11003 |
</p> |
| 11004 |
<div class="example"> |
| 11005 |
<pre class="example"> ≠ B ←→ (B⍳B)=(⍳⍴B) |
| 11006 |
</pre></div> |
| 11007 |
|
| 11008 |
<p>Examples: |
| 11009 |
</p> |
| 11010 |
<div class="example"> |
| 11011 |
<pre class="example"> ≠'Hello, World.' |
| 11012 |
1 1 1 0 1 1 1 1 0 1 0 1 1 |
| 11013 |
≠ 1 (2 3) 4 (2 3) 5 6 |
| 11014 |
1 1 1 0 1 1 |
| 11015 |
</pre></div> |
| 11016 |
|
| 11017 |
|
| 11018 |
|
| 11019 |
|
| 11020 |
<hr> |
| 11021 |
</div> |
| 11022 |
</div> |
| 11023 |
<div class="chapter" id="Limitations-and-Missing-Features"> |
| 11024 |
<div class="header"> |
| 11025 |
<p> |
| 11026 |
Next: <a href="#Internationalization" accesskey="n" rel="next">Internationalization</a>, Previous: <a href="#Non_002dstandard-GNU-APL-Features" accesskey="p" rel="prev">Non-standard GNU APL Features</a>, Up: <a href="#Top" accesskey="u" rel="up">GNU APL Reference Manual</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 11027 |
</div> |
| 11028 |
<span id="Limitations-and-Missing-Features-1"></span><h2 class="chapter">3 Limitations and Missing Features</h2> |
| 11029 |
|
| 11030 |
<p>GNU APL is an almost full implementation of the ISO standard 13751. |
| 11031 |
However, a few limitations exist. See file README-4-compliance for |
| 11032 |
an up-to-date description of limitations. |
| 11033 |
</p> |
| 11034 |
<ul class="section-toc"> |
| 11035 |
<li><a href="#System-Limits" accesskey="1">System Limits</a></li> |
| 11036 |
<li><a href="#Shared-Variables" accesskey="2">Shared Variables</a></li> |
| 11037 |
</ul> |
| 11038 |
<hr> |
| 11039 |
<div class="section" id="System-Limits"> |
| 11040 |
<div class="header"> |
| 11041 |
<p> |
| 11042 |
Next: <a href="#Shared-Variables" accesskey="n" rel="next">Shared Variables</a>, Up: <a href="#Limitations-and-Missing-Features" accesskey="u" rel="up">Limitations and Missing Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 11043 |
</div> |
| 11044 |
<span id="System-Limits-1"></span><h3 class="section">3.1 System Limits</h3> |
| 11045 |
|
| 11046 |
<p>APL floating point values are 64-bit wide, thus ranging from |
| 11047 |
-8.98E307 to 8.98E307. |
| 11048 |
</p> |
| 11049 |
<p>GNU APL integers have a guaranteed range from -9200000000000000000 to |
| 11050 |
9200000000000000000, which is a slighly smaller range. |
| 11051 |
</p> |
| 11052 |
<p>A 64-bit integer represents a value between -9223372036854775808 and |
| 11053 |
9223372036854775807. |
| 11054 |
</p> |
| 11055 |
<p>If the result of a computation is integer by nature, for example +, -, or × |
| 11056 |
with integer arguments, <b>and</b> falls into the guaranteed range, then |
| 11057 |
the result will be an APL integer. If the result is too large for a 64-bit |
| 11058 |
signed integer then the result will be automatically converted to an APL |
| 11059 |
floating point value. However, if the result is outside the guaranteed range |
| 11060 |
but still within the 64-bit integer range, e.g. between 9200000000000000000 |
| 11061 |
and 9223372036854775807 (exclusive), then GNU APL gives no guarantees as to |
| 11062 |
whether the result will be a 64-bit integer or a 64-bit floating point (with |
| 11063 |
the resulting loss of precision). This decision is usually function-specific |
| 11064 |
and driven by performance considerations. |
| 11065 |
</p> |
| 11066 |
<p>APL values have a maximum rank of 8. However, the maximum range can be set |
| 11067 |
by means of ./configure (see README-2-configure). |
| 11068 |
</p> |
| 11069 |
<hr> |
| 11070 |
</div> |
| 11071 |
<div class="section" id="Shared-Variables"> |
| 11072 |
<div class="header"> |
| 11073 |
<p> |
| 11074 |
Previous: <a href="#System-Limits" accesskey="p" rel="prev">System Limits</a>, Up: <a href="#Limitations-and-Missing-Features" accesskey="u" rel="up">Limitations and Missing Features</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 11075 |
</div> |
| 11076 |
<span id="Shared-Variables-1"></span><h3 class="section">3.2 Shared Variables</h3> |
| 11077 |
|
| 11078 |
<p>The system functions and variables related to shared variables, i.e. ⎕SVO, |
| 11079 |
⎕SVR, ⎕SVC, ⎕SVS, and ⎕SVQ, are implemented. |
| 11080 |
</p> |
| 11081 |
<p>Communication between two workspaces is supported, but with some |
| 11082 |
limitations. Two workspaces can only communicate via shared variables if they |
| 11083 |
(i.e. their processes) run on the same machine. |
| 11084 |
</p> |
| 11085 |
<p>However, only two auxiliary processors, AP100 and AP210, are provided as |
| 11086 |
examples of how to implement auxiliary processors in GNU APL. |
| 11087 |
</p> |
| 11088 |
<p>Shared variables for auxiliary processors are provided for some backward |
| 11089 |
compatibility. In the past - without access to the source code of the APL |
| 11090 |
interpreter - shared variables were the only method available to extend the |
| 11091 |
functionality of the interpreter. |
| 11092 |
</p> |
| 11093 |
<p>With this interpreter - and access to its source code - it is often more |
| 11094 |
convenient to add your own commands or your own system variables to the |
| 11095 |
APL interpreter rather than adding auxiliary processors. |
| 11096 |
</p> |
| 11097 |
<hr> |
| 11098 |
</div> |
| 11099 |
</div> |
| 11100 |
<div class="chapter" id="Internationalization"> |
| 11101 |
<div class="header"> |
| 11102 |
<p> |
| 11103 |
Next: <a href="#Vector-Notation" accesskey="n" rel="next">Vector Notation</a>, Previous: <a href="#Limitations-and-Missing-Features" accesskey="p" rel="prev">Limitations and Missing Features</a>, Up: <a href="#Top" accesskey="u" rel="up">GNU APL Reference Manual</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 11104 |
</div> |
| 11105 |
<span id="Internationalization-1"></span><h2 class="chapter">4 Internationalization</h2> |
| 11106 |
|
| 11107 |
<p>GNU APL used to be internationalized by means of GNU gettext, but is not |
| 11108 |
anymore. |
| 11109 |
</p> |
| 11110 |
<p>For APL characters to work properly with keyboards and terminal emulators |
| 11111 |
(see also README-3-keyboard) it is essential that your LANG environment |
| 11112 |
variable is correctly set. For German, that would be "de_DE.utf8", like: |
| 11113 |
</p> |
| 11114 |
<p>$export LANG=de_DE.utf8 |
| 11115 |
</p> |
| 11116 |
<p>A misspelling of the language can cause APL characters to become unavailable, |
| 11117 |
even if your xmodmap is correct. You can check your setting by executing the |
| 11118 |
program ’locale’. If it shows warnings like these: |
| 11119 |
</p> |
| 11120 |
<div class="example"> |
| 11121 |
<pre class="example">locale: Cannot set LC_CTYPE to default locale: No such file or directory |
| 11122 |
locale: Cannot set LC_MESSAGES to default locale: No such file or directory |
| 11123 |
locale: Cannot set LC_ALL to default locale: No such file or directory |
| 11124 |
</pre></div> |
| 11125 |
|
| 11126 |
<p>then something is wrong and you should check your LANG setting and installed |
| 11127 |
locales. |
| 11128 |
</p> |
| 11129 |
<p>As far as xterm is concerned, the xterm command line options –u8, –lc, and |
| 11130 |
–en might solve problems related to the terminal. |
| 11131 |
</p> |
| 11132 |
<hr> |
| 11133 |
</div> |
| 11134 |
<div class="chapter" id="Vector-Notation"> |
| 11135 |
<div class="header"> |
| 11136 |
<p> |
| 11137 |
Next: <a href="#GNU-APL-Project-Structure" accesskey="n" rel="next">GNU APL Project Structure</a>, Previous: <a href="#Internationalization" accesskey="p" rel="prev">Internationalization</a>, Up: <a href="#Top" accesskey="u" rel="up">GNU APL Reference Manual</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 11138 |
</div> |
| 11139 |
<span id="Vector-Notation-1"></span><h2 class="chapter">5 Vector Notation</h2> |
| 11140 |
|
| 11141 |
<p>This chapter describes details of the GNU APL vector notation. Unfortunately |
| 11142 |
there exists misleading information concerning the GNU APL vector notation |
| 11143 |
on the public internet and the attempts of the author of this manual to have |
| 11144 |
the misleading information corrected were not successful. |
| 11145 |
</p> |
| 11146 |
<ul class="section-toc"> |
| 11147 |
<li><a href="#History" accesskey="1">History</a></li> |
| 11148 |
<li><a href="#Standardization" accesskey="2">Standardization</a></li> |
| 11149 |
<li><a href="#Quotes-from-the-lrm" accesskey="3">Quotes from the lrm</a></li> |
| 11150 |
<li><a href="#Some-APL2-Tests" accesskey="4">Some APL2 Tests</a></li> |
| 11151 |
<li><a href="#Definitions" accesskey="5">Definitions</a></li> |
| 11152 |
<li><a href="#Unexpected-Stranding" accesskey="6">Unexpected Stranding</a></li> |
| 11153 |
<li><a href="#GNU-APL-Vector-Notation" accesskey="7">GNU APL Vector Notation</a></li> |
| 11154 |
</ul> |
| 11155 |
<hr> |
| 11156 |
<div class="section" id="History"> |
| 11157 |
<div class="header"> |
| 11158 |
<p> |
| 11159 |
Next: <a href="#Standardization" accesskey="n" rel="next">Standardization</a>, Up: <a href="#Vector-Notation" accesskey="u" rel="up">Vector Notation</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 11160 |
</div> |
| 11161 |
<span id="History-1"></span><h3 class="section">5.1 History</h3> |
| 11162 |
|
| 11163 |
<p>Vector Notation is as old as APL. The famous Book <i>APL \360: An interactive |
| 11164 |
approach</i> by <b>Leonard Gilman</b> and <b>Allen J. Rose</b> introduces vector |
| 11165 |
notation already on page 2, but without calling it vector notation. |
| 11166 |
</p> |
| 11167 |
<p>Quote: |
| 11168 |
</p> |
| 11169 |
<div class="example"> |
| 11170 |
<pre class="example">Or we can assign a string of numbers to a variable called X, and ask the |
| 11171 |
computer to execute the command shown, + / X , with the response 17.1 : |
| 11172 |
X+-3 4 1.1 3 6 |
| 11173 |
+/X |
| 11174 |
17.1 |
| 11175 |
</pre></div> |
| 11176 |
|
| 11177 |
<p>The terms <i>vector notation</i> (used by IBM APL and by GNU APL) was |
| 11178 |
apparently coined by <b>Kenneth Iverson</b> (<i>A Programming Language</i>, |
| 11179 |
p. 163) and the equivalent term <i>strand notation</i> is used by other |
| 11180 |
APL vendors. |
| 11181 |
</p> |
| 11182 |
|
| 11183 |
<hr> |
| 11184 |
</div> |
| 11185 |
<div class="section" id="Standardization"> |
| 11186 |
<div class="header"> |
| 11187 |
<p> |
| 11188 |
Next: <a href="#Quotes-from-the-lrm" accesskey="n" rel="next">Quotes from the lrm</a>, Previous: <a href="#History" accesskey="p" rel="prev">History</a>, Up: <a href="#Vector-Notation" accesskey="u" rel="up">Vector Notation</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 11189 |
</div> |
| 11190 |
<span id="Standardization-1"></span><h3 class="section">5.2 Standardization</h3> |
| 11191 |
|
| 11192 |
<p>The current ISO standard ISO/IEC 13751 <i>Programming Language APL, extended</i>, |
| 11193 |
in the following abbreviated as <b>iso</b>, does not formally define vector |
| 11194 |
notation, but uses it all over the place in its examples. |
| 11195 |
</p> |
| 11196 |
<p>The IBM APL2 <i>Language Reference Manual</i>, in the following abbreviated as |
| 11197 |
<b>lrm</b>, was the blueprint for GNU APL. The <b>lrm</b> describes vector notation |
| 11198 |
briefly. |
| 11199 |
</p> |
| 11200 |
|
| 11201 |
<hr> |
| 11202 |
</div> |
| 11203 |
<div class="section" id="Quotes-from-the-lrm"> |
| 11204 |
<div class="header"> |
| 11205 |
<p> |
| 11206 |
Next: <a href="#Some-APL2-Tests" accesskey="n" rel="next">Some APL2 Tests</a>, Previous: <a href="#Standardization" accesskey="p" rel="prev">Standardization</a>, Up: <a href="#Vector-Notation" accesskey="u" rel="up">Vector Notation</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 11207 |
</div> |
| 11208 |
<span id="Quotes-from-the-lrm-1"></span><h3 class="section">5.3 Quotes from the lrm</h3> |
| 11209 |
|
| 11210 |
<p>Different aspects of vector notation are distributed over the <b>lrm</b>. To |
| 11211 |
get a compressed view of the matter we quote the relevant pieces: |
| 11212 |
</p> |
| 11213 |
<ol> |
| 11214 |
<li> <b>lrm page 14</b>: <i>The juxtaposition of two or more arrays in an |
| 11215 |
expression results in a vector whose items are the arrays. Representing |
| 11216 |
a vector in this manner is called <b>vector notation</b>.</i> |
| 11217 |
|
| 11218 |
</li><li> <b>lrm page 14</b>: <i>Characters in a vector consisting only of |
| 11219 |
characters can be listed within one set of single quotation marks: |
| 11220 |
’FACE’ ←→ (’F’ ’A’ ’C’ ’E’)</i> |
| 11221 |
|
| 11222 |
</li><li> <b>lrm page 33</b>: <i>The hierarchy of binding strengths is listed |
| 11223 |
below in descending order.</i> |
| 11224 |
<pre class="verbatim"> Binding Strength What Is Bound |
| 11225 |
────────────────────── ──────────────────────────────────── |
| 11226 |
1. Brackets Brackets to what is on their left |
| 11227 |
2. Specification left Left arrow to what is on its left |
| 11228 |
3. Right operand Dyadic operator to its right operand |
| 11229 |
4. Vector Array to an array |
| 11230 |
5. Left operand Operator to its left operand |
| 11231 |
6. Left argument Function to its left argument |
| 11232 |
7. Right argument Function to its right argument |
| 11233 |
8. Specification right Left arrow to what is on its right |
| 11234 |
════════════════════════════════════════════════════════════════ |
| 11235 |
</pre><p>The binding strength <b>4.</b> above is the one for vector notation. It |
| 11236 |
defines how the items of a vector notation are bound together (as |
| 11237 |
opposed to being bound to other tokens). For example: <b>1 2 3[2]</b> |
| 11238 |
becomes <b>1 2 (3[2])</b> because <b>[2]</b> binds stronger to <b>3</b> left |
| 11239 |
of it than <b>3</b> binds to <b>2</b> left of it (which then raises |
| 11240 |
a <b>RANK ERROR</b> because <b>3</b> is a scalar). |
| 11241 |
</p></li></ol> |
| 11242 |
|
| 11243 |
|
| 11244 |
<hr> |
| 11245 |
</div> |
| 11246 |
<div class="section" id="Some-APL2-Tests"> |
| 11247 |
<div class="header"> |
| 11248 |
<p> |
| 11249 |
Next: <a href="#Definitions" accesskey="n" rel="next">Definitions</a>, Previous: <a href="#Quotes-from-the-lrm" accesskey="p" rel="prev">Quotes from the lrm</a>, Up: <a href="#Vector-Notation" accesskey="u" rel="up">Vector Notation</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 11250 |
</div> |
| 11251 |
<span id="Some-APL2-Tests-1"></span><h3 class="section">5.4 Some APL2 Tests</h3> |
| 11252 |
|
| 11253 |
<p>Before explaining the details of vector notation in GNU APL we would like |
| 11254 |
to share the results of some tests performed with IBM APL2 (again the demo |
| 11255 |
version for PCs). |
| 11256 |
</p> |
| 11257 |
<ul class="section-toc"> |
| 11258 |
<li><a href="#Test-1_003a-Binding-strength-of-_005b_005d" accesskey="1">Test 1: Binding strength of []</a></li> |
| 11259 |
<li><a href="#Test-2_003a-Binding-strength-of-the-left-operand" accesskey="2">Test 2: Binding strength of the left operand</a></li> |
| 11260 |
</ul> |
| 11261 |
<hr> |
| 11262 |
<div class="subsection" id="Test-1_003a-Binding-strength-of-_005b_005d"> |
| 11263 |
<div class="header"> |
| 11264 |
<p> |
| 11265 |
Next: <a href="#Test-2_003a-Binding-strength-of-the-left-operand" accesskey="n" rel="next">Test 2: Binding strength of the left operand</a>, Up: <a href="#Some-APL2-Tests" accesskey="u" rel="up">Some APL2 Tests</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 11266 |
</div> |
| 11267 |
<span id="Test-1_003a-Binding-strength-of-_005b_005d-1"></span><h4 class="subsection">5.4.1 Test 1: Binding strength of []</h4> |
| 11268 |
|
| 11269 |
<div class="example"> |
| 11270 |
<pre class="example"> ⍝ IBM APL2: Binding strength of []... |
| 11271 |
|
| 11272 |
⍝ Test 1a. |
| 11273 |
⍝ |
| 11274 |
1 2 3[2] |
| 11275 |
RANK ERROR |
| 11276 |
1 2 3[2] |
| 11277 |
^^ |
| 11278 |
|
| 11279 |
⍝ Test 1b. |
| 11280 |
⍝ |
| 11281 |
'a' 'b' 'c'[2] |
| 11282 |
RANK ERROR |
| 11283 |
'ab' 'c'[2] |
| 11284 |
^ ^ |
| 11285 |
|
| 11286 |
⍝ Test 1c. |
| 11287 |
⍝ |
| 11288 |
'abc'[b][2] |
| 11289 |
b |
| 11290 |
</pre></div> |
| 11291 |
|
| 11292 |
<p><b>Test 1a</b>: no surprise. <b>[]</b> has the strongest binding and raises a |
| 11293 |
<b>RANK ERROR</b> when indexing the scalar <b>3</b>. |
| 11294 |
</p> |
| 11295 |
<p><b>Test 1b</b>: no surprise. since it follows suit. |
| 11296 |
</p> |
| 11297 |
<p><b>Test 1c</b>: no surprise for the binding strength. This test confirms |
| 11298 |
the second quote on page 14 of the lrm. |
| 11299 |
</p> |
| 11300 |
<hr> |
| 11301 |
</div> |
| 11302 |
<div class="subsection" id="Test-2_003a-Binding-strength-of-the-left-operand"> |
| 11303 |
<div class="header"> |
| 11304 |
<p> |
| 11305 |
Previous: <a href="#Test-1_003a-Binding-strength-of-_005b_005d" accesskey="p" rel="prev">Test 1: Binding strength of []</a>, Up: <a href="#Some-APL2-Tests" accesskey="u" rel="up">Some APL2 Tests</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 11306 |
</div> |
| 11307 |
<span id="Test-2_003a-Binding-strength-of-the-left-operand-1"></span><h4 class="subsection">5.4.2 Test 2: Binding strength of the left operand</h4> |
| 11308 |
|
| 11309 |
<p>For this test we create a monadic defined function <b>SHOW_NC</b>, a monadic |
| 11310 |
defined operator <b>OPER1</b>, and a dyadic defined operator <b>OPER2</b>: |
| 11311 |
</p> |
| 11312 |
<div class="example"> |
| 11313 |
<pre class="example"> ⍝ display the name class of B¯B |
| 11314 |
⍝ |
| 11315 |
∇Z←SHOW_NC B¯B;N |
| 11316 |
N←8↑B,':' |
| 11317 |
→(¯1 0 1 2 3 4 = ⎕NC B¯B)/I U L V F O ◊ ++ |
| 11318 |
I: →0, Z←(8↑B), ': Invalid Name' |
| 11319 |
U: →0, Z←(8↑B), ': Unused Name' |
| 11320 |
L: →0, Z←(8↑B), ': Label' |
| 11321 |
V: →0, Z←(8↑B), ': Value', ⍎B¯B |
| 11322 |
F: →0, Z←(8↑B), ': Function' |
| 11323 |
O: →0, Z←(8↑B), ': Operator' |
| 11324 |
∇ |
| 11325 |
|
| 11326 |
⍝ monadic operator |
| 11327 |
⍝ |
| 11328 |
∇Z←A (LO OPER1) B |
| 11329 |
SHOW_NC 'A' |
| 11330 |
SHOW_NC 'LO' |
| 11331 |
SHOW_NC 'OPER1' |
| 11332 |
SHOW_NC 'B' |
| 11333 |
∇ |
| 11334 |
|
| 11335 |
⍝ dyadic operator |
| 11336 |
⍝ |
| 11337 |
∇Z←A (LO OPER2 RO) B |
| 11338 |
SHOW_NC 'A' |
| 11339 |
SHOW_NC 'LO' |
| 11340 |
SHOW_NC 'OPER1' |
| 11341 |
SHOW_NC 'RO' |
| 11342 |
SHOW_NC 'B' |
| 11343 |
∇ |
| 11344 |
</pre></div> |
| 11345 |
|
| 11346 |
<p>The somewhat strange looking argument name <b>B¯B</b> of <b>SHOW_NC</b> instead of |
| 11347 |
the rather frequent <b>B</b> was chosen to avoid name conflicts between the |
| 11348 |
right value argument of <b>SHOW_NC</b> and the right value argument the |
| 11349 |
operators under test (like <b>OPER1</b> or <b>OPER2</b>). Then: |
| 11350 |
</p> |
| 11351 |
<div class="example"> |
| 11352 |
<pre class="example"> ⍝ Test 2a: binding of the left operand (literal LO) |
| 11353 |
⍝ |
| 11354 |
11 22 33 OPER1 1 2 3 |
| 11355 |
A : Unused Name |
| 11356 |
LO : Value 11 22 33 |
| 11357 |
OPER1 : Operator |
| 11358 |
B : Value 1 2 3 |
| 11359 |
|
| 11360 |
⍝ Test 2b: binding of the left operand (parser LO) |
| 11361 |
⍝ |
| 11362 |
(UU VV WW)←11 22 33 |
| 11363 |
UU VV WW OPER1 1 2 3 |
| 11364 |
A : Unused Name |
| 11365 |
LO : Value 11 22 33 |
| 11366 |
OPER1 : Operator |
| 11367 |
B : Value 1 2 3 |
| 11368 |
|
| 11369 |
⍝ Test 2c. binding of the left operand (in parentheses) |
| 11370 |
⍝ |
| 11371 |
11 22 (33 OPER1) 1 2 3 |
| 11372 |
A : 11 |
| 11373 |
LO : Value 22 33 |
| 11374 |
OPER1 : Operator |
| 11375 |
B : Value 1 2 3 |
| 11376 |
|
| 11377 |
⍝ Test 2d. binding of the right operand |
| 11378 |
⍝ |
| 11379 |
11 22 33 'lop' OPER2 'rop' 1 2 3 |
| 11380 |
A : Unused Name |
| 11381 |
LO : Value 11 22 33 lop |
| 11382 |
OPER2 : Operator |
| 11383 |
RO : Value rop |
| 11384 |
B : Value 1 2 3 |
| 11385 |
</pre></div> |
| 11386 |
|
| 11387 |
<p>The results are rather interesting. We will later on discuss a potential |
| 11388 |
difference between vector notation at tokenization time and vector notation |
| 11389 |
at execution time. The same outcome of tests <b>2a.</b> and <b>2b.</b> demonstrates |
| 11390 |
that IBM APL2 handles both variants in the same fashion (supposedly because |
| 11391 |
both cases are resolved at execution time). |
| 11392 |
</p> |
| 11393 |
<p>Test <b>2a.</b> proves that vector notation binds stronger than the left operand |
| 11394 |
to its dyadic operator. Test <b>2c.</b> demonstrates how the binding strengths |
| 11395 |
can be undermined with parentheses. |
| 11396 |
</p> |
| 11397 |
<p>Test <b>2d.</b> proves that the right operand binds stronger than vector notation. |
| 11398 |
However, this case is interesting from an <b>iso</b>. Page 126 of <b>iso</b> gives |
| 11399 |
the following example for the dyadic rank operator: |
| 11400 |
</p> |
| 11401 |
<div class="example"> |
| 11402 |
<pre class="example"> ⍝ example from ISO/IEC 13751 p.126 |
| 11403 |
⍝ |
| 11404 |
0 1 2⌽∘0 1 'ABC' |
| 11405 |
ABC |
| 11406 |
BCA |
| 11407 |
CAB |
| 11408 |
</pre></div> |
| 11409 |
|
| 11410 |
<p>Comparing the results of Test <b>2d.</b> with GNU APL shows how <b>iso</b> believes |
| 11411 |
their example should be parsed: |
| 11412 |
</p> |
| 11413 |
<div class="example"> |
| 11414 |
<pre class="example"> ⍝ Test 2e. (GNU APL): |
| 11415 |
⍝ |
| 11416 |
0 1 2(⌽⍤0 1) 'ABC' |
| 11417 |
ABC |
| 11418 |
BCA |
| 11419 |
CAB |
| 11420 |
|
| 11421 |
⍝ Test 2f. (GNU APL): |
| 11422 |
⍝ |
| 11423 |
0 1 2(⌽⍤0) 1 'ABC' |
| 11424 |
LENGTH ERROR |
| 11425 |
0 1 2(⌽⍤0 0 0)1 'ABC' |
| 11426 |
^ ^ |
| 11427 |
</pre></div> |
| 11428 |
|
| 11429 |
<p><b>NOTE</b>: It is not possible to run tests <b>2e.</b> and <b>2f.</b> in IBM APL2 |
| 11430 |
directly (because at least in the PC demo version of IBM APL2 the rank |
| 11431 |
operator <b>⍤</b> is not implemented. However using our defined function |
| 11432 |
<b>OPER2</b> above instead of <b>⍤</b> shows that IBM APL2 evaluates the ISO |
| 11433 |
example as <b>0 1 2(⌽∘0) 1 ’ABC’</b> (in accordance with <b>lrm</b>) and not |
| 11434 |
as <b>0 1 2(⌽∘0 1) ’ABC’</b> as <b>iso</b> suggests. |
| 11435 |
</p> |
| 11436 |
<p><b>Takeaways</b>: the tests above teach us the following: |
| 11437 |
</p> |
| 11438 |
<ul> |
| 11439 |
<li> Vector notation differs between: |
| 11440 |
<ul> |
| 11441 |
<li> The ISO standard for APL, |
| 11442 |
</li><li> IBM APL2, and |
| 11443 |
</li><li> APL implementation of other vendors (including GNU APL). |
| 11444 |
</li></ul> |
| 11445 |
</li><li> It is therefore impossible to accommodate both the ISO standard and |
| 11446 |
IBM APL2 to 100% at the same time, but |
| 11447 |
</li><li> GNU APL tries to be as close as possible to one of them, |
| 11448 |
</li><li> The issues highlighted above can be easily avoided by always using |
| 11449 |
parentheses around operators and their operands (even though they |
| 11450 |
may appear to be redundant). These parentheses are the (only) key |
| 11451 |
to portable APL programs. |
| 11452 |
</li></ul> |
| 11453 |
|
| 11454 |
|
| 11455 |
<hr> |
| 11456 |
</div> |
| 11457 |
</div> |
| 11458 |
<div class="section" id="Definitions"> |
| 11459 |
<div class="header"> |
| 11460 |
<p> |
| 11461 |
Next: <a href="#Unexpected-Stranding" accesskey="n" rel="next">Unexpected Stranding</a>, Previous: <a href="#Some-APL2-Tests" accesskey="p" rel="prev">Some APL2 Tests</a>, Up: <a href="#Vector-Notation" accesskey="u" rel="up">Vector Notation</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 11462 |
</div> |
| 11463 |
<span id="Definitions-1"></span><h3 class="section">5.5 Definitions</h3> |
| 11464 |
|
| 11465 |
<p><b>Definition</b>: A <i>(complete) strand</i> consists of two (!) or more adjacent |
| 11466 |
values in a defined function, or in a string being ⍎’ed, or on a line entered |
| 11467 |
in immediate execution mode. Such values can be literals (like in <b>1 2 3</b>), |
| 11468 |
but also values of variables or results of niladic functions. A strand is |
| 11469 |
always a vector and we call the values in a strand the <i>items of the strand</i>. |
| 11470 |
Strand items can be simple (i.e. numbers or single characters) or nested |
| 11471 |
(strings or other strands). Strand items are always (possibly nested) |
| 11472 |
APL scalars. |
| 11473 |
</p> |
| 11474 |
<p><b>Definition</b>: A <i>literal strand</i> is a strand whose items are only |
| 11475 |
literals (including nested literals like in 1 2 (3 4) 5). Literal strands are |
| 11476 |
created when an APL expression is tokenized. At that point in time the |
| 11477 |
literal strand is incomplete and more strand items may be added to it when |
| 11478 |
the statement is executed. |
| 11479 |
</p> |
| 11480 |
<p><b>Note</b>: Strands are, in general, subject to what is known |
| 11481 |
as <i>unexpected stranding</i>, which occurs when an operator accept values as |
| 11482 |
operands. This is the case for the power operator <b>⍣</b> and for the rank |
| 11483 |
operator <b>⍤</b>; both can have values as right operands. The clean way of |
| 11484 |
avoiding unexpected stranding is to put the operator and its operands |
| 11485 |
into parentheses, but the <b>iso</b> does not do that and in order to make |
| 11486 |
the examples in <b>iso</b> work, GNU APL has dedicated code for the rank and |
| 11487 |
power operators that prevents unexpected stranding for their right operand |
| 11488 |
and their right function value. For defined operators this is not possible |
| 11489 |
because at tokenization time a defined operator is only a symbol whose |
| 11490 |
name class at execution time is unknown at tokenization time of its caller. |
| 11491 |
For the same reason. the binding strengths defined above can not cure this |
| 11492 |
kind of unexpected stranding. |
| 11493 |
</p> |
| 11494 |
<p><b>Definition</b>: An <i>extended literal strand</i> is a strand whose items are |
| 11495 |
either literals (including nested literals) or particular simple primitive |
| 11496 |
function is with particular literal arguments. |
| 11497 |
</p> |
| 11498 |
<p><b>Definition</b>: A <i>mixed strand</i> is a strand which is not a literal strand. |
| 11499 |
</p> |
| 11500 |
<p><b>Definition</b>: A strand is <i>open</i> if more items can be appended to it. |
| 11501 |
</p> |
| 11502 |
<p><b>Definition</b>: A strand is <i>closed</i> if it is not open. |
| 11503 |
</p> |
| 11504 |
<p><b>Definition</b>: A strand is <i>nested</i> if at lease one of its items is nested. |
| 11505 |
</p> |
| 11506 |
<p>Examples: |
| 11507 |
</p> |
| 11508 |
<div class="example"> |
| 11509 |
<pre class="example"> 1 2 3 ⍝ open literal strand |
| 11510 |
|
| 11511 |
1 2 (3⍴4) 5 ⍝ open extended literal strand ←→ 1 2 4 4 4 5 |
| 11512 |
1 2 (3/4) 5 ⍝ open extended literal strand ←→ 1 2 4 4 4 5 |
| 11513 |
'ab' (⍳3) 'ef' ⍝ open extended literal strand ←→ 'ab' (1 2 3) 'ef' |
| 11514 |
|
| 11515 |
VAR←1 2 3 ⍝ mixed strand item |
| 11516 |
∇Z←FOO ⍝ mixed strand item |
| 11517 |
Z←1 2 3 |
| 11518 |
∇ |
| 11519 |
|
| 11520 |
1 VAR 3 ⍝ nested open mixed strand |
| 11521 |
1 FOO 3 ⍝ nested open mixed strand |
| 11522 |
|
| 11523 |
(1 2 3) ⍝ closed literal strand |
| 11524 |
'abc' ⍝ closed literal strand |
| 11525 |
</pre></div> |
| 11526 |
|
| 11527 |
|
| 11528 |
<hr> |
| 11529 |
</div> |
| 11530 |
<div class="section" id="Unexpected-Stranding"> |
| 11531 |
<div class="header"> |
| 11532 |
<p> |
| 11533 |
Next: <a href="#GNU-APL-Vector-Notation" accesskey="n" rel="next">GNU APL Vector Notation</a>, Previous: <a href="#Definitions" accesskey="p" rel="prev">Definitions</a>, Up: <a href="#Vector-Notation" accesskey="u" rel="up">Vector Notation</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 11534 |
</div> |
| 11535 |
<span id="Unexpected-Stranding-1"></span><h3 class="section">5.6 Unexpected Stranding</h3> |
| 11536 |
|
| 11537 |
<p><i>Unexpected stranding</i> (or better: <i>false stranding</i>) refers to a situation |
| 11538 |
where the stranding of adjacent values leads to a wrong result. Unexpected |
| 11539 |
stranding is not unexpected at all, as we will see in this section. |
| 11540 |
</p> |
| 11541 |
<p>In non-nested APL interpreters, such as APL \360, the binding strength of |
| 11542 |
strand items was the highest. That was a wise decision which had two |
| 11543 |
consequences: |
| 11544 |
</p> |
| 11545 |
<ul> |
| 11546 |
<li> Expressions like <b>1 2 3[2]</b> were always valid in APL \360 and friends. |
| 11547 |
The current APL2 and, (for the sake of compatibility) also GNU APL cases, |
| 11548 |
where <b>1 2 3[2]</b> raises a RANK ERROR, are merely an unfortunate |
| 11549 |
consequence of binding expressions in brackets stronger than strand |
| 11550 |
items. |
| 11551 |
</li><li> Similarly, the IBM APL2 design decision to bind right operand stronger |
| 11552 |
than strand items, together with the decision to allow values as operands, |
| 11553 |
create the possibility of false stranding. |
| 11554 |
</li></ul> |
| 11555 |
|
| 11556 |
<p><b>Corollary 1:</b> unexpected stranding was not an issue before binding strength |
| 11557 |
in APL2 was introduced. |
| 11558 |
</p> |
| 11559 |
<p><b>Corollary 2:</b> The only binding strengths for which unexpected stranding |
| 11560 |
can occur are those for that bind stronger than vector (i.e. strand item), |
| 11561 |
i.e. <b>1. bracket</b>, <b>2. specification left</b>, and <b>3. right operand</b>. |
| 11562 |
Of these 3 binding strengths, only <b>3. right operand</b> conflicts with |
| 11563 |
strand notation (because neither <b>[...]</b> nor <b>←</b> can be strand items. |
| 11564 |
</p> |
| 11565 |
<p>To go into a little more detail we consider the following token sequences: |
| 11566 |
</p> |
| 11567 |
<div class="example"> |
| 11568 |
<pre class="example"> ⍝ at tokenizatio time... |
| 11569 |
PRIMITIVE_FUNCTION VALUE_A VALUE_B ⍝ ├── expected |
| 11570 |
PRIMITIVE_DYADIC_OPERATOR VALUE_A VALUE_B ⍝ ├── unexpected |
| 11571 |
VALUE VALUE_A VALUE_B ⍝ ├── expected |
| 11572 |
SYMBOL VALUE_A VALUE_B ⍝ └── unknown |
| 11573 |
|
| 11574 |
⍝ at execution time... |
| 11575 |
VALUE VALUE_A VALUE_B ⍝ ├── expected |
| 11576 |
FUNCTION VALUE_A VALUE_B ⍝ ├── expected |
| 11577 |
DYADIC_OPERATOR VALUE_A VALUE_B ⍝ └── unexpected |
| 11578 |
</pre></div> |
| 11579 |
|
| 11580 |
<p>The fact that <b>VALUE_A</b> and <b>VALUE_B</b> are adjacent constitutes what is |
| 11581 |
known as a <i>shift/reduce conflict</i> in compiler terminology. Let’s add |
| 11582 |
some parentheses to see how these shift/reduce conflicts are, by means |
| 11583 |
of the APL2 binding strength, supposed to be resolved: |
| 11584 |
</p> |
| 11585 |
<div class="example"> |
| 11586 |
<pre class="example"> ⍝ at tokenization time... |
| 11587 |
PRIMITIVE_FUNCTION ( VALUE_A VALUE_B ) ⍝ ├── expected |
| 11588 |
( PRIMITIVE_DYADIC_OPERATOR VALUE_A ) VALUE_B ⍝ ├── unexpected |
| 11589 |
VALUE ( VALUE_A VALUE_B ) ⍝ ├── expected |
| 11590 |
? SYMBOL ? VALUE_A ? VALUE_B ? ⍝ └── unknown |
| 11591 |
|
| 11592 |
⍝ at execution time... |
| 11593 |
VALUE ( VALUE_A VALUE_B ) ⍝ ├── expected |
| 11594 |
FUNCTION ( VALUE_A VALUE_B ) ⍝ ├── expected |
| 11595 |
( DYADIC_OPERATOR VALUE_A ) VALUE_B ⍝ └── unexpected |
| 11596 |
</pre></div> |
| 11597 |
|
| 11598 |
<p>The first four sequences occurs at tokenization time, the others at |
| 11599 |
execution time. The significant difference between primitive functions |
| 11600 |
and primitive operators on the one hand and defined functions and defined |
| 11601 |
operators on the other hand is that the parser "knows" in the first three |
| 11602 |
cases if <b>VALUE_A</b> and <b>VALUE_B</b> shall be stranded together or not. |
| 11603 |
In the fourth case the parser cannot decide whether <b>SYMBOL</b> refers to a |
| 11604 |
defined function (including functions derived from monadic operators), |
| 11605 |
to a variable, or to a dyadic defined operator. Therefore the parser can |
| 11606 |
resolve the first three cases at tokenization time, i.e. bind <b>VALUE_A</b> |
| 11607 |
to <b>PRIMITIVE_DYADIC_OPERATOR</b> or to <b>VALUE</b> if so, and to <b>VALUE_B</b> |
| 11608 |
otherwise. Only the binding of <b>SYMBOL</b> is left over and will be decided |
| 11609 |
at execution time. |
| 11610 |
</p> |
| 11611 |
<p>At execution time, the first thing that happens is that <b>SYMBOL</b> is resolved |
| 11612 |
to its current value (so its token class changes from <b>SYMBOL</b> to <b>VALUE</b> |
| 11613 |
(for variables), or to <b>FUNCTION</b> (for defined functions), or to |
| 11614 |
<b>OPERATOR</b> for defined operators. At the time when the parser sees the |
| 11615 |
pattern <b>VALUE_A VALUE_B</b> it can, with a lookahead of 1 token decide |
| 11616 |
if the token <b>VALUE_A</b> shall be bound to it <b>PRIMITIVE_DYADIC_OPERATOR</b>, |
| 11617 |
or stranded to its adjacent value <b>VALUE_B</b>. To do this a so-called |
| 11618 |
<b>LALR-1</b> parser suffices. In simple terms: if the parser sees a |
| 11619 |
<b>PRIMITIVE_DYADIC_OPERATOR</b> left of <b>VALUE_A VALUE_B</b> then it shifts |
| 11620 |
<b>VALUE_A</b> (which will later on become the right operand of that operator) |
| 11621 |
and otherwise it starts or continues strand building with <b>VALUE_A</b>. |
| 11622 |
In <b>iso</b> terminology: the phrase evaluator for pattern <b>VALUE_A VALUE_B</b> |
| 11623 |
stops the strand building (in compiler terminology it <b>shifts</b> <b>VALUE_A</b>) |
| 11624 |
when the lookahead token is <b>DYADIC_OPERATOR</b>), and otherwise it continues |
| 11625 |
the strand building (in compiler terminology it <b>reduces</b> the pattern |
| 11626 |
<b>VALUE_A VALUE_B</b>). |
| 11627 |
</p> |
| 11628 |
<p>As an aside: The ISO standard provides examples with strand notation |
| 11629 |
that would be illegal in IBM APL2 (rank operator, page 126): |
| 11630 |
</p> |
| 11631 |
<div class="example"> |
| 11632 |
<pre class="example"> 0 1 2 ⌽⍤0 1 'ABC' |
| 11633 |
ABC |
| 11634 |
BCA |
| 11635 |
CAB |
| 11636 |
</pre></div> |
| 11637 |
|
| 11638 |
<p>In IBM APL2, the rightmost <b>0</b> would bind to <b>⍤</b> and not to the rightmost |
| 11639 |
<b>1</b>, like in (parentheses added according to the APL binding strength: |
| 11640 |
</p> |
| 11641 |
<div class="example"> |
| 11642 |
<pre class="example"> (0 1 2) (⌽ ⍤ 0) (1 'ABC') |
| 11643 |
LENGTH ERROR |
| 11644 |
0 1 2(⌽⍤0 0 0)1 'ABC' |
| 11645 |
^ ^ |
| 11646 |
</pre></div> |
| 11647 |
|
| 11648 |
<p>What saves IBM here is only the fact that the two primitive operators |
| 11649 |
that accept values as right operands (the rank operator ⍤ and the power |
| 11650 |
operator ⍣) are not implemented in IBM APL2. In contrast GNU APL has |
| 11651 |
implemented both operators and the <b>iso</b> examples work as shown in |
| 11652 |
the standard. |
| 11653 |
</p> |
| 11654 |
<p>The same <b>iso</b> example in Dyalog APL (who seem to be the inventor of these |
| 11655 |
operators) does not work either (at least not without parentheses: |
| 11656 |
</p> |
| 11657 |
<div class="example"> |
| 11658 |
<pre class="example"> ⍝ Dyalog APL |
| 11659 |
⍝ |
| 11660 |
0 1 2 ⌽⍤0 1 'ABC' |
| 11661 |
SYNTAX ERROR: Missing right argument |
| 11662 |
0 1 2⌽⍤0 1 'ABC' |
| 11663 |
∧ |
| 11664 |
|
| 11665 |
⍝ Dyalog APL |
| 11666 |
⍝ |
| 11667 |
0 1 2 (⌽⍤0 1) 'ABC' |
| 11668 |
ABC |
| 11669 |
BCA |
| 11670 |
CAB |
| 11671 |
</pre></div> |
| 11672 |
|
| 11673 |
<p>and <b>1 2 3[2]</b> is valid in Dyalog APL, which suggests that Dyalog has not |
| 11674 |
adapted the idea of binding strength but rather remains backward compatible |
| 11675 |
with APL \360. |
| 11676 |
</p> |
| 11677 |
<ul class="section-toc"> |
| 11678 |
<li><a href="#Performance-considerations" accesskey="1">Performance considerations</a></li> |
| 11679 |
</ul> |
| 11680 |
<div class="subsection" id="Performance-considerations"> |
| 11681 |
<h4 class="subsection">5.6.1 Performance considerations</h4> |
| 11682 |
|
| 11683 |
<p>But why bother? The tokenizer could have made its life easier by only |
| 11684 |
converting (number-) strings and quoted strings to APL values and postpone |
| 11685 |
the resolution of shift/reduce conflicts to the execution phase. To understand |
| 11686 |
why it is important to perform as much of the strand building at tokenization |
| 11687 |
time, have a look at the following, somewhat crude, APL code (which is not |
| 11688 |
too uncommon in real life): |
| 11689 |
</p> |
| 11690 |
<div class="example"> |
| 11691 |
<pre class="example"> ∇Z←FOO N |
| 11692 |
Z←100⍴0 ◊ J←1 |
| 11693 |
LOOP: Z[J]←J+1 2 3 4 5 6 7 8 9 10 ÷ →(100 < J←J+1)/LOOP |
| 11694 |
∇ |
| 11695 |
</pre></div> |
| 11696 |
|
| 11697 |
<p>There are smarter ways to do that in APL, but before APL2 an APL programmer |
| 11698 |
could corectly assume that <b>1 2 3 4 5 6 7 8 9 10</b> will be tokenized into |
| 11699 |
a strand created at tokenization time, which would have been more efficient |
| 11700 |
than e.g. storing that term in an APL variable. That strand would have been |
| 11701 |
a single APL value. |
| 11702 |
</p> |
| 11703 |
<p>The tokenization of the LOOP line is pretty fast; the tokenizer runs once |
| 11704 |
over the line and produces a strand as it goes. Most of the tokenization, such |
| 11705 |
as converting number strings to integers is the same in both cases compared |
| 11706 |
below. |
| 11707 |
</p> |
| 11708 |
<p>Now, if the strand is built at tokenization time, then the strand is created |
| 11709 |
once and becomes a single APL value. |
| 11710 |
</p> |
| 11711 |
<p>If, however, the strand is built at execution time, then: |
| 11712 |
</p> |
| 11713 |
<ul> |
| 11714 |
<li> the tokenization produces 10 scalar APL values, |
| 11715 |
</li><li> every iteration of the LOOP line creates 9 more values: |
| 11716 |
<ul> |
| 11717 |
<li> 9 10 |
| 11718 |
</li><li> 8 (9 10) |
| 11719 |
</li><li> 7 (8 (9 10)) |
| 11720 |
</li><li> ... |
| 11721 |
</li></ul> |
| 11722 |
</li><li> and each of the 9 steps in the strand creation requires a pattern |
| 11723 |
match for the pattern <b>VALUE_A VALUE_B</b> |
| 11724 |
</li></ul> |
| 11725 |
|
| 11726 |
<p>The function FOO would therefore create 900 more APL values and perform |
| 11727 |
900 more pattern matches compared to the strand creation at tokenization time. |
| 11728 |
GNU APL has further extended this principle to APL values that may not only |
| 11729 |
contain literals but also a handful of primitives with literal argument. |
| 11730 |
For example, the APL expression: |
| 11731 |
</p> |
| 11732 |
<div class="example"> |
| 11733 |
<pre class="example"> ⍪3 4⍴"Hello" |
| 11734 |
</pre></div> |
| 11735 |
|
| 11736 |
<p>would be tokenized into a single APL value. This kind of optimization |
| 11737 |
can be disabled at compile time. |
| 11738 |
</p> |
| 11739 |
<hr> |
| 11740 |
</div> |
| 11741 |
</div> |
| 11742 |
<div class="section" id="GNU-APL-Vector-Notation"> |
| 11743 |
<div class="header"> |
| 11744 |
<p> |
| 11745 |
Previous: <a href="#Unexpected-Stranding" accesskey="p" rel="prev">Unexpected Stranding</a>, Up: <a href="#Vector-Notation" accesskey="u" rel="up">Vector Notation</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 11746 |
</div> |
| 11747 |
<span id="GNU-APL-Vector-Notation-1"></span><h3 class="section">5.7 GNU APL Vector Notation</h3> |
| 11748 |
|
| 11749 |
<p>With the definitions from the previous section we can explain how GNU APL |
| 11750 |
has implemented vector notation: |
| 11751 |
</p> |
| 11752 |
<p>1. GNU APL distinguishes between literal and mixed strands. Literal strands |
| 11753 |
are combined into a single APL value at tokenization time. This is a |
| 11754 |
very effective optimization (which can be disabled at <b>./configure</b> |
| 11755 |
time). In contrast, mixed strands are created at phrase matching time, i.e. |
| 11756 |
when an APL expression is evaluated. The tokenization of APL expressions |
| 11757 |
happens only once, while phrase matching occurs every time when a |
| 11758 |
statement is being executed and therefore moving major parts of the strand |
| 11759 |
building from phrase matching time to tokenization time can bring |
| 11760 |
substantial performance benefits. |
| 11761 |
</p> |
| 11762 |
<p>2. The tokenization expands simple APL primitives with literal arguments and |
| 11763 |
short results into their literal equivalent. Currently the APL primitives |
| 11764 |
<b>N⍴B</b>, <b>N/B</b>, <b>N⌿B</b>, <b>,B</b>, <b>⍪B</b>, and <b>⊂B</b> are handled this way. |
| 11765 |
</p> |
| 11766 |
<p>3. The tokenization of literal strands has dedicated code for literal |
| 11767 |
arguments of the power (<b>⍣</b>) and rank operators (<b>⍤</b>) to make make |
| 11768 |
it working like described in the ISO standard. This is, in contrast to |
| 11769 |
defined operators, possible because the ISO standard defines in very |
| 11770 |
detail how its right operand needs to look like and how deviations shall |
| 11771 |
be handled (<b>DOMAIN ERROR</b>, <b>LENGTH ERROR</b>) etc. |
| 11772 |
</p> |
| 11773 |
<p>4. The phrase matching of mixed strands builds the strand step-by-step |
| 11774 |
according to the following rules: |
| 11775 |
</p> |
| 11776 |
<ul> |
| 11777 |
<li> two adjacent APL scalars <b>A</b> and <b>B</b> create a new open strand |
| 11778 |
(with two strand items). Each of the two scalars <b>A</b> or <b>B</b> can |
| 11779 |
be simple (like numbers or single characters) or nested (like strings |
| 11780 |
or closed strands). |
| 11781 |
</li><li> An APL scalar <b>A</b> adjacent to an open strand <b>B</b> prepends <b>A</b> |
| 11782 |
to <b>B</b>. That is, <b>B←A, B</b>. |
| 11783 |
</li><li> An open strand <b>A</b> adjacent to an an APL scalar <b>B</b> appends <b>B</b> |
| 11784 |
to <b>A</b>. That is, <b>A←A, B</b>. |
| 11785 |
</li><li> the previous two rules prevent two adjacent open strands, because the |
| 11786 |
strand items of a potential open left strand <b>A</b> are prepended item |
| 11787 |
by item to an open right strand <b>B</b> (which prevents the creation of a |
| 11788 |
new open left strand while an open right strand exists, |
| 11789 |
|
| 11790 |
</li><li> Like the normal APL evaluation, this procedure is preformed from the |
| 11791 |
right to the left. |
| 11792 |
</li><li> if an open strand hits a closing parenthesis then a new phrase matching |
| 11793 |
context is created in which the current procedure is abandoned until |
| 11794 |
the corresponding opening parentheses has been processed. The result |
| 11795 |
of the expression in parentheses is then taken as the next strand item |
| 11796 |
for the abandoned strand (if any). |
| 11797 |
</li><li> Any symbols encountered during this procedure are being resolved into |
| 11798 |
scalars (possibly enclosing them if they are not). Niladic functions are |
| 11799 |
called to obtain their result. |
| 11800 |
</li><li> Likewise, any literal strands that were created at tokenization time |
| 11801 |
are considered closed (which cause them to be enclosed when prepended |
| 11802 |
or appended to an open mixed strand). |
| 11803 |
</li><li> If a strand is open then any other token (functions, operators, |
| 11804 |
brackets, end-of-statement, etc.) closes it. The result is a single |
| 11805 |
value for the strand. |
| 11806 |
</li></ul> |
| 11807 |
|
| 11808 |
<p>5. The operators <b>⍣</b> (power operator) and <b>⍤</b> (rank operator), whose |
| 11809 |
right operand can be identified by the rules given in <b>iso</b>) have |
| 11810 |
dedicated code that "unstrands" the right operand from a strand that |
| 11811 |
may have been mistakenly created in <b>3.</b> above. |
| 11812 |
</p> |
| 11813 |
<ul class="section-toc"> |
| 11814 |
<li><a href="#Example" accesskey="1">Example</a></li> |
| 11815 |
</ul> |
| 11816 |
<div class="subsection" id="Example"> |
| 11817 |
<h4 class="subsection">5.7.1 Example</h4> |
| 11818 |
|
| 11819 |
<p>Consider the following APL statement: |
| 11820 |
</p> |
| 11821 |
<div class="example"> |
| 11822 |
<pre class="example"> ∇FOO |
| 11823 |
"Time is now: " ⎕TS |
| 11824 |
∇ |
| 11825 |
</pre></div> |
| 11826 |
|
| 11827 |
<p>When function <b>FOO</b> is created its single function line is being tokenized. |
| 11828 |
The tokenization of the function line sees the string "Time is now: " which |
| 11829 |
is a literal token with 13 literal items (= single characters). The result of |
| 11830 |
the tokenization is therefore 2 tokens: the string and the system function |
| 11831 |
<b>⎕TS</b>. Naturally <b>⎕TS</b> is the time stamp when function <b>FOO</b> is called |
| 11832 |
and not the time when function <b>FOO</b> is created. Therefore the strand |
| 11833 |
building stops at this point and leaves the string as an (incomplete) strand |
| 11834 |
because the strand building can not predict when <b>FOO</b> will be called. At |
| 11835 |
this point the incomplete strand and the system function <b>⎕TS</b> will become |
| 11836 |
adjacent tokens in the function body of <b>FOO</b>. |
| 11837 |
</p> |
| 11838 |
<p>Later on (or maybe never) <b>FOO</b> will be called. The execution of <b>FOO</b> |
| 11839 |
(which goes from right to left) first sees the niladic token <b>⎕TS</b>, and |
| 11840 |
evaluates it to an integer vector <b>B</b>, say <b>2026 1 1 18 5 6 194</b>. Values |
| 11841 |
returned from functions, values of variables, and the literal strands from |
| 11842 |
the tokenization are all closed and incomplete, and so is <b>B</b> at this point. |
| 11843 |
The execution then fetches the next token <b>A</b>, which is the string. The |
| 11844 |
two adjacent tokens <b>A</b> and <b>B</b> now match the pattern <b>A B</b> in the |
| 11845 |
phrase table of the interpreter. The corresponding phrase evaluator for |
| 11846 |
that pattern then prepends the items in <b>A</b> to <b>B</b> and replaces the |
| 11847 |
two tokens <b>A</b> and <b>B</b> with the new (single) token for the modified <b>B</b>. |
| 11848 |
The next token is then an <b>END</b> (for end of staement) token which causes |
| 11849 |
<b>B</b> to be printed. |
| 11850 |
</p> |
| 11851 |
<p><b>A final remark</b>: It should be noted, that the phrase table defined |
| 11852 |
in <b>iso</b> is somewhat incomplete. In particular the pattern <b>A B</b> |
| 11853 |
above (which performs the strand building in the execution phase) is |
| 11854 |
not present in <b>iso</b>. Also, <b>iso</b> defines <b>END</b> tokens as used |
| 11855 |
above, but no pattern in which they appear. All this has the unfortunate |
| 11856 |
consequence that vector notation is provided by every APL interpreter, |
| 11857 |
but the details of it differ considerably. For example, <b>1 2 3[2]</b> could |
| 11858 |
be <b>2</b> in one interpreter, but raise a <b>RANK ERROR</b> in another. Even |
| 11859 |
for different interpreters of the same vendor. The only reliable way to |
| 11860 |
write portable APL programs is to use (otherwise redundant) parentheses, |
| 11861 |
in particular around operators and their operands, and around strands that |
| 11862 |
are being indexed. |
| 11863 |
</p> |
| 11864 |
|
| 11865 |
<hr> |
| 11866 |
</div> |
| 11867 |
</div> |
| 11868 |
</div> |
| 11869 |
<div class="chapter" id="GNU-APL-Project-Structure"> |
| 11870 |
<div class="header"> |
| 11871 |
<p> |
| 11872 |
Next: <a href="#Libraries-Contributed-by-GNU-APL-Users" accesskey="n" rel="next">Libraries Contributed by GNU APL Users</a>, Previous: <a href="#Vector-Notation" accesskey="p" rel="prev">Vector Notation</a>, Up: <a href="#Top" accesskey="u" rel="up">GNU APL Reference Manual</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 11873 |
</div> |
| 11874 |
<span id="GNU-APL-Project-Structure-1"></span><h2 class="chapter">6 GNU APL Project Structure</h2> |
| 11875 |
|
| 11876 |
<p>The top-level directory of the GNU APL project has a structure like this: |
| 11877 |
</p> |
| 11878 |
<div class="example"> |
| 11879 |
<pre class="example"> apl-2.0/ |
| 11880 |
├── build |
| 11881 |
├── debian |
| 11882 |
├── doc |
| 11883 |
├── erlang |
| 11884 |
├── gnu-apl.d |
| 11885 |
├── HOWTOs |
| 11886 |
├── html |
| 11887 |
├── m4 |
| 11888 |
├── rpm |
| 11889 |
├── src |
| 11890 |
├── support-files |
| 11891 |
├── tools |
| 11892 |
├── websock |
| 11893 |
├── workspaces |
| 11894 |
├── wslib2 |
| 11895 |
├── wslib3 |
| 11896 |
├── wslib4 |
| 11897 |
└── wslib5 |
| 11898 |
</pre></div> |
| 11899 |
|
| 11900 |
<p>Most of these directories are contained in the project tar file |
| 11901 |
(e.g. apl-2.0.tar.gz) and some are created during the build of GNU APL. Only |
| 11902 |
the directories in the top-level are shown above. |
| 11903 |
</p> |
| 11904 |
<p>The GNU APL project follows the standard layout for autoconf/automake projects. |
| 11905 |
The top-level itself contains the files needed by autoconf/automake and a |
| 11906 |
handful of README-XXX files that might be of interest when building GNU APL. |
| 11907 |
</p> |
| 11908 |
<p>The sub-directories are (in order of decreasing relevance): |
| 11909 |
</p> |
| 11910 |
<ul class="section-toc"> |
| 11911 |
<li><a href="#The-sub_002ddirectory-src" accesskey="1">The sub-directory src</a></li> |
| 11912 |
<li><a href="#The-sub_002ddirectory-support_002dfiles" accesskey="2">The sub-directory support-files</a></li> |
| 11913 |
<li><a href="#The-sub_002ddirectory-doc" accesskey="3">The sub-directory doc</a></li> |
| 11914 |
<li><a href="#The-sub_002ddirectory-HOWTOs" accesskey="4">The sub-directory HOWTOs</a></li> |
| 11915 |
<li><a href="#The-sub_002ddirectories-workspaces-and-wslib2-_002e_002e_002e-wslib5" accesskey="5">The sub-directories workspaces and wslib2 ... wslib5</a></li> |
| 11916 |
<li><a href="#The-sub_002ddirectory-m4" accesskey="6">The sub-directory m4</a></li> |
| 11917 |
<li><a href="#The-sub_002ddirectories-debian-and-debian_005ftmp" accesskey="7">The sub-directories debian and debian_tmp</a></li> |
| 11918 |
<li><a href="#The-sub_002ddirectory-tools" accesskey="8">The sub-directory tools</a></li> |
| 11919 |
</ul> |
| 11920 |
<hr> |
| 11921 |
<div class="section" id="The-sub_002ddirectory-src"> |
| 11922 |
<div class="header"> |
| 11923 |
<p> |
| 11924 |
Next: <a href="#The-sub_002ddirectory-support_002dfiles" accesskey="n" rel="next">The sub-directory support-files</a>, Up: <a href="#GNU-APL-Project-Structure" accesskey="u" rel="up">GNU APL Project Structure</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 11925 |
</div> |
| 11926 |
<span id="The-sub_002ddirectory-src-1"></span><h3 class="section">6.1 The sub-directory src</h3> |
| 11927 |
|
| 11928 |
<p>The sub-directory src contains all C++ source files that are needed to build |
| 11929 |
either the GNU APL interpreter itself, or libapl (a library that contains the |
| 11930 |
essential part of GNU APL, but without the interactive REPL loop of the |
| 11931 |
interpreter). During the build, the object files produced by the compiler are |
| 11932 |
also placed in this directory. |
| 11933 |
</p> |
| 11934 |
<p>The sub-directory src contains further sub-directories for components of GNU APL |
| 11935 |
that are optional and typically require the installation of additional |
| 11936 |
libraries on the build machine. The ./configure script in the top-level |
| 11937 |
directory determines, which optional components shall be included in the build. |
| 11938 |
</p> |
| 11939 |
<div class="example"> |
| 11940 |
<pre class="example"> apl-2.0/ |
| 11941 |
├── src |
| 11942 |
├── APs APs for ⎕SVO and friends |
| 11943 |
├── emacs_mode dito |
| 11944 |
├── Gtk ⎕GTK (graphical user interface) |
| 11945 |
├── native templates for native functions |
| 11946 |
├── sql ⎕SQL |
| 11947 |
├── testcases dito |
| 11948 |
</pre></div> |
| 11949 |
|
| 11950 |
<p>GNU APL comes with an automated test suite, the testcases are |
| 11951 |
contained in sub-directory src/testcases |
| 11952 |
</p> |
| 11953 |
<hr> |
| 11954 |
</div> |
| 11955 |
<div class="section" id="The-sub_002ddirectory-support_002dfiles"> |
| 11956 |
<div class="header"> |
| 11957 |
<p> |
| 11958 |
Next: <a href="#The-sub_002ddirectory-doc" accesskey="n" rel="next">The sub-directory doc</a>, Previous: <a href="#The-sub_002ddirectory-src" accesskey="p" rel="prev">The sub-directory src</a>, Up: <a href="#GNU-APL-Project-Structure" accesskey="u" rel="up">GNU APL Project Structure</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 11959 |
</div> |
| 11960 |
<span id="The-sub_002ddirectory-support_002dfiles-1"></span><h3 class="section">6.2 The sub-directory support-files</h3> |
| 11961 |
|
| 11962 |
<p>The sub-directory support-file contains a number of configuration files that aim |
| 11963 |
at making a standard keyboard produce APL characters. Details are explained in |
| 11964 |
top-level file README-3-keyboard. |
| 11965 |
</p> |
| 11966 |
<hr> |
| 11967 |
</div> |
| 11968 |
<div class="section" id="The-sub_002ddirectory-doc"> |
| 11969 |
<div class="header"> |
| 11970 |
<p> |
| 11971 |
Next: <a href="#The-sub_002ddirectory-HOWTOs" accesskey="n" rel="next">The sub-directory HOWTOs</a>, Previous: <a href="#The-sub_002ddirectory-support_002dfiles" accesskey="p" rel="prev">The sub-directory support-files</a>, Up: <a href="#GNU-APL-Project-Structure" accesskey="u" rel="up">GNU APL Project Structure</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 11972 |
</div> |
| 11973 |
<span id="The-sub_002ddirectory-doc-1"></span><h3 class="section">6.3 The sub-directory doc</h3> |
| 11974 |
|
| 11975 |
<p>The sub-directory doc is used to create <b>this</b> info file in different file |
| 11976 |
formats (.info, .html). |
| 11977 |
</p> |
| 11978 |
<hr> |
| 11979 |
</div> |
| 11980 |
<div class="section" id="The-sub_002ddirectory-HOWTOs"> |
| 11981 |
<div class="header"> |
| 11982 |
<p> |
| 11983 |
Next: <a href="#The-sub_002ddirectories-workspaces-and-wslib2-_002e_002e_002e-wslib5" accesskey="n" rel="next">The sub-directories workspaces and wslib2 ... wslib5</a>, Previous: <a href="#The-sub_002ddirectory-doc" accesskey="p" rel="prev">The sub-directory doc</a>, Up: <a href="#GNU-APL-Project-Structure" accesskey="u" rel="up">GNU APL Project Structure</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 11984 |
</div> |
| 11985 |
<span id="The-sub_002ddirectory-HOWTOs-1"></span><h3 class="section">6.4 The sub-directory HOWTOs</h3> |
| 11986 |
|
| 11987 |
<p>The sub-directory HOWTOs contains some documents that try to explain how some |
| 11988 |
of the non-standard features of GNU APL are intended to be used. These |
| 11989 |
documents were written for two different audiences: APL programmers and |
| 11990 |
GNU APL hackers. The documents for APL programmers are, by default, installed |
| 11991 |
in directory /usr/local/share/doc/apl by <b>make install</b> while the documents |
| 11992 |
for GNU APL hackers (i.e. C++ programmers or trouble-shooters) are not |
| 11993 |
installed by <b>make install</b>, but rather remain in the source tree. |
| 11994 |
</p> |
| 11995 |
<hr> |
| 11996 |
</div> |
| 11997 |
<div class="section" id="The-sub_002ddirectories-workspaces-and-wslib2-_002e_002e_002e-wslib5"> |
| 11998 |
<div class="header"> |
| 11999 |
<p> |
| 12000 |
Next: <a href="#The-sub_002ddirectory-m4" accesskey="n" rel="next">The sub-directory m4</a>, Previous: <a href="#The-sub_002ddirectory-HOWTOs" accesskey="p" rel="prev">The sub-directory HOWTOs</a>, Up: <a href="#GNU-APL-Project-Structure" accesskey="u" rel="up">GNU APL Project Structure</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 12001 |
</div> |
| 12002 |
<span id="The-sub_002ddirectories-workspaces-and-wslib2-_002e_002e_002e-wslib5-1"></span><h3 class="section">6.5 The sub-directories workspaces and wslib2 ... wslib5</h3> |
| 12003 |
|
| 12004 |
<p>These directories (and their content) are, by default, copied to |
| 12005 |
/usr/local/lib/apl by <b>make install</b>. Some sub-directories are empty while |
| 12006 |
others contain small workspaces or libraries for various purposes (mostly |
| 12007 |
demonstrating the use of some non-standard APL features). |
| 12008 |
</p> |
| 12009 |
<hr> |
| 12010 |
</div> |
| 12011 |
<div class="section" id="The-sub_002ddirectory-m4"> |
| 12012 |
<div class="header"> |
| 12013 |
<p> |
| 12014 |
Next: <a href="#The-sub_002ddirectories-debian-and-debian_005ftmp" accesskey="n" rel="next">The sub-directories debian and debian_tmp</a>, Previous: <a href="#The-sub_002ddirectories-workspaces-and-wslib2-_002e_002e_002e-wslib5" accesskey="p" rel="prev">The sub-directories workspaces and wslib2 ... wslib5</a>, Up: <a href="#GNU-APL-Project-Structure" accesskey="u" rel="up">GNU APL Project Structure</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 12015 |
</div> |
| 12016 |
<span id="The-sub_002ddirectory-m4-1"></span><h3 class="section">6.6 The sub-directory m4</h3> |
| 12017 |
|
| 12018 |
<p>The sub-directory m4 contains macros used by autoconf and automake. In most |
| 12019 |
cases the top-level ./configure script can be used as is. If a platform on |
| 12020 |
which GNU APL shall be built differs too much from the platform on which the |
| 12021 |
GNU APL project tar file (e.g. apl-2.0.tar.gz) was created, then it might |
| 12022 |
be necessary to re-create the ./configure script on the platform. |
| 12023 |
</p> |
| 12024 |
<p>Re-creating the ./configure script requires: |
| 12025 |
</p> |
| 12026 |
<ul> |
| 12027 |
<li> the installation of autoconf, |
| 12028 |
</li><li> the installation of automake, |
| 12029 |
</li><li> the installation of libtool, |
| 12030 |
</li><li> maybe running aclocal, libtoolize, and other scripts, and finally |
| 12031 |
</li><li> running autoreconf |
| 12032 |
</li></ul> |
| 12033 |
|
| 12034 |
<hr> |
| 12035 |
</div> |
| 12036 |
<div class="section" id="The-sub_002ddirectories-debian-and-debian_005ftmp"> |
| 12037 |
<div class="header"> |
| 12038 |
<p> |
| 12039 |
Next: <a href="#The-sub_002ddirectory-tools" accesskey="n" rel="next">The sub-directory tools</a>, Previous: <a href="#The-sub_002ddirectory-m4" accesskey="p" rel="prev">The sub-directory m4</a>, Up: <a href="#GNU-APL-Project-Structure" accesskey="u" rel="up">GNU APL Project Structure</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 12040 |
</div> |
| 12041 |
<span id="The-sub_002ddirectories-debian-and-debian_005ftmp-1"></span><h3 class="section">6.7 The sub-directories debian and debian_tmp</h3> |
| 12042 |
|
| 12043 |
<p>These sub-directories are templates for building Debian |
| 12044 |
packages that contain GNU APL. Sub-directory debian_tmp is initially empty and |
| 12045 |
acts as a scratch directory inside which the interpreter is being compiled |
| 12046 |
when a Debian package is built. |
| 12047 |
</p> |
| 12048 |
<hr> |
| 12049 |
</div> |
| 12050 |
<div class="section" id="The-sub_002ddirectory-tools"> |
| 12051 |
<div class="header"> |
| 12052 |
<p> |
| 12053 |
Previous: <a href="#The-sub_002ddirectories-debian-and-debian_005ftmp" accesskey="p" rel="prev">The sub-directories debian and debian_tmp</a>, Up: <a href="#GNU-APL-Project-Structure" accesskey="u" rel="up">GNU APL Project Structure</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 12054 |
</div> |
| 12055 |
<span id="The-sub_002ddirectory-tools-1"></span><h3 class="section">6.8 The sub-directory tools</h3> |
| 12056 |
|
| 12057 |
<p>GNU APL uses generated C++ code. The sub-directory tools contains the source |
| 12058 |
code for the code generator (phrase_gen) and also some other small tools for |
| 12059 |
various purposes. These tools are typically used by GNU APL hackers and are |
| 12060 |
therefore not installed by <b>make install</b>. |
| 12061 |
</p> |
| 12062 |
<hr> |
| 12063 |
</div> |
| 12064 |
</div> |
| 12065 |
<div class="chapter" id="Libraries-Contributed-by-GNU-APL-Users"> |
| 12066 |
<div class="header"> |
| 12067 |
<p> |
| 12068 |
Next: <a href="#Licenses-for-this-GNU-APL-Manual-and-for-GNU-APL" accesskey="n" rel="next">Licenses for this GNU APL Manual and for GNU APL</a>, Previous: <a href="#GNU-APL-Project-Structure" accesskey="p" rel="prev">GNU APL Project Structure</a>, Up: <a href="#Top" accesskey="u" rel="up">GNU APL Reference Manual</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 12069 |
</div> |
| 12070 |
<span id="Libraries-Contributed-by-GNU-APL-Users-1"></span><h2 class="chapter">7 Libraries Contributed by GNU APL Users</h2> |
| 12071 |
|
| 12072 |
<p>Since the first release of GNU APL, a number of libraries, but also other |
| 12073 |
developments, have been made by users of GNU APL. Below are links to these |
| 12074 |
contributions. |
| 12075 |
</p> |
| 12076 |
<ul class="section-toc"> |
| 12077 |
<li><a href="#The-GNU-APL-Community-Webpage" accesskey="1">The GNU APL Community Webpage</a></li> |
| 12078 |
<li><a href="#Core-Libraries" accesskey="2">Core Libraries</a></li> |
| 12079 |
</ul> |
| 12080 |
<hr> |
| 12081 |
<div class="section" id="The-GNU-APL-Community-Webpage"> |
| 12082 |
<div class="header"> |
| 12083 |
<p> |
| 12084 |
Next: <a href="#Core-Libraries" accesskey="n" rel="next">Core Libraries</a>, Up: <a href="#Libraries-Contributed-by-GNU-APL-Users" accesskey="u" rel="up">Libraries Contributed by GNU APL Users</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 12085 |
</div> |
| 12086 |
<span id="The-GNU-APL-Community-Webpage-1"></span><h3 class="section">7.1 The GNU APL Community Webpage</h3> |
| 12087 |
|
| 12088 |
<p>The GNU APL project maintains a web page that lists contributions made by |
| 12089 |
GNU APL users: |
| 12090 |
</p> |
| 12091 |
<p><a href="http://www.gnu.org/software/apl/Community.html">http://www.gnu.org/software/apl/Community.html</a> |
| 12092 |
</p> |
| 12093 |
<p>The contributions listed there were collected from emails sent to |
| 12094 |
[email protected] |
| 12095 |
</p> |
| 12096 |
<p>Since the list was started long after [email protected] was created. It is |
| 12097 |
therefore quite possible that your contribution is missing. That does not |
| 12098 |
mean that your contribution was not considered worthwhile to be listed but |
| 12099 |
more likely that it was overlooked. Just send an email to [email protected] |
| 12100 |
to fix that. |
| 12101 |
</p> |
| 12102 |
<hr> |
| 12103 |
</div> |
| 12104 |
<div class="section" id="Core-Libraries"> |
| 12105 |
<div class="header"> |
| 12106 |
<p> |
| 12107 |
Previous: <a href="#The-GNU-APL-Community-Webpage" accesskey="p" rel="prev">The GNU APL Community Webpage</a>, Up: <a href="#Libraries-Contributed-by-GNU-APL-Users" accesskey="u" rel="up">Libraries Contributed by GNU APL Users</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 12108 |
</div> |
| 12109 |
<span id="Core-Libraries-1"></span><h3 class="section">7.2 Core Libraries</h3> |
| 12110 |
|
| 12111 |
<p>There is a small number of libraries that are considered "core" APL because, |
| 12112 |
for example, the ISO standard requires their functionality, or because other |
| 12113 |
APL interpreters normally support them. |
| 12114 |
</p> |
| 12115 |
<p>These libraries are linked via the GNU APL Community web page. In addition |
| 12116 |
they are stored in the GNU APL SVN repository and also included in the |
| 12117 |
GNU APL packages that follows their contribution. |
| 12118 |
</p> |
| 12119 |
<p>Currently the following core libraries exist: |
| 12120 |
</p> |
| 12121 |
<p>GNU APL Emacs mode (for Emacs users) by Elias Mårtenson |
| 12122 |
</p> |
| 12123 |
<p>SQL interface (SQLite and Postgres) by Elias Mårtenson |
| 12124 |
</p> |
| 12125 |
<p>Component File System (as required by ISO 13751) by David B. Lamkins |
| 12126 |
</p> |
| 12127 |
<p>Component File System (as required by ISO 13751) by Blake McBride |
| 12128 |
</p> |
| 12129 |
<p>SQL |
| 12130 |
</p> |
| 12131 |
<hr> |
| 12132 |
</div> |
| 12133 |
</div> |
| 12134 |
<div class="chapter" id="Licenses-for-this-GNU-APL-Manual-and-for-GNU-APL"> |
| 12135 |
<div class="header"> |
| 12136 |
<p> |
| 12137 |
Previous: <a href="#Libraries-Contributed-by-GNU-APL-Users" accesskey="p" rel="prev">Libraries Contributed by GNU APL Users</a>, Up: <a href="#Top" accesskey="u" rel="up">GNU APL Reference Manual</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 12138 |
</div> |
| 12139 |
<span id="Licenses-for-this-GNU-APL-Manual-and-for-GNU-APL-1"></span><h2 class="chapter">8 Licenses for this GNU APL Manual and for GNU APL</h2> |
| 12140 |
|
| 12141 |
<p>This manual for GNU APL is licensed under the GNU Free Documentation |
| 12142 |
License, *Note Section 8.1:: below. |
| 12143 |
</p> |
| 12144 |
<p>GNU APL itself is licensed under the GNU Public License version 3 or later |
| 12145 |
(aka GPLv3+), *Note Section 8.2:: below. |
| 12146 |
</p> |
| 12147 |
<ul class="section-toc"> |
| 12148 |
<li><a href="#The-GNU-Free-Documentation-License" accesskey="1">The GNU Free Documentation License</a></li> |
| 12149 |
<li><a href="#The-GNU-GENERAL-PUBLIC-LICENSE" accesskey="2">The GNU GENERAL PUBLIC LICENSE</a></li> |
| 12150 |
</ul> |
| 12151 |
<hr> |
| 12152 |
<div class="section" id="The-GNU-Free-Documentation-License"> |
| 12153 |
<div class="header"> |
| 12154 |
<p> |
| 12155 |
Next: <a href="#The-GNU-GENERAL-PUBLIC-LICENSE" accesskey="n" rel="next">The GNU GENERAL PUBLIC LICENSE</a>, Up: <a href="#Licenses-for-this-GNU-APL-Manual-and-for-GNU-APL" accesskey="u" rel="up">Licenses for this GNU APL Manual and for GNU APL</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 12156 |
</div> |
| 12157 |
<span id="The-GNU-Free-Documentation-License-1"></span><h3 class="section">8.1 The GNU Free Documentation License</h3> |
| 12158 |
|
| 12159 |
<div align="center">Version 1.3, 3 November 2008 |
| 12160 |
</div> |
| 12161 |
<div class="display"> |
| 12162 |
<pre class="display">Copyright © 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc. |
| 12163 |
<a href="http://fsf.org/">http://fsf.org/</a> |
| 12164 |
|
| 12165 |
Everyone is permitted to copy and distribute verbatim copies |
| 12166 |
of this license document, but changing it is not allowed. |
| 12167 |
</pre></div> |
| 12168 |
|
| 12169 |
<ol start="0"> |
| 12170 |
<li> PREAMBLE |
| 12171 |
|
| 12172 |
<p>The purpose of this License is to make a manual, textbook, or other |
| 12173 |
functional and useful document <em>free</em> in the sense of freedom: to |
| 12174 |
assure everyone the effective freedom to copy and redistribute it, |
| 12175 |
with or without modifying it, either commercially or non-commercially. |
| 12176 |
Secondarily, this License preserves for the author and publisher a way |
| 12177 |
to get credit for their work, while not being considered responsible |
| 12178 |
for modifications made by others. |
| 12179 |
</p> |
| 12180 |
<p>This License is a kind of “copyleft”, which means that derivative |
| 12181 |
works of the document must themselves be free in the same sense. It |
| 12182 |
complements the GNU General Public License, which is a copyleft |
| 12183 |
license designed for free software. |
| 12184 |
</p> |
| 12185 |
<p>We have designed this License in order to use it for manuals for free |
| 12186 |
software, because free software needs free documentation: a free |
| 12187 |
program should come with manuals providing the same freedoms that the |
| 12188 |
software does. But this License is not limited to software manuals; |
| 12189 |
it can be used for any textual work, regardless of subject matter or |
| 12190 |
whether it is published as a printed book. We recommend this License |
| 12191 |
principally for works whose purpose is instruction or reference. |
| 12192 |
</p> |
| 12193 |
</li><li> APPLICABILITY AND DEFINITIONS |
| 12194 |
|
| 12195 |
<p>This License applies to any manual or other work, in any medium, that |
| 12196 |
contains a notice placed by the copyright holder saying it can be |
| 12197 |
distributed under the terms of this License. Such a notice grants a |
| 12198 |
world-wide, royalty-free license, unlimited in duration, to use that |
| 12199 |
work under the conditions stated herein. The “Document”, below, |
| 12200 |
refers to any such manual or work. Any member of the public is a |
| 12201 |
licensee, and is addressed as “you”. You accept the license if you |
| 12202 |
copy, modify or distribute the work in a way requiring permission |
| 12203 |
under copyright law. |
| 12204 |
</p> |
| 12205 |
<p>A “Modified Version” of the Document means any work containing the |
| 12206 |
Document or a portion of it, either copied verbatim, or with |
| 12207 |
modifications and/or translated into another language. |
| 12208 |
</p> |
| 12209 |
<p>A “Secondary Section” is a named appendix or a front-matter section |
| 12210 |
of the Document that deals exclusively with the relationship of the |
| 12211 |
publishers or authors of the Document to the Document’s overall |
| 12212 |
subject (or to related matters) and contains nothing that could fall |
| 12213 |
directly within that overall subject. (Thus, if the Document is in |
| 12214 |
part a textbook of mathematics, a Secondary Section may not explain |
| 12215 |
any mathematics.) The relationship could be a matter of historical |
| 12216 |
connection with the subject or with related matters, or of legal, |
| 12217 |
commercial, philosophical, ethical or political position regarding |
| 12218 |
them. |
| 12219 |
</p> |
| 12220 |
<p>The “Invariant Sections” are certain Secondary Sections whose titles |
| 12221 |
are designated, as being those of Invariant Sections, in the notice |
| 12222 |
that says that the Document is released under this License. If a |
| 12223 |
section does not fit the above definition of Secondary then it is not |
| 12224 |
allowed to be designated as Invariant. The Document may contain zero |
| 12225 |
Invariant Sections. If the Document does not identify any Invariant |
| 12226 |
Sections then there are none. |
| 12227 |
</p> |
| 12228 |
<p>The “Cover Texts” are certain short passages of text that are listed, |
| 12229 |
as Front-Cover Texts or Back-Cover Texts, in the notice that says that |
| 12230 |
the Document is released under this License. A Front-Cover Text may |
| 12231 |
be at most 5 words, and a Back-Cover Text may be at most 25 words. |
| 12232 |
</p> |
| 12233 |
<p>A “Transparent” copy of the Document means a machine-readable copy, |
| 12234 |
represented in a format whose specification is available to the |
| 12235 |
general public, that is suitable for revising the document |
| 12236 |
straightforwardly with generic text editors or (for images composed of |
| 12237 |
pixels) generic paint programs or (for drawings) some widely available |
| 12238 |
drawing editor, and that is suitable for input to text formatters or |
| 12239 |
for automatic translation to a variety of formats suitable for input |
| 12240 |
to text formatters. A copy made in an otherwise Transparent file |
| 12241 |
format whose markup, or absence of markup, has been arranged to thwart |
| 12242 |
or discourage subsequent modification by readers is not Transparent. |
| 12243 |
An image format is not Transparent if used for any substantial amount |
| 12244 |
of text. A copy that is not “Transparent” is called “Opaque”. |
| 12245 |
</p> |
| 12246 |
<p>Examples of suitable formats for Transparent copies include plain |
| 12247 |
ASCII without markup, Texinfo input format, LaTeX input |
| 12248 |
format, SGML or XML using a publicly available |
| 12249 |
DTD, and standard-conforming simple HTML, |
| 12250 |
PostScript or PDF designed for human modification. Examples |
| 12251 |
of transparent image formats include PNG, XCF and |
| 12252 |
JPG. Opaque formats include proprietary formats that can be |
| 12253 |
read and edited only by proprietary word processors, SGML or |
| 12254 |
XML for which the DTD and/or processing tools are |
| 12255 |
not generally available, and the machine-generated HTML, |
| 12256 |
PostScript or PDF produced by some word processors for |
| 12257 |
output purposes only. |
| 12258 |
</p> |
| 12259 |
<p>The “Title Page” means, for a printed book, the title page itself, |
| 12260 |
plus such following pages as are needed to hold, legibly, the material |
| 12261 |
this License requires to appear in the title page. For works in |
| 12262 |
formats which do not have any title page as such, “Title Page” means |
| 12263 |
the text near the most prominent appearance of the work’s title, |
| 12264 |
preceding the beginning of the body of the text. |
| 12265 |
</p> |
| 12266 |
<p>The “publisher” means any person or entity that distributes copies |
| 12267 |
of the Document to the public. |
| 12268 |
</p> |
| 12269 |
<p>A section “Entitled XYZ” means a named subunit of the Document whose |
| 12270 |
title either is precisely XYZ or contains XYZ in parentheses following |
| 12271 |
text that translates XYZ in another language. (Here XYZ stands for a |
| 12272 |
specific section name mentioned below, such as “Acknowledgements”, |
| 12273 |
“Dedications”, “Endorsements”, or “History”.) To “Preserve the Title” |
| 12274 |
of such a section when you modify the Document means that it remains a |
| 12275 |
section “Entitled XYZ” according to this definition. |
| 12276 |
</p> |
| 12277 |
<p>The Document may include Warranty Disclaimers next to the notice which |
| 12278 |
states that this License applies to the Document. These Warranty |
| 12279 |
Disclaimers are considered to be included by reference in this |
| 12280 |
License, but only as regards disclaiming warranties: any other |
| 12281 |
implication that these Warranty Disclaimers may have is void and has |
| 12282 |
no effect on the meaning of this License. |
| 12283 |
</p> |
| 12284 |
</li><li> VERBATIM COPYING |
| 12285 |
|
| 12286 |
<p>You may copy and distribute the Document in any medium, either |
| 12287 |
commercially or noncommercially, provided that this License, the |
| 12288 |
copyright notices, and the license notice saying this License applies |
| 12289 |
to the Document are reproduced in all copies, and that you add no other |
| 12290 |
conditions whatsoever to those of this License. You may not use |
| 12291 |
technical measures to obstruct or control the reading or further |
| 12292 |
copying of the copies you make or distribute. However, you may accept |
| 12293 |
compensation in exchange for copies. If you distribute a large enough |
| 12294 |
number of copies you must also follow the conditions in section 3. |
| 12295 |
</p> |
| 12296 |
<p>You may also lend copies, under the same conditions stated above, and |
| 12297 |
you may publicly display copies. |
| 12298 |
</p> |
| 12299 |
</li><li> COPYING IN QUANTITY |
| 12300 |
|
| 12301 |
<p>If you publish printed copies (or copies in media that commonly have |
| 12302 |
printed covers) of the Document, numbering more than 100, and the |
| 12303 |
Document’s license notice requires Cover Texts, you must enclose the |
| 12304 |
copies in covers that carry, clearly and legibly, all these Cover |
| 12305 |
Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on |
| 12306 |
the back cover. Both covers must also clearly and legibly identify |
| 12307 |
you as the publisher of these copies. The front cover must present |
| 12308 |
the full title with all words of the title equally prominent and |
| 12309 |
visible. You may add other material on the covers in addition. |
| 12310 |
Copying with changes limited to the covers, as long as they preserve |
| 12311 |
the title of the Document and satisfy these conditions, can be treated |
| 12312 |
as verbatim copying in other respects. |
| 12313 |
</p> |
| 12314 |
<p>If the required texts for either cover are too voluminous to fit |
| 12315 |
legibly, you should put the first ones listed (as many as fit |
| 12316 |
reasonably) on the actual cover, and continue the rest onto adjacent |
| 12317 |
pages. |
| 12318 |
</p> |
| 12319 |
<p>If you publish or distribute Opaque copies of the Document numbering |
| 12320 |
more than 100, you must either include a machine-readable Transparent |
| 12321 |
copy along with each Opaque copy, or state in or with each Opaque copy |
| 12322 |
a computer-network location from which the general network-using |
| 12323 |
public has access to download using public-standard network protocols |
| 12324 |
a complete Transparent copy of the Document, free of added material. |
| 12325 |
If you use the latter option, you must take reasonably prudent steps, |
| 12326 |
when you begin distribution of Opaque copies in quantity, to ensure |
| 12327 |
that this Transparent copy will remain thus accessible at the stated |
| 12328 |
location until at least one year after the last time you distribute an |
| 12329 |
Opaque copy (directly or through your agents or retailers) of that |
| 12330 |
edition to the public. |
| 12331 |
</p> |
| 12332 |
<p>It is requested, but not required, that you contact the authors of the |
| 12333 |
Document well before redistributing any large number of copies, to give |
| 12334 |
them a chance to provide you with an updated version of the Document. |
| 12335 |
</p> |
| 12336 |
</li><li> MODIFICATIONS |
| 12337 |
|
| 12338 |
<p>You may copy and distribute a Modified Version of the Document under |
| 12339 |
the conditions of sections 2 and 3 above, provided that you release |
| 12340 |
the Modified Version under precisely this License, with the Modified |
| 12341 |
Version filling the role of the Document, thus licensing distribution |
| 12342 |
and modification of the Modified Version to whoever possesses a copy |
| 12343 |
of it. In addition, you must do these things in the Modified Version: |
| 12344 |
</p> |
| 12345 |
<ol type="A" start="1"> |
| 12346 |
<li> Use in the Title Page (and on the covers, if any) a title distinct |
| 12347 |
from that of the Document, and from those of previous versions |
| 12348 |
(which should, if there were any, be listed in the History section |
| 12349 |
of the Document). You may use the same title as a previous version |
| 12350 |
if the original publisher of that version gives permission. |
| 12351 |
|
| 12352 |
</li><li> List on the Title Page, as authors, one or more persons or entities |
| 12353 |
responsible for authorship of the modifications in the Modified |
| 12354 |
Version, together with at least five of the principal authors of the |
| 12355 |
Document (all of its principal authors, if it has fewer than five), |
| 12356 |
unless they release you from this requirement. |
| 12357 |
|
| 12358 |
</li><li> State on the Title page the name of the publisher of the |
| 12359 |
Modified Version, as the publisher. |
| 12360 |
|
| 12361 |
</li><li> Preserve all the copyright notices of the Document. |
| 12362 |
|
| 12363 |
</li><li> Add an appropriate copyright notice for your modifications |
| 12364 |
adjacent to the other copyright notices. |
| 12365 |
|
| 12366 |
</li><li> Include, immediately after the copyright notices, a license notice |
| 12367 |
giving the public permission to use the Modified Version under the |
| 12368 |
terms of this License, in the form shown in the Addendum below. |
| 12369 |
|
| 12370 |
</li><li> Preserve in that license notice the full lists of Invariant Sections |
| 12371 |
and required Cover Texts given in the Document’s license notice. |
| 12372 |
|
| 12373 |
</li><li> Include an unaltered copy of this License. |
| 12374 |
|
| 12375 |
</li><li> Preserve the section Entitled “History”, Preserve its Title, and add |
| 12376 |
to it an item stating at least the title, year, new authors, and |
| 12377 |
publisher of the Modified Version as given on the Title Page. If |
| 12378 |
there is no section Entitled “History” in the Document, create one |
| 12379 |
stating the title, year, authors, and publisher of the Document as |
| 12380 |
given on its Title Page, then add an item describing the Modified |
| 12381 |
Version as stated in the previous sentence. |
| 12382 |
|
| 12383 |
</li><li> Preserve the network location, if any, given in the Document for |
| 12384 |
public access to a Transparent copy of the Document, and likewise |
| 12385 |
the network locations given in the Document for previous versions |
| 12386 |
it was based on. These may be placed in the “History” section. |
| 12387 |
You may omit a network location for a work that was published at |
| 12388 |
least four years before the Document itself, or if the original |
| 12389 |
publisher of the version it refers to gives permission. |
| 12390 |
|
| 12391 |
</li><li> For any section Entitled “Acknowledgements” or “Dedications”, Preserve |
| 12392 |
the Title of the section, and preserve in the section all the |
| 12393 |
substance and tone of each of the contributor acknowledgements and/or |
| 12394 |
dedications given therein. |
| 12395 |
|
| 12396 |
</li><li> Preserve all the Invariant Sections of the Document, |
| 12397 |
unaltered in their text and in their titles. Section numbers |
| 12398 |
or the equivalent are not considered part of the section titles. |
| 12399 |
|
| 12400 |
</li><li> Delete any section Entitled “Endorsements”. Such a section |
| 12401 |
may not be included in the Modified Version. |
| 12402 |
|
| 12403 |
</li><li> Do not retitle any existing section to be Entitled “Endorsements” or |
| 12404 |
to conflict in title with any Invariant Section. |
| 12405 |
|
| 12406 |
</li><li> Preserve any Warranty Disclaimers. |
| 12407 |
</li></ol> |
| 12408 |
|
| 12409 |
<p>If the Modified Version includes new front-matter sections or |
| 12410 |
appendices that qualify as Secondary Sections and contain no material |
| 12411 |
copied from the Document, you may at your option designate some or all |
| 12412 |
of these sections as invariant. To do this, add their titles to the |
| 12413 |
list of Invariant Sections in the Modified Version’s license notice. |
| 12414 |
These titles must be distinct from any other section titles. |
| 12415 |
</p> |
| 12416 |
<p>You may add a section Entitled “Endorsements”, provided it contains |
| 12417 |
nothing but endorsements of your Modified Version by various |
| 12418 |
parties—for example, statements of peer review or that the text has |
| 12419 |
been approved by an organization as the authoritative definition of a |
| 12420 |
standard. |
| 12421 |
</p> |
| 12422 |
<p>You may add a passage of up to five words as a Front-Cover Text, and a |
| 12423 |
passage of up to 25 words as a Back-Cover Text, to the end of the list |
| 12424 |
of Cover Texts in the Modified Version. Only one passage of |
| 12425 |
Front-Cover Text and one of Back-Cover Text may be added by (or |
| 12426 |
through arrangements made by) any one entity. If the Document already |
| 12427 |
includes a cover text for the same cover, previously added by you or |
| 12428 |
by arrangement made by the same entity you are acting on behalf of, |
| 12429 |
you may not add another; but you may replace the old one, on explicit |
| 12430 |
permission from the previous publisher that added the old one. |
| 12431 |
</p> |
| 12432 |
<p>The author(s) and publisher(s) of the Document do not by this License |
| 12433 |
give permission to use their names for publicity for or to assert or |
| 12434 |
imply endorsement of any Modified Version. |
| 12435 |
</p> |
| 12436 |
</li><li> COMBINING DOCUMENTS |
| 12437 |
|
| 12438 |
<p>You may combine the Document with other documents released under this |
| 12439 |
License, under the terms defined in section 4 above for modified |
| 12440 |
versions, provided that you include in the combination all of the |
| 12441 |
Invariant Sections of all of the original documents, unmodified, and |
| 12442 |
list them all as Invariant Sections of your combined work in its |
| 12443 |
license notice, and that you preserve all their Warranty Disclaimers. |
| 12444 |
</p> |
| 12445 |
<p>The combined work need only contain one copy of this License, and |
| 12446 |
multiple identical Invariant Sections may be replaced with a single |
| 12447 |
copy. If there are multiple Invariant Sections with the same name but |
| 12448 |
different contents, make the title of each such section unique by |
| 12449 |
adding at the end of it, in parentheses, the name of the original |
| 12450 |
author or publisher of that section if known, or else a unique number. |
| 12451 |
Make the same adjustment to the section titles in the list of |
| 12452 |
Invariant Sections in the license notice of the combined work. |
| 12453 |
</p> |
| 12454 |
<p>In the combination, you must combine any sections Entitled “History” |
| 12455 |
in the various original documents, forming one section Entitled |
| 12456 |
“History”; likewise combine any sections Entitled “Acknowledgements”, |
| 12457 |
and any sections Entitled “Dedications”. You must delete all |
| 12458 |
sections Entitled “Endorsements.” |
| 12459 |
</p> |
| 12460 |
</li><li> COLLECTIONS OF DOCUMENTS |
| 12461 |
|
| 12462 |
<p>You may make a collection consisting of the Document and other documents |
| 12463 |
released under this License, and replace the individual copies of this |
| 12464 |
License in the various documents with a single copy that is included in |
| 12465 |
the collection, provided that you follow the rules of this License for |
| 12466 |
verbatim copying of each of the documents in all other respects. |
| 12467 |
</p> |
| 12468 |
<p>You may extract a single document from such a collection, and distribute |
| 12469 |
it individually under this License, provided you insert a copy of this |
| 12470 |
License into the extracted document, and follow this License in all |
| 12471 |
other respects regarding verbatim copying of that document. |
| 12472 |
</p> |
| 12473 |
</li><li> AGGREGATION WITH INDEPENDENT WORKS |
| 12474 |
|
| 12475 |
<p>A compilation of the Document or its derivatives with other separate |
| 12476 |
and independent documents or works, in or on a volume of a storage or |
| 12477 |
distribution medium, is called an “aggregate” if the copyright |
| 12478 |
resulting from the compilation is not used to limit the legal rights |
| 12479 |
of the compilation’s users beyond what the individual works permit. |
| 12480 |
When the Document is included in an aggregate, this License does not |
| 12481 |
apply to the other works in the aggregate which are not themselves |
| 12482 |
derivative works of the Document. |
| 12483 |
</p> |
| 12484 |
<p>If the Cover Text requirement of section 3 is applicable to these |
| 12485 |
copies of the Document, then if the Document is less than one half of |
| 12486 |
the entire aggregate, the Document’s Cover Texts may be placed on |
| 12487 |
covers that bracket the Document within the aggregate, or the |
| 12488 |
electronic equivalent of covers if the Document is in electronic form. |
| 12489 |
Otherwise they must appear on printed covers that bracket the whole |
| 12490 |
aggregate. |
| 12491 |
</p> |
| 12492 |
</li><li> TRANSLATION |
| 12493 |
|
| 12494 |
<p>Translation is considered a kind of modification, so you may |
| 12495 |
distribute translations of the Document under the terms of section 4. |
| 12496 |
Replacing Invariant Sections with translations requires special |
| 12497 |
permission from their copyright holders, but you may include |
| 12498 |
translations of some or all Invariant Sections in addition to the |
| 12499 |
original versions of these Invariant Sections. You may include a |
| 12500 |
translation of this License, and all the license notices in the |
| 12501 |
Document, and any Warranty Disclaimers, provided that you also include |
| 12502 |
the original English version of this License and the original versions |
| 12503 |
of those notices and disclaimers. In case of a disagreement between |
| 12504 |
the translation and the original version of this License or a notice |
| 12505 |
or disclaimer, the original version will prevail. |
| 12506 |
</p> |
| 12507 |
<p>If a section in the Document is Entitled “Acknowledgements”, |
| 12508 |
“Dedications”, or “History”, the requirement (section 4) to Preserve |
| 12509 |
its Title (section 1) will typically require changing the actual |
| 12510 |
title. |
| 12511 |
</p> |
| 12512 |
</li><li> TERMINATION |
| 12513 |
|
| 12514 |
<p>You may not copy, modify, sublicense, or distribute the Document |
| 12515 |
except as expressly provided under this License. Any attempt |
| 12516 |
otherwise to copy, modify, sublicense, or distribute it is void, and |
| 12517 |
will automatically terminate your rights under this License. |
| 12518 |
</p> |
| 12519 |
<p>However, if you cease all violation of this License, then your license |
| 12520 |
from a particular copyright holder is reinstated (a) provisionally, |
| 12521 |
unless and until the copyright holder explicitly and finally |
| 12522 |
terminates your license, and (b) permanently, if the copyright holder |
| 12523 |
fails to notify you of the violation by some reasonable means prior to |
| 12524 |
60 days after the cessation. |
| 12525 |
</p> |
| 12526 |
<p>Moreover, your license from a particular copyright holder is |
| 12527 |
reinstated permanently if the copyright holder notifies you of the |
| 12528 |
violation by some reasonable means, this is the first time you have |
| 12529 |
received notice of violation of this License (for any work) from that |
| 12530 |
copyright holder, and you cure the violation prior to 30 days after |
| 12531 |
your receipt of the notice. |
| 12532 |
</p> |
| 12533 |
<p>Termination of your rights under this section does not terminate the |
| 12534 |
licenses of parties who have received copies or rights from you under |
| 12535 |
this License. If your rights have been terminated and not permanently |
| 12536 |
reinstated, receipt of a copy of some or all of the same material does |
| 12537 |
not give you any rights to use it. |
| 12538 |
</p> |
| 12539 |
</li><li> FUTURE REVISIONS OF THIS LICENSE |
| 12540 |
|
| 12541 |
<p>The Free Software Foundation may publish new, revised versions |
| 12542 |
of the GNU Free Documentation License from time to time. Such new |
| 12543 |
versions will be similar in spirit to the present version, but may |
| 12544 |
differ in detail to address new problems or concerns. See |
| 12545 |
<a href="http://www.gnu.org/copyleft/">http://www.gnu.org/copyleft/</a>. |
| 12546 |
</p> |
| 12547 |
<p>Each version of the License is given a distinguishing version number. |
| 12548 |
If the Document specifies that a particular numbered version of this |
| 12549 |
License “or any later version” applies to it, you have the option of |
| 12550 |
following the terms and conditions either of that specified version or |
| 12551 |
of any later version that has been published (not as a draft) by the |
| 12552 |
Free Software Foundation. If the Document does not specify a version |
| 12553 |
number of this License, you may choose any version ever published (not |
| 12554 |
as a draft) by the Free Software Foundation. If the Document |
| 12555 |
specifies that a proxy can decide which future versions of this |
| 12556 |
License can be used, that proxy’s public statement of acceptance of a |
| 12557 |
version permanently authorizes you to choose that version for the |
| 12558 |
Document. |
| 12559 |
</p> |
| 12560 |
</li><li> RELICENSING |
| 12561 |
|
| 12562 |
<p>“Massive Multiauthor Collaboration Site” (or “MMC Site”) means any |
| 12563 |
World Wide Web server that publishes copyrightable works and also |
| 12564 |
provides prominent facilities for anybody to edit those works. A |
| 12565 |
public wiki that anybody can edit is an example of such a server. A |
| 12566 |
“Massive Multiauthor Collaboration” (or “MMC”) contained in the |
| 12567 |
site means any set of copyrightable works thus published on the MMC |
| 12568 |
site. |
| 12569 |
</p> |
| 12570 |
<p>“CC-BY-SA” means the Creative Commons Attribution-Share Alike 3.0 |
| 12571 |
license published by Creative Commons Corporation, a not-for-profit |
| 12572 |
corporation with a principal place of business in San Francisco, |
| 12573 |
California, as well as future copyleft versions of that license |
| 12574 |
published by that same organization. |
| 12575 |
</p> |
| 12576 |
<p>“Incorporate” means to publish or republish a Document, in whole or |
| 12577 |
in part, as part of another Document. |
| 12578 |
</p> |
| 12579 |
<p>An MMC is “eligible for relicensing” if it is licensed under this |
| 12580 |
License, and if all works that were first published under this License |
| 12581 |
somewhere other than this MMC, and subsequently incorporated in whole |
| 12582 |
or in part into the MMC, (1) had no cover texts or invariant sections, |
| 12583 |
and (2) were thus incorporated prior to November 1, 2008. |
| 12584 |
</p> |
| 12585 |
<p>The operator of an MMC Site may republish an MMC contained in the site |
| 12586 |
under CC-BY-SA on the same site at any time before August 1, 2009, |
| 12587 |
provided the MMC is eligible for relicensing. |
| 12588 |
</p> |
| 12589 |
</li></ol> |
| 12590 |
|
| 12591 |
<span id="ADDENDUM_003a-How-to-use-this-License-for-your-documents"></span><h3 class="heading">ADDENDUM: How to use this License for your documents</h3> |
| 12592 |
|
| 12593 |
<p>To use this License in a document you have written, include a copy of |
| 12594 |
the License in the document and put the following copyright and |
| 12595 |
license notices just after the title page: |
| 12596 |
</p> |
| 12597 |
<div class="example"> |
| 12598 |
<pre class="example"> Copyright (C) <var>year</var> <var>your name</var>. |
| 12599 |
Permission is granted to copy, distribute and/or modify this document |
| 12600 |
under the terms of the GNU Free Documentation License, Version 1.3 |
| 12601 |
or any later version published by the Free Software Foundation; |
| 12602 |
with no Invariant Sections, no Front-Cover Texts, and no Back-Cover |
| 12603 |
Texts. A copy of the license is included in the section entitled ``GNU |
| 12604 |
Free Documentation License''. |
| 12605 |
</pre></div> |
| 12606 |
|
| 12607 |
<p>If you have Invariant Sections, Front-Cover Texts and Back-Cover Texts, |
| 12608 |
replace the “with…Texts.” line with this: |
| 12609 |
</p> |
| 12610 |
<div class="example"> |
| 12611 |
<pre class="example"> with the Invariant Sections being <var>list their titles</var>, with |
| 12612 |
the Front-Cover Texts being <var>list</var>, and with the Back-Cover Texts |
| 12613 |
being <var>list</var>. |
| 12614 |
</pre></div> |
| 12615 |
|
| 12616 |
<p>If you have Invariant Sections without Cover Texts, or some other |
| 12617 |
combination of the three, merge those two alternatives to suit the |
| 12618 |
situation. |
| 12619 |
</p> |
| 12620 |
<p>If your document contains nontrivial examples of program code, we |
| 12621 |
recommend releasing these examples in parallel under your choice of |
| 12622 |
free software license, such as the GNU General Public License, |
| 12623 |
to permit their use in free software. |
| 12624 |
</p> |
| 12625 |
<hr> |
| 12626 |
</div> |
| 12627 |
<div class="section" id="The-GNU-GENERAL-PUBLIC-LICENSE"> |
| 12628 |
<div class="header"> |
| 12629 |
<p> |
| 12630 |
Previous: <a href="#The-GNU-Free-Documentation-License" accesskey="p" rel="prev">The GNU Free Documentation License</a>, Up: <a href="#Licenses-for-this-GNU-APL-Manual-and-for-GNU-APL" accesskey="u" rel="up">Licenses for this GNU APL Manual and for GNU APL</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 12631 |
</div> |
| 12632 |
<span id="The-GNU-GENERAL-PUBLIC-LICENSE-1"></span><h3 class="section">8.2 The GNU GENERAL PUBLIC LICENSE</h3> |
| 12633 |
|
| 12634 |
<p>GNU GENERAL PUBLIC LICENSE |
| 12635 |
Version 3, 29 June 2007 |
| 12636 |
</p> |
| 12637 |
<p>Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> |
| 12638 |
Everyone is permitted to copy and distribute verbatim copies |
| 12639 |
of this license document, but changing it is not allowed. |
| 12640 |
</p> |
| 12641 |
<p>Preamble |
| 12642 |
</p> |
| 12643 |
<p>The GNU General Public License is a free, copyleft license for |
| 12644 |
software and other kinds of works. |
| 12645 |
</p> |
| 12646 |
<p>The licenses for most software and other practical works are designed |
| 12647 |
to take away your freedom to share and change the works. By contrast, |
| 12648 |
the GNU General Public License is intended to guarantee your freedom to |
| 12649 |
share and change all versions of a program–to make sure it remains free |
| 12650 |
software for all its users. We, the Free Software Foundation, use the |
| 12651 |
GNU General Public License for most of our software; it applies also to |
| 12652 |
any other work released this way by its authors. You can apply it to |
| 12653 |
your programs, too. |
| 12654 |
</p> |
| 12655 |
<p>When we speak of free software, we are referring to freedom, not |
| 12656 |
price. Our General Public Licenses are designed to make sure that you |
| 12657 |
have the freedom to distribute copies of free software (and charge for |
| 12658 |
them if you wish), that you receive source code or can get it if you |
| 12659 |
want it, that you can change the software or use pieces of it in new |
| 12660 |
free programs, and that you know you can do these things. |
| 12661 |
</p> |
| 12662 |
<p>To protect your rights, we need to prevent others from denying you |
| 12663 |
these rights or asking you to surrender the rights. Therefore, you have |
| 12664 |
certain responsibilities if you distribute copies of the software, or if |
| 12665 |
you modify it: responsibilities to respect the freedom of others. |
| 12666 |
</p> |
| 12667 |
<p>For example, if you distribute copies of such a program, whether |
| 12668 |
gratis or for a fee, you must pass on to the recipients the same |
| 12669 |
freedoms that you received. You must make sure that they, too, receive |
| 12670 |
or can get the source code. And you must show them these terms so they |
| 12671 |
know their rights. |
| 12672 |
</p> |
| 12673 |
<p>Developers that use the GNU GPL protect your rights with two steps: |
| 12674 |
(1) assert copyright on the software, and (2) offer you this License |
| 12675 |
giving you legal permission to copy, distribute and/or modify it. |
| 12676 |
</p> |
| 12677 |
<p>For the developers’ and authors’ protection, the GPL clearly explains |
| 12678 |
that there is no warranty for this free software. For both users’ and |
| 12679 |
authors’ sake, the GPL requires that modified versions be marked as |
| 12680 |
changed, so that their problems will not be attributed erroneously to |
| 12681 |
authors of previous versions. |
| 12682 |
</p> |
| 12683 |
<p>Some devices are designed to deny users access to install or run |
| 12684 |
modified versions of the software inside them, although the manufacturer |
| 12685 |
can do so. This is fundamentally incompatible with the aim of |
| 12686 |
protecting users’ freedom to change the software. The systematic |
| 12687 |
pattern of such abuse occurs in the area of products for individuals to |
| 12688 |
use, which is precisely where it is most unacceptable. Therefore, we |
| 12689 |
have designed this version of the GPL to prohibit the practice for those |
| 12690 |
products. If such problems arise substantially in other domains, we |
| 12691 |
stand ready to extend this provision to those domains in future versions |
| 12692 |
of the GPL, as needed to protect the freedom of users. |
| 12693 |
</p> |
| 12694 |
<p>Finally, every program is threatened constantly by software patents. |
| 12695 |
States should not allow patents to restrict development and use of |
| 12696 |
software on general-purpose computers, but in those that do, we wish to |
| 12697 |
avoid the special danger that patents applied to a free program could |
| 12698 |
make it effectively proprietary. To prevent this, the GPL assures that |
| 12699 |
patents cannot be used to render the program non-free. |
| 12700 |
</p> |
| 12701 |
<p>The precise terms and conditions for copying, distribution and |
| 12702 |
modification follow. |
| 12703 |
</p> |
| 12704 |
<p>TERMS AND CONDITIONS |
| 12705 |
</p> |
| 12706 |
<p>0. Definitions. |
| 12707 |
</p> |
| 12708 |
<p>"This License" refers to version 3 of the GNU General Public License. |
| 12709 |
</p> |
| 12710 |
<p>"Copyright" also means copyright-like laws that apply to other kinds of |
| 12711 |
works, such as semiconductor masks. |
| 12712 |
</p> |
| 12713 |
<p>"The Program" refers to any copyrightable work licensed under this |
| 12714 |
License. Each licensee is addressed as "you". "Licensees" and |
| 12715 |
"recipients" may be individuals or organizations. |
| 12716 |
</p> |
| 12717 |
<p>To "modify" a work means to copy from or adapt all or part of the work |
| 12718 |
in a fashion requiring copyright permission, other than the making of an |
| 12719 |
exact copy. The resulting work is called a "modified version" of the |
| 12720 |
earlier work or a work "based on" the earlier work. |
| 12721 |
</p> |
| 12722 |
<p>A "covered work" means either the unmodified Program or a work based |
| 12723 |
on the Program. |
| 12724 |
</p> |
| 12725 |
<p>To "propagate" a work means to do anything with it that, without |
| 12726 |
permission, would make you directly or secondarily liable for |
| 12727 |
infringement under applicable copyright law, except executing it on a |
| 12728 |
computer or modifying a private copy. Propagation includes copying, |
| 12729 |
distribution (with or without modification), making available to the |
| 12730 |
public, and in some countries other activities as well. |
| 12731 |
</p> |
| 12732 |
<p>To "convey" a work means any kind of propagation that enables other |
| 12733 |
parties to make or receive copies. Mere interaction with a user through |
| 12734 |
a computer network, with no transfer of a copy, is not conveying. |
| 12735 |
</p> |
| 12736 |
<p>An interactive user interface displays "Appropriate Legal Notices" |
| 12737 |
to the extent that it includes a convenient and prominently visible |
| 12738 |
feature that (1) displays an appropriate copyright notice, and (2) |
| 12739 |
tells the user that there is no warranty for the work (except to the |
| 12740 |
extent that warranties are provided), that licensees may convey the |
| 12741 |
work under this License, and how to view a copy of this License. If |
| 12742 |
the interface presents a list of user commands or options, such as a |
| 12743 |
menu, a prominent item in the list meets this criterion. |
| 12744 |
</p> |
| 12745 |
<p>1. Source Code. |
| 12746 |
</p> |
| 12747 |
<p>The "source code" for a work means the preferred form of the work |
| 12748 |
for making modifications to it. "Object code" means any non-source |
| 12749 |
form of a work. |
| 12750 |
</p> |
| 12751 |
<p>A "Standard Interface" means an interface that either is an official |
| 12752 |
standard defined by a recognized standards body, or, in the case of |
| 12753 |
interfaces specified for a particular programming language, one that |
| 12754 |
is widely used among developers working in that language. |
| 12755 |
</p> |
| 12756 |
<p>The "System Libraries" of an executable work include anything, other |
| 12757 |
than the work as a whole, that (a) is included in the normal form of |
| 12758 |
packaging a Major Component, but which is not part of that Major |
| 12759 |
Component, and (b) serves only to enable use of the work with that |
| 12760 |
Major Component, or to implement a Standard Interface for which an |
| 12761 |
implementation is available to the public in source code form. A |
| 12762 |
"Major Component", in this context, means a major essential component |
| 12763 |
(kernel, window system, and so on) of the specific operating system |
| 12764 |
(if any) on which the executable work runs, or a compiler used to |
| 12765 |
produce the work, or an object code interpreter used to run it. |
| 12766 |
</p> |
| 12767 |
<p>The "Corresponding Source" for a work in object code form means all |
| 12768 |
the source code needed to generate, install, and (for an executable |
| 12769 |
work) run the object code and to modify the work, including scripts to |
| 12770 |
control those activities. However, it does not include the work’s |
| 12771 |
System Libraries, or general-purpose tools or generally available free |
| 12772 |
programs which are used unmodified in performing those activities but |
| 12773 |
which are not part of the work. For example, Corresponding Source |
| 12774 |
includes interface definition files associated with source files for |
| 12775 |
the work, and the source code for shared libraries and dynamically |
| 12776 |
linked subprograms that the work is specifically designed to require, |
| 12777 |
such as by intimate data communication or control flow between those |
| 12778 |
subprograms and other parts of the work. |
| 12779 |
</p> |
| 12780 |
<p>The Corresponding Source need not include anything that users |
| 12781 |
can regenerate automatically from other parts of the Corresponding |
| 12782 |
Source. |
| 12783 |
</p> |
| 12784 |
<p>The Corresponding Source for a work in source code form is that |
| 12785 |
same work. |
| 12786 |
</p> |
| 12787 |
<p>2. Basic Permissions. |
| 12788 |
</p> |
| 12789 |
<p>All rights granted under this License are granted for the term of |
| 12790 |
copyright on the Program, and are irrevocable provided the stated |
| 12791 |
conditions are met. This License explicitly affirms your unlimited |
| 12792 |
permission to run the unmodified Program. The output from running a |
| 12793 |
covered work is covered by this License only if the output, given its |
| 12794 |
content, constitutes a covered work. This License acknowledges your |
| 12795 |
rights of fair use or other equivalent, as provided by copyright law. |
| 12796 |
</p> |
| 12797 |
<p>You may make, run and propagate covered works that you do not |
| 12798 |
convey, without conditions so long as your license otherwise remains |
| 12799 |
in force. You may convey covered works to others for the sole purpose |
| 12800 |
of having them make modifications exclusively for you, or provide you |
| 12801 |
with facilities for running those works, provided that you comply with |
| 12802 |
the terms of this License in conveying all material for which you do |
| 12803 |
not control copyright. Those thus making or running the covered works |
| 12804 |
for you must do so exclusively on your behalf, under your direction |
| 12805 |
and control, on terms that prohibit them from making any copies of |
| 12806 |
your copyrighted material outside their relationship with you. |
| 12807 |
</p> |
| 12808 |
<p>Conveying under any other circumstances is permitted solely under |
| 12809 |
the conditions stated below. Sublicensing is not allowed; section 10 |
| 12810 |
makes it unnecessary. |
| 12811 |
</p> |
| 12812 |
<p>3. Protecting Users’ Legal Rights From Anti-Circumvention Law. |
| 12813 |
</p> |
| 12814 |
<p>No covered work shall be deemed part of an effective technological |
| 12815 |
measure under any applicable law fulfilling obligations under article |
| 12816 |
11 of the WIPO copyright treaty adopted on 20 December 1996, or |
| 12817 |
similar laws prohibiting or restricting circumvention of such |
| 12818 |
measures. |
| 12819 |
</p> |
| 12820 |
<p>When you convey a covered work, you waive any legal power to forbid |
| 12821 |
circumvention of technological measures to the extent such circumvention |
| 12822 |
is effected by exercising rights under this License with respect to |
| 12823 |
the covered work, and you disclaim any intention to limit operation or |
| 12824 |
modification of the work as a means of enforcing, against the work’s |
| 12825 |
users, your or third parties’ legal rights to forbid circumvention of |
| 12826 |
technological measures. |
| 12827 |
</p> |
| 12828 |
<p>4. Conveying Verbatim Copies. |
| 12829 |
</p> |
| 12830 |
<p>You may convey verbatim copies of the Program’s source code as you |
| 12831 |
receive it, in any medium, provided that you conspicuously and |
| 12832 |
appropriately publish on each copy an appropriate copyright notice; |
| 12833 |
keep intact all notices stating that this License and any |
| 12834 |
non-permissive terms added in accord with section 7 apply to the code; |
| 12835 |
keep intact all notices of the absence of any warranty; and give all |
| 12836 |
recipients a copy of this License along with the Program. |
| 12837 |
</p> |
| 12838 |
<p>You may charge any price or no price for each copy that you convey, |
| 12839 |
and you may offer support or warranty protection for a fee. |
| 12840 |
</p> |
| 12841 |
<p>5. Conveying Modified Source Versions. |
| 12842 |
</p> |
| 12843 |
<p>You may convey a work based on the Program, or the modifications to |
| 12844 |
produce it from the Program, in the form of source code under the |
| 12845 |
terms of section 4, provided that you also meet all of these conditions: |
| 12846 |
</p> |
| 12847 |
<p>a) The work must carry prominent notices stating that you modified |
| 12848 |
it, and giving a relevant date. |
| 12849 |
</p> |
| 12850 |
<p>b) The work must carry prominent notices stating that it is |
| 12851 |
released under this License and any conditions added under section |
| 12852 |
7. This requirement modifies the requirement in section 4 to |
| 12853 |
"keep intact all notices". |
| 12854 |
</p> |
| 12855 |
<p>c) You must license the entire work, as a whole, under this |
| 12856 |
License to anyone who comes into possession of a copy. This |
| 12857 |
License will therefore apply, along with any applicable section 7 |
| 12858 |
additional terms, to the whole of the work, and all its parts, |
| 12859 |
regardless of how they are packaged. This License gives no |
| 12860 |
permission to license the work in any other way, but it does not |
| 12861 |
invalidate such permission if you have separately received it. |
| 12862 |
</p> |
| 12863 |
<p>d) If the work has interactive user interfaces, each must display |
| 12864 |
Appropriate Legal Notices; however, if the Program has interactive |
| 12865 |
interfaces that do not display Appropriate Legal Notices, your |
| 12866 |
work need not make them do so. |
| 12867 |
</p> |
| 12868 |
<p>A compilation of a covered work with other separate and independent |
| 12869 |
works, which are not by their nature extensions of the covered work, |
| 12870 |
and which are not combined with it such as to form a larger program, |
| 12871 |
in or on a volume of a storage or distribution medium, is called an |
| 12872 |
"aggregate" if the compilation and its resulting copyright are not |
| 12873 |
used to limit the access or legal rights of the compilation’s users |
| 12874 |
beyond what the individual works permit. Inclusion of a covered work |
| 12875 |
in an aggregate does not cause this License to apply to the other |
| 12876 |
parts of the aggregate. |
| 12877 |
</p> |
| 12878 |
<p>6. Conveying Non-Source Forms. |
| 12879 |
</p> |
| 12880 |
<p>You may convey a covered work in object code form under the terms |
| 12881 |
of sections 4 and 5, provided that you also convey the |
| 12882 |
machine-readable Corresponding Source under the terms of this License, |
| 12883 |
in one of these ways: |
| 12884 |
</p> |
| 12885 |
<p>a) Convey the object code in, or embodied in, a physical product |
| 12886 |
(including a physical distribution medium), accompanied by the |
| 12887 |
Corresponding Source fixed on a durable physical medium |
| 12888 |
customarily used for software interchange. |
| 12889 |
</p> |
| 12890 |
<p>b) Convey the object code in, or embodied in, a physical product |
| 12891 |
(including a physical distribution medium), accompanied by a |
| 12892 |
written offer, valid for at least three years and valid for as |
| 12893 |
long as you offer spare parts or customer support for that product |
| 12894 |
model, to give anyone who possesses the object code either (1) a |
| 12895 |
copy of the Corresponding Source for all the software in the |
| 12896 |
product that is covered by this License, on a durable physical |
| 12897 |
medium customarily used for software interchange, for a price no |
| 12898 |
more than your reasonable cost of physically performing this |
| 12899 |
conveying of source, or (2) access to copy the |
| 12900 |
Corresponding Source from a network server at no charge. |
| 12901 |
</p> |
| 12902 |
<p>c) Convey individual copies of the object code with a copy of the |
| 12903 |
written offer to provide the Corresponding Source. This |
| 12904 |
alternative is allowed only occasionally and noncommercially, and |
| 12905 |
only if you received the object code with such an offer, in accord |
| 12906 |
with subsection 6b. |
| 12907 |
</p> |
| 12908 |
<p>d) Convey the object code by offering access from a designated |
| 12909 |
place (gratis or for a charge), and offer equivalent access to the |
| 12910 |
Corresponding Source in the same way through the same place at no |
| 12911 |
further charge. You need not require recipients to copy the |
| 12912 |
Corresponding Source along with the object code. If the place to |
| 12913 |
copy the object code is a network server, the Corresponding Source |
| 12914 |
may be on a different server (operated by you or a third party) |
| 12915 |
that supports equivalent copying facilities, provided you maintain |
| 12916 |
clear directions next to the object code saying where to find the |
| 12917 |
Corresponding Source. Regardless of what server hosts the |
| 12918 |
Corresponding Source, you remain obligated to ensure that it is |
| 12919 |
available for as long as needed to satisfy these requirements. |
| 12920 |
</p> |
| 12921 |
<p>e) Convey the object code using peer-to-peer transmission, provided |
| 12922 |
you inform other peers where the object code and Corresponding |
| 12923 |
Source of the work are being offered to the general public at no |
| 12924 |
charge under subsection 6d. |
| 12925 |
</p> |
| 12926 |
<p>A separable portion of the object code, whose source code is excluded |
| 12927 |
from the Corresponding Source as a System Library, need not be |
| 12928 |
included in conveying the object code work. |
| 12929 |
</p> |
| 12930 |
<p>A "User Product" is either (1) a "consumer product", which means any |
| 12931 |
tangible personal property which is normally used for personal, family, |
| 12932 |
or household purposes, or (2) anything designed or sold for incorporation |
| 12933 |
into a dwelling. In determining whether a product is a consumer product, |
| 12934 |
doubtful cases shall be resolved in favor of coverage. For a particular |
| 12935 |
product received by a particular user, "normally used" refers to a |
| 12936 |
typical or common use of that class of product, regardless of the status |
| 12937 |
of the particular user or of the way in which the particular user |
| 12938 |
actually uses, or expects or is expected to use, the product. A product |
| 12939 |
is a consumer product regardless of whether the product has substantial |
| 12940 |
commercial, industrial or non-consumer uses, unless such uses represent |
| 12941 |
the only significant mode of use of the product. |
| 12942 |
</p> |
| 12943 |
<p>"Installation Information" for a User Product means any methods, |
| 12944 |
procedures, authorization keys, or other information required to install |
| 12945 |
and execute modified versions of a covered work in that User Product from |
| 12946 |
a modified version of its Corresponding Source. The information must |
| 12947 |
suffice to ensure that the continued functioning of the modified object |
| 12948 |
code is in no case prevented or interfered with solely because |
| 12949 |
modification has been made. |
| 12950 |
</p> |
| 12951 |
<p>If you convey an object code work under this section in, or with, or |
| 12952 |
specifically for use in, a User Product, and the conveying occurs as |
| 12953 |
part of a transaction in which the right of possession and use of the |
| 12954 |
User Product is transferred to the recipient in perpetuity or for a |
| 12955 |
fixed term (regardless of how the transaction is characterized), the |
| 12956 |
Corresponding Source conveyed under this section must be accompanied |
| 12957 |
by the Installation Information. But this requirement does not apply |
| 12958 |
if neither you nor any third party retains the ability to install |
| 12959 |
modified object code on the User Product (for example, the work has |
| 12960 |
been installed in ROM). |
| 12961 |
</p> |
| 12962 |
<p>The requirement to provide Installation Information does not include a |
| 12963 |
requirement to continue to provide support service, warranty, or updates |
| 12964 |
for a work that has been modified or installed by the recipient, or for |
| 12965 |
the User Product in which it has been modified or installed. Access to a |
| 12966 |
network may be denied when the modification itself materially and |
| 12967 |
adversely affects the operation of the network or violates the rules and |
| 12968 |
protocols for communication across the network. |
| 12969 |
</p> |
| 12970 |
<p>Corresponding Source conveyed, and Installation Information provided, |
| 12971 |
in accord with this section must be in a format that is publicly |
| 12972 |
documented (and with an implementation available to the public in |
| 12973 |
source code form), and must require no special password or key for |
| 12974 |
unpacking, reading or copying. |
| 12975 |
</p> |
| 12976 |
<p>7. Additional Terms. |
| 12977 |
</p> |
| 12978 |
<p>"Additional permissions" are terms that supplement the terms of this |
| 12979 |
License by making exceptions from one or more of its conditions. |
| 12980 |
Additional permissions that are applicable to the entire Program shall |
| 12981 |
be treated as though they were included in this License, to the extent |
| 12982 |
that they are valid under applicable law. If additional permissions |
| 12983 |
apply only to part of the Program, that part may be used separately |
| 12984 |
under those permissions, but the entire Program remains governed by |
| 12985 |
this License without regard to the additional permissions. |
| 12986 |
</p> |
| 12987 |
<p>When you convey a copy of a covered work, you may at your option |
| 12988 |
remove any additional permissions from that copy, or from any part of |
| 12989 |
it. (Additional permissions may be written to require their own |
| 12990 |
removal in certain cases when you modify the work.) You may place |
| 12991 |
additional permissions on material, added by you to a covered work, |
| 12992 |
for which you have or can give appropriate copyright permission. |
| 12993 |
</p> |
| 12994 |
<p>Notwithstanding any other provision of this License, for material you |
| 12995 |
add to a covered work, you may (if authorized by the copyright holders of |
| 12996 |
that material) supplement the terms of this License with terms: |
| 12997 |
</p> |
| 12998 |
<p>a) Disclaiming warranty or limiting liability differently from the |
| 12999 |
terms of sections 15 and 16 of this License; or |
| 13000 |
</p> |
| 13001 |
<p>b) Requiring preservation of specified reasonable legal notices or |
| 13002 |
author attributions in that material or in the Appropriate Legal |
| 13003 |
Notices displayed by works containing it; or |
| 13004 |
</p> |
| 13005 |
<p>c) Prohibiting misrepresentation of the origin of that material, or |
| 13006 |
requiring that modified versions of such material be marked in |
| 13007 |
reasonable ways as different from the original version; or |
| 13008 |
</p> |
| 13009 |
<p>d) Limiting the use for publicity purposes of names of licensors or |
| 13010 |
authors of the material; or |
| 13011 |
</p> |
| 13012 |
<p>e) Declining to grant rights under trademark law for use of some |
| 13013 |
trade names, trademarks, or service marks; or |
| 13014 |
</p> |
| 13015 |
<p>f) Requiring indemnification of licensors and authors of that |
| 13016 |
material by anyone who conveys the material (or modified versions of |
| 13017 |
it) with contractual assumptions of liability to the recipient, for |
| 13018 |
any liability that these contractual assumptions directly impose on |
| 13019 |
those licensors and authors. |
| 13020 |
</p> |
| 13021 |
<p>All other non-permissive additional terms are considered "further |
| 13022 |
restrictions" within the meaning of section 10. If the Program as you |
| 13023 |
received it, or any part of it, contains a notice stating that it is |
| 13024 |
governed by this License along with a term that is a further |
| 13025 |
restriction, you may remove that term. If a license document contains |
| 13026 |
a further restriction but permits relicensing or conveying under this |
| 13027 |
License, you may add to a covered work material governed by the terms |
| 13028 |
of that license document, provided that the further restriction does |
| 13029 |
not survive such relicensing or conveying. |
| 13030 |
</p> |
| 13031 |
<p>If you add terms to a covered work in accord with this section, you |
| 13032 |
must place, in the relevant source files, a statement of the |
| 13033 |
additional terms that apply to those files, or a notice indicating |
| 13034 |
where to find the applicable terms. |
| 13035 |
</p> |
| 13036 |
<p>Additional terms, permissive or non-permissive, may be stated in the |
| 13037 |
form of a separately written license, or stated as exceptions; |
| 13038 |
the above requirements apply either way. |
| 13039 |
</p> |
| 13040 |
<p>8. Termination. |
| 13041 |
</p> |
| 13042 |
<p>You may not propagate or modify a covered work except as expressly |
| 13043 |
provided under this License. Any attempt otherwise to propagate or |
| 13044 |
modify it is void, and will automatically terminate your rights under |
| 13045 |
this License (including any patent licenses granted under the third |
| 13046 |
paragraph of section 11). |
| 13047 |
</p> |
| 13048 |
<p>However, if you cease all violation of this License, then your |
| 13049 |
license from a particular copyright holder is reinstated (a) |
| 13050 |
provisionally, unless and until the copyright holder explicitly and |
| 13051 |
finally terminates your license, and (b) permanently, if the copyright |
| 13052 |
holder fails to notify you of the violation by some reasonable means |
| 13053 |
prior to 60 days after the cessation. |
| 13054 |
</p> |
| 13055 |
<p>Moreover, your license from a particular copyright holder is |
| 13056 |
reinstated permanently if the copyright holder notifies you of the |
| 13057 |
violation by some reasonable means, this is the first time you have |
| 13058 |
received notice of violation of this License (for any work) from that |
| 13059 |
copyright holder, and you cure the violation prior to 30 days after |
| 13060 |
your receipt of the notice. |
| 13061 |
</p> |
| 13062 |
<p>Termination of your rights under this section does not terminate the |
| 13063 |
licenses of parties who have received copies or rights from you under |
| 13064 |
this License. If your rights have been terminated and not permanently |
| 13065 |
reinstated, you do not qualify to receive new licenses for the same |
| 13066 |
material under section 10. |
| 13067 |
</p> |
| 13068 |
<p>9. Acceptance Not Required for Having Copies. |
| 13069 |
</p> |
| 13070 |
<p>You are not required to accept this License in order to receive or |
| 13071 |
run a copy of the Program. Ancillary propagation of a covered work |
| 13072 |
occurring solely as a consequence of using peer-to-peer transmission |
| 13073 |
to receive a copy likewise does not require acceptance. However, |
| 13074 |
nothing other than this License grants you permission to propagate or |
| 13075 |
modify any covered work. These actions infringe copyright if you do |
| 13076 |
not accept this License. Therefore, by modifying or propagating a |
| 13077 |
covered work, you indicate your acceptance of this License to do so. |
| 13078 |
</p> |
| 13079 |
<p>10. Automatic Licensing of Downstream Recipients. |
| 13080 |
</p> |
| 13081 |
<p>Each time you convey a covered work, the recipient automatically |
| 13082 |
receives a license from the original licensors, to run, modify and |
| 13083 |
propagate that work, subject to this License. You are not responsible |
| 13084 |
for enforcing compliance by third parties with this License. |
| 13085 |
</p> |
| 13086 |
<p>An "entity transaction" is a transaction transferring control of an |
| 13087 |
organization, or substantially all assets of one, or subdividing an |
| 13088 |
organization, or merging organizations. If propagation of a covered |
| 13089 |
work results from an entity transaction, each party to that |
| 13090 |
transaction who receives a copy of the work also receives whatever |
| 13091 |
licenses to the work the party’s predecessor in interest had or could |
| 13092 |
give under the previous paragraph, plus a right to possession of the |
| 13093 |
Corresponding Source of the work from the predecessor in interest, if |
| 13094 |
the predecessor has it or can get it with reasonable efforts. |
| 13095 |
</p> |
| 13096 |
<p>You may not impose any further restrictions on the exercise of the |
| 13097 |
rights granted or affirmed under this License. For example, you may |
| 13098 |
not impose a license fee, royalty, or other charge for exercise of |
| 13099 |
rights granted under this License, and you may not initiate litigation |
| 13100 |
(including a cross-claim or counterclaim in a lawsuit) alleging that |
| 13101 |
any patent claim is infringed by making, using, selling, offering for |
| 13102 |
sale, or importing the Program or any portion of it. |
| 13103 |
</p> |
| 13104 |
<p>11. Patents. |
| 13105 |
</p> |
| 13106 |
<p>A "contributor" is a copyright holder who authorizes use under this |
| 13107 |
License of the Program or a work on which the Program is based. The |
| 13108 |
work thus licensed is called the contributor’s "contributor version". |
| 13109 |
</p> |
| 13110 |
<p>A contributor’s "essential patent claims" are all patent claims |
| 13111 |
owned or controlled by the contributor, whether already acquired or |
| 13112 |
hereafter acquired, that would be infringed by some manner, permitted |
| 13113 |
by this License, of making, using, or selling its contributor version, |
| 13114 |
but do not include claims that would be infringed only as a |
| 13115 |
consequence of further modification of the contributor version. For |
| 13116 |
purposes of this definition, "control" includes the right to grant |
| 13117 |
patent sublicenses in a manner consistent with the requirements of |
| 13118 |
this License. |
| 13119 |
</p> |
| 13120 |
<p>Each contributor grants you a non-exclusive, worldwide, royalty-free |
| 13121 |
patent license under the contributor’s essential patent claims, to |
| 13122 |
make, use, sell, offer for sale, import and otherwise run, modify and |
| 13123 |
propagate the contents of its contributor version. |
| 13124 |
</p> |
| 13125 |
<p>In the following three paragraphs, a "patent license" is any express |
| 13126 |
agreement or commitment, however denominated, not to enforce a patent |
| 13127 |
(such as an express permission to practice a patent or covenant not to |
| 13128 |
sue for patent infringement). To "grant" such a patent license to a |
| 13129 |
party means to make such an agreement or commitment not to enforce a |
| 13130 |
patent against the party. |
| 13131 |
</p> |
| 13132 |
<p>If you convey a covered work, knowingly relying on a patent license, |
| 13133 |
and the Corresponding Source of the work is not available for anyone |
| 13134 |
to copy, free of charge and under the terms of this License, through a |
| 13135 |
publicly available network server or other readily accessible means, |
| 13136 |
then you must either (1) cause the Corresponding Source to be so |
| 13137 |
available, or (2) arrange to deprive yourself of the benefit of the |
| 13138 |
patent license for this particular work, or (3) arrange, in a manner |
| 13139 |
consistent with the requirements of this License, to extend the patent |
| 13140 |
license to downstream recipients. "Knowingly relying" means you have |
| 13141 |
actual knowledge that, but for the patent license, your conveying the |
| 13142 |
covered work in a country, or your recipient’s use of the covered work |
| 13143 |
in a country, would infringe one or more identifiable patents in that |
| 13144 |
country that you have reason to believe are valid. |
| 13145 |
</p> |
| 13146 |
<p>If, pursuant to or in connection with a single transaction or |
| 13147 |
arrangement, you convey, or propagate by procuring conveyance of, a |
| 13148 |
covered work, and grant a patent license to some of the parties |
| 13149 |
receiving the covered work authorizing them to use, propagate, modify |
| 13150 |
or convey a specific copy of the covered work, then the patent license |
| 13151 |
you grant is automatically extended to all recipients of the covered |
| 13152 |
work and works based on it. |
| 13153 |
</p> |
| 13154 |
<p>A patent license is "discriminatory" if it does not include within |
| 13155 |
the scope of its coverage, prohibits the exercise of, or is |
| 13156 |
conditioned on the non-exercise of one or more of the rights that are |
| 13157 |
specifically granted under this License. You may not convey a covered |
| 13158 |
work if you are a party to an arrangement with a third party that is |
| 13159 |
in the business of distributing software, under which you make payment |
| 13160 |
to the third party based on the extent of your activity of conveying |
| 13161 |
the work, and under which the third party grants, to any of the |
| 13162 |
parties who would receive the covered work from you, a discriminatory |
| 13163 |
patent license (a) in connection with copies of the covered work |
| 13164 |
conveyed by you (or copies made from those copies), or (b) primarily |
| 13165 |
for and in connection with specific products or compilations that |
| 13166 |
contain the covered work, unless you entered into that arrangement, |
| 13167 |
or that patent license was granted, prior to 28 March 2007. |
| 13168 |
</p> |
| 13169 |
<p>Nothing in this License shall be construed as excluding or limiting |
| 13170 |
any implied license or other defenses to infringement that may |
| 13171 |
otherwise be available to you under applicable patent law. |
| 13172 |
</p> |
| 13173 |
<p>12. No Surrender of Others’ Freedom. |
| 13174 |
</p> |
| 13175 |
<p>If conditions are imposed on you (whether by court order, agreement or |
| 13176 |
otherwise) that contradict the conditions of this License, they do not |
| 13177 |
excuse you from the conditions of this License. If you cannot convey a |
| 13178 |
covered work so as to satisfy simultaneously your obligations under this |
| 13179 |
License and any other pertinent obligations, then as a consequence you may |
| 13180 |
not convey it at all. For example, if you agree to terms that obligate you |
| 13181 |
to collect a royalty for further conveying from those to whom you convey |
| 13182 |
the Program, the only way you could satisfy both those terms and this |
| 13183 |
License would be to refrain entirely from conveying the Program. |
| 13184 |
</p> |
| 13185 |
<p>13. Use with the GNU Affero General Public License. |
| 13186 |
</p> |
| 13187 |
<p>Notwithstanding any other provision of this License, you have |
| 13188 |
permission to link or combine any covered work with a work licensed |
| 13189 |
under version 3 of the GNU Affero General Public License into a single |
| 13190 |
combined work, and to convey the resulting work. The terms of this |
| 13191 |
License will continue to apply to the part which is the covered work, |
| 13192 |
but the special requirements of the GNU Affero General Public License, |
| 13193 |
section 13, concerning interaction through a network will apply to the |
| 13194 |
combination as such. |
| 13195 |
</p> |
| 13196 |
<p>14. Revised Versions of this License. |
| 13197 |
</p> |
| 13198 |
<p>The Free Software Foundation may publish revised and/or new versions of |
| 13199 |
the GNU General Public License from time to time. Such new versions will |
| 13200 |
be similar in spirit to the present version, but may differ in detail to |
| 13201 |
address new problems or concerns. |
| 13202 |
</p> |
| 13203 |
<p>Each version is given a distinguishing version number. If the |
| 13204 |
Program specifies that a certain numbered version of the GNU General |
| 13205 |
Public License "or any later version" applies to it, you have the |
| 13206 |
option of following the terms and conditions either of that numbered |
| 13207 |
version or of any later version published by the Free Software |
| 13208 |
Foundation. If the Program does not specify a version number of the |
| 13209 |
GNU General Public License, you may choose any version ever published |
| 13210 |
by the Free Software Foundation. |
| 13211 |
</p> |
| 13212 |
<p>If the Program specifies that a proxy can decide which future |
| 13213 |
versions of the GNU General Public License can be used, that proxy’s |
| 13214 |
public statement of acceptance of a version permanently authorizes you |
| 13215 |
to choose that version for the Program. |
| 13216 |
</p> |
| 13217 |
<p>Later license versions may give you additional or different |
| 13218 |
permissions. However, no additional obligations are imposed on any |
| 13219 |
author or copyright holder as a result of your choosing to follow a |
| 13220 |
later version. |
| 13221 |
</p> |
| 13222 |
<p>15. Disclaimer of Warranty. |
| 13223 |
</p> |
| 13224 |
<p>THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY |
| 13225 |
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT |
| 13226 |
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY |
| 13227 |
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, |
| 13228 |
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 13229 |
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM |
| 13230 |
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF |
| 13231 |
ALL NECESSARY SERVICING, REPAIR OR CORRECTION. |
| 13232 |
</p> |
| 13233 |
<p>16. Limitation of Liability. |
| 13234 |
</p> |
| 13235 |
<p>IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING |
| 13236 |
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS |
| 13237 |
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY |
| 13238 |
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE |
| 13239 |
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF |
| 13240 |
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD |
| 13241 |
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), |
| 13242 |
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF |
| 13243 |
SUCH DAMAGES. |
| 13244 |
</p> |
| 13245 |
<p>17. Interpretation of Sections 15 and 16. |
| 13246 |
</p> |
| 13247 |
<p>If the disclaimer of warranty and limitation of liability provided |
| 13248 |
above cannot be given local legal effect according to their terms, |
| 13249 |
reviewing courts shall apply local law that most closely approximates |
| 13250 |
an absolute waiver of all civil liability in connection with the |
| 13251 |
Program, unless a warranty or assumption of liability accompanies a |
| 13252 |
copy of the Program in return for a fee. |
| 13253 |
</p> |
| 13254 |
<p>END OF TERMS AND CONDITIONS |
| 13255 |
</p> |
| 13256 |
<p>How to Apply These Terms to Your New Programs |
| 13257 |
</p> |
| 13258 |
<p>If you develop a new program, and you want it to be of the greatest |
| 13259 |
possible use to the public, the best way to achieve this is to make it |
| 13260 |
free software which everyone can redistribute and change under these terms. |
| 13261 |
</p> |
| 13262 |
<p>To do so, attach the following notices to the program. It is safest |
| 13263 |
to attach them to the start of each source file to most effectively |
| 13264 |
state the exclusion of warranty; and each file should have at least |
| 13265 |
the "copyright" line and a pointer to where the full notice is found. |
| 13266 |
</p> |
| 13267 |
<p><one line to give the program’s name and a brief idea of what it does.> |
| 13268 |
Copyright (C) <year> <name of author> |
| 13269 |
</p> |
| 13270 |
<p>This program is free software: you can redistribute it and/or modify |
| 13271 |
it under the terms of the GNU General Public License as published by |
| 13272 |
the Free Software Foundation, either version 3 of the License, or |
| 13273 |
(at your option) any later version. |
| 13274 |
</p> |
| 13275 |
<p>This program is distributed in the hope that it will be useful, |
| 13276 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13277 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13278 |
GNU General Public License for more details. |
| 13279 |
</p> |
| 13280 |
<p>You should have received a copy of the GNU General Public License |
| 13281 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 13282 |
</p> |
| 13283 |
<p>Also add information on how to contact you by electronic and paper mail. |
| 13284 |
</p> |
| 13285 |
<p>If the program does terminal interaction, make it output a short |
| 13286 |
notice like this when it starts in an interactive mode: |
| 13287 |
</p> |
| 13288 |
<p><program> Copyright (C) <year> <name of author> |
| 13289 |
This program comes with ABSOLUTELY NO WARRANTY; for details type ‘show w’. |
| 13290 |
This is free software, and you are welcome to redistribute it |
| 13291 |
under certain conditions; type ‘show c’ for details. |
| 13292 |
</p> |
| 13293 |
<p>The hypothetical commands ‘show w’ and ‘show c’ should show the appropriate |
| 13294 |
parts of the General Public License. Of course, your program’s commands |
| 13295 |
might be different; for a GUI interface, you would use an "about box". |
| 13296 |
</p> |
| 13297 |
<p>You should also get your employer (if you work as a programmer) or school, |
| 13298 |
if any, to sign a "copyright disclaimer" for the program, if necessary. |
| 13299 |
For more information on this, and how to apply and follow the GNU GPL, see |
| 13300 |
<http://www.gnu.org/licenses/>. |
| 13301 |
</p> |
| 13302 |
<p>The GNU General Public License does not permit incorporating your program |
| 13303 |
into proprietary programs. If your program is a subroutine library, you |
| 13304 |
may consider it more useful to permit linking proprietary applications with |
| 13305 |
the library. If this is what you want to do, use the GNU Lesser General |
| 13306 |
Public License instead of this License. But first, please read |
| 13307 |
<http://www.gnu.org/philosophy/why-not-lgpl.html>. |
| 13308 |
</p> |
| 13309 |
|
| 13310 |
|
| 13311 |
|
| 13312 |
</div> |
| 13313 |
</div> |
| 13314 |
</div> |
| 13315 |
|
| 13316 |
|
| 13317 |
|
| 13318 |
</body> |
| 13319 |
</html> |