Posts filed under ‘nifty’
How Tim Burks and Nu Stole the Show at C4[1]
Edit: Fixed some factual inaccuracies about the language itself.
Tim Burks, noted contributor to RubyCocoa and creator of RubyObjC, gave a talk at C4[1] about his experiences with creating a Ruby <-> ObjectiveC bridge, and the problems he overcame in doing so. It was an interesting presentation, and we were all suitably appreciative when he showed his custom visual chip-design software written in Ruby with a Cocoa interface.
And then he dropped a bombshell.
For the past year, Tim’s been working on a new dialect of Lisp – written in Objective-C – called Nu. Here are its features (more precisely, here are the ones that I remember; I was so awestruck that many went over my head):
- Interpreted, running on top of Objective-C.
- Scheme-y syntax. Everything is an s-expression (data is code, code is data). Variable assignment was done without let-clauses (which are a pain in the ass) – all one has to do was
(set varname value). - Variable sigils to indicate variable scope.
- True object-orientation – everything is an object.
- True closures with the do-statement – which, incidentally, is how Ruby should have done it.
- Macros. HOLY CRAP, MACROS! When Tim showed us an example of using
define-macrofor syntactical abstraction, Wolf Rentzsch and I started spontaneously applauding. His example even contained an example of absolutely beautiful exception handling that should be familiar to anyone with any ObjC or Ruby experience. - Symbol generation (__) to make macros hygenic and prevent variable name conflicts.
- Nu data objects are Cocoa classes – the strings are NSStrings, the arrays NSArrays, etc.
- Ability to create new Obj-C classes from inside Nu.
- Interfaces with Cocoa libraries – you can access Core Data stores from within Nu in a much easier fashion than pure ObjC, thanks to Tim’s very clever idea of using a $session global to store the NSManagedObjectModel, NSManagedObjectContext, and NSPersistentStoreCoordinator.
- Ruby-style string interpolation with #{}.
- Regular expressions.
- Positively drool-inducing metaprogramming, including a simulation of Ruby’s
method_missingfunctionality. - A web-based templating system similar to ERb in 80 lines of Nu code – compare that with the 422 lines of code in erb.rb.
Tim showed us a MarsEdit-like blog editor written entirely in Nu, using Core Data as its backend – and then showed us the built-in Nu web server inside that program, complete with beautiful CSS/HTML/Ajax.
As F-Script is to Smalltalk, so Nu is to Lisp. Tim said that he hopes someday to open-source Nu; if he does, he will introduce what is quite possibly the most exciting development in the Lisp-related community in a long time. I don’t think I speak for just myself when I say I cannot wait to get my hands on it.
I got you a present!
[Update: Looks like Dave Batton beat me to the punch. *cries*]
Merry Atheist Children Get Presents Day Christmas, everyone!
In celebration of this day, I am giving you a gift – yes, a gift – from me to you. Yes, you. It is my first piece of public code – well, actually, that’s a lie. I posted this some months ago – I consider it my cleverest Java hack EVER. I’m quite proud of it. No! Digression! Must…focus. Wait…my second was this.
Anyway, it’s my third piece of public code, and I hope you like it. In short, it’s called PVCGradientCell, and it’s a subclass of NSTextFieldCell that uses the CTGradient class to mimic the Source List found in iTunes 6. It’s notable for several reasons:
- Despite the name of the file (PVCGradientTable) , it is actually not a subclass of NSTableView – all the code is contained in the NSTextFieldCell subclass. This is unlike Matt Gemmell’s iTableView, which requires subclassing of NSTableView. (By the way, props to Matt – his iTableView helped me fix a lot of bugs.)
- It uses Chad Weider’s CTGradient code to render the gradient – the majority of implementations use either stretching images or bare CoreImage code.
- It allows you to enable centering the text vertically, a lá Daniel Jalkut’s RSVerticallyCenteredTextCell.
- It allows one to specify whether the text should be bold when clicked upon.
- It freshens your breath.
Here’s a screenshot, with the text bolded and vertically centered:
You can grab it here, or check it out from my Subversion repository (courtesy of Assembla – great job, guys!) here:
http://tools.assembla.com/svn/importantshock
Use the username and password ‘anonymous‘ (without quotes, of course) to access the repository.
Bug reports, accolades, fame, and large sacks of cash are welcome at:
ironswallow at gmail dot etc
By the way, PVC was the initial acronym for the Cocoa application I’m working on.
Anyway, I hope that y’all have a rockin’ Christmas. Oh, and check out Scott Stevenson’s really neat THCalendarInfo present to you; it kinda owns my present in terms of complexity. (It reminds me of the Ruby linguistics module in terms of slickness and usefulness.)
Bye!
