yeah, I think records are the best approach, but I just struggle with
them. Unfortunately I need an article or 2 on these to really get
them. Last time I tried I was pretty unsuccessful.
On Nov 13, 11:41 am, Chris Maier wrote:
> Another approach would be to use records and protocols:
>
> (defpr
thanks Michel, the more realistic form was quite a bit longer, but i
will show just a piece of my (mis)direction
(defstruct Ruleform-struct
:rname :rule-seq
:if-cnt :then-cnt )
(defn rule-if-names [{:keys [ rule-seq if-cnt ] :as ruleform } ]
; (Camoflage Spotted Cover Action Use-Cover
Another approach would be to use records and protocols:
(defprotocol HasCees
(c [this] "Returns a 'c'"))
(defrecord Foo [a b]
HasCees
(c [this]
(+ (:a this) (:b this
Now, to use it:
user> (def my-foo (Foo. 1 2)
#'user/my-foo
user> (c my-foo)
3
This is practically a drop-in replac
On Sat, 13 Nov 2010 06:31:03 -0800, garf wrote:
> If I have a struct whose creation will require some function calls that
> references some of its members, I am unsure how to go about it in a
> clean way. For example:
> (defstruct tz :a :b :c)
>
> (def tz1 1 2 (+ (:a tz1) (:b tz1))
>
Could
thank you! It seems so obvious now
On Nov 13, 10:38 am, Benny Tsai wrote:
> One way you could do it is by building up the members incrementally
> via 'let':
>
> (defstruct tz :a :b :c)
>
> (def tz1 (let [a 1
> b 2
> c (+ a b)]
> (struct tz a b c)))
>
> On
One way you could do it is by building up the members incrementally
via 'let':
(defstruct tz :a :b :c)
(def tz1 (let [a 1
b 2
c (+ a b)]
(struct tz a b c)))
On Nov 13, 7:31 am, garf wrote:
> If I have a struct whose creation will require some function ca
If I have a struct whose creation will require some function calls
that references some of its members, I am unsure how to go about it in
a clean way. For example:
(defstruct tz :a :b :c)
(def tz1 1 2 (+ (:a tz1) (:b tz1))
will not work, but reflects the problem. Ideally at the end of this