I am looking at building a Scala web app that will have lots of code snippets in many programming languages that I would like to hightlight. It looks like one of the best, most popular syntax highlighters is Pygments, a Python tool. I downloaded Jython and was able to load first it and then Pygments from within my Scala REPL. However, al...
Here's a bit of Scala code to sum the values from 1 to 9 which are divisible by 3 or 5. Why does line 5 return a Unit and not a Boolean type?
object Sample {
def main(args : Array[String]) {
val answer = (1 until 10).foldLeft(0) ((result, current) => {
if ((current % 3 == 0) || (current % 5 == 0)) {
...
We have a slow backend server that is getting crushed by load and we'd like the middle-tier Scala server to only have one outstanding request to the backend for each unique lookup.
The backend server only stores immutable data, but upon the addition of new data, the middle-tier servers will request the newest data on behalf of the cli...
I want to convert a Joda Time UTC DateTime object to local time.
Here's a laborious way to do it which seems to work. But there must be a better way.
Here's the code (in Scala) without surrounding declarations:
val dtUTC = new DateTime("2010-10-28T04:00")
println("dtUTC = " + dtUTC)
val dtLocal = timestampLocal(dtUTC)
...
Hi,
I'm doing a project to test Scala and Lift at my company, atm I'm implementing a REST API
that shoves XML around. I saw that there is an XMLApiHelper that offers the createTag method
that encapsulates the responses in a root element.
So I did this
object RestAPI extends RestHelper with XMLApiHelper {
serve {
…
}
…
def ...
OK the question might not say much, but here's the deal:
I'm learning scala and decided to make an utility class "FuncThread" with a method which receives a by-name parameter function (I guess its called that because it's a function but without a parameter list) and then starts a thread with a runable which in turn executes the passed fu...
I am using the Scala 2.8 default parameters on a constructor, and for Java compatibility reasons, I wanted a no-arg constructor that uses the default parameters.
This doesn't work for very sensible reasons:
class MyClass(field1: String = "foo", field2: String = "bar") {
def this() = {
this() // <-- Does not compile, but how...
I'm working on a homework assignment for my object oriented design class, and I'm running into trouble with Scala's companion objects. I've read in a few places that companion objects are supposed to have access to their companion class's private methods, but I can't seem to get it to work. (Just as a note, the meat of the assignment had...
I'm trying to integrate a Lift application into some existing Java code. In one of my snippets, I have an Array of Java objects that I need to map that into a NodeSeq. I can get an Array of Node's, but not a NodeSeq. (At least, not in very functional-looking way).
import scala.xml.NodeSeq
// pretend this is code I can't do anything ...
There are claims that Scala's type system is Turing complete. My questions are:
Is there a formal proof for this?
How would a simple computation look like in the Scala type system?
Is this of any benefit to Scala - the language? Is this making Scala more "powerful" in some way compared languages without a Turing complete type system?
...
I need define some case classes like the following one:
case class Gt(key: String, value: Any) extends Expression {
def evalute[V, E](f: String => Any) = {
def compare(v: Any): Boolean = {
v match {
case x: Number => x.doubleValue > value.asInstanceOf[Number].doubleValue
case x: Array[_] => x.forall(a => comp...
I'd like to be able to set a colour of every point (addressed by x&y, where x is a DateTime (of joda-time, actually) and y is a double) on a chart to represent a z=f(x,y) value. Is it possible with JFreeChart?
...
I want to use a tree in my Scala swing application, but the component isn't available in the API.
Does a wrapper of JTree exists ?
If not, do you have any advice for making it ?
Thanks
...
Considering the following Scala snippet:
case class Foo(v1: String, v2: Int, v3: Any)
def inspect(p: Product) =
(0 until p.productArity).foreach(i => println(p.productElement(i)))
inspect(Foo("Moin", 77, null))
Does the invocation of inspect() here means that reflection is used (in whatever way)?
I'd like to somehow be able to ac...
With too many arguments, String.format easily gets too confusing. Is there a more powerful way to format a String. Like so:
"This is #{number} string".format("number" -> 1)
Or is this not possible because of type issues (format would need to take a Map[String, Any], I assume; don’t know if this would make things worse).
Or is the bet...
I have a project running simple built tool as building tool. All of my sub projects are sharing the same dependencies, so I want them to use the same lib folder. I could do so by creating symbolic links to my shared lib folder, but I hope to find a configuration in sbt that lets me change to path of my libraries.
override def dependenc...
Does scalatra use circumflex behind the scenes (or vise versa)? What are the key differences between them, and which one would you use?
Both frameworks are inspired by Sinatra and from a glance look identical.
Request routing with scalatra:
class ScalatraExample extends ScalatraServlet {
get("/date/:year/:month/:day") {
<ul>
<...
I'm just getting started with Scala and something which I think should be easy is hard to figure out. I am trying to implement the following function:
def square(x:Int):Int = { x * x }
This works just fine, but if I want to try to make this function work for any kind of number I would like to be able to do the following:
def square[T ...
There are tools of code obfuscation for Scala?
Thanks
...
I have an application that I'd like to have a prompt in. If it helps, this is a graph database implementation and I need a prompt just like any other database client (MySQL, Postgresql, etc.).
So far I have my own REPL like so:
object App extends Application {
REPL ! Read
}
object REPL extends Actor {
def act() {
loop...