views:

450

answers:

6

I'm sketching a design of something (machine learning of functions) that will preferably want a functional programming language, and also introspection, specifically the ability to examine the program's own code in some nicely tractable format, and preferably also the ability to get machine generated code compiled at runtime, and I'm wondering what's the best language to write it in. Lisp of course has strong introspection capabilities, but the statically typed languages also have advantages; the ones I'm considering are:

F# - the .Net platform has a good story here, you can read byte code at run time and also emit byte code and get it compiled; I assume there's no problem accessing these facilities from F#.

Haskell, Ocaml - do these have similar facilities, either via byte code or parse tree?

Are there other languages I should also be looking at?

+5  A: 

Not really an answer, but note also the F# Quotations feature and library, for more homoiconicity stuff.

Brian
+1  A: 

I'd also look at Scala or Clojure which come with them all the libraries that have been developed for Java. You'll never need to worry if a library does not exist. But more to the point of your question, these languages give you the same reflection (or more powerful types) that you will find within Java.

wheaties
+3  A: 

Haskell's introspection mechanism is Template Haskell, which supports compile time metaprogramming, and when combined with e.g. llvm, provides runtime metaprogramming facilities.

Don Stewart
+8  A: 

Ocaml has:

  • Camlp4 to manipulate Ocaml concrete syntax trees in Ocaml. The maintained implementation of Camlp4 is Camlp5.

  • MetaOCaml for full-scale multi-stage programming.

  • Ocamljit to generate native code at run time, but I don't think it's been maintained recently.

  • Ocaml-Java to compile Ocaml code for the Java virtual machine. I don't know if there are nice reflection capabilities.

Gilles
Camlp4 Wiki: http://groups.google.com/group/fa.caml/browse_thread/thread/632bb527a6762d89
nlucaroni
+2  A: 

You might check out the typed variant of Racket (previously known as PLT Scheme). It retains most of the syntactic simplicity of Scheme, but provides a static type system. Since Racket is a Scheme, metaprogramming is par for the course, and the runtime can emit native code by way of a JIT.

dhaffey
+1  A: 

The Haskell approach would be more along the lines of parsing the source. The Haskell Platform includes a complete source parser, or you can use the GHC API to get access that way.

Paul Johnson