Monday, November 19, 2012

Monads, shmonads and functional programming

Post consolidated and moved to http://www.coolscala.com/wiki/Cool_Scala/Monads_shmonads_and_functional_programming

Saturday, September 29, 2012

OMG, scala is a complex language!

Blog post consolidated to http://www.coolscala.com/wiki/Cool_Scala/OMG_scala_is_a_complex_language

Quick scala – step 1: setup

This was originally posted in Oct 2011, on the blog.coolscala.com which I'm removing.

If you just want to play with scala quickly – you can use one of the few online interpreters, like http://www.simplyscala.com/or http://www.tryscala.org - these let you run small bits of code interactively. Otherwise, continue reading, to complete a local setup for scala development. You need these:
1.Java
2.Scala (command line)
3.Eclipse with the scala plugin
Installing Java:
1.Download and install a 1.6 JDK from http://www.oracle.com/technetwork/java/javase/downloads/index.html . Do not use a 1.7 for this exercise and make sure you install the JDK not just the JRE. The exact link I use is: http://www.oracle.com/technetwork/java/javase/downloads/jdk-6u27-download-440405.html
a.I recommend you use a 64 bit version, so you can allocate more memory to it
2.Run and install somewhere, let’s say C:\bin\jdk1.6.0_27\
a.I found it a good practice to keep my development tools in c:/bin
b.Make sure to check the “change destination folder” checkbox before letting the installer run…
3.Make sure the path to java.exe is in the PATH
a.Add C:\bin\jdk1.6.0_27\bin to the PATH system variable
b.Define a variable called JAVA_HOME with the value “C:\bin\jdk1.6.0_27\”.
4.Test it by opening a command line window and typing “java”.
Installing scala command line:
1.Download a distribution from http://www.scala-lang.org/downloads
2.Unpack it in a folder, let’s say C:/bin/scala
3.Make sure the path to scala.bat is in your PATH
a.Add C:/bin/scala/bin to the PATH system variable
4.Test it by opening a command line window and typing “scala”. You should get the scala interpreter prompt and then type“exit” to exit the interpreter.
Installing Eclipse:
1.Download Eclipse Classic from the download site: http://www.eclipse.org/downloads/packages/release/indigo/r
2.Install it (unzip it) in C:/bin/eclipsescala
3.To make sure it uses the JDK you just installed (if you went that route) modify your eclipsescala/eclipse.ini and add this line:
a.-vm
C:\bin\jdk1.6.0_27\bin
4.Start it up (eclipsescala/bin/eclipse.exe)
5.Install the scala plugin
a.Go to Help/Install new software
b.Click on Add
c.Type in name “scala291” and the url: http://download.scala-ide.org/releases-29/2.0.0-beta
d.You can see if there is a newer version at http://www.scala-ide.org/
e.Select this source in the drop-down
f.Click “Select All” to select the three features
g.Go ahead with the installation
6.Restart Eclipse
7.Read the detailed setups at http://www.assembla.com/spaces/scala-ide/wiki/SetupIt is a good idea to allocate Eclipse at least 1G – I use 2G.
8.If you changed any settings, restart Eclipse
To test your eclipse installation, select File/New/Project and see if “Scala Project” is in the list. You’ll use it for the “Hello World”exercise.
Check that the sources for the scala library are setup properly:
1.Open your project
2.CTRL+SHIFT+T to find types and type ‘List’
3.Scroll down the list to find the List from scala.collection.immutable
4.Click enter – you should now see the nicely formatted source code for List
5.You can take a quick look but don’t despair if that code looks foreign – we’ll get there soon enough.
Spruce up your Eclipse – my favorite plugins include:
-The GOTO plugin from, http://muermann.org/gotofile/
-The Color themes plugin, from http://www.eclipsecolorthemes.org/
-The VI plugin, from http://www.viplugin.com/viplugin/
Cheers – you are now setup to play with scala.

Friday, August 24, 2012

Racer kidz and wiki clubs - update

My little R&D into wiki domains at http://www.racerkidz.com seems to work fine - I add a feature evry now and then.

You can register a club, describe a racing schedule, then racers can add it to their profile and automatically, via the magic of wiki xpath, see the racing calendar and the map...

You can give it a try without an account from the home page.

I also experimentally used it to create simple blogs, like this enduro school. A blog has posts and that's that, see its domain definition.

Cheers!

Sunday, March 28, 2010

Killing an annoying warning

The most annoying warning ever has been haunting me for a while.

[javac] /home/razvanc/workspace7u6/razxml/src/razie/base/data/RiXmlUtils.java:160: warning: com.sun.org.apache.xpath.internal.objects.XObject is Sun proprietary API and may be removed in a future release


I refuse to include and move around large unnecessary libraries to deal with XML and XPATH just because Sun considers themselves the center of the universe and their internal libraries somehow more important then mine. In short, they figured there should be no way to remove this warning, although, in this case, they copied code from apache into their own libraries.

Well, the solution is rather simple. Most likely everyone has specific XML wrappers. Just put them in their own project, disable the java/scala builders. Then, build it manually, create a jar file and check it in.

Then, in all the other projects, use this jar directly. Since the jar is already compiled, the annoying warning is no more.

See for instance my xml utilities, at http://github.com/razie/razxml

What's more, I don't actually use the XML stuff directly. I wrapped it all in pretty much one single class, using XPATH for access. It's simple, fast enough and makes for very simple code:


Reg.doc(MediaConfig.MEDIA_CONFIG).xpa(
"/config/storage/host[@name='" + Agents.me().name + "']/media/@localdir"
)


For all xml data access, you should limit yourself to the xpe/xpl/xpa methods described in an earlier post (http://blog.homecloud.ca/2010/02/one-xpath-to-rule-them-all.html). So, use something like this instead: http://github.com/razie/razxml/blob/master/src/razie/base/data/XmlDoc.java

Cheers.

Saturday, March 13, 2010

The Option monad pattern thing

This informative post is consolidated in the new blog, at:

 http://www.coolscala.com/wiki/Blog:Cool_Scala/Post:The_Option_monad_pattern_thing

... where we take a closer look at the Option type of Scala, the monadic aspect of it and see how we can use it to inspire new patterns and new ways of looking at the code we write.

(Sorry - original content was removed from here, to avoid duplicates).

Monday, March 1, 2010

Scripster - interactive scala REPL using telnet, http etc

As mentioned before, I think that all apps must alllow scripted/programatic access to their objects.

I created a simple interactive gate to acces the scala REPL in any scala process. It only uses one port and supports telnet, http and swing:



The graphics are based on my 20widgets project, with the addition of a ScriptPad widget.

Content assist is only available in the telnet version (sic!). I will work to find some nice syntax-colored controls for the web version. Switch to character mode ("mode character" on ubuntu or default on windows) and use TAB to see a list of options. Right now it's a demo only, I need to find the parser's APIs to get the real content assist options ;)

You can download the single scripster-dist.jar file from my razpub project download, at http://code.google.com/p/razpub/ and run the example with this command line (replace /host/bin/scala with your $SCALA_HOME) :

java -classpath ./scripster-dist.jar:/host/bin/scala/lib/scala-library.jar:/host/bin/scala/lib/scala-compiler.jar:/host/bin/scala/lib/scala-swing.jar razie.scripster.JScalapSwing


To use it in your process, put these jars in your classpath and use this:
razie.scripster.Scripster.create(4445)
where 4445 is the port you want to use, see the razie.scripster.MainScripster for an example. To enable the swing version, use the swing jars as well and see the razie.scripster.MainSwingScripster class for an example.

For further tweaking, look at the code yourself, at http://github.com/razie/scripster/tree/master/src/razie/scripster/

If you want to keep in touch with the evolution of scripster or my other related endeavours, subscribe to the RSS feed or twitter/razie.

Scripster's main page, kept up-to-date, is at http://wiki.homecloud.ca/scripster. There's also an online live demo at http://scripster.codewitter.com.

Enjoy!