2016-04-26 41 views
1

我建立Datomic交易具有這種功能,這我然後在輸入關鍵字列表映射:cond爲什麼顯示'緩存'一個內部綁定?

(defn build-enum-transaction [inp] 
    (cond 
    (.contains (namespace (first inp)) "region") 
     [:db/add #db/id[:db.part/region] :db/ident (first inp)] 
    (.contains (namespace (first inp)) "sector") 
     [:db/add #db/id[:db.part/sector] :db/ident (first inp)] 
    (.contains (namespace (first inp)) "specialism") 
     [:db/add #db/id[:db.part/specialism] :db/ident (first inp)])) 

(defn build-all-enum-transactions [inp] 
    (vec (map build-enum-transaction inp))) 

的輸入數據集結全枚舉交易是:

([:region/EU] 
[:region/UK] 
[:region/NAFTA] 
[:sector/NON-CYCLICALS] 
[:sector/FINANCIALS] 
[:specialism/INSURANCE] 
[:specialism/VAT]) 

我得到以下結果:

[[:db/add #db/id[:db.part/region -1000289] :db/ident :region/EU] 
[:db/add #db/id[:db.part/region -1000289] :db/ident :region/UK] 
[:db/add #db/id[:db.part/region -1000289] :db/ident :region/NAFTA] 
[:db/add #db/id[:db.part/sector -1000290] :db/ident :sector/NON-CYCLICALS] 
[:db/add #db/id[:db.part/sector -1000290] :db/ident :sector/FINANCIALS] 
[:db/add #db/id[:db.part/specialism -1000291] :db/ident :specialism/INSURANCE] 
[:db/add #db/id[:db.part/specialism -1000291] :db/ident :specialism/VAT]] 

正如你所看到的,:db.part/應爲每個'cond'從句產生一個遞增數字。爲什麼是這樣?看起來好像'cond'正在關閉價值並重新使用它。謝謝。

回答

2

您應該使用d/tempid在運行時創建tempid。 #db/id是一個閱讀器宏,當程序被讀取時會擴展到一個臨時的,即編譯時間。

相關問題