emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Jarmo Hurri <jarmo.hurri@iki.fi>
To: emacs-orgmode@gnu.org
Subject: Scala problem in Babel
Date: Sun, 02 Apr 2017 15:39:40 +0300	[thread overview]
Message-ID: <87r31bm19v.fsf@iki.fi> (raw)


Greetings.

I am illustrating some basic syntactic differences between programming
languages to some people. In order to do this I embedded a small Scala
program into an Org file

  #+BEGIN_SRC scala :exports both
    object Fibonacci extends App
    {
      def fib (n : Int) : Int =
      {
        if (n == 1 || n == 2)
          n - 1
        else
          fib (n - 1) + fib (n - 2)
      }

      println (fib (7))
    }
  #+END_SRC

This isn't in any way a correctly efficient way to (recursively)
calculate numbers from the sequence, but this is only about syntactics
for beginners, so I need to keep it very simple.

Anyway, when I compile and run this code in Scala it works just fine:

------------------
[jarmo@localhost tmp]$ scalac test.scala
[jarmo@localhost tmp]$ scala Fibonacci
8
------------------

But C-c C-c in Org mode gives me a warning and no result:

  #+RESULTS:
  : /tmp/babel-6890GcO/scala-6890K2a:6: warning: Fibonacci$2 has a main method with parameter type Array[String], but Main.$anon$2.$anonfun$1.Fibonacci$2 will not be a runnable program.
  :   Reason: companion contains its own main method, which means no static forwarder can be generated.
  : 
  : object Fibonacci extends App
  :        ^
  : one warning found
  : ()

When I look at the temporary file I see that the code has been embedded
in a wrapper defined in ob-scala.el. I guess it's the wrapper that
messes up the execution of the code.

What is the wrapper for? How am I supposed to use it?

Jarmo

             reply	other threads:[~2017-04-02 12:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-02 12:39 Jarmo Hurri [this message]
2017-04-03  8:10 ` Scala problem in Babel Jarmo Hurri

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r31bm19v.fsf@iki.fi \
    --to=jarmo.hurri@iki.fi \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).