{"id":360,"date":"2024-10-06T08:40:46","date_gmt":"2024-10-06T07:40:46","guid":{"rendered":"http:\/\/monkey.ploogie.co.uk\/?page_id=360"},"modified":"2024-10-06T08:40:46","modified_gmt":"2024-10-06T07:40:46","slug":"mwnci-set-function","status":"publish","type":"page","link":"https:\/\/monkey.ploogie.co.uk\/index.php\/mwnci-set-function\/","title":{"rendered":"Mwnci set() Function"},"content":{"rendered":"<h2><span id=\"Syntax\" class=\"mw-headline\">Syntax<\/span><\/h2>\n<p>set(<i><b>hash<\/b><\/i>, <i><b>key<\/b><\/i>, <i><b>value<\/b><\/i>)<\/p>\n<p>set(<i><b>array<\/b><\/i>, <i><b>index<\/b><\/i>, <i><b>value<\/b><\/i>)<\/p>\n<h2><span id=\"Description\" class=\"mw-headline\">Description<\/span><\/h2>\n<p>A hash is a key\/value container, but not that keys may only be of type <i>boolean<\/i>, <i>int<\/i>, and <i>string<\/i>.<\/p>\n<p>Updating a hash is done via the <i>set()<\/i> function, but note that this returns a new updated hash rather than changing in-place.<\/p>\n<p>Updating an array or strings works in much the same way by using the index of each rather than a key value.<\/p>\n<p><em>*This isn&#8217;t particularly efficient, and instructions s such as\u00a0 a[10]=100\u00a0 rather than a=set(a,10,100) are being worked on.<br \/>\n<\/em><\/p>\n<h2><span id=\"Example\" class=\"mw-headline\">Example<\/span><\/h2>\n<pre>a={\"name\":\"mwnci\",\r\n           true:1,\r\n           7:\"seven\"}\r\nprintln(a)\r\na=set(a, 8, \"eight\")\r\na=set(a, \"name\", \"derek\")\r\nprintln(a)\r\n\r\nMyArray=[1,2,3,4]\r\nMyArray=set(MyArray,0,6)\r\nprintln(MyArray)\r\n\r\nMyString=\"Fobar\"\r\nMyString=set(MyString,1,\"u\")\r\nprintln(MyString)\r\n\r\n\r\n\r\n{8: eight, true: 1, 7: seven, name: derek}\r\n[6, 2, 3, 4]\r\nFubar\r\n\r\n\r\n\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Syntax set(hash, key, value) set(array, index, value) Description A hash is a key\/value container, but not that keys may only be of type boolean, int, and string. Updating a hash is done via the set() function, but note that this returns a new updated hash rather than changing in-place. Updating an array or strings works &hellip; <a href=\"https:\/\/monkey.ploogie.co.uk\/index.php\/mwnci-set-function\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Mwnci set() Function&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-360","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/pages\/360","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/comments?post=360"}],"version-history":[{"count":1,"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/pages\/360\/revisions"}],"predecessor-version":[{"id":361,"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/pages\/360\/revisions\/361"}],"wp:attachment":[{"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/media?parent=360"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}