Hi folks! I've recently started playing with Scala (2.8) and noticed the I can write the following code (in the Scala Interpreter):
scala> var x : Unit = 10
x : Unit = ()
It's not obvious what's going on there. I really didn't expect to see any implicit conversion to Unit.
...
I've been programming in Java for the last few years, but due to disappointment with the current state of the language I'd like to switch to another JVM language with all the goodies of dynamic languages and features like closures, etc. I've looked around and Scala and Groovy seem the most popular choices. Am I missing other good languag...
In Scala I could define an abstract class and implement it with an object:
abstrac class Base {
def doSomething(x: Int): Int
}
object MySingletonAndLiteralObject extends Base {
override def doSomething(x: Int) = x*x
}
My concrete example in Python:
class Book(Resource):
path = "/book/{id}"
def get(request):
...
I have this inheritance
sealed abstract class MyValue
case class MyString(s:String) extends MyValue
case class MyBoolean(b:Boolean) extends MyValue
case class MyR(m1:MyValue, m2:MyValue) extends MyValue
case class MyU(m1:MyValue, m2:MyValue) extends MyValue
/* ... */
and
implicit def string2myString(s:String) = MyString(s)
implicit ...
In Scala (2.7.7final), the Predef.println method is defined as having the following signature:
def println (x : Any) : Unit
How come, then that the following works:
scala> println(1,2)
(1,2)
Does the compiler automatically convert a comma-separated list of arguments into a Tuple? By what magic? Is there an implicit conversion goi...
The Good Book states that:
A class and its companion object can access each other’s private members.
Perhaps naively, I took this as meaning that a class didn't need to explicitly import the members from its companion object. I.e., the following would work:
object Foo {
def bar = 4
}
class Foo {
def foo = bar
}
Well, the re...
Hi,
I´m pretty new to scala, so excuse my question if it is dumb.
Is there any way to build dynamic multi-dimensional arrays in scala. I know arrays in scala must be initializes in its sizes and dimensions, so I don't want that. The Datastructure should be dynamic. I tried to build it with lists in lists, but I lost myself some way :)...
I have a tree-like structure of abstract classes and case classes representing an Abstract Syntax Tree of a small language.
For the top abstract class i've implemented a method map:
abstract class AST {
...
def map(f: (AST => AST)): AST = {
val b1 = this match {
case s: STRUCTURAL => s.smap(f) // structural node for examp...
For lift development, I sometimes need to use match–case statements like the following. (Rewritten to plain scala for easier understanding.) One note to them: These are actually different partial functions, defined in different parts of the code, so it’s important that a case statement fails in or before the guard in order to have the ot...
I was playing with creating a generic factory as follows:
trait Factory[T] { def createInstance():T = new T() }
val dateFactory = new Factory[Date](){}
val myDate = dateFactory.createInstance()
The 'new T()' doesn't compile, as T is undefined until runtime. I know that I can get it to work by passing in an instance of the class to so...
How can scala make writing multi-threaded programs easier than in java? What can scala do (that java can't) to facilitate taking advantage of multiple processors?
...
I have a high CPU/memory bound task that I would like my Scala program to execute in parallel. So, I'm using the Actors framework (using receive in a while(true) loop). I call the start method on the actor and send it thousands of messages to process.
During the execution of the program (takes about an hour), only 100 - 120% of the CPU...
What would be the best Scala collection (in 2.8+), mutable or immutable, for the following scenario:
Sequentially ordered, so I can access items by position (a Seq)
Need to insert items frequently, so the collection must be able to grow without too much penalty
Random access, frequently need to remove and insert items at arbitrary inde...
Has anyone successfully used Circumflex ORM from an sbt project? How can I specify my Circumflex properties, such as 'orm.connection.driver'? A properties.cx file is not picked up as my runtime classpath apparently contains only sbt-launch-0.7.3.jar.
...
I have a Scala application using Akka that receives REST requests, makes some operations against a database, and responds with some information to the client. As it is, my db operations take a long time and my REST-enabled actor is unable to respond to new requests in the meantime, even though I could run lots of operations concurrently ...
I'm quite impressed by what Lift 2.0 brings to the table with Actors and StatefulSnippets, etc, but I'm a little worried about the memory overhead of these things. My question is twofold:
How does Lift determine when to garbage collect state objects?
What does the memory footprint of a page request look like?
If a web crawler dances ...
Hi, I have problem with simple spring mvc controller written in scala:
@Controller
class HelloWorldController {
implicit def sessionFactory2Session(sf: SessionFactory) = sf.getCurrentSes
@Autowired
var sessionFactory: SessionFactory = null
@Transactional
@RequestMapping(value=Array("/hello.html"),method = Array(RequestMethod.GE...
While browsing the source code of the scala API I met this package definition here :
package scala.util.parsing
package combinator
package syntactical
What does that mean ? That the class will be available in more than one package ?
...
When using Scala RemoteActors I was getting a ClassNotFoundException that referred to scala.actors.remote.NetKernel. I copied someone else's example and added RemoteActor.classLoader = getClass.getClassLoader to my Actor and now everything works. Why is this necessary?
...
scala> Float.floatToI
On pressing tab here, it displays Float.floatToIntBits. But,
scala> Float.floatToIntBits(2f)
<console>:6: error: value floatToIntBits is not a member of object Float
Float.floatToIntBits(2f)
^
...