Looking for a new language that supports both interpreted and native compilation modes

335 Views Asked by At

I currently program in Perl, Python, C#, C, C++, Java, and a few other languages, and I'm looking for a new language to use as a primary when doing personal projects.

My current criteria are:

  • can be run as an interpreted language (i.e., run without having to wait to compile it);
  • can be compiled to native code;
  • are strongly typed (even if optionally);
  • support macros/templating/code morphing/wtf you want to call it;
  • has a decent number of libraries for it, or easily accessible to it;

Ideas? Suggestions?

3

There are 3 best solutions below

4
On

Scala? It does run scripts, although they are compiled (transparently) first. I'm not sure what you mean by code morphing etc, but it's pretty good for DSLs. It meets all your other requirements - compiled as much as Java is, strongly typed, and has a reasonable number of its own libraries as well as all of Java's. I'm still a beginner with it, but I like it so far.

3
On

Common Lisp fits: there is an optional typing, efficient native compilation is available, powerful REPL makes it a perfect choice for scripting, and there is a powerful macro metaprogramming.

OCaml fits as well, with CamlP4 for metaprogramming.

1
On

I would suggest that Haskell suits your criteria.

  • Can be run as an interpreted language? Yes, via GHCI.
  • Can be compiled to native code? Yes.
  • Is strongly typed? Very much so. Perhaps even the most strongly typed language today, with the exception of some theorem provers like Agda.
  • Support macros/templating/morphing? If you use template haskell. This is an optional extension of the language however, so most libraries don't use macros. I haven't used template haskell myself so i can't comment on if it's any good.
  • Has decent library support? The standard library is not bad. There is also Hackage, an open repository of Haskell libraries a bit in the style of CPAN.

Additionally, it sounds like you already know a lot of imperative/object oriented languages. IMHO if you learn another one of those langs. it will probably be a slightly different permutation of features you've already seen somewhere else. Adding another programming paradigm like functional programming to your toolbox will probably be a better learning experience. Though I guess whether that's an advantage or not depends on if you want to learn new things or be productive quickly.