Question

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.

Was it helpful?

Solution

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... ;)

OTHER TIPS

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.

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

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

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top