Hacker News new | past | comments | ask | show | jobs | submit login

Ruby belongs in the list you gave as well, I think, but they all have tradeoffs, just in terms of the convenience of using first-class functions in them. Ruby's block syntax (|x,y| x * y) is a lot more convenient than the more verbose "function" syntax of JS and Lua for expressing inline functions (Lua: function (x,y) return x*y end), pretty comparable to something like Haskell. However, Ruby requires you to use either coroutine-style yield syntax or the call() method to actually invoke a function value, while JavaScript and Lua let you write parentheses after the value's name, in the same way that you would call any other function.

For first-class functions to be convenient, minimally you need a terse syntax for in-line functions, the ability to call function values as you would normal functions, and closures. (this last, fortunately, all of the above support) I'd argue that language support for currying is also extremely valuable and difficult to live without, because it greatly increases the situations in which a given function is useful. It's frustrating to me that mainstream "scripting" languages like JS, Lua, and Ruby can't get all of these aspects right - I hope for pattern matching and ADTs in a mainstream language, too, but I'm still waiting for a good implementation of first-class functions to arrive!




FWIW, I wrote a pattern-matching library for Lua, Tamale (http://github.com/silentbicycle/tamale/).

It was an interesting project, because almost everything I could find about implementing pattern-matching assumed the patterns could be analyzed at compile time, rather than building some kind of dispatch tree at runtime. After trying some more elaborate methods (e.g. building a decision tree via CPS), I figured out that just indexing (on the first field, by default) and then doing linear search within the index's patterns got 90% of the benefit with very little runtime analysis.


Very cool!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: