blob: a59696a52d40985f9cc5e9b92c4d1ae93a487f5c [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001SYNOPSIS
2 mixed arr[index];
3 int str[index];
4
5 *mixed arr[from .. to];
6 string str[from .. to];
7
8BESCHREIBUNG
9 Liefert ein Element aus einem Array oder String (erste Form), oder
10 eine Teilmenge (zweite Form).
11
12 Die Indizes <index>, <from> und <to> sind durchnummeriert von 0 bis
13 strlen(<str>)-1 bzw. sizeof(<arr>)-1. Wenn ein <index> als '<wert'
14 geschrieben wird, wird der Wert vom Ende des Stings / Arrays her
15 gezaehlt. Dabei wird nummeriert von 1 bis strlen(<str>) bzw.
16 sizeof(<arr>). Wird <from> weggelassen, beginnt die Teilmenge mit
17 dem ersten Element. Wird <to> weggelassen, endet die Teilmenge mit
18 dem letzten Element.
19
20 In der ersten Form muss <index> innerhalb der Grenzen des Strings /
21 Arrays sein, sonst wird ein Laufzeitfehler (RTE) verursacht. In der
22 zweiten Form werden die Indizes an die Groesse des Strings / Arrays
23 angepasst. Wenn <from> groesser ist als <to> oder beide ausserhalb
24 der Groesse des Strings / Arrays liegen, wird ein leerer String ""
25 bzw. ein leeres Array ({}) zurueck geliefert.
26
27 Die Notation als Closure ist entsprechend:
28
29 [index] -> ({'#[, arr, index })
30 [<index] -> ({'#[<, arr, index })
31 [from..to] -> ({'#[..], arr, from, to })
32 [<from..to] -> ({'#[<..], arr, from, to })
33 [from..<to] -> ({'#[..<], arr, from, to })
34 [<from..<to] -> ({'#[<..<], arr, from, to })
35
36BEISPIELE
37 foo = ({ 1, 2, 3, 4 }); str = "test";
38
39 foo[1] -> 1 str[1] -> 'e' == 101
40 foo[1..2] -> ({ 2, 3 }) str[1..2] -> "es"
41 foo[2..1] -> ({ }) str[2..1] -> ""
42 foo[0..<2] -> ({ 1, 2 }) str[0..<2] -> "tes"
43
44 foo[..<2] -> ({ 1, 2 }) str[..<2] -> "tes"
45 foo[<3..] -> ({ 2, 3, 4 }) str[<3..] -> "est"
46
47 foo[1] = 5 -> foo == ({ 1, 5, 3, 4 })
48 foo[1..2] = ({ 5, 6, 7 }) -> foo == ({ 1, 5, 6, 7, 4 })
49 foo[1..2] = ({ }) -> foo == ({ 1, 4 })
50
51 str[1] = 'a' -> str == "tast"
52 str[1..2] = "bar" -> str == "tbart"
53 str[1..2] = "" -> str == "tt"
54
55AENDERUNGEN
56 slice_array() ist die alte Form der []-Operatoren fuer Arrays,
57 extract() ist die alte Form der []-Operatoren fuer Strings.
58 BEIDE VARIANTEN SIND VERALTET, WERDEN NICHT MEHR UNTERSTUETZT UND
59 SOLLTEN DESHALB NICHT MEHR VERWENDET WERDEN.
60
61 Die Syntax fuer 'rueckwaerts zaehlen vom letzten Element' hat sich von
62 Version 3.1.J zu 3.1.K geaendert von '-1' zu '<1'. Auch ist seit dann
63 foo[0..-1] ein leeres Array bzw. ein leerer String.
64
65SIEHE AUCH
66 member(E), sizeof(E), slice_array(E)