views:

469

answers:

5

I'm about to start an LFS-based linux distro just for a hobby project. I plan on doing some very non-standard tasks, and most of it will involve change almost all scripts in the distro. (mainly init scripts, but also I'll be writing a simple set of package manager scripts.) Since I'm gonna be going this far off the norm, and since I have never been a fan of dynamic-typed languages (perl, python, bash and the rest are good, but just not my forte), I was wondering if anyone knew of an interpreted language that actually has declared variables.

A: 

F# provides a combination of "type safety, succinctness, performance, expresivity and scripting".

MichaelGG
F# is not a scripting language.
shoosh
What defines a scripting language? Lightweight syntax? A REPL? F# has those...
Brian
being interpreted rather than compiled.
shoosh
What's interpreted versus compiled have to do with it? If you can run a F# program by doing "fsi foo.fsx", how's that different than any other script?
MichaelGG
Which is nothing to do with the question, and probably isn't suitable for the original poster's purpose.
MarkR
The OP specifies "scripting", only later on "interpreted".
MichaelGG
+2  A: 

Typically the statically typed languages are compiled languages. I guess the reason is, that statical analysis of types is rather expensive and you have to have an in depth look at all the code you're processing. After you've done that it feels like a waste to not write all that information into a file, so that you don't have to do it again next time. So you quickly end up with a compiled language.

On the other hand, to turn a compiled language in a "not-compiled" one is rather easy. You just don't store the results of the compilation anywhere but execute them directly. One compiler I know that provides such a wrapper is GHC, the standard Haskell compiler. You can add #!/usr/bin/runhaskell to your source files and then directly execute them. And since you're planning to be far off the norm, Haskell seems like a perfect fit ;). But expect some rather large startup time for your scripts, because all the "compile time" analysis and optimization isn't free.

Haskell isn't made for shell scripting and it's a functional language, so if you've never seen it before, it might take some time to get used to. But it has very little syntactical overhead and the strength of functional languages is abstraction, so I don't see why you couldn't create a library that makes shell scripting fun. There is even some experimental Haskell shell, but it does seem to be more a proof-of-concept than a real solution.

Generally I would say the overhead of all the type analysis is significant, but I would suggest you pick your favorite statically typed compiled language and look for a wrapper like runhaskell to execute scripts written in it.

sth
There is no such thing as a *compiled language*. Every language can be implemented by either a compiler or an interpreter. And, in fact, the vast majority of programming languages have at least one implementation of each. Also, most modern language implementations have actually *both* a compiler *and* an interpreter. Since you mention Haskell: Hugs is a Haskell interpreter. V8 is a JavaScript compiler. Microsoft's PowerShell is a compiler. A couple of years ago, the Bash developers were thinking about switching to a compiled implementation. The HotSpot JVM is both an interpreter and a compiler
Jörg W Mittag
+3  A: 

quick google. F3, javaFX script, Linden Scripting Language (scripting for second life), Unlike the comment on the first answer F# can be used as a scripting language http://blogs.msdn.com/chrsmith/archive/2008/09/12/scripting-in-f.aspx

Felix, Tuga, CFGScript, Talc, Angelscript, and guessing there is more than that quick search.

Douglas

DouglasH
A: 

Look in to the "typeset" command in your favorite shell. bash and ksh93 both can enforce integers and strings, use references (variable variables), etc. With ksh93, you can also do floating-point math and use objects with attributes. Static typing doesn't really buy you anything useful in init scripts and similar. You're primarily going to be reading files and running system commands - which is what the shell's really good at. Take some time with the O'Reilly "learning the Korn Shell" book before deciding that all those other Unixes are stupidly designed... ;)

dannysauer
and "set -o nounset" early on in the script...
dannysauer
This is a terrible suggestion. If the OP doesn't dynamic languages, he's going to *hate* shell scripting. They are much more dynamic than any other scripting language.
Paul Biggar
A: 

Groovy. By default it's dynamic, duck-typed. But also supports static typing.

vartec