brehaut has gotten interested in another language. Lisp, Scheme {see also Structure and Interpretation of Computer Programs} and in particular the new Mac OS X language Nu.
Gosh
So heres the dirt. My interest in Nu flows from my interest in F-Script as an language for scripting Objective-C / Mac OS X apps. Both Smalltalk and Lisp interest me. Nu however has a few small advantages over F-Script:
- Supports class creation and extension out of the gate. There are a number of third party F-Script ones, but they arent as nice as Nu.
- Nu has a broader range of supporting tools. Most importantly, it has ‘nush’ the Nu Shell as standard. Basicly, it has a richer ecosystem as part of its toolset, and the developer seems to have put a lot of effort into making it useful.
- Macros. I’m embeding Nu into an app that needs to load complex rule descriptions, i was previously using XML but it was lumpy and not really very suited to it. Now im using Nu and some macros to implement it directly and allow flexible and comprehensive scripting. Much nicer.
Examples
find-prop takes a list and separates out the properties into a dictionary and returns it with a list
(function find-props (l)
;; the dictionary will store the properties
(set properties (((NSMutableDictionary) alloc) init))
(function search (l)
(cond
((not l) l)
((and ((head l) isKindOfClass: NuSymbol)
((head l) isLabel)
(tail l))
(progn
(properties setObject:(second l)
forKey:((head l) labelName))
(search (tail (tail l)))))
(else (cons (head l) (search (tail l))))))
(list (search l) properties))
unpack is a very basic destructuring macro. it takes a data-structure and a matching structure of symbols and sets the symbols to the equivalently placed data. Not super safe, it wont crash your program, but it may only partially apply the unpack.
(macro unpack
(set __struct (eval (first margs)))
(set __pattern (eval (second margs)))
(if (and __pattern __struct (head __pattern) (head __struct))
(cond
(((head __pattern) isKindOfClass: NuCell)
(unpack (head __struct) (head __pattern)))
(else (eval (list set (head __pattern) (quote (head
__struct)))))
)
(unpack (tail __struct) (tail __pattern))))
