Re: Macro help/strategy for writing a tiny DSL for circuit-model quantum computing?

2019-05-16 Thread Vic Putz
Alex-- The reason I'm starting with macros is that they're the high-risk/less-understood part of this; the rest is more or less straightforward, so I want to get a vertical slice working as soon as possible and expand from there. 1. Start with data - what are the entities (bits? gates?), and

Re: Macro help/strategy for writing a tiny DSL for circuit-model quantum computing?

2019-05-15 Thread Alex Miller
My general advice would be not to start with macros. 1. Start with data - what are the entities (bits? gates?), and how do you represent them? It's ok (actually better) for these to be verbose. Plan for extension (maps are open, which is why they're so common in representing data in Clojure).

Macro help/strategy for writing a tiny DSL for circuit-model quantum computing?

2019-05-15 Thread Vic Putz
...which sounds a LOT more complex than it is. I don't care about simulation--there are great Python-based packages for that. I don't even care about verification or optimization yet; I just want to generate a data structure that's exportable in, say, EDN that I can write a parser for in

Re: macro help

2015-10-02 Thread Colin Yates
I’m kicking myself as I have exactly that book but it got lost in the ‘TODO’ pile. > On 2 Oct 2015, at 13:31, Jason Stewart wrote: > > "Mastering Clojure Macros" by Colin Jones gets my vote as the go to book for > writing clojure macros. > > > On Fri, Oct 2, 2015 at

Re: macro help

2015-10-02 Thread Thomas Heller
Well, if you don't like that 'form' you could use a binding. (binding [form/*state* {:editing? true :values form-values :validation validation-report :on-change handle-form-change}] (form/tag (form/text :name) (form/number :age))) Anyways,

Re: macro help

2015-10-02 Thread Colin Yates
Hi Thomas, binding - really? :-). Apart from the general negative reaction they seem to have, I don’t want the individual elements (e.g. text and number) to assume rely on the binding as they can be called individually as well and the binding would just get in the way. My understanding is that

Re: macro help

2015-10-02 Thread Colin Yates
Hi Thomas - yes, you are right. The example I provided is all pain/no-gain in terms of macros. However, future plans will require manipulating the invocation of (for example form/text and form/number) before they are evaluated. Having said all of that, that repeated ‘form’ does bug me a bit

Re: macro help

2015-10-02 Thread Thomas Heller
Have you tried NOT using a macro at all? This code does not need to be a macro at all if you ask me. Just a little sketch but things could look just about the same without any macros at all: (let [form {:editing? true :values form-values :validation validation-report

Re: macro help

2015-10-02 Thread Colin Yates
Thanks for your comments - very helpful! The reference to destructuring might be irrelevant now. Previously I noticed that the _map construction_ was emitted from the macro rather than the symbol bound to the map. For example, some variation of quoting meant (defmacro a [m] (println m)) called

Re: macro help

2015-10-02 Thread gianluca torta
Hi Colin, as far as I can tell, your solution looks fine... here are a couple of comments on your step-by-step analysis cheers, Gianluca 1(defmacro form [state & elements] > 2 (let [m-state (gensym)] > 3`(let [~m-state ~state] > 4 [:div.form.horizontal > 5~@(map (fn [[f m &

Re: macro help

2015-10-02 Thread Jason Stewart
"Mastering Clojure Macros" by Colin Jones gets my vote as the go to book for writing clojure macros. On Fri, Oct 2, 2015 at 8:24 AM, Colin Yates wrote: > Thanks for your comments - very helpful! > > The reference to destructuring might be irrelevant now. Previously I >

Re: macro help

2015-10-02 Thread Thomas Heller
Well, yeah .. don't use binding. Sometimes they are a good solution though, so don't forget about it. Again I do not know your future plans. I would always recommend writing everything with data+functions first. If you find that you have written the same thing over and over again it might be

Re: macro help

2015-10-02 Thread Colin Yates
This is my first venture into macros since starting with Clojure a bunch of years ago - no urge here. I also use binding for a use-case I haven’t seen any other solution for; an implementation of a protocol which doesn’t take a tx as a parameter but wants to participate in a tx. Binding is a

Re: macro help

2015-09-30 Thread Michael Blume
#foo gensyms don't survive across a 'break' in quoting you can do `(let [foo# bar] (other stuff (foo# ...))) but you can not do `(let [foo# bar] ~(for [i s] `(foo# ...))) or anything like that. The workaround is to create a gensym explicitly using (gensym), let that, and

macro help

2015-09-30 Thread Colin Yates
Hi all, I am banging my head against the wall - I think it is obvious but I have started too long: The use-case is that I want a form which takes a set of children. The form also takes in some form-wide state, like the form-wide validation, the values for each item etc. I want the macro, for

Macro Help with Symbols and Evaluation

2015-03-19 Thread Mark Bastian
Hi All, I am trying to write a simple macro to resolve local symbols and I just can't seem to figure out the right invocation. Here are some commands you can type/paste in a repl: (def ONE 1) ;define one (def s1 (symbol ONE)) ;get the symbol (eval s1) ;evaluates to 1, no surprise ;My goal is

Re: Macro Help with Symbols and Evaluation

2015-03-19 Thread Colin Yates
I don't have the answer (as I too am in the still-going-blind phase) but the following might help: - deref symbols to get their value - http://learnxinyminutes.com/docs/clojure-macros/ (short and very helpful) - http://www.braveclojure.com/writing-macros/ (long and very helpful) -

Re: Macro Help with Symbols and Evaluation

2015-03-19 Thread Ambrose Bonnaire-Sergeant
What problem are you trying to solve? On Thu, Mar 19, 2015 at 12:49 PM, Mark Bastian markbast...@gmail.com wrote: Hi All, I am trying to write a simple macro to resolve local symbols and I just can't seem to figure out the right invocation. Here are some commands you can type/paste in a

Re: Macro Help with Symbols and Evaluation

2015-03-19 Thread Mark Bastian
To provide a little more context, the problem I am trying to solve is this: Often in Java I see constructors that have a pattern of (ClassName. X) where X is some static integer value. For example, in Swing you build a Box like so (Box. BoxLayout/X_AXIS). I want to simplify this by doing

Re: Macro Help with Symbols and Evaluation

2015-03-19 Thread Ambrose Bonnaire-Sergeant
If there are a unknown number of layouts you can just define a map from keywords to layouts: {:x_axis BoxLayout/x_axis ..} Otherwise using java reflection is another option. Thanks, Ambrose On Thu, Mar 19, 2015 at 4:34 PM, Mark Bastian markbast...@gmail.com wrote: To provide a little more

Re: Macro help

2010-11-08 Thread Sunil S Nandihalli
Hi Miki, Just to elaborate on what I said before, session# creates a new symbol using gensym with a prefix session. It avoids accidental variable capture. Sunil. On Mon, Nov 8, 2010 at 8:40 PM, Sunil S Nandihalli sunil.nandiha...@gmail.com wrote: use session# instead of session .. I think

Re: Macro help

2010-11-08 Thread Alan
This. Macros, unless you do some gymnastics, always generate fully- qualified names, which is a Good Thing. You can't bind qnames, in let or function arguments or anywhere else. But clojure provides you with a very useful var# syntax: this creates a new symbol which is guaranteed to be unique, and

Re: Macro help

2010-11-08 Thread Miki
As in the below (which doesn't work). (defmacro def-dispatcher-test [test-name state command body] `(deftest ~test-name (let [session (test-session ~state)] (dispatcher ~command session) ~...@body))) (def-dispatcher-test user-test :authorization USER bugs (is (= (:user

Re: Macro help

2010-11-08 Thread Laurent PETIT
Hi, session will be fully qualified. this is the default behavior. If you really want it, then you can treat it as the result of the unquoting of a value which resolves to a symbol. So you'll use ~ to say you want the value of (quote session) (quote session returns the symbol session when

Re: Macro help

2010-11-08 Thread Ken Wesson
On Mon, Nov 8, 2010 at 2:01 PM, Laurent PETIT laurent.pe...@gmail.com wrote: Hi, session will be fully qualified. this is the default behavior. If you really want it, then you can treat it as the result of the unquoting of a value which resolves to a symbol. So you'll use ~ to say you want

Re: Macro help

2010-11-08 Thread Miki
Great, that did it. Thanks. On Nov 8, 11:01 am, Laurent PETIT laurent.pe...@gmail.com wrote: Hi, session will be fully qualified. this is the default behavior. If you really want it, then you can treat it as the result of the unquoting of a value which resolves to a symbol. So you'll use ~

Re: Macro help

2010-11-08 Thread Miki
that is, use ~'session instead of just session. What you really want in this case is a binding. Try this: ... The added parameter just before the body specifies a name to bind the session object to; this name can then be used in the body. This is good a well, but I prefer to dark magic

Re: Macro help

2010-11-08 Thread Alan
Yes, those are the two choices. Ken's suggestion is the cleanest, and you definitely should do that in cases where it's not burdensome. Here, where it's a macro for private testing, and you are certain not to forget that it's magically binding session for you, then go ahead and use Laurent's

Re: Macro help

2010-11-08 Thread Laurent PETIT
2010/11/8 Alan a...@malloys.org Yes, those are the two choices. Ken's suggestion is the cleanest, and you definitely should do that in cases where it's not burdensome. Here, where it's a macro for private testing, and you are certain not to forget that it's magically binding session for you,

Re: Macro help

2010-11-08 Thread Alan
Yeah, I know you wouldn't make such a dreadful recommendation without prompting. I just want to make sure *he* knows that this is considered a little smelly: Clojure gives you the power to do stuff like this, and it's appropriate to use it sometimes, but you should be careful - it's hard for a

Re: Macro help

2010-11-08 Thread Miki
I just want to make sure *he* knows that this is considered a little smelly: Clojure gives you the power to do stuff like this, and it's appropriate to use it sometimes, but you should be careful - it's hard for a reason. I know it smells, and regularly I won't use such a thing (didn't like

Re: macro help

2010-05-10 Thread RandyHudson
As Lauren Petit points out, you need the macro to define the whole desired result. Something like this should do it: (defmacro defautoroutes [name paths] (let [getps (for [p paths] `(GET ~(str / p) (foo ~p)))] `(defroutes ~name ~...@getps))) (defautoroutes all-routes one two three) On

Re: macro help

2010-05-10 Thread James Reeves
On 7 May 2010 03:21, Micah Martin micahmar...@gmail.com wrote: I'm having trouble writing a macro and I hoping some one here can help.  My desired result is the following: (defroutes all-routes  (GET /one   (foo one))  (GET /two   (foo two))  (GET /three (foo three))) But I'd like to

macro help

2010-05-07 Thread Micah Martin
Hey all, I'm having trouble writing a macro and I hoping some one here can help. My desired result is the following: (defroutes all-routes (GET /one (foo one)) (GET /two (foo two)) (GET /three (foo three))) But I'd like to write it like so: (defroutes all-routes (make-foos one

Re: macro help

2010-05-07 Thread Laurent PETIT
Hello, Maybe defroutes is not the right building-block to build upon if you want to make things more supple for you. Look up the building blocks defroutes is built upon,and if they are part of the public API, then maybe it's better (and easier) to build on them. And note that a macro can only

Re: Minor macro help

2009-08-04 Thread John Harrop
Very clever, Meikel. --~--~-~--~~~---~--~~ 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 patient with

Re: Minor macro help

2009-08-03 Thread CuppoJava
You can use eval to retrieve the value of a-map when the macro is expanded. (let [value (eval a-map)] `(binding ~(vec (process-a-map value)) ~...@forms)) I've programmed some substantial programs now in Clojure though, and I've never had to use this. Perhaps there is another way to achieve

Re: Minor macro help

2009-08-03 Thread John Harrop
On Mon, Aug 3, 2009 at 5:43 PM, samppi rbysam...@gmail.com wrote: I'm getting stuck because a-map always gets passed into my-macro as a symbol. (defmacro my-macro [a-map forms] ; Naive implementation `(binding ~(vec (process-a-map a-map)) ~...@forms)) Try (defmacro my-macro [a-map

Re: Minor macro help

2009-08-03 Thread John Harrop
On Mon, Aug 3, 2009 at 8:01 PM, CuppoJava patrickli_2...@hotmail.comwrote: You can use eval to retrieve the value of a-map when the macro is expanded. (let [value (eval a-map)] `(binding ~(vec (process-a-map value)) ~...@forms)) I've programmed some substantial programs now in Clojure

macro help

2009-01-27 Thread .Bill Smith
I'm trying to write a helper macro for invoking a class's main. Here's the macro: (defmacro main [class args] #^{:doc Invoke class's main with specified arguments, which are automatically stringified} (if (= (count args) 0) `(. ~class main (make-array String 0)) `(. ~class main

Re: macro help

2009-01-27 Thread Christophe Grand
.Bill Smith a écrit : To take the extra Java class out of the loop, I wrote this second macro: user= (defmacro s [ args] `(java.util.Arrays/asList (into-array (map str '~args #'user/s user= (let [c value of c] (s 1 c)) #ArrayList [1, c] user= (macroexpand-1 '(s 1 c))

Re: macro help

2008-12-27 Thread Christophe Grand
what-a-guy a écrit : (defmacro dlg [dlgid# fields#] `(fn [parent# layout#] ~@(map (fn [[f# id# text# type#]] `(fld parent# layout# '~id# ~text# ~type#)) fields#))) (def inp '(dlg test (field fld-1 Field number one (JTextField.))

macro help

2008-12-26 Thread what-a-guy
I'm attempting what should be a simple transformation using a macro called dlg in the following code: (defn fld [parent lay id text field] '...) ;; dlg macro. For this input: ;; ;; (dlg test ;; (field fld-1 Field number one (JTextField.)) ;; (field fld-2 Field number two (JTextField.))) ;;