Funk is a scripting language that is very simple at it's core: It has functions (as values), pattern matching and real variables. That's it - the rest is just nice notation for defining different kinds of functions - every value is a function. Object oriented programming is implemented via pattern matching, and the notation is shorter than most other dynamic (and static) languages.

Implementation statusThe current implementation is written in the OCaml language and translates the language into OCaml. It also requires ExtLib. Please use a Subversion client to check out the source if you want to play around with it. Modules and standard libraries are not implemented at this point, since I'm thinking about moving the language to the Neko platform and use NekoML instead of OCaml.

I am currently working on a new vesion of Funk, which simplifies the existing syntax and adds optional type annotations (with inference). I hope to release a new version late this year (2009).

A short introductionThe details aren't entirely accurate, see the Reference for specifics.

:fib {

|0| 0

|1| 1

|n| fib(n - 1) + fib(n - 2)

}This is a naive implementation of the Fibonacci function (returns element n in the sequence 1, 1, 2, 3, 5, 8, 13, 21, ...). It uses a simple form of pattern matching: if the argument matches the pattern 0, that is, if it is zero, the function returns zero. If the argument matches 1, it returns one, and otherwise it calls itself to find the answer.

:point {|x y| {

|X| x

|Y| y

|Add p| point(x + p.X, y + p.Y)

|ToString| "("..x..", "..y..")"

}}The above is a constructor function that constructs a point (x, y). The first thing to notice is the |x y| pattern. It simply says that the parameter takes two arguments, x and y. The interesting part is what it returns - a new object. This new object has methods X and Y that returns the x and y that the constructor was called with (notice that those arguments are never forgotten in the entirety of the constructed objects lifetime).

The Add method takes an argument p, which is a point, and returns a new point with coordinates that are the sums of the individual coordinates of this point and the p point. The ToString method simply returns a nice string representation of the point.

:p1 point(5, 7) # let p1 be the point (5, 7)

:p2 point(2, 3) # let p2 be the point (2, 3)

print p1.X # prints "5"

print p1.Add(p2) # prints "(7, 10)"This example shows the basics of how to define variables and how to call methods (oh yeah, and line comments begin with a hash (#) and are ignored). Apart from the colon syntax for defining variables, it should be straightforward if you already know OOP. If not, don't worry, I'll explain it without reference to OOP later on.

There are no keywords in Funk. No if, no while and no print. The if statement has what must seem like a rather peculiar replacement in this language:

(x > 42).Then({print "x is great!"})As you may have guessed, this reads "if x is greater than 42, then print >>x is great!<s an unusual implementation.