While creating a map of String to partial functions I ran into unexpected behavior. When I create a partial function as a map element it works fine. When I allocate to a val it invokes instead. Trying to invoke the check generates an error. Is this expected? Am I doing something dumb? Comment out the check() to see the invocation. ...
Hello all,
I have been working on a project in scala, but I am getting some error messages that I don't quite understand. The classes that I am working with are relatively simple.
For example:
abstract class Shape
case class Point(x: Int, y: Int) extends Shape
case class Polygon(points: Point*) extends Shape
Now suppose that I create...
Language FAQ says
import scala.collection.mutable.{_, Map => _, Set => _}
should import all classes from package scala.collection.mutable, except Map and Set. But it gives me this error:
error: '}' expected but ',' found.
import scala.collection.mutable.{_, Map => _, Set => _}
Is there still a way to do this?
...
In Scala 2.8.0 RC 2 this definition:
def buttonGroup[T](values: Array[T], textProvider: T => String = (t: T => t.toString)) = ...
gives the error message:
not found: value t
def buttonGroup[T](values: Array[T], textProvider: T => String = (_.toString)) = ...
gives
missing parameter type for expanded function ((x$1) =>...
Hoogle allows you to search many standard Haskell libraries by either function name, or by approximate type signature. I find it very useful. Is there anything like Hoogle for Scala? Search in ScalaDoc 2 only finds types and packages by name.
...
Types:
def radioGroup[T](values: Array[T], textProvider: T => String)(setups:(RadioGroup[T] => Unit)*)(parent: Composite): RadioGroup[T]
def label(setups:(Label => Unit)*)(parent:Composite): Label
def contains(setups : (Composite => Unit)*) : Composite // "Pimp my library" on Composite
This works:
new Composite(parent, SWT.NONE).c...
Up until now I've been using Scala 2.7.7 (with Programming in Scala as my main reference). But as I'm a relative n00b, and 2.8 seems as if it will be out soon, I thought it would be a good idea to start using 2.8 before I get into any bad/outdated habits.
I've seen http://www.scala-lang.org/node/1564 as a list of key new features, but d...
For instance, I have a list (1 2 3 4 5 6 7 8 9 10 11), and want to roughen it by 3 elements (or another length) to get ((1 2 3) (4 5 6) (7 8 9) (10 11)). What pretty code could I use for this? Thanks.
...
In the code snippet below - why do I have to give a type annotation for Nil?
Welcome to Scala version 2.8.0.RC2 (OpenJDK Server VM, Java 1.6.0_18).
Type in expressions to have them evaluated.
Type :help for more information.
scala> List(Some(1), Some(2), Some(3), None).foldLeft(Nil)((lst, o) => o match { case Some(i) => i::lst; case No...
Is there a better way of doing this:
val totalScore = set.foldLeft(0)( _ + score(_) )
or this:
val totalScore = set.map(score(_)).sum
I think it's quite a common operation so was expecting something sleeker like:
val totalScore = set.sum( score(_) )
...
Say I have a list val list = List(34, 11, 98, 56, 43).
Now how do I find the index of the minimum element of the list (e.g. 1 in this case)?
...
Would you consider autoboxing in Java to be a form of polymorphism? Put another way, do you think autoboxing extends the polymorphic capabilities of Java?
What about implicit conversions in Scala?
My opinion is that they are both examples of polymorphism. Both features allow values of different data types to be handled in a uniform m...
I want to divide a list in "a specific number of" sublists.
That is, for example if I have a list List(34, 11, 23, 1, 9, 83, 5) and the number of sublists expected is 3 then I want List(List(34, 11), List(23, 1), List(9, 83, 5)).
How do I go about doing this? I tried grouped but it doesn't seem to be doing what I want.
PS: This is no...
I'm trying to implement a type of SortedMap with extended semantics. I'm trying to delegate to SortedMap as the storage but can't get around the variance constraints:
class IntervalMap[A, +B](implicit val ordering: Ordering[A])
//extends ...
{
var underlying = SortedMap.empty[A, List[B]]
}
Here is the error I get. I understand w...
The source code of map for Array is:
override def map[B](f: A => B): Array[B] = throw new Error()
But the following works:
val name : Array[String]= new Array(1)
name(0)="Oscar"
val x = name.map { ( s: String ) => s.toUpperCase }
// returns: x: Array[java.lang.String] = Array(OSCAR)
...
I am one step away from making the method described here:
http://stackoverflow.com/questions/2761443/targeting-android-with-scala-2-8-trunk-builds
work with a single project (vs one project for scala and one for android).
I've come across a problem. Using this input file (arguments to) proguard:
-injars bin;lib/scala-library.jar(!MET...
I run:
$ echo 'object Hi { def main(args: Array[String]) { println("Hi!") } }' > hw.scala
$ sbt
> warn
Set log level to warn
> run
Hi!
> package
$ java -jar target/scala_2.7.7/test_2.7.7-1.0.jar
Exception in thread "main" java.lang.NoClassDefFoundError: scala/ScalaObject
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang...
In language like python and ruby to ask the language what index-related methods its string class supports (which methods’ names contain the word “index”) you can do
“”.methods.sort.grep /index/i
And in java
List results = new ArrayList();
Method[] methods = String.class.getMethods();
for (int i = 0; i < methods.length; i++) { ...
How can I add a new page in the webapp directory in lift that can be accessed by users?
Currently only the index.html can be accessed through http://localhost:8080/ or http://localhost:8080/index.html
Say I add a static file newpage.html into webapp dir, then what can I do so users can access it through http://localhost:8080/newpage.ht...
Is there a way to tell sbt to package all needed libraries (scala-library.jar) into the main package, so it is stand-alone? (static?)
...