{"id":2593,"date":"2021-11-01T11:44:29","date_gmt":"2021-11-01T06:14:29","guid":{"rendered":"https:\/\/www.rangakrish.com\/?p=2593"},"modified":"2021-11-01T11:44:29","modified_gmt":"2021-11-01T06:14:29","slug":"implicit-indexing-and-slicing-in-newlisp","status":"publish","type":"post","link":"https:\/\/www.rangakrish.com\/index.php\/2021\/11\/01\/implicit-indexing-and-slicing-in-newlisp\/","title":{"rendered":"Implicit Indexing and Slicing in &#8220;newLisp&#8221;"},"content":{"rendered":"<p>In traditional <em><strong>Lisp<\/strong><\/em> (<em><strong>Common Lisp<\/strong><\/em>), when evaluating an S-expression list, the first element in the <em><strong>&#8220;functor&#8221;<\/strong><\/em> position must be a function or valid operator. <a href=\"http:\/\/www.newlisp.org\" target=\"_blank\" rel=\"noopener\"><em><strong>newLisp<\/strong><\/em><\/a>\u00a0relaxes this requirement and allows the first element to be a context symbol type, a list, an array, or an integer. For today&#8217;s discussion, let us ignore the context symbol, but look at examples of the other types.<\/p>\n<p>Let us start with the <em><strong>&#8220;List&#8221;<\/strong><\/em> type. Take a look at the following snippet:<\/p>\n<figure id=\"attachment_2594\" aria-describedby=\"caption-attachment-2594\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/list1.jpg?ssl=1\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" data-attachment-id=\"2594\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/11\/01\/implicit-indexing-and-slicing-in-newlisp\/list1\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/list1.jpg\" data-orig-size=\"466,219\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1635678497&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"List Indexing\" data-image-description=\"&lt;p&gt;List Indexing&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;List Indexing&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/list1.jpg\" class=\"wp-image-2594\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/list1.jpg?resize=500%2C235&#038;ssl=1\" alt=\"List Indexing\" width=\"500\" height=\"235\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/list1.jpg?resize=300%2C141&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/list1.jpg?w=466&amp;ssl=1 466w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2594\" class=\"wp-caption-text\"><strong>List Indexing<\/strong><\/figcaption><\/figure>\n<p>First, we assign to <em><strong>&#8220;list1&#8221;<\/strong><\/em> variable a list of symbols. Then we use the same variable in the <em><strong>&#8220;functor&#8221;<\/strong><\/em> position, followed by an integer argument. Even though <em><strong>&#8220;list1&#8221;<\/strong><\/em> is not a <em><strong>&#8220;function&#8221;<\/strong><\/em>, <em><strong>newLisp<\/strong><\/em> evaluates this S-expression, treating it as an <em><strong>&#8220;indexing&#8221;<\/strong><\/em> operation, returning the third element of the list (indices start from zero). An error is signalled when we index beyond the list size.<\/p>\n<p>We could have also used the built-in function <em><strong>&#8220;nth&#8221;<\/strong><\/em> to access the list element, but <em><strong>newLisp<\/strong><\/em> supports the above shortcut.<\/p>\n<figure id=\"attachment_2595\" aria-describedby=\"caption-attachment-2595\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/nth.jpg?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"2595\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/11\/01\/implicit-indexing-and-slicing-in-newlisp\/nth\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/nth.jpg\" data-orig-size=\"535,204\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1635754481&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Using &amp;#8220;nth&amp;#8221; Function\" data-image-description=\"&lt;p&gt;Using &amp;#8220;nth&amp;#8221; Function&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Using &amp;#8220;nth&amp;#8221; Function&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/nth.jpg\" class=\"wp-image-2595\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/nth.jpg?resize=500%2C191&#038;ssl=1\" alt=\"Using &quot;nth&quot; Function\" width=\"500\" height=\"191\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/nth.jpg?resize=300%2C114&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/nth.jpg?w=535&amp;ssl=1 535w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2595\" class=\"wp-caption-text\"><strong>Using &#8220;nth&#8221; Function<\/strong><\/figcaption><\/figure>\n<p>Here is another example involving a nested list:<\/p>\n<figure id=\"attachment_2596\" aria-describedby=\"caption-attachment-2596\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/list2.jpg?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"2596\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/11\/01\/implicit-indexing-and-slicing-in-newlisp\/list2\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/list2.jpg\" data-orig-size=\"468,271\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1635700196&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Indexing Nested Lists\" data-image-description=\"&lt;p&gt;Indexing Nested Lists&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Indexing Nested Lists&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/list2.jpg\" class=\"wp-image-2596\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/list2.jpg?resize=500%2C290&#038;ssl=1\" alt=\"Indexing Nested Lists\" width=\"500\" height=\"290\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/list2.jpg?resize=300%2C174&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/list2.jpg?w=468&amp;ssl=1 468w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2596\" class=\"wp-caption-text\"><strong>Indexing Nested Lists<\/strong><\/figcaption><\/figure>\n<p>As you can see, it is possible to access an element of the nested list in two ways. The last example shows how we can directly use a list literal in the first argument position.<\/p>\n<p>What about <em><strong>&#8220;arrays&#8221;<\/strong><\/em>? Let us create two one-dimensional arrays:<\/p>\n<figure id=\"attachment_2598\" aria-describedby=\"caption-attachment-2598\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/array1.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2598\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/11\/01\/implicit-indexing-and-slicing-in-newlisp\/array1\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/array1.jpg\" data-orig-size=\"426,103\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1635604928&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Indexing Arrays\" data-image-description=\"&lt;p&gt;Indexing Arrays&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Indexing Arrays&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/array1.jpg\" class=\"wp-image-2598\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/array1.jpg?resize=500%2C121&#038;ssl=1\" alt=\"Indexing Arrays\" width=\"500\" height=\"121\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/array1.jpg?resize=300%2C73&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/array1.jpg?w=426&amp;ssl=1 426w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2598\" class=\"wp-caption-text\"><strong>Creating Arrays<\/strong><\/figcaption><\/figure>\n<p>The second array above has a nested item that has 3 elements in it.<\/p>\n<p>We can access the array elements this way:<\/p>\n<figure id=\"attachment_2599\" aria-describedby=\"caption-attachment-2599\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/array2.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2599\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/11\/01\/implicit-indexing-and-slicing-in-newlisp\/array2\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/array2.jpg\" data-orig-size=\"413,147\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1635605281&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Array Indexing\" data-image-description=\"&lt;p&gt;Array Indexing&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Array Indexing&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/array2.jpg\" class=\"wp-image-2599\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/array2.jpg?resize=500%2C178&#038;ssl=1\" alt=\"Array Indexing\" width=\"500\" height=\"178\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/array2.jpg?resize=300%2C107&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/array2.jpg?w=413&amp;ssl=1 413w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2599\" class=\"wp-caption-text\"><strong>Array Indexing<\/strong><\/figcaption><\/figure>\n<p>What about multi-dimensional arrays? The logic is quite similar.<\/p>\n<figure id=\"attachment_2600\" aria-describedby=\"caption-attachment-2600\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/array3.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2600\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/11\/01\/implicit-indexing-and-slicing-in-newlisp\/array3\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/array3.jpg\" data-orig-size=\"497,119\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1635606154&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Multi-Dimensional Arrays\" data-image-description=\"&lt;p&gt;Multi-Dimensional Arrays&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Multi-Dimensional Arrays&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/array3.jpg\" class=\"wp-image-2600\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/array3.jpg?resize=500%2C120&#038;ssl=1\" alt=\"Multi-Dimensional Arrays\" width=\"500\" height=\"120\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/array3.jpg?resize=300%2C72&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/array3.jpg?w=497&amp;ssl=1 497w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2600\" class=\"wp-caption-text\"><strong>Multi-Dimensional Arrays<\/strong><\/figcaption><\/figure>\n<p>The above creates and uses a <em><strong>2 by 3<\/strong><\/em> array.<\/p>\n<p>It is possible to use a -ve index:<\/p>\n<figure id=\"attachment_2601\" aria-describedby=\"caption-attachment-2601\" style=\"width: 375px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/array4.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2601\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/11\/01\/implicit-indexing-and-slicing-in-newlisp\/array4\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/array4.jpg\" data-orig-size=\"245,113\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1635608986&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Negative Index\" data-image-description=\"&lt;p&gt;Negative Index&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Negative Index&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/array4.jpg\" class=\"wp-image-2601\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/array4.jpg?resize=375%2C173&#038;ssl=1\" alt=\"Negative Index\" width=\"375\" height=\"173\" \/><\/a><figcaption id=\"caption-attachment-2601\" class=\"wp-caption-text\"><strong>Negative Index<\/strong><\/figcaption><\/figure>\n<p>The index <em><strong>&#8220;-1&#8221;<\/strong><\/em> represents the <em><strong>last element<\/strong><\/em> of the array.<\/p>\n<p>Since <em><strong>Strings<\/strong><\/em> are implicitly arrays, we can use the same indexing mechanism:<\/p>\n<figure id=\"attachment_2602\" aria-describedby=\"caption-attachment-2602\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/str1.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2602\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/11\/01\/implicit-indexing-and-slicing-in-newlisp\/str1\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/str1.jpg\" data-orig-size=\"339,161\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1635609978&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Indexing Strings\" data-image-description=\"&lt;p&gt;Indexing Strings&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Indexing Strings&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/str1.jpg\" class=\"wp-image-2602\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/str1.jpg?resize=500%2C237&#038;ssl=1\" alt=\"Indexing Strings\" width=\"500\" height=\"237\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/str1.jpg?resize=300%2C142&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/str1.jpg?w=339&amp;ssl=1 339w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2602\" class=\"wp-caption-text\"><strong>Indexing Strings<\/strong><\/figcaption><\/figure>\n<p>A natural extension of <em><strong>&#8220;implicit indexing&#8221;<\/strong><\/em> that we have seen so far is <em><strong>&#8220;implicit slicing&#8221;<\/strong><\/em>. Slicing comes into picture when we use an <em><strong>integer<\/strong><\/em> in the <em><strong>&#8220;functor&#8221;<\/strong><\/em> position.<\/p>\n<p>Check this out:<\/p>\n<figure id=\"attachment_2603\" aria-describedby=\"caption-attachment-2603\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/slice1.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2603\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/11\/01\/implicit-indexing-and-slicing-in-newlisp\/slice1\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/slice1.jpg\" data-orig-size=\"353,223\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1635678656&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Slicing\" data-image-description=\"&lt;p&gt;Slicing&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Slicing&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/slice1.jpg\" class=\"wp-image-2603\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/slice1.jpg?resize=500%2C316&#038;ssl=1\" alt=\"Slicing\" width=\"500\" height=\"316\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/slice1.jpg?resize=300%2C190&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/slice1.jpg?w=353&amp;ssl=1 353w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2603\" class=\"wp-caption-text\"><strong>Slicing A List<\/strong><\/figcaption><\/figure>\n<p>The first expression returns a <em><strong>sublist<\/strong><\/em>\u00a0starting from the <em><strong>second<\/strong><\/em>\u00a0element of the given list. Another integer argument, if provided, specifies the number elements to extract from the starting position.<\/p>\n<p>The following shows slicing applied on arrays and strings:<\/p>\n<figure id=\"attachment_2604\" aria-describedby=\"caption-attachment-2604\" style=\"width: 550px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/slice2.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2604\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/11\/01\/implicit-indexing-and-slicing-in-newlisp\/slice2\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/slice2.jpg\" data-orig-size=\"626,220\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1635700408&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Slicing Arrays and Strings\" data-image-description=\"&lt;p&gt;Slicing Arrays and Strings&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Slicing Arrays and Strings&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/slice2.jpg\" class=\"wp-image-2604\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/slice2.jpg?resize=550%2C193&#038;ssl=1\" alt=\"Slicing Arrays and Strings\" width=\"550\" height=\"193\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/slice2.jpg?resize=300%2C105&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/slice2.jpg?w=626&amp;ssl=1 626w\" sizes=\"(max-width: 550px) 100vw, 550px\" \/><\/a><figcaption id=\"caption-attachment-2604\" class=\"wp-caption-text\"><strong>Slicing Arrays and Strings<\/strong><\/figcaption><\/figure>\n<p>Of course, we can also use integer variables instead of <em><strong>literals<\/strong><\/em> for slicing, as shown below:<\/p>\n<figure id=\"attachment_2605\" aria-describedby=\"caption-attachment-2605\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/slice3.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2605\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/11\/01\/implicit-indexing-and-slicing-in-newlisp\/slice3\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/slice3.jpg\" data-orig-size=\"346,114\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1635757205&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Index Need Not Be A Literal\" data-image-description=\"&lt;p&gt;Index Need Not Be A Literal&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Index Need Not Be A Literal&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/slice3.jpg\" class=\"size-medium wp-image-2605\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/slice3.jpg?resize=300%2C99&#038;ssl=1\" alt=\"Index Need Not Be A Literal\" width=\"300\" height=\"99\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/slice3.jpg?resize=300%2C99&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/slice3.jpg?w=346&amp;ssl=1 346w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-2605\" class=\"wp-caption-text\"><strong>Index Need Not Be A Literal<\/strong><\/figcaption><\/figure>\n<p>According to the <a href=\"http:\/\/www.newlisp.org\/ExpressionEvaluation.html\" target=\"_blank\" rel=\"noopener\"><em><strong>official documentation<\/strong><\/em><\/a>, <em><strong>implicit indexing<\/strong><\/em>\u00a0is optional (we can always use <em><strong>&#8220;nth&#8221;<\/strong><\/em>, etc.) and when used, it improves performance.<\/p>\n<p>Have a great week ahead!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In traditional Lisp (Common Lisp), when evaluating an S-expression list, the first element in the &#8220;functor&#8221; position must be a function or valid operator. newLisp\u00a0relaxes this requirement and allows the first element to be a context symbol type, a list, an array, or an integer. For today&#8217;s discussion, let us ignore the context symbol, but [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[297,17],"tags":[299,298],"class_list":["post-2593","post","type-post","status-publish","format-standard","hentry","category-newlisp","category-programming","tag-implicit-indexing","tag-newlisp"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9OLnF-FP","jetpack-related-posts":[{"id":2620,"url":"https:\/\/www.rangakrish.com\/index.php\/2021\/11\/28\/understanding-the-unify-function-in-newlisp\/","url_meta":{"origin":2593,"position":0},"title":"Understanding the &#8220;unify&#8221; Function in &#8220;newLisp&#8221;","author":"admin","date":"November 28, 2021","format":false,"excerpt":"Unification between two symbolic expressions involves finding substitutions for variables (if any) in the expressions such that the expressions match\u00a0after applying the substitutions. This is a powerful idea and is quite common in logic programming languages such as Prolog. Interestingly, \"newLisp\" has a buil-in function called \"unify\" that can be\u2026","rel":"","context":"In &quot;newLisp&quot;","block_context":{"text":"newLisp","link":"https:\/\/www.rangakrish.com\/index.php\/category\/newlisp\/"},"img":{"alt_text":"Unifying \"atomic\" expressions","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/Example1-1-300x106.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":2632,"url":"https:\/\/www.rangakrish.com\/index.php\/2021\/12\/12\/the-net-eval-function-in-newlisp\/","url_meta":{"origin":2593,"position":1},"title":"The &#8220;net-eval&#8221; Function in &#8220;newLisp&#8221;","author":"admin","date":"December 12, 2021","format":false,"excerpt":"One of the cool\u00a0things about \"newLisp\" is that despite its small fooprint, it comes with a lot of functionality built-in. For instance, if you are interested in distributed computing, it is pretty easy to get started. In this article, I will touch upon the net-eval function\u00a0that allows an expression to\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"Two Servers","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/12\/Servers-300x253.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":2580,"url":"https:\/\/www.rangakrish.com\/index.php\/2021\/10\/17\/some-interesting-features-of-newlisp\/","url_meta":{"origin":2593,"position":2},"title":"Some Interesting Features of &#8220;newLisp&#8221;","author":"admin","date":"October 17, 2021","format":false,"excerpt":"newLisp is a general-purpose scripting language with a Lisp-like syntax. That is one of the reasons I wanted to take a closer look at the language. It has a compact footprint, small resource requirements, and can easily be embedded. It is available on multiple platforms, and on my Windows machine,\u2026","rel":"","context":"In &quot;newLisp&quot;","block_context":{"text":"newLisp","link":"https:\/\/www.rangakrish.com\/index.php\/category\/newlisp\/"},"img":{"alt_text":"\"amb\" Function","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/example1.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":2610,"url":"https:\/\/www.rangakrish.com\/index.php\/2021\/11\/14\/currying-in-newlisp\/","url_meta":{"origin":2593,"position":3},"title":"Currying in &#8220;newLisp&#8221;","author":"admin","date":"November 14, 2021","format":false,"excerpt":"In the last two articles, I discussed what I believe are some interesting features of \"newLisp\". Today's topic is \"currying\", another useful feature. For those of you who are new to this topic, I had earlier written about \"currying\" in Mathematica here. You may want to take a look at\u2026","rel":"","context":"In &quot;newLisp&quot;","block_context":{"text":"newLisp","link":"https:\/\/www.rangakrish.com\/index.php\/category\/newlisp\/"},"img":{"alt_text":"Example of Currying","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/11\/Example1-300x141.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":2645,"url":"https:\/\/www.rangakrish.com\/index.php\/2021\/12\/25\/calling-lisp-functions-from-d-language\/","url_meta":{"origin":2593,"position":4},"title":"Calling Lisp Functions from D Language","author":"admin","date":"December 25, 2021","format":false,"excerpt":"After exploring \"newLisp\" in the past few posts, I would like to start looking at the \"D Programming Language\"\u00a0(DLang). DLang\u00a0has been around since 2001. It was originally created by Walter Bright and later Andrei Alexandrescu joined the team in 2007. The main inspiration for DLang was C++, although it uses\u2026","rel":"","context":"In &quot;D Language&quot;","block_context":{"text":"D Language","link":"https:\/\/www.rangakrish.com\/index.php\/category\/d-language\/"},"img":{"alt_text":"Lisp Function Called from D","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/12\/Lisp-300x107.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/12\/Lisp-300x107.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/12\/Lisp-300x107.jpg?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":263,"url":"https:\/\/www.rangakrish.com\/index.php\/2016\/06\/17\/pattern-matching-with-optima-lisp-library-part-2\/","url_meta":{"origin":2593,"position":5},"title":"Pattern Matching with Optima Lisp Library &#8211; Part 2","author":"admin","date":"June 17, 2016","format":false,"excerpt":"Let us continue where we left off last time. List Patterns If the incoming argument is a list, then we can use two types of list patterns to match the list elements, namely, list and list*. (match '(a b c)\u00a0 ((list 'a 'b X) X)) => c This list pattern\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/2593","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/comments?post=2593"}],"version-history":[{"count":0,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/2593\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/media?parent=2593"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/categories?post=2593"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/tags?post=2593"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}