Needle

What is it?

Needle is object-oriented functional programming language. It is basically the language that I wish I could program in. The list of features I'm aiming to implement are:

Fully OO Every value in Needle is an object. I get fast integers using a tagged integers like Smalltalk and Lisp do. (Implemented, but integers are boxed until I rewrite Needle in C.)

Every value in Needle is an object. I get fast integers using a tagged integers like Smalltalk and Lisp do. (Implemented, but integers are boxed until I rewrite Needle in C.) Multiple dispatch Like Cecil and Dylan, Needle has methods with multiple dispatch. In a conventional OO language, methods can do dynamic dispatch on the first argument -- the receiver or self argument. With multiple dispatch, the method is selected based on all of the method's arguments. This makes hacks like the Visitor pattern obsolete, and solves the binary method problem completely. (Implemented adequately but suboptimally)

Like Cecil and Dylan, Needle has methods with multiple dispatch. In a conventional OO language, methods can do dynamic dispatch on the first argument -- the receiver or self argument. With multiple dispatch, the method is selected based on all of the method's arguments. This makes hacks like the Visitor pattern obsolete, and solves the binary method problem completely. (Implemented adequately but suboptimally) Garbage collection Needle is a garbage-collected language. There is no malloc() or free(). (Implemented)

Needle is a garbage-collected language. There is no malloc() or free(). (Implemented) Tail recursion As in Scheme, recursive function calls that immediately return are compiled to a goto. This makes it possible to do things like write a state machine as a set of mutually recursive functions without blowing the stack. (Implemented)

As in Scheme, recursive function calls that immediately return are compiled to a goto. This makes it possible to do things like write a state machine as a set of mutually recursive functions without blowing the stack. (Implemented) First-class functions Functions are first-class values, and nested functions capture the lexical environment. Scheme and ML programmers will recognize this. (Implemented)

Functions are first-class values, and nested functions capture the lexical environment. Scheme and ML programmers will recognize this. (Implemented) First-class continuations This basically reifies the stack as a value, like in Scheme and some Smalltalks. Very useful for implementing coroutines and backtracking engines. (Not yet implemented, but very close.)

This basically reifies the stack as a value, like in Scheme and some Smalltalks. Very useful for implementing coroutines and backtracking engines. (Not yet implemented, but very close.) Static typing with type inference Needle will have polymorphic type inference, much like ML does. (Implemented, but I still need to write a type simplifier to make inferred types more readable.)

Needle will have polymorphic type inference, much like ML does. (Implemented, but I still need to write a type simplifier to make inferred types more readable.) Keyword and optional function arguments Functions can specify named parameters, like in Lisp, Python, OCaml or Ada. Thanks to static typing it won't have any overhead either -- label checking happens at typechecking time. (Keyword args exist, but they can't have default values yet.)

Functions can specify named parameters, like in Lisp, Python, OCaml or Ada. Thanks to static typing it won't have any overhead either -- label checking happens at typechecking time. (Keyword args exist, but they can't have default values yet.) Parameterized Modules Like in ML, a module can be parameterized with another module. I think Ada might have something similar too. (Not implemented)

Like in ML, a module can be parameterized with another module. I think Ada might have something similar too. (Not implemented) Macros I like macros in Lisp. I see no reason why an infix language can't have them. I'm basing Needle's macro system on <bigwig>, which means that it's more or less an extensible grammar system with guaranteed termination. (Not implemented)

Where do I get it?

You can download the current Needle sources from the GNU Savannah Needle project page. I'd like to thank the fine volunteers at this project for helping me transfer not only the Needle sources, but all the CVS history, too, to their CVS server.

Why did I bother?

I gave a presentation for the LL2 language design workshop explaining why Needle is necessary. You can download the the slides to the talk, or see the webcast.

I've also given a talk at the MIT Dynamic Languages Seminar, and the slides to that talk are also available.

Useful Links

Needle's type system is based on the ML-sub type system of Bourdoncle and Merz, and the type inference algorithm that Danniel Bonniot developed for it.