Hi, I'm new to clojure (though I've messed around in scheme a little)
and I'm trying to represent an electrical circuit with "pins" and
"nets" (ie in graph terminology vertices and edges).

I'd like to represent the nets as {:name "net_name" :pins #{pin1 pin2
pin3}} etc.
I'd like to represent each pin as {:name "pin_name" :net the_net :type
pin_type}

I want to query the net for all its attached pins, and to query any
pin to see what net it's attached to.  The problem here is that these
are mutually-referring things.  The net refers to the pins and each
pin refers back to the net.

How do I create these without mutation?  For example I could create
all the pins, then the net, then go back and fill in the net for all
the pins.  I'm still reading through how to implement mutable stuff,
but I have a strong sense this is not the correct implementation.

I thought maybe instead I should represent the circuit by having each
"pin" and each "net" actually be a vertex in the graph, and each graph
edge is a connection between a pin and a net.  If I represent this as
a set of edges, the above then becomes (I'm doing this in analog to
emphasize I don't want a source or destination pin, and I don't
believe I need a directed graph.)

(def p1 {:name "pin1" :impedance 1.0})
(def p2 {:name "pin2" :impedance 1e6})
(def p3 {:name "pin3" :impedance 1e6})
(def n1 {:name "the_net" :type "analog"})

(def circuit
   #{{ :pin p1 :net n1}
      { :pin p2 :net n1}
      { :pin p3 :net n1}} )

I can then use this for all the basic stuff such as seeing which pin
is connected to which net. Connections are easy to create or delete.

For a large circuit however it may be slow to filter through this set
to see what's connected to what for any given query, so perhaps I
could assoc to each pin or net its local connectivity.  This would not
require mutation, only copying the set where each pin or net gets a
new key and list of its local connection.  The drawback here is any
connectivity changes requires going through the affected nets or pins
and updating their local cache.

Any advice mucho appreciated

Thanks
Michael

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