clojure macros

2009-03-02 Thread linh
hello, there are lots of good examples of clojure macros on the web, but i miss a more detailed explanation. for example what do all these special characters used inside macros really mean ` ' @ ~ # ~...@. anyone know if there's a tutorial for clojure macros (not lisp)? macros are very

Clojure macros

2010-09-05 Thread ingokr
Hello -- I am trying to gain a better understanding of Clojure's macro language. The output I am aiming for (and which is to be used as code in another macro) is as follows: {:a a :b b :c c :d d} The attempt I made is as follows: (defmacro tm [& args] `{~@(mapcat (fn [x] (list (keyword x) x)

Re: clojure macros

2009-03-02 Thread linh
now i've found an interesting article that describes macros in more details http://www.ociweb.com/mark/clojure/article.html#Macros On 2 Mar, 10:27, linh wrote: > hello, > there are lots of good examples of clojure macros on the web, but i > miss a more detailed explanation. >

Re: Clojure macros

2010-09-05 Thread Andrew Gwozdziewycz
This seems like a bug to me. user> `[~@(mapcat #(list (keyword %) (str %)) '(a b c))] [:a "a" :b "b" :c "c"] user> `(~@(mapcat #(list (keyword %) (str %)) '(a b c))) (:a "a" :b "b" :c "c") user> `#{~@(mapcat #(list (keyword %) (str %)) '(a b c))} #{"a" "b" "c" :a :c :b} user> `{~@(mapcat #(list (k

Re: Clojure macros

2010-09-05 Thread CuppoJava
I'm not sure if this is intended behavior or not, since unquote- splicing was originally meant for splicing into lists. But for now anyway, you can use this as a workaround? (defmacro tm [& args] `(hash-map ~@(mapcat (fn [x] (list (keyword x) x)) args))) Hope that helps -Patrick On Sep 5, 3:

Re: Clojure macros

2010-09-05 Thread Meikel Brandmeyer
Hi, Am 05.09.2010 um 23:10 schrieb CuppoJava: > (defmacro tm [& args] > `(hash-map ~@(mapcat (fn [x] (list (keyword x) x)) args))) Or you return the map directely: (defmacro tm [& args] (apply hash-map (mapcat (juxt keyword identity) args))) Sincerely Meikel -- You received this message

Re: Clojure macros

2010-09-05 Thread Kent
When clojure evaluates a piece of code it goes through several steps. First the reader takes the string representation of your code and turns it into the clojure data structures represented by your code. Those data structures are then sent to the compiler for compilation, including possible macro e

Re: Clojure macros

2010-09-05 Thread Andrew Gwozdziewycz
On Sun, Sep 5, 2010 at 5:18 PM, Kent wrote: > When clojure evaluates a piece of code it goes through several steps. > First the reader takes the string representation of your code and > turns it into the clojure data structures represented by your code. > Those data structures are then sent to the

Re: Clojure macros

2010-09-05 Thread ingokr
Hi again -- First, let me thank all of you for you kind and instructive comments. Kent: thanks for the explanation of the relationships between reader and macro expansion. Patrick & Meikel: thanks! Your solutions do produce almost what I need; the idea is with (tm a b) I should get back {:a a

Re: Clojure macros

2010-09-05 Thread Michał Marczyk
On 6 September 2010 01:11, ingokr wrote: > Patrick & Meikel: thanks! Your solutions do produce almost what I > need; the idea is with > > (tm a b) > > I should get back > > {:a a :b b} > > Your solutions produce sth equivalent to {:a (eval a) :b (eval b)} in > this case. Actually Meikel's solutio

Re: Clojure macros

2010-09-05 Thread ingokr
Ah! Thanks a lot, Michał -- that clarifies a lot for me. Best regards, Ingolf -- 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 Note that posts from new members are moderated - please be pat

how does Clojure macros work?

2009-06-26 Thread Michele Simionato
to spent a few words about the differences between Scheme and other lisps. In particular I want to asset the status of Clojure macros with respect to hygiene. Since they look a lot like Common Lisp macros, I initially assumed that Clojure macros were not hygienic, but after performing some ex

Re: how does Clojure macros work?

2009-06-26 Thread Michele Simionato
On Jun 26, 9:53 am, Michele Simionato wrote: > I want to asset the status of Clojure > macros with respect to hygiene. Some further experiment: $ clj Clojure 1.1.0-alpha-SNAPSHOT user=> (def x 42) #'user/x user=> (defmacro m[] 'x) #'user/m user=> (m) 42 user=>

Re: how does Clojure macros work?

2009-06-26 Thread Rich Hickey
hygienic > macros > (http://www.artima.com/weblogs/viewpost.jsp?thread=260195) > and I wanted to spent a few words about the differences between > Scheme and other lisps. In particular I want to asset the status of > Clojure > macros with respect to hygiene. > > Since they look a

Re: how does Clojure macros work?

2009-06-26 Thread Rich Hickey
On Fri, Jun 26, 2009 at 9:22 AM, Michele Simionato wrote: > > On Jun 26, 9:53 am, Michele Simionato > wrote: >> I want to asset the status of Clojure >> macros with respect to hygiene. > > Some further experiment: > > $ clj > Clojure 1.1.0-alpha-SNAPSHOT &

Re: how does Clojure macros work?

2009-06-26 Thread Michele Simionato
On Jun 26, 3:51 pm, Rich Hickey wrote: > By using quote, and not syntax-quote, you have written an > intentionally capturing macro Acc, I missed that. I have read the documentation of syntax-quote now: "" For Symbols, syntax-quote resolves the symbol in the current context, yielding a fully-qu

Re: how does Clojure macros work?

2009-06-26 Thread Laurent PETIT
Hi, 2009/6/26 Michele Simionato > > > On Jun 26, 3:51 pm, Rich Hickey wrote: > > By using quote, and not syntax-quote, you have written an > > intentionally capturing macro > > Acc, I missed that. I have read the documentation of syntax-quote now: > > "" > For Symbols, syntax-quote resolves the

Re: how does Clojure macros work?

2009-06-26 Thread Meikel Brandmeyer
Hi, Am 26.06.2009 um 16:39 schrieb Michele Simionato: That means that I do not need gensym, I can just add a `#` to the identifiers I want to introduce hygienically, right? I guess this is what you meant by autogensym in the other post. A pretty cool idea, actually. Exactly, here a short real

Re: how does Clojure macros work?

2009-06-26 Thread Konrad Hinsen
On 26.06.2009, at 15:22, Michele Simionato wrote: > Finally, as an unrelated question, is there an equivalent of macrolet > in Clojure? Not in Clojure itself, but there is an implementation in an external library, clojure.contrib.macro-utils: http://github.com/richhickey/clojure-contrib/blob/

Is There An Upcoming Book On Clojure Macros?

2012-12-06 Thread octopusgrabbus
I have most of the Clojure text books available, and have found them all to be quite good. Each one seems to have a different focus, which, depending on the problem at the time, shines light on my particular problem du jour. IMHO, while the current crop of books is quite good, none that I've see

Re: Is There An Upcoming Book On Clojure Macros?

2012-12-06 Thread Andy Fingerhut
Paul Graham's On Lisp is available for free here: http://www.paulgraham.com/onlisp.html It is definitely focused on Common Lisp, not Clojure, and there are differences between the way symbols and namespaces (Clojure) and packages (Common Lisp) are handled in those two languages that make some C

Re: Is There An Upcoming Book On Clojure Macros?

2012-12-06 Thread ericClojure
Here's someone who's translating Paul Graham's "On Lisp" to Clojure: http://onbeyondlambda.blogspot.com/search?q=on+lisp Some of the authors of Clojure books have done translations as well, although the translations I saw stopped a few chapters in. On Thursday, December 6, 2012 1:44:46 PM UTC-5

Text replacement capability in clojure macros (just like C #define)

2019-02-01 Thread faiz
I want to write a macro (defmacro params [] 'a 'b 'c) that will be used in places like this ;; without macro (fnc a b c) ;; with macro (fnc pararms) => (fnc a b c) If you see this could be easily done by C's #define which was just a text replacement -- You received this messa

Re: Text replacement capability in clojure macros (just like C #define)

2019-02-01 Thread Ben Sima
f...@helpshift.com writes: > I want to write a macro > > (defmacro params [] 'a 'b 'c) > > that will be used in places like this > > ;; without macro > (fnc a b c) > > ;; with macro > (fnc pararms) => (fnc a b c) If you have a list of params, you can apply a function to it like so:

Will it ever be possible to use reader conditionals in clojure macros

2017-03-17 Thread Arewa Olakunle
I have been trying to define a macro for clojurescript/clojure using a cljc file (ns async (:require #?(:clj [clojure.core.async :as a :refer [go-loop]]) #?@(:cljs [[cljs.core.async :as a] [cljs.core.async.macros :refer [go-loop]]]))) (defmacro dochan "Wrap

Re: Will it ever be possible to use reader conditionals in clojure macros

2017-03-17 Thread Arewa Olakunle
Sorry I posted this here, wasn't aware of clojurescript group. Found a similar posting(almost a clone) here with a useful hack here