मैं एक Clojure defprotocol
है कि मैं कई समान स्विंग घटकों के लिए लिख रहा हूँ के लिए कई तरीके जोड़ने की जरूरत से एक से अधिक मान लौटने वाले:एक clojure मैक्रो
(defprotocol view-methods
(ok-button-add-action-listener [this listener])
(ok-button-set-enabled [this enabled])
(ok-button-set-selected [this selected])
(cancel-button-add-action-listener [this listener])
(cancel-button-set-enabled [this enabled])
(cancel-button-set-selected [this selected])
(other-button-add-action-listener [this listener])
(other-button-set-enabled [this enabled])
(other-button-set-selected [this selected]))
वहाँ किसी भी तरह से है कि मैं एक मैक्रो है कि सभी रिटर्न लिख सकते है तीन विधि हस्ताक्षर (xxx-button-add-action-listener
, xxx-button-set-enabled
, xxx-button-set-selected
)?
(defprotocol view-methods
(add-methods ok)
(add-methods cancel)
(add-methods other))
इस मैक्रो प्रत्येक मंगलाचरण के साथ बढ़ रहा defprotocol
करने के लिए तीन आइटम जोड़ने की जरूरत है।
क्या मैक्रो `[email protected]
लौटा सकता है और "जगह में" विस्तार कर सकता है?
मुझे पता चल रहा है कि स्टुअर्ट सिएरा के 'डू-टेम्पलेट' मैक्रो (http://clojure.github.com/clojure/clojure.template-api.html) को देखने से। जैसा कि हम बोलते हैं, मैं इसका प्रयोग कर रहा हूं :-)। धन्यवाद। – Ralph