prototype-based Nu

4 views
Skip to first unread message

Jason Grossman

unread,
Oct 13, 2009, 9:13:51 PM10/13/09
to Programming Nu
I'm used to prototype-based programming, from Io and Ioke.

It's nice and easy to do prototype-based programming in Nu: just make
all your new objects classes, and all your new methods class methods.
Existing instance methods (from the libraries) can be converted into
class methods, either automatically or as required. This seems to
give the same kind of differential inheritance as I'm used to. It can
be made prettier by defining a new word, say "proto", to mean the same
as "class", thus:

(macro-1 proto (*body) `(class ,@*body))

(By the way, I'm surprised to see that "macro" is still "macro-0".
Shouldn't it be "macro-1"?)

A toy example:

(proto animal is NSObject
(+ call is "I don't know what to say.")
(+ size is "unknown"))

(proto dog is animal
(+ call is "woof!"))

(dog call)
;; returns "woof!"

(dog size)
;; returns "unknown"

Now for my question: is there a major efficiency problem with doing
this?

sasha

unread,
Oct 14, 2009, 3:34:16 AM10/14/09
to Programming Nu
Well, I'm not sure about any problem with efficiency, but I suppose
that one thing you'll lost is automatic indentation in Emacs or
TextMate, if you use any.
And other people can have some problems reading your code.

All the best,
Sasha
Reply all
Reply to author
Forward
0 new messages