views:

244

answers:

2

Hi, I'm toying with the idea of writing a command line interpreter and I suspect that a functional language such as Clojure is well suited to this task.

I am however 5 years out of a CS degree and my only experience with functional languages was a harrowing experience with Haskell in a third year languages course.

So, is a language such as Clojure ideal for this task? If not, what is an ideal language.

Loose requirements:

  • Has to run on a JVM
  • Provide an interactive shell where users enter commands with a CLI like syntax
  • User commands ultimately end up making calls to a remote service using SOAP.

Thanks!

A: 

I don't think a CLI has any specific requirements language-wise; you could probably do just as well writing it in Java or Scala. Ultimately I think language choice is down to:

  1. Which ones you are most comfortable working with
  2. Which ones have adequate library support for what you want to do (i.e. web services).
Robert Harvey
+1  A: 

You can approximately do that out-of-the-box with Clojure and Scala, and with Java if you add BeanShell. You might look at the REPL facilities they already have.

I imagine that's suited only for sophisticated users. But really, it's hard to imagine a language that wouldn't do a fine job on a CLI.

Deciding between platforms, the more of a modern system it is, the more it will have scripting language convenience.

I certainly know what I would use given your requirements: JRuby. (It has an out-of-the-box REPL, too.)

DigitalRoss
Thanks for the leads. I'll certainly look into it. You make a very good point about sophisticated users. This is something that would be used primarily by sysadmins who would be hard pressed to learn functional programming. I want to become familiar with a language like Clojure so I'll find a better nail for that hammer.Thanks.
ckovacs
So if you install those, you get the Scala REPL by just running `scala`, the JRuby REPL by running `jirb`, the Clojure REPL by running `bin/repl.sh` and I have no idea how to run BeanShell, but wouldn't it be funny if it was `$ bs`. :-)
DigitalRoss
+1 for jruby - it's very well suited for that sort of thing
Martin DeMello