Johannes <bra...@nordakademie.de> writes:

Hi Johannes,

> I am trying to build an alternative record building macro. For example
>
> (define-record point [x y])
> should define 
> - a new type point
> - a constructor make-point

(defrecord Point [x y]) generates also a constructor function (->Point x
y).

> - a type checker point?

As a shorthand for (instance? Point my-obj)?  Well, that could make
sense here and there, although in general, if you use those type-checks
like

     (cond
      (Point? o)   (transform-point o)
      (Polygon? o) (transform-polygon o)
      ...)

it's likely that you want a protocol Transformable declaring a
`transform` method, and both Point and Polygon provide an implementation
for it.  Then the above becomes just (transform o), and it'll do the
right thing no matter if it's a Point or Polygon.

> - and 2 getters point-x and point-y

I don't see a benefit of (point-x point) over (:x point).

The main problem with your `define-point` macro is that it should also
allow for defining protocol implementations like `defrecord`.  Else,
it's simply not as powerful as the latter.

Bye,
Tassilo

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to