Re: ANN: lein-search
Nice! Towards a similar purpose, I wrote a little Emacs hack last week that web-scrapes clojars.org and inserts the artifact declaration at the cursor. Since I had to rely on their search feature, I couldn't do proper regular expression matching. -Per On Fri, Apr 9, 2010 at 11:23 AM, Heinz N. Gies wrote: > Some people might have had to endure my complains about maven already (no > worries this isn't one of them). Them aside I usually don't complain without > attempting to do something against the problem I see. > > So here you go lein-search. It's by far not perfect and surely not the nicest > or best way to do things but I feel it is a start to take some of the pain I > have with maven away and I hope others feel the same. > > What does it do? It is a simple lein plugin to search clojars and easily add > artifacts from there to a lein project. It just has three commands: > > lein update (creates a index on clojars.org's repo) > lein search (searches this index) > lein add (a somewhat interactive version of search that lets you > select a precise artifact and version and adds this to your project.clj) > > go enjoy and let me know if something goes wrong. > > Regards, > Hienz aka Licenser aka 'The guy that whines about maven'. > > -- > 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 To unsubscribe, reply using "remove me" as the subject.
Re: Symbol resolution (between quote and eval/execution)
On Fri, Apr 9, 2010 at 11:26 AM, Douglas Philips wrote: > On 2010 Apr 8, at 11:48 PM, Per Vognsen wrote: >> >> The body of fn is still compiled in an expression context. When the >> compiler sees (fn [...] ...), it will introduce the bindings into the >> local environment and recursively compile the body in that >> environment. Note that I said compile rather than evaluate. If you >> make a phase distinction between compile time and run time, all this >> should be easier to understand. > > Yes, I knew there was another "time" involved, but not now to get access to > that in my own code. :) > > >> If you're still confused, check out Compiler.java. The code is very >> simple and everything is right there. > > I've come to clojure with Lisp, C, C++, Python, Forth... roots. > Java, not so much. But I'll look. Thank you for the explanations. I didn't really do any Java programming before coming to Clojure. Rich's Java coding style is so unorthodox (mostly in a good way) that you probably have an advantage over Java programmers in reading his code. When I started learning Clojure last month, one of my points of confusion was indeed symbol resolution, and I cleared it up to my own satisfaction by reading Compiler.java. > >> Macro expansion happens (and has to happen) before everything I >> described above. Your macro will see symbols, not vars. > > Yes, I understood that part. > >> If the macro splices some of the symbols into places that after all macro >> expansion >> are in expression context, they will be resolved into vars. You >> generally don't have to invoke the resolution machinery yourself as >> long as you do that. > > Understood. The macro is going to store the unevaluated form (probably into > a list, maybe into a map), and then other code is going to walk and mutate > it before it (eventually) gets evaluated. I'd like to check the form before > any further processing happens on it, so it sounds like what I need is a > tree walker that just checks resolve's return value as a side effect. I'm not convinced you need to do that. Macro expansion is interleaved with compilation. I'm very doubtful you need resolution to happen at macro expansion time rather than compile time proper. Anyway, I'll let you learn by trial and error. Maybe you'll prove me wrong. :) There was something I had wanted to mention previously but forgot. If you're ever confused about whether something counts as expression context, think about whether macro expansion would take place there. Clearly the arguments to quote are not macro expanded, so they are not in expression context. Similarly for the left-hand sides in let and the bindings in fn. Your initial heuristic about "delaying execution" was too vague. You could say that the branches of the if form have their execution delayed; all the same, they are macro expanded ahead of time. -Per -- 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: Symbol resolution (between quote and eval/execution)
On 2010 Apr 8, at 11:48 PM, Per Vognsen wrote: The body of fn is still compiled in an expression context. When the compiler sees (fn [...] ...), it will introduce the bindings into the local environment and recursively compile the body in that environment. Note that I said compile rather than evaluate. If you make a phase distinction between compile time and run time, all this should be easier to understand. Yes, I knew there was another "time" involved, but not now to get access to that in my own code. :) If you're still confused, check out Compiler.java. The code is very simple and everything is right there. I've come to clojure with Lisp, C, C++, Python, Forth... roots. Java, not so much. But I'll look. Thank you for the explanations. Macro expansion happens (and has to happen) before everything I described above. Your macro will see symbols, not vars. Yes, I understood that part. If the macro splices some of the symbols into places that after all macro expansion are in expression context, they will be resolved into vars. You generally don't have to invoke the resolution machinery yourself as long as you do that. Understood. The macro is going to store the unevaluated form (probably into a list, maybe into a map), and then other code is going to walk and mutate it before it (eventually) gets evaluated. I'd like to check the form before any further processing happens on it, so it sounds like what I need is a tree walker that just checks resolve's return value as a side effect. Thanks, -Doug -- 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 To unsubscribe, reply using "remove me" as the subject.
ANN: lein-search
Some people might have had to endure my complains about maven already (no worries this isn't one of them). Them aside I usually don't complain without attempting to do something against the problem I see. So here you go lein-search. It's by far not perfect and surely not the nicest or best way to do things but I feel it is a start to take some of the pain I have with maven away and I hope others feel the same. What does it do? It is a simple lein plugin to search clojars and easily add artifacts from there to a lein project. It just has three commands: lein update (creates a index on clojars.org's repo) lein search (searches this index) lein add (a somewhat interactive version of search that lets you select a precise artifact and version and adds this to your project.clj) go enjoy and let me know if something goes wrong. Regards, Hienz aka Licenser aka 'The guy that whines about maven'. -- 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
"Introduction to Monads in Clojure" tech talk
Adam Smyczek's "Introduction to Monads" video is now available. http://www.youtube.com/user/LinkedInTechTalks?feature=mhw5#p/u/0/ObR3qi4Guys I'll work on getting an HD version up Friday. -mike -- 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: Symbol resolution (between quote and eval/execution)
On Fri, Apr 9, 2010 at 10:35 AM, Douglas Philips wrote: > On 2010 Apr 8, at 11:16 PM, Per Vognsen wrote: >> >> It's not a defn thing. If you write (do (a) (b) (c)) at the REPL, you >> should see the same exception. > > Yes, I would expect that since at the REPL I am asking to have the > expression evaluated immediately. > Same with let. > > Yet, if I say: '(do (a) (b) (c)) > I do not get such an error, because quote is protecting me. > defn/fn are quoting in the sense that their body's expression is not > immediately evaluated, The body of fn is still compiled in an expression context. When the compiler sees (fn [...] ...), it will introduce the bindings into the local environment and recursively compile the body in that environment. Note that I said compile rather than evaluate. If you make a phase distinction between compile time and run time, all this should be easier to understand. Quoting is a special form. When the compiler sees (quote ...), it does not recursively compile the argument forms. If you're still confused, check out Compiler.java. The code is very simple and everything is right there. > yet they are doing more than quote because they're resolving the symbols. > >> When the compiler sees a symbol in expression context, it first checks >> whether it is bound in the local environment: >> >> (let [x 42] x) >> >> In this case, x is bound in the local environment. >> >> If a symbol isn't bound in this way, the compiler will call (resolve >> ...) on the symbol at compile time. This yields some var v. The code >> will then be evaluated as (deref v) at run time. > > So how do I invoke that resolution machinery myself? > > (my-do-later (a) (b 23) (c d e)) > while the forms in the body of my-do-later will be spliced into other places > for later evaluation, I want to know that they're valid symbols when > my-do-later is called (which has to be a macro to delay evaluation). I don't > necessarily need or care to know what they are resolved to (even regular > code in clojure can be affected by binding forms, which is what I'm planning > to inject the bodies of my-do-later forms into eventually). Macro expansion happens (and has to happen) before everything I described above. Your macro will see symbols, not vars. If the macro splices some of the symbols into places that after all macro expansion are in expression context, they will be resolved into vars. You generally don't have to invoke the resolution machinery yourself as long as you do that. But you can of course do it if you want, in which case you should call resolve at macro expansion time and have the macro expand to something that calls derefs on the resolved var: (defmacro symbol-eval [x] (let [v (resolve x)] `(deref ~v))) -Per -- 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 To unsubscribe, reply using "remove me" as the subject.
Re: Symbol resolution (between quote and eval/execution)
On 2010 Apr 8, at 11:16 PM, Per Vognsen wrote: It's not a defn thing. If you write (do (a) (b) (c)) at the REPL, you should see the same exception. Yes, I would expect that since at the REPL I am asking to have the expression evaluated immediately. Same with let. Yet, if I say: '(do (a) (b) (c)) I do not get such an error, because quote is protecting me. defn/fn are quoting in the sense that their body's expression is not immediately evaluated, yet they are doing more than quote because they're resolving the symbols. When the compiler sees a symbol in expression context, it first checks whether it is bound in the local environment: (let [x 42] x) In this case, x is bound in the local environment. If a symbol isn't bound in this way, the compiler will call (resolve ...) on the symbol at compile time. This yields some var v. The code will then be evaluated as (deref v) at run time. So how do I invoke that resolution machinery myself? (my-do-later (a) (b 23) (c d e)) while the forms in the body of my-do-later will be spliced into other places for later evaluation, I want to know that they're valid symbols when my-do-later is called (which has to be a macro to delay evaluation). I don't necessarily need or care to know what they are resolved to (even regular code in clojure can be affected by binding forms, which is what I'm planning to inject the bodies of my-do-later forms into eventually). Thanks, -Doug -- 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 To unsubscribe, reply using "remove me" as the subject.
Re: Symbol resolution (between quote and eval/execution)
On Fri, Apr 9, 2010 at 10:04 AM, Douglas Philips wrote: > I'm trying to understand how the two forms here differ: > > In a fresh repl: > > user=> '((a) (b) (c)) > ((a) (b) (c)) > > which is OK, those are just symbols. > > But then: > > user=> (defn x [] (a) (b) (c)) > java.lang.Exception: Unable to resolve symbol: a in this context > (NO_SOURCE_FILE:2) > > so defn is doing something more than quoting the symbols (which quote did > without generating an exception), but less than eval/execution. It's not a defn thing. If you write (do (a) (b) (c)) at the REPL, you should see the same exception. When the compiler sees a symbol in expression context, it first checks whether it is bound in the local environment: (let [x 42] x) In this case, x is bound in the local environment. If a symbol isn't bound in this way, the compiler will call (resolve ...) on the symbol at compile time. This yields some var v. The code will then be evaluated as (deref v) at run time. -Per -- 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 To unsubscribe, reply using "remove me" as the subject.
Symbol resolution (between quote and eval/execution)
I'm trying to understand how the two forms here differ: In a fresh repl: user=> '((a) (b) (c)) ((a) (b) (c)) which is OK, those are just symbols. But then: user=> (defn x [] (a) (b) (c)) java.lang.Exception: Unable to resolve symbol: a in this context (NO_SOURCE_FILE:2) so defn is doing something more than quoting the symbols (which quote did without generating an exception), but less than eval/execution. http://clojure.org/evaluation says: A Symbol is resolved: ... • Else, it is not qualified and the first of the following applies: ... • If in a local scope (i.e. in a function definition), a lookup is done to see if it names a local binding (e.g. a function argument or let-bound name). If so, the value is the value of the local binding. • A lookup is done in the current namespace to see if there is a mapping from the symbol to a var. If so, the value is the value of the binding of the var referred-to by the symbol. ... searching for 'local scope' using clojure.org's search box hasn't been fruitful. I did read through http://clojure.org/special_forms since the text quoted above mentioned function definitions, but I didn't find anything there either. I'd like to understand how this works, as I am writing a DSL and I want to be able to invoke the symbol resolution (to catch typos, etc) without having to be in a defn or let context. Thanks, -Doug -- 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 To unsubscribe, reply using "remove me" as the subject.
Re: Error when tried to compile with C-c C-k in emacs.
On Thu, Apr 8, 2010 at 3:32 PM, Stefan Kamphausen wrote: > In the long run the Clojure community should either create an > "official" fork of SLIME (and try to port the good stuff, that happens > in SLIME) or try to work closer together with the fine SLIME folks. I > don't think that we should risk losing the Emacs users, because they > may be very happy to find a usable way of leveraging Java's wealth > without having to type Java ;-) And the frequency of Emacs-setup- > related posts in the near past should tell us that things are not too > well right now. You'll notice 90% of the "I'm having trouble with Emacs" posts have one thing in common: they all start with "I'm trying to install without ELPA". I would like to keep swank in line with upstream slime, but it is a lot of work. There are just so many more valuable things to work on right now... when using an older version of slime is such a low-friction solution, it's hard to justify the amount of work it would take to bring everything up to date with the latest, especially given the fact that slime "doesn't do stable releases". Though Hugo has done a fair bit of this work, and I'm grateful for that. If anyone else is keen on the latest slime then I'd be glad to get contributions from them too. -Phil -- 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 To unsubscribe, reply using "remove me" as the subject.
Re: iterating over a nested vector
Or you can separate concerns a bit more: (defn transpose [xs] (apply map vector xs)) Now Nurullah's original suggestion applies: (map #(apply max %) (transpose xs)) -Per On Fri, Apr 9, 2010 at 12:38 AM, James Reeves wrote: > On Apr 8, 1:13 pm, John Sanda wrote: >> [ >> [1 2 3] >> [2 5 1] >> [4 2 6] >> ] >> >> I am comparing the values in each of the columns, so the result should be [4 >> 5 6] where the first element represents the largest value in the first >> column, the second element represents the largest value in the second >> column, etc. > > The `map` function allows you to specify more than one collection. > With multiple collections, the mapping function is passed an argument > for each collection. So: > > (map + [1 2 3] [4 5 6]) > => ((+ 1 4) (+ 2 5) (+ 3 6)) > => (5, 7, 9) > > By combining this with `apply` and `max`, you can find the maximum > value of each column: > > (defn max-columns [coll] > (apply map max coll)) > > If we pass your vector to max-columns: > > (max-columns [[1 2 3] [2 5 1] [4 2 6]]) > => (apply map max [[1 2 3] [2 5 1] [4 2 6]]) > => (map max [1 2 3] [2 5 1] [4 2 6]) > => ((max 1 2 4) (max 2 5 2) (max 3 1 6)) > => (4 5 6) > > - James > > -- > 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 > > To unsubscribe, reply using "remove me" as the subject. > -- 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: New clojure support in Polyglot Maven
Thanks for your response. Since that's already more than I can chew I'll stick to regular pom files as I try to follow your directions and look through docs and samples. -- 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: Error when tried to compile with C-c C-k in emacs.
On Thu, 08 Apr 2010 18:32:56 -0400, Stefan Kamphausen wrote: you're using a rather recent checkout of CVS SLIME. They added keyword args to compile-file-for-emacs which is currently not understood on the clojure swank side. The quickest way to fix that would be changing that part of SLIME. Yes, this is ugly. This is fixed in swank-clojure and is available in 1.2-SNAPSHOT. I use SLIME 2010-03-10. In the long run the Clojure community should either create an "official" fork of SLIME (and try to port the good stuff, that happens in SLIME) or try to work closer together with the fine SLIME folks. I don't think that we should risk losing the Emacs users, because they may be very happy to find a usable way of leveraging Java's wealth without having to type Java ;-) And the frequency of Emacs-setup- related posts in the near past should tell us that things are not too well right now. Ho-humm (or what did the Ents say?) The autodoc and hyperdoc branches in technomancy's swank-clojure repository implement recent slime features, and require testing with ELPA slime before they can be merged. Volunteers? -- Hugo Duncan -- 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: mutating multiple java swing components
It sounds like the doseq is the macro you're looking for, e.g. (doseq [c my-components] (.setVisible c true)) On Thu, Apr 8, 2010 at 5:07 PM, strattonbrazil wrote: > What's the function to call java code on multiple java components? If > I have a sequence of Java swing components and I want to go through > and set the same properties for each one, I would use a for loop in > Java. If I were using immutable structs in clojure, I'd just a map > and just change the keys I'd want to change. Should I still use a map > if I don't care about what I'm returning and I just want to call set* > methods on each component? > > -- > 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: Error when tried to compile with C-c C-k in emacs.
Hi, you're using a rather recent checkout of CVS SLIME. They added keyword args to compile-file-for-emacs which is currently not understood on the clojure swank side. The quickest way to fix that would be changing that part of SLIME. Yes, this is ugly. It's really a pity that SLIME and clojure/mode/swank move forward so independently. In the long run the Clojure community should either create an "official" fork of SLIME (and try to port the good stuff, that happens in SLIME) or try to work closer together with the fine SLIME folks. I don't think that we should risk losing the Emacs users, because they may be very happy to find a usable way of leveraging Java's wealth without having to type Java ;-) And the frequency of Emacs-setup- related posts in the near past should tell us that things are not too well right now. Ho-humm (or what did the Ents say?) However, I digress... 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: mutating multiple java swing components
> What's the function to call java code on multiple java components? If > I have a sequence of Java swing components and I want to go through > and set the same properties for each one, I would use a for loop in > Java. If I were using immutable structs in clojure, I'd just a map > and just change the keys I'd want to change. Should I still use a map > if I don't care about what I'm returning and I just want to call set* > methods on each component? By the way, I'm doing this from a map of existing components, so for example if I have a sequence of 10 JButtons, I want to make 10 new JButtons mapping the text from the originals and also set specific properties on the new ones, so I'm wondering if I should just do it in a really big map call or break it into two pieces--copy over the buttons then "line them up" again to set one to the other. -- 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
mutating multiple java swing components
What's the function to call java code on multiple java components? If I have a sequence of Java swing components and I want to go through and set the same properties for each one, I would use a for loop in Java. If I were using immutable structs in clojure, I'd just a map and just change the keys I'd want to change. Should I still use a map if I don't care about what I'm returning and I just want to call set* methods on each component? -- 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: New clojure support in Polyglot Maven
On Thu, Apr 8, 2010 at 4:57 PM, Armando Blancas wrote: >> Looks cool. This should help the XML-allergic :) > > Though I don't like it, the XML is the least of my problems. Don't > know what to do or even where to start. I want to do the following in > maven or pmaven, but anything beyond their Hello World example has > been a real struggle :-( Any pointers? > The steps are: Add antlr3-maven-plugin to your Project Object Model (pom). In maven xml it looks like: ... org.codehaus.mojo antlr3-maven-plugin 1.0 antlr ... I'm guessing that in the new polyglot world it would look something like: (defmaven ; ... other stuff that defines your project name, version, etc :build [:plugins [['org.codehaus.mojo/antlr3-maven-plugin "1.0" :executions [[:goals ["antlr"]]]) ; Who knows if I got the braces correct Which already seems like a pretty big improvement to me. As a result you would be able to: (The following all assumes that your *.g files are in src/main/antlr, where maven looks by default, more details at: http://mojo.codehaus.org/antlr3-maven-plugin/) > -- Generate Java code from an ANTLR lexer: > java -cp ... org.antlr.Tool Scanner.g mvn -f project.clj generate-sources (the resulting java files end up in the "target/generated-sources/antlr" directory by default) > -- Compile the scanner and an exception class: > javac -cp ... Scanner.java ExitException.java I'm not sure how you'd do this in a maven-only world. I guess you'd have to do "java -cp target/generated-sources/antlr/*.java", not sure why you'd want to though. I guess one way would be to put your antlr stuff in its own sub-project and then "mvn -f project.clj compile". > -- Compile the clojure program using the above classes > java -Dclojure.compile.path=... -cp ... clojure.lang.Compile prog.main mvn -f project.clj compile (You can also skip straight to this if you want, the antlr files should be processed automatically into java for you, you'd also need to add the maven-clojure-plugin to your plugins to be able to do compile clojure code and do something like "mvn repl") > -- Package incl. the antlr runtime inside the jar > jar -x ... > jar cMf prog.jar ... *.class mvn -f project.clj package (The resulting jar file ends up in "target\project_name-module_name-.jar by default. A file called "target\project_name-module-name--sources.jar" is also automatically created containing all your source code. I don't think, however, that it adds the antlr runtime to your jar) For more complicated packaging (such as adding the antlr runtime), you'd use the maven-assembly-plugin to add arbitrary stuff to your resulting jar. It's a little more complicated, and requires its own xml. http://maven.apache.org/plugins/maven-assembly-plugin/ > - clean up: delete the generated Java classes, the .tokens file, the > expanded antl runtime, all .class files mvn -f project.clj clean -- 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: A syntax question: positional & keyword
On Apr 8, 11:08 am, David Nolen wrote: > In my own code I only avoid the convenience of destructuring in the > rare tight loops such as calculations intended to drive animations. But when you write a function you would have to decide positional vs. keyword. Would you then take a guess about usage in tight loops vs. not? > I've found it to have little effect elsewhere on program performance. I suspect you are right. Anyway, I'm very glad to see the style supported, and hope the cleaner defnk version wins, with some ability to further destructure the keyworded arguments. (defnk f [a b :c 1 :d 2] [a b c d]) -- 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: New clojure support in Polyglot Maven
> Looks cool. This should help the XML-allergic :) Though I don't like it, the XML is the least of my problems. Don't know what to do or even where to start. I want to do the following in maven or pmaven, but anything beyond their Hello World example has been a real struggle :-(Any pointers? -- Generate Java code from an ANTLR lexer: java -cp ... org.antlr.Tool Scanner.g -- Compile the scanner and an exception class: javac -cp ... Scanner.java ExitException.java -- Compile the clojure program using the above classes java -Dclojure.compile.path=... -cp ... clojure.lang.Compile prog.main -- Package incl. the antlr runtime inside the jar jar -x ... jar cMf prog.jar ... *.class - clean up: delete the generated Java classes, the .tokens file, the expanded antl runtime, all .class files -- 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: A syntax question: positional & keyword
Yes, I meant that :-) But I agree that some more sugar in general in map destructuring could help (and be more DRY). e.g. (defn g [a b & {:keys [[c 1] [d 2]]}] [a b c d]) or (defn g [a b & {c [:c 1] d [:d 2]]}] [a b c d]) in the general case 2010/4/8 Chris Perkins : > On Apr 7, 5:41 am, Laurent PETIT wrote: >> I think defnk is deprecated by the new feature mentioned by Stuart. > > Do you mean to say that this: > > user=> (defnk f [a b :c 1 :d 2] [a b c d]) > #'user/f > user=> (f 3 4 :d 7) > [3 4 1 7] > > is deprecated in favor of this: > > user=> (defn g [a b & {:keys [c d] :or {c 1 d 2}}] [a b c d]) > #'user/g > user=> (g 3 4 :d 7) > [3 4 1 7] > > Eeek, I certainly hope not. > > - Chris Perkins > > -- > 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 > > To unsubscribe, reply using "remove me" as the subject. > -- 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: A syntax question: positional & keyword
On Apr 7, 5:41 am, Laurent PETIT wrote: > I think defnk is deprecated by the new feature mentioned by Stuart. Do you mean to say that this: user=> (defnk f [a b :c 1 :d 2] [a b c d]) #'user/f user=> (f 3 4 :d 7) [3 4 1 7] is deprecated in favor of this: user=> (defn g [a b & {:keys [c d] :or {c 1 d 2}}] [a b c d]) #'user/g user=> (g 3 4 :d 7) [3 4 1 7] Eeek, I certainly hope not. - Chris Perkins -- 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 To unsubscribe, reply using "remove me" as the subject.
Re: iterating over a nested vector
Another one using for (defn col-widths [arr] (for [i (range (count arr))] (apply max (map #(nth % i) arr On Thu, Apr 8, 2010 at 1:55 PM, John Sanda wrote: > Thanks for the explanation. I did see in the docs that the map function can > take multiple collections, but I guess I did not quite understand it. Your > explanation really helps illustrate how it works. My Java version of this is > probably around 30 lines with several branches/execution paths and variables > as opposed to a 1-line clojure version that is free of branching and > variables. I'm hooked ;-) > On Thu, Apr 8, 2010 at 1:38 PM, James Reeves > wrote: > >> On Apr 8, 1:13 pm, John Sanda wrote: >> > [ >> > [1 2 3] >> > [2 5 1] >> > [4 2 6] >> > ] >> > >> > I am comparing the values in each of the columns, so the result should >> be [4 >> > 5 6] where the first element represents the largest value in the first >> > column, the second element represents the largest value in the second >> > column, etc. >> >> The `map` function allows you to specify more than one collection. >> With multiple collections, the mapping function is passed an argument >> for each collection. So: >> >> (map + [1 2 3] [4 5 6]) >> => ((+ 1 4) (+ 2 5) (+ 3 6)) >> => (5, 7, 9) >> >> By combining this with `apply` and `max`, you can find the maximum >> value of each column: >> >> (defn max-columns [coll] >> (apply map max coll)) >> >> If we pass your vector to max-columns: >> >> (max-columns [[1 2 3] [2 5 1] [4 2 6]]) >> => (apply map max [[1 2 3] [2 5 1] [4 2 6]]) >> => (map max [1 2 3] [2 5 1] [4 2 6]) >> => ((max 1 2 4) (max 2 5 2) (max 3 1 6)) >> => (4 5 6) >> >> - James >> >> -- >> 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 >> >> To unsubscribe, reply using "remove me" as the subject. >> > > > > -- > > - John > > -- > 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: iterating over a nested vector
Thanks for the explanation. I did see in the docs that the map function can take multiple collections, but I guess I did not quite understand it. Your explanation really helps illustrate how it works. My Java version of this is probably around 30 lines with several branches/execution paths and variables as opposed to a 1-line clojure version that is free of branching and variables. I'm hooked ;-) On Thu, Apr 8, 2010 at 1:38 PM, James Reeves wrote: > On Apr 8, 1:13 pm, John Sanda wrote: > > [ > > [1 2 3] > > [2 5 1] > > [4 2 6] > > ] > > > > I am comparing the values in each of the columns, so the result should be > [4 > > 5 6] where the first element represents the largest value in the first > > column, the second element represents the largest value in the second > > column, etc. > > The `map` function allows you to specify more than one collection. > With multiple collections, the mapping function is passed an argument > for each collection. So: > > (map + [1 2 3] [4 5 6]) > => ((+ 1 4) (+ 2 5) (+ 3 6)) > => (5, 7, 9) > > By combining this with `apply` and `max`, you can find the maximum > value of each column: > > (defn max-columns [coll] > (apply map max coll)) > > If we pass your vector to max-columns: > > (max-columns [[1 2 3] [2 5 1] [4 2 6]]) > => (apply map max [[1 2 3] [2 5 1] [4 2 6]]) > => (map max [1 2 3] [2 5 1] [4 2 6]) > => ((max 1 2 4) (max 2 5 2) (max 3 1 6)) > => (4 5 6) > > - James > > -- > 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 > > To unsubscribe, reply using "remove me" as the subject. > -- - John -- 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: iterating over a nested vector
If I got you right this time, if you (apply interleave [[1 2 3] [2 5 1] [4 2 6]]) you will get, (1 2 4 2 5 2 3 1 6) then if you partition by 3, (partition 3 (apply interleave [[1 2 3] [2 5 1] [4 2 6]])) you get, ((1 2 4) (2 5 2) (3 1 6)) then as before applying max, (map #(apply max %) (partition 3 (apply interleave [[1 2 3] [2 5 1] [4 2 6]]))) will give you, (4 5 6) Regards, -- Nurullah Akkaya http://nakkaya.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 To unsubscribe, reply using "remove me" as the subject.
Re: iterating over a nested vector
On Apr 8, 1:13 pm, John Sanda wrote: > [ > [1 2 3] > [2 5 1] > [4 2 6] > ] > > I am comparing the values in each of the columns, so the result should be [4 > 5 6] where the first element represents the largest value in the first > column, the second element represents the largest value in the second > column, etc. The `map` function allows you to specify more than one collection. With multiple collections, the mapping function is passed an argument for each collection. So: (map + [1 2 3] [4 5 6]) => ((+ 1 4) (+ 2 5) (+ 3 6)) => (5, 7, 9) By combining this with `apply` and `max`, you can find the maximum value of each column: (defn max-columns [coll] (apply map max coll)) If we pass your vector to max-columns: (max-columns [[1 2 3] [2 5 1] [4 2 6]]) => (apply map max [[1 2 3] [2 5 1] [4 2 6]]) => (map max [1 2 3] [2 5 1] [4 2 6]) => ((max 1 2 4) (max 2 5 2) (max 3 1 6)) => (4 5 6) - James -- 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 To unsubscribe, reply using "remove me" as the subject.
Error when tried to compile with C-c C-k in emacs.
Hi, I setup my emacs/swank-clojure/clojure without using elpa. I could run slime/swank-clojure and evaluate an expression just fine, but when I try to compile with C-c C-k, it give me this error. Wrong number of args passed to: basic$eval--2073$compile-file-for- emacs [Thrown class java.lang.IllegalArgumentException] Restarts: 0: [ABORT] Return to SLIME's top level. Backtrace: 0: clojure.lang.AFn.throwArity(AFn.java:441) 1: clojure.lang.AFn.invoke(AFn.java:61) 2: clojure.lang.Var.invoke(Var.java:385) 3: user$eval__3020.invoke(NO_SOURCE_FILE) 4: clojure.lang.Compiler.eval(Compiler.java:5358) 5: clojure.lang.Compiler.eval(Compiler.java:5326) 6: clojure.core$eval__4174.invoke(core.clj:2139) --more-- = I have no clue where should I look into. Any suggestion would be really appreciate. Preecha -- 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: iterating over a nested vector
That is actually not what I want. Consider the vector a table where each element which is itself a vector a row. And each element of a nested vector is a cell where its index indicates its column. Writing it as follows may make it more clear, [ [1 2 3] [2 5 1] [4 2 6] ] I am comparing the values in each of the columns, so the result should be [4 5 6] where the first element represents the largest value in the first column, the second element represents the largest value in the second column, etc. I am about half way through the Programming Clojure book. Maybe as I get further along a more concise solution will become apparent. - John On Thu, Apr 8, 2010 at 12:50 PM, Nurullah Akkaya wrote: > > If you just want max in each group you can use, > > (map #(apply max %) [[1 2 3] [2 5 1] [4 2 6]]) > > this will give you, > > (3 5 6) > > Regards, > -- > Nurullah Akkaya > http://nakkaya.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 > > To unsubscribe, reply using "remove me" as the subject. > -- - John -- 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: iterating over a nested vector
If you just want max in each group you can use, (map #(apply max %) [[1 2 3] [2 5 1] [4 2 6]]) this will give you, (3 5 6) Regards, -- Nurullah Akkaya http://nakkaya.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 To unsubscribe, reply using "remove me" as the subject.
iterating over a nested vector
Hi, I am just getting started with Clojure and with functional programming for matter. I decided that a good exercise would be for to try and port some Java code that I recently wrote. In the Java code I had a 2-D array which basically represents a table of values, and to keep things simple assume that they are just integers. My Java code had to find the greatest value in each column and return those values in an array. For example, given something like, [[1 2 3] [2 5 1] [4 2 6]], I would expect [4 5 6] to be returned. I came up with the following solution in clojure, (defn num-cols [rows] (count (first rows))) (defn next-col [col rows] (rem (inc col) (num-cols rows))) (defn col-max [col rows] (apply max (map #(nth % col) rows))) (defn col-widths [rows] (loop [widths [] col 0] (if (= (count widths) (num-cols rows)) widths (recur (conj widths (col-max col rows)) (next-col col rows) I am assuming that there is probably a simpler, more efficient doing this and am hoping someone can point me in the right direction. I would like to do something along these lines. Start with a sequence that contains the values from the first row of my table. For each row in my table, compare the column values in that row against the corresponding values in the sequence. If any of the columns in the row are greater than the corresponding values in the sequence, then update/replace the sequence with the greater values from that row. Thanks - John -- 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 To unsubscribe, reply using "remove me" as the subject.
Re: A syntax question: positional & keyword
In my own code I only avoid the convenience of destructuring in the rare tight loops such as calculations intended to drive animations. I've found it to have little effect elsewhere on program performance. As an aside I personally prefer non positional keyword arguments. I find positional ones quite tedious. David On Thursday, April 8, 2010, Sophie wrote: > On Apr 7, 7:56 am, David Nolen wrote: >> The runtime cost of destructuring is not worth getting worked up >> about. It's easy to check this yourself with (time ...) > > Results below: > > user=> (defn fk [& {:keys [a b c]}] (+ a b c)) > > user=> (defn fp [a b c] (+ a b c)) > > user=> (time (dotimes [_ 100] (fk :a 2 :b 2 :c 2))) > "Elapsed time: 1582.178 msecs" > > user=> (time (dotimes [_ 100] (fp 2 2 2))) > "Elapsed time: 319.243 msecs" > > Not sure how significant that would be in user code, but I'd rather > not have to choose less a less readable version because of the hit. > Positional keywords would give the readable function calls without the > run-time hit (and we could still use optional &keys if they were > somehow distinguished in the function calls). > > -- > 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 To unsubscribe, reply using "remove me" as the subject.
Re: A syntax question: positional & keyword
You can easily code positional keyword parameters yourself. It takes only a few minutes for a basic version. Here's an admittedly not very pretty example: http://gist.github.com/360145 -Per On Thu, Apr 8, 2010 at 9:13 PM, Sophie wrote: > On Apr 7, 7:56 am, David Nolen wrote: >> The runtime cost of destructuring is not worth getting worked up >> about. It's easy to check this yourself with (time ...) > > Results below: > > user=> (defn fk [& {:keys [a b c]}] (+ a b c)) > > user=> (defn fp [a b c] (+ a b c)) > > user=> (time (dotimes [_ 100] (fk :a 2 :b 2 :c 2))) > "Elapsed time: 1582.178 msecs" > > user=> (time (dotimes [_ 100] (fp 2 2 2))) > "Elapsed time: 319.243 msecs" > > Not sure how significant that would be in user code, but I'd rather > not have to choose less a less readable version because of the hit. > Positional keywords would give the readable function calls without the > run-time hit (and we could still use optional &keys if they were > somehow distinguished in the function calls). > > -- > 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 To unsubscribe, reply using "remove me" as the subject.
Re: A syntax question: positional & keyword
On Apr 7, 12:37 pm, Armando Blancas wrote: > in other languages they'd be annotations and maybe perceived > as redundant, e.g. a call like: (circle x y radius) is readable Ah, but what about: (circle year population income) vs. (circle :x year :y population :r income) > In Smtalltalk a single-arg keyword message is readable because the > syntax gets the received out of the way to the left: 5.0 raisedTo: 3 > where #raisedTo: is both the selector and keyword. (raise base: 5 to: 3) ;; all keyword (raise 5 to: 3) ;; 1st positional + 2nd keyword Smalltalk may actually be the asymmetrical one here: truck moveX: 5 y: 6 vs. truck move x: 5 y: 6 ;; my "prefixed" version Smalltalk munges the root command name (move) with the keyword for the first argument (X), which is why I showed a prefixed version instead. In Clojure this might be: (move :obj truck :x 5 :y 6) ;; all keyword (move truck :x 5 :y 6) ;; combine position + keyword -- 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: A syntax question: positional & keyword
On Apr 7, 7:56 am, David Nolen wrote: > The runtime cost of destructuring is not worth getting worked up > about. It's easy to check this yourself with (time ...) Results below: user=> (defn fk [& {:keys [a b c]}] (+ a b c)) user=> (defn fp [a b c] (+ a b c)) user=> (time (dotimes [_ 100] (fk :a 2 :b 2 :c 2))) "Elapsed time: 1582.178 msecs" user=> (time (dotimes [_ 100] (fp 2 2 2))) "Elapsed time: 319.243 msecs" Not sure how significant that would be in user code, but I'd rather not have to choose less a less readable version because of the hit. Positional keywords would give the readable function calls without the run-time hit (and we could still use optional &keys if they were somehow distinguished in the function calls). -- 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: question about "into"
Indeed, and in the absence of single stepping (manual or automatic), some simple trace macros can be very useful. Here's what I use right now: http://gist.github.com/360102 -Per On Thu, Apr 8, 2010 at 8:38 PM, Sean Devlin wrote: > The REPL is you best friend whenever you have a question like this. > It's often useful to execute the offending form step by step, to see > what the result of each computation is. > > Love the REPL. > > Sean > > On Apr 7, 8:45 pm, Per Vognsen wrote: >> The second case is equivalent to (into [] [{:a 1 :b 2}]). You're >> passing a singleton list containing a single element which happens to >> be a map. >> >> -Per >> >> On Thu, Apr 8, 2010 at 7:35 AM, Base wrote: >> > Hi All - >> >> > I have a question about into. >> >> > When you run the into against a map you get a vector of >> >> > (into [] {:a 1 :b 2}) >> >> > => [[:a 1] [:b 2]] >> >> > However when you use a for in front of this you get the full map. >> >> > (into [] (for [_ (range 1)] {:a 1 :b 2})) >> >> > => [{:a 1, :b 2}] >> >> > Why is this? I would have expected them both to yield the same >> > results... >> >> > Thanks >> >> > Bassel >> >> > -- >> > 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 >> >> > To unsubscribe, reply using "remove me" as the subject. > > -- > 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: question about "into"
The REPL is you best friend whenever you have a question like this. It's often useful to execute the offending form step by step, to see what the result of each computation is. Love the REPL. Sean On Apr 7, 8:45 pm, Per Vognsen wrote: > The second case is equivalent to (into [] [{:a 1 :b 2}]). You're > passing a singleton list containing a single element which happens to > be a map. > > -Per > > On Thu, Apr 8, 2010 at 7:35 AM, Base wrote: > > Hi All - > > > I have a question about into. > > > When you run the into against a map you get a vector of > > > (into [] {:a 1 :b 2}) > > > => [[:a 1] [:b 2]] > > > However when you use a for in front of this you get the full map. > > > (into [] (for [_ (range 1)] {:a 1 :b 2})) > > > => [{:a 1, :b 2}] > > > Why is this? I would have expected them both to yield the same > > results... > > > Thanks > > > Bassel > > > -- > > 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 > > > To unsubscribe, reply using "remove me" as the subject. -- 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: New clojure support in Polyglot Maven
On 08/04/2010, at 9:09 PM, Jarkko Oranen wrote: > >> Hopefully you can see that this syntax falls out of the direct construction >> of maven Model object, unmediated by intermediate syntax or data >> structuring. So there's a good reason for the way it looks. >> > > Right. Thanks for the thorough explanation. It's not so bad if you > quote the vectors instead of the individual symbols. However, it seems > to me that defmaven could very well be a plain function in that case > (just (reset! *MODEL* (apply Model args))). :) Yes, you're right. I'll make that change. Antony Blakey - CTO, Linkuistics Pty Ltd Ph: 0438 840 787 The ultimate measure of a man is not where he stands in moments of comfort and convenience, but where he stands at times of challenge and controversy. -- Martin Luther King -- 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 To unsubscribe, reply using "remove me" as the subject.
Re: My non-ELPA Emacs swank-clojure setup
On Thursday 08 April 2010 13:33:43 Alex Osborne wrote: Hi Alex, > > To get swank-clojure.jar I need to check out the project from github > > and use "lein jar" to generate the jar, right? Or is it possible to > > download a ready-made jar? > > You can just download it by hand from Clojars if you like: > > http://clojars.org/repo/swank-clojure/swank-clojure/ That did the trick, and thanks a lot for the further explanations. 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 To unsubscribe, reply using "remove me" as the subject.
Re: New clojure support in Polyglot Maven
> Hopefully you can see that this syntax falls out of the direct construction > of maven Model object, unmediated by intermediate syntax or data structuring. > So there's a good reason for the way it looks. > Right. Thanks for the thorough explanation. It's not so bad if you quote the vectors instead of the individual symbols. However, it seems to me that defmaven could very well be a plain function in that case (just (reset! *MODEL* (apply Model args))). :) -- 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 To unsubscribe, reply using "remove me" as the subject.
Re: My non-ELPA Emacs swank-clojure setup
Tassilo Horn writes: > To get swank-clojure.jar I need to check out the project from github and > use "lein jar" to generate the jar, right? Or is it possible to > download a ready-made jar? You can just download it by hand from Clojars if you like: http://clojars.org/repo/swank-clojure/swank-clojure/ I've never had a problem with the stable 1.1.0 version fine, or you can try the 'break' snapshot which has better debugging support. >> So for example if you have a leiningen project and run lein deps so >> the lib directory is populated with clojure, contrib, swank-clojure >> and anything else your project needs, then when you run M-x >> swank-clojure-project and point it at your project's directory, it'll >> completely disregard ~/.swank-clojure and use those jars. > > Isn't it a bad idea to include all deps into a project, so that one ends > up with so much duplication? What is a "bad idea" is subjective and depends on your use case and your workflow. You may need to use a particular version of Clojure for a particular project, for example because AOT-compiled 1.1.0 and git master are incompatible. Similarly I find having a project checkout fully self-contained so that it can just be copied to a server and run without any prior setup except having a JVM installed extremely handy. But it seems a lot of people don't agree and would prefer to save a small amount of disk space by sharing jars between projects. It's up to you really, you can use symlinks if you prefer (and there's apparently a patch you can apply to Lein that makes it use symlinks). There's also a branch of Lein which allows you to use checked out projects as dependencies which lets you hack on multiple inter-dependent projects at once nicely: http://groups.google.com/group/leiningen/browse_thread/thread/f67cb42c06515e53 -- 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 To unsubscribe, reply using "remove me" as the subject.
Re: Trying to set emacs for some clojure coding
>If you have any idea or inkling why swank-clojure wasn't able to >automatically download the jars please let me know; I'd like to get it >fixed. Seems that it didn't download swank-clojure.jar because I already had a .clojure folder. -- 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 To unsubscribe, reply using "remove me" as the subject.
Re: My non-ELPA Emacs swank-clojure setup
>> It will only download anything if ~/.swank-clojure and ~/.clojure >> don't exist. > > Ah, then that's my problem. I already have a ~/.clojure/ directory with > a user.clj, the leiningen jar, and some additional jars, but not > swank-clojure.jar. ~/.swank-clojure doesn't exist, though. > That was my problem also. I think I will delete the de directory so swank-clojure downloads all the correct files. -- 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 To unsubscribe, reply using "remove me" as the subject.
Re: My non-ELPA Emacs swank-clojure setup
On Thursday 08 April 2010 12:28:07 Alex Osborne wrote: Hi Alex, > > To me, all this stuff seems to magical, for example that > > swank-clojure downloads the required clojure/contrib jars (at least > > the comment in the el-file says so). How do I know what version it > > will fetch? How does it know when to update those jars? > > It will only download anything if ~/.swank-clojure and ~/.clojure > don't exist. Ah, then that's my problem. I already have a ~/.clojure/ directory with a user.clj, the leiningen jar, and some additional jars, but not swank-clojure.jar. ~/.swank-clojure doesn't exist, though. > If you create either of those directories manually and populate it > with clojure.jar, clojure-contrib.jar and swank-clojure.jar (and any > other jars you like) then you can use whatever versions you like. To get swank-clojure.jar I need to check out the project from github and use "lein jar" to generate the jar, right? Or is it possible to download a ready-made jar? > Also note that they're only used when you use M-x slime. If you use > M-x swank-clojure-project instead then it'll add these subdirectories > to the classpath: > > src/ > classes/ > lib/*.jar > > So for example if you have a leiningen project and run lein deps so > the lib directory is populated with clojure, contrib, swank-clojure > and anything else your project needs, then when you run M-x > swank-clojure-project and point it at your project's directory, it'll > completely disregard ~/.swank-clojure and use those jars. Isn't it a bad idea to include all deps into a project, so that one ends up with so much duplication? 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 To unsubscribe, reply using "remove me" as the subject.
Re: My non-ELPA Emacs swank-clojure setup
Tassilo Horn writes: > To me, all this stuff seems to magical, for example that swank-clojure > downloads the required clojure/contrib jars (at least the comment in the > el-file says so). How do I know what version it will fetch? How does > it know when to update those jars? It will only download anything if ~/.swank-clojure and ~/.clojure don't exist. If you create either of those directories manually and populate it with clojure.jar, clojure-contrib.jar and swank-clojure.jar (and any other jars you like) then you can use whatever versions you like. Also note that they're only used when you use M-x slime. If you use M-x swank-clojure-project instead then it'll add these subdirectories to the classpath: src/ classes/ lib/*.jar So for example if you have a leiningen project and run lein deps so the lib directory is populated with clojure, contrib, swank-clojure and anything else your project needs, then when you run M-x swank-clojure-project and point it at your project's directory, it'll completely disregard ~/.swank-clojure and use those jars. -- 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 To unsubscribe, reply using "remove me" as the subject.
Re: My non-ELPA Emacs swank-clojure setup
On Thursday 08 April 2010 12:08:37 Pelayo Ramón wrote: Hi! > > M-x slime RET > > > > I only get this error: > > > > , > > | Clojure 1.1.0 > > | user=> java.io.FileNotFoundException: Could not locate > > swank/swank__init.class or swank/swank.clj on classpath: (NO_SOURCE_FILE:0) > > | user=> user=> java.lang.ClassNotFoundException: swank.swank > > (NO_SOURCE_FILE:0) > > | user=> user=> nil > > | java.lang.ClassNotFoundException: swank.swank (NO_SOURCE_FILE:0) > > ` > > > > What's wrong? > > That's the same error I've commented in another discussion. I had to > download the swank-clojure.jar and point classpath to its directory Hm, but the docs say that swank-clojure.jar would be downloaded as soon as I do M-x slime. ,[ ~/.emacs.d/elpa/swank-clojure-1.1.0/swank-clojure.el ] | ;; 1. Standalone: If you just hit M-x slime, swank-clojure will | ;;download the jars for Clojure, contrib, and swank-clojure, | ;;launch an instance, and connect to it. If you just want to try | ;;out Clojure, this is all you need. Just get Swank Clojure | ;;through ELPA (http://tromey.com/elpa) and stop reading here. ` In *Messages* nothing indicates that it tries to download anything... 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 To unsubscribe, reply using "remove me" as the subject.
Re: My non-ELPA Emacs swank-clojure setup
> M-x slime RET > > I only get this error: > > , > | Clojure 1.1.0 > | user=> java.io.FileNotFoundException: Could not locate > swank/swank__init.class or swank/swank.clj on classpath: (NO_SOURCE_FILE:0) > | user=> user=> java.lang.ClassNotFoundException: swank.swank > (NO_SOURCE_FILE:0) > | user=> user=> nil > | java.lang.ClassNotFoundException: swank.swank (NO_SOURCE_FILE:0) > ` > > What's wrong? > > Bye, > Tassilo That's the same error I've commented in another discussion. I had to download the swank-clojure.jar and point classpath to its directory with (setq swank-clojure-extra- classpaths (list "/home/user/.clojure")) in the .emacs . Still have to report the log messages, I'm working in windows atm and I didn't have time to log into linux. I will this afternoon. -- 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 To unsubscribe, reply using "remove me" as the subject.
Re: New clojure support in Polyglot Maven
On 08/04/2010, at 5:45 PM, Jarkko Oranen wrote: > Looks cool. This should help the XML-allergic :) > > Though, is there a reason why all symbol arguments to defmodel have to > be quoted? It looks rather unpleasant. Seems like you should be able > to fix that by changing the body of defmaven to > `(reset! *MODEL* (Model ~@(for [a args] `(quote ~a > > Another possible approach is to wrap the free key-value pairs in a map > or a vector so that it's easy to quote the whole form. The point is that the unlike defproject, the body is assumed to be executable content, rather than just data. And you can do :dependencies '[[org.clojure/clojure-contrib "1.2.0-SNAPSHOT"] ... [hiccup "0.2.3"]] which reduces the amount of quoting. In fact, this defmaven form: (defmaven 'org.clojure/clojure "1.2.0-master-SNAPSHOT" :model-version "4.0.0" :name "Lamdras Website" :description "Acumen / LRMDS Integration" :properties { :project.build.sourceEncoding "UTF-8" } :packaging "war" :dependencies [['ring/ring-servlet "0.2.0-RC2"] ['ring/ring-devel "0.2.0-RC2"] ['clj-routing/ "0.1.0-SNAPSHOT"] ['clout "0.2.0-SNAPSHOT"] ['compojure "0.4.0-SNAPSHOT"] ['hiccup "0.1.0-SNAPSHOT"] 'org.clojure/clojure 'org.clojure/clojure-contrib 'congomongo/congomongo] :provided-dependencies [['org.mortbay.jetty/servlet-api-2.5 "6.1.14"]] :build [:final-name "website" :plugins [['org.apache.maven.plugins/maven-compiler-plugin "2.1" :source "1.6" :target "1.6"] ['com.theoryinpractise/clojure-maven-plugin "1.3.1" :sourceDirectories ["src/main/java"] :executions [[:id "compile-clojure" :phase "compile" :goals ["compile" ['org.mortbay.jetty/maven-jetty-plugin "6.1.10" :scanIntervalSeconds 10 :stopKey "foo" :stopPort ]]]) has an equivalent, canonical representation something like this: (Model :group-id "org.clojure" :artifact-id "clojure" :version "1.2.0-master-SNAPSHOT" :model-version "4.0.0" :name "Lamdras Website" :description "Acumen / LRMDS Integration" :properties { :project.build.sourceEncoding "UTF-8" } :packaging "war" :dependencies [(Dependency :group-id "ring" :artifact-id "ring-servlet" :version "0.2.0-RC2") (Dependency :group-id "ring" :artifact-id "ring-devel" :version "0.2.0-RC2") (Dependency :group-id "clj-routing" :artifact-id "clj-routing" :version "0.1.0-SNAPSHOT") (Dependency :group-id "clout" :artifact-id "clout" :version "0.2.0-SNAPSHOT") (Dependency :group-id "compojure" :artifact-id "compojure" :version "0.4.0-SNAPSHOT") (Dependency :group-id "hiccup" :artifact-id "hiccup" :version "0.1.0-SNAPSHOT") (Dependency :group-id "org.clojure" :artifact-id "clojure") (Dependency :group-id "org.clojure" :artifact-id "clojure-contrib") (Dependency :group-id "congomongo" :artifact-id "congomongo") (Dependency :group-id "org.mortbay.jetty" :artifact-id "servlet-api-2.5" :version "6.1.14" scope: "provided")] :build (Build :final-name "website" :plugins [(Plugin :group-id "org.apache.maven.plugins" :artifact-id "maven-compiler-plugin" :version "2.1" :configuration: [[:source "1.6"] [:target "1.6"]]) (Plugin :group-id "com.theoryinpractise" :artifact-id "clojure-maven-plugin" :version "1.3.1" :configuration [[:sourceDirectories [[:sourceDirectory "src/main/java" :executions [(Execution :id "compile-clojure" :phase "compile" :goals ["compile"])]) (Plugin :group-id "org.mortbay.jetty" :artifact-id "maven-jetty-plugin" :version "6.1.10" :configuration [[:scanIntervalSeconds 10] [:stopKey "foo"] [:stopPort ]])])) where Model, Dependency, Build,. Plugin, Execution (and many more) are functions that create e.g. org.apache.maven.model.Model and set the properties from key/value arguments. There are a variety of shortcuts built into the functions e.g. knowing the type of each field - which for the maven model is even possible for List<> generics due to the presence of parallel addXXX(YYY) methods for every setXXX(List) which gives you the erased parameter of the list generic - allows you to elide the type constructor. The :configuration elements are more complicated than I've shown because they need to generate nearly fill XML with attributes and namespaces (but not mixed content). Hopefully you can see that this syntax falls out of the direct construction of maven Model object, unmediated by intermediate syntax or data structuring. So there's a good reason for the way it looks. Antony Blakey - CTO, Linkuistics Pty Ltd Ph: 0438 840 787 A reasonable man adapts himself to su
Re: My non-ELPA Emacs swank-clojure setup
On Thursday 08 April 2010 07:08:43 Phil Hagelberg wrote: Hi Phil, > Both those options sound like an awful lot of work. I'm curious as to > what advantages there are to this method over the original > installation instructions. To me, all this stuff seems to magical, for example that swank-clojure downloads the required clojure/contrib jars (at least the comment in the el-file says so). How do I know what version it will fetch? How does it know when to update those jars? I already installed leiningen, so all clojure files are already contained in leiningen-1.1.0-standalone.jar somewhere in ~/.m2/repository/. Can I use those somehow? > Do you realize that package.el is going to be included in Emacs 24? Well, in general I think that's a good thing. But it has to be enhanced with better version checking. For example, I used to have a SLIME CVS checkout and used that for my lisp editing needs. But swank-clojure from ELPA requires some older SLIME version only accible via ELPA again. This "use one ELPA package and catch (already accessible duplicate) dependencies" is a bad thing, IMO. But I guess it will become better as soon as ELPA matures and is accepted as emacs package standard. BTW: Now I installed slime, slime-repl, clojure-mode and swank-clojure from ELPA. I symlinked the leiningen-1.1.0-standalone.jar in the maven repo from ~/.clojure/ so that the jar should be picked up. When I do M-x slime RET I only get this error: , | Clojure 1.1.0 | user=> java.io.FileNotFoundException: Could not locate swank/swank__init.class or swank/swank.clj on classpath: (NO_SOURCE_FILE:0) | user=> user=> java.lang.ClassNotFoundException: swank.swank (NO_SOURCE_FILE:0) | user=> user=> nil | java.lang.ClassNotFoundException: swank.swank (NO_SOURCE_FILE:0) ` What's wrong? 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 To unsubscribe, reply using "remove me" as the subject.
Re: New clojure support in Polyglot Maven
Looks cool. This should help the XML-allergic :) Though, is there a reason why all symbol arguments to defmodel have to be quoted? It looks rather unpleasant. Seems like you should be able to fix that by changing the body of defmaven to `(reset! *MODEL* (Model ~@(for [a args] `(quote ~a Another possible approach is to wrap the free key-value pairs in a map or a vector so that it's easy to quote the whole form. -- 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