Re: Recursion/Algorithm Question
Thanks, That (along with returning the completed path via (list)) nailed it. I thought I'd tried concat at some point, but that might have been with another problem I've been tackling. -- 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: Recursion/Algorithm Question
Thanks, Nathan, that did help. I'm still stuck, however, figuring out how to return the values as a flat sequence of vectors. Maybe I'm just missing the right function from the API. Here's where I'm at right now: (defn get-paths ([n] (get-paths n [0 0] '())) ([n point path] (cond (points-equal? (vector n n) point) (reverse (conj path point)) (out-of-bounds? n point) nil (blocked? point) nil :else (list (get-paths n (inc-y point) (conj path point)) (get-paths n (inc-x point) (conj path point)) So, right now when I call the function with nothing blocked (get-paths 1) it returns ((nil ([0 0] [0 1] [1 1])) (([0 0] [1 0] [1 1]) nil)) but what I want is (([0 0] [0 1] [1 1]) ([0 0] [1 0] [1 1])) so that a call to (count) would return the total number of paths. -- 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
Recursion/Algorithm Question
I've been working through algorithm problems to learn the language a little better. I'm currently struggling with the question about a robot traversing a grid. If the grid is completely open, then the answer to how many possible ways to traverse the grid? is simply the math for combinations using factorials (see Project Euler #15). But if you suppose that some places in the grid are blocked or that you have to actually traverse the paths? I know that the code below doesn't work yet (recur is not at the tail). Think of it as pseudo-code to show my intent. I've left out the other methods to get at the heart of what I'm asking about. Essentially, each path leads to two more recursion points (at least the way I've formulated it in my else), until they finally run out of bounds or meet the goal. The input n represents the width of the square grid. I'm using a two-element vector to represent a point in the grid. (defn get-paths [n] (let [paths (agent '()) goal (vector n n)] (loop [point [0 0] path '()] (cond (points-equal? goal point) (send paths conj (conj path point)) (out-of-bounds? n point) nil (blocked? point) nil :else (recur (inc-x point) (conj path point)) (recur (inc-y point) (conj path point (deref paths))) Perhaps ultimately, the approach I've tried here is a dead-end? I'm not sure that this loop formulation would ever exit, or perhaps it would exit too quickly. -- 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: not= counterintuitive?
The clojure.contrib.combinatorics/combinations does do exactly what I was trying to do, although I was doing the problem as an exercise in how to do it, and not in really needing combinations for something else. The combinatorics library certainly does it in a more generic way. Since I knew that I was dealing with numbers as input, I actually ended up using ( m n o) as my test condition, which has the same effect of guaranteeing all the numbers are distinct. I was looking for unique sets where order didn't matter. Thanks for the input, all! -- 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
not= counterintuitive?
This code doesn't return the value I intuitively expect: user= (not= 1 2 1) true When I write that, I was expecting the equivalent of (and (= 1 2) (= 1 1)), but the macro expansion is essentially (not (= 1 2 1)). Note: This came out of the :while condition of a (for) expression not returning what I expected on three separate values, where (= x z). I can work around it to get what I want, but I was curious if perhaps the (not=) was not in the spirit it was intended. -- 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: not= counterintuitive?
That's what I get for posting a question while feeding a 1-year-old child and getting ready to leave for lunch. I was trying to put together a (for) construct to output the combinations of a set, and my logic was flawed. Here's what I really wanted [for sets of 3]: (for [m x n x o x :while (and (not= m n) (not= m o) (not= n o))] [m n o]) Maybe not the most efficient, but the smallest construct I've come up with, but it isn't generic enough for me yet. I'll keep working on it. -- 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: Stanford AI Class
The NYTimes article on the class also mentions two other classes being offered for free: * Machine Learning, by Andrew Ng * Introductory course on database software, by Jennifer Widom I'm not sure of the official website for either of these, but the Machine Learning class sounds promising and didn't have a required textbook the way the AI class does. -- 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: Good book on migrating from (Java) OO to FP
Can you provide a more detailed review? How did it help you? What area(s) that it focused on did you find most useful? I've been playing with Clojure for nearly a year now, but it has just been on my own. At work, however, it is just Java and C#. Of course, I've also got several computer books waiting to be read, so essentially I'm asking you to convince me to let this book jump the queue. :^) On Jul 29, 5:03 am, Colin Yates colin.ya...@gmail.com wrote: Hi all, Not sure whether this is good etiquette or not, but I wanted to praisehttp://oreilly.com/catalog/0636920021667. I found it pretty useful in bridging the gap between OO and FP. It isn't Clojure specific, but as a (well established) Java/OO guy, this helped me get FP. (not connected in anyway with the book or author other than through appreciation :)) -- 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: Creating prime? function
This is just my copy of something I pulled together from other sources while working of Project Euler problems and perhaps refined a little: (defn prime? [n] (cond (or (= n 2) (= n 3)) true (even? n) false :else (let [sqrt-n (Math/sqrt n)] (loop [i 3] (cond (divisible? n i) false ( sqrt-n i) true :else(recur (+ i 2))) I settled on this one because it seems to be the fastest. Of course, there is a library implementation somewhere. What I am curious about is figuring out a way to retain primes in a useful way. In this example, we start with 3 and just keep adding 2, but if you are doing something like (filter prime? (range 2 1)), wouldn't there be some ideal way to memoize the prime values you've discovered so far and use them as the values to check against? Perhaps this just leads to more overhead than it is worth, but I haven't explored it yet, I've been too busy with other stuff lately. -- 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: Loading JNI
Sorry for the late response, but I haven't had time to play with things in a couple days. First discovery is that I probably cannot use the library path variable, because some of the DLLs have to be loaded in a specific order. Specifically, there is a clientswig.dll that has to be loaded last. Going back to the old style of loading them manually inside the Clojure code, I still have a problem, though. The problem now seems to be with the JAR file that I need to be using. I get a NoClassDefFoundError on a class within the JAR: Could not initialize class ...ClientModuleJNI. I have included the JAR in the build path as I traditionally would in Eclipse (Properties - Java Build Path - Libraries - Add JARs). I've also tried launching from the command line and get the same error. I've mangled the code below to hide company-specific information, but this is what I'm doing right now. --- In Clojure --- (ns app) (def path C:\\SVN\\lib3rdParty\\) (try (System/load (str path client.dll)) (catch UnsatisfiedLinkError e (println Failed library load.))) (try (System/load (str path utils.dll)) (catch UnsatisfiedLinkError e (println Failed library load.))) (try (System/load (str path clientswig.dll)) (catch UnsatisfiedLinkError e (println Failed library load.))) (import '(com.app Client ClientSession)) (def my-client (Client.)) --- In Java --- public final class AlertClient extends Client { // Load the JNI static { try { path = C:\\SVN\\lib3rdParty\\; String[] libraries = { client.dll, utils.dll, csclientswig.dll }; for (int i = 0; i libraries.length; ++i) { String libPath = path + libraries[i]; System.load(libPath); } } catch (UnsatisfiedLinkError e) { System.err.println(Native code library failed to load.\n + e); System.exit(1); } } public AlertClient() throws Exception { super(); } } -- 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: Loading JNI
Thanks for the suggestions. I'll look at the JNA soon to see if that fits. But I already have working examples of Java code which uses the JNI wrapper classes (generated by swig - by someone else). I'm not making direct JNI calls myself, but trying to instantiate the Java classes that are a part of this generated library. That's my confusion and frustration, because seemingly identical code works in Java, but doesn't work for me in Clojure ... either in Eclipse or from a command- line, actually. -- 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: Loading JNI
Hmm, I see that the final draft of my question missed an essential element, I am using Eclipse. In any case, I've tried something really basic, and it fails: (try (System/load C:\\app/bin/coms.dll) (println Native code library failed to load.)) The file is there (I checked with an exists() call). Maybe this is an eclipse problem, but I can do the same call in Java (in Eclipse) and have no issues. -- 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: Loading JNI
Of course not. I mentioned I'm new at this, right? It seems I was doing that part right before. I'm getting InvocationTargetException and NoClassDefFoundError, so I tried to work my way from the start to see if I was missing something (which I thought was a valid assumption, if exceptions were being swallowed). My first instinct was that it wasn't loading the libraries correctly. Or course, I'm still stuck. It clearly sees the classes, because my import statements aren't throwing ClassNotFoundExceptions. The exceptions I'm getting are bubbling up out of the JNI, apparently, but I don't have any idea why. At this point I have ugly looking Clojure code that looks as Java-like as possible, so that I'm doing the exact same thing in the exact same order as I do in a Java example, but I get exceptions when I do it in Clojure. So, when I get to (def my-client (Client.)) it throws. BTW, Java equivalent ... Client myClient = new Client(); It feels like something is fundamentally different in a way I cannot conceive, like Java automatically handles something behind the scenes and I don't realize it. 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: Tailing a file in Clojure
Does any familiar with this NIO Watch service know if it handles NFS issues? We have an in-house log monitoring tool at work (doesn't everyone) which is written in Java, but the two big issues are message framing (knowing when a multi-line message has ended) and getting null bytes when tailing an NFS file. We have some fairly heavy code to handle these problems. I've thought about trying to write something similar in Clojure as a project, but haven't started to tackle it yet precisely because I didn't see any way to make it more efficient. -- 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: Little LISPer and Ten Commandments
Yeah, it has been a good educational resource for working through. I'm not finished, but I've put the Clojure version of all the code up here: https://www.assembla.com/code/little_clojure/subversion/nodes Looking forward to those last couple chapters. msd -- 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
Little LISPer and Ten Commandments
Newbie here, to both LISP and Clojure. A friend has lent me a copy of The Little LISPer and I've started working through it, using some web resources to translate it into clojure. My questions: How relevant are the ten commandments? What modification need to be made ... either to the commandments or to your code in clojure? I ask because the first commandment (always ask null?) hasn't translated directly into any single statement for me. I can achieve the same with (or) to navigate the difference between nil and () in clojure, but sure that difference is in there for a reason. Any other input on the other commandments or using the book in general? Thanx -- 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