aspose file tools*
The moose likes Scala and the fly likes scalac versus scala Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Scala
Bookmark "scalac versus scala" Watch "scalac versus scala" New topic
Author

scalac versus scala

Red Smith
Ranch Hand

Joined: Aug 05, 2007
Posts: 136
    
    1
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

Joined: Mar 01, 2009
Posts: 1715
    
  14

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?



No more Blub for me, thank you, Vicar.
Red Smith
Ranch Hand

Joined: Aug 05, 2007
Posts: 136
    
    1
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

Joined: Aug 16, 2005
Posts: 14150
    
  18

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: scalac versus scala