zcaudate
zcaudate

Reputation: 14258

is it possible to define a constructor for deftype?

a trivial case for a constructor for deftype

(deftype Atom [v]
    ...)

and I want v to be wrapped in an atom so that

@(.v (Atom. 1)) => 1

is this possible?

Upvotes: 2

Views: 2097

Answers (2)

Ivan Koblik
Ivan Koblik

Reputation: 4325

Same question was asked before, please see this: Add constructor to deftype created class

Upvotes: 0

Ankur
Ankur

Reputation: 33657

Nope. If you really want to go the OO way of constructor then you will need to use gen-class.

In functional world it is very simple using a function.

(defn createAtom [v] (Atom. (atom v)))
@(.v (createAtom 1)) => 1

Upvotes: 3

Related Questions