I'm attempting what should be a simple transformation using a macro
called dlg in the following code:
(defn fld [parent lay id text field]
  '...)

;; dlg macro.  For this input:
;;
;; (dlg "test"
;;  (field fld-1 "Field number one" (JTextField.))
;;  (field fld-2 "Field number two" (JTextField.)))
;;
;; we want this output:
;;
;; (fn [parent layout]
;;   (fld parent layout 'fld-1 "Field number one" (JTextField.))
;;   (fld parent layout 'fld-2 "Field number two" (JTextField.))
;;   parent)

(defmacro dlg [dlgid# & fields#]
  `(fn  [parent# layout#]
     ~@(map
        (fn [[f# id# text# type#]]
          `(fld parent# layout# '~id# ~text# ~type#))
        fields#)))

(def inp '(dlg "test"
               (field fld-1 "Field number one" (JTextField.))
               (field fld-2 "Field number two" (JTextField.))))

(macroexpand inp)

;; =>
;; (fn* ([parent__6 layout__7]
;;      (user/fld parent__4 layout__5 (quote fld-1) "Field number
one" (JTextField.))
;;      (user/fld parent__4 layout__5 (quote fld-2) "Field number
two" (JTextField.))))

(eval inp)

;; =>
;; java.lang.Exception: Unable to resolve symbol: parent__4 in this
context (NO_SOURCE_FILE:24)

I'm wondering why the macro produces 2 different "parent" symbols--I'd
like both references to be the same parent.  Any suggestions?

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