error: ';' expected but double literal found - scala

I am learning Scala and I am using typesafe activator to run the programs. I have my first program in the below path <downloads>\typesafe-activator-1.3.7\activator-dist-1.3.7\simple scala project\scala-2.11\Simple_scala_project.scala
Below is the program content
object Simple_scala_project {
def main (args:String): Unit =
{ println("My first scala program") }
}
when I am running the below command in the command line I am getting the error
scala -cp <downloads>\typesafe-activator-1.3.7\activator-dist-1.3.7\simple scala project\scala-2.11 Simple_scala_project
:1: error: ';' expected but double literal found.
Please help me in this.

I noted a similar error when I inadvertently placed a line including "sbt.version=1.3.13" (in my case) in the wrong file. I realize now that it should have gone into a folder insider my overall project folder called "project", inside a file called "build.properties" (instead of in "build.sbt").
The take-away from this is that I don't think you experienced a compiler error at all, but an error owing to some files in the project setup. Better SBT documentation may be found here.
It's absolutely true that SBT isn't needed for very simple examples, and indeed offends the sensibilities of ones volunteering to learn a new language (soon to be improved, Scala 3.x, not a hundred other extraneous technologies. I find IntelliJ Idea Community to be a boost, here, since its Scala support is first-rate, and will create simple example projects for you in a variety of ways Installing Scala / Installing Scala plugin for Idea.

Related

Running scala in cmd makes i look like I am missing 'build.sbt'

I'm trying to run Scala in my command line.
I checked my java, went to the Scala website, downloaded and installed it, updated my environment variables.
So far the only thing different from guides online is that the folder where sbt is installed does not include a "lib" folder.
I then run sbt command in my prompt, and I get this message:
It looks like I'm missing a file called build.sbt, what is this? and do i need it?
Edit:
If I press 'continue' on the picture above, I get
sbt:scalaproj>
Which looks fine, but if i type some code, like this:
sbt:scalaproj> var a : Int = 12;
Then it returns errors:
[error] Expected ';'
[error] var a : Int = 12
What in the world is going wrong? can someone point me to a guide for writing Scala in the prompt that is not too old to work?
Let's first understand the terminology. Scala is the language you are writing. SBT is an acronym for Scala Build Tool. Both of them have REPL.
When you call sbt in the command line, you initiate the REPL of sbt. The commands you can run there, are all commands sbt supports. You can find here the common commands. For example, if you run compile, it will compile the build.sbt located at the directory where you called the sbt command. Anyway, Scala commands WILL NOT work here. Scala commands are not sbt commands.
In order to run Scala REPL, you need to type console in the sbt REPL. You can find here the Scala REPL documentation. Within the Scala REPL you can run Scala commands.
P.S.
You can find the Scala download page here.

Can't expand macros compiled by previous versions of Scala

I changed my Scala version from 2.10.x to 2.11.8. I am getting some compilation issues. I tried, but still not able to resolve because I am poor in Scala and sbt.
WebService.scala:36: can't expand macros compiled by previous versions of Scala
[error] logger.error(s"WebService.getSiteData(${Id}): Unknown Error, Error Message: $e")
What might be the issue here?
I resolved this issue but it not a single thing, I did couple of things:
First I gone through the error location in WebService.scala.
Then to the corresponding "Logger" class.
I check from which jar that "Logger" class coming.
I found that it referring to some thing else jar than what I am expecting.
That jar is coming from one of my dependent project (modules) so in build.sbt, those dependent jars I excluded that wrong jar which I found.
After I changed the code in WebService.scala, I removed that import for logger and added new import having Logger what I expecting. I did same all the other places in my project.
WebService.scala:36: can't expand macros compiled by previous versions of Scala
[error] logger.error(s"WebService.getSiteData(${Id}): Unknown Error, Error Message: $e")
This is not particular to logger issue. If you are getting "can't expand macros compiled by previous versions of Scala" issue", you have to do same procedure for corresponding to your error (my case logger).
First time, I search online regarding this issue, I found same issue facing lot of people, but different library classes (I face Logger class issue).

Unable to run a HelloWorld Scala program on Ubuntu

I have my very first Scala program, which is as simple as:
object HelloWorld{
def main(args: Array[String]){
println("Hello world!")
}
}
I then try to compile it like so:
$ scalac HelloWorld.scala
And it compiles without any error messages. When however I try to run it like so:
$ scala HelloWorld
I get an error message:
No such file or class on classpath: HelloWorld
To implement this, I followed this tutorial and to solve the emerged error, I followed this suggestion. However,
$ scala objects.HelloWorld
also does not work. I know many people will now start heavily voting down my question and asking questions - have you ever tried to read some books on it (Yes, I did. I've read Horstman book for beginners, but it does not contain any information on compiling programs under Ubuntu). Still, I hope someone could help.
(This was a comment before, and I rephrased it to a response.)
You've done everything right, except for the last step: Use the java command instead of the scala command.
scala is the Scala REPL. No separate run command is required for Scala code, because it compiles to regular Java bytecode.
So try: java HelloWorld
For more complex programs that make use of the Scala library however, you need to include the Scala runtime library in the classpath. So, on the long run, it is beneficiary to use a tool like SBT, as pointed out by #roterl in the comments.
The answer saying that the scala command is just for the REPL is incorrect. You can see from the man page entry for scala (http://www.scala-lang.org/files/archive/nightly/docs-2.10.2/manual/html/scala.html) that it is intended to be used in the same way as the java command with the added flexibility that it will run the REPL, scripts, or compiled applications.
As some of the comments have indicated, this is almost certainly a path issue, which means that it requires more information to diagnose. One thing you can check is whether the scalac command produced a .class file in your current directory. If that is in the directory where you are running scala then the comments about needing . in your classpath are almost certainly correct.

Scala worksheet not working in Intellij

I have Intellij-IDEA 13.1.2. [edited, previously 13.0.2]
I use the scala-plugin.
I'm trying to use worksheets to evaluate code.
But all I got are two errors :
bad macro impl binding: versionFormat is supposed to be there
Unable to read an event from: rO0ABXNyADVvcmcuamV0YnJhaW5zLmpwcy5pbmNyZW1lbnRhbC...
I can run the scala console normally and execute my code in it,
but the worksheet doesn't function.
If my code is incorrect, it outputs an error indicating the interpreter failed to parse my code. I got the "bad macro impl binding" error only if my code is correct.
I tried creating a new project, but it didn't work.
I followed tutorial to configure scala in intellij but it didn't help either.
Is there an important configuration step I may have missed ? What does that error mean ?
EDIT : I tried the simplest thing in my worksheet like 1 or var x = 1 or println("Hello World!")
EDIT2: I'm not sure what I changed but now I have another error :
Error:error while loading MacroPrinter, class file needed by MacroPrinter is missing.
reference value macros of package reflect refers to nonexisting symbol.
UPDATE: Now it works fine under Intellij 13.1.5, Scala plugin 0.41.2 with both scala-2.10 and 2.11
I had the "Unable to read an event from" issue and switching from Scala 2.11.0 to Scala 2.10.4 fixed it for me.
I've shared a workaround in a similar question and I think it can work for this question as well:
I'm having the same issue with latest Idea and Scala plugin.
It seems that the worksheet has a problem executing any line which evaluates to Unit. Assigning is Unit, that's why your tableTest(0) = "zero" fails.
I've temporarily solved it with the following workaround:
this line will fail with error Error:Unable to read an event from:...
println("Will fail")
You can fix it by defining this helper method and using it for any Unit expression:
def unit(f: => Unit): String = {f; ""}
unit(println("Will work"))
You just have to ignore the line it generates in the output panel with res0: String =
You also can put this method in some object and import in any WS you need.
I am using IntelliJIDEA 13.1.2 and Scala Plugin 0.36.431. I tried to create a Scala Non-SBT project and created a worksheet file, then I met the "bad macro impl binding" problem. But if I created a Scala SBT project with a worksheet file, it worked well.
After updating to IntelliJ 13.1.5 build 135.1289 with JRE 1.7.0_60 and Scala 2.11.0 I had the same issue.
I fixed the problem by disabling the checkbox in settings -> IDE Settings -> Scala -> "Run compile server".

Scala errors in Eclipse 3.5 using Scala 2.8.0b, "Syntax error on token String"

I seem to be missing libraries but I am not certain.
In this file:
object Test {
def main(args: Array[String]) {
for (arg <- args)
println(arg)
}
}
I am not certain what leads to these errors:
Description Resource Path Location Type
Syntax error on token "object", interface expected TestSrc.scala /ScalaDataMiningFunctions/src line 1 Java Problem
Syntax error on token "String", delete this token TestSrc.scala /ScalaDataMiningFunctions/src line 2 Java Problem
Syntax error on token ":", delete this token TestSrc.scala /ScalaDataMiningFunctions/src line 2 Java Problem
Syntax error on token "<", ( expected TestSrc.scala /ScalaDataMiningFunctions/src line 3 Java Problem
I may just need to go through the steps and do this in Netbeans instead, but I would prefer to find out what is going on.
In my lift project, which was created by using maven, I don't have these errors, but there are many jar files there that I don't have in mine.
One jar file is scala-compiler-2.7.3.jar that is in the lift project but not in my scala project.
The only libraries in my scala project are Scala Library version 2.8.0r19106-... and JRE System Library [jre1.6.0_07]
Eclipse is seeing your Scala sources as Java and choking on them (the clue is the text "Java Problem" at the end of each problem report).
Most likely you don't have JDT Weaving enabled (or not enabled successfully), so please follow the troubleshooting instructions here,
http://scala-ide.assembla.com/wiki/show/scala-ide/Troubleshooting
and if you still have issues, please follow up on the scala-ide-user list,
http://groups.google.com/group/scala-ide-user
The scala plugin for Eclipse is still quite immature. If you are not locked into eclipse i would advise you to try out the netbeans plugin which is alot more stable. :)
please install scala plugin to eclipse
add following site
http://download.scala-ide.org/update-current-35
it will work...