Question

After reading Practical Common Lisp I finally understood what the big deal about macros was, and I have been looking for a language for the .NET platform that supports this. There are a few lisp dialects for .NET but from what I have been able to gather all are either very beta or abandoned. Recently my interest has been sparked by Clojure, but it's for the java platform and while on probably could use ikvm it doesn't feel some integrated. Especially when you want to do stuff like WPF.

Recently I have been hearing whisper about F#, I tried to look at the documentation if I could find anything about macro support, but haven't found it. So does anyone know?

Thanks :)

Was it helpful?

Solution

Well, F# is based on OCaml and OCaml has a rather extensive macro system. Given the syntactic and semantic similarities of F# and OCaml you may be able to port over the Ocaml macro system to F#.

Other than stealing Ocaml's macro system I'm unaware of a canned macro system for F#.

OTHER TIPS

Nemerle, at http://nemerle.org/ , is a .NET language (also supporting mono) that supports a lot of of the functional programming paradigm while staying visually close to C#. It has extensive macro support.

Nope. No macros for F#.

Have you looked at Boo? While Boo doesn't have macros, it has an open compiler pipeline, which is a good alternative to macros for syntactic metaprogramming.

[EDIT] As noted in the comments, Boo does have macros now.

but good horrors the syntax in those ocaml examples looks obscure

There you're running into the same fundamental syntactic trade-off you do with Lisp. If you want the power of lisp-like macros, you tend to either end up with lisp-like syntax for the language, or else your macro syntax looks quite different from your regular syntax... nothing wrong with either approach, just different choices

I thought I should point out that there is now a pretty active .NET/Mono port of Clojure. Clojure supports LISP style macros as is noted in the question.

As others have said, macros are not supported in F# at this point (late 2010).

Recently I have been hearing whisper about F#, I tried to look at the documentation if I could find anything about macro support, but haven't found it. So does anyone know?

F# does not support macros and it is unlikely that it ever will.

How about using F# quotations?

http://tomasp.net/blog/fsquotations.aspx

That may be the other way around than what you want, but do you know about RDNZL? It's a foerign-function interface (FFI) that lets you call .NET libraries from your Lisp code.

They are most probably much less mature than any Common Lisp or Scheme implementation, but there are Lisp dialects for .NET: L# and DotLisp.

There are two actively developed Lisps for .net

IronScheme - DLR based scheme implementation

Xronos - DLR based port of clojure

I'm currently investigating possibilities of meta-programming in F#. If we define macros as text template which expands into code then there are two obvious approaches:

  1. T4 templates. There is implementation for F#: https://github.com/kerams/Templatus

  2. I've seen somewhere invocation of F# from strings into separate assembly and then loading of the assembly.

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