File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

scalac versus scala

 
Red Smith
Ranch Hand
Posts: 136
1
Netscape Opera Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a very basic beginner question. It appears that you can do things at the scala prompt and with the "scala" command, that you can't do with the "scalac" compiler command. Specifically, you can create functions and execute functions outside of classes(like Python, Perl, etc.) in the former, but not in the latter. Is that correct?
 
chris webster
Bartender
Pie
Posts: 2358
31
Linux Oracle Postgres Database Python Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think most of us are Scala beginners around here at the moment!

"scala" is the Scala interactive shell, so it can execute commands/scripts directly e.g. if you type them in, or it can read them from a named Scala file, a bit like the "python" shell.

"scalac" is the Scala compiler, which takes your Scala code files and compiles them into Java class (bytecode) files that can be executed on the JVM.

I would have thought both approaches would require a valid Scala code file, but it may be that the interpreter can wrap functions in a Scala object if necessary, a bit like the Scala worksheet in the Scala IDE.

Why not just try it out e.g. run/compile a script containing just a function and see what happens?

 
Red Smith
Ranch Hand
Posts: 136
1
Netscape Opera Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
chris webster wrote:

Why not just try it out e.g. run/compile a script containing just a function and see what happens?



I have tried it an I get an error "hello_world.scala:1: error: expected class or object definition".

The confusing thing is that Scala is touted as a language that can be used for Object Oriented Programming or Functional Programming. But it doesn't seem very Functional if everything has to be in a class (when you compile it). It is also confusing that it has different functionality from when it is compiled versus when it is interpreted.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Red Smith wrote:The confusing thing is that Scala is touted as a language that can be used for Object Oriented Programming or Functional Programming. But it doesn't seem very Functional if everything has to be in a class (when you compile it).

Scala is a fusion of functional and object oriented programming. The fact that you have to put everything in a class (or trait or object) doesn't make it less functional. It's not a "pure" functional programming language.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic