0
votes
1answer
34 views

Clojure - inversion of control macro - Timothy Baldridge

In this podcast on core.async at approximately 12 mins in, Rich Hickey refers to a macro written by Timothy Baldridge that does 'inversion of control'. That this macro rewrites code into a state ...
1
vote
2answers
21 views

How to catch IllegalArgumentException in tests using thrown-with-msg?

I try to test the throw of an exception: ;;; src ;; Courtesy https://github.com/clojure/clojure/blob/master/src/clj/clojure/core.clj (defmacro assert-args [& pairs] `(do (when-not ~(first ...
2
votes
2answers
44 views

Issue with clojure macro returning map with java object

I'm very new to macros so I have a basic question that seems to do with the way that Java objects are represented in Clojure code. I have a macro that should return a map: (defmacro g [] (let [m ...
1
vote
2answers
75 views

How can I avoid evaluation of a lazy-seq inside a collection

I'm trying to write a debug macro that prints out expressions and their values. This lead to problems if I send in a lazy-seq, because if I turn it into a string (with str) the program hangs. It's ...
3
votes
1answer
44 views

Why doesn't my macro give any output

I wrote a simple macro for printing out expressions and their results when debugging. (defmacro dbg-print "Print out values or expressions in context" [& rest] `(let [symb-str# (map str ...
5
votes
1answer
92 views

Starting points to morph regular Servlets coding to my DSL

Clojure offers a good Java interop. However, I really want to have this: (servlet IndexServlet (service[parmas] ....) (do-post[params] ....) (do-get [params] ....)) (servlet-filter ...
3
votes
1answer
44 views

Reverting to global scope in macro in clojure?

I want to make a macro which defines a function outside of the local variable scope, as to catch errors where the programmer (aka me) is incorrectly referencing variables in the local scope. It should ...
2
votes
1answer
58 views

Clojure macro Instantiation Exception

I have a macro which works in the repl, and it seems to work in my code outside the let and also inside the let as follows. However it also breaks and I have no idea why. The macro basically just ...
2
votes
1answer
96 views

How to test a clojure macro that uses gensyms?

I want to test a macro that uses gensyms. For example, if I want to test this: (defmacro m1 [x f] `(let [x# ~x] (~f x#))) I can use macro-expansion... (macroexpand-1 '(m1 2 inc)) ...to ...
4
votes
1answer
72 views

Clojure How to Expand Macro in Source File Versus Repl

I am leaning macros in Clojure and have a question about macro expansion. In the repl, when I do this: user=> (defmacro unless [pred a b] `(if (not ~pred) ~a ~b)) #'user/unless user=> ...
1
vote
2answers
51 views

How do you transform a vector of maps into a series of symbols that eval to a particular map?

I am a Clojure newbie using Light Table to learn macros. My goal is to convert a vector of maps into a list of def statements. I want to transform the following data structure: (def label-data [ ...
2
votes
2answers
79 views

How to use defmacro instead of eval?

I have come up with the below function, which works as intended but it uses eval which is horrible, and does not exist in ClojureScript where i intend to use it. (defn path [d p] (eval (concat ...
2
votes
2answers
87 views

Clojure macro that doesn't need space next to it

Trying to create a macro form of Haskell's lambda syntax, I'm pretty close except one last tweak, the / (which should be a \, but can't grumble..) needs a space next to it, is there any way to make it ...
1
vote
1answer
36 views

Macro want to use symbol instead of string in clojure

So trying to make something like the haskell lambda syntax, and with a macro this is what I've got: (defmacro / [& all] (let [args (take-while #(not (= %1 "=>")) all) argCount (count ...
2
votes
3answers
136 views

Backquote without parens

I am working through the excellent book Let Over Lambda, and I am trying to port the Common Lisp code for defunits over to Clojure. The following generates a macro that is supposed to take (defn ...

1 2 3 4 5 13
15 30 50 per page