| 1 |
<html><head><meta name="robots" content="index,follow"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| 2 |
<title>part#</title> |
| 3 |
<style> |
| 4 |
td { padding-left: 5pt; padding-right: 5pt; } |
| 5 |
th { padding-left: 5pt; padding-right: 5pt; } |
| 6 |
code { white-space: pre-wrap; } |
| 7 |
dd { white-space: pre-wrap; } |
| 8 |
</style> |
| 9 |
</head><body bgcolor="#FFFFFF"> |
| 10 |
|
| 11 |
<table border=0 cellpadding=0 cellspacing=0><tr><td bgcolor="#CCCC00"><table border=4 cellpadding=9><tr><td align=middle bgcolor="#000000"><font face="Monaco,Courier" size=6 color="#999900"><b> |
| 12 |
part# |
| 13 |
</b></font></table></table> |
| 14 |
<p>A function that can be used in <a href="Formulas.html">Formulas</a>.</p> |
| 15 |
<h2>Syntax and semantics</h2> |
| 16 |
<dl> |
| 17 |
<dt><b><code><font size=+1>part#</font></code></b> (<i><code><font size=+1>vector#</font></code></i>, <i><code><font size=+1>from</font></code></i>, <i><code><font size=+1>to</font></code></i>) |
| 18 |
<dd>compute a subsequence of elements of a vector.</dd> |
| 19 |
</dl> |
| 20 |
<h2>Examples</h2> |
| 21 |
<code> <a href="_assert_.html">assert</a> part# ({ 7, 4, 99, 103, 1 }, 3, 4) = { 99, 103 }<br></code> |
| 22 |
<h2>Examples of error messages</h2> |
| 23 |
<p>Checks on the number of arguments (always has to be 3):</p> |
| 24 |
<code> asserterror The function “part#” requires exactly three arguments<br></code> |
| 25 |
<code> ... (namely a vector, a starting index, and an end index),<br></code> |
| 26 |
<code> ... not the 0 given.<br></code> |
| 27 |
<code> a# = part# ()<br></code> |
| 28 |
<code> <br></code> |
| 29 |
<code> asserterror The function “part#” requires exactly three arguments<br></code> |
| 30 |
<code> ... (namely a vector, a starting index, and an end index),<br></code> |
| 31 |
<code> ... not the 5 given.<br></code> |
| 32 |
<code> a# = part# (7, 8, 9, "hello", "world")<br></code> |
| 33 |
<p>Checks on the types of the arguments (always has to be vector, number, number):</p> |
| 34 |
<code> asserterror The first argument of the function “part#” should be<br></code> |
| 35 |
<code> ... a numeric vector, not a number.<br></code> |
| 36 |
<code> a# = part# (2, 4, { 5, 6, 7, 9, 8 })<br></code> |
| 37 |
<code> <br></code> |
| 38 |
<code> asserterror The first argument of the function “part#” should be<br></code> |
| 39 |
<code> ... a numeric vector, not a string.<br></code> |
| 40 |
<code> a# = part# ("hello", 4, { 5, 6, 7, 9, 8 })<br></code> |
| 41 |
<code> <br></code> |
| 42 |
<code> asserterror The second argument of the function “part#” should be<br></code> |
| 43 |
<code> ... a number (the starting index), not a string.<br></code> |
| 44 |
<code> a# = part# ({ 5, 6, 7, 9, 8 }, "hello", 4)<br></code> |
| 45 |
<code> <br></code> |
| 46 |
<code> asserterror The second argument of the function “part#” should be<br></code> |
| 47 |
<code> ... a number (the starting index), not a numeric vector.<br></code> |
| 48 |
<code> a# = part# ({ 5, 6, 7, 9, 8 }, { 0 }, 4)<br></code> |
| 49 |
<code> <br></code> |
| 50 |
<code> asserterror The third argument of the function “part#” should be<br></code> |
| 51 |
<code> ... a number (the end index), not a string.<br></code> |
| 52 |
<code> a# = part# ({ 5, 6, 7, 9, 8 }, 4, "hello")<br></code> |
| 53 |
<code> <br></code> |
| 54 |
<code> asserterror The third argument of the function “part#” should be<br></code> |
| 55 |
<code> ... a number (the end index), not a numeric vector.<br></code> |
| 56 |
<code> a# = part# ({ 5, 6, 7, 9, 8 }, 4, { 0 })<br></code> |
| 57 |
<p>Finally the checks on the preconditions of the arguments: both element numbers should be within bounds:</p> |
| 58 |
<code> asserterror The second argument of the function “part#” (the starting index)<br></code> |
| 59 |
<code> ... should (after rounding) be a positive whole number, not -3.<br></code> |
| 60 |
<code> a# = part# ({ 5, 6, 7, 9, 8 }, -2.98, 0)<br></code> |
| 61 |
<code> <br></code> |
| 62 |
<code> asserterror The second argument of the function “part#” (the starting index)<br></code> |
| 63 |
<code> ... should (after rounding) be a positive whole number, not 0.<br></code> |
| 64 |
<code> a# = part# ({ 5, 6, 7, 9, 8 }, 0, 0)<br></code> |
| 65 |
<code> <br></code> |
| 66 |
<code> asserterror The second argument of the function “part#” (the starting index)<br></code> |
| 67 |
<code> ... should (after rounding) be at most the number of elements (5), not 99.<br></code> |
| 68 |
<code> a# = part# ({ 10, 6, 7, 9, 8 }, 99, 0)<br></code> |
| 69 |
<code> <br></code> |
| 70 |
<code> asserterror The second argument of the function “part#” (the starting index)<br></code> |
| 71 |
<code> ... should (after rounding) be at most the number of elements (5), not 6.<br></code> |
| 72 |
<code> a# = part# ({ 10, 6, 7, 9, 8 }, 5.5, 0)<br></code> |
| 73 |
<code> <br></code> |
| 74 |
<code> asserterror The third argument of the function “part#” (the end index)<br></code> |
| 75 |
<code> ... should (after rounding) be a positive whole number, not -3.<br></code> |
| 76 |
<code> a# = part# ({ 10, 6, 7, 9, 8 }, 3, -2.98)<br></code> |
| 77 |
<code> <br></code> |
| 78 |
<code> asserterror The third argument of the function “part#” (the end index)<br></code> |
| 79 |
<code> ... should (after rounding) be a positive whole number, not 0.<br></code> |
| 80 |
<code> a# = part# ({ 10, 6, 7, 9, 8 }, 3, 0)<br></code> |
| 81 |
<code> <br></code> |
| 82 |
<code> asserterror The third argument of the function “part#” (the end index)<br></code> |
| 83 |
<code> ... should (after rounding) be at most the number of elements (5), not 99.<br></code> |
| 84 |
<code> a# = part# ({ 10, 6, 7, 9, 8 }, 3, 99)<br></code> |
| 85 |
<code> <br></code> |
| 86 |
<code> asserterror The third argument of the function “part#” (the end index)<br></code> |
| 87 |
<code> ... should (after rounding) be at most the number of elements (5), not 6.<br></code> |
| 88 |
<code> a# = part# ({ 10, 6, 7, 9, 8 }, 3, 5.5)<br></code> |
| 89 |
<h3>Links to this page</h3> |
| 90 |
<ul> |
| 91 |
<li><a href="What_was_new_in_6_4_.html">What was new in 6.4?</a> |
| 92 |
</ul> |
| 93 |
<hr> |
| 94 |
<address> |
| 95 |
<p>© Paul Boersma 2023</p> |
| 96 |
</address> |
| 97 |
</body> |
| 98 |
</html> |