I would like to do a presentation of Scala on my University in hope that I can get some attention for this great language.
I would like to show some slides and then do some real-time codding.
I think I will use IDEA IDE to further show how easy it is to use.
What I need are good slides (to lazy to do them myself).
Neat examples of code...
And I mean that in the same sense that a C/Java for is just a funky syntax for a while loop.
I still remember when first learning about the for loop in C, the mental effort that had to go into understanding the execution sequence of the three control expressions relative to the loop statement. Seems to me the same sort of effort has to ...
I'm writing a code generator which produces Scala output.
I need to emulate a ternary operator in such a way that the tokens leading up to '?' remain intact.
e.g. convert the expression c ? p : q to c something. The simple if(c) p else q fails my criteria, as it requires putting if( before c.
My first attempt (still using c/p/q as abo...
simple REPL test...
def g(a:Int)(implicit b:Int) = {a+b}
Why do neither of these attempted usages work?
1.
scala> class A { var b:Int =8; var c = g(2) }
:6: error: could not find implicit value for parameter b: Int
class A { var b:Int =8; var c = g(2) }
2.
scala> class A(var b:Int) { var c = g(2) }
:6: error: could no...
How does scala.collection.JavaConversions supercede the answers given here:
http://stackoverflow.com/questions/495741/iterating-over-java-collections-in-scala
(doesn't work because the "jcl" package is gone)
and here
http://www.eishay.com/2009/05/iterating-over-map-with-scala.html
(doesn't work me in a complicated test which I'l...
Or does it just clutter up the code for something the JIT would take care of automatically anyway.
...
this works as expected
scala> 3 match { case x:Int => 2*x }
res1: Int = 6
why does this fail?
scala> 3 match { case $x:Int => 2*$x }
:1: error: '=>' expected but ':' found.
3 match { case $x:Int => 2*$x }
^
scala> 3 match { case `$x`:Int => 2*$x }
:1: error: '=>' expected but ':' found.
3 matc...
Why does this code fail to compile, but compiles successfully when I uncomment the indicated line? (I'm using Scala 2.8 nightly). It seems that explicitly calling string2Wrapper allows it to be used implicitly from that point on.
class A {
import Implicits.string2Wrapper
def foo() {
//string2Wrapper("A") ==> "B" // <-- uncommen...
assuming I running Scala 2.8.0 RC1, the following scala code should print out the content of the file "c:/hello.txt"
for ( line<-Source.fromPath( "c:/hello.txt" ).getLines )
println( line )
However, when I run it, I get the following error
<console>:10: error: missing arguments for method getLines in class Source;
...
Hi, using the CPS compiler-plugin of Scala 2.8, there are the two magic controls reset and shift. Reset delimits the continuation and shift captures the continuation.
There is an example of using CPS with NIO, using nested resets as a type of "forking"...?
I don't exactly understand the purpose of nesting the resets, what's the effect?
...
I'm studying the source code of the Scala 2.8 collection classes. I have questions about the hierarchy of scala.collection.Traversable. Look at the following declarations:
package scala.collection
trait Traversable[+A]
extends TraversableLike[A, Traversable[A]]
with GenericTraversableTemplate[A, Traversable]
tr...
Using XScalaWT, this compiled under Scala 2.7:
class NodeView(parent: Composite) extends Composite(parent) {
var nodeName: Label = null
this.contains(
label(
nodeName = _
)
)
}
With 2.8.0 RC1, I get this error:
type mismatch; found : main.scala.NodeView required: org.eclipse.swt.widgets.Label
The types ...
The definitive reference for using Scala on android seems to be here: http://www.scala-lang.org/node/160
Unfortunately, all the references on using scala with android are based around Scala 2.7 and refer to a custom build android-library.jar, with a couple of cryptic references suggesting that this custom build isn't needed for later ve...
I seem to remember Scala treating methods ending in _= specially, so something like this:
object X { var x: Int = 0; def y_=(n : Int) { x = n }}
X.y = 1
should call X.y_=(1). However, in 2.8.0 RC1, I get an error message:
<console>:6: error: value y is not a member of object X
X.y = 1
^
Interestingly, just trying t...
Are there named constructors in Scala?
...
I tend to have this redundant naming in case classes:
abstract class MyTree
case class MyTreeNode (...)
case class MyTreeLeaf (...)
Isn't it possible to define Node and Leaf inside of MyTree?
What are best practices here?
...
I need something like this:
class Node (left : Node*, right : Node*)
I understand the ambiguity of this signature.
Is there a way around it better than the following?
class Node (left : Array[Node, right : Array[Node])
val n = new Node (Array(n1, n2), Array(n3))
Maybe some kind of separator like this?
val n = new Node (n1, n2, Se...
What is the difference between package and object?
...
I have a normal tree defined in Scala.
sealed abstract class Tree
object Tree {
case class Node (...) extends Tree
case class Leaf (...) extends Tree
}
Now I want to add a member variable to all nodes and leaves in the tree.
Is it possible with extend keyword or do I have to modify the tree classes by adding [T]?
Update:
It seems...
I have some class C:
class C (...) { ... }
I want to use it to index an efficient map. The most efficient map is an Array.
So I add a "global" "static" counter in companion object to give each object unique id:
object C {
var id_counter = 0
}
In primary constructor of C, with each creation of C I want to
remember global counter ...