Hi,

Am 23.11.2008 um 02:29 schrieb James Reeves:
(defn make-person [name age]
  (assoc (struct person name age person) :type person))

Maybe you could roll this into a macro:

(defmacro struct*
[type & params]
`(assoc (struct ~type [EMAIL PROTECTED]) :type ~type))

Why? A function does the same. There is no need for a macro.

(defn struct*
  [type & params]
  (assoc (apply struct type params) :type type))

(defn make-person
  [name age]
  (struct* person name age))

(defn make-circle
  [center radius]
  (struct* circle center radius))

Evaluating type twice in the above macro might also lead
to unexpected problems. Although this very unlikely in this
use case.

Please use macros very carefully! They are a source of
great power, but they are also a big cannon aiming at your
foot (and leg and hip and ...).

Sorry for being the nit-picker.

Sincerely
Meikel

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to