How mouch Scala standard library can be reused to create variant of HashMap that does not handle collisions at all?
In HashMap implementation in Scala I can see that traits HashEntry, DefaultEntry and LinkedEntry are related, but I'm not sure whether I have any control over them.
...
These languages do not support mutually recursive functions optimization 'natively', so I guess it must be trampoline or.. heh.. rewriting as a loop) Do I miss something?
UPDATE: It seems that I did lie about FSharp, but I just didn't see an example of mutual tail-calls while googling
...
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 p...
I am trying to retrieve the AST from scala souce file. I have simplified the code (only relevant code) to following.
trait GetAST {
val settings = new Settings
val global = new Global(settings, new ConsoleReporter(settings))
def getSt = "hello" //global.typedTree(src, true)
}
object Tre extends GetAST {
def main(args:...
How do you code a function that takes in a block of code as a parameter that contains case statements? For instance, in my block of code, I don't want to do a match or a default case explicitly. I am looking something like this
myApi {
case Whatever() => // code for case 1
case SomethingElse() => // code for case 2
}
And insid...
I just found out that there are such iterators in Java.
Does Scala have iterators with 'set' and 'remove' methods for
iterating (and modifying) mutable collections like array?
If there is no such iterator then is there a good reason for that?
...
I'd like to process a document to retrieve a value that could have more than one path. The ideal signature would look something like:
def value(doc: Elem, potential_paths: List[something]): String
Where it would simply process the doc looking at the head of the potential_paths, if found, return it, otherwise continue with potential_p...
I'm trying to parse an Apple plist file and I need to get an array Node within it. Unfortunately its only unique identifier is sibling Node right before it, <key>ProvisionedDevices</key>. Right now my best thoughts are to use Java's XPATH querying or Node.indexOf.
Here is an example:
<plist version="1.0">
<dict>
<...
Can someone tell me why this does not work?
case class XY(enum: MyEnum)
object MyEnum extends Enumeration {
val OP1, OP2 = Value
}
Error: not found: type MyEnum
...
This isn't necessarily a Scala question, it's a design question that has to do with avoiding mutable state, functional thinking and that sort. It just happens that I'm using Scala.
Given this set of requirements:
Input comes from an essentially infinite stream of random numbers between 1 and 10
Final output is either SUCCEED or FAIL
T...
I'm starting with Scala + Android (and using the sbt android plugin). I'm trying to wire a button action to a button without the activity implementing View.OnClickListener.
The button click fails at runtime because the method cannot be found. The document I'm working through says that I need only declare a public void method taking a Vi...
Currently my whole work cycle is:
edit foo.scala
fsc foo.scala && scala -cp . FooMain
But my project is getting bigger and I would like to split files, make unit tests, etc.
But I'm too lazy for reading sbt documentation and doing whatever needs to be done to get a sbt's "Makefile". Similarly for unit tests (there are so many framewo...
And more specific example:
abstract trait A
trait B extends A
trait C extends A
How to check what traits that extend trait A (it can be from 0 to many) were mixed in specified class?
...
When this code is executed:
var a = 24
var b = Array (1, 2, 3)
a = 42
b = Array (3, 4, 5)
b (1) = 42
I see three (five?) assignments here. What is the name of the method call that is called in such circumstances?
Is it operator overloading?
Update:
Can I create a class and overload assignment? ( x = y not x(1) = y )
...
Hello, is there any way to have a tail-recursive function inside CPS not throwing a StackOverflow?
import scala.util.continuations._
object CPSStackOverflow {
def main(args: Array[String]) = {
reset {
def recurse(i: Int): Unit @suspendable = {
println(i)
shift { k: (Unit => Unit) =>
k( () ) // just ...
Given this:
abstract class ViewPresenterPair {
type V <: View
type P <: Presenter
trait View {self: V =>
val presenter: P
}
trait Presenter {self: P =>
var view: V
}
}
I am trying to define an implementation in this way:
case class SensorViewPresenter[T] extends ViewPresenterPair {
type V = SensorView[T]
ty...
I've got this code that works:
def testTypeSpecialization: String = {
class Foo[T]
def add[T](obj: Foo[T]): Foo[T] = obj
def addInt[X <% Foo[Int]](obj: X): X = {
add(obj)
obj
}
val foo = addInt(new Foo[Int] {
def someMethod: String = "Hello world"
})
foo.someMethod
}
But, I'd lik...
private[this]object MMMap extends HashMap[A, Set[B]] with MultiMap[A, B]
How convert it to immutable?
...
val uninterestingthings = ".".r
val parser = "(?ui)(regexvalue)".r | (uninterestingthings~>parser)
This recursive parser will try to parse "(?ui)(regexvalue)".r until the end of input. Is in scala a way to prohibit parsing when some defined number of characters were consumed by "uninterestingthings" ?
UPD: I have one poor solution:
...
Given an instance of a class, we can obviously return its name:
trait MixedInClassDiscovery {
val className = this.getClass.getName
}
class AClass extends MixedInClassDiscovery {
...
this.className // returns "AClass"
...
}
But this way uses reflection, once for every instance of AClass. Can the same be done once for every cl...