{"id":10988,"date":"2025-01-26T16:37:27","date_gmt":"2025-01-26T16:37:27","guid":{"rendered":"https:\/\/putridparrot.com\/blog\/?p=10988"},"modified":"2025-01-26T16:37:27","modified_gmt":"2025-01-26T16:37:27","slug":"basic-use-of-the-elixir-interactive-shell","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/basic-use-of-the-elixir-interactive-shell\/","title":{"rendered":"Basic use of the Elixir interactive shell"},"content":{"rendered":"<p>If you&#8217;re wanting to play around with Elixir in a REPL you can use <em><a href=\"https:\/\/hexdocs.pm\/iex\/1.14.5\/IEx.html\" rel=\"noopener\" target=\"_blank\">iex<\/a><\/em>. <\/p>\n<p><em>Note: To exit <em>iex<\/em> just CTRL+C twice.<\/em><\/p>\n<p>Within the shell we can simply type in code on a line and press enter to evaluate it. So for example type <\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nle = &#x5B;1,10,20]\r\n<\/pre>\n<p>press enter and the shell will display the list now bound to the value <em>l<\/em>.<\/p>\n<p>Now type<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nlength(l)\r\n<\/pre>\n<p>and the shell should display 3, the length of the list.<\/p>\n<p>To get help from the shell, execute <\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nh()\r\n<\/pre>\n<p><strong>Compiling a module into iex<\/strong><\/p>\n<p>Whilst you&#8217;re developing your modules you might which to test them via the shell, in which case from you can load it when you start iex using (in this case my module in called math.ex)<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\niex math.ex\r\n<\/pre>\n<p>or if you&#8217;ve already started iex, simple use<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nc &quot;math.ex&quot;\r\n<\/pre>\n<p>The line above compiles your code and loads into iex so it&#8217;s now available to call from the shell.<\/p>\n<p>If you want to view the exports on a module (in this example on my Math module), use the command<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nexports(Math)\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;re wanting to play around with Elixir in a REPL you can use iex. Note: To exit iex just CTRL+C twice. Within the shell we can simply type in code on a line and press enter to evaluate it. So for example type le = &#x5B;1,10,20] press enter and the shell will display the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[730,732],"tags":[],"class_list":["post-10988","post","type-post","status-publish","format-standard","hentry","category-elixir","category-iex"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/10988","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=10988"}],"version-history":[{"count":3,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/10988\/revisions"}],"predecessor-version":[{"id":11237,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/10988\/revisions\/11237"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=10988"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=10988"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=10988"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}