LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices

Reply
 
Search this Thread
Old 10-30-2011, 05:03 AM   #1
mcnalu
Member
 
Registered: Dec 2006
Location: Glasgow, UK
Distribution: Slackware 13.37 and 13.1
Posts: 393

Rep: Reputation: 63
scala


I've installed scala on slackware 13.37 32bit using a script from slackbuilds.org

In the interpreter it works fine, but it just hangs and gives no output when I try and run any code from the command line with something like

Code:
$ scala hello.scala
where the file hello.scala is something like

Code:
println("Hello, world, from a script!")
or even a more java-like explicit class:
Code:
  object HelloWorld {
    def main(args: Array[String]) {
      println("Hello, world!")
    }
  }
Any one else got past this?
 
Old 10-30-2011, 07:44 AM   #2
pgeek
LQ Newbie
 
Registered: Apr 2011
Location: Germany
Distribution: Slackware
Posts: 7

Rep: Reputation: 0
I don't know scala, but where do you call that "function"?
Don't you need something like this:
Code:
object HelloWorld {
  def main(args: Array[String]) {
    println("Hello, world!")
  }
}
HelloWorld.main
?

Last edited by pgeek; 10-30-2011 at 07:49 AM. Reason: forgot code :)
 
Old 10-30-2011, 09:09 AM   #3
mcnalu
Member
 
Registered: Dec 2006
Location: Glasgow, UK
Distribution: Slackware 13.37 and 13.1
Posts: 393

Original Poster
Rep: Reputation: 63
Apparently you don't have to with a code fragment like the first example.

With the second I tried explicitly calling main too but same result.
 
Old 10-30-2011, 11:47 AM   #4
kfritz
Member
 
Registered: Aug 2006
Distribution: Slackware, OpenBSD
Posts: 71

Rep: Reputation: 19
Tried it on x86_64 (13.37) and 32-bit (current), and your first example works for me.

Try running with strace and see if you can figure out where it's getting stuck.
 
Old 10-30-2011, 02:22 PM   #5
pgeek
LQ Newbie
 
Registered: Apr 2011
Location: Germany
Distribution: Slackware
Posts: 7

Rep: Reputation: 0
Ok, tried it and it works.
Here they tell you, that you have to compile it first with scalac.
Code:
$ cat HelloWorld.scala
object HelloWorld {
  def main(args: Array[String]) {
    println("Hello, world! ")
  }
}
$ scalac HelloWorld.scala
$ scala HelloWorld
Hello, world!
 
Old 10-30-2011, 06:30 PM   #6
mcnalu
Member
 
Registered: Dec 2006
Location: Glasgow, UK
Distribution: Slackware 13.37 and 13.1
Posts: 393

Original Poster
Rep: Reputation: 63
I've seen that page and it's the example of "Script it!" above the one you quote that doesn't work for me.

It should be possible to run scala programs without a scalac compile first, e.g. here.

Last edited by mcnalu; 10-30-2011 at 06:30 PM. Reason: typo
 
Old 10-30-2011, 06:40 PM   #7
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 242Reputation: 242Reputation: 242
Maybe the output is buffered, so it needs a new line to flush

println("Hello, world, from a script!\n")

Just a thought, I don't know really
[edit]
I doubt it, as println seems to produces newlines automatically...

Last edited by Cedrik; 10-30-2011 at 06:50 PM.
 
Old 10-31-2011, 07:08 AM   #8
pgeek
LQ Newbie
 
Registered: Apr 2011
Location: Germany
Distribution: Slackware
Posts: 7

Rep: Reputation: 0
Quote:
Originally Posted by mcnalu View Post
I've seen that page and it's the example of "Script it!" above the one you quote that doesn't work for me.

It should be possible to run scala programs without a scalac compile first, e.g. here.
I just installed the SBo package on Slackware 13.37 32bit and all examples worked for me.

I tried again:
Code:
$ which scala
/usr/lib/scala/bin/scala
$ cat HelloWorld.scala 
println("Hello world!")
$ scala HelloWorld.scala 
Hello world!
$ cat HelloWorld2.scala 
object HelloWorld {
  def main(args: Array[String]) {
    println("Hello, world!")
  }
}
HelloWorld.main(args)
$ scala HelloWorld2.scala
Hello, world!
And now the last output didn't appear until I clicked into xterm... strange.

Edit:
When I tried running the second example without "HelloWorld.main(args)" and without compiling, I received an error message. It seems, that you have to add this line only when running without compiling it first.

Sorry, I know C, C++, Ruby, Python and very little Java... never worked with scala

Last edited by pgeek; 10-31-2011 at 07:12 AM.
 
Old 10-31-2011, 07:19 AM   #9
pino_otto
Member
 
Registered: Dec 2005
Location: Italy
Distribution: Slackware
Posts: 83

Rep: Reputation: 18
From a book about Scala:

By the way, if you’re on some flavor of Unix, you can run a Scala script
as a shell script by prepending a “pound bang” directive at the top of the file.
For example, type the following into a file named helloarg:

#!/bin/sh
exec scala "$0" "$@"
!#
// Say hello to the first argument
println("Hello, " + args(0) + "!")

The initial #!/bin/sh must be the very first line in the file. Once you set its
execute permission:

$ chmod +x helloarg

You can run the Scala script as a shell script by simply saying:

$ ./helloarg globe
 
Old 10-31-2011, 07:22 AM   #10
pino_otto
Member
 
Registered: Dec 2005
Location: Italy
Distribution: Slackware
Posts: 83

Rep: Reputation: 18
I installed scala by downloading it from the scala website.

It works also with scripts, without compiling them in advance.

That is a nice feature of scala.
 
Old 10-31-2011, 09:24 AM   #11
mcnalu
Member
 
Registered: Dec 2006
Location: Glasgow, UK
Distribution: Slackware 13.37 and 13.1
Posts: 393

Original Poster
Rep: Reputation: 63
pgeek

Thanks for trying it out - very helpful, here's what I get when I do the same:
Quote:
$ which scala
/usr/lib/scala/bin/scala
$ cat HelloWorld.scala
println("Hello world!")
$ scala HelloWorld.scala
^C
$
The ^C is me having to interrupt it - clicking doesn't cause the output to appear, in any terminal.

I'll try reinstalling and looking more closely at the slackbuild.

pino_otto - yes, it's handy to run scala like an interpreted language - hence my desire to get it working! I tried the bash script approach but it also gives no output

Last edited by mcnalu; 10-31-2011 at 09:30 AM. Reason: typo
 
Old 11-01-2011, 06:48 AM   #12
pino_otto
Member
 
Registered: Dec 2005
Location: Italy
Distribution: Slackware
Posts: 83

Rep: Reputation: 18
did you set the variable SCALA_HOME

if you give the command:

$ echo $SCALA_HOME

what do you see?
 
Old 11-02-2011, 07:28 AM   #13
mcnalu
Member
 
Registered: Dec 2006
Location: Glasgow, UK
Distribution: Slackware 13.37 and 13.1
Posts: 393

Original Poster
Rep: Reputation: 63
Yup - seems fine.

Code:
$ echo $SCALA_HOME
/usr/lib/scala
$ ls /usr/lib/scala
bin/  lib/  man/  meta/  misc/  src/
 
  


Reply

Tags
scala


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting scala Path on slackware problem n3mbers Linux - Software 3 07-22-2009 10:04 AM
LXer: Create a mobile application for Android using Scala and Eclipse LXer Syndicated Linux News 0 07-06-2009 09:11 PM
LXer: Grails and Scala support Google's AppEngine LXer Syndicated Linux News 0 05-15-2009 03:40 PM
Scala MM200 - similar program for Linux? technobeast Linux - Software 1 12-21-2004 02:52 AM


All times are GMT -5. The time now is 09:57 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration