Search Results

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

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

  • Can you return an assignable lvalue in Scala?

    - by Alex R
    (note, lvalue is actually a term from the C grammar, I don't know what it's called in Scala!) Trying to learn Scala... this evening I'm working on an internal DSL for a dynamically scoped language that might resemble PHP syntax. My REPL is: Welcome to Scala version 2.7.6.final (Java HotSpot(TM) Client VM, Java 1.6.0). I have some made-up example code: class $(any: Any) { def update(sym: Symbol, any: Any) { println("line 2 executed");} def -(sym: Symbol) : $ = { println("line 1 executed"); return this } def update(any: Any) { println("line 3 executed");} } The following works as expected: scala var a = new $(0) a: $ = $@19238ad scala a('x) = "blah" line 2 executed On the other hand, why does the following not invoke the 1-parameter update method? scala a = 1 :6: error: type mismatch; found : Int(1) required: $ a = 1 ^ Ultimately, I would like this to work: a-'x = "blah" Thanks

    Read the article

  • How to use Scala interpreter options with SBT?

    - by John Threepwood
    When using the Scala interpreter, one could start it with an option like: C:\Users\John>scala -unchecked Welcome to Scala version 2.9.2 (Java HotSpot(TM) Client VM, Java 1.6.0_32). Type in expressions to have them evaluated. Type :help for more information. scala> When using sbt, how can one start the Scala interpreter with options ? The following try will not work: C:\Users\John\Test Scala Project 1>sbt [...] [info] Loading global plugins from C:\Users\John\.sbt\plugins [info] Set current project to default-8d4ecc (in build file:/C:/Users/John/Tes t%20Scala%20Project%201/) > console -unchecked [error] Expected end of input. [error] console -unchecked [error] ^ With Google & Co I could not figure out how to do this from within the sbt shell. Does anyone know ?

    Read the article

  • scala REPL is slow on vista

    - by Jacques René Mesrine
    I installed scala-2.8.0.RC3 by extracting the tgz file into my cygwin (vista) home directory. I made sure to set $PATH to scala-2.8.0.RC3/bin. I start the REPL by typing: $ scala Welcome to Scala version 2.8.0.RC3 (Java HotSpot(TM) Client VM, Java 1.6.0_20). Type in expressions to have them evaluated. Type :help for more information. scala> Now when I tried to enter an expression scala> 1 + 'a' the cursor hangs there without any response. Granted that I have chrome open with a million tabs and VLC playing in the background, but CPU utilization was 12% and virtual memory was about 75% utilized. What's going on ? Do I have to set the CLASSPATH or perform other steps.

    Read the article

  • Scala class to implement two Java Interfaces - how?

    - by puudeli
    Hi, I have just started learning Scala and I'm now wondering how I could implement two different Java interfaces with one Scala class? Let's say I have the following interfaces written in Java public interface EventRecorder { public void abstract record(Event event); } public interface TransactionCapable { public void abstract commit(); } But a Scala class can extend only one class at a time. How can I have a Scala class that could fulfill both contracts? Do I have to map those interfaces into traits? Note, my Scala classes would be used from Java as I am trying to inject new functionality written in Scala into an existing Java application. And the existing framework expects that both interface contracts are fulfilled.

    Read the article

  • Scala: Mixing traits with private fields

    - by Vilius Normantas
    It's not much of a question, it's rather my excitement that it's possible at all! I wrote this little example just to prove the opposite - I expected either a compiler error or one of the values (111 or 222, I wasn't sure). scala> trait T1 { private val v = 111; def getValueT1 = v } scala> trait T2 { private val v = 222; def getValueT2 = v } scala> class T12 extends T1 with T2 scala> val t = new T12 scala> t.getValueT1 res9: Int = 111 scala> t.getValueT2 res10: Int = 222 Why doesn't the v get overridden? Off course this works only as long as vs are private, but still.

    Read the article

  • Scala Eclipse IDE suddenly ignoring breakpoints

    - by malsmith
    I've been using Scala 2.8RC1 and Scala Eclipse plugin for 2.8 RC1 happily for a few days. However, last night after adding a couple jar files to my environment (apache http client jars) the debugger just stopped stopping at breakpoints in scala code. Java code stops fine at breakpoints. I tried creating a new mimimal scala app breakpoints don't stop. I've tried switching to sun-jre-1.6.0.20 from the openjdk-1.6.18 I had been using. I've switched to the scala 2.8 nightly and also eclipse plugin for scala nightly builds. No luck. I would greatly appreciate ideas for fixes. Rather frustrating as the initial experience with 2.8 was really great.

    Read the article

  • Scala :: operator, how it works?

    - by Felix
    Hello Guys, in Scala, I can make a caseclass case class Foo(x:Int) and then put it in a list like so: List(Foo(42)) Now, nothing strange here. The following is strange to me. The operator :: is a function on a list, right? With any function with 1 argument in Scala, I can call it with infix notation. An example is 1 + 2 is a function (+) on the object Int. The class Foo I just defined does not have the :: operator, so how is the following possible: Foo(40) :: List(Foo(2)) ? In scala 2.8 rc1, I get the following output from the interactive prompt: scala> case class Foo(x:Int) defined class Foo scala> Foo(40) :: List(Foo(2)) res2: List[Foo] = List(Foo(40), Foo(2)) scala> I can go on and use it, but if someone can explain it I will be glad :)

    Read the article

  • Simple Scala syntax - trying to define "==" operator - what am I missing?

    - by Alex R
    While experimenting with some stuff on the REPL, I got to a point where I needed something like this: scala class A(x:Int) { println(x); def ==(a:A) : Boolean = { this.x == a.x; } } Just a simple class with an "==" operator. Why doesn't it work??? Here's the result: :10: error: type mismatch; found : A required: ?{val x: ?} Note that implicit conversions are not applicable because they are ambiguous: both method any2ArrowAssoc in object Predef of type [A](x: A)ArrowAssoc[A] and method any2Ensuring in object Predef of type [A](x: A)Ensuring[A] are possible conversion functions from A to ?{val x: ?} class A(x:Int) { println(x); def ==(a:A) : Boolean = { this.x == a.x; } } ^ This is scala 2.8 RC1. Thanks

    Read the article

  • In Scala 2.8 collections, why was the Traversable type added above Iterable?

    - by Seth Tisue
    I know that to be Traversable, you need only have a foreach method. Iterable requires an iterator method. Both the Scala 2.8 collections SID and the "Fighting Bitrot with Types" paper are basically silent on the subject of why Traversable was added. The SID only says "David McIver... proposed Traversable as a generalization of Iterable." I have vaguely gathered from discussions on IRC that it has to do with reclaiming resources when traversal of a collection terminates? The following is probably related to my question. There are some odd-looking function definitions in TraversableLike.scala, for example: def isEmpty: Boolean = { var result = true breakable { for (x <- this) { result = false break } } result } I assume there's a good reason that wasn't just written as: def isEmpty: Boolean = { for (x <- this) return false true }

    Read the article

  • Why is this Scala example of implicit paremeter not working?

    - by Alex R
    simple REPL test... def g(a:Int)(implicit b:Int) = {a+b} Why do neither of these attempted usages work? 1. scala class A { var b:Int =8; var c = g(2) } :6: error: could not find implicit value for parameter b: Int class A { var b:Int =8; var c = g(2) } 2. scala class A(var b:Int) { var c = g(2) } :6: error: could not find implicit value for parameter b: Int class A(var b:Int) { var c = g(2) } ^ Thanks

    Read the article

  • How do I implement a collection in Scala 2.8?

    - by Simon Reinhardt
    In trying to write an API I'm struggling with Scala's collections in 2.8(.0-beta1). Basically what I need is to write something that: adds functionality to immutable sets of a certain type where all methods like filter and map return a collection of the same type without having to override everything (which is why I went for 2.8 in the first place) where all collections you gain through those methods are constructed with the same parameters the original collection had (similar to how SortedSet hands through an ordering via implicits) which is still a trait in itself, independent of any set implementations. Additionally I want to define a default implementation, for example based on a HashSet. The companion object of the trait might use this default implementation. I'm not sure yet if I need the full power of builder factories to map my collection type to other collection types. I read the paper on the redesign of the collections API but it seems like things have changed a bit since then and I'm missing some details in there. I've also digged through the collections source code but I'm not sure it's very consistent yet. Ideally what I'd like to see is either a hands-on tutorial that tells me step-by-step just the bits that I need or an extensive description of all the details so I can judge myself which bits I need. I liked the chapter on object equality in "Programming in Scala". :-) But I appreciate any pointers to documentation or examples that help me understand the new collections design better.

    Read the article

  • Clojure Protocols vs Scala Structural Types

    - by Vasil Remeniuk
    After watching the interview with Rich Hickey on Protocols in Clojure 1.2, and knowing very little about Clojure, I have some questions on Clojure Protocols: Are they intended to do the same thing as Structural Types in Scala? What benefits do Protocols have over Structural Types (performance, flexibility, code clarity, etc.)? Are they implemented through reflections? Questions on interoperability with Scala: Can Protocols be used instead of Structural Types in Scala? Can they be extended (if 'extension' term can be applied to Protocols) in Scala?

    Read the article

  • Scala command line parameters in eclipse?

    - by Mitch Blevins
    Scala includes the continuations plugin now (yay), but must be enabled by passing "-P:continuations:enable" to the scala compiler. Is there a way to pass arbitrary arguments to scalac for the eclipse scala plugin? From: http://permalink.gmane.org/gmane.comp.lang.scala/19439 the plugin is loaded by default, but it must be enabled by the command line argument -P:continuations:enable

    Read the article

  • Scala actors: receive vs react

    - by jqno
    Let me first say that I have quite a lot of Java experience, but have only recently become interested in functional languages. Recently I've started looking at Scala, which seems like a very nice language. However, I've been reading about Scala's Actor framework in Programming in Scala, and there's one thing I don't understand. In chapter 30.4 it says that using react instead of receive makes it possible to re-use threads, which is good for performance, since threads are expensive in the JVM. Does this mean that, as long as I remember to call react instead of receive, I can start as many Actors as I like? Before discovering Scala, I've been playing with Erlang, and the author of Programming Erlang boasts about spawning over 200,000 processes without breaking a sweat. I'd hate to do that with Java threads. What kind of limits am I looking at in Scala as compared to Erlang (and Java)? Also, how does this thread re-use work in Scala? Let's assume, for simplicity, that I have only one thread. Will all the actors that I start run sequentially in this thread, or will some sort of task-switching take place? For example, if I start two actors that ping-pong messages to each other, will I risk deadlock if they're started in the same thread? According to Programming in Scala, writing actors to use react is more difficult than with receive. This sounds plausible, since react doesn't return. However, the book goes on to show how you can put a react inside a loop using Actor.loop. As a result, you get loop { react { ... } } which, to me, seems pretty similar to while (true) { receive { ... } } which is used earlier in the book. Still, the book says that "in practice, programs will need at least a few receive's". So what am I missing here? What can receive do that react cannot, besides return? And why do I care? Finally, coming to the core of what I don't understand: the book keeps mentioning how using react makes it possible to discard the call stack to re-use the thread. How does that work? Why is it necessary to discard the call stack? And why can the call stack be discarded when a function terminates by throwing an exception (react), but not when it terminates by returning (receive)? I have the impression that Programming in Scala has been glossing over some of the key issues here, which is a shame, because otherwise it's a truly excellent book.

    Read the article

  • Using Scala array from java

    - by Grégoire
    Hi I'm trying to use some library code written in scala from a java program. I have a function that returns an Array (a scala Array) and I thought it would be possible to do Tree[] = ScalaObject.myScalaFunction() But the I get this error : [error] found : scala.runtime.BoxedArray [error] required: org.grammaticalframework.Trees.Absyn.Tree[] What is the correct way to use a scala array in java ?

    Read the article

  • Samples of Scala and Java code where Scala code looks simpler/has fewer lines?

    - by Roman
    I need some code samples (and I also really curious about them) of Scala and Java code which show that Scala code is more simple and concise then code written in Java (of course both samples should solve the same problem). If there is only Scala sample with comment like "this is abstract factory in Scala, in Java it will look much more cumbersome" then this is also acceptable. Thanks!

    Read the article

  • Parser that accepts Scala Identifiers?

    - by Mirko Stocker
    I was wondering whether the standard Scala parser combinators contain a parser that accepts the same identifiers that the Scala language itself also accepts (as specified in the Scala Language Specification, Section 1.1). The StdTokenParsers trait has an ident parser, but it rejects identifiers like empty_?. (If there is indeed no such parser, I could also just instantiate the Scala parser itself, but that wouldn't be as lightweight anymore.)

    Read the article

  • Samples of Scala and Java code where Scala code looks simpler/has less lines?

    - by Roman
    I need some code samples (and I also really curious about them) of Scala and Java code which show that Scala code is more simple and concise then code written in Java (of course both samples should solve the same problem). If there is only Scala sample with comment like "this is abstract factory in Scala, in Java it will look much more cumbersome" then this is also acceptable. Thanks!

    Read the article

  • In Scala, when is (A,A)=>R not equivalent to Function2 ?

    - by Alex R
    I'm trying to define and use my own foreach function. This is in the middle of a larger block of code. But the essence of the error I'm getting is this: test_2.scala:32: error: type mismatch; found : (A, A) = Unit required: Function2 $amount.foreach( (k:A,v:A) = { How is this error conceivably possible? Isn't (A, A) => Unit always a subtype of Function2 regardless of what else might be going on in the code?

    Read the article

  • How to write Tetris in Scala? (code review)

    - by eed3si9n
    Today's the 25th birthday of Tetris. I believe writing Tetris clone is one of the best ways to familiarize oneself to a new language or a platform. It's not completely trivial and it lends itself well to learning language specific constructs like iterators and closures. I've been hearing about Scala, and finally decided to read some docs and write a Tetris clone. So, this is my first Scala code. I did try to use functional constructs, but am sure there are lots of things I can improve to do it more Scala way. Please give me suggestions using comment. Also other submissions of Tetris clone in Scala are welcome too. I'm aware that the actual question itself is somewhat subjective, but I think this is of some value since others can use this as example (or anti-example) code. Edit: Let me rephrase the question. What can I do to make the code more Scala-ish?

    Read the article

  • Catch all exceptions in Scala 2.8 RC1

    - by Michel Krämer
    I have the following dummy Scala code in the file test.scala: class Transaction { def begin() {} def commit() {} def rollback() {} } object Test extends Application { def doSomething() {} val t = new Transaction() t.begin() try { doSomething() t.commit() } catch { case _ => t.rollback() } } If I compile this on Scala 2.8 RC1 with scalac -Xstrict-warnings test.scala I'll get the following warning: test.scala:16: warning: catch clause swallows everything: not advised. case _ => t.rollback() ^ one warning found So, if catch-all expressions are not advised, how am I supposed to implement such a pattern instead? And apart from that why are such expressions not advised anyhow?

    Read the article

  • How to use @PersistentCapable annotation in Scala 2.8

    - by Gero
    Hi, I'm switching from Scala 2.7.7 to Scala 2.8.0RC3 and now a few of my classes don't compile anymore. The problem is in the @PersistentCapable annotation: import javax.jdo.annotations._ import java.util.Date @PersistenceCapable{identityType=IdentityType.APPLICATION} class Counter(dt: Date, cName: String, vl: int) { <.. snip ..> } This code results in the following compilation errors: [ERROR] /Users/gero/prive/kiva/kivanotify-gae/src/main/scala/net/vermaas/kivanotify/model/LoanProcessed.scala:7: error: expected start of definition [INFO] @PersistenceCapable{val identityType = IdentityType.APPLICATION} I already tried a couple of variations, did some Googling but without luck. Any ideas on how I can use the @PersistentCapable annotation with Scala 2.8.0 RC3? Thanks, Gero

    Read the article

  • Setting Scala "Platform" for NetBeans 6.8 on Ubuntu Lucid Lynx

    - by David
    I'm trying to use NetBeans 6.8 with Scala, and it can't find the "Scala Platform" (whatever that is supposed to be). I'm using Ubuntu Lucid Lynx (fully updated). The libraries are in /usr/share/java, the binaries in /usr/bin, the docs in /usr/share/doc/scala-doc/, and the sources are uninstalled. I think that NetBeans is looking for Scala to be in one single directory (with bin, lib, etc.). I created /usr/share/scala and placed links to the other directories, but it still didn't quite make it. Can someone straighten me out? (And why is it a "platform"? More needless jargon...)

    Read the article

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