| Andrew Cooke | Contents | Latest | RSS | Twitter | Previous | Next

C[omp]ute

Welcome to my blog, which was once a mailing list of the same name and is still generated by mail. Please reply via the "comment" links.

Always interested in offers/projects/new ideas. Eclectic experience in fields like: numerical computing; Python web; Java enterprise; functional languages; GPGPU; SQL databases; etc. Based in Santiago, Chile; telecommute worldwide. CV; email.

Personal Projects

Lepl parser for Python.

Colorless Green.

Photography around Santiago.

SVG experiment.

Professional Portfolio

Calibration of seismometers.

Data access via web services.

Cache rewrite.

Extending OpenSSH.

C-ORM: docs, API.

Last 100 entries

Lepton Decay Irregularity; An Easier Way; Julia's BinDeps (aka How To Install Cairo); Good Example Of Good Police Work (And Anonymity Being Hard); Best Santiago Burgers; Also; Michael Emmerich (Vibrator Translator) Interview (Japanese Books); Clarice Lispector (Brazillian Writer); Books On Evolution; Looks like Ara (Modular Phone) is dead; Index - Translations From Chile; More Emotion in Chilean Wines; Week 7; Aeon Magazine (Science-ish); QM, Deutsch, Constructor Theory; Interesting Talk Transcripts; Interesting Suggestion Of Election Fraud; "Hard" Books; Articles or Papers on depolarizing the US; Textbook for "QM as complex probabilities"; SFO Get Libor Trader (14 years); Why Are There Still So Many Jobs?; Navier Stokes Incomplete; More on Benford; FBI Claimed Vandalism; Architectural Tessellation; Also: Go, Blake's 7; Delusions of Gender (book); Crypto AG DID work with NSA / GCHQ; UNUMS (Universal Number Format); MOOCs (Massive Open Online Courses); Interesting Looking Game; Euler's Theorem for Polynomials; Weeks 3-6; Reddit Comment; Differential Cryptanalysis For Dummies; Japanese Graphic Design; Books To Be Re-Read; And Today I Learned Bugs Need Clear Examples; Factoring a 67 bit prime in your head; Islamic Geometric Art; Useful Julia Backtraces from Tasks; Nothing, however, is lost with less discomfort than that which, when lost, cannot be missed; Article on Didion; Cost of Living by City; British Slavery; Derrida on Metaphor; African SciFi; Traits in Julia; Alternative Japanese Lit; Pulic Key as Address (Snow); Why Information Grows; The Blindness Of The Chilean Elite; Some Victoriagate Links; This Is Why I Left StackOverflow; New TLS Implementation; Maths for Physicists; How I Am 8; 1000 Word Philosophy; Cyberpunk Reading List; Detailed Discussion of Message Dispatch in ParserCombinator Library for Julia; FizzBuzz in Julia w Dependent Types; kokko - Design Shop in Osaka; Summary of Greece, Currently; LLVM and GPUs; See Also; Schoolgirl Groyps (Maths); Japanese Lit; Another Example - Modular Arithmetic; Music from United; Python 2 and 3 compatible alternative.; Read Agatha Christie for the Plot; A Constructive Look at TempleOS; Music Thread w Many Recommendations; Fixed Version; A Useful Julia Macro To Define Equality And Hash; k3b cdrom access, OpenSuse 13.1; Week 2; From outside, the UK looks less than stellar; Huge Fonts in VirtualBox; Keen - Complex Emergencies; The Fallen of World War II; Some Spanish Fiction; Calling C From Fortran 95; Bjork DJ Set; Z3 Example With Python; Week 1; Useful Guide To Starting With IJulia; UK Election + Media; Review: Reinventing Organizations; Inline Assembly With Julia / LLVM; Against the definition of types; Dumb Crypto Paper; The Search For Quasi-Periodicity...; Is There An Alternative To Processing?; CARDIAC (CARDboard Illustrative Aid to Computation); The Bolivian Case Against Chile At The Hague; Clear, Cogent Economic Arguments For Immigration; A Program To Say If I Am Working; Decent Cards For Ill People; New Photo

© 2006-2015 Andrew Cooke (site) / post authors (content).

Starting a Scala Project

From: andrew cooke <andrew@...>

Date: Sun, 27 Sep 2009 15:35:39 -0400

I just decided to do a quick + dirty project - I want to run through
my mp3s, read the tags, store everything in a database, and then pull
tags from the last.fm API so that I can automatically construct
playlists of related music.

I also decided the time has come to learn Scala.  I could do this
easily in Python, but I've been postponing Scala for too long.

I looked at Scala yesterday and downloaded the port of processing,
which used sbt (Simple Build Tool).  I was thinking about looking at
ant+ivy (something else I need to learn), but I *think* sbt uses ivy
under the hood (or uses Maven, or all share the same basic
infrastructure).  So for now I am going with sbt.
http://code.google.com/p/simple-build-tool/ (which I had installed
yesterday).

So, first step was to create a new directory and run sbt.  It asked if
I wanted to create a new project and I said yes, and gave it a name.
Now it seems to be downloading stuff.

OK, so that left me with some basic directories:

spu63 uykfd: ls
lib  project  src  target

OK, now how do I make that work with Eclipse?  No idea.
http://code.google.com/p/simple-build-tool/wiki/IntegrationSupport
suggests using IvyDE (note - I have already installed the Scala plugin
in Eclipse).  So I install this via
http://www.apache.org/dist/ant/ivyde/updatesite

reload + deliver-local in sbt (following instructions at
IntegrationSupport link above).

I still don't get this.  I think I need to create the Scala project
first in Eclipse, so move the directories generated with sbt above out
of the way, create the Scala project from within Eclipse, and then
move the sub-directories back.

But Eclipse is using Scala 2.7.6 and sbt is using 2.7.5

So delete those and in the project directory created by Eclipse run
sbt again, giving the correct Scala version.

That gives an error "unknown resolver sbt-chain" which I am going to
ignore, and otherwise seems to have worked.

F5 to refresh Eclipse and we seem to be cool.

Run reload and deliver-local again in sbt.  F5 again in Eclipse and
add library as described in link above.  Looks good.

Next I create a HelloWorld class in the main.scala package, based on
http://www.scala-lang.org/node/166 but when I try to run it in Eclipse
it is treated as "HelloWorl" (no final "d") and so fails!

If I fix that in the run configurations I then get
Exception in thread "main" java.lang.NoSuchMethodError: main
which sucks somewhat.

This is not looking good.

Running via sbt gives something similar.  Does the "main" have to have
a special name?

I checked with the example and had "class" rather than "object";
fixing that doesn't seem to change anything in Eclipse, but now sbt
works:

> run main.scala.HelloWorld
[info]
[info] == copy-resources ==
[info] == copy-resources ==
[info]
[info] == compile ==
[info]   Source analysis: 1 new/modified, 0 indirectly invalidated, 0 removed.
[info] Compiling main sources...
[info] Compilation successful.
[info]   Post-analysis: 2 classes.
[info] == compile ==
[info]
[info] == run ==
[info] Running main.scala.HelloWorld ...
hello world
[info] == run ==
[success] Successful.
[info]
[info] Total time: 2 s

Trying with the syntax at http://www.scala-lang.org/node/94 also works
with sbt, but not with Eclipse.

Looking at the comments for Application (via Eclipse F3) it seems it's
not recommended.  So revert to earlier syntax:

package main.scala

object HelloWorld {
  def main(args: Array[String]) {
    println("hello world")
  }
}

Which seems identical to the example.

Andrew

Scala Bug Report

From: andrew cooke <andrew@...>

Date: Sun, 27 Sep 2009 16:01:55 -0400

https://lampsvn.epfl.ch/trac/scala/ticket/2402

Andrew

Trying Again (New Instructions)

From: andrew cooke <andrew@...>

Date: Sun, 27 Sep 2009 18:35:59 -0400

OK, as you can see via the bug report, it's not clear what went wrong,
but the following appears to work:

- First, install all software (sbt, Eclipse plugins for Scala and Ivy)
- Next, start Eclipse with a new workspace
- Create the project from inside Eclipse using the "new Scala project" wizard
- In the project directory, run sbt and create a new project with a
matching name (so that you end up with the "src" directory Eclipse
created matching the "src" directory sbt would also create)
- F5 in Eclipse to pick up new files
- At this point I created a HelloWorld object in main.scala, which
worked just fine
- run main.scala.HelloWorld in sbt also runs the hello world
- inside sbt, "reload" and "deliver-local" to generate the ivy file
- F5 again in Eclipse, then projects settings, Java build path,
libraries, and add the Ivy file (in the target directory)

The above creates a project that works both in Eclipse and sbt.

To add a dependency you need to open the ivy xml file using the
dedicated editor.  For example, right click on the ivy xml file in the
build part of the project explorer (NOT the file in target) and select
"edit".

The edit the dependency (the values seem to be as for Maven).  So, for
example, to include Empire DB -
http://incubator.apache.org/empire-db/downloads/latest.htm - I added:
  <dependency org="org.apache.empire-db" name="empire-db"
rev="2.0.5-incubating"/>
and when I saved the file, it went off and downloaded that and a pile
of supporting libraries (not very quickly - I am in S America and the
net is not that fast, so perhaps that's the reason - but it did work).

Andrew

Scala in More Detail

From: andrew cooke <andrew@...>

Date: Sun, 27 Sep 2009 19:35:30 -0400

So now I'm at the point where I need to understand Scala more.  This
is a good overview of the main language features:
http://www.scala-lang.org/sites/default/files/linuxsoft_archives/docu/files/ScalaOverview.pdf
(as I read it, I realised that some examples assume familiarity with
ideas from functional programming, so it may not be for everyone).

There's also more specific details (scroll down to the "table of
contents") on individual features here -
http://www.scala-lang.org/node/104

One thing that has already puzzled me is the use of "object", which is
illuminated by the first link: "In fact, every Java class is seen in
Scala as two entities, a class containing all dynamic members and a
singleton object, containing all static members."

There's a nice clear separation between Value and Reference types
(which in Python would help clarify things for newbies and in Java
helps unify equality).  And explicit Nothing and Null (reference)
types.

Oh and operators are methods (and vice versa!) with fixed precedence
(right associative if they end in a colon, which just happens to give
a sweet syntax for list consing!).  Parameterless methods are
possible.  And "override" is a modifier, not an annotation (ie it's
built-in).

Whoa.  Pass by name exists (lazy evaluation).  The syntax is a little
odd (a "=>" precedes the type).  Ah, because it's a think that "goes
to" a value, I guess.  Evaluated each time they are used (implemented
as parameterless function).

Mixins!  called traits.

I need to go cook dinner, but this is awesome :o)

Andrew

More on Scala

From: andrew cooke <andrew@...>

Date: Sun, 27 Sep 2009 21:06:34 -0400

Continuing with notes from
http://www.scala-lang.org/sites/default/files/linuxsoft_archives/docu/files/ScalaOverview.pdf

Anonymous (using => again), curried and generally first class
functions.  And closures.  And partial evaluation:
  forall(row, 0 ==)
page 6

Functions implemented via generic FunctionN classes.

Wow - arrays are treated as functions over integers (special handling
of assignment to functions via "update").

Sequences and list comprehensions.

Good discussion of co + contra variance.  Helps clarify some problems
I have had with generic types in Java.

Surprisingly, "new" still seems to exist.  I thought it was
unnecessary, so why keep it?

Enough type discussion to make my head explode.

Aha.  Traits must have empty constructor arguments.  That's a very
nice way to keep mixins clean.

The "case" modifier gives you constructor-like matching.

Native XML support including queries.

Hmmm.  Seem to have stalled at views.  Try again tomorrow.

Andrew

Revised Instructions for Adding Dependencies

From: andrew cooke <andrew@...>

Date: Mon, 28 Sep 2009 09:09:43 -0400

The notes above on adding dependencies are incorrect.  The problem is
that the ivy file is generated by sbt.  So extending it is not
permanent.  It exists only as a mechanism to communicate from sbt to
Eclipse.  The actual configuration of dependencies is done in sbt.

It turns out that sbt is configured by writing a scala class:

- Under the project directory add a "build" directory
- In the build directory create a class named after your project (in
my case uykfd):

import sbt._

class uykfdProject(info: ProjectInfo) extends DefaultProject(info)
{
  lazy val hi = task { println("Hello World"); None }
  val empire_db = "org.apache.empire-db" % "empire-db" % "2.0.5-incubating"
}

- The "hi" above defines an action, so inside sbt you can type "hi"
and it will print "Hello World" (pointless, but a good test that
things are working)
- The "empire_db" defines a dependency.  The name of the value doesn't
matter and the various strings are as above (ie as Maven).
- If sbt is still running you need to "reload" to pick this up
- You then MUST do "update" to download
- After that "compile" should work.  For example, I altered my test class to be:

package main.scala

import org.apache.empire.db.DBDatabase

object HelloWorld extends Application {
	println("boo")
    object db extends DBDatabase {
    }
}

- To get this working in Eclipse you then use the ivy xml file, so
"deliver-local" and then click around in Eclipse to get the ivy.xml
file to be added to the build path
- It's not at all clear, but you can also delete the ivy build path
thing via the Eclipse build path dialog (under libraries).
- Once that is done, the libraries downloaded by sbt/ivy appear in the
Eclipse project too.

Andrew

Switched to Emacs

From: andrew cooke <andrew@...>

Date: Tue, 6 Oct 2009 09:02:43 -0400

This page is getting a few hits, so I should add that I have given up
on Eclipse and switched to emacs (for Scala - I still use Eclipse for
Python and Java). So much was broken that emacs does the same and uses
much less memory on my laptop.

To set up emacs follow the instructions at http://scala.sygneca.com/tools/emacs

Despite that having an sbt window, I use sbt in a separate console
(the emacs window shows some strange control characaters and I need to
exit sbt regularly to kill the in-memory database I am using).

In short, Scala tooling is not that great, still.  The language itself
appears to be fine, however.

Andrew

Comment on this post