 | Scripster - interactive scala script pad |
//crash-course into scala: select the following defs and issue "run selection"
class Num (val i:Int) {
def + (other:Num) = new Num (this.i + other.i) // operators
override def toString : String = "Numero " + i.toString // inherit Java methods
override def equals (other:Any) = other match { // or override them
case n:Num => n.i == i
case _ => false // wildcard serves like a default case
}
}
object Num { // companion object contains statics for Num
def apply (i:Int) = new Num (i) // this lets you do Num(3) instead of new Num(3)
def valueOf (s:String) = new Num (s.toInt)
}
implicit def toNum (i:Int) = Num (i) // this makes the conversion implicit
def add (i:Num*) = { // variable argument list
val ss = "12344" // type inferred as String
var ii = Num(0)
for (k <- i) ii = ii + k // boo hoo - the way of the java...
assert (ii == i.foldLeft (Num(0)) (_+_)) // woo hoo - the way of the lambda ...
ii
}
//move cursor to following line and issue "run line"
add (1+2, 8/4) // see the implicit conversion?
//move cursor to end of following line and press ctrl+space for content assist
java.lang.Sys
Status is updated here...
Notice
Try and share scala code, using the Scripster, @2010 by Razvan Cojocaru.
See the guide,
forum or brush up on your
scala.
The current version is built on scala 2.9.1 and includes
scalaz 6.0.1, a
scala workflow DSL and the
snakking framework.
If you'd like to see more libraries included, please post on the forum.
- refresh page to get a new "session"
- F9 - runs current line
- CTRL+F9 runs the current selection
- CTRL+SPACE for content assist
Please note that this is a server that runs somewhere, i.e.
println ("Hello") will print in the server log files. If you want to see 3
just type 1+2
... not println(1+2)
Known issues:
- due to some Javascript/DOM incompatibilities that I don't understand, content assist doesn't work in I.E.
- if you encounter any issues, please refresh the browser (F5) - that will create a new session. You will loose the contents of the pad, so it would be a good idea to copy them beforehand.
- sessions expire in about 2-3 minutes and there's max 10...memory ain't cheap
- there should be no interaction between sessions...but, this is not fully tested yet.
- list of all current issues here.
Some of the 3rd party libraries used:
- ACE (former Bespin) - a code editor in JavaScript
- CodeMirror - an editable iframe-based code editor in JavaScript
- the scala parser
- JLine - a Java library for handling console input, we're using the one bundled with scala
Terms: the "blah-blah"
This service is provided as is, no warranties implied. You use it at your own risk.
It may crap out, stop working, be discontinued or changed to a yellow & red
pallette at any time, just to mess with you...of course, we'll get you to pay, to get nice colors... :) nah...just messing with ya'...
See current issues and please report new issues or enhancements here.
Customizing
When reusing the scripster library in your code, to customize this notice, put a "/public/scripster.html" in your classpath. An empty file should eliminate this (good in swing).