blob: 357092f8e23dc23fad2ed1c38c95acfc87bb8ca4 [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001SYNOPSIS
Zesstra715ec202025-07-09 22:18:31 +02002 mixed arr[index]
3 int str[index]
MG Mud User88f12472016-06-24 23:31:02 +02004
Zesstra715ec202025-07-09 22:18:31 +02005 mixed * arr[from .. to]
6 string str[from .. to]
7 mixed m[key, from .. to]
MG Mud User88f12472016-06-24 23:31:02 +02008
Zesstra715ec202025-07-09 22:18:31 +02009DESCRIPTION
10 Return one element from a string/array (first form), or a slice
11 (substring resp. subarray) of a string/array/mapping (second form).
MG Mud User88f12472016-06-24 23:31:02 +020012
Zesstra715ec202025-07-09 22:18:31 +020013 The indexes <index>, <from> and <to> are numbered 0 to
14 strlen(str)-1, sizeof(arr)-1 resp. widthof(m)-1.
MG Mud User88f12472016-06-24 23:31:02 +020015
Zesstra715ec202025-07-09 22:18:31 +020016 If an index is written '<value', the value is counted from the
17 end of the string/array/mapping and is numbered 1 to strlen(str),
18 sizeof(arr) resp. widthof(m).
MG Mud User88f12472016-06-24 23:31:02 +020019
Zesstra715ec202025-07-09 22:18:31 +020020 If an index is written '>value', the value is counted from the
21 end of the string/array/mapping if it is negative (starting with
22 -1 for the last element), and from the beginning if it is positive
23 (starting with 0 for the first element).
MG Mud User88f12472016-06-24 23:31:02 +020024
Zesstra715ec202025-07-09 22:18:31 +020025 If <from> is omitted, it defaults to the beginning of the
26 string/array/mapping.
27 If <to> is omitted, it defaults to the beginning of the
28 string/array/mapping.
MG Mud User88f12472016-06-24 23:31:02 +020029
Zesstra715ec202025-07-09 22:18:31 +020030 In the first form, the <index> must be within the bounds of
31 the string/array, or a runtime error occurs.
32 In the second form, the indexes will be fitted to the bounds of
33 the string/array/mapping. If <from> is greater than <to>, or both
34 outside the bounds, an empty string/array ("" resp. ({})) will
35 be returned.
36
37 The closure notation is straightforward:
38
39 [index] -> ({'#[, arr, index })
40 [<index] -> ({'#[<, arr, index })
41 [>index] -> ({'#[>, arr, index })
42 [from..to] -> ({'#[..], arr, from, to })
43 [<from..to] -> ({'#[<..], arr, from, to })
44 [from..<to] -> ({'#[..<], arr, from, to })
45 [<from..<to] -> ({'#[<..<], arr, from, to })
46 [>from..to] -> ({'#[>..], arr, from, to })
47 [from..>to] -> ({'#[..>], arr, from, to })
48 [>from..<to] -> ({'#[>..<], arr, from, to })
49 [<from..>to] -> ({'#[<..>], arr, from, to })
50 [>from..>to] -> ({'#[>..>], arr, from, to })
51 [key,index] -> ({'#[,], m, index })
52 [key,<index] -> ({'#[,<], m, index })
53 [key,>index] -> ({'#[,>], m, index })
54 [key,from..to] -> ({'#[,..], m, from, to })
55 [key,<from..to] -> ({'#[,<..], m, from, to })
56 [key,from..<to] -> ({'#[,..<], m, from, to })
57 [key,<from..<to] -> ({'#[,<..<], m, from, to })
58 [key,>from..to] -> ({'#[,>..], m, from, to })
59 [key,from..>to] -> ({'#[,..>], m, from, to })
60 [key,>from..<to] -> ({'#[,>..<], m, from, to })
61 [key,<from..>to] -> ({'#[,<..>], m, from, to })
62 [key,>from..>to] -> ({'#[,>..>], m, from, to })
63
64EXAMPLES
MG Mud User88f12472016-06-24 23:31:02 +020065 foo = ({ 1, 2, 3, 4 }); str = "test";
66
67 foo[1] -> 1 str[1] -> 'e' == 101
68 foo[1..2] -> ({ 2, 3 }) str[1..2] -> "es"
69 foo[2..1] -> ({ }) str[2..1] -> ""
70 foo[0..<2] -> ({ 1, 2 }) str[0..<2] -> "tes"
MG Mud User88f12472016-06-24 23:31:02 +020071 foo[..<2] -> ({ 1, 2 }) str[..<2] -> "tes"
72 foo[<3..] -> ({ 2, 3, 4 }) str[<3..] -> "est"
73
Zesstra715ec202025-07-09 22:18:31 +020074 foo[1] = 5 -> foo == ({ 1, 5, 3, 4 })
75 foo[1..2] = ({ 5, 6, 7 }) -> foo == ({ 1, 5, 6, 7, 4 })
76 foo[1..2] = ({ }) -> foo == ({ 1, 4 })
MG Mud User88f12472016-06-24 23:31:02 +020077
Zesstra715ec202025-07-09 22:18:31 +020078 str[1] = 'a' -> str == "tast"
79 str[1..2] = "bar" -> str == "tbart"
80 str[1..2] = "" -> str == "tt"
MG Mud User88f12472016-06-24 23:31:02 +020081
Zesstra715ec202025-07-09 22:18:31 +020082HISTORY
83 slice_array() is the old form of the [] operator on arrays.
84 extract() is the old form of the [] operator on strings.
85 Both ARE NO LONGER SUPPORTED and should not be used anymore!
MG Mud User88f12472016-06-24 23:31:02 +020086
Zesstra715ec202025-07-09 22:18:31 +020087 The syntax for ``counting from last element'' has changed
88 between versions 3.1.J and 3.1.K from ``-1'' to ``<1''.
89 foo[0..-1] is now an empty string resp. array.
MG Mud User88f12472016-06-24 23:31:02 +020090
Zesstra715ec202025-07-09 22:18:31 +020091 LDMud 3.3 introduced the '>' indexing method.
92
93 LDMud 3.6.6 introduced range indexing for mappings.
94
95SEE ALSO
96 member(E), sizeof(E)
97