defstruct is deprecated. You should use defrecord or deftype instead. You
can define operations on these via defprotocol.

And you can even type hint the members:

(defprotocol IScale
  (scale [this ^double amount]))

(deftype Point [^double x ^double y]
  IScale
  (scale [this amount]
    (Point. (* x amount) (* y amount))))

(scale (Point. 10 1))

Timothy



On Wed, Jul 2, 2014 at 9:41 AM, SharpCoder <cannonicalco...@gmail.com>
wrote:

> As an exercise, I'm trying to port a library that I originally wrote in
> C#. It's actually a Neural Network, so my imperative design was a pretty
> straightforward tree-like structure of nodes that could manipulate state.
> During my port to Clojure, I've been writing functions that take multiple
> arrays (typically "graph of outputs" and "graph of weights"). Then I
> remembered about structs, so I refactored my code to deal with a collection
> of structs "node". A node contains a vector of weights and an output. In
> this way, I am only passing around a single collection that can represent
> my whole neural network.
>
> Now I'm running into the fact that I kind of need to update the structure.
> So what I've implemented is essentially, each time you calculate the
> network output - my code iterates over the list of structs and creates new
> ones with the "updated" values. Performance is something that people don't
> seem to talk about much with Clojure, but I'm kind of thinking my approach
> with structs might not be the best one.
>
> My question is, am I approaching this incorrectly? I've seen a lot of
> resources that deal with the syntax of Clojure but haven't found a good
> guide on actual application design. My usage of structures seems natural to
> me, but that makes me question it even more!
>
> For anyone interested, here is my code: https://www.refheap.com/87775
> I'm going to open source the library after many many iterations to
> beautify it. I'm sure it's a bit too haphazard to make sense to right now...
>
> Thank you for your time!
> -SharpCoder
>
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
“One of the main causes of the fall of the Roman Empire was that–lacking
zero–they had no way to indicate successful termination of their C
programs.”
(Robert Firth)

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to