|
367 | 367 | <li><a class="link" href="#faq_indexed_from_one"><b>
|
368 | 368 | Why are strings indexed from one?
|
369 | 369 | </b></a></li>
|
| 370 | +<li><a class="link" href="#faq_minimum_array_index"><b> |
| 371 | +Are arrays indexed from one? |
| 372 | +</b></a></li> |
370 | 373 | <li><a class="link" href="#faq_comparisons"><b>
|
371 | 374 | How are comparisons done in Seed7?
|
372 | 375 | </b></a></li>
|
@@ -889,12 +892,12 @@ <h2>
|
889 | 892 | </h3></a><hr />
|
890 | 893 | <p>
|
891 | 894 | The Seed7 package contains more than 100000 lines of C and more
|
892 |
| -than 400000 lines of Seed7. For version 2025-01-11 the number of lines is: |
| 895 | +than 400000 lines of Seed7. For version 2025-03-25 the number of lines is: |
893 | 896 | </p><dl><dd><table border="0" cellspacing="0">
|
894 |
| - <tr><td align="right">184871</td> <td width="20"></td> <td>C source files (*.c)</td></tr> |
895 |
| - <tr><td align="right"> 13806</td> <td width="20"></td> <td>C header files (*.h)</td></tr> |
896 |
| - <tr><td align="right">267373</td> <td width="20"></td> <td>Seed7 source files (*.sd7)</td></tr> |
897 |
| - <tr><td align="right">197752</td> <td width="20"></td> <td>Seed7 library/include files (*.s7i)</td></tr> |
| 897 | + <tr><td align="right">188316</td> <td width="20"></td> <td>C source files (*.c)</td></tr> |
| 898 | + <tr><td align="right"> 14009</td> <td width="20"></td> <td>C header files (*.h)</td></tr> |
| 899 | + <tr><td align="right">272719</td> <td width="20"></td> <td>Seed7 source files (*.sd7)</td></tr> |
| 900 | + <tr><td align="right">198222</td> <td width="20"></td> <td>Seed7 library/include files (*.s7i)</td></tr> |
898 | 901 | </table></dd></dl><p>
|
899 | 902 | C code (*.c and *.h files) can be divided into the following areas:
|
900 | 903 | </p><dl><dd><table border="0" cellspacing="0">
|
@@ -1805,7 +1808,10 @@ <h2>
|
1805 | 1808 | type annotations are optional they are not considered when the program is
|
1806 | 1809 | written, but at a later time (maybe by someone else). If the type annotations
|
1807 | 1810 | are not 100% correct unnecessary conversions might take place, which slow
|
1808 |
| -down the program. |
| 1811 | +down the program. Python has type annotations and this would allow writing |
| 1812 | +performance critical code in Python instead of C/C++. But in practice the |
| 1813 | +type annotations of Python did not lead to a situation where C/C++ code is |
| 1814 | +not needed. |
1809 | 1815 | </p></div>
|
1810 | 1816 |
|
1811 | 1817 | <div><br /><a name="faq_first_class_types_and_type_checking"><h3>How can static type checking work if types are first-class objects?
|
@@ -1877,7 +1883,7 @@ <h2>
|
1877 | 1883 | </pre><p>
|
1878 | 1884 | triggers the error:
|
1879 | 1885 | </p><pre class="indent">
|
1880 |
| -*** tst249.sd7(6):52: <span class="link">Match for {var intArrayType : {arr } is {[ ] {1 , 2 } } } failed</span> |
| 1886 | +*** tst249.sd7(6):57: <span class="link">Match for {var intArrayType : {arr } is {[ ] {1 , 2 } } } failed</span> |
1881 | 1887 | var intArrayType: arr is [](1, 2);
|
1882 | 1888 | </pre><p>
|
1883 | 1889 | A <tt><span class="keywd">local</span></tt> declaration block is parsed completely before it is executed.
|
@@ -1907,7 +1913,7 @@ <h2>
|
1907 | 1913 | </pre><p>
|
1908 | 1914 | triggers the error:
|
1909 | 1915 | </p><pre class="indent">
|
1910 |
| -*** tst309.sd7(4):52: <span class="link">Match for {func result var func type: <BLOCKOBJECT> ({array type: <TYPEOBJECT> ({array string }) }) : {data } is {0 times {0 times "" } } begin {data := {3 times {2 times value } } } end func } failed</span> |
| 1916 | +*** tst309.sd7(4):57: <span class="link">Match for {func result var func type: <BLOCKOBJECT> ({array type: <TYPEOBJECT> ({array string }) }) : {data } is {0 times {0 times "" } } begin {data := {3 times {2 times value } } } end func } failed</span> |
1911 | 1917 | const func array array string: test (in string: value) is func
|
1912 | 1918 | </pre><p>
|
1913 | 1919 | The reason is: The two occurrences of <tt><span class="type">array</span> <span class="type">array</span> <span class="type">string</span></tt> are considered
|
@@ -2070,10 +2076,10 @@ <h2>
|
2070 | 2076 | </pre><p>
|
2071 | 2077 | This overloading of the result type triggers compile-time errors:
|
2072 | 2078 | </p><pre class="indent">
|
2073 |
| -*** tst508.sd7(4):34: <a name="faq_OBJTWICEDECLARED_example"></a><span class="link">Redeclaration of "f (val char: x)"</span> |
| 2079 | +*** tst508.sd7(4):43: <a name="faq_OBJTWICEDECLARED_example"></a><span class="link">Redeclaration of "f (val char: x)"</span> |
2074 | 2080 | const func string: f (in char: x) is return str(x);
|
2075 | 2081 | ----------------------------------------------------^
|
2076 |
| -*** tst508.sd7(3):35: <a name="faq_PREVIOUS_DECLARATION_example"></a><span class="link">Previous declaration of "f (val char: x)"</span> |
| 2082 | +*** tst508.sd7(3):44: <a name="faq_PREVIOUS_DECLARATION_example"></a><span class="link">Previous declaration of "f (val char: x)"</span> |
2077 | 2083 | const func integer: f (in char: x) is return ord(x);
|
2078 | 2084 | </pre><p>
|
2079 | 2085 | Assume return type overloading would be allowed. In this case the expression
|
@@ -2156,7 +2162,7 @@ <h2>
|
2156 | 2162 | A variable declaration with <tt><span class="op">:=</span></tt> would need a different syntax definition.
|
2157 | 2163 | An attempt to define this new syntax leads to an error:
|
2158 | 2164 | </p><pre class="indent">
|
2159 |
| -*** tst356.sd7(3):42: <a name="faq_FALSE_INFIX_PRIORITY_example"></a><span class="link">":=" redeclared with infix priority 127 not 20</span> |
| 2165 | +*** tst356.sd7(3):52: <a name="faq_REDECLARED_INFIX_PRIORITY_example"></a><span class="link">":=" redeclared with infix priority 127 not 20</span> |
2160 | 2166 | syntax expr: .var.(). : .(expr). := .(expr) is -> 40;
|
2161 | 2167 | ---------------------------------------------------------^
|
2162 | 2168 | </pre><p>
|
@@ -2190,14 +2196,14 @@ <h2>
|
2190 | 2196 | Since the syntax pattern would expect a <tt><span class="op">:=</span></tt> after <tt>number <span class="op">:=</span> 42;</tt> this
|
2191 | 2197 | would lead to the error:
|
2192 | 2198 | </p><pre class="indent">
|
2193 |
| -*** tst356.sd7(8):47: <a name="faq_EXPECTED_SYMBOL_example"></a><span class="link">":=" expected found "begin"</span> |
| 2199 | +*** tst356.sd7(8):40: <a name="faq_EXPECTED_SYMBOL_example"></a><span class="link">":=" expected found "begin"</span> |
2194 | 2200 | begin
|
2195 | 2201 | -------^
|
2196 | 2202 | </pre><p>
|
2197 | 2203 | To avoid this misinterpretation, the syntax of a variable declaration
|
2198 | 2204 | with <tt><span class="op">:=</span></tt> is rejected beforehand with:
|
2199 | 2205 | </p><pre class="indent">
|
2200 |
| -*** tst356.sd7(3):42: <span class="link">":=" redeclared with infix priority 127 not 20</span> |
| 2206 | +*** tst356.sd7(3):52: <span class="link">":=" redeclared with infix priority 127 not 20</span> |
2201 | 2207 | </pre><p>
|
2202 | 2208 | Languages with hard-coded syntax analysis use a trick to allow the same
|
2203 | 2209 | symbol for assignments and initialization. They read the parameter
|
@@ -2405,6 +2411,52 @@ <h2>
|
2405 | 2411 | zero has been introduced.
|
2406 | 2412 | </p></div>
|
2407 | 2413 |
|
| 2414 | +<div><br /><a name="faq_minimum_array_index"><h3>Are arrays indexed from one? |
| 2415 | +</h3></a><hr /> |
| 2416 | +<p> |
| 2417 | +You can set the minimum index of an array. Standard <tt><span class="type">array</span></tt> types like |
| 2418 | +<tt><span class="type">array</span> <span class="type">integer</span></tt> do not define a minimum index or the size of the array. |
| 2419 | +Instead of being defined by the type the minimum index and the size are |
| 2420 | +part of the array value. For an <tt><span class="type">array</span> <span class="type">integer</span></tt> the minimum index could be |
| 2421 | +0, 1, 1000 or even -3. An <tt><span class="type">array</span> <span class="type">integer</span></tt> consisting of 5 elements, each |
| 2422 | +with the value 123, is created with: |
| 2423 | +</p><pre class="indent"> |
| 2424 | +5 <span class="op">times</span> 123 |
| 2425 | +</pre><p> |
| 2426 | +In this case the minimum index is 1. The same array with a minimum index |
| 2427 | +of 0 is created with: |
| 2428 | +</p><pre class="indent"> |
| 2429 | +[0 .. 4] <span class="op">times</span> 123 |
| 2430 | +</pre><p> |
| 2431 | +or |
| 2432 | +</p><pre class="indent"> |
| 2433 | +[0 <span class="op">len</span> 5] <span class="op">times</span> 123 |
| 2434 | +</pre><p> |
| 2435 | +The minimum index and the size of <tt><span class="type">array</span></tt> types like <tt><span class="type">array</span> <span class="type">integer</span></tt> may be |
| 2436 | +changed at run-time. Functions like <span class="func">minIdx</span>, <span class="func">maxIdx</span> and <span class="func">length</span> can be used to |
| 2437 | +determine the current properties of an array value. |
| 2438 | +</p><p> |
| 2439 | +In base idx <tt><span class="type">arrays</span></tt> the minimum index is part of the type. E.g.: |
| 2440 | +</p><pre class="indent"> |
| 2441 | +<span class="keywd">const</span> <span class="type">type</span>: nameList <span class="keywd">is</span> <span class="type">array</span> [1 ..] <span class="type">string</span>; <span class="comment"># minimum index is 1</span> |
| 2442 | +<span class="keywd">const</span> <span class="type">type</span>: huffmanSymbolArray <span class="keywd">is</span> <span class="type">array</span> [0 ..] <span class="type">integer</span>; <span class="comment"># minimum index is 0</span> |
| 2443 | +</pre><p> |
| 2444 | +The size of a base idx <tt><span class="type">array</span></tt> may be changed at run-time. |
| 2445 | +</p><p> |
| 2446 | +In fixed size <tt><span class="type">arrays</span></tt> the minimum index and the size are part |
| 2447 | +of the type. E.g.: |
| 2448 | +</p><pre class="indent"> |
| 2449 | +<span class="keywd">const</span> <span class="type">type</span>: dataBlockType <span class="keywd">is</span> <span class="type">array</span> [64] <span class="type">integer</span>; <span class="comment"># minimum index is 1 and maximum index is 64</span> |
| 2450 | +<span class="keywd">const</span> <span class="type">type</span>: keccakStateType <span class="keywd">is</span> <span class="type">array</span> [0 .. 24] <span class="type">bin64</span>; <span class="comment"># minimum index is 0 and maximum index is 24</span> |
| 2451 | +</pre><p> |
| 2452 | +Finally, there are indexed <tt><span class="type">arrays</span></tt> where the index may be any type that |
| 2453 | +can be converted to an integer. E.d: |
| 2454 | +</p><pre class="indent"> |
| 2455 | +<span class="keywd">const</span> <span class="type">type</span>: charIndexArray <span class="keywd">is</span> <span class="type">array</span> [char] <span class="type">bigInteger</span>; |
| 2456 | +</pre><p> |
| 2457 | +A <tt><span class="type">hash</span></tt> can be used if the index type does not map to an <tt><span class="type">integer</span></tt>. |
| 2458 | +</p></div> |
| 2459 | + |
2408 | 2460 | <div><br /><a name="faq_comparisons"><h3>How are comparisons done in Seed7?
|
2409 | 2461 | </h3></a><hr />
|
2410 | 2462 | <p>
|
@@ -3773,7 +3825,7 @@ <h2>
|
3773 | 3825 | match fails, because a corresponding declaration is not found, you will get
|
3774 | 3826 | an error like:
|
3775 | 3827 | </p><pre class="indent">
|
3776 |
| -*** chkloop.sd7(35):52: <span class="link">Match for {while "X" do {1 + 2 } end while } failed</span> |
| 3828 | +*** chkloop.sd7(35):57: <span class="link">Match for {while "X" do {1 + 2 } end while } failed</span> |
3777 | 3829 | </pre><p>
|
3778 | 3830 | If all expressions are found in the dictionary the matching process leads to an
|
3779 | 3831 | enriched AST, the <a class="link" href="#faq_bytecode">call-code</a>. Call-code can be executed by the <a class="link" href="#faq_interpreter">interpreter</a>.
|
|
0 commit comments