4

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?

Loki
  • 6,205
  • 4
  • 24
  • 36
  • This list is very hard to satisfy. Except for two or three languages, you have to bend the rules: Python e.g. is strongly typed (perhaps you meant **statically**?) and *can* (but shouldn't just for the fun of it) be compiled natively if you're willing to use Cython etc. Really powerful macro systems rules out everything but Lisps, weird extensions of a few other languages and perhaps a handful of other, very little-known languages. –  Dec 20 '10 at 17:35
  • Even C has strong macro support... – Loki Dec 20 '10 at 17:56
  • C has laughable macros (if you can call them macros at all), compared to... well, everything else; becausee Lisp has the most powerful macros every and everything else is inspired by Lisp. C preprocessor macros may come handy from time to time, but they're a huge unhygenic mess that is way too limited. Also, C and the languages that regrettably are backwards-compatible with it are pretty much the only ones with the text replacement that is the preprocessor. –  Dec 20 '10 at 18:47

3 Answers3

5

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.

keiter
  • 3,534
  • 28
  • 38
  • I was thinking of suggesting this. +1, especially because the last paragraph is important. When you learn Haskell (no matter if you know a dozen imperative languages), you don't write real world apps after a few weeks. –  Dec 20 '10 at 18:48
3

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.

SK-logic
  • 9,605
  • 1
  • 23
  • 35
  • +1 for CL. Macros (and the CLOS MOP) make for some mindbending possibilities. – The Archetypal Paul Dec 20 '10 at 17:49
  • that is a good suggest, though I shiver with horror every time I remember the syntax. But you're right - it does fit most of my requirements. The other major problem with Lisp is though it has quite a few libraries available for it, they are hard to find, and there is no real central index for them (though cliki isn't bad). – Loki Dec 20 '10 at 17:55
  • I forgot to mention Scheme - it could be a little better than CL with libraries. I actually used Bigloo a lot for my little scripting tasks. – SK-logic Dec 20 '10 at 18:01
-1

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.

The Archetypal Paul
  • 41,321
  • 20
  • 104
  • 134