Page 1 of 1

define-subclass macro

Posted: Thu Oct 15, 2009 9:26 pm
by itistoday
While working on the Dragonfly framework I came up with a useful macro called define-subclass for FOOP:

Code: Select all

(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:

Code: Select all

(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? :-)

Re: define-subclass macro

Posted: Sat Oct 17, 2009 8:58 am
by cormullion
Cool. Are you adding FOOPy stuff to Dragonfly? Sounds fascinating!

Re: define-subclass macro

Posted: Sat Oct 17, 2009 9:31 am
by hilti
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

Re: define-subclass macro

Posted: Sat Oct 17, 2009 4:03 pm
by 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?

Re: define-subclass macro

Posted: Wed Oct 21, 2009 3:58 pm
by itistoday
cormullion wrote: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.