tags:

views:

198

answers:

2

I'm trying to get started with Scala and cannot get out of the starting gate.

A file consisting of the line

package x

gives me

error: illegal start of definition

Regardless of what x is and regardless of where I put the file (I had a theory that I had to place the file in a directory hierarchy to match the package definition, but no). I get the same error with the example code from the web site and with the REPL.

+4  A: 

It looks like you're trying to declare the package membership in a Scala script (run using the scala command) or in the REPL.

Only files defining just classes and objects which are compiled with scalac may be defined as belonging to a package.

When you run code in a script or a REPL session, behind the scenes it is actually compiled inside a method of an object, in which scope a package declaration wouldn't be legal.

Ben James
A: 

I don't get this error. How are you compiling this? And, by the way, what web site? As for REPL, it doesn't accept packages. Packages are only for compiled code.

Daniel
Wow, it literally *never* occurred to me that the compiler and the interpreter might have different command names. I was thinking of Python and using scala instead of scalac."What web site?" -- I was about to answer http://www.scala-lang.org/ but I went and checked: the example code was from (the excellent) http://max-l.github.com/Squeryl/ (qv).You may know begin making those little doy, duh, durp noises you like so much.
Malvolio