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
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>
…
Being stuck with a scala2.9 compiler bug I've decided to try moving to Scala2.10 RC. As a part of the switch I was trying to install SBT 0.13 snapshot.
The official web page lists a broken link:
http://scalasbt.artifactoryonline.com/scalasbt/sbt-native-packages/org/scala-sbt/sbt//0.13.0-SNAPSHOT/sbt.tgz
There is nothing about 0.13 in the…
Do any exist? Ideally it would also come with a library of basic PHP functions.
I have a bunch of simple PHP scripts (no extensions, no fancy dynamic hacks, etc) I'd like to convert to Java... It would be great if a tool could do 80% of the work while I do the other 20%.
I have two solutions, but one doesn't compile and the other, I think, could be better:
object Foo extends App {
val vectors = List(List(1,2,3), List(2,2,3), List(1,2,2)) //just a stupid example
//transposing
println("vectors = " + vectors.transpose.map (_.sum)) //it prints vectors = List(4, 6, 8)
//folding
…
Given:
case class FirstCC {
def name: String = ... // something that will give "FirstCC"
}
cass class SecondCC extends FirstCC
val one = FirstCC()
val two = SecondCC()
How can I get "FirstCC" from one.name and "SecondCC" from two.name?
Ok, I'll explain why I ask this question. I begin to read Lift 2.2 source code these days.
In Lift, I found that, define inner class and inner trait are very heavily used.
object Menu has 2 inner traits and 4 inner classes. object Loc has 18 inner classes, 5 inner traits, 7 inner objects.
There're tons of codes write like this. I…
As far as I understand, Scala's == defines the natural equality of two objects.
I expected that Array(0,1,2) == Array(0,1,2) compares the natural equality e. g. checks if all elements of the array return true when compared with the corresponding elements of the other array.
People told me that Scala's Array is just a Java []…
I know that objects are treated pretty much like singletons in scala. However, I have been unable to find an elegant way to specify default behavior on initial instantiation. I can accomplish this by just putting code into the body of the object declaration but this seems overly hacky. Using an apply doesn't really work…
I want to create a very simple 2d multiplayer browsergame in html5. Something like Scalatron
I mainly want to do this to improve my scala skills, the problem is I would have to code the clientside code in javascript and the serverside code in scala. This would result in duplicated code.
Another option would be to ignore…
object Problem_2 extends App {
def fibLoop():Long =
{
var x = 1L
var y = 2L
var sum = 0L
var swap = 0L
while(x < 4000000)
{
if(x % 2 ==0) sum +=x
swap = x
x = y
y = swap + x
}
sum
}
def fib:Int = {
lazy val fs: Stream[Int] = 0 #:: 1 #:: fs.zip(fs.tail).map(p => p._1 + p._2)
…
When you create a case class, the compiler creates a corresponding companion object with a few of the case class goodies: an apply factory method matching the primary constructor, equals, hashCode, and copy.
Somewhat oddly, this generated object extends FunctionN.
scala> case class A(a: Int) …
I would like to know if it is possible to abstract the copy method of case classes. Basically I have something like sealed trait Op and then something like case class Push(value: Int) extends Op and case class Pop() extends Op.
The first problem: A case class without arguments/members does not define a copy method.…
I have just completed an evaluation of Java, Groovy and Scala.
The factors I considered were: readability, precision
The factors I would like to know: performance, ease of integration
I needed a BigDecimal level of precision.
Here are my results:
Java
void someOp()
{
BigDecimal del_theta_1 = toDec(6);
…
I am getting introduced to Functional Programming [FP] (using Scala). One thing that is coming out from my initial learnings is that FPs rely heavily on recursion. And also it seems like, in pure FPs the only way to do iterative stuff is by writing recursive functions.
And because of the heavy usage of recursion…
Is this an intended behavior or is it a bug? Consider the following trait (be it a class, doesn't matter):
trait P[T] {
class Inner(val f: T => Unit = _ => println("nope"))
}
This is what I would have expected:
scala> val p = new P[Int] {
| val inner = new Inner
| }
p:…
One of my high school students and I are going to try to do a port of Haskell's Parsec parser combinator library into Scala. (It has the advantage over Scala's built-in parsing library that you can pass state around fairly easily because all the parsers are monads.)
The first hitch I've come across…
I'm learning Scala and I want to know the best way of expressing this imperative pattern using Scala's functional programming capabilities.
def f(l: List[Int]): Boolean = {
for (e <- l) {
if (test(e))
return true
}
}
return false
}
The best I can come up with is along the…
Hi,
I'm trying to use Scala as part of an existing Java application and now I run into an issue with dependencies injected with a setter method (no DI frameworks in this part of code). How is this handled in a Scala way?
In Scala both val and var require to be initialized when declared but I…
Play Framework's (2.x) Form class has a method called fold who's usage is indicated as:
anyForm.bindFromRequest().fold(
f => redisplayForm(f),
t => handleValidFormSubmission(t)
)
Essentially, the first function parameter is what gets executed on binding failure, and the 2nd on…
Hi to everyone!
I'm working in a homework, and the professor asked me to implement the evaluation strategy called "call by name" in scheme in a certain language that we developed and he gave us an example at http://www.scala-lang.org/node/138 in the scala language, but i don't understand…
Can you people please suggest some good books / weblinks from where I can get to learn about above mentioned concepts?
(Please note that I am a Java programmer and have NO prior experience with functional programming. I have been studying Scala since last one month and would appreciate…
Hi,
I am fairly new to scala and I have the need to convert a string that is pipe delimited to one that is comma delimited, with the values wrapped in quotes and any quotes escaped by "\"
in c# i would probably do this like this
string st = "\"" + oldStr.Replace("\"",…