Re: macro question

2016-01-27 Thread echigoyamontoya
Great! Thanks all for your explanations. On Wednesday, January 27, 2016 at 4:33:40 AM UTC-8, gianluca torta wrote: > > Hi Dan, > > > And, if I understand correctly, what was really happening with the macro >> bar was that in ('+ 2 'u), '+ was looking itself up in 2, not finding >> itself, and

Re: macro question

2016-01-27 Thread gianluca torta
Hi Dan, And, if I understand correctly, what was really happening with the macro > bar was that in ('+ 2 'u), '+ was looking itself up in 2, not finding > itself, and so returning the default value 'u. This was the expansion of > the macro, and so at run time, it was bound to 10. > > exactly,

macro question

2016-01-26 Thread echigoyamontoya
I'm new to clojure and macros and am having trouble wrapping my head around some simple things. I know that this macro will add 2 to its argument: user=> (defmacro plus-two [x] `(+ 2 ~x)) #'user/plus-two user=> (plus-two 5) 7 user=> (def u 10) #'user/u user=> (plus-two u) 12 I tried the

Re: macro question

2016-01-26 Thread Dan Burton
> I know that this macro will add 2 to its argument: This isn't what that macro does. That macro takes a piece of syntax, and sticks that syntax in the hole in the expression (+ 2 HOLE). The macro doesn't evaluate the expression, it just generates it. It is the evaluation of *that* expression

Re: macro question

2016-01-26 Thread echigoyamontoya
Thanks for your reply. I guess I was forgetting that at macroexpansion time (if I'm using the word correctly), we don't have access to the binding between u and 10. The same error I message I noted above does appear for (+ 2 'u). And, if I understand correctly, what was really happening with

Re: macro question

2016-01-26 Thread Matching Socks
A macro emits a form for the compiler to compile. And it understands its inputs as forms -- unevaluated forms. - Your plus-two emits a list with + in function position. - foo, when it is computing the form to emit, applies + to 2 and some form x. So 5 works but u does not, even after (def u

Re: about macro exception : Unable to resolve classname: LinkedList, macro question and possible better approach

2015-03-08 Thread coco
All your macro needs to do is to convert the first form into the second. thanks james, that make sense for me... I don't know what the rest of your function is supposed to be doing you can check my second example (def data (atom )) (defmacro blahhh [] (go (let [ch

Re: about macro exception : Unable to resolve classname: LinkedList, macro question and possible better approach

2015-03-08 Thread coco
Sure, because you haven't quoted the symbol. If you write: (str *ns* : some-bus) ups!!, yes I forget quoted the symbol, thanks james!!... In Clojure, then Clojure will look for a variable called some-bus. The error you get is because it can't find such a variable. You want to

Re: about macro exception : Unable to resolve classname: LinkedList, macro question and possible better approach

2015-03-08 Thread James Reeves
On 8 March 2015 at 20:05, coco clasesparticulares...@gmail.com wrote: I don't know what the rest of your function is supposed to be doing you can check my second example I'm afraid that doesn't explain you intend your function to do. You appear to be setting up some form of message

Re: about macro exception : Unable to resolve classname: LinkedList, macro question and possible better approach

2015-03-06 Thread James Reeves
You're not using macros correctly. A macro does not evaluate its arguments, but it does evaluate its return value. The only thing a macro should do is to transform one piece of code into another. So let's look at what you want your syntax to look like: (send! (function-blah hi!)) Now

Re: about macro exception : Unable to resolve classname: LinkedList, macro question and possible better approach

2015-03-06 Thread coco
sorry for my crappy code, but I was changing some conditions and testing my parameters before and I end with this code (if (not (false? res)) res (recur)) I must write just (if res res (recur)) -- You received this message because you are subscribed to the Google

about macro exception : Unable to resolve classname: LinkedList, macro question and possible better approach

2015-03-06 Thread coco
Hi guys, first I'm really noob using macros, basically I've this (!b (function-blah hi)) Hey..I didn't know than intellij copy/paste the text with format!..cool! Ok..returning to my question...I don't need call to function-blah...I need send a message to one address possibly named

Re: macro question

2014-06-18 Thread gianluca torta
you can also use macroexpand-1 to see how your macro expands for example, having defined your macro as suggested by Gary and James above, you can write something like: (macroexpand-1 '(if-zero (- 4 2 2) (+ 1 1) (+ 2 2))) and see that it correctly to: (if (clojure.core/= (- 4 2 2) 0) (+ 1 1) (+

macro question

2014-06-16 Thread Christopher Howard
Disclosure: I'm rather fascinated with macros (the things they are supposed to allow us to do), but I'm still rather mystified about how they actually work. It seems like every time I try to write one, it rarely behaves anything like I expect. Question: Is there any obvious problems with this

Re: macro question

2014-06-16 Thread Gary Trakhman
Yes, you need to revisit the fundamentals of macros. Macros are functions that take in data (the forms), and return data (possibly altered forms). In your example, you're checking if the expression itself, a list or some kind of value or something is equal to the value 0, at compile-time, then

Re: macro question

2014-06-16 Thread James Reeves
Macros differ from functions in two ways: 1. They're executed at compile-time, rather than run-time. 2. Their arguments are unevaluated. Your if-zero function probably doesn't act the way you expect it to, because you're expecting test-expr to be evaluated. If all of the arguments to your macro

Re: macro question

2012-01-04 Thread Robert Marianski
On Tue, Jan 03, 2012 at 07:22:22PM -0800, Trevor wrote: hmmm macro question: ; here's a macro that assembles many puts. It serves no purpose to me (and doesn't even make sense in its current form). It's just something I hit playing around and learning macros. (defmacro doto-putter [x

Re: macro question

2012-01-04 Thread Trevor
macro question: ; here's a macro that assembles many puts. It serves no purpose to me (and doesn't even make sense in its current form). It's just something I hit playing around and learning macros. (defmacro doto-putter [x y xs]   `(doto (java.util.HashMap.)      (.put ~x ~y

macro question

2012-01-03 Thread Trevor
hmmm macro question: ; here's a macro that assembles many puts. It serves no purpose to me (and doesn't even make sense in its current form). It's just something I hit playing around and learning macros. (defmacro doto-putter [x y xs] `(doto (java.util.HashMap.) (.put ~x ~y

Re: macro question

2012-01-03 Thread Alan Malloy
On Jan 3, 7:22 pm, Trevor tcr1...@gmail.com wrote: hmmm macro question: ; here's a macro that assembles many puts. It serves no purpose to me (and doesn't even make sense in its current form). It's just something I hit playing around and learning macros. (defmacro doto-putter [x y xs

Quick Practical Clojure macro question

2011-10-24 Thread Alan O'Donnell
Hi everyone, I'm working my way through Practical Clojure's macro chapter, and I'd like to check my understanding about one of the examples. The book discusses writing a macro to randomly evaluate a form out of a list of forms--essentially a cond that randomly selects which branch to evaluate.

Re: Quick Practical Clojure macro question

2011-10-24 Thread Alan Malloy
Yes, definitely. Your version selects which form to evaluated once, at compile time; the original selects a form every time the expansion is evaluated. user (defn rand-num [] (rand-expr-mulit 1 2 3 4 5 6 7 8 9)) #'user/rand-num user (rand-num) 7 user (rand-num) 7 user (rand-num) 7 user (rand-num)

Macro question from a clojure newbie

2010-05-30 Thread Daniel
Hi all, I'm running into a problem where I need to define several functions and/or vars inside another function, but the function has multiple definitions and they all need to have access to the inner things. This could be solved by making private functions and using partial, but this sounds like

Re: Macro question from a clojure newbie

2010-05-30 Thread Erik Söhnel
Hi, Not really mechanisms, but two Idioms will help you with your problem: Either wrap the defn in a let: (let [U (gen-matrix [1 2 2 -2 -1 -2 2 2 3] 3 3) A (gen-matrix [1 2 2 2 1 2 2 2 3] 3 3) D (gen-matrix [-1 -2 -2 2 1 2 2 2 3] 3 3) S (gen-vector [3 4 5])] (letfn

Re: Macro question from a clojure newbie

2010-05-30 Thread Daniel
The first solution looks good. I had no idea that wrapping a defn inside of let's would leave the function exposed. Interesting. Is it considered idiomatic though? On May 30, 2:16 pm, Erik Söhnel eriksoeh...@googlemail.com wrote: Hi, Not really mechanisms, but two Idioms will help you with

Macro question

2009-01-01 Thread synphonix
Hello and happy new year, I've started this year with playing around with clojure macros and wrote a macro that behaves in a way I don't understand: (defmacro foo ([x] `(list ~x ~x)) ([x n] (if (= n 0) `(foo ~x) `(foo ~(foo x) ~(- n 1) (foo :a 0)

Re: Macro question

2009-01-01 Thread synphonix
Hello, just a follow up: I discovered that I sent the macro def twice and than applied the macro. If the first time the defmacro is evaluated then the resulting macro works as I expected. But when I send the same defmacro a second time to the interpreter, the macro behaves as described below.

Re: Macro question

2009-01-01 Thread Rich Hickey
On Jan 1, 2009, at 5:45 AM, synphonix wrote: Hello and happy new year, I've started this year with playing around with clojure macros and wrote a macro that behaves in a way I don't understand: (defmacro foo ([x] `(list ~x ~x)) ([x n] (if (= n 0) `(foo ~x)

Re: Macro question

2009-01-01 Thread synphonix
Thanks a lot. This year starts well (I learned something :-) Regards Poul --~--~-~--~~~---~--~~ 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 To unsubscribe

Re: a macro question, this time completely specified :-)

2008-11-09 Thread Meikel Brandmeyer
Hi, Am 09.11.2008 um 12:23 schrieb Stuart Halloway: Just to make things even more fun: *None* of the proposed fixes to the concurrency bug in the original actually preserve the` semantics of the original. All have moved from run (usually) once, mark as done to mark as done, try once. This also

Re: a macro question, this time completely specified :-)

2008-11-09 Thread Stuart Halloway
You should be able to do this without the ref. Have the agent's state contain a pair of [has-run, fn-result]. Stuart Hi, Am 09.11.2008 um 12:23 schrieb Stuart Halloway: Just to make things even more fun: *None* of the proposed fixes to the concurrency bug in the original actually

Re: a macro question, this time completely specified :-)

2008-11-09 Thread Rich Hickey
On Nov 9, 8:21 am, Stuart Halloway [EMAIL PROTECTED] wrote: You should be able to do this without the ref. Have the agent's state contain a pair of [has-run, fn-result]. The semantics of your runonce aren't clear to me, but here are some strategies: As Chouser proposed, if you only want a

Re: a macro question, this time completely specified :-)

2008-11-09 Thread Stuart Halloway
Hi Rich, Wow, that's a comprehensive answer. Thanks. I am using runonce to create lancet, a build system that ties into Java's Ant. Build steps definitely do have side effects, so I will probably end up using the agent approach. Targets don't have (or ignore) return values, so I could

a macro question, this time completely specified :-)

2008-11-08 Thread Stuart Halloway
The defrunonce macro below works, creating a function that runs only once and tracking its run status in metadata. Now, how do I write it without using eval? (defn runonce Create a function that will only run once, given a function. Returns a vector containing the function and the

Re: a macro question, this time completely specified :-)

2008-11-08 Thread Chouser
On Sat, Nov 8, 2008 at 10:23 PM, Stuart Halloway [EMAIL PROTECTED] wrote: How about: (defn runonce Create a function that will only run its argument once. [function] (let [call-count (ref 0)] (fn [ args] (when (= 1 (dosync (alter call-count inc))) (apply function

Re: a macro question, this time completely specified :-)

2008-11-08 Thread Stephen C. Gilardi
On Nov 8, 2008, at 10:23 PM, Stuart Halloway wrote: How about: (defn runonce Create a function that will only run its argument once. [function] (let [call-count (ref 0)] (fn [ args] (when (= 1 (dosync (alter call-count inc))) (apply function args) The

Re: a macro question, this time completely specified :-)

2008-11-08 Thread Stuart Halloway
How about: (defn runonce Create a function that will only run its argument once. [function] (let [call-count (ref 0)] (fn [ args] (when (= 1 (dosync (alter call-count inc))) (apply function args) On Nov 8, 2008, at 8:31 PM, Stuart Halloway wrote: The

Re: a macro question, this time completely specified :-)

2008-11-08 Thread Chouser
On Sat, Nov 8, 2008 at 8:31 PM, Stuart Halloway [EMAIL PROTECTED] wrote: (defmacro defrunonce [sym doc forms] Defines a function with runonce semantics. Curren run status is kept in a reference under the :has-run metadata key. (let [[function has-run] (runonce (eval (concat (list 'fn

Re: a macro question, this time completely specified :-)

2008-11-08 Thread Stephen C. Gilardi
On Nov 8, 2008, at 8:31 PM, Stuart Halloway wrote: The defrunonce macro below works, creating a function that runs only once and tracking its run status in metadata. Now, how do I write it without using eval? (defn runonce Create a function that will only run once, given a function.