Hi stu,

take a look in clojure protocols. I think that this can help you.
http://clojure.org/protocols  <http://clojure.org/protocols>

Luiz Costa
<http://clojure.org/protocols>
On Mon, Mar 14, 2011 at 11:54 PM, stu <stuart.hungerf...@gmail.com> wrote:

> Hi,
>
> I'd like to create a simple library of drawable shapes: lines, circles
> and rectangles.  I've placed each type of shape in its own namespace
> with functions that operate on that shape kind:
>
> (ns myshapes.line)
>
> (defn line ... creates new line ...)
>
> (defn draw ... draws a line ...)
>
>
> To keep things simple a line is just a vector of two points and
> circles and rectangles are just structs.
> I'd also like to have a sequence of shapes called a picture:
>
> (ns myshapes.picture)
>
> (defn picture ... returns picture sequence from args ...)
>
> (defn draw ... draws whole picture)
>
>
> The problem I have is with the myshapes.picture/draw function. As a
> Clojure newb I keep wanting to think of this like a polymorphic
> function in the O-O world that relies on each sequence member having a
> draw function.
>
> What's the idiomatic way of handling a situation like this in
> Clojure?  Do I need to use richer data structures than vectors and
> structs for the shapes so they carry some kind of type information?  I
> can see how a draw multi-method would work if the individual shapes
> could be distinguished, or am I going about this the wrong way?
>
> Any advice much appreciated,
>
> Stu
>
> --
> 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

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