unable to understand the syntax - scala

71 views
Skip to first unread message

Sherry Sethi

unread,
Sep 21, 2016, 11:54:10 AM9/21/16
to scala-user
 def above(that: Element): Element = { 
      val this1 = this widen that.width 
      val that1 = that widen this.width 
      assert(this1.width == that1.width)
      elem(this1.contents ++ that1.contents) 
    }


In the above code snippet - What do u mean by line 2? what is the value of this1 and what is implied by this line? I am new to scala and still learning my basics using the 
http://www.artima.com/pins1ed/assertions-and-unit-testing.html

Thanks in advance!

Regards

Oliver Ruebenacker

unread,
Sep 21, 2016, 12:09:41 PM9/21/16
to Sherry Sethi, scala-user

     Hello,

  I'm not sure where the confusion comes from - maybe from the fact that dots and parentheses can sometimes be omitted? Also, "this" refers to the enclosing object. The code is equivalent to:

def above(that: Element): Element = { 
      val this1 = this.widen(that.width) 
      val that1 = that.widen(this.width) 
      assert(this1.width == that1.width)
      elem(this1.contents ++ that1.contents) 
    }
  Does that help?

     Best, Oliver

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Oliver Ruebenacker
Senior Software Engineer, Diabetes Portal, Broad Institute

Reply all
Reply to author
Forward
0 new messages