PedroPS (12) [Avatar] Offline
#1
Hello,

The "concat" function example provided in page 103 (boldface typing) is not "tail-recursive" (I think).
Doesn't it suffer from the same stack troubles as the before mentioned no-TR functions?
What's different in this case to be "acceptable"?

Regards.
aslam.khan (50) [Avatar] Offline
#2
Re: p 103. concat example
Hi Pedro

I'll look at that example again and get back to you. Stay tuned.
nresni (8) [Avatar] Offline
#3
maybe ...

  def concat(ns: AList): AList = {
    def loop(xs: AList, acc: AList): AList = {
      if(xs.isEmpty) acc
      else loop(xs.tail, xs.head :: acc)
    }
    loop(this, ns)
  }