define-subclass macro

Pondering the philosophy behind the language
Locked
itistoday
Posts: 429
Joined: Sun Dec 02, 2007 5:10 pm
Contact:

define-subclass macro

Post 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? :-)
Get your Objective newLISP groove on.

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Re: define-subclass macro

Post by cormullion »

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

hilti
Posts: 140
Joined: Sun Apr 19, 2009 10:09 pm
Location: Hannover, Germany
Contact:

Re: define-subclass macro

Post 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
--()o Dragonfly web framework for newLISP
http://dragonfly.apptruck.de

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Re: define-subclass macro

Post 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?

itistoday
Posts: 429
Joined: Sun Dec 02, 2007 5:10 pm
Contact:

Re: define-subclass macro

Post 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.
Get your Objective newLISP groove on.

Locked