<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Камило Куньа</title>
    <description>The latest articles on DEV Community by Камило Куньа (@cazevedo).</description>
    <link>https://dev.to/cazevedo</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F848209%2F2e3d5fa1-a6ca-4e8a-93f9-3ee86c85772c.jpg</url>
      <title>DEV Community: Камило Куньа</title>
      <link>https://dev.to/cazevedo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/cazevedo"/>
    <language>en</language>
    <item>
      <title>Learning Clojure, part VII</title>
      <dc:creator>Камило Куньа</dc:creator>
      <pubDate>Wed, 18 May 2022 00:22:53 +0000</pubDate>
      <link>https://dev.to/cazevedo/learning-clojure-part-vii-4i52</link>
      <guid>https://dev.to/cazevedo/learning-clojure-part-vii-4i52</guid>
      <description>&lt;p&gt;We learned how to use functions and some basic data structures, now we finally will start to make things a little more interesting as define values and functions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Symbols
&lt;/h2&gt;

&lt;p&gt;Symbols are a different kind of value, they are a name that represents a value. We can define symbols using the &lt;strong&gt;def&lt;/strong&gt; function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;trainer&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Green"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; #'user/trainer&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;team&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Pidgeotto"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Rattata"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Abra"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Charmander"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; #'user/team&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When we evaluate values we get them as return, as an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="s"&gt;"Red"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; "Red"&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; 8&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But symbols evaluate for the value it's referring to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="n"&gt;trainer&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; "Green"&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="n"&gt;team&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; ["Pidgeotto" "Rattata" "Abra" "Charmander"]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When we define symbols we're not binding it directly to a value, instead, it does it through a Var a mechanism that is used to refer to values.&lt;/p&gt;

&lt;p&gt;When we defined our symbols &lt;code&gt;trainer&lt;/code&gt; and &lt;code&gt;team&lt;/code&gt; you should notice that it returned the name with &lt;code&gt;#'user/&lt;/code&gt; in front of it. It's saying we defined a var that's in the &lt;code&gt;user&lt;/code&gt; namespace and that's because symbols are bound to a namespace and we can call them in the fully qualified name (we just don't have to do it when we're in the same namespace of the symbol):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="n"&gt;user/trainer&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; "Green"&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="n"&gt;user/team&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; ["Pidgeotto" "Rattata" "Abra" "Charmander"]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Is important that you have the attention that REPL always starts in the &lt;strong&gt;user&lt;/strong&gt; namespace if you running these commands from a project maybe you have a different one declared at the beginning of the file. We can also redefine or define new namespaces as we see in the next parts.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  let
&lt;/h2&gt;

&lt;p&gt;Sometimes we want to define symbols that are just used locally instead of as global values in the namespace and we use the &lt;strong&gt;let&lt;/strong&gt; function to do it, this function receives a vector with a pair number of elements ordered as symbols and values that are only available inside the same block (parenthesis) as let.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;region&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Kanto"&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="n"&gt;place&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="s"&gt;"Route 1"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"You are in "&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;place&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;" of the region "&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;region&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; "You are in Route 1 of the region Kanto"&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="n"&gt;region&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; Syntax error compiling at (REPL:0:0).&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;;         =&amp;gt; Unable to resolve symbol: region in this context&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We'll use let a lot when we're defining our functions. Defining local variables helps a lot in the legibility of our code since it helps to figure out what each value means.&lt;/p&gt;

&lt;h2&gt;
  
  
  Functions
&lt;/h2&gt;

&lt;p&gt;As we have seen until this point we can evoke functions using forms (also called expressions) that have the syntax &lt;code&gt;(operator arg arg args...)&lt;/code&gt;, but it's time to learn how to define our functions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Anonymous functions
&lt;/h3&gt;

&lt;p&gt;Sometimes we just need a function that we need to pass as a parameter or just use briefly and they're the most basic use of functions, as they will be used just once we don't name them so they're now as anonymous functions.&lt;/p&gt;

&lt;p&gt;We can define an anonymous function using the &lt;strong&gt;fn&lt;/strong&gt; function that receives a vector with the parameters and then the function definition.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="c1"&gt;;; How define an anonymous function&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;fn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt; 
  &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;println&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Making a vector..."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; #object[user$eval2048$fn__2049 0x6cce008e "user$eval2048$fn__2049@6cce008e"]&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="c1"&gt;;; How to call an anonymous function&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="k"&gt;fn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
   &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;println&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Making a vector..."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
   &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"The answer is "&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; Making a vector...&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;;         =&amp;gt; ["The answer is " 42]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Clojure doesn't have any kind of instruction on what is the return of a function, instead, the last value of the body of the function is returned from the function (as the vector in our example above). &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Functions always return some value in Clojure (even if it's a &lt;strong&gt;nil&lt;/strong&gt; value).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Shorthand anonymous functions
&lt;/h3&gt;

&lt;p&gt;Is possible to use &lt;strong&gt;#&lt;/strong&gt; in front of the parenthesis to define an anonymous function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;#&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Hello "&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Clojure!"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; "Hello Clojure!"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Is also possible to use % for shorthand as a parameter.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;#&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Hello "&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;%&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Camilo"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; "Hello Camilo"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the function expects multiple parameters is possible to number % as %1, %2...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;#&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;Math/pow&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;%1&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;%2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; 256.0&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Naming functions
&lt;/h3&gt;

&lt;p&gt;We can use the &lt;strong&gt;def&lt;/strong&gt; function to bind an anonymous function (that is a value) to a symbol and it will help us to call them as many times we want intuitively.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;sum-numbers&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;fn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;reduce&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;+&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; #'user/sum-numbers&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;sum-numbers&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; 21&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;sum-numbers&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; 32&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;user/sum-numbers&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;14&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;39&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;43&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;-60&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;21&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;83&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; 140&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&amp;amp;&lt;/strong&gt; is a special form in Clojure that is used to package the rest of the parameters in a vector. So in parameter definition [x y &amp;amp; z], this function will have 2 parameters x and y, and all other values passed after it will be in a vector called z. While in our case [&amp;amp; args] we packed all parameters in a vector called args.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Defining functions with defn
&lt;/h3&gt;

&lt;p&gt;There's syntactic sugar for defining functions in a more readable way is the &lt;strong&gt;defn&lt;/strong&gt;, you can think of it as &lt;code&gt;(+ def fn) =&amp;gt; defn&lt;/code&gt;. The defn gets as parameters a symbol, a vector of the function parameters, and the body of the function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="c1"&gt;;; Function definition with defn&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;name&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="s"&gt;"Optional docstring that describes what this function does."&lt;/span&gt;&lt;span class="w"&gt; 
  &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="n"&gt;...params&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="c1"&gt;;; example&lt;/span&gt;&lt;span class="w"&gt;
 &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;sum-evens&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
   &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;-&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;filter&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;even?&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;reduce&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;+&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; #'user/sum-evens&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Functions with multiple arities
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Arity&lt;/strong&gt; is the number of arguments or operands taken by a function.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We can specify that a function can have multiple parameter possibilities, for this instead of passing a vector of parameters we will wrap each definition in a &lt;strong&gt;form&lt;/strong&gt; where each receives a pair with a vector and the definition, for this work each definition has to be different from other.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;make-point&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;]))&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;make-point&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; [5 0]&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;make-point&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; [5 4]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  See you soon!
&lt;/h3&gt;

&lt;p&gt;Now we're starting to have fun, with functions we can make a lot of useful things and I challenge you to start doing it. It's a good time to build simple functions that do things like flip a number order or a fizzbuzz exercise.&lt;/p&gt;

&lt;p&gt;In the next chapters, we will continue to explore Clojure collections and learn how to use Hash-Maps to structure our data.&lt;/p&gt;

</description>
      <category>clojure</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>functional</category>
    </item>
    <item>
      <title>GambiConf — Why do we need a new tech event?</title>
      <dc:creator>Камило Куньа</dc:creator>
      <pubDate>Wed, 11 May 2022 15:39:29 +0000</pubDate>
      <link>https://dev.to/cazevedo/gambiconf-why-do-we-need-a-new-tech-event-4h5c</link>
      <guid>https://dev.to/cazevedo/gambiconf-why-do-we-need-a-new-tech-event-4h5c</guid>
      <description>&lt;p&gt;&lt;strong&gt;GambiConf&lt;/strong&gt; is the event I’ve always desired to happen, and it fits a specific unmet demand in tech conferences.&lt;/p&gt;

&lt;p&gt;Tech events like Code BEAM, BrazilJS, Strange Loop Conference, and GOTO Conference are great, but they usually end up fitting into two categories:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;its a conference focused on an environment (e.g., Code BEAM is about languages that run on BEAM, BrazilJS about JS and web in general)&lt;/li&gt;
&lt;li&gt;its a conference focused on forefront technologies and research, normally useful for industry (e.g., Strange Loop Conference and GOTO Conference)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It’s all good. If you’re looking for cutting-edge technology check out the GOTO Conference playlist. If you’re curious about the latest internet developments, then you’ll enjoy the BrazilJS playlist.&lt;/p&gt;

&lt;p&gt;But it’s missing a vital thing: we are people. &lt;strong&gt;We like to do 4fun projects. We like to develop pet projects exploring random things just for the sake of curiosity.&lt;/strong&gt; We also want to share our achievements. But unfortunately, it’s harder to find a place to share them.&lt;/p&gt;

&lt;p&gt;Pet projects usually aren’t focused on being used in the industry, thus serious events focused on the industry likely won’t accept them.&lt;br&gt;
Another feature that makes it harder to talk about random subjects is the technology requirement. Let’s say that I want to talk about how to build a computer using water — but since it isn’t related to any programming language or environment, events focused on these features often won’t accept it.&lt;br&gt;
Sometimes you can try to comply: suppose you got to run DOOM in a PDF file. It’s fun, and you want to share it. Then you notice that the PyCon conference is coming up. Since you used a Python script to achieve it, you can try to apply it to PyCon… but since the proposal is outside the audience’s normal expectations, there may not be much interest.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GambiConf is the solution!&lt;/strong&gt; This is an event for mind-blowing personal projects and random computer subjects that are fun. We focus more on the purpose of the presented projects, the unique nature of the sessions, and what one can learn from a random, very unusual idea.&lt;/p&gt;

&lt;p&gt;If someone needs to quench their thirst for curiosity, they can rely on GambiConf. It’s also the place to be inspired for their next personal project.&lt;/p&gt;

&lt;p&gt;These kinds of unusual talks are helpful to learn a new topic. For example, a talk about running DOOM in a PDF file can cover how the PDF format works, its specs, other related formats, etc. A talk about making a computer using water can cover what is computation itself, explain the Antikythera mechanism, and so on.&lt;/p&gt;

&lt;p&gt;Of course, there are events with a purpose similar to GambiConf. As far as I know, the closest is &lt;strong&gt;!!Con&lt;/strong&gt;. It’s a place to find fun talks and crazy personal projects that surprise you. But its talks are limited to 10 minutes. It’s good for getting some highlights, but someone can learn a lot more from a random topic that takes time for the speaker to explain in more detail. That’s why in GambiConf, the speaker has the freedom to decide on the length of their talk. As a result, GambiConf not only fits short talks like !!Con does, but also talks that explore a broader subject.&lt;br&gt;
I would also like to also mention &lt;strong&gt;SIGBOVIK&lt;/strong&gt;, which is like when someone took the joke too seriously. They publish a “paper” with all the crazy ideas and have a fun “academic congress”. The diverse subjects presented at this event have a close spirit that I want to bring to GambiConf.&lt;br&gt;
You can check the &lt;a href="https://www.youtube.com/channel/UC2kxl-dcUYQQvTCuQtfuChQ/videos"&gt;!!Con YouTube channel&lt;/a&gt; and the &lt;a href="http://sigbovik.org/"&gt;annals of the previous SIGBOVIK &lt;/a&gt;editions.&lt;/p&gt;

&lt;p&gt;I love both events. They inspired me a lot to make GambiConf.&lt;br&gt;
In the end, GambiConf is a mix of these events, my desire to have more events unrelated to the industry, focused on 4fun talks, and flexible time slots for speakers to cover the subject as far as they want.&lt;/p&gt;

&lt;p&gt;In the first edition of GambiConf, we achieved this goal, and we had a couple of fun talks covering many subjects with an excellent technical level. I would like to highlight some of them (all in Portuguese):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Theory and research in the computing field, covering mind-blowing topics: &lt;a href="https://youtu.be/UWiXNTdmL2Q"&gt;How to build computers using only water&lt;/a&gt;, and &lt;a href="https://youtu.be/hiPrQ7-oKdo"&gt;Computational creativity&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Fun personal projects: &lt;a href="https://youtu.be/_-o3ToBC0AI"&gt;How to run DOOM on an oscilloscope&lt;/a&gt;, &lt;a href="https://youtu.be/ZZUJRp8qJ24"&gt;Making your own printer driver&lt;/a&gt;, &lt;a href="https://youtu.be/hXEZP7uEZ1c"&gt;Weather station using JS only&lt;/a&gt;, and &lt;a href="https://youtu.be/kQcWbhaxCCA"&gt;Let’s be creative using hardware + emulators&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Innovative solutions for a real problem: &lt;a href="https://youtu.be/UO274qxCmQk"&gt;Self-Man-in-the-Middle&lt;/a&gt;, &lt;a href="https://youtu.be/I2k1_cUanMc"&gt;Google Sheets, a CMS with potential&lt;/a&gt;, and &lt;a href="https://youtu.be/soAyXnrBQlI"&gt;Segfault as Optimization&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The first GambiConf edition was in Portuguese since it was focused on a Brazilian audience (that’s also why the mascot is a golden lion tamarin). Since it had fantastic feedback, I decided to expand it to Europe, now in English. GambiConf is a good way to encourage the culture of making 4fun projects with computers, learning random subjects, and sharing them. As far as I know, there is currently no event like this in Europe, since both !!Con and SIGBOVIK are USA-based.&lt;/p&gt;

&lt;p&gt;If GambiConf sounds fun to you, you are invited to apply to the CFP and be present to watch the talks. &lt;strong&gt;Let’s make computing more fun!&lt;/strong&gt;&lt;/p&gt;





&lt;ul&gt;
&lt;li&gt;Check our site: &lt;a href="https://gambiconf.dev/"&gt;https://gambiconf.dev/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Follow us on Twitter: &lt;a href="https://twitter.com/gambiconf"&gt;https://twitter.com/gambiconf&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Facebook page: &lt;a href="https://www.facebook.com/GambiConf-102543485504335"&gt;https://www.facebook.com/GambiConf-102543485504335&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Linkedin page: &lt;a href="https://www.linkedin.com/company/gambiconf"&gt;https://www.linkedin.com/company/gambiconf&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>techtalks</category>
      <category>programming</category>
      <category>braziliandevs</category>
    </item>
    <item>
      <title>Learning Clojure, part VI</title>
      <dc:creator>Камило Куньа</dc:creator>
      <pubDate>Fri, 06 May 2022 02:14:36 +0000</pubDate>
      <link>https://dev.to/cazevedo/learning-clojure-part-vi-47kj</link>
      <guid>https://dev.to/cazevedo/learning-clojure-part-vi-47kj</guid>
      <description>&lt;p&gt;We already learned how to use lists and the importance of this data structure in Clojure in the &lt;a href="https://dev.to/cazevedo/learning-clojure-part-v-2bl3"&gt;previous post&lt;/a&gt;. Now we gonna learn another important data structure: Vector.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are vectors?
&lt;/h2&gt;

&lt;p&gt;Vectors as lists are immutable persistent data collections that can hold any value. They can be created using the &lt;strong&gt;vec&lt;/strong&gt; function passing a collection of values or passing the values directly between square brackets.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="c1"&gt;;; (vec collection)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;vec&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;'&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Red"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Green"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Blue"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; ["Red" "Green" "Blue"]&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Gold"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Silver"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Crystal"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; ["Gold" "Silver" "Crystal"]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Vectors vs Lists
&lt;/h2&gt;

&lt;p&gt;Both vectors and lists are collections of data, but they differ a lot in how each one of them works. The first main difference you probably notice between them is while lists are written using parenthesis, vectors are written using square brackets.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="o"&gt;'&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"List"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; ("List" 1 2 3)&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Vector"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; ["Vector" 1 2 3]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Looking now they seem to do the same thing, but the data structure underlying these collections are different and have a lot of differences in practical use.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;class&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;'&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"List"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; clojure.lang.PersistentList&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Vector"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; clojure.lang.PersistentVector&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While lists, as we seem, are noncontinuous values in memory that hold a value and a reference to the next value, vectors are values that are continuous in memory so the elements are indexed and can be fast accessed by their index position using the function &lt;strong&gt;nth&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="c1"&gt;;; (nth collection index)&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;nth&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Charmander"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Pikachu"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Buterfree"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; "Charmander"&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;nth&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Charmander"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Pikachu"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Buterfree"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; "Buterfree"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Py3hzqOQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ee7fox7isavatukbqz5v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Py3hzqOQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ee7fox7isavatukbqz5v.png" alt="The image shows a vector with five strings represented as a continuous tape with each index pointing to the segment where the next value beggins" width="700" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;Image&lt;/strong&gt;: "Vectors representation" made by the author is copyleft material under unlicense.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Adding values
&lt;/h2&gt;

&lt;p&gt;Another great difference between them is when we use the &lt;strong&gt;conj&lt;/strong&gt; function to add an element to the collection because the function will add the element in faster way to the collection:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In &lt;strong&gt;lists&lt;/strong&gt; is faster to add a new element to the &lt;strong&gt;beginning&lt;/strong&gt; since that to do it it's not necessary to go through the entire list to add it in another position.&lt;/li&gt;
&lt;li&gt;In &lt;strong&gt;vectors&lt;/strong&gt;, the element is added in the &lt;strong&gt;last position&lt;/strong&gt; since it just gets the last index and adds it after. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--s16dfKuQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vkuu1lgsady510ow22wt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--s16dfKuQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vkuu1lgsady510ow22wt.png" alt="The image represent the conj function and each square is a different value, when an element is added in a list it is added in beginning and when an element is added in a vector it is added in the last" width="705" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;Image&lt;/strong&gt;: "Conj vector vs list" made by the author is copyleft material under unlicense.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We can see this with some examples:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;conj&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="o"&gt;'&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Charmander"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Pikachu"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Buterfree"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Zubat"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; ("Zubat" "Charmander" "Pikachu" "Buterfree")&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;conj&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Charmander"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Pikachu"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Buterfree"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Zubat"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; ["Charmander" "Pikachu" "Buterfree" "Zubat"]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Vectors and Lists
&lt;/h2&gt;

&lt;p&gt;We can use the &lt;strong&gt;nth&lt;/strong&gt; to efficiently access a value by its position, but we can also use any of the functions we see in lists before as well. They can be used to iterate over the vector as we can do with lists and other collections.&lt;/p&gt;

&lt;h3&gt;
  
  
  first
&lt;/h3&gt;

&lt;p&gt;The first function returns the element at the beginning of the vector.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;first&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Brock"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Misty"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Lt. Surge"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Erika"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; "Brock"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  second
&lt;/h3&gt;

&lt;p&gt;The second function returns the second element of the vector.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;second&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Brock"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Misty"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Lt. Surge"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Erika"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; "Misty"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  last
&lt;/h3&gt;

&lt;p&gt;The last function returns the element at the end of the vector.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;last&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Brock"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Misty"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Lt. Surge"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Erika"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; "Erika"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  rest
&lt;/h3&gt;

&lt;p&gt;The rest functions return the vector as a list without the first element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;rest&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Brock"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Misty"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Lt. Surge"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Erika"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; ("Misty" "Lt. Surge" "Erika")&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  When we should use lists over vectors?
&lt;/h2&gt;

&lt;p&gt;If you intend to add and retrieve values at the beginning or at the end of the collection all the time, then a list will be far more efficient than a vector.&lt;/p&gt;

&lt;p&gt;On another side, if you need to add and retrieve values in the middle or in indexed positions then a vector will be far more efficient than a list.&lt;/p&gt;

&lt;p&gt;You should consider it when choosing which of them you will use, as general advice usually vectors are more frequently used than lists in most cases.&lt;/p&gt;

&lt;h2&gt;
  
  
  See you in the next part!
&lt;/h2&gt;

&lt;p&gt;Having 2 different collections that look so similar and work so different can be a little confusing at begging especially if you don't know how these data structures are made but don't worry this will become natural as you get used to Clojure. &lt;/p&gt;

</description>
      <category>clojure</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Learning Clojure, part V</title>
      <dc:creator>Камило Куньа</dc:creator>
      <pubDate>Tue, 03 May 2022 19:11:15 +0000</pubDate>
      <link>https://dev.to/cazevedo/learning-clojure-part-v-2bl3</link>
      <guid>https://dev.to/cazevedo/learning-clojure-part-v-2bl3</guid>
      <description>&lt;p&gt;In the &lt;a href="https://dev.to/cazevedo/learning-clojure-part-iv-16hl"&gt;previous part&lt;/a&gt; we learnt what are forms, how Clojure evaluates them into values and how to return code as data. Now we gonna learn about a fundamental underlying data structure behind all of it: the list.&lt;/p&gt;

&lt;h2&gt;
  
  
  The meaning of being LISP
&lt;/h2&gt;

&lt;p&gt;The name LISP derives from "LISt Processor" and the reason for it is because everything in the language is in fact a list. What we call as a "list" is in fact the Linked List data structure that is represented in Clojure and all other historically LISPs as values between parenthesis separated by a space.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"This"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"is"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"a"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"list"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As we can see the forms that compose the language syntax are a linked list with a function as the first element that is applied in all the remaining elements from the list.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ltYMVjd_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ntr4q875gmezu84ry7el.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ltYMVjd_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ntr4q875gmezu84ry7el.png" alt="The image shows the first element of the list being applied to the remaining ones in the list. Also show the linked list of a form with each element as a value and a pointer to the position of the next" width="705" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;Image&lt;/strong&gt;: "Forms as linked lists" made by the author is copyleft material under unlicense.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"This "&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"is"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;" a "&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"list"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; "This is a list"&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;apply&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"This "&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"is"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;" a "&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"list"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; "This is a list"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This linked list is formed with pairs of elements e.g. (1 (2 (3 ()))) that usually are called cons. In most LISPs implementations cons are a structure of a pair of elements (A.B) in Clojure the underlying structure are Seqs that we'll see later, but the language has some syntax tricks so we call it cons as well and that's what we'll use for now.&lt;/p&gt;

&lt;p&gt;We can create lists as creating cons cells where each one receives the value of the element as A and the next cell as B in (A.B):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;cons&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"This"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;cons&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"is"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;cons&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"a"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;cons&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"list"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;'&lt;/span&gt;&lt;span class="p"&gt;()))))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; ("This" "is" "a" "list")&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As we can see the last element of each list is a nil cell '() that represents the end of the list and it's ignored when we print all elements since it's just an empty value.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating lists of values
&lt;/h2&gt;

&lt;p&gt;Since forms are part of the structure of the language we cannot just create a list of values in code mode since Clojure evaluates every list as a form.&lt;/p&gt;

&lt;p&gt;If we try to simply enter our list on REPL we'll get an error:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"This"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"is"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"a"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"list"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; Execution error (ClassCastException) at user/eval2051 (REPL:1).&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; =&amp;gt; class java.lang.String cannot be cast to class clojure.lang.IFn (java.lang.String is in module java.base of loader 'bootstrap'; clojure.lang.IFn is in unnamed module of loader 'bootstrap')&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Most times you see errors about &lt;strong&gt;clojure.lang.IFn&lt;/strong&gt; is because something related to functions, in this case, is because "This" can't be read as a function since Clojure expects it to be an operator that will be applied to the remaining elements.&lt;/p&gt;

&lt;p&gt;For we create lists we need to quote them so they will be treated as data:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="o"&gt;'&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"This"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"is"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"a"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"list"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; ("This" "is" "a" "list")&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or we can instead use the &lt;strong&gt;list&lt;/strong&gt; function as we did in example above:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"This"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"is"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"a"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"list"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; ("This" "is" "a" "list")&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As Clojure is a dynamic language lists can hold any given value:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="o"&gt;'&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;3.1415&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"PI"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="sc"&gt;\π&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; (3.1415 "PI" \π)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case, we created a list that contains a float, a string and a char.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting values from a list
&lt;/h2&gt;

&lt;p&gt;The main thing we have to know about lists is that when we want to get a value from it we have to access all values before it. Imagine we have the following list:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="o"&gt;'&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Brock"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Misty"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Lt. Surge"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Erika"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we want to access "Lt. Surge" that is the third element first we have to access the two elements before it "Brock" and "Misty". This happens since it's a linked list and we don't have a direct reference to the position of each value, as the close element is to the end of the list longer will be the time needed to get its value.&lt;/p&gt;

&lt;p&gt;To get elements we usually have three functions that we combine to go through the list: &lt;strong&gt;first&lt;/strong&gt;, &lt;strong&gt;second&lt;/strong&gt;, &lt;strong&gt;last&lt;/strong&gt;,  and &lt;strong&gt;rest&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  first
&lt;/h3&gt;

&lt;p&gt;The first function returns the element at the beginning of the list.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;first&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;'&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Brock"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Misty"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Lt. Surge"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Erika"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; "Brock"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  second
&lt;/h3&gt;

&lt;p&gt;The second function returns the second element of the list.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;second&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;'&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Brock"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Misty"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Lt. Surge"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Erika"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; "Misty"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  last
&lt;/h3&gt;

&lt;p&gt;The last function returns the element at the end of the list.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;last&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;'&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Brock"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Misty"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Lt. Surge"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Erika"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; "Erika"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  rest
&lt;/h3&gt;

&lt;p&gt;The rest functions return the list without the first element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;rest&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;'&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Brock"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Misty"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Lt. Surge"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Erika"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; ("Misty" "Lt. Surge" "Erika")&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Getting specific values
&lt;/h2&gt;

&lt;p&gt;Most times when we iterate over lists we combine some of these functions to reach the desired element, let's imagine that we want to get the third element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;first&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;rest&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;rest&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;'&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Brock"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Misty"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Lt. Surge"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Erika"&lt;/span&gt;&lt;span class="p"&gt;))))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; "Lt. Surge"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When we iterate over lists we usually use recursion that's something we gonna see later and help us not have to write a lot of functions to get our data, but for now is important that you know how to use and combine them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding values
&lt;/h2&gt;

&lt;p&gt;There are two main functions that we use to add things to a list. The first is the &lt;strong&gt;cons&lt;/strong&gt; function that as we see before is used to build lists and the second is &lt;strong&gt;conj&lt;/strong&gt; which is used to create a new list adding an arbitrary number of elements to the beginning of an existing one.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;conj&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;'&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Koga"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Sabrina"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Blaine"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Giovanni"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Erika"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Lt. Surge"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Misty"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Brock"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; ("Brock" "Misty" "Lt. Surge" "Erika" "Koga" "Sabrina" "Blaine" "Giovanni")&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When we use cons on other hand we build a new list with the passed exact one element on the beginning of it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;cons&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Brock"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;'&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Misty"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Lt. Surge"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Erika"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;;; returns =&amp;gt; ("Brock" "Misty" "Lt. Surge" "Erika")&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  That's all
&lt;/h2&gt;

&lt;p&gt;Now you're becoming to understand LISP a little more in the next parts we'll continue exploring some of the fundamental data structures that we can use to build our programs and how to use them to structure our data.&lt;/p&gt;

</description>
      <category>clojure</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Learning Clojure, part IV</title>
      <dc:creator>Камило Куньа</dc:creator>
      <pubDate>Fri, 22 Apr 2022 03:01:11 +0000</pubDate>
      <link>https://dev.to/cazevedo/learning-clojure-part-iv-16hl</link>
      <guid>https://dev.to/cazevedo/learning-clojure-part-iv-16hl</guid>
      <description>&lt;p&gt;Now we understand the basics is time to delve into the language. As we study the language is recommended that you also use the REPL to follow the code examples (and you can use an &lt;a href="https://tryclojure.org/"&gt;online REPL&lt;/a&gt; if you want to).&lt;/p&gt;

&lt;h2&gt;
  
  
  Syntax
&lt;/h2&gt;

&lt;p&gt;As we know Clojure is a LISP and in all of its dialects what draws attention when we're reading the code is the parenthesis. In fact, when we're talking about LISP most of our code is written using parenthesis in what we call &lt;strong&gt;form&lt;/strong&gt; or &lt;strong&gt;expression&lt;/strong&gt; (for simplicity we can adopt form).&lt;/p&gt;

&lt;p&gt;A form is composed as:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Kvd4hyDg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qhzxkux7q6h4qd1d7xd4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Kvd4hyDg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qhzxkux7q6h4qd1d7xd4.png" alt="Form composition where a form is a opening parenthesis followed of an operator a arbitrary number of arguments and a closing parenthesis" width="365" height="149"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;Image&lt;/strong&gt;: "Form composition" made by the author is copyleft material under unlicense.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;operator&lt;/strong&gt; is an operation that receives arguments and produces a result.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;...args&lt;/strong&gt; is one or more arguments that are consumed by the operator.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In fact, Clojure as a LISP only supports two structures:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Data is the literal representation of values.&lt;/li&gt;
&lt;li&gt;Forms.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For example when we enter a form like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;+&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The form is composed of the operator (the function +) and the arguments (3 4 5) that are arguments passed to the function and produce &lt;strong&gt;12&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This at first glance may look strange, but Clojure (and LISPs) have uniformity in its syntax. When someone programs in Java there are operations with different syntax depending on the operation and operands while in Clojure everything has always the same structure.&lt;/p&gt;

&lt;h2&gt;
  
  
  Evaluation
&lt;/h2&gt;

&lt;p&gt;When we work with Clojure is frequent that part of the arguments of the form is other forms. As example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;+&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;More complex forms are evaluated as follows:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Cy5l5jBO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hn8d2dr8hctunftvtklh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Cy5l5jBO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hn8d2dr8hctunftvtklh.png" alt="Code evaluation step-by-step, first the forms in arguments are reduced to values and then the operand is applied" width="400" height="448"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;Image&lt;/strong&gt;: "Clojure form evaluation" made by the author is copyleft material under unlicense.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  Data
&lt;/h2&gt;

&lt;p&gt;If we append a form with apostrophe ' then the form is evaluated as data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="o"&gt;'&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;+&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;+&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the form is evaluated as data the computer will not execute it, instead, it will return it as plain old data which we can use to perform operations on code.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This is one of the main advantages of LISP dialects over most programming languages that are mainstream. In LISP there's a concept known as &lt;a href="https://en.wikipedia.org/wiki/Homoiconicity"&gt;homoiconicity&lt;/a&gt; where &lt;em&gt;code is data and data is code&lt;/em&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The use of an apostrophe to treat forms as data is called &lt;em&gt;quoting&lt;/em&gt;. When we quote our form everything on it is ignored and treated as a simple list containing data (and lists will be our next subject).&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's continue the Clojure Quest
&lt;/h2&gt;

&lt;p&gt;Now we started to mess with code we're barely starting. Clojure is a great language with so much yet to see and we will continue our quest to master it in the next post on this series hope have you there too.&lt;/p&gt;

</description>
      <category>clojure</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Learning Clojure, part III</title>
      <dc:creator>Камило Куньа</dc:creator>
      <pubDate>Thu, 21 Apr 2022 20:57:48 +0000</pubDate>
      <link>https://dev.to/cazevedo/learning-clojure-part-iii-28e5</link>
      <guid>https://dev.to/cazevedo/learning-clojure-part-iii-28e5</guid>
      <description>&lt;p&gt;We already discussed &lt;a href="https://dev.to/cazevedo/learning-clojure-part-1-13om"&gt;the reasons you should try Clojure&lt;/a&gt; and also&lt;a href="https://dev.to/cazevedo/learning-clojure-part-ii-22b4"&gt; configured our development tools and installed Clojure&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hello, Clojure!
&lt;/h2&gt;

&lt;p&gt;As every developer knows since the dawn of computing the first program that we have to write to be successful in any programming language we're learning is print 'Hello World' on console.&lt;/p&gt;

&lt;p&gt;For this we gonna start a new project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ lein new app hello-world
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And open it on our IDE:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ code hello-world
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The project will have the following structure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.
├── CHANGELOG.md
├── doc
│   └── intro.md
├── LICENSE
├── project.clj
├── README.md
├── resources
├── src
│   └── hello_world
├── target
│   └── default+test
└── test
    └── hello_world
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;CHANGELOG&lt;/strong&gt;: That's a model for CHANGELOG in the project.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;doc&lt;/strong&gt;: Is a folder dedicated to the documentation of the project, it's initialized with an &lt;strong&gt;intro.md&lt;/strong&gt; for writing the first steps.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;LICENSE&lt;/strong&gt;: Is a file containing the &lt;strong&gt;Eclipse Public License - v 2.0&lt;/strong&gt; the same license used in Clojure and default in most Open Source projects that use the language.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;project.clj&lt;/strong&gt;: That we're gonna declare our dependencies and configuration for the project.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;README&lt;/strong&gt;: That's a entry document and front page in remote repository for the project.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;resources&lt;/strong&gt;: Where we can put the files we want to zip in the final jar when we compile the project.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;src&lt;/strong&gt;: That's where &lt;strong&gt;our code&lt;/strong&gt; will really be.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;target&lt;/strong&gt;: Where will be the compiled jar's.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;test&lt;/strong&gt;: That's where the &lt;strong&gt;tests&lt;/strong&gt; will be place.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now we can run our code using leiningen:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ lein run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And if we want to build it as a jar (if you're not from Java and not familiar with the concept we'll explain next) for distribute we can use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ lein uberjar
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we want to run the generated jar file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ java -jar target/uberjar/hello-world-0.1.0-SNAPSHOT-standalone.jar
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And we should receive the same message as before.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's a jar?
&lt;/h2&gt;

&lt;p&gt;The JAR (&lt;strong&gt;J&lt;/strong&gt;ava &lt;strong&gt;Ar&lt;/strong&gt;chive) it's a compressed format of a compiled project for Java Virtual Machine (JVM). When the project is compiled to a JAR File all the JVM bytecode generated will be compressed in this file together with metadata and additional resources needed to run the code.&lt;/p&gt;

&lt;p&gt;This is analog to what most people think about an auto executable .exe or .dll on Windows. The JAR file is the format that is used to distribute programs written to be executed in JVM or libraries to be used in languages that run on it.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Clojure works
&lt;/h2&gt;

&lt;p&gt;Clojure is 100% written in Java (and Clojure itself). In fact, the whole language runs from a JAR file that can be built from &lt;a href="https://github.com/clojure/clojure" rel="noopener noreferrer"&gt;Clojure source code&lt;/a&gt;. But the process of compilation and execution of the code it's little different from Java.&lt;/p&gt;

&lt;p&gt;When we run a Java program the source code is send to the compiler who will parse, tokenize, structure... the code and then compile it to a .class file that contains the compiled bytecode and that file when run will be sent to JVM who will translate it to the optimized machine code for where it's running.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz0dz2hy4nlyxeay0isvu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz0dz2hy4nlyxeay0isvu.png" alt="Diagram of the code evaluation where shows that the characters of a file are sent to the compiler who's produces bytecode and then send to JVM execute"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;"Traditional Evaluation (Java)" by Rich Hickey is copyrighted material of &lt;a href="https://clojure.org/guides/learn/syntax#_traditional_evaluation_java" rel="noopener noreferrer"&gt;clojure.org&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;By other way, when a Clojure program is evaluated first it passes by a special step that's the reader a program written for receive the source parse it and return all code structured in some data structure, only after it the code gets in compiler. In Clojure the compile only receive data structures and never text, separating the reader from compiling makes it easier to process macros and substitutions. As most times the Clojure program is running in live mode (like REPL) the bytecode is immediately sent to JVM that caches and executes it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwjv2dzg64v7f6j0obzin.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwjv2dzg64v7f6j0obzin.png" alt="Diagram of the code evaluation where shows that the character of a file are sent to a reader who transforms it into data structures that are sent to compiler that generate bytecodes who are immediately send to JVM execute"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;"Clojure Evaluation" by Rich Hickey is copyrighted material of &lt;a href="https://clojure.org/guides/learn/syntax#_clojure_evaluation" rel="noopener noreferrer"&gt;clojure.org&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  How our hello-world JAR works
&lt;/h2&gt;

&lt;p&gt;If we use an &lt;a href="http://www.javadecompilers.com/" rel="noopener noreferrer"&gt;online Java decompiler&lt;/a&gt; tool to analyze the compressed bytecode in the JAR we created when compile our project we'll get that the JAR has a folder structure like that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;hello-world-0.1.0-SNAPSHOT-standalone.jar
├── clojure
└── hello-world
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Where the &lt;strong&gt;clojure&lt;/strong&gt; folder contains the compiled bytecode of the reader and compiler altogether with the language source compiled.&lt;/p&gt;

&lt;p&gt;While the &lt;strong&gt;hello-world&lt;/strong&gt; folder have the original Clojure file we written and also helper classes to run main and these same files compiled in Java, but the compiled result are internal symbols of the Clojure language and not a simple and readable Java program.&lt;/p&gt;

&lt;p&gt;So every time we compile our Clojure apps for a JAR to be run in JVM the JAR itself contains also the whole code needed to run Clojure including the the language functions, reader and compiler that can be executed if needed.&lt;/p&gt;

&lt;h2&gt;
  
  
  See ya!
&lt;/h2&gt;

&lt;p&gt;Our Clojure journey is still far from the end, now we can understand how the process compilation and execution of Clojure works we can understand how it's different from a Java project and how JVM can execute the JAR since it was not thought to run Clojure code. Hope to see you in part IV.&lt;/p&gt;

</description>
      <category>clojure</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>java</category>
    </item>
    <item>
      <title>Learning Clojure, part II</title>
      <dc:creator>Камило Куньа</dc:creator>
      <pubDate>Wed, 20 Apr 2022 00:18:21 +0000</pubDate>
      <link>https://dev.to/cazevedo/learning-clojure-part-ii-22b4</link>
      <guid>https://dev.to/cazevedo/learning-clojure-part-ii-22b4</guid>
      <description>&lt;p&gt;Now you're convinced that is a good idea learn Clojure (and if you not I recommend to read the part I) we'll start the practical part installing the language and all the tools that we need for program in Clojure.&lt;/p&gt;

&lt;p&gt;I'll not cover the process on Windows, most of things like SDKMan! only work on Linux/Mac Operating Systems, if you're using Windows I would recommend you to use WSL to follow this tutorial.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install SDKMan! and Java
&lt;/h2&gt;

&lt;p&gt;The first thing to do is install Java. Clojure is entirely written in Java (and Clojure itself) we need have Java installed and configured in our computer not only to run most of the tools that we use to program in Clojure, but also to run Clojure itself.&lt;/p&gt;

&lt;p&gt;To do this we will install a bash tool called &lt;a href="https://sdkman.io/"&gt;SDKMan!&lt;/a&gt; this is a version manager tool for all JVM languages (including our beloved Clojure). To install it we have to run the command in our terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ curl -s "https://get.sdkman.io" | bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After it complete the installation we have to source or open/close our terminal to load the changes in our &lt;code&gt;~/.bashrc&lt;/code&gt;. SDKMan is a collection of bash functions that are linked in our bash profile.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you want to understand how the &lt;strong&gt;sdk&lt;/strong&gt; function we'll use works you can use the following command on your terminal: &lt;code&gt;$ describe -f sdk&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now we have to install Java on our machine. The actual Long-Term Supported (LTS) version of Java is the 17 we'll use it. In your terminal run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sdk install java 17.0.2-open
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All right! now you can check if Java is installed and running with the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ java -version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The SDKMan! not only helps you to install and configure Java as it also manages different JDKs on your computer if you want to learn more about it I recommend reading the &lt;a href="https://sdkman.io/usage"&gt;documentation&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install Maven and Leiningen
&lt;/h2&gt;

&lt;p&gt;Now we have to install the build tools both for Java and for Clojure since we'll use them for manage dependencies and build our code. For our own luck SDKMan! also do this for us.&lt;/p&gt;

&lt;p&gt;For install maven we have to run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sdk install maven
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And for install leiningen we have to run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sdk install leiningen
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After doing it we should have all we need to run Clojure. If you want to start doing things in REPL or just test the installation you can run it in you terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ lein repl
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;By the way if you need to exit the REPL just run the function &lt;code&gt;(exit)&lt;/code&gt; on REPL.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Installing VS Code and Calva
&lt;/h2&gt;

&lt;p&gt;Wait... VS Code? Why not Emacs?&lt;/p&gt;

&lt;p&gt;Well, a lot of people following this tutorial never learned Emacs before and I won't recommend learning Clojure and Emacs at the same time because things can become messy and confusing. After all, the complexity of the ecosystem and the elisp language be so similar that can be confusing.&lt;/p&gt;

&lt;p&gt;By other way, probably you already have VS Code installed in your computer, and even if you don't you can just use &lt;a href="https://code.visualstudio.com/docs/setup/linux"&gt;apt&lt;/a&gt; or snap to install it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo apt install snapd
$ sudo snap install –classic code
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After installing the IDE you can open it and install the Calva plugin it will add a lot of features to VS Code including things such as REPL integration and folding parens capabilities. To install it, open your VS Code press CTRL+P and paste this code into the open dialog:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ext install betterthantomorrow.calva
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After restarting your VS Code everything will be fine for we start the development in Clojure.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hello Clojure!
&lt;/h2&gt;

&lt;p&gt;After we have all set we can start programming in Clojure by building our first project. To do this you can just open a terminal in the folder where you want your project to be created and run the following command for leiningen create our project scaffold named &lt;code&gt;getting-started&lt;/code&gt; based on &lt;code&gt;app&lt;/code&gt; template:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ lein new app getting-started
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And then we can open it on VS Code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ code getting-started
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The entry point of our project will be &lt;code&gt;./getting-started/src/getting-started/core.clj&lt;/code&gt; file that contains a Hello World program, let's change "Hello, World!" for "Hello, Clojure!" and then run the project with the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ lein run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If everything worked fine you should see the printed string printed in a newline in your terminal.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using the REPL
&lt;/h2&gt;

&lt;p&gt;One of the main advantages of using Clojure is the Read-Eval-Print-Loop (REPL) tool that helps a lot to get feedback while we're coding for work with Clojure is recommended that at least you learn to use the basics on it.&lt;/p&gt;

&lt;p&gt;For start a REPL open the VS Code and press &lt;code&gt;CTRL+ALT+C&lt;/code&gt; and the &lt;code&gt;CTRL+ALT+J&lt;/code&gt; and then select &lt;code&gt;leiningen&lt;/code&gt; and use the &lt;code&gt;uberjar&lt;/code&gt; profile.&lt;/p&gt;

&lt;p&gt;You will see a prompt with &lt;code&gt;clj꞉getting-started.core꞉&amp;gt;&lt;/code&gt; open on the right of the code, this is our REPL window and you can run any Clojure code or part of the code you're writing on it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;clj꞉getting-started.core꞉&amp;gt;  (+ 1 1)
2
clj꞉getting-started.core꞉&amp;gt;  (-main)
Hello, Clojure!
nil
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At any moment you can also put the file cursor on the closing parenthesis in your file and run &lt;code&gt;CTRL+ENTER&lt;/code&gt; and it will send the code to REPL and display the result of it.&lt;/p&gt;

&lt;p&gt;If you want to learn more about how to send files to REPL, how to make a partial evaluation, and everything else in Calva I recommend you to look at the docs.&lt;/p&gt;

&lt;h2&gt;
  
  
  I'll be back
&lt;/h2&gt;

&lt;p&gt;This is just the first step in the Clojure journey, now we installed and configurated our whole development ambient we're ready to start evaluating parenthesis on our next post.&lt;/p&gt;

</description>
      <category>clojure</category>
      <category>beginners</category>
      <category>functional</category>
    </item>
    <item>
      <title>Learning Clojure, part I</title>
      <dc:creator>Камило Куньа</dc:creator>
      <pubDate>Mon, 18 Apr 2022 22:30:01 +0000</pubDate>
      <link>https://dev.to/cazevedo/learning-clojure-part-1-13om</link>
      <guid>https://dev.to/cazevedo/learning-clojure-part-1-13om</guid>
      <description>&lt;h2&gt;
  
  
  What's Clojure?
&lt;/h2&gt;

&lt;p&gt;Clojure is a LISP Dialect originally made to run on the JVM (Java Virtual Machine) and has been ported for the .NET and JavaScript ecosystem as well.&lt;/p&gt;

&lt;p&gt;As a LISP Clojure adopts dynamic typing functional programming as the main programming style and as it runs on JVM and is mainly written in Java it can interoperate with Java seamlessly and run the same code on any platform that runs JVM.&lt;/p&gt;

&lt;h2&gt;
  
  
  When Clojure was created?
&lt;/h2&gt;

&lt;p&gt;Clojure was an experimental project that Rich Hickey released in 2007 after prior attempts to make interoperability between Common LISP the language he was using at his job and the greater programming ecosystems JVM and .NET.&lt;/p&gt;

&lt;p&gt;The language is being developed as a community-driven project and has evolved a lot since its initial release as one of the most successful functional programming languages in the mainstream.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why learn Clojure?
&lt;/h2&gt;

&lt;p&gt;Let me try to sell this to you.&lt;/p&gt;

&lt;p&gt;Many of the most regarded programmers of all time recommended that every programmer at a certain point should try a LISP dialect.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Richard Stallman&lt;/strong&gt;, Founder of the Free Software Movement in &lt;a href="https://stallman.org/stallman-computing.html"&gt;How I do my computing&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"The most powerful programming language is Lisp. If you don't know Lisp (or its variant, Scheme), you don't know what it means for a programming language to be powerful and elegant." &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Eric Steven Raymond&lt;/strong&gt; Founder of the Open Source Initiative in &lt;a href="http://www.catb.org/~esr/faqs/hacker-howto.html"&gt;How to become a hacker&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"LISP is worth learning for a different reason — the profound enlightenment experience you will have when you finally get it. That experience will make you a better programmer for the rest of your days, even if you never actually use LISP itself a lot."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Both founders of the biggest FOSS movements and authors of important open source projects have recommended that every programmer learn LISP for decades and there a many more that also did as Edsger Dijkstra, Bjarne Stroustrup, Larry Wall and Alan Kay.&lt;/p&gt;

&lt;p&gt;Clojure is a LISP that runs in JVM one of the most popular runtimes ever created and that empowers tons of the most famous systems out there. Being a JVM language means it can access all the Java ecosystem and thus making it capable to use a very wide range of libraries and tools to make useful things.&lt;/p&gt;

&lt;p&gt;Learning Clojure empowers you as a programmer to have the enlightenment of a LISP and the productivity and capacity of Java. If you want to build robust systems with a language with extreme expressiveness Clojure is the right language for you. &lt;/p&gt;

&lt;h2&gt;
  
  
  How to learn Clojure?
&lt;/h2&gt;

&lt;p&gt;There are many great resources where you can learn Clojure for free.&lt;/p&gt;

&lt;p&gt;The first one is &lt;a href="https://www.braveclojure.com/"&gt;Clojure for the Brave and True&lt;/a&gt;  a free online book written by &lt;a href="https://twitter.com/nonrecursive"&gt;Daniel Higginbotham&lt;/a&gt; that teaches Clojure in a very fun approach and with a lot of visual content that helps to illustrate each lesson.&lt;/p&gt;

&lt;p&gt;If you prefer something a little more practical, there is the &lt;a href="http://clojurekoans.com/"&gt;Clojure Koans&lt;/a&gt; a set of Clojure exercises that help to guide you over the language syntax and rules. Each lesson is a unit test written based on a problem you have to resolve using the part of the language being taught.&lt;/p&gt;

&lt;p&gt;If you prefer the best of the two worlds is the &lt;a href="https://exercism.org/tracks/clojure"&gt;exercism&lt;/a&gt; project, a website that reunites lessons divided into chapters and lessons with community mentors to answer and help in community forums and discussions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where I can find help?
&lt;/h2&gt;

&lt;p&gt;The Clojure community is great and  there are a lot of places you can reach other clojurians.&lt;/p&gt;

&lt;p&gt;There is the official community forum that is hosted on the language website &lt;a href="https://ask.clojure.org/"&gt;ask.clojure.org&lt;/a&gt; for joining the forum you need a GitHub account, after authenticating you can post questions (and answers) in the forum.&lt;/p&gt;

&lt;p&gt;If you prefer to use Discord you can join one (or both) the &lt;a href="https://discord.gg/discljord"&gt;Discljord&lt;/a&gt; or &lt;a href="https://discord.gg/MsejPv9JNG"&gt;Clojurians&lt;/a&gt; Discord Servers. Both are great discord communities dedicated to Clojure.&lt;/p&gt;

&lt;p&gt;If you're on Twitter you can join the &lt;a href="https://twitter.com/i/communities/1494013093059432451"&gt;Clojure Community&lt;br&gt;
&lt;/a&gt; there you can find a lot of tweets and people related to the language and ask for help or any question you have.&lt;/p&gt;

&lt;h2&gt;
  
  
  That's all folks! (At least for now)
&lt;/h2&gt;

&lt;p&gt;This is just the beginning of a series of posts I will write while learning Clojure for my new job. I'm eager to start developing great applications with it and hope you continue to follow the upcoming posts. &lt;/p&gt;

</description>
      <category>clojure</category>
      <category>beginners</category>
      <category>codenewbie</category>
    </item>
  </channel>
</rss>
