Hi,
I'm learning Scala, so this is probably pretty noob-irific.
I want to to a multiline regular expression.
In Ruby it would be:
MY_REGEX = /com:Node/m
My Scala looks like:
val ScriptNode = new Regex("""<com:Node>""")
Here's my match function:
def matchNode( value : String ) : Boolean = value match
{
case ScriptNode() =>...
I have a project that is mixed Java/Scala, it is Java GUI code that makes use of a Scala library. Is there a way to write Scala code such that it will emit Java enums on compile time? The approaches I tried so far (sealed case classes, extend Enumeration) seem to generate normal classes which makes working with them from Java much hairie...
My company is beginning to write some code using Scala. I've been moved onto this project, and am a big fan of TDD, so I would like to get a unit-testing framework in place. However, the build system we're using for this project is Maven, and that's not going to change, for a variety of reasons.
I've looked at both ScalaTest and Scala...
It's a sad fact of life on Scala that if you instantiate a List[Int], you can verify that your instance is a List, and you can verify that any individual element of it is an Int, but not that it is a List[Int], as can be easily verified:
scala> List(1,2,3) match {
| case l : List[String] => println("A list of strings?!")
| cas...
I am using scala to load a XML file from file via the scala.xml.XML.loadFile() method. The documents I'm working with have namespaces already defined and I wish to change the namespace to something else using scala. For example, a document has a xmlns of "http://foo.com/a" with a prefix of "a" - I would like to change the namespace and p...
How do you provide overloaded constructors in Scala?
...
I'm new to Scala, so I may be off base on this, I want to know if the problem is my code. Given the Scala file httpparse, simplified to:
object Http {
import java.io.InputStream;
import java.net.URL;
def request(urlString:String): (Boolean, InputStream) =
try {
val url = new URL(urlString)
val body = ur...
Operator overloading in C++ is considered by many to be A Bad Thing(tm), and a mistake not to be repeated in newer languages. Certainly, it was one feature specifically dropped when designing Java.
Now that I've started reading up on Scala, I find that it has what looks very much like operator overloading (although technically it doesn'...
I just started exploring Scala in my free time.
I have to say that so far I'm very impressed. Scala sits on top of the JVM, seamlessly integrates with existing Java code and has many features that Java doesn't.
Beyond learning a new language, what's the downside to switching over to Scala?
...
Hi,
I am an experienced C++ programmer with average Python skills. The reasons I studied Python in the first place were:
to get a different perspective on programming (static vs dynamic, interpreted vs compiled, etc)
to increase the breadth of projects that I can work on (Python allows me to do web development, develop for Symbian phon...
Hello folks,
Just going through the sample Scala code on Scala website, but encountered an annoying error when trying to run it.
Here's the code: http://www.scala-lang.org/node/45. On running it on Eclipse, I get this 'Editor does not contain a main type' that prevents it from running.
Is there anything I need to do...i.e break that f...
In Scala, a class's primary constructor has no explicit body, but is defined implicitly from the class body. How, then, does one distinguish between fields and local values (i.e. values local to the constructor method)?
For example, take the following code snippet, a modified form of some sample code from "Programming in Scala":
class ...
I'm learning Scala and lift at the same time and I got stuck on understanding the syntax used to inintialize the SiteMap in the Boot.scala:
val entries = Menu(Loc("Home", "/", "Home")) ::
Menu(Loc("Foo", "/badger", "Foo")) ::
Menu(Loc("Directory Foo", "/something/foo", "Directory Foo")) :: Nil
LiftRules.setSiteMap(Site...
I have zero experience writing applications with Swing, but I have one application with which to start experimenting.
For this application, I want my window to have a variable number of small "tile"-like structures, which can be moved/closed/minimized just like windows by the user inside my main frame, and which will display, each a sma...
I try to test this in Scala Console (I mean console not script file):
while i < 10 {print(i) i += 1}
It doesn't work. I tried multiple lines it doesn't seem to either.
Am I obliged to use a script file just to test a simple loop ?
...
I can see there's a Sorting object with a quickSort method on it.
Can someone provide a code example of using it, sorting an array of object of arbitrary type? It looks like I need to pass in an impl of the Orderable trait, but I am unsure of the syntax.
Also, I would prefer answers doing this the 'scala way'. I know I can just use a J...
I am developing an application that needs to store information to a database. I would like to use a Scala solution if possible. If the database connectivity fails for some reason, I would like to write the raw SQL statements that would have been executed to a .sql script file. The idea is that when/if the connectivity to the database is ...
I have generated a new Scala project with Maven and it created a folder structure with a src/main/scala and a src/test/scala folder.
I have some code in src/main/scala and wanted to write some tests, the problem is that I can't import the classes from src/main/scala.
How do I do that?
...
I have a directory that continually fills up with "artefact" files. Many different programs dump their temporary files in this directory and it's unlikely that these programs will become self-cleaning any time soon.
Meanwhile, I would like to write a program that continually deletes files in this directory as they become stale, which I'...
The question is best explained by an example:
In Java for a JPA EntityManager, I can do the following(Account is my Entity class):
Account result = manager.find(Account.class, primaryKey);
In Scala, my naive attempt is:
val result = manager.find(Account.class, primaryKey)
But when I try to use Account.class in Scala, it seems to n...