ANN: core.unify v0.5.2
core.unify v0.5.2 Release Notes === core.unify is a Clojure contrib library providing the following features: * Factory functions for constructing unification binding, subst, and unification functions, with or without occurs checking * Packaged functions for unification binding, subst, and unification functions, with or without occurs checking, recognizing variables tagged as symbols prefixed with `?` characters core.unify is based on a library named Unifycle, found at http://github.com/fogus/unifycle that has been deprecated. This is likely the last release before the performance work begins. Absorb -- You can use core.unify in your [Leiningen](https://github.com/ technomancy/leiningen) and [Cake](https://github.com/flatland/cake) projects with the following `:dependencies` directive in your `project.clj` file: [org.clojure/core.unify 0.5.2] For Maven-driven projects, use the following slice of XML in your `pom.xml`'s `dependencies` section: dependency groupIdorg.clojure/groupId artifactIdcore.unify/artifactId version0.5.2/version /dependency Enjoy! Places -- * [Source code](https://github.com/clojure/core.unify) * [Ticket system](http://dev.clojure.org/jira/browse/UNIFY) * [Examples and documentation](http://fogus.me/fun/unifycle) -- in progress Changes from version 0.5.1 -- * Removed all reflection warnings in the code. (thanks goes to André Thieme for pointing them out) * More tests around common unification edge cases. Plans - The following capabilities are under design, development, or consideration for future versions of core.unify: * High-performant unification based on unrolling recursive backtracking into polymorphic calls * Iterative unification option * Boolean unification * Implicit variable recognition option(s) * More examples * More documentation More planning is needed around capabilities not listed nor thought of. -- 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: Trying to understand variable capture
Macro expansion time is not run time, is it? Thanks. :-) On Jan 8, 2:59 pm, Michael Fogus mefo...@gmail.com wrote: The names in the first let only exist at compile time and do not exist when the expanded form eventually runs. -- 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: Help with binding
Cedric - thanks. I'm new to Clojure and after posting this realized that I could/should use one of the do* approaches. I ended up using doseq and it worked great. 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: Difference between clojure.lang.Cons and clojure.lang.PersistenList
Yes, seq? works. Thanks for the help! On Sun, Jan 8, 2012 at 9:03 PM, Cedric Greevey cgree...@gmail.com wrote: On Sun, Jan 8, 2012 at 10:30 AM, Samuel Lê samuel...@gmail.com wrote: Hi and Happy New Year to all the Clojure mailing list, I am am having some trouble with the two classes Cons and PersistentList: user (class (conj (map #(+ % 1) '(1 2 3)) 4)) clojure.lang.Cons user (class '(1 2 3 4)) clojure.lang.PersistentList My problem is that list? returns false for a Cons and true for a PersistentList. What can I do to make my Cons a PersistentList, or is there a way to use another function instead of list? that will return true for both classes? If any (...) structure will do, test with seq? instead. If you really need a PersistentList, you'll probably have to call that class's constructor or resort to icky hacks like user= (class (apply list (cons 4 '(1 2 3 clojure.lang.PersistentList (though much more evil would be user= (class (eval `(quote ~(cons 4 '(1 2 3) clojure.lang.PersistentList instead), because for some odd reason and despite its name (list* 4 '(1 2 3)) returns a clojure.lang.Cons. -- 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: Bug with ClojureScript keyword? function
Apologies, there was a typo in my original email, what I meant to say was that: (js/alert (keyword? :foobar)) output result = false was compiled to = alert.call(null,cljs.core.keyword_QMARK_.call(null, 'foobar)); (js/alert (string? :foobar)) output result = true was compiled to = alert.call(null,cljs.core.string_QMARK_.call(null, 'foobar)); The actual object that was passed to both clj.core.string_QMARK_ and keyword_QMARK_ is a string with a 3 character bytestring of hex values 0xef 0xb7 0x90, followed by quote ' and the keyword string (foobar in this case). Is this a bug in the conversion of the clojure keyword to the JavaScript object? On Jan 9, 4:50 am, Michael Fogus mefo...@gmail.com wrote: In the compiled code it looks like the call to keyword? Is happening in both cases. Wires are definitely crossed, but it's unclear where. Are you certain that the ClojureScript shown is the same code that gets compiled? -- 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: Two Slightly Different Versions Using lazy-seq: One works, One doesn't. Why?
For some reason I never saw either my first post nor your answer to it. It was my first post to the group, so I thought maybe it had been swallowed up (maybe the moderators had to approve my membership before I could post or something), so after waiting a day, I posted again. And...not 5 minutes after sending the second post, I saw the difference. The one that works is a def, and my version is a defn, whoops. So of course to use mine I'd have to say (take 7 (fib-seq- used-to-fail-but-works-great-now)). And all my lazy-seqs everywhere are working now, hooray. Thanks, -Tom On Jan 8, 12:59 pm, Michael Fogus mefo...@gmail.com wrote: See my answer in the other, seemingly identical thread. -- 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: Two Slightly Different Versions Using lazy-seq: One works, One doesn't. Why?
For some reason I never saw either my first post nor your answer to it. It was my first post to the group, so I thought maybe it had been swallowed up (maybe the moderators had to approve my membership before I could post or something), so after waiting a day, I posted again. And...not 5 minutes after posting this second one, I saw the difference. The one that works is a def, and my version is a defn, whoops. So of course to use mine I'd have to say (take 7 (fib-seq-used-to-fail-but-works-great-now)). And all my lazy-seqs everywhere are working now, hooray. Thanks, -Tom On Sun, Jan 8, 2012 at 12:59 PM, Michael Fogus mefo...@gmail.com wrote: See my answer in the other, seemingly identical thread. -- 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: Bug with ClojureScript keyword? function
Is this a bug in the conversion of the clojure keyword to theJavaScript object? I think there's probably an issue with string conversion in your program. In ClojureScript keywords are not separate objects. Instead they are simply strings that start with a bizarre unicode character. Example from core.cljs: (defn string? [x] (and (goog/isString x) (not (or (= (.charAt x 0) \uFDD0) (= (.charAt x 0) \uFDD1) (defn keyword? [x] (and (goog/isString x) (= (.charAt x 0) \uFDD0))) I'd start at the repl and investigate out the Unicode values. That may help debug this a bit. Timothy -- 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
Templating, how to?
I want to generate rules with constant and/or functions producing parts of the rules: (defn rulemaker [] (str SCOPE global-constant ; (some-global-function) ;)) which could be called with (with-super-closure model-in-file-reference (rulemaker)) Is there a way to make some temporary global constants that could be reached from a function without passing it the this state or closure explicitly? What's the simpler way? Should I simply make a search-replace table which I prepare and run all the templates through or is there another way? I would love to be able not to pass around a state, like (defn rulemaker [z] (str SCOPE (some-generator-function z))) since that's a bit error-prone and verbose. Is this one of few occasions for a macro or should I somehow create a namespace or something explicitly for this code-generation? All magic allowed, since it's a very restricted domain that rather should be as convenient as possible to use. /Linus -- 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: Enlive reborn in ClojureScript - Enfocus (Dom Manipulation Lib)
On Sun, Jan 8, 2012 at 10:48 PM, Peter Taoussanis ptaoussa...@gmail.com wrote: I also get the impression that Enlive itself seems to be quite widely misunderstood and consequently underrated. Haven't had a chance to take a serious look at this yet myself (I will!), but just wanted to throw my support behind the idea. I'll +1 both of these sentiments. I use Enlive for HTML emails that we send out at World Singles and we're pretty happy with it so I expect once we start using ClojureScript, we'd be interested in Enfocus. -- Sean A Corfield -- (904) 302-SEAN An Architect's View -- http://corfield.org/ World Singles, LLC. -- http://worldsingles.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: mysql and fruit tables
On Sun, Jan 8, 2012 at 8:26 PM, jayvandal s...@ida.net wrote: I have been able to access tables in mysql, but not able to add records. I look at the examples fo fruit so I created a lein named fruitI made th project file as the mysql project file. I copied the database instructions as in mysql. I added all of the statements for the fruit example but I can't even get it to access the connection or the database You must provide more detail when asking questions: what is the exact error message / problem you see? How exactly are you running your code (you never answer this one)? Here is the project file ; defproject fruit 1.0.0-SNAPSHOT :description FIXME: write description :dependencies [[org.clojure/clojure 1.3.0]] [org.clojure/java.jdbc 0.0.6] [mysql/mysql-connector-java 5.1.6]) I assume you haven't pasted this correctly? There was no ( before defproject and you close the dependencies on line 3 so java.jdbc and mysql-connector-java are not part of that list. Here's what it should look like: (defproject fruit 1.0.0-SNAPSHOT :description FIXME: write description :dependencies [[org.clojure/clojure 1.3.0] [org.clojure/java.jdbc 0.0.6] [mysql/mysql-connector-java 5.1.6]]) (defn db {:classname com.mysql.jdbc.Driver :subprotocol mysql :subname //localhost:3306/world :user root :password pass}) This should be a def not a defn. (defn create-fruit [] (sql/with-connection db (sql/create-table :fruit [:id :integer PRIMARY KEY AUTO_INCREMENT] [:name varchar(25)] [:appearance varchar(25)] [:cost integer(5)])) You're missing a closing parenthesis here. (defn insert-rows-fruit Insert complete rows [] (sql/insert-rows :fruit [Apple red 59 87] [Banana yellow 29 92.2] [Peach fuzzy 139 90.0] [Orange juicy 89 88.6])) This doesn't match how you declared the table: you declared ID (integer), NAME (varchar), APPEARANCE (varchar), COST (integer) but you are trying to insert string, string, integer, double. The http://clojure.github.com/java.jdbc documentation is correct but you have changed the code to something that does not work. -- Sean A Corfield -- (904) 302-SEAN An Architect's View -- http://corfield.org/ World Singles, LLC. -- http://worldsingles.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: ANN: core.unify v0.5.2
On Mon, Jan 9, 2012 at 8:00 AM, Fogus mefo...@gmail.com wrote: core.unify v0.5.2 Release Notes === core.unify is a Clojure contrib library providing the following features: * Factory functions for constructing unification binding, subst, and unification functions, with or without occurs checking * Packaged functions for unification binding, subst, and unification functions, with or without occurs checking, recognizing variables tagged as symbols prefixed with `?` characters Yes, but what exactly are these unification binding, subst, and unification functions? In other words, I'm a developer. I have some concrete problems. Which of those can this library help solve, and how? What, in short, is it good for? Unfortunately, the description you provided seems to use solution domain language only, not problem domain. Someone who doesn't know what this unification stuff is all about won't have any idea whether or how this library might be useful to them. -- 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: Difference between clojure.lang.Cons and clojure.lang.PersistenList
On Sun, Jan 8, 2012 at 4:11 PM, Samuel Lê samuel...@gmail.com wrote: Yes, seq? works. Thanks for the help! You're welcome. -- 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: Help with binding
On Mon, Jan 9, 2012 at 7:48 AM, Matthew Giannini matthew.giann...@gmail.com wrote: Cedric - thanks. I'm new to Clojure and after posting this realized that I could/should use one of the do* approaches. I ended up using doseq and it worked great. Thanks. You're welcome. -- 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: Templating, how to?
On Mon, Jan 9, 2012 at 10:36 AM, Linus Ericsson oscarlinuserics...@gmail.com wrote: I want to generate rules with constant and/or functions producing parts of the rules: (defn rulemaker [] (str SCOPE global-constant ; (some-global-function) ;)) which could be called with (with-super-closure model-in-file-reference (rulemaker)) Is there a way to make some temporary global constants that could be reached from a function without passing it the this state or closure explicitly? What's the simpler way? Should I simply make a search-replace table which I prepare and run all the templates through or is there another way? I would love to be able not to pass around a state, like (defn rulemaker [z] (str SCOPE (some-generator-function z))) since that's a bit error-prone and verbose. Is this one of few occasions for a macro or should I somehow create a namespace or something explicitly for this code-generation? All magic allowed, since it's a very restricted domain that rather should be as convenient as possible to use. Dynamic binding is often used for this sort of purpose. It has caveats, though, particularly when the binding is used in generating a lazy seq. If the seq is passed out of the binding's scope while still at least partly unrealized, attempting to realize the remaining elements may not go as planned. -- 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: ClojureScript – inter-namespace usage
Hi Shantanu, #1 is a bug. #2 is not possible because `import` doesn't exist in ClojureScript: it doesn't differentiate between host classes and ClojureScript code. Protocols and types should be accessible with normal `require` in ClojureScript. #3 seems unlikely to be implemented. ClojureScript doesn't have Vars, and it doesn't have threads, so there's not much for `binding` to do. I could see `with-redefs` being supported, however. -S -- 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: ClojureScript – inter-namespace usage
On Mon, Jan 9, 2012 at 1:18 PM, Stuart Sierra the.stuart.sie...@gmail.com wrote: #3 seems unlikely to be implemented. ClojureScript doesn't have Vars, and it doesn't have threads, so there's not much for `binding` to do. I could see `with-redefs` being supported, however. Actually, the lack of threads just simplifies the heck out of implementing binding: push the current value onto some stack and assign a new value at the start, and pop the old value off the stack and restore it at the end. Which boils down to with-redefs, so binding could just be made to be a kind of alias for that in ClojureScript. It would increase source portability between the two to make both names invoke this functionality and not just with-redefs, though. -- 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: ANN: core.unify v0.5.2
Yes, but what exactly are these unification binding, subst, and unification functions? This is information that seems a bit odd to include in a set of release notes, but I suppose a link to where such information could be found is warranted. In other words, I'm a developer. I have some concrete problems. Which of those can this library help solve, and how? I have no idea what kinds of problems you're trying to solve. Unfortunately, the description you provided seems to use solution domain language only, not problem domain. Someone who doesn't know what this unification stuff is all about won't have any idea whether or how this library might be useful to them. This is a 0.5.2 set of release notes meant as information for people currently using the library. If you want more information on unification then you'll need to wait until a later release. Google also helps too. :-) -- 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: core.logic, leiningen, clj-stacktrace: someone eats my backtraces
Tassilo Horn tass...@member.fsf.org writes: One thing that really made the programming extremely hard was that I don't get any backtraces if an exception occurs inside a `run'. For example, I get this in SLIME with M-x clojure-jack-in RET. (defn wrongo [a b] false) ;; intentionally broken ;= #'logic-introduction.extend/wrongo (run* [q] (wrongo 1 2)) ; Evaluation aborted. Does the problem only happen with specific exceptions coming from core.logic or is it a general problem? If it's the latter I'm afraid I can't reproduce, so I need more details before I can do anything. If you can find the places where clj-stacktrace is used inside swank-clojure and wrap them in try/catches that do .printStackTrace you might be able to discover more about the cause. Or if it's something specific to using core.logic please provide steps for how to reproduce, preferably in the issue tracker. thanks, 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
Re: ANN: core.unify v0.5.2
On Mon, Jan 9, 2012 at 1:45 PM, Michael Fogus mefo...@gmail.com wrote: Yes, but what exactly are these unification binding, subst, and unification functions? This is information that seems a bit odd to include in a set of release notes, but I suppose a link to where such information could be found is warranted. It's usual for release notes to at least link to more complete documentation, but not uncommon for them to also have a quick summary paragraph explaining what the application or library does or is for. Particularly if they get posted to lists like this, where they might be the way someone first hears about it. More generally, Foo is a library providing the following features: is usually followed by something that developers can immediately understand as something useful, such as DOM parsing or raytracing or GUI framework. This seemed to be more mathematical in character, or perhaps described in terms of its implementation or some other abstraction, rather than in terms of what a prospective user of the library would actually use it for. In other words, I'm a developer. I have some concrete problems. Which of those can this library help solve, and how? I have no idea what kinds of problems you're trying to solve. Er ... how about what problems or tasks would cause a developer who already knew all about your library to reach for it in preference to some other tool, and why? then. Unfortunately, the description you provided seems to use solution domain language only, not problem domain. Someone who doesn't know what this unification stuff is all about won't have any idea whether or how this library might be useful to them. This is a 0.5.2 set of release notes meant as information for people currently using the library. If you want more information on unification then you'll need to wait until a later release. That doesn't help grow your user base/beta tester base/whatever, though, does it? Google also helps too. :-) Not really, not with a single fairly generic word like unification. Right off the top of my head I can think of several political causes, a few format standardization efforts, and at least one Star Trek episode with that word in the name, of which the format standardization efforts are the only ones that sound like they could plausibly be relevant here. No doubt there's lots more uses of the word and most of those are also not likely to be relevant. -- 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: ANN: core.unify v0.5.2
On Mon, Jan 9, 2012 at 11:00 AM, Cedric Greevey cgree...@gmail.com wrote: On Mon, Jan 9, 2012 at 1:45 PM, Michael Fogus mefo...@gmail.com wrote: Google also helps too. :-) Not really, not with a single fairly generic word like unification. #1 result: wikipedia, which has a disambiguation page with the second entry: Unification (computer science), the act of identifying two terms with a suitable substitution That page in turn says: Unification, in computer science and logic, is an algorithmic process by which one attempts to solve the satisfiability problem. The goal of unification is to find a substitution which demonstrates that two seemingly different terms are in fact either identical or just equal. Unification is widely used in automated reasoning, logic programming and programming language type system implementation. I don't know whether that definition helps you? It's hard for me to know what most developers know about unification because I've worked in Prolog so I suspect I'm an edge case (and I'm excited about core.unify - I just haven't needed it in my production code yet). -- Sean A Corfield -- (904) 302-SEAN An Architect's View -- http://corfield.org/ World Singles, LLC. -- http://worldsingles.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: ANN: core.unify v0.5.2
Not really, not with a single fairly generic word like unification. In the amount of time that you spent lecturing me on good library release note practices you could have learned what unification was, read the code, and decided if it filled any of your needs. Hint. My library has very little if nothing to do with Star Trek. -- 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: ClojureScript – inter-namespace usage
#3 seems unlikely to be implemented. ClojureScript doesn't have Vars, and it doesn't have threads, so there's not much for `binding` to do. I could see `with-redefs` being supported, however. Hi Stuart, Thanks for the pointers. So, I am trying to understand what is the canonical way to write code that works the same on both Clojure and ClojureScript. When I use `binding` my intentions are: 1. Rebind the dynamic vars with common parameters so that the intermediate calls don't need to pass the args around. 2. Make it local to the current thread if the platform supports multi- threading. If ClojureScript were to fall back to internally using `with-redefs` every time it encountered `binding` that should be OK because there is no multi-threading on the platform. Is it possible to detect the current environment (CLJ vs CLJS) and execute separate code based on that? Shantanu -- 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: ANN: core.unify v0.5.2
On Mon, Jan 9, 2012 at 2:08 PM, Sean Corfield seancorfi...@gmail.com wrote: On Mon, Jan 9, 2012 at 11:00 AM, Cedric Greevey cgree...@gmail.com wrote: On Mon, Jan 9, 2012 at 1:45 PM, Michael Fogus mefo...@gmail.com wrote: Google also helps too. :-) Not really, not with a single fairly generic word like unification. #1 result: wikipedia, which has a disambiguation page with the second entry: Unification (computer science), the act of identifying two terms with a suitable substitution That page in turn says: Unification, in computer science and logic, is an algorithmic process by which one attempts to solve the satisfiability problem. The goal of unification is to find a substitution which demonstrates that two seemingly different terms are in fact either identical or just equal... In other words, a particular one out of ten links, followed by some other link, followed by a particular one out of some *more* links, leads to something abstruse and theoretical that *still* has no immediately obvious implications for any real-world programming project other than, possibly, a compiler's optimizer or type inference system. And meanwhile there's nothing in what you wrote to eliminate the possibility that other chains of links from the Google search wouldn't lead to other plausibly-relevant subject matters. Such as the standard-setting efforts and suchlike. :) -- 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: ANN: core.unify v0.5.2
unify, but I have no idea where to begin! Having short description and some simple use cases in announce would be great. I do not disagree. Those elements will be in place by the 1.0.0 release (as listed in the planned section). In the meantime, patches welcomed. -- 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: ANN: core.unify v0.5.2
On Mon, Jan 9, 2012 at 2:16 PM, Michael Fogus mefo...@gmail.com wrote: Not really, not with a single fairly generic word like unification. In the amount of time that you spent lecturing me on good library release note practices you could have learned what unification was, read the code, and decided if it filled any of your needs. Perhaps, given mind-reading powers and one or two other unusual capabilities, I might have been able to do so, yes. :) Hint. My library has very little if nothing to do with Star Trek. Talk about completely missing the point. I think I was pretty clear myself that that was the case; I was just indicating that the Google search would produce a thicket of results in which it would be difficult to find one that actually could definitely enlighten as to what your library was all about, *both* due to the amount of obviously-irrelevant clutter in said results *and* because there'd be multiple plausibly-relevant but dissimilar candidates after said clutter was mentally weeded out. The search query would need to be narrower than just the word unification, in other words. -- 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: ClojureScript – inter-namespace usage
On Mon, Jan 9, 2012 at 2:20 PM, Shantanu Kumar kumar.shant...@gmail.com wrote: #3 seems unlikely to be implemented. ClojureScript doesn't have Vars, and it doesn't have threads, so there's not much for `binding` to do. I could see `with-redefs` being supported, however. Hi Stuart, Thanks for the pointers. So, I am trying to understand what is the canonical way to write code that works the same on both Clojure and ClojureScript. When I use `binding` my intentions are: 1. Rebind the dynamic vars with common parameters so that the intermediate calls don't need to pass the args around. 2. Make it local to the current thread if the platform supports multi- threading. If ClojureScript were to fall back to internally using `with-redefs` every time it encountered `binding` that should be OK because there is no multi-threading on the platform. Is it possible to detect the current environment (CLJ vs CLJS) and execute separate code based on that? It's a library macro and CLJ and CLJS have different versions of the library. They already behave differently: binding works in CLJ and produces a not found error in CLJS. Adding a binding macro (that just punts to with-redefs) to the CLJS library would suffice (given a CLJS with-redefs implementation, of course). -- 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: [ClojureScript] My implementation of ISeqable for NodeList doesn't work on Opera.
I would like to have NodeList be seqable. Please file a ticket with a patch. Perhaps someone else can shed light on why Opera doesn't work. -S -- 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: ANN: core.unify v0.5.2
On Mon, Jan 9, 2012 at 3:20 PM, Cedric Greevey cgree...@gmail.com wrote: Talk about completely missing the point. I had no idea what core.unify would be used for either. However, the email included a link to the github page, and the Readme on the github page included a link called more information and several other references. If you chose not to go down that path, it's your own fault. -- 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: core.logic, leiningen, clj-stacktrace: someone eats my backtraces
Phil Hagelberg p...@hagelb.org writes: Hi Phil, One thing that really made the programming extremely hard was that I don't get any backtraces if an exception occurs inside a `run'. For example, I get this in SLIME with M-x clojure-jack-in RET. (defn wrongo [a b] false) ;; intentionally broken ;= #'logic-introduction.extend/wrongo (run* [q] (wrongo 1 2)) ; Evaluation aborted. Does the problem only happen with specific exceptions coming from core.logic or is it a general problem? It seems to be specific to exceptions thrown inside core.logic. For example, all those put me in the SLIME debugger just as it should be: (run* [q] (/ 1 0)) = ArithmeticException (run* [q] (wrongo 1)) = ArityException However, exceptions thrown inside core.logic don't show up. (run* [q] (wrongo 1 2)) ; Evaluation aborted. (clojure.repl/pst *e) ClassCastException java.lang.Boolean cannot be cast to clojure.lang.IFn clojure.core.logic.Substitutions (logic.clj:207) de.uni-koblenz.ist.funtg.funrl/eval5744/fn--5745/fn--5746/-inc--5747 (NO_SOURCE_FILE:1) clojure.core.logic/eval2975/fn--2976/fn--2977 (logic.clj:885) clojure.lang.LazySeq.sval (LazySeq.java:42) clojure.lang.LazySeq.seq (LazySeq.java:67) clojure.lang.RT.seq (RT.java:466) clojure.core/seq (core.clj:133) clojure.core/take/fn--3836 (core.clj:2499) clojure.lang.LazySeq.sval (LazySeq.java:42) clojure.lang.LazySeq.seq (LazySeq.java:60) clojure.lang.RT.seq (RT.java:466) clojure.core/seq (core.clj:133) nil If you can find the places where clj-stacktrace is used inside swank-clojure and wrap them in try/catches that do .printStackTrace you might be able to discover more about the cause. Or if it's something specific to using core.logic please provide steps for how to reproduce, preferably in the issue tracker. I'll do so, but not this evening. Now that I know of *e and `pst', it lost much of its importance, anyway. :-) 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
Need help to translate a simple java program into Clojure program
Hello, I'm new to functional programming and Clojure and I'm trying to translate a simple java program into Clojure. My program must build from 2 input lists (stored in a vector) 2 output lists (also stored in a vector) which have same number of elements as input lists for both output lists. The elements' values of the output lists will be the result of a very simple arithmetical calculation based on input lists' elements. Since my java program iterates on lists, I wanted to use a 'higher order function' in the Clojure version of the program (like the 'map' function). But I didn't manage to write the equivalent program in Clojure. Could someone please help me? Below is the java program that I'd like to translate. Thanks a lot, Regards, Nicolas // first file (these are the elements of my lists): public class Pos { public String name; public int value; public Pos(String newName, int newValue) { name = newName; value = newValue; } @Override public String toString() { return Name: + name + , Value: + value + \n; } } // second file that contains the method I'd like to translate using a higher order function (method called match): import java.util.ArrayList; import java.util.List; import java.util.Vector; public class Matching { public static void main(String[] args) throws Exception { ListPos options = new ArrayListPos(5); Pos option1 = new Pos(IBM, -50); Pos option2 = new Pos(ACCOR, -30); Pos option3 = new Pos(IBM, -10); Pos option4 = new Pos(APPLE, -20); Pos option5 = new Pos(AIRFRANCE, -20); options.add(option1); options.add(option2); options.add(option3); options.add(option4); options.add(option5); ListPos actions = new ArrayListPos(4); Pos action1 = new Pos(IBM, 55); Pos action2 = new Pos(ACCOR, 40); Pos action3 = new Pos(AIRFRANCE, 10); Pos action4 = new Pos(LUFTHANSA, 100); actions.add(action1); actions.add(action2); actions.add(action3); actions.add(action4); VectorListPos input = new VectorListPos(2); input.set(0, options); input.set(1, actions); System.out.println(Options: + options); System.out.println(Actions: + actions); VectorListPos res = Matching.match(input); System.out.println(Options: + res.get(0)); System.out.println(Actions: + res.get(1)); } public static VectorListPos match(VectorListPos optionsAndActions) { if (optionsAndActions == null) { return optionsAndActions; } if (optionsAndActions.size() 2) { return optionsAndActions; } VectorListPos modifiedOptionsAndActions = new VectorListPos(2); if (optionsAndActions.get(1) == null) { modifiedOptionsAndActions.add(0, new ArrayListPos(optionsAndActions.get(0))); return modifiedOptionsAndActions; } else if (optionsAndActions.get(0) == null) { modifiedOptionsAndActions.add(1, new ArrayListPos(optionsAndActions.get(1))); return modifiedOptionsAndActions; } ArrayListPos modifiedOptions = new ArrayListPos(optionsAndActions.get(0)); ArrayListPos modifiedActions = new ArrayListPos(optionsAndActions.get(1)); modifiedOptionsAndActions.add(0, modifiedOptions); modifiedOptionsAndActions.add(1, modifiedActions); for (Pos option : modifiedOptions) { for (Pos action : modifiedActions) { if (option.name.equals(action.name)) { int tempActionValue = Math.max(0, action.value + option.value); int tempOptionValue = Math.min(0, action.value + option.value); action.value = tempActionValue; option.value = tempOptionValue; } } } return modifiedOptionsAndActions; } } -- 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
Problem with :pre checks against nil in 1.3.0?
Ok, I've got a couple thousand lines of Clojure under my belt, but this has me stumped, unless it's a compiler etc. issue. If I'm missing something dumb, what is it, please? I have a function that is failing a not-nil precondition. Here are four versions of the same test; only #3 works correctly. Obviously I can work around the problem, but am I doing something wrong? user (def fq (frequencies abbccc)) #'user/fq user fq {\a 1, \b 2, \c 3} user (fq \a) 1 user ; incorrectly fails :pre (defn test-fun1 [mp k] {:pre (not (nil? (mp k)))} (mp k)) #'user/test-fun1 user (test-fun1 fq \a) Assert failed: (nil? (mp k)) [Thrown class java.lang.AssertionError] user ; incorrectly fails :pre (defn test-fun2 [mp k] {:pre (not= nil (mp k))} (mp k)) #'user/test-fun2 user (test-fun2 fq \a) Assert failed: nil [Thrown class java.lang.AssertionError] user ; correctly survives :pre (defn test-fun3 [mp k] {:pre (not= 0 (mp k 0))} (mp k)) #'user/test-fun3 user (test-fun3 fq \a) 1 user ; incorrectly fails :pre (defn test-fun4 [mp k] {:pre (not= nil (mp k nil))} (mp k)) #'user/test-fun4 user (test-fun4 fq \a) Assert failed: nil [Thrown class java.lang.AssertionError] Thanks in advance, -Tom -- 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: ANN: core.unify v0.5.2
On Mon, Jan 9, 2012 at 3:43 PM, Jay Fields j...@jayfields.com wrote: On Mon, Jan 9, 2012 at 3:20 PM, Cedric Greevey cgree...@gmail.com wrote: Talk about completely missing the point. I had no idea what core.unify would be used for either. However, the email included a link to the github page, and the Readme on the github page included a link called more information and several other references. If you chose not to go down that path, it's your own fault. Neverminding the amount of indirection (once again), there's the minor matter that nobody is likely to click through to the github page of something unless they're already looking to download it, or maybe even modify it. You have to pitch people on the potential benefits of downloading your library *before* they click the download link for it, or they mostly never will. -- 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: Problem with :pre checks against nil in 1.3.0?
On Mon, Jan 9, 2012 at 12:53 PM, Tom Chappell tomchapp...@gmail.com wrote: Ok, I've got a couple thousand lines of Clojure under my belt, but this has me stumped, unless it's a compiler etc. issue. If I'm missing something dumb, what is it, please? I have a function that is failing a not-nil precondition. Here are four versions of the same test; only #3 works correctly. Obviously I can work around the problem, but am I doing something wrong? user (def fq (frequencies abbccc)) #'user/fq user fq {\a 1, \b 2, \c 3} user (fq \a) 1 user ; incorrectly fails :pre (defn test-fun1 [mp k] {:pre (not (nil? (mp k)))} (mp k)) #'user/test-fun1 user (test-fun1 fq \a) Assert failed: (nil? (mp k)) [Thrown class java.lang.AssertionError] user ; incorrectly fails :pre (defn test-fun2 [mp k] {:pre (not= nil (mp k))} (mp k)) #'user/test-fun2 user (test-fun2 fq \a) Assert failed: nil [Thrown class java.lang.AssertionError] user ; correctly survives :pre (defn test-fun3 [mp k] {:pre (not= 0 (mp k 0))} (mp k)) #'user/test-fun3 user (test-fun3 fq \a) 1 user ; incorrectly fails :pre (defn test-fun4 [mp k] {:pre (not= nil (mp k nil))} (mp k)) #'user/test-fun4 user (test-fun4 fq \a) Assert failed: nil [Thrown class java.lang.AssertionError] user (test-fun3 {} :foo) nil Looks to me like it is treating the second item of the seq following :pre as the entire test. I'd check the precondition documentation (wherever that is) as it looks like the syntax isn't just {:pre test-expr} but rather {:pre (something test-expr maybe-something-else)}. -- 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: ANN: core.unify v0.5.2
You have to pitch people on the potential benefits of downloading your library *before* they click the download link for it, or they mostly never will. Sold. I've learned my lesson. -- 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: Problem with :pre checks against nil in 1.3.0?
Try to put your :pre entries in a vector, like so: {:pre [(not= 0 (mp k 0))]} -- 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: Problem with :pre checks against nil in 1.3.0?
The precondition should be a vector of expressions. (defn foo [x] {:pre [(not (nil? x))]} (* 3 x)) On Jan 9, 2012, at 12:53 PM, Tom Chappell wrote: Ok, I've got a couple thousand lines of Clojure under my belt, but this has me stumped, unless it's a compiler etc. issue. If I'm missing something dumb, what is it, please? I have a function that is failing a not-nil precondition. Here are four versions of the same test; only #3 works correctly. Obviously I can work around the problem, but am I doing something wrong? user (def fq (frequencies abbccc)) #'user/fq user fq {\a 1, \b 2, \c 3} user (fq \a) 1 user ; incorrectly fails :pre (defn test-fun1 [mp k] {:pre (not (nil? (mp k)))} (mp k)) #'user/test-fun1 user (test-fun1 fq \a) Assert failed: (nil? (mp k)) [Thrown class java.lang.AssertionError] -- 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: [ClojureScript] My implementation of ISeqable for NodeList doesn't work on Opera.
Beware that NodeList is often a live collection, so it is probably a good idea to produce eager seq. I use this to convert it to seq: (defn nodelist-to-seq Converts nodelist to (not lazy) seq. [nl] (let [result-seq (map #(.item nl %) (range (.length nl)))] (doall result-seq))) -- 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: Need help to translate a simple java program into Clojure program
2012/1/9 Nicolas Garcin nicolas.etienne.gar...@gmail.com Hello, I'm new to functional programming and Clojure and I'm trying to translate a simple java program into Clojure. My program must build from 2 input lists (stored in a vector) 2 output lists (also stored in a vector) which have same number of elements as input lists for both output lists. The elements' values of the output lists will be the result of a very simple arithmetical calculation based on input lists' elements. Since my java program iterates on lists, I wanted to use a 'higher order function' in the Clojure version of the program (like the 'map' function). But I didn't manage to write the equivalent program in Clojure. Could someone please help me? Below is the java program that I'd like to translate. Thanks a lot, Regards, Nicolas I've started sketchy below, but the matching function would really be happier if it had one or two comments. Usually it's a lot easier to implement clojure code from algoritmic ideas rather than existing java code since they are quite different. For instance I would change the object to a hash map {:name :value} and NOT change the input vector, the actions taken would actually return a new nested vector. I guess you could make a much better algoritm in the matching function using reduce or some other higher order function. Also, null is nil which is mostly the same but less prone to break, which could probably remove a few of the if-statements as well. Sorry for sketchy answer, but hopefully it's a start. The solutions to the problem would be quite different than the java version, and the clojure version will be a somewhat more compact. Rich Hickey have made some really really good introductions to Clojure where he touches many of concepts you could have good use of in the code below named Clojure for Java Programmes pt 1 and 2 http://blip.tv/clojure/clojure-for-java-programmers-1-of-2-989128 http://blip.tv/clojure/clojure-for-java-programmers-2-of-2-989262 Hopefully this will get you started! /Linus // first file (these are the elements of my lists): public class Pos { public String name; public int value; public Pos(String newName, int newValue) { name = newName; value = newValue; } @Override public String toString() { return Name: + name + , Value: + value + \n; } } A pos could be described as {:name IBM :value 150}. (defn pos-str [pos] (str Name: (:name pos) , Value: (:value pos) \n)) // second file that contains the method I'd like to translate using a higher order function (method called match): import java.util.ArrayList; import java.util.List; import java.util.Vector; public class Matching { public static void main(String[] args) throws Exception { ListPos options = new ArrayListPos(5); Pos option1 = new Pos(IBM, -50); Pos option2 = new Pos(ACCOR, -30); Pos option3 = new Pos(IBM, -10); Pos option4 = new Pos(APPLE, -20); Pos option5 = new Pos(AIRFRANCE, -20); options.add(option1); options.add(option2); options.add(option3); options.add(option4); options.add(option5); ListPos actions = new ArrayListPos(4); Pos action1 = new Pos(IBM, 55); Pos action2 = new Pos(ACCOR, 40); Pos action3 = new Pos(AIRFRANCE, 10); Pos action4 = new Pos(LUFTHANSA, 100); actions.add(action1); actions.add(action2); actions.add(action3); actions.add(action4); VectorListPos input = new VectorListPos(2); input.set(0, options); input.set(1, actions); (ns matching.thing) (def options [{:name IBM :value -50} {...} ...]) (def actions [{:name IBM :value 55} {...} ...]) (def input [options actions]) ;;or just write everything in one declaration System.out.println(Options: + options); System.out.println(Actions: + actions); VectorListPos res = Matching.match(input); System.out.println(Options: + res.get(0)); System.out.println(Actions: + res.get(1)); (println Options: options) ... (println Matched: (match options)) ;;since you have immutability you get a new vector, no changing of the old above, so you have to catch the result somehow } ;;The code below is a can of worms for someone who don't know what the algoritm is supposed to do public static VectorListPos match(VectorListPos optionsAndActions) { ;;if null return null (would probably not be needed to catch when using nil) if (optionsAndActions == null) { return optionsAndActions; } ;;if one or zero elements they're already matched, return it as a whole if (optionsAndActions.size() 2) { return optionsAndActions; } ;;this code is quite opaque to me: VectorListPos modifiedOptionsAndActions = new VectorListPos(2); if (optionsAndActions.get(1) == null)
Re: mysql and fruit tables
I am running Win Vista. I create a project with Lein new fruit in C:\projects I cd to fruit in C:/projects/fruit I copy code from the mysql project that runs when reading the book table. This is the project code and the core code to access mysql. I added code to create the table fruit in test db. I run Lein deps I run lein repl I enter statement(load /fruit/core) I enter statement (fruit.core/create-fruit) I get error message == user= (fruit.core/insert-rows-fruit) Exception no current database connection clojure.java.jdbc.internal/connection* (internal.clj:40) user= fruit/core.clj fiele == I have deleted create-fruit I'm not sure what you mean by How exactly are you running your code (you never answer this one)? === (ns fruit.core (:require [clojure.java.jdbc :as sql])) (def db {:classname com.mysql.jdbc.Driver :subprotocol mysql :subname //localhost:3306/test :user root :password pass}) ; Inserting multiple rows ;If you want to insert complete rows, you can use insert-rows and provide the values as a simple vector for each row. Every column's value must be present in the same order the columns are declared in the table. This performs a single insert statement. If you attempt to insert a single row, a map of the generated keys will be returned. (defn insert-rows-fruit (sql/with-connection db Insert complete rows [] (sql/insert-record :books (sql/insert-rows :fruit [Apple red 59 87] [Banana yellow 29 92.2] [Peach fuzzy 139 90.0] [Orange juicy 89 88.6])) ;Inserting partial rows ;If you want to insert rows but only specify some columns' values, you can use insert-values and provide the names of the columns following by vectors containing values for those columns. This performs a single insert statement. If you attempt to insert a single row, a map of the generated keys will be returned. (defn insert-values-fruit Insert rows with values for only specific columns [] (sql/insert-values :fruit [:name :cost] [Mango 722] [Feijoa 441])) ;Inserting a record ;If you want to insert a single record, you can use insert-record and specify the columns and their values as a map. This performs a single insert statement. A map of the generated keys will be returned. (defn insert-record-fruit Insert a single record, map from keys specifying columsn to values [] (sql/insert-record :fruit {:name Pear :appearance green :cost 99})) ;Inserting multiple records ;If you want to insert multiple records, you can use insert-records and specify each record as a map of columns and their values. This performs a separate insert statement for each record. The generated keys are returned in a sequence of maps. (defn insert-records-fruit Insert records, maps from keys specifying columns to values [] (sql/insert-records :fruit {:name Pomegranate :appearance fresh :cost 585} {:name Kiwifruit :grade 93})) ;Using transactions ;You can write multiple operations in a transaction to ensure they are either all performed, or all rolled back. (defn db-write Write initial values to the database as a transaction [] (sql/with-connection db (sql/transaction ; (drop-fruit) ; (create-fruit) (insert-rows-fruit) (insert-values-fruit) (insert-records-fruit))) nil) ;Reading and processing rows ;To execute code against each row in a result set, use with-query-results with SQL. (defn db-read Read the entire fruit table [] (sql/with-connection db (sql/with-query-results res [SELECT * FROM fruit] (doseq [rec res] (println rec) (defn db-read-all Return all the rows of the fruit table as a vector [] (sql/with-connection db (sql/with-query-results res [SELECT * FROM fruit] (into [] res (defn db-grade-range Print rows describing fruit that are within a grade range [min max] (sql/with-connection db (sql/with-query-results res [(str SELECT name, cost, grade FROM fruit WHERE grade = ? AND grade = ?) min max] (doseq [rec res] (println rec) (defn db-grade-a Print rows describing all grade a fruit (grade between 90 and 100) [] (db-grade-range 90 100)) ;Updating values across a table ;To update column values based on a SQL predicate, use update-values with a SQL where clause and a map of columns to new values. The result is a sequence of update counts, indicating the number of records affected by each update (in this case, a single update and therefore a single count in the sequence). (defn db-update-appearance-cost Update the appearance and cost of the named fruit [name appearance cost] (sql/update-values :fruit [name=? name] {:appearance appearance :cost cost})) (defn db-update Update two fruits as a transaction [] (sql/with-connection db (sql/transaction (db-update-appearance-cost Banana bruised 14)
Java interop: inner class
How do you instantiate a (non-static) inner class? -- 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: ClojureScript – inter-namespace usage
binding works just fine in CLJS. That it doesn't work with required vars sounds like a bug. On Monday, January 9, 2012, Stuart Sierra the.stuart.sie...@gmail.com wrote: Hi Shantanu, #1 is a bug. #2 is not possible because `import` doesn't exist in ClojureScript: it doesn't differentiate between host classes and ClojureScript code. Protocols and types should be accessible with normal `require` in ClojureScript. #3 seems unlikely to be implemented. ClojureScript doesn't have Vars, and it doesn't have threads, so there's not much for `binding` to do. I could see `with-redefs` being supported, however. -S -- 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: core.logic, leiningen, clj-stacktrace: someone eats my backtraces
Do you see the same issue when working with lazy sequences? We definitely don't eat exceptions. On Monday, January 9, 2012, Tassilo Horn tass...@member.fsf.org wrote: Phil Hagelberg p...@hagelb.org writes: Hi Phil, One thing that really made the programming extremely hard was that I don't get any backtraces if an exception occurs inside a `run'. For example, I get this in SLIME with M-x clojure-jack-in RET. (defn wrongo [a b] false) ;; intentionally broken ;= #'logic-introduction.extend/wrongo (run* [q] (wrongo 1 2)) ; Evaluation aborted. Does the problem only happen with specific exceptions coming from core.logic or is it a general problem? It seems to be specific to exceptions thrown inside core.logic. For example, all those put me in the SLIME debugger just as it should be: (run* [q] (/ 1 0)) = ArithmeticException (run* [q] (wrongo 1)) = ArityException However, exceptions thrown inside core.logic don't show up. (run* [q] (wrongo 1 2)) ; Evaluation aborted. (clojure.repl/pst *e) ClassCastException java.lang.Boolean cannot be cast to clojure.lang.IFn clojure.core.logic.Substitutions (logic.clj:207) de.uni-koblenz.ist.funtg.funrl/eval5744/fn--5745/fn--5746/-inc--5747 (NO_SOURCE_FILE:1) clojure.core.logic/eval2975/fn--2976/fn--2977 (logic.clj:885) clojure.lang.LazySeq.sval (LazySeq.java:42) clojure.lang.LazySeq.seq (LazySeq.java:67) clojure.lang.RT.seq (RT.java:466) clojure.core/seq (core.clj:133) clojure.core/take/fn--3836 (core.clj:2499) clojure.lang.LazySeq.sval (LazySeq.java:42) clojure.lang.LazySeq.seq (LazySeq.java:60) clojure.lang.RT.seq (RT.java:466) clojure.core/seq (core.clj:133) nil If you can find the places where clj-stacktrace is used inside swank-clojure and wrap them in try/catches that do .printStackTrace you might be able to discover more about the cause. Or if it's something specific to using core.logic please provide steps for how to reproduce, preferably in the issue tracker. I'll do so, but not this evening. Now that I know of *e and `pst', it lost much of its importance, anyway. :-) 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 -- 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: Java interop: inner class
The syntax for this is atrocious in Java and the mechanism is in general rarely useful; I wouldn't be surprised if there's no non-hacky way to do this in Clojure. fooInstance.new Bar() is the construct you're talking about, right? My best guess would be that you just use the inner class's real (JVM-level) name, and pass it an instance of the outer class as its first argument. Something like (new Foo$Bar foo- instance), perhaps, but frankly that's a guess. On Jan 9, 5:46 pm, Alan sf.fly...@gmail.com wrote: How do you instantiate a (non-static) inner class? -- 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: Java interop: inner class
On Mon, Jan 9, 2012 at 8:46 PM, Alan sf.fly...@gmail.com wrote: How do you instantiate a (non-static) inner class? Something like the following? foo.java: public class foo { public class bar { public bar() { System.out.println(Made a bar); } } } and (import 'foo) (import 'foo$bar) (foo$bar. (foo.)) Lars Nilsson -- 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: Java interop: inner class
On 1/9/12, Lars Nilsson chamael...@gmail.com wrote: (foo$bar. (foo.)) Thanks! That works. Actually this is exactly what I had guessed. But when I tried it, it wasn't working for me. But it turns out my problem was something unrelated, and the error message I got wasn't enough to get me to see where I was wrong. I should have worked up a more minimal example, just as you showed, in order to isolate the issue. -- 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: ClojureScript – inter-namespace usage
I bind *print-fn* and it seems to work fine in my snapshot of master pulled on 12/14. On Mon, Jan 9, 2012 at 6:16 PM, David Nolen dnolen.li...@gmail.com wrote: binding works just fine in CLJS. That it doesn't work with required vars sounds like a bug. On Monday, January 9, 2012, Stuart Sierra the.stuart.sie...@gmail.com wrote: Hi Shantanu, #1 is a bug. #2 is not possible because `import` doesn't exist in ClojureScript: it doesn't differentiate between host classes and ClojureScript code. Protocols and types should be accessible with normal `require` in ClojureScript. #3 seems unlikely to be implemented. ClojureScript doesn't have Vars, and it doesn't have threads, so there's not much for `binding` to do. I could see `with-redefs` being supported, however. -S -- 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 -- (praki) -- 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: mysql and fruit tables
On Mon, Jan 9, 2012 at 3:43 PM, s...@ida.net wrote: I run lein repl I enter statement(load /fruit/core) You can just do: (require 'fruit.core) I enter statement (fruit.core/create-fruit) I get error message == user= (fruit.core/insert-rows-fruit) Exception no current database connection clojure.java.jdbc.internal/connection* (internal.clj:40) Your original insert-rows-fruit looked like this: (defn insert-rows-fruit Insert complete rows [] (sql/insert-rows :fruit [Apple red 59 87] [Banana yellow 29 92.2] [Peach fuzzy 139 90.0] [Orange juicy 89 88.6])) It doesn't have a with-connection call. In your latest email, you have: (defn insert-rows-fruit (sql/with-connection db Insert complete rows [] (sql/insert-record :books (sql/insert-rows :fruit [Apple red 59 87] [Banana yellow 29 92.2] [Peach fuzzy 139 90.0] [Orange juicy 89 88.6])) This cannot be what your actual code looks like - the parentheses don't match and your function has no argument list (because you've wrapped the with-connection call around too much - and you have both an insert-record and an insert-rows call in there). Your choices are either to type this in the REPL: user= (require '[clojure.java.jdbc :as sql]) nil user= (sql/with-connection fruit.core/db (fruit.core/insert-rows-fruit)) BatchUpdateException Incorrect integer value: 'Orange' for column 'id' at row 1 com.mysql.jdbc.PreparedStatement.executeBatchSerially (PreparedStatement.java:1666) user= (I pointed out you'd get that exception because you changed the table definition from what works in the documentation to something else and you're inserting incompatible data - see my previous response) or update your insert-rows-fruit function like this: (defn insert-rows-fruit Insert complete rows [] (sql/with-connection db (sql/insert-rows :fruit [Apple red 59 87] [Banana yellow 29 92.2] [Peach fuzzy 139 90.0] [Orange juicy 89 88.6]))) That will solve the connection problem. Of course, you're still get the BatchUpdateException - see above. I'm not sure what you mean by How exactly are you running your code (you never answer this one)? You've finally answered this by showing the commands you type in the REPL. There are lots of ways to run Clojure code - I needed to see how you were running your code to be able to reproduce your problems and suggest fixes. -- Sean A Corfield -- (904) 302-SEAN An Architect's View -- http://corfield.org/ World Singles, LLC. -- http://worldsingles.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
Struggling in making a sub-process work in an interactive way
Hello there, I'm writing some code, int my code it does following things (under Windows): 1. create a sub-process by (.exec (Runtime/getRuntime) cmd) named shell 2. get input-stream, output-stream and err-stream from the shell object 3. send commands to shell by dropping line into the output-string then get any result from input-stream/err-stream now it works fine for NON-interactive command such as dir or help, but it will hang when I send the shell commands that require user input, such as time. I think the reason is that my code doesn't detect any input requirement so the shell keep waiting for an input infinitely. Later on I tried to add code that can make this possible but I found there's no way to detect if a command requires user's input and thus I have to find another way to make it work - but I didn't success and have been struggling for a workaround for a long while anyone has any idea? Thanks, Jaime -- 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: Struggling in making a sub-process work in an interactive way
jaime xiejianm...@gmail.com writes: Later on I tried to add code that can make this possible but I found there's no way to detect if a command requires user's input and thus I have to find another way to make it work - but I didn't success and have been struggling for a workaround for a long while anyone has any idea? As far as I know this is impossible to do without bringing in third-party libraries; this is just a (rather serious) shortcoming of the JDK. I haven't looked into it enough to know which libraries would offer it though. -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
Re: mysql and fruit tables
Sorry for all the mistakes I make, but am trying todo something in mysql. In fruits example how is the mysql database called? In mysql example the statement is used to call mysql everytime a defn is called. === (sql/with-connection db. == Why is this statement not used?? What is its replacement/ Thanks - Original Message - From: s...@ida.net To: clojure@googlegroups.com Sent: Monday, January 09, 2012 4:43 PM Subject: Re: mysql and fruit tables I am running Win Vista. I create a project with Lein new fruit in C:\projects I cd to fruit in C:/projects/fruit I copy code from the mysql project that runs when reading the book table. This is the project code and the core code to access mysql. I added code to create the table fruit in test db. I run Lein deps I run lein repl I enter statement(load /fruit/core) I enter statement (fruit.core/create-fruit) I get error message == user= (fruit.core/insert-rows-fruit) Exception no current database connection clojure.java.jdbc.internal/connection* (internal.clj:40) user= fruit/core.clj fiele == I have deleted create-fruit I'm not sure what you mean by How exactly are you running your code (you never answer this one)? === (ns fruit.core (:require [clojure.java.jdbc :as sql])) (def db {:classname com.mysql.jdbc.Driver :subprotocol mysql :subname //localhost:3306/test :user root :password pass}) ; Inserting multiple rows ;If you want to insert complete rows, you can use insert-rows and provide the values as a simple vector for each row. Every column's value must be present in the same order the columns are declared in the table. This performs a single insert statement. If you attempt to insert a single row, a map of the generated keys will be returned. (defn insert-rows-fruit (sql/with-connection db Insert complete rows [] (sql/insert-record :books (sql/insert-rows :fruit [Apple red 59 87] [Banana yellow 29 92.2] [Peach fuzzy 139 90.0] [Orange juicy 89 88.6])) ;Inserting partial rows ;If you want to insert rows but only specify some columns' values, you can use insert-values and provide the names of the columns following by vectors containing values for those columns. This performs a single insert statement. If you attempt to insert a single row, a map of the generated keys will be returned. (defn insert-values-fruit Insert rows with values for only specific columns [] (sql/insert-values :fruit [:name :cost] [Mango 722] [Feijoa 441])) ;Inserting a record ;If you want to insert a single record, you can use insert-record and specify the columns and their values as a map. This performs a single insert statement. A map of the generated keys will be returned. (defn insert-record-fruit Insert a single record, map from keys specifying columsn to values [] (sql/insert-record :fruit {:name Pear :appearance green :cost 99})) ;Inserting multiple records ;If you want to insert multiple records, you can use insert-records and specify each record as a map of columns and their values. This performs a separate insert statement for each record. The generated keys are returned in a sequence of maps. (defn insert-records-fruit Insert records, maps from keys specifying columns to values [] (sql/insert-records :fruit {:name Pomegranate :appearance fresh :cost 585} {:name Kiwifruit :grade 93})) ;Using transactions ;You can write multiple operations in a transaction to ensure they are either all performed, or all rolled back. (defn db-write Write initial values to the database as a transaction [] (sql/with-connection db (sql/transaction ; (drop-fruit) ; (create-fruit) (insert-rows-fruit) (insert-values-fruit) (insert-records-fruit))) nil) ;Reading and processing rows ;To execute code against each row in a result set, use with-query-results with SQL. (defn db-read Read the entire fruit table [] (sql/with-connection db (sql/with-query-results res [SELECT * FROM fruit] (doseq [rec res] (println rec) (defn db-read-all Return all the rows of the fruit table as a vector [] (sql/with-connection db (sql/with-query-results res [SELECT * FROM fruit] (into [] res (defn db-grade-range Print rows describing fruit that are within a grade range [min max] (sql/with-connection db (sql/with-query-results res [(str SELECT name, cost, grade FROM fruit WHERE grade = ? AND grade = ?) min max] (doseq [rec res] (println rec) (defn db-grade-a Print rows describing all grade a fruit (grade between 90 and 100) [] (db-grade-range 90 100)) ;Updating values across a table ;To update column values based on a SQL predicate, use update-values with a SQL where clause and a map of columns to new values. The result is a sequence of update counts,
Re: Need help to translate a simple java program into Clojure program
On Tue, Jan 10, 2012 at 1:17 AM, Nicolas Garcin nicolas.etienne.gar...@gmail.com wrote: I'm new to functional programming and Clojure and I'm trying to translate a simple java program into Clojure. My program must build from 2 input lists (stored in a vector) 2 output lists (also stored in a vector) which have same number of elements as input lists for both output lists. The elements' values of the output lists will be the result of a very simple arithmetical calculation based on input lists' elements. Since my java program iterates on lists, I wanted to use a 'higher order function' in the Clojure version of the program (like the 'map' function). But I didn't manage to write the equivalent program in Clojure. Could someone please help me? Below is the java program that I'd like to translate. Translating Java code is not a very good idea. Implementing an algorithm is a much better approach. If you could explain exactly what needs to be done as opposed to how, I could pitch in with my Clojure solution. Just explaining what `match` is supposed to do should suffice. Regards, BG -- Baishampayan Ghose b.ghose at gmail.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: mysql and fruit tables
I guess I cange some things ecauseI don't know what the commands actually do. Icopied some ccode fromNakkaya using mysql with clojure and for some reason I go that code running. I got to study what I screwed up in your fruit code and seeif I can understand that. Thanks - Original Message - From: Sean Corfield seancorfi...@gmail.com To: clojure@googlegroups.com Sent: Monday, January 09, 2012 9:06 PM Subject: Re: mysql and fruit tables On Mon, Jan 9, 2012 at 3:43 PM, s...@ida.net wrote: I run lein repl I enter statement(load /fruit/core) You can just do: (require 'fruit.core) I enter statement (fruit.core/create-fruit) I get error message == user= (fruit.core/insert-rows-fruit) Exception no current database connection clojure.java.jdbc.internal/connection* (internal.clj:40) Your original insert-rows-fruit looked like this: (defn insert-rows-fruit Insert complete rows [] (sql/insert-rows :fruit [Apple red 59 87] [Banana yellow 29 92.2] [Peach fuzzy 139 90.0] [Orange juicy 89 88.6])) It doesn't have a with-connection call. In your latest email, you have: (defn insert-rows-fruit (sql/with-connection db Insert complete rows [] (sql/insert-record :books (sql/insert-rows :fruit [Apple red 59 87] [Banana yellow 29 92.2] [Peach fuzzy 139 90.0] [Orange juicy 89 88.6])) This cannot be what your actual code looks like - the parentheses don't match and your function has no argument list (because you've wrapped the with-connection call around too much - and you have both an insert-record and an insert-rows call in there). Your choices are either to type this in the REPL: user= (require '[clojure.java.jdbc :as sql]) nil user= (sql/with-connection fruit.core/db (fruit.core/insert-rows-fruit)) BatchUpdateException Incorrect integer value: 'Orange' for column 'id' at row 1 com.mysql.jdbc.PreparedStatement.executeBatchSerially (PreparedStatement.java:1666) user= (I pointed out you'd get that exception because you changed the table definition from what works in the documentation to something else and you're inserting incompatible data - see my previous response) or update your insert-rows-fruit function like this: (defn insert-rows-fruit Insert complete rows [] (sql/with-connection db (sql/insert-rows :fruit [Apple red 59 87] [Banana yellow 29 92.2] [Peach fuzzy 139 90.0] [Orange juicy 89 88.6]))) That will solve the connection problem. Of course, you're still get the BatchUpdateException - see above. I'm not sure what you mean by How exactly are you running your code (you never answer this one)? You've finally answered this by showing the commands you type in the REPL. There are lots of ways to run Clojure code - I needed to see how you were running your code to be able to reproduce your problems and suggest fixes. -- Sean A Corfield -- (904) 302-SEAN An Architect's View -- http://corfield.org/ World Singles, LLC. -- http://worldsingles.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 -- 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: Need help to translate a simple java program into Clojure program
On Mon, Jan 9, 2012 at 1:56 PM, Linus Ericsson oscarlinuserics...@gmail.com wrote: the last one becomes something like this: (for [option modified-options action modified-actions] (if (= (:name option) (:name option)) (let [sum (+ (:value action) (:value option))] [{:name (:name option) (Math/max 0 sum)} {:name (:name option) (Math/min 0 sum)}]))) The original code modifies the options and actions in place so the actions are cumulative on the options. Your Clojure code does not have that same property and produces different results. I'll be interested to see what Clojure solutions folks come up with that give the same results. I'm having a hard time with the solution myself :( -- Sean A Corfield -- (904) 302-SEAN An Architect's View -- http://corfield.org/ World Singles, LLC. -- http://worldsingles.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: Need help to translate a simple java program into Clojure program
(defrecord Pos [name value] Object (toString [this] (str Name: name , Value: value ))) (def actions [(Pos. IBM, -50) (Pos. ACCOR, -30); (Pos. IBM, -10); (Pos. APPLE, -20); (Pos. AIRFRANCE, -20)]) (def options [(Pos. IBM, 55) (Pos. ACCOR, 40) (Pos. AIRFRANCE, 10) (Pos. LUFTHANSA, 100)]) (defn process [options actions] (cond (nil? (seq options)) actions (nil? (seq actions)) options :else (for [option options action actions :when (= (:name option) (:name action))] [(Pos. (:name option) (min 0 (+ (:value option) (:value action (Pos. (:name option) (max 0 (+ (:value option) (:value action]))) (defn match [[options actions]] (reduce #(do [(conj (first %1) (first %2)) (conj (second %1) (second %2))]) [[] []] (process options actions))) (println Options: (map str options)) (println Actions: (map str actions)) (println --after match--) (let [[options actions] (match [options actions])] (println Options: (map str options)) (println Actions: (map str actions))) -- 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: Need help to translate a simple java program into Clojure program
Oops. A possible solution might look something like that... -- 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: Trying to understand variable capture
Macro expansion time is just before compile time. -- 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