Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Scala
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Scala
I failed to write : Good-looking assignment to private Array
Heep Po
Greenhorn
Posts: 3
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
class GoodLookingAssign { private var theScore = Array(0.0, 0.0, 0.0); // To return theScore(i) // Example use : println(score(0)) // it's OK def score(i:Int): Double = theScore(i) // To set theScore(i) // Example use : score(1) = 4.4 // it's go complier error // I get this idea from section "Property" in : http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-2 def score(i:Int)_=(v:Double) = { theScore(i) = checkValid(v) } // To ensure that score is not negative def checkValid(x:Double): Double = { var out = x if (out < 0) { out = 0} out } } // ################# END Class ################ object ApplyGoodLooking { def main(args: Array[String]) { val g = new GoodLookingAssign() println("g.score(0) = "+g.score(0)) g.score(1) = 4.4 println("g.score(0) = "+g.score(0)) } // ------------ End main ------------ } // ################# END Object ################
Thanks for suggestion
Jesper de Jong
Java Cowboy
Posts: 16084
88
I like...
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Welcome to the Ranch.
Instead of this:
def score(i:Int)_=(v:Double)
try this:
def score_=(i: Int)(v: Double)
(I have not tested it, but I think that will work).
The _= is part of the method name.
You should
put it with the method name, not after the (i: Int) argument list.
Jesper's Blog
-
Pluralsight Author Page
Heep Po
Greenhorn
Posts: 3
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thanks to your response, Jesper de Jong, but your solution produces compiler error.
And I've got the solution at:
http://scala-forum.org/read.php?3,549,551#msg-551
Consider Paul's
rocket mass heater
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Project Euler problems with Scala
Tail Calls vs memoization
Interface combinations ...
losing data
Scala not compiling on Eclipse
More...