Re: Applying Java functions
Hi, user> (definline sqrt [x] `(Math/sqrt ~x)) #'user/sqrt user> (map sqrt (range 1 10)) (1.0 1.4142135623730951 1.7320508075688772 2.0 2.23606797749979 2.449489742783178 2.6457513110645907 2.8284271247461903 3.0) -- http://www.nostdal.org/ -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Allow Data Structure to Be Called as Function
Is it possible to use this approach to create a callable record which can take a variable number of arguments? I can't get the following to work: (defrecord Foo [a] clojure.lang.IFn (invoke [this & args] (println (str a args (def yo (Foo. "sam")) (yo 1 2 3 4) ;=> sc-one.Foo.invoke(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; [Thrown class java.lang.AbstractMethodError] Sam --- http://sam.aaron.name On 15 Jun 2011, at 20:57, Ken Wesson wrote: > On Wed, Jun 15, 2011 at 3:53 PM, RJ Nowling wrote: >> Hi, >> >> I'm sorry if this has been asked before, but I would like to know how >> to create data structures in Clojure that can be used in the same way >> as the built-in data structures. For example, I can access the >> elements of a vector by (my-vec 1). How can I implement this >> interface when creating a data structure in Clojure? > > (defrecord Foo [...] > ... > IFn > (invoke [this] (do-this-on-zero-argument-call)) > (invoke [this x] (do-when-called-with-x)) > (invoke [this x y] (+ x y))) > > => ((Foo.) 33 9) > 42 > => > > -- > Protege: What is this seething mass of parentheses?! > Master: Your father's Lisp REPL. This is the language of a true > hacker. Not as clumsy or random as C++; a language for a more > civilized age. > > -- > 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 your > first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Why should I use emacs instead of netbeans?
Hello all. I'm currently using Netbeans' clojure IDE and I quite like it. It has a REPL. It highlights syntax and matches parentheses. It supports maven and mercurial/git. It provides completion and doc for both clojure and java. It has allows evaluation of forms from source code to repl. It also allows me to customize keyboard shortcuts. The other option that I've seen being popular is emacs with cake. I've seen that cake opens two jvms, one for itself and one for project, ok, nevermind that, no big deal, but emacs, i find, is unnecessarily arcane compared to a modern java IDE. It's keyboard shortcuts and combinations are based on ancient keyboards and terminals and historical conventions, and while i can customize that and only use what I need, netbeans already has a comfortable, modern setup out of the box. I see that some would suggest paredit, but honestly, i don't see that, navigating code through keyboard shortcuts, as all that much of an advantage considering that using the mouse or the trackpad is very convenient. What am I missing out on? Thanks. -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: What's the best way to test private functions?
>>(defn refer-private [ns] >> (doseq [[symbol var] (ns-interns ns)] >>(when (:private (meta var)) >> (intern *ns* symbol var >> >> As he says, "this is slightly evil, and I would never recommend it for >> any purpose except unit testing, but there it is." This works, and the >> macro approach also makes sense to me. > > I use it, too. > >> But these threads are respectively three and two years old. Have there >> been any changes in Clojure since then which solve this problem or >> provide a recommended workaround? > > Not that I know of. To access a private var, simply deref through the var: @#'some-ns/some-private-var This is in the coding standards doc (http://dev.clojure.org/display/design/Library+Coding+Standards). The doc is pretty short and worth reading if you haven't. Stu Stuart Halloway Clojure/core http://clojure.com -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Allow Data Structure to Be Called as Function
On Sat, Jun 18, 2011 at 4:44 AM, Sam Aaron wrote: > Is it possible to use this approach to create a callable record which can > take a variable number of arguments? > > I can't get the following to work: > > (defrecord Foo [a] > clojure.lang.IFn > (invoke [this & args] (println (str a args > > (def yo (Foo. "sam")) > > (yo 1 2 3 4) ;=> > sc-one.Foo.invoke(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; > [Thrown class java.lang.AbstractMethodError] Not easily. You may be able to override applyTo to get that to work. Alternatively, you can work around it by using destructuring and an extra vector around the args: (defrecord Foo [a] clojure.lang.IFn (invoke [this [& args]] (println (str a args (def yo (Foo. "sam")) (yo [1 2 3 4]) A bit ugly, but it should work. -- Protege: What is this seething mass of parentheses?! Master: Your father's Lisp REPL. This is the language of a true hacker. Not as clumsy or random as C++; a language for a more civilized age. -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Why should I use emacs instead of netbeans?
On Sat, Jun 18, 2011 at 7:07 AM, James Keats wrote: > Hello all. > > I'm currently using Netbeans' clojure IDE and I quite like it. It has > a REPL. It highlights syntax and matches parentheses. It supports > maven and mercurial/git. It provides completion and doc for both > clojure and java. It has allows evaluation of forms from source code > to repl. It also allows me to customize keyboard shortcuts. > > The other option that I've seen being popular is emacs with cake. I've > seen that cake opens two jvms, one for itself and one for project, ok, > nevermind that, no big deal, but emacs, i find, is unnecessarily > arcane compared to a modern java IDE. It's keyboard shortcuts and > combinations are based on ancient keyboards and terminals and > historical conventions, and while i can customize that and only use > what I need, netbeans already has a comfortable, modern setup out of > the box. I see that some would suggest paredit, but honestly, i don't > see that, navigating code through keyboard shortcuts, as all that much > of an advantage considering that using the mouse or the trackpad is > very convenient. > > What am I missing out on? By not using emacs? IMO, not much. Not even paredit, since it's available in CCW (the Eclipse Clojure plug-in) if you want it badly enough. (With emacs-ish keyboard navigation bindings, natch. But you'd be able to copy, paste, save files, etc. "the normal way" with CCW, without any time spent rebinding dozens of keys first, and you'd be able to navigate both the normal way AND the paredit way. Best of both worlds?) -- Protege: What is this seething mass of parentheses?! Master: Your father's Lisp REPL. This is the language of a true hacker. Not as clumsy or random as C++; a language for a more civilized age. -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: What's the best way to test private functions?
On Sat, Jun 18, 2011 at 7:16 AM, Stuart Halloway wrote: > To access a private var, simply deref through the var: > @#'some-ns/some-private-var > This is in the coding standards doc > (http://dev.clojure.org/display/design/Library+Coding+Standards). The doc is > pretty short and worth reading if you haven't. That's a bit awkward to manually type in e.g. tests. On the other hand it's very useful if you want a macro to emit a call to a function but don't feel that function should be public. In that case it only has to be typed the once, in the macro definition. -- Protege: What is this seething mass of parentheses?! Master: Your father's Lisp REPL. This is the language of a true hacker. Not as clumsy or random as C++; a language for a more civilized age. -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Why should I use emacs instead of netbeans?
Never used Cake, but Lein works great. Emacs is all about customization - something bothers you? Just change it The standard keybindings are extremely bad, change them. I use this one: http://xahlee.org/emacs/ergonomic_emacs_keybinding.html Just ignore the controversy around the guy, the bindings are well reasoned. If you are going to use Emacs you must learn the keybindings, else a standard ide is a better choice. When writing code you are spending a surprising amount of time on navigation and copy/paste. It's well worth it in the end and your mouse arm will thank you. 2011/6/18 James Keats > Hello all. > > I'm currently using Netbeans' clojure IDE and I quite like it. It has > a REPL. It highlights syntax and matches parentheses. It supports > maven and mercurial/git. It provides completion and doc for both > clojure and java. It has allows evaluation of forms from source code > to repl. It also allows me to customize keyboard shortcuts. > > The other option that I've seen being popular is emacs with cake. I've > seen that cake opens two jvms, one for itself and one for project, ok, > nevermind that, no big deal, but emacs, i find, is unnecessarily > arcane compared to a modern java IDE. It's keyboard shortcuts and > combinations are based on ancient keyboards and terminals and > historical conventions, and while i can customize that and only use > what I need, netbeans already has a comfortable, modern setup out of > the box. I see that some would suggest paredit, but honestly, i don't > see that, navigating code through keyboard shortcuts, as all that much > of an advantage considering that using the mouse or the trackpad is > very convenient. > > What am I missing out on? Thanks. > > -- > 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 > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Why should I use emacs instead of netbeans?
James Keats writes: Hi James, > I'm currently using Netbeans' clojure IDE and I quite like it. So why are you bothering to use something else? > but emacs, i find, is unnecessarily arcane compared to a modern java > IDE. It's keyboard shortcuts and combinations are based on ancient > keyboards and terminals and historical conventions, and while i can > customize that and only use what I need, netbeans already has a > comfortable, modern setup out of the box. Once you are used to it, you cannot believe how anyone can get work done with these "modern" (aka windows-like, mouse-driven, inextensible) user interfaces. Emacs has an extremely high usability factor, but it requires some time to become acquainted with it. What I totally miss in any "modern" application is emacs' ability to describe itself. `C-h k ' explains exactly what the shortcut does, `C-h k ' explains in details what a mouse click on some text, button, or menu item does, `C-h b' shows you all currently applicable shortcuts, and I could go on and on. In contrast, "modern" UIs have at best some tooltip that might give a hint on keywords you can use to search the documentation, if there's any... > I see that some would suggest paredit, but honestly, i don't see that, > navigating code through keyboard shortcuts, Paredit it about editing on syntactic units (which are lists in lisp) instead of only characters, words, and lines. That it also offers good navigation is only a side-effect. > as all that much of an advantage considering that using the mouse or > the trackpad is very convenient. Hey, now I know two guys that really think a trackpad is convenient. ;-) Bye, Tassilo -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Detailed Macro Quoting Question
Hi Clojure Gurus :) I've a somewhat contrived use-case for macros that I've been struggling with. Let's say there's an interface called EWrapper that I'm trying to implement with methods "tickPrice" and "tickSize", a concrete class EWrapperMsgGenerator that has methods with those names that return strings. I'd like to write a macro that proxies EWrapper's tickSize and tickPrice methods so that they print out the method name as well as the string returned from EWrapperMsgGenerator. E.g. (in java code): public tickSize( args ) { // on the proxied EWrapper System.out.println( "tickSize: " + EWrapperMsgGenerator.tickSize( args ) ) } Here's what I've come up with so far: (defmacro make-msg-ewrapper [method-names] `(proxy [EWrapper] [] ~@(map (fn [method-name] `(~(symbol method-name) [& args#] (println ~method-name ":" (. EWrapperMsgGenerator ~(symbol method-name) args# method-names))) It's a bit messy -- I'm splicing in a map evaluation into proxy, and then writing in symbols in the function body. This works except that when I run the macro I get "No matching method: tickSize" referring to EWrapperMsgGenerator. The macro expansion looks like: (let* [p__4736__auto__ (new user.proxy$java.lang.Object$EWrapper $11bc5609)] (clojure.core/init-proxy p__4736__auto__ {tickPrice (clojure.core/fn ([this & args__2058__auto__] (clojure.core/println tickPrice : (. com.ib.client.EWrapperMsgGenerator tickPrice args__2058__auto__, list (clojure.core/fn ([this & args__2058__auto__] (clojure.core/println list : (. com.ib.client.EWrapperMsgGenerator list args__2058__auto__}) p__4736__auto__) So far this looks fine to me, except that tickPrice within the EWrapperMsgGenerator call isn't scoped. Is there a better way to do this? Thanks, Jian -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Why should I use emacs instead of netbeans?
James, For working with Clojure, if you are happy with Netbeans, use it. Especially if you are relatively new to Clojure, switching to Emacs won't do groundbreaking changes to your productivity in the short term. As you become more and more savvy with Lisp, Emacs will have more and more to offer you. However, your assumption that Emacs is "archaic" is wrong. Emacs is very mature and battle tested. Emacs is fully programmable, with very efficient shortcuts, a lot more features than you can imagine (especially for functional programming languages) and it simply has a lot less noise in the UI. It has most of the features people attribute to "modern Java IDEs" out of the box (Etags alone provide 80% of those features Eclipse users love to cite), newcomers just don't know about them because they have weird names for historical reasons or work slightly differently (again etags is a good example). But again, If you are happy with Netbeans or IntelliJ IDEA, don't worry about Emacs too much and ignore Emacs zealots. I can imagine that as time goes by and polyglot programming on the JVM becomes more and more widespread, IDEs like IDEA will offer cross-language intergration features Emacs won't match, at least without sophisticated extensions. 2011/6/18 James Keats > Hello all. > > I'm currently using Netbeans' clojure IDE and I quite like it. It has > a REPL. It highlights syntax and matches parentheses. It supports > maven and mercurial/git. It provides completion and doc for both > clojure and java. It has allows evaluation of forms from source code > to repl. It also allows me to customize keyboard shortcuts. > > The other option that I've seen being popular is emacs with cake. I've > seen that cake opens two jvms, one for itself and one for project, ok, > nevermind that, no big deal, but emacs, i find, is unnecessarily > arcane compared to a modern java IDE. It's keyboard shortcuts and > combinations are based on ancient keyboards and terminals and > historical conventions, and while i can customize that and only use > what I need, netbeans already has a comfortable, modern setup out of > the box. I see that some would suggest paredit, but honestly, i don't > see that, navigating code through keyboard shortcuts, as all that much > of an advantage considering that using the mouse or the trackpad is > very convenient. > > What am I missing out on? Thanks. > -- MK -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Help organizing code and namespaces
Hi, I have 3 namespaces, each with functions that relate to the name of the ns: core -- contains config and *server* var query -- contains fn's related to querying update -- contains update/delete fn's I want to be able to "use" my core ns in my application, and call all of the public fn's in core, query and update without going through the query and update ns aliases. This would be as simple as specifying "use" in the core ns when defining the namespace. The problem is that the query and update ns's need to access a var called *server* in the core ns. The *server* var is set using binding like so: (use 'my.core) (with-server :whatever-sever-name (delete-by-id "xyz")) delete-by-id is an fn in the update namespace, and looks something like: (defn delete-by-id [id] (*server*/delete-by-id id)) The problem is *server* belongs to core, so that doesn't work. If I pull in core to the update ns, I get a circular reference error. My question is, how can I keep my code separated as it is, but have it so I use core, and automatically bring all the fn's in to the same scope, all while sharing the core/*server* var? I could easily push all the fn's in the same ns, but that seems messy. Thanks, Matt -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Allow Data Structure to Be Called as Function
On Sat, Jun 18, 2011 at 4:44 AM, Sam Aaron wrote: > Is it possible to use this approach to create a callable record which can > take a variable number of arguments? > > I can't get the following to work: > > (defrecord Foo [a] > clojure.lang.IFn > (invoke [this & args] (println (str a args > > (def yo (Foo. "sam")) > > (yo 1 2 3 4) ;=> > sc-one.Foo.invoke(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; > [Thrown class java.lang.AbstractMethodError] > > Sam > defrecord/type methods don't support rest args. David -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Detailed Macro Quoting Question
On Fri, Jun 17, 2011 at 11:51 PM, Jian Liu wrote: > Hi Clojure Gurus :) > > I've a somewhat contrived use-case for macros that I've been > struggling with. > > Let's say there's an interface called EWrapper that I'm trying to > implement with methods "tickPrice" and "tickSize", a concrete class > EWrapperMsgGenerator that has methods with those names that return > strings. > > I'd like to write a macro that proxies EWrapper's tickSize and > tickPrice methods so that they print out the method name as well as > the string returned from EWrapperMsgGenerator. > > E.g. (in java code): > public tickSize( args ) { // on the proxied EWrapper > System.out.println( "tickSize: " + > EWrapperMsgGenerator.tickSize( args ) ) > } > > Here's what I've come up with so far: > > (defmacro make-msg-ewrapper [method-names] > `(proxy [EWrapper] [] >~@(map > (fn [method-name] > `(~(symbol method-name) [& args#] > (println ~method-name ":" >(. EWrapperMsgGenerator ~(symbol method-name) > args# > method-names))) > > It's a bit messy -- I'm splicing in a map evaluation into proxy, and > then writing in symbols in the function body. This works except that > when I run the macro I get "No matching method: tickSize" referring to > EWrapperMsgGenerator. > > The macro expansion looks like: > > (let* [p__4736__auto__ (new user.proxy$java.lang.Object$EWrapper > $11bc5609)] (clojure.core/init-proxy p__4736__auto__ {tickPrice > (clojure.core/fn ([this & args__2058__auto__] (clojure.core/println > tickPrice : (. com.ib.client.EWrapperMsgGenerator tickPrice > args__2058__auto__, list (clojure.core/fn ([this & > args__2058__auto__] (clojure.core/println list : (. > com.ib.client.EWrapperMsgGenerator list args__2058__auto__}) > p__4736__auto__) > > So far this looks fine to me, except that tickPrice within the > EWrapperMsgGenerator call isn't scoped. Is there a better way to do > this? > > Thanks, > Jian > Do you have a working version of the code you want that doesn't involve a macro? David -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Why should I use emacs instead of netbeans?
Hi, these modern IDEs really do a tremendous job at organizing projects and providing additional information at programming time. It's just, their text-editor components suck. If you are a Java developer, it's probably better to stay away from Emacs. Should you ever get used to it, you're doomed to never be able to use something else, and Emacs is not particularly good at Java programming. That being said, I had my best times in front of the computer with Emacs/SLIME and Emacs/AUCTeX. ;-) Cheers, Stefan -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Detailed Macro Quoting Question
Hi David, Yes, the expansion I essentially want, and which runs properly without the macro: (proxy [EWrapper] [] (tickPrice [& args] (println "tickPrice" (. EWrapperMsgGenerator tickPrice args))) (tickSize [& args] (println "tickSize" (. EWrapperMsgGenerator tickSize args))) ... other methods ) I resorted to a macro because there are 20-30 different methods, and if I wanted to write boilerplate all day I'd just do it in pure Java :) I'm sure there are other approaches like using reflection, or pulling out the inner (println ...) form into another macro, but this pretty well-defined. Thanks, Jian On Jun 18, 10:52 am, David Nolen wrote: > On Fri, Jun 17, 2011 at 11:51 PM, Jian Liu wrote: > > Hi Clojure Gurus :) > > > I've a somewhat contrived use-case for macros that I've been > > struggling with. > > > Let's say there's an interface called EWrapper that I'm trying to > > implement with methods "tickPrice" and "tickSize", a concrete class > > EWrapperMsgGenerator that has methods with those names that return > > strings. > > > I'd like to write a macro that proxies EWrapper's tickSize and > > tickPrice methods so that they print out the method name as well as > > the string returned from EWrapperMsgGenerator. > > > E.g. (in java code): > > public tickSize( args ) { // on the proxied EWrapper > > System.out.println( "tickSize: " + > > EWrapperMsgGenerator.tickSize( args ) ) > > } > > > Here's what I've come up with so far: > > > (defmacro make-msg-ewrapper [method-names] > > `(proxy [EWrapper] [] > > ~@(map > > (fn [method-name] > > `(~(symbol method-name) [& args#] > > (println ~method-name ":" > > (. EWrapperMsgGenerator ~(symbol method-name) > > args# > > method-names))) > > > It's a bit messy -- I'm splicing in a map evaluation into proxy, and > > then writing in symbols in the function body. This works except that > > when I run the macro I get "No matching method: tickSize" referring to > > EWrapperMsgGenerator. > > > The macro expansion looks like: > > > (let* [p__4736__auto__ (new user.proxy$java.lang.Object$EWrapper > > $11bc5609)] (clojure.core/init-proxy p__4736__auto__ {tickPrice > > (clojure.core/fn ([this & args__2058__auto__] (clojure.core/println > > tickPrice : (. com.ib.client.EWrapperMsgGenerator tickPrice > > args__2058__auto__, list (clojure.core/fn ([this & > > args__2058__auto__] (clojure.core/println list : (. > > com.ib.client.EWrapperMsgGenerator list args__2058__auto__}) > > p__4736__auto__) > > > So far this looks fine to me, except that tickPrice within the > > EWrapperMsgGenerator call isn't scoped. Is there a better way to do > > this? > > > Thanks, > > Jian > > Do you have a working version of the code you want that doesn't involve a > macro? > > David -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Detailed Macro Quoting Question
So I realized that the method wasn't being found because args# is a single argument, and I actually need it spliced in. At this point I'm rather stuck. For example: (defmacro make-msg-ewrapper [method-names] `(proxy [EWrapper] [] ~@(map (fn [method-name] (let [args (gensym "args")] `(~(symbol method-name) [& args#] (println ~method-name ":" (. EWrapperMsgGenerator ~(symbol method-name)) ~@args# method-names))) This doesn't work because args needs to be delayed until runtime rather than macro-expand time. Would memfn work? E.g. something like (apply (memfn tickPrice) EWrapperMsgGenerator args)? Or does that only work for instance methods (EWrapperMsgGenerator is static). On Jun 18, 11:45 am, Jian Liu wrote: > Hi David, > > Yes, the expansion I essentially want, and which runs properly without > the macro: > > (proxy [EWrapper] [] > (tickPrice [& args] (println "tickPrice" (. EWrapperMsgGenerator > tickPrice args))) > (tickSize [& args] (println "tickSize" (. EWrapperMsgGenerator > tickSize args))) > ... other methods > ) > > I resorted to a macro because there are 20-30 different methods, and > if I wanted to write boilerplate all day I'd just do it in pure > Java :) > > I'm sure there are other approaches like using reflection, or pulling > out the inner (println ...) form into another macro, but this pretty > well-defined. > > Thanks, > Jian > > On Jun 18, 10:52 am, David Nolen wrote: > > > > > > > > > On Fri, Jun 17, 2011 at 11:51 PM, Jian Liu wrote: > > > Hi Clojure Gurus :) > > > > I've a somewhat contrived use-case for macros that I've been > > > struggling with. > > > > Let's say there's an interface called EWrapper that I'm trying to > > > implement with methods "tickPrice" and "tickSize", a concrete class > > > EWrapperMsgGenerator that has methods with those names that return > > > strings. > > > > I'd like to write a macro that proxies EWrapper's tickSize and > > > tickPrice methods so that they print out the method name as well as > > > the string returned from EWrapperMsgGenerator. > > > > E.g. (in java code): > > > public tickSize( args ) { // on the proxied EWrapper > > > System.out.println( "tickSize: " + > > > EWrapperMsgGenerator.tickSize( args ) ) > > > } > > > > Here's what I've come up with so far: > > > > (defmacro make-msg-ewrapper [method-names] > > > `(proxy [EWrapper] [] > > > ~@(map > > > (fn [method-name] > > > `(~(symbol method-name) [& args#] > > > (println ~method-name ":" > > > (. EWrapperMsgGenerator ~(symbol method-name) > > > args# > > > method-names))) > > > > It's a bit messy -- I'm splicing in a map evaluation into proxy, and > > > then writing in symbols in the function body. This works except that > > > when I run the macro I get "No matching method: tickSize" referring to > > > EWrapperMsgGenerator. > > > > The macro expansion looks like: > > > > (let* [p__4736__auto__ (new user.proxy$java.lang.Object$EWrapper > > > $11bc5609)] (clojure.core/init-proxy p__4736__auto__ {tickPrice > > > (clojure.core/fn ([this & args__2058__auto__] (clojure.core/println > > > tickPrice : (. com.ib.client.EWrapperMsgGenerator tickPrice > > > args__2058__auto__, list (clojure.core/fn ([this & > > > args__2058__auto__] (clojure.core/println list : (. > > > com.ib.client.EWrapperMsgGenerator list args__2058__auto__}) > > > p__4736__auto__) > > > > So far this looks fine to me, except that tickPrice within the > > > EWrapperMsgGenerator call isn't scoped. Is there a better way to do > > > this? > > > > Thanks, > > > Jian > > > Do you have a working version of the code you want that doesn't involve a > > macro? > > > David -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Why should I use emacs instead of netbeans?
I want to know how to do it with netbeans ide ? any nice step by step instructions will be very helpful , as emacs learning curve and setup is taking much time thanks in advance . vincent -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Why should I use emacs instead of netbeans?
2011/6/18 Vincent > I want to know how to do it with netbeans ide ? > any nice step by step instructions will be very helpful , > Vincent, Check out http://www.enclojure.org/gettingstarted -- MK -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Why should I use emacs instead of netbeans?
On Sat, Jun 18, 2011 at 4:07 AM, James Keats wrote: > I'm currently using Netbeans' clojure IDE and I quite like it. I'm currently using Eclipse with CCW and I quite like it. Much depends on what you've been used to. I've worked in an Eclipse environment for several years and use it for all my day-to-day coding needs (Java, Scala, Clojure, CFML, HTML, JavaScript, CSS - supported by various plugins). > The other option that I've seen being popular is emacs with cake. I used Emacs many years ago and when I first started getting into Clojure I tried a few different flavors of Emacs again since it seemed to be the editor of choice for a lot of Clojure / Lisp people. I found it clunky - and it seemed (to me) like it really hadn't changed much in about 20 years (which is both good and bad). So I quickly settled back into Eclipse. > What am I missing out on? Thanks. If you're happy with Netbeans, especially if you're using it for other languages, I don't think you're missing out on anything. Switching IDEs is really a much bigger deal than a lot of people seem to think. You have to really immerse yourself in the new IDE and stick with it. You have to learn a lot of new stuff. Emacs fans will tell you it's worth it. Maybe it is. But "good enough" is a perfectly good reason not to switch. -- Sean A Corfield -- (904) 302-SEAN An Architect's View -- http://corfield.org/ World Singles, LLC. -- http://worldsingles.com/ Railo Technologies, Inc. -- http://www.getrailo.com/ "Perfection is the enemy of the good." -- Gustave Flaubert, French realist novelist (1821-1880) -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Why should I use emacs instead of netbeans?
My main motivation for using Emacs is that it is rock-solid stable. I look forward, however, to the day when the clojure plug-ins for the other IDEs reach that level of maturity and stability, so I can leave Emacs behind. -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en