scala

Can an Akka anonymous actor access self?

Can an Akka anonymous actor have access to self? In my particular case I'm wondering if I can reply back to the sender with code similar to this (does not compile due to self not being found): val xmlLoader = Actor.init { println("xml loader started") } receive { case LoadResource(url) => { try { val xml = XM...

PHP or Lift framework for a web application?

Hi guys! I'm currently developing a web application using PHP, but I'm considering developing the web application using the lift framework instead, because twitter and foursquare have implemented it. I know a few benefits using lift/Scala but, could you guys mention some benefits compared to PHP? Many thanks ...

How to apply function to each tuple of a multi-dimensional array in Scala?

I've got a two dimensional array and I want to apply a function to each value in the array. Here's what I'm working with: scala> val array = Array.tabulate(2,2)((x,y) => (0,0)) array: Array[Array[(Int, Int)]] = Array(Array((0,0), (0,0)), Array((0,0), (0,0))) I'm using foreach to extract the tuples: scala> array.foreach(i => i.foreac...

Scala: Remove duplicates in list of objects

Hi Folks, I've got a list of objects List[Object] which are all instantiated from the same class. This class has a field which must be unique Object.property. What is the cleanest way to iterate the list of objects and remove all objects(but the first) with the same property? Cheers Parsa ...

How to restrict a anonymous function's boundary?

I saw a below code: Map(1 -> "one", 2 -> "two") map _._1 this return a Iterable[Int], but if I want to do nothing with map, how to do it? I want to do something like below, but the below code can't compile, I know because it a object instance not a function, but how to create a function to do x => x and use placeholder: Map(1 -> "on...

(Number, Number) matches (Float, Int) but does not match (Int, Float)

Is it a bug in Scala 2.8.0 ? (the same happens with 2.8.1.RC2) import junit.framework._ import Assert._ class BugTest extends TestCase { def compare(first: Any, second: Any): Int = { (first, second) match { case (k: Int, o: Int) => k compare o //why the next case matches (Float, Int) but does not match (Int, F...

&& and || in Scala

Hi, since normal operators like +, ::, -> and so on are all methods which can be overloaded and stuff I was wondering if || and && are methods as well. This could theoretically work if this were methods in of the boolean object. But if they are, why is something like if (foo == bar && buz == fol) possible? If the compiler reads from ...

Working with tuples in Scala

I want to do something like this (simplified quite heavily): ((1, 2, 3, 4, 5, 6), (6, 5, 4, 3, 2, 1)).zipped map (_ + _) Ignore the actual values of the integers (although it's important that these are 6-tuples, actually :)). Essentially, I want to use this fairly regularly in a function which maintains a Map[String, (Int, Int, Int, ...

Scala type alias including companion object [beginner question]

Hello, I'd like to write a type alias to shorten, nice and encapsulated Scala code. Suppose I got some collection which has the property of being a list of maps, the value of which are tuples. My type would write something like List[Map[Int, (String, String)]], or anything more generic as my application allows it. I could imagine having...

Scala : parameterize a type with one of its inner types

I would like to parameterize a type with one of its subclasses. Consider the following: class DataLoader { class Data { /* data specifics to this data loader */ } def getData : Data /* and so on */ } Now I want to make this loader able to asynchronously retrieve data from the network. One of the options is to have it subclass Call...

Scala: Convert org.w3c.dom.Document to scala.xml.NodeSeq

Hey folks, Title is pretty self-explanatory. How can I convert an instance of org.w3c.dom.Document to a Scala NodeSeq, to enjoy it's facilitation? Cheers Parsa ...

How to combine multiple PNGs into one big PNG file?

I have approx. 6000 PNG files (256*256 pixels) and want to combine them into a big PNG holding all of them programmatically. What's the best/fastest way to do that? (The purpose is printing on paper, so using some web-technology is not an option and having one, single picture file will eliminate many usage errors.) I tried fahd's sugg...

Debunking Scala myths

What are the most commonly held misconceptions about the Scala language, and what counter-examples exist to these? UPDATE I was thinking more about various claims I've seen, such as "Scala is dynamically typed" and "Scala is a scripting language". I accept that "Scala is [Simple/Complex]" might be considered a myth, but it's also a vi...

error: value sorted is not a member of List[Int]

Welcome to Scala version 2.8.0.Beta1-prerelease (Java HotSpot(TM) Client VM, Java 1.6.0_21). Type in expressions to have them evaluated. Type :help for more information. scala> List(3, 1, 2).sorted <console>:5: error: value sorted is not a member of List[Int] List(3, 1, 2).sorted ^ Why am I getting this wei...

Design patterns/best practice for building Actor-based system

I am struggling to find any decent links to design patterns, best practice or good, basic architectural principles that should be used in building Actor-based apps. Those few that I know of are: Blog posts, articles, WIKIs, guides OTP Design Principles User's Guide Patterns and Best Practices for Enterprise Integration (in general, c...

How to emulate a dependent type in Scala

I'm trying to define a generic residue class ring in Scala. A residue class ring is defined by some base ring (e.g. the integers) and a modulus (e.g. two), which is a value from the base ring. Both rings and their elements are objects, hence the type of the modulus would normally be a dependent type, depending on the base ring. I underst...

Slice notation in scala ?

Is there something similar to slice notation in python in scala ? I think this is really a useful operation that should be incorporated in all languages. ...

Generating (PHP-)Code with Scala

Hello I want to generate PHP-code from a Model I created from parsing a WSDL-File. Anyone an advice how to generate PHP-Code in a smart way? Thanks ...

How would this Scala code look in idiomatic C#?

I came across this really nice looking Scala code while researching XMPP for a .Net project we're working on: object Main { /** * @param args the command line arguments */ def main(args: Array[String]) :Unit = { new XMPPComponent( new ComponentConfig() { def secret() : String = { "secret.goes.here" ...

Why are List and String identifiers named "xs" (in Scala and other languages)?

A lot of sample Scala code contains Strings and Collections named "xs" Why xs? Anything to do with the xs: used in XML (for Schema?) Examples: var xs = List(1,2,3) val xs = "abc" ...