title: Understanding infix method call and cons operator(::) in Scala
body: <p>I'm quite new to Scala programming language, and was trying something out stucked in my mind while I was following the lecture notes at <a href="http://horstmann.com/sjsu/cs152/04-closures1.html" rel="noreferrer">here</a>.</p>
  
  <p>I think I couldn't really understand how cons operator works, here are some things I tried:</p>
  
  <p>I've created a pseudo-random number generator, then tried to create a list of one random value:</p>
  
  <pre><code>scala&gt; val gen = new java.util.Random
  gen: java.util.Random = java.util.Random@1b27332
  
  scala&gt; gen nextInt 3 :: Nil
  &lt;console&gt;:7: error: type mismatch;
   found   : List[Int]
   required: Int
         gen nextInt 3 :: Nil
                       ^
  </code></pre>
  
  <p>But it tried to pass List(3) to nextnt method. When i used paratheses, there was no problem</p>
  
  <pre><code>scala&gt; (gen nextInt 3) :: Nil
  res69: List[Int] = List(1)
  </code></pre>
  
  <p>I was curious about the execution order, so i created a function to check it</p>
  
  <pre><code>scala&gt; def pr(i:Int):Int = { println(i); i }
  pr: (i: Int)Int
  
  scala&gt; pr(1) :: pr(2) :: pr(3) :: Nil
  1
  2
  3
  res71: List[Int] = List(1, 2, 3)
  </code></pre>
  
  <p>As seen in outputs, execution order is the same as the order of appearance. Then I thought it might be about the 'nextInt' function, then I tried following:</p>
  
  <pre><code>scala&gt; 1 + 2 :: Nil
  res72: List[Int] = List(3)
  </code></pre>
  
  <p>It first executed addition, and after that cons is executed. So here is the question: What is the difference between <code>gen nextInt 3 :: Nil</code> and <code>1 + 2 :: Nil</code>?</p>