<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://miniscript.org/w/index.php?action=history&amp;feed=atom&amp;title=Square_brackets</id>
	<title>Square brackets - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://miniscript.org/w/index.php?action=history&amp;feed=atom&amp;title=Square_brackets"/>
	<link rel="alternate" type="text/html" href="http://miniscript.org/w/index.php?title=Square_brackets&amp;action=history"/>
	<updated>2026-04-13T11:55:03Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.34.0</generator>
	<entry>
		<id>http://miniscript.org/w/index.php?title=Square_brackets&amp;diff=1334&amp;oldid=prev</id>
		<title>Redspark at 02:33, 30 January 2025</title>
		<link rel="alternate" type="text/html" href="http://miniscript.org/w/index.php?title=Square_brackets&amp;diff=1334&amp;oldid=prev"/>
		<updated>2025-01-30T02:33:43Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 02:33, 30 January 2025&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l43&quot; &gt;Line 43:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 43:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Note that in the context of a map, the term &amp;quot;index&amp;quot; and &amp;quot;key&amp;quot; are synonyms.  But intrinsic functions like [[hasIndex]] and [[indexOf]] always refer to them as indexes, since those functions also apply to lists and strings.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Note that in the context of a map, the term &amp;quot;index&amp;quot; and &amp;quot;key&amp;quot; are synonyms.  But intrinsic functions like [[hasIndex]] and [[indexOf]] always refer to them as indexes, since those functions also apply to lists and strings.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[Category:Language]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Redspark</name></author>
		
	</entry>
	<entry>
		<id>http://miniscript.org/w/index.php?title=Square_brackets&amp;diff=531&amp;oldid=prev</id>
		<title>JoeStrout: Created page with &quot;Square brackets are used in MiniScript to ''index'' into a value — that is, to select just one element out of a collection of elements.  They are also used to slice lists an...&quot;</title>
		<link rel="alternate" type="text/html" href="http://miniscript.org/w/index.php?title=Square_brackets&amp;diff=531&amp;oldid=prev"/>
		<updated>2020-06-19T17:13:49Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;Square brackets are used in MiniScript to &amp;#039;&amp;#039;index&amp;#039;&amp;#039; into a value — that is, to select just one element out of a collection of elements.  They are also used to slice lists an...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Square brackets are used in MiniScript to ''index'' into a value — that is, to select just one element out of a collection of elements.  They are also used to slice lists and strings.&lt;br /&gt;
&lt;br /&gt;
== List Indexing and Slicing ==&lt;br /&gt;
&lt;br /&gt;
Given a list &amp;lt;c&amp;gt;a&amp;lt;/c&amp;gt;, square brackets can be used in several ways:&lt;br /&gt;
* &amp;lt;c&amp;gt;a[i]&amp;lt;/c&amp;gt; gets element ''i'' of the list.  If ''i'' is 0 or more, then this is the element with ''i'' elements to its left: the first one is &amp;lt;c&amp;gt;a[0]&amp;lt;/c&amp;gt;, the next one is &amp;lt;c&amp;gt;a[1]&amp;lt;/c&amp;gt;, and so on.  If ''i'' is negative, then it counts from the end of the list: &amp;lt;c&amp;gt;a[-1]&amp;lt;/c&amp;gt; gets the last element, &amp;lt;c&amp;gt;a[-2]&amp;lt;/c&amp;gt; gets the next-to-last one, etc.&lt;br /&gt;
 &lt;br /&gt;
* &amp;lt;c&amp;gt;a[i] = x&amp;lt;/c&amp;gt; replaces element ''i'' of the list with a new value ''x''.  The meaning of ''i'' here is exactly the same as above.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;c&amp;gt;a[i:j]&amp;lt;/c&amp;gt; gets a new list with elements made up a sub-range of ''a'': specifically, element ''i'' up to (but not including) element ''j''.  The meaning of both ''i'' and ''j'' is as above.  (This operation is known as ''slicing'' the list, and the resulting copy is sometimes called a ''slice''.)&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;c&amp;gt;a[i:]&amp;lt;/c&amp;gt; gets a new list made of elements ''i'' through the end of the list.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;c&amp;gt;a[:i]&amp;lt;/c&amp;gt; gets a new list made of elements from the beginning of the list up to (but not including) element ''i''.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;c&amp;gt;a[:]&amp;lt;/c&amp;gt; gets a new list containing all the same elements of ''a'' (and is a handy way to copy a list, in case you want to change the copy without affecting the original list).&lt;br /&gt;
&lt;br /&gt;
Note that you cannot assign to a slice of a list.  To replace a sub-range of a list you will need to add (concatenate) the part before the sub-range, your new middle, and the part after the sub-range.&lt;br /&gt;
&lt;br /&gt;
== String Indexing and Slicing ==&lt;br /&gt;
&lt;br /&gt;
Given a string &amp;lt;c&amp;gt;s&amp;lt;/c&amp;gt;, square brackets can be used in several ways:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;c&amp;gt;s[i]&amp;lt;/c&amp;gt; gets character ''i'' of the string.  If ''i'' is 0 or more, then this is the character with ''i'' characters to its left: the first one is &amp;lt;c&amp;gt;s[0]&amp;lt;/c&amp;gt;, the next one is &amp;lt;c&amp;gt;s[1]&amp;lt;/c&amp;gt;, and so on.  If ''i'' is negative, then it counts from the end of the string: &amp;lt;c&amp;gt;s[-1]&amp;lt;/c&amp;gt; gets the last character, &amp;lt;c&amp;gt;s[-2]&amp;lt;/c&amp;gt; gets the next-to-last one, etc.&lt;br /&gt;
 &lt;br /&gt;
* &amp;lt;c&amp;gt;s[i:j]&amp;lt;/c&amp;gt; gets a new string with characters made up a sub-range of ''s'': specifically, character ''i'' up to (but not including) character ''j''.  The meaning of both ''i'' and ''j'' is as above.  (This operation is known as ''slicing'' the string, and the resulting copy is sometimes called a ''slice''.)&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;c&amp;gt;s[i:]&amp;lt;/c&amp;gt; gets a new string made of characters ''i'' through the end of the list.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;c&amp;gt;s[:i]&amp;lt;/c&amp;gt; gets a new string made of characters from the beginning of the string up to (but not including) character ''i''.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;c&amp;gt;s[:]&amp;lt;/c&amp;gt; gets a new string containing all the same characters of ''n'' (but since strings are immutable, this is generally a pointless thing to do).&lt;br /&gt;
&lt;br /&gt;
Note that because strings are immutable (cannot be changed), you cannot replace an element of a string via indexing.  This is unlike lists or maps, which are mutable (can be changed).&lt;br /&gt;
&lt;br /&gt;
== Map Indexing ==&lt;br /&gt;
&lt;br /&gt;
Given a map &amp;lt;c&amp;gt;m&amp;lt;/c&amp;gt;, square brackets can be used in these ways:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;c&amp;gt;m[k]&amp;lt;/c&amp;gt; gets the value in the map associated with key ''k''.  (You may want to first check whether that key exists using [[hasIndex]].)&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;c&amp;gt;m[k] = x&amp;lt;/c&amp;gt; stores value ''x'' in the map, associated with key ''k''.  This replaces the previous value, if any, associated with ''k''.&lt;br /&gt;
&lt;br /&gt;
Note that in the context of a map, the term &amp;quot;index&amp;quot; and &amp;quot;key&amp;quot; are synonyms.  But intrinsic functions like [[hasIndex]] and [[indexOf]] always refer to them as indexes, since those functions also apply to lists and strings.&lt;/div&gt;</summary>
		<author><name>JoeStrout</name></author>
		
	</entry>
</feed>