<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.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="https://wiki.miniscript.org/w/index.php?action=history&amp;feed=atom&amp;title=Square_brackets"/>
	<link rel="alternate" type="text/html" href="https://wiki.miniscript.org/w/index.php?title=Square_brackets&amp;action=history"/>
	<updated>2026-11-16T15:13:53Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.34.0</generator>
	<entry>
		<id>https://wiki.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="https://wiki.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=&#039;diff-marker&#039;&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=&#039;diff-marker&#039;&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=&#039;diff-marker&#039;&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=&#039;diff-marker&#039;&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=&#039;diff-marker&#039;&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=&#039;diff-marker&#039;&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>https://wiki.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 &#039;&#039;index&#039;&#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...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.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 &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 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 &amp;#039;&amp;#039;i&amp;#039;&amp;#039; of the list.  If &amp;#039;&amp;#039;i&amp;#039;&amp;#039; is 0 or more, then this is the element with &amp;#039;&amp;#039;i&amp;#039;&amp;#039; 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 &amp;#039;&amp;#039;i&amp;#039;&amp;#039; 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 &amp;#039;&amp;#039;i&amp;#039;&amp;#039; of the list with a new value &amp;#039;&amp;#039;x&amp;#039;&amp;#039;.  The meaning of &amp;#039;&amp;#039;i&amp;#039;&amp;#039; 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 &amp;#039;&amp;#039;a&amp;#039;&amp;#039;: specifically, element &amp;#039;&amp;#039;i&amp;#039;&amp;#039; up to (but not including) element &amp;#039;&amp;#039;j&amp;#039;&amp;#039;.  The meaning of both &amp;#039;&amp;#039;i&amp;#039;&amp;#039; and &amp;#039;&amp;#039;j&amp;#039;&amp;#039; is as above.  (This operation is known as &amp;#039;&amp;#039;slicing&amp;#039;&amp;#039; the list, and the resulting copy is sometimes called a &amp;#039;&amp;#039;slice&amp;#039;&amp;#039;.)&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 &amp;#039;&amp;#039;i&amp;#039;&amp;#039; 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 &amp;#039;&amp;#039;i&amp;#039;&amp;#039;.&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 &amp;#039;&amp;#039;a&amp;#039;&amp;#039; (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 &amp;#039;&amp;#039;i&amp;#039;&amp;#039; of the string.  If &amp;#039;&amp;#039;i&amp;#039;&amp;#039; is 0 or more, then this is the character with &amp;#039;&amp;#039;i&amp;#039;&amp;#039; 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 &amp;#039;&amp;#039;i&amp;#039;&amp;#039; 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 &amp;#039;&amp;#039;s&amp;#039;&amp;#039;: specifically, character &amp;#039;&amp;#039;i&amp;#039;&amp;#039; up to (but not including) character &amp;#039;&amp;#039;j&amp;#039;&amp;#039;.  The meaning of both &amp;#039;&amp;#039;i&amp;#039;&amp;#039; and &amp;#039;&amp;#039;j&amp;#039;&amp;#039; is as above.  (This operation is known as &amp;#039;&amp;#039;slicing&amp;#039;&amp;#039; the string, and the resulting copy is sometimes called a &amp;#039;&amp;#039;slice&amp;#039;&amp;#039;.)&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 &amp;#039;&amp;#039;i&amp;#039;&amp;#039; 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 &amp;#039;&amp;#039;i&amp;#039;&amp;#039;.&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 &amp;#039;&amp;#039;n&amp;#039;&amp;#039; (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 &amp;#039;&amp;#039;k&amp;#039;&amp;#039;.  (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 &amp;#039;&amp;#039;x&amp;#039;&amp;#039; in the map, associated with key &amp;#039;&amp;#039;k&amp;#039;&amp;#039;.  This replaces the previous value, if any, associated with &amp;#039;&amp;#039;k&amp;#039;&amp;#039;.&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>