Clojure macro inside another macro: how to generate string from symbol -


The title is not 100% accurate, but let me show you this problem:

   

In short: there is a macro called defxetch (this is part of lib quil , but it does not matter). This signature is basically the defxetch [applet -name] is & amp; Options] , and it creates something and it is tied in a var called applet-name . For the reason, I want to wrap it in another macro - in another thing - - takes an applet-name parameter, to name that name as applet-name-viewport , And I go to defsketch . However, I'm unable to (pprint (macroexpand (nvp test-name 500 500)) , me

  To understand how to use macroxpand at the above code (def (closeor.core / symbol (closeor.core / stroke (cl.j.or / name 'my-namespace.core / test-name) "-viewport") (quil.applet / applet: Title (clojure.core / name 'my-namespace.core / test-name)))   

(clojure.core / symbol (clojure.core / str (clojure.core / Name "my-namespace.core / test-name" "-viewport") - This part looks good, but it should be evaluated before passing the internal macro by any means ... < / P>

You have to leave the form that generates new symbol instead of the original symbol.

Here is a small example of how to use a defn for the macro internal macro:

  (defmacro mydefn [name & Amp; body] `(defn ~ name ~ @ body) (defmacro defnview [n & amp; body]` (mydefn ~ (symbol (str (name n) "-viewport")) ~ ~ body) ;; Or defmacro defnview [n & amp; body] ([n (symbol (str (name n) "-details"))] `(mydefn ~ n ~ @ body)))   

Example:

  (defnview foo [a] a) ;; = & Gt; # 'User / FU-viewport (FU-viewport 1) ;; = & Gt; 1 (macroxpand '(defniewuefu [a] a)) ;; = & Gt; (Def foo-viewport (clojure.core / fn ([a] a))    

Comments

  1. शुरुआती के लिए जावा प्रोग्रामिंग के नमूने
    सरल अंकगणित जावा कार्यक्रम

    ReplyDelete

Post a Comment

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -