{
if ( n < 0) then raise (Failure "Gunwo")
else if n = 0 then 0
else if n = 1 then 1
else fib (n - 1) + fib (n - 2);;
let fib2 = fun n ->
let rec fib_tr = fun (n, fib1, fib2) ->
if (n < 0)
else if (n
else if (n == 1) 1
else Fib(n - 1) + Fib(n - 2)
}
import scala.annotation.tailrec
def Fib_tr(n: Int): Int =
{
@tailrec
def Fibb(n: Int, fib1: Int, fib2: Int): Int =
if (n < 0) throw new Exception("Gunwo")
else if (n == 0)
else if (n
else
Fibb(n,0, 1)
}
import scala.annotation.tailrec
def me_Kill_Myself (a: Double): Double = {
@tailrec
def root3_tl(x: Double): Double = {
if (math.abs(math.pow(x, 3) - a) <= 1.0E-15 * Math.abs(a)) x
else root3_tl(x + (a / math.pow(x, 2) - x) / 3)
}
root3_tl(if (a > 1) a/3 else a)
}
me_Kill_Myself (27)
val
in fib_tr(n,0,1);;
let x1 = (-2, -1, 0, 1,
val
let (_, _, x, _, _) =
val
let x2 = ((1, 2), (0,
val
let ((_, _), (x, _)) =
def id[A](x:A)
let rec initSegment =
def initSegment[A] (xs1: List[A], xs2: List[A]): Boolean = {
// val h1::t1 = xs1
// val h2::t2 = xs2
if (xs1
else if (xs2
else if
else
}
val
let l1 = 1 :: 2 ::
val
let l2 =
initSegment(l2,
def id[A](x:A)
let rec replaceNth =
def replaceNth[A] (xs:List[A], n: Int, el: A): List[A] =
{
if (n < 0 || xs
else if (n
else
}
replaceNth('a' :: 'b' :: 'c'