Search Results

Search found 972 results on 39 pages for 'scala'.

Page 3/39 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Scala methods ending in _=

    - by Alexey Romanov
    I seem to remember Scala treating methods ending in _= specially, so something like this: object X { var x: Int = 0; def y_=(n : Int) { x = n }} X.y = 1 should call X.y_=(1). However, in 2.8.0 RC1, I get an error message: <console>:6: error: value y is not a member of object X X.y = 1 ^ Interestingly, just trying to call the method without parentheses fails as well: scala> X.y_= 1 <console>:1: error: ';' expected but integer literal found. X.y_= 1 ^ Am I misremembering something which does actually exist or did I just invent it out of whole cloth?

    Read the article

  • Scala case class generated field value

    - by Petteri Hietavirta
    I have an existing Scala application and it uses case classes which are then persisted in MongoDB. I need to introduce a new field to a case class but the value of it is derived from existing field. For example, there is phone number and I want to add normalised phone number while keeping the original phone number. I'll update the existing records in MongoDB but I would need to add this normalisation feature to existing save and update code. So, is there any nice shortcut in Scala to add a "hook" to a certain field of a case class? For example, in Java one could modify setter of the phone number.

    Read the article

  • Scala factory pattern returns unusable abstract type

    - by GGGforce
    Please let me know how to make the following bit of code work as intended. The problem is that the Scala compiler doesn't understand that my factory is returning a concrete class, so my object can't be used later. Can TypeTags or type parameters help? Or do I need to refactor the code some other way? I'm (obviously) new to Scala. trait Animal trait DomesticatedAnimal extends Animal trait Pet extends DomesticatedAnimal {var name: String = _} class Wolf extends Animal class Cow extends DomesticatedAnimal class Dog extends Pet object Animal { def apply(aType: String) = { aType match { case "wolf" => new Wolf case "cow" => new Cow case "dog" => new Dog } } } def name(a: Pet, name: String) { a.name = name println(a +"'s name is: " + a.name) } val d = Animal("dog") name(d, "fred") The last line of code fails because the compiler thinks d is an Animal, not a Dog.

    Read the article

  • Is Clojure, Scala and other restrained by the JVM vs CLR

    - by jia93
    The Java implementors seem slow to adopt language improvements, for example compare C# with full closures, expression trees, LINQ etc.. to Java, and even the push back of some stuff to Java 8 will still leave it behind the current implementation of C#. However since I dont intend to use either Java or C# that particular language war isnt of interest too much, im more concerned with the JVM vs CLR. Is this lagging-behind also applicable to the JVM? Will Scala, Clojure etc.. will they be able to continue to innovate or score optimal performance in the face of slowly progressing underlying VM such as JVM? Is Clojure/Scala restrained at present by JVM limitations?

    Read the article

  • Decision for Unchecked Exceptions in Scala

    - by Jatin
    As a java programmer, I have always been critical of Unchecked Exceptions. Mostly programmers use it as an en-route to coding easiness only to create trouble later. Also the programs (though untidy) with checked exceptions are much robust compared to unchecked counterparts. Surprisingly in Scala, there is nothing called Checked Exceptions. All the Java checked and unchecked are unchecked in Scala. What is the motivation behind this decision? For me it opens wide range of problems when using any external code. And if by chance the documentation is poor, it results in KILL.

    Read the article

  • Common idiom in Java to Scala, traverse/Iterate Java list into Scala list

    - by Berlin Brown
    I am processing a XML document and iterating through nodes. I want to iterate through the nodes and build a new List of some type. How would I do this with Scala: Here is my XML traverse code: def findClassRef(xmlNode: Elem) = { xmlNode\"classDef" foreach { (entry) => val name = entry \ "@name" val classid = entry \ "@classId" println(name + "//" + classid) } } Where the line of println is, I want to append elements to a list.

    Read the article

  • what's the right way to use scala.io.Source?

    - by woods
    In many examples, it is described that you can use scala.io.Source to read a whole file like this: val str = scala.io.Source.fromFile("test.txt").mkString() But closing the underlying stream is not mentioned. Why does Scala not provide a convenient way to do that such as with clause in Python? It looks useful but not difficult. Is there any other better way to do that safely in Scala, i means to read a whole file?

    Read the article

  • How do I use continuations on Scala 2.8?

    - by Seth Tisue
    Scala 2.8.0.RC1 includes the continuations plugin on trunk for the first time, but the details of how to use it have changed from previous releases, so it's difficult to follow the blog entries and SO answers out there that talk about continuations but were written for previous versions.

    Read the article

  • What's the new way to iterate over a Java Map in Scala 2.8.0?

    - by Alex R
    How does scala.collection.JavaConversions supercede the answers given here: http://stackoverflow.com/questions/495741/iterating-over-java-collections-in-scala (doesn't work because the "jcl" package is gone) and here http://www.eishay.com/2009/05/iterating-over-map-with-scala.html (doesn't work me in a complicated test which I'll try to boil down and post here later) The latter is actually a Scala Map question but I think I need to know both answers in order to iterate over a java.util.Map. Thanks

    Read the article

  • Extending existing data structure in Scala.

    - by Lukasz Lew
    I have a normal tree defined in Scala. sealed abstract class Tree case class Node (...) extends Tree case class Leaf (...) extends Tree Now I want to add a member variable to all nodes and leaves in the tree. Is it possible with extend keyword or do I have to modify the tree classes by adding [T]?

    Read the article

  • What is a "context bound" in Scala?

    - by Jesper
    One of the new features of Scala 2.8 are context bounds. What is a context bound and where is it useful? Of course I searched first (and found for example this) but I couldn't find any really clear and detailed information.

    Read the article

  • How to get Ponter/Reference semantics in Scala.

    - by Lukasz Lew
    In C++ I would just take a pointer (or reference) to arr[idx]. In Scala I find myself creating this class to emulate a pointer semantic. class SetTo (val arr : Array[Double], val idx : Int) { def apply (d : Double) { arr(idx) = d } } Isn't there a simpler way? Doesn't Array class have a method to return some kind of reference to a particular field?

    Read the article

  • Scala - learning by doing

    - by wrecked
    coming from the PHP-framework symfony (with Apache/MySQL) I would like to dive into the Scala programming language. I already followed a few tutorials and had a look at Lift and Play. Java isn't a stranger to me either. However the past showed that it's easiest to learn things by just doing them. Currently we have a little - mostly ajax-driven - application build on symfony at my company. My idea is to just build a little project similar to this one which might gets into production in the future. The app should feature: High scalability and performance a backend-server web-interface and a GUI-client There are plenty of questions arising when I think of this. First of all: Whats the best way to accomplish a easy to maintain, structured base for it? Would it be best to establish a socket based communication between pure-scala server/client and accessing that data via Lift or is building a Lift-app serving as a server and connecting the gui-client (via REST?) the better way? Furthermore I wounder which database to choose. I'm familiar with (My)SQL but feel like a fool beeing confronted with all these things like NoSQL, MongoDB and more. Thanks in advance!

    Read the article

  • What is in scala-android.jar?

    - by synic
    I've been trying to experiment with developing Android applications with Scala. I've gotten to the point where I can get the app to compile, but there are no helper functions for things like: button.setOnClickListener( () => { text.setText("test") }) (I'm talking about the closure there) I see lots of references to scala-android.jar, and have this file in my project, but I'm not sure what it does, or how to use it. I get the feeling it has these helper conversion functions, but I'm not sure. Running jar -tvf scala-android.jar on the file gives me this: 401 Sun Jun 06 10:06:02 MDT 2010 scala/Function0$class.class 431 Sun Jun 06 10:06:02 MDT 2010 scala/Function0.class 572 Sun Jun 06 10:06:02 MDT 2010 scala/Function1.class 282 Sun Jun 06 10:06:02 MDT 2010 scala/ScalaObject$class.class 271 Sun Jun 06 10:06:02 MDT 2010 scala/ScalaObject.class 458 Sun Jun 06 10:06:02 MDT 2010 scala/runtime/BoxedUnit.class If this isn't what I'm looking for, is there a simple library that'll do conversions for this kind of stuff?

    Read the article

  • Diving into Scala with Cay Horstmann

    - by Janice J. Heiss
    A new interview with Java Champion Cay Horstmann, now up on otn/java, titled  "Diving into Scala: A Conversation with Java Champion Cay Horstmann," explores Horstmann's ideas about Scala as reflected in his much lauded new book,  Scala for the Impatient.  None other than Martin Odersky, the inventor of Scala, called it "a joy to read" and the "best introduction to Scala". Odersky was so enthused by the book that he asked Horstmann if the first section could be made available as a free download on the Typesafe Website, something Horstmann graciously assented to. Horstmann acknowledges that some aspects of Scala are very complex, but he encourages developers to simply stay away from those parts of the language. He points to several ways Java developers can benefit from Scala: "For example," he says, " you can write classes with less boilerplate, file and XML handling is more concise, and you can replace tedious loops over collections with more elegant constructs. Typically, programmers at this level report that they write about half the number of lines of code in Scala that they would in Java, and that's nothing to sneeze at. Another entry point can be if you want to use a Scala-based framework such as Akka or Play; you can use these with Java, but the Scala API is more enjoyable. " Horstmann observes that developers can do fine with Scala without grasping the theory behind it. He argues that most of us learn best through examples and not through trying to comprehend abstract theories. He also believes that Scala is the most attractive choice for developers who want to move beyond Java and C++.  When asked about other choices, he comments: "Clojure is pretty nice, but I found its Lisp syntax a bit off-putting, and it seems very focused on software transactional memory, which isn't all that useful to me. And it's not statically typed. I wanted to like Groovy, but it really bothers me that the semantics seems under-defined and in flux. And it's not statically typed. Yes, there is Groovy++, but that's in even sketchier shape. There are a couple of contenders such as Kotlin and Ceylon, but so far they aren't real. So, if you want to do work with a statically typed language on the JVM that exists today, Scala is simply the pragmatic choice. It's a good thing that it's such a nice choice." Learn more about Scala by going to the interview here.

    Read the article

  • Question on Scala Closure (From "Programming in Scala")

    - by Ekkmanz
    I don't understand why authors said that Code Listing 9.1 from "Programming in Scala" use closure. In chapter 9, they show how to refactor code into more less duplicated form, from this original code: object FileMatcher { private def filesHere = (new java.io.File(".")).listFiles def filesEnding(query: String) = for (file <- filesHere; if file.getName.endsWith(query)) yield file def filesContaining(query: String) = for (file <- filesHere; if file.getName.contains(query)) yield file def filesRegex(query: String) = for (file <- filesHere; if file.getName.matches(query)) yield file } To the second version: object FileMatcher { private def filesHere = (new java.io.File(".")).listFiles def filesMatching(query: String, matcher: (String, String) => Boolean) = { for (file <- filesHere; if matcher(file.getName, query)) yield file } def filesEnding(query: String) = filesMatching(query, _.endsWith(_)) def filesContaining(query: String) = filesMatching(query, _.contains(_)) def filesRegex(query: String) = filesMatching(query, _.matches(_)) } Which they said that there is no use of closure here. Now I understand until this point. However they introduced the use of closure to refactor even some more, shown in Listing 9.1: object FileMatcher { private def filesHere = (new java.io.File(".")).listFiles private def filesMatching(matcher: String => Boolean) = for (file <- filesHere; if matcher(file.getName)) yield file def filesEnding(query: String) = filesMatching(_.endsWith(query)) def filesContaining(query: String) = filesMatching(_.contains(query)) def filesRegex(query: String) = filesMatching(_.matches(query)) } Now they said that query is a free variable but I don't really understand why they said so? Since ""query"" seems to be passed from top method down to string matching function explicitly.

    Read the article

  • Scala method where type of second parameter equals part of generic type from first parameter

    - by ifischer
    I want to create a specific generic method in Scala. It takes two parameters. The first is of the type of a generic Java Interface (it's from the JPA criteria query). It currently looks like this: def genericFind(attribute:SingularAttribute[Person, _], value:Object) { ... } // The Java Interface which is the type of the first parameter in my find-method: public interface SingularAttribute<X, T> extends Attribute<X, T>, Bindable<T> Now i want to achieve the following: value is currently of type java.lang.Object. But I want to make it more specific. Value has to be the of the same type as the placeholder "_" from the first parameter (and so represents the "T" in the Java interface). Is that somehow possible, and how? BTW Sorry for the stupid question title (any suggestions?)

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >