Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The function </p> <pre><code>def fixedPoint (f: Double =&gt; Double)(firstGuess: Double):Double </code></pre> <p>is a function definition which takes two arguments:</p> <ol> <li>a function "f" which takes a parameter of type <code>Double</code> which returns a <code>Double</code> and</li> <li>a <code>Double</code> value named "firstGuess"</li> </ol> <p>and returns a <code>Double</code>. The separation of the single parameters into their own parenthesis groups allows the function to be used in currying:</p> <pre><code>def mySqrtCalc(x:Double)(firstGuess:Double):Double = {...} val mySqrtFunc = mySqrtCalc(2.0) _ val v = mySqrtFunc(1) // parameter firstGuess is set to 1 </code></pre> <p>Beside the ability for currying, this is equivalent to the uncurried version</p> <pre><code>def fixedPoint (f: Double =&gt; Double,firstGuess: Double):Double </code></pre> <p>which might look more familiar to you.</p> <p>The result of the <code>calculateAverate</code> is a Double because you add up the result of applying the passed function f to x with x which gives you a <code>Double</code> because f is a function <code>Double =&gt; Double</code>.</p> <p>You use <code>calculateAverate</code> method in a curried way in your <code>myNewSquareRoot</code> method body, by giving only the first of both parameters in first place and omitting the second one, which is taken from the from the outer <code>fixedPoint</code> method. Omitting the second parameter of <code>calculateAverate</code> gives you a method <code>Double=&gt;Double</code> as it is required by the <code>fixedPoint</code> method. </p> <p>You might insert some <code>println(s"&lt;methodname&gt; value=$value")</code> to observe the execution flow and understand the method call order.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload