The Artima Developer Community
Sponsored Link

Programming in Scala Forum
Chapter 14, p. 261

2 replies on 1 page. Most recent reply: Jan 22, 2008 11:30 AM by Javier Diaz Soto

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Frederic Jean

Posts: 4
Nickname: freddyjean
Registered: Dec, 2007

Chapter 14, p. 261 Posted: Jan 3, 2008 11:03 PM
Reply to this message Reply
Advertisement
It appears that this is innacurate:


scala> abcde
res22: List[Char] = List(a, b, c, d, e)

scala> abcde.reverse.init == abcde.tail
res23: Boolean = false

scala> abcde.reverse.tail == abcde.init
res24: Boolean = false


We end up with a different list since the order is important. The other 2 statements are correct:

scala> abcde.reverse.head == abcde.last
res25: Boolean = true

scala> abcde.reverse.last == abcde.head
res27: Boolean = true


Fred


Frederic Jean

Posts: 4
Nickname: freddyjean
Registered: Dec, 2007

Re: Chapter 14, p. 261 Posted: Jan 3, 2008 11:10 PM
Reply to this message Reply
And the rev function example corrected:


scala> def rev[T](xs: List[T]): List[T] = xs match {
| case List() => xs
| case x :: xs1 => rev(xs1) ::: List(x)
| }
rev: [T](List[T])List[T]

scala> rev(abcde)
res31: List[Char] = List(e, d, c, b, a)


Fred

Javier Diaz Soto

Posts: 29
Nickname: javierbds
Registered: Sep, 2005

Re: Chapter 14, p. 261 Posted: Jan 22, 2008 11:30 AM
Reply to this message Reply
I think that was was 'meant' was this :

xs.init == xs.reverse.tail.reverse
xs.tail == xs.reverse.init.reverse

(how to define one in terms of the other requires two reverses)

Flat View: This topic has 2 replies on 1 page
Topic: self-types, existentials, index and a general comment Previous Topic   Next Topic Topic: 08IEEE intel wireless commnication conference

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use