http://lisperati.planvita.com/でclojureに適合したロシア語バージョンの「castingSPELs」チュートリアルを読みました...そしてこれまで、次のマクロがどのように機能するか理解できません:( http:を参照)ロシア語バージョンの場合は//lisperati.planvita.com/actions.html、Lispの場合は元のバージョンの場合はhttp://lisperati.com/actions.html):
(defspel game-action [command subj obj place & args]
`(defspel ~command [subject# object#]
`(spel-print (cond (and (= location '~'~place)
(= '~subject# '~'~subj)
(= '~object# '~'~obj)
(have? '~'~subj))
~@'~args
:else '(i cannot ~'~command like that -)))))
それはさらに次のように使用されます:
(game-action weld chain bucket attic
(cond (and (have? 'bucket) (def chain-welded true))
'(the chain is now securely welded to the bucket -)
:else '(you do not have a bucket -)))
(game-action dunk bucket well garden
(cond chain-welded
(do (def bucket-filled true)
'(the bucket is now full of water))
:else '(the water level is too low to reach -)))
ここでdefspel-はdefmacroの単なるエイリアスです。
マクロを作成する理由は、次の関数を置き換えるためです。
(defn weld [subject object]
(cond (and (= location 'attic)
(= subject 'chain)
(= object 'bucket)
(have? 'chain)
(have? 'bucket)
(not chain-welded))
(do (def chain-welded true)
'(the chain is now securely welded to the bucket -))
:else '(you cannot weld like that -)))
(defn dunk [subject object]
(cond (and (= location 'garden)
(= subject 'bucket)
(= object 'well)
(have? 'bucket)
chain-welded)
(do (def bucket-filled true)
'(the bucket is now full of water))
:else '(you cannot dunk like that -)))
私はこの「ゲームアクション」マクロがどのように機能するかについて完全に混乱しています...誰かがそれについてのすべてのこと(ネストされた引用符)を私に説明できますか?
私はすでに次の記事を読んだ-http://blog.8thlight.com/colin-jones/2012/05/22/quoting-without-confusion.html-それは役に立たなかった...
macroexpand-1も私を怖がらせます...
これは、溶接ゲームアクションの出力です。
(clojure-magic-game.core / defspelweld [subject_ 1058 _auto__ object_ 1059 _auto_](clojure.core / seq(clojure.core / concat(clojure.core / list(quote clojure-magic-game.core / spel-print))(clojure.core / list(clojure.core / seq(clojure.core) / concat(clojure.core / list(quote clojure.core / cond))(clojure.core / list(clojure.core / seq(clojure.core / concat(clojure.core / list(quote clojure.core / and)) (clojure.core / list(clojure.core / seq(clojure.core / concat(clojure.core / list(quote clojure.core / =))(clojure.core / list(quote clojure-magic-game.core / location ))(clojure.core / list(clojure.core / seq(clojure.core / concat(clojure.core / list(quote quote))(clojure.core / list(quote attic))))))))(clojure .core / list(clojure.core / seq(clojure.core / concat(clojure.core / list(quote clojure.core / =)))(clojure.core / list(clojure.core / seq(clojure.core / concat( clojure.core / list(quote quote))(clojure.core / list subject _1058_auto _))))(clojure.core / list(clojure.core / seq(clojure.core / concat(clojure.core / list(quote quote))(clojure.core / list(quote chain)))))) ))(clojure.core / list(clojure.core / seq(clojure.core / concat(clojure.core / list(quote clojure.core / =)))(clojure.core / list(clojure.core / seq(clojure。 core / concat(clojure.core / list(quote quote))(clojure.core / list object_ 1059_auto__))))(clojure.core / list(clojure.core / seq(clojure.core / concat(clojure.core / list(quote quote))(clojure.core / list(quotebucket))))))) )(clojure.core / list(clojure.core / seq(clojure.core / concat(clojure.core / list(quote clojure-magic-game.core / have?))(clojure.core / list(clojure.core / seq(clojure.core / concat(clojure.core / list(quote quote))(clojure.core / list(quote chain)))))))))))(quote((cond(and(have?(quoteバケット))(def chain-welded true))(quote(チェーンはバケットにしっかりと溶接されています-)):else(quote(バケットがありません-)))))(clojure.core/list: else)(clojure.core / list(clojure.core / seq(clojure.core / concat(clojure.core / list(quote quote)))(clojure.core / list(clojure.core / seq(clojure.core / concat( clojure.core / list(quote clojure-magic-game.core / i))(clojure.core / list(quoteclojure-magic-game。core / cannot))(clojure.core / list(quoteweld))(clojure.core / list(quote clojure-magic-game.core / like))(clojure.core / list(quote clojure-magic-game.core / that))(clojure.core / list(quote clojure.core /-))))))))))))))))
すべての名前空間を削除して出力をインデントしたとしても、私には理解できないほど複雑に見えます。
(defspel weld [subject__1058__auto__ object__1059__auto__]
(seq (concat
(list (quote spel-print))
(list (seq (concat
(list (quote cond))
(list (seq (concat
(list (quote and))
(list (seq (concat
(list (quote =))
(list (quote location))
(list (seq (concat
(list (quote quote))
(list (quote attic))))))))
(list (seq (concat (list (quote =))
(list (seq (concat
(list (quote quote))
(list subject__1058__auto__))))
(list (seq (concat
(list (quote quote))
(list (quote chain))))))))
(list (seq (concat
(list (quote =))
(list (seq (concat
(list (quote quote))
(list object__1059__auto__))))
(list (seq (concat
(list (quote quote))
(list (quote bucket))))))))
(list (seq (concat
(list (quote have?))
(list (seq (concat
(list (quote quote))
(list (quote chain)))))))))))
(quote ((cond
(and
(have? (quote bucket))
(def chain-welded true))
(quote (the chain is now securely welded to the bucket -))
:else (quote (you do not have a bucket -)))))
(list :else)
(list (seq (concat
(list (quote quote))
(list (seq (concat
(list (quote i))
(list (quote cannot))
(list (quote weld))
(list (quote like))
(list (quote that))
(list (quote -))))))))))))))