> here's the 'is-pt' macro again:
>
> (define-syntax is-pt
>
> (lambda (stx)
>
> (syntax-case stx ()
>
> ((is-pt var)
>
> (syntax
>
> (begin
>
> (define-get-field-syntax var x pt-x)
> (define-get-field-syntax var y pt-y)
>
> (define-set-field-syntax var x pt-x-set!)
> (define-set-field-syntax var y pt-y-set!)
>
> (define-record-method-syntax var neg pt-neg)
> (define-record-method-syntax var norm pt-norm)))))))
I like having the factored out macros like 'define-get-field-syntax',
and 'is-pt' isn't very complicated, but it would be nice to have a macro
generating macro to define things like 'is-pt' based on a record
description.
So next up is 'define-is-type-syntax':
http://gist.github.com/244817
And the pt example again, where I generate 'is-pt' via
'define-is-type-syntax':
http://gist.github.com/244819
By now, the 'define-is-type-syntax' expression contains all the info
passed to 'define-record-type' so I could do everything in a single
statement...
Notice that in the notion for specifying methods:
(define-is-type-syntax is-pt
pt
(fields x y)
(methods (neg pt-neg)))
'neg' is the method name and 'pt-neg' is the procedure that implements
the method. If I imposed a certain naming convention for method
procedures like pt::neg or just pt-neg, the syntax could just be:
(define-is-type-syntax is-pt
pt
(fields x y)
(methods neg))
but I'm leaving in the flexibility for now.
Also notice the method implementation:
(define (pt-neg p)
(make-pt (- (pt-x p))
(- (pt-y p))))
There could be sugar for this:
(define-method pt (neg)
(make-pt (- x)
(- y)))
where 'define-method' takes care of the the expansion into:
(define (pt-neg this)
(import-pt this)
(make-pt (- x)
(- y)))
By the way... while this single-receiver style of methods is nice in
some cases, I'm also a big fan of multi-methods and CLOS style object
systems. I'm not much of a "this" means we can't have "that" kinda guy;
I think both systems have their place and can co-exist; along with
prototype style systems. Also, check out Categories, an experimental
object system by Mikel Evins:
http://www.mikelevins.com/categories/categories.html
Ed
Who's technically still on "vacation" visting familia; but there ain't
much going on in Los Fresnos, Texas. :-)