define-subclass macro

Started by itistoday, October 15, 2009, 02:26:19 PM

Previous topic - Next topic

itistoday

While working on the Dragonfly framework I came up with a useful macro called define-subclass for FOOP:


(define-macro (define-subclass)
(new (args 0 1) (args 0 0))
(dolist (method (rest $args))
(setf (method 0 0) (sym $it (args 0 0)))
(eval (push 'define method))
)
)


It must be called while in the MAIN context. Here's an example of how it's used:


(new Class 'Foo)
(define (Foo:get x) (x 1))
(define (Foo:set x v) (setf (x 1) v) x)

(define-subclass (Bar Foo)
((get x) (x 2))
((set x v) (setf (x 2) v) x)
((str x) (string x))
)

(:get (Foo 1 2)) => 1
(:get (Bar 1 2)) => 2
(:str (:set (Bar 1 2) 3)) => (Bar 1 3)


Neat huh? :-)
Get your Objective newLISP groove on.

cormullion

#1
Cool. Are you adding FOOPy stuff to Dragonfly? Sounds fascinating!

hilti

#2
Yep. Greg and I are now working together on the next version of Dragonfly. Some cool things will be included like static routes or a parser which enables you to use your very own templating language.



Cheers!

Hilti
--()o Dragonfly web framework for newLISP

http://dragonfly.apptruck.de\">http://dragonfly.apptruck.de

cormullion

#3
Excellent! I'm looking forward to seeing what you come up with...



I think I've said before that the only real problem I have with using Dragonfly so far is that it's hard to upgrade to a newer version, since the user's data and the framework are intertwined to an extent. Don't know how that works for other frameworks - perhaps it's always a problem?

itistoday

#4
Quote from: "cormullion"Excellent! I'm looking forward to seeing what you come up with...



I think I've said before that the only real problem I have with using Dragonfly so far is that it's hard to upgrade to a newer version, since the user's data and the framework are intertwined to an extent. Don't know how that works for other frameworks - perhaps it's always a problem?


The next release of Dragonfly is going to have a lot of changes, and it will include an upgrade guide. One of the changes is that the framework will be decoupled from both the user's data and the demo site, so hopefully that should address your concern.
Get your Objective newLISP groove on.