Re: Unable to use contrib
Hi, I ran into a similar problem myself recently. I'm not sure if this is the "best" approach but I found that if you (use 'clojure.contrib.math) instead of require, it should work. Regards, Mark. On Oct 7, 2:50 pm, vishy wrote: > Hi, > > I am on windows machine. I am using these commands to startup clojure, > but not able to use functions from contrib library. > > java -cp clojure.jar;clojure-contrib.jar clojure.lang.Repl > Clojure 1.0.0- > user=> (require 'clojure.contrib.math) > nil > user=> (lcm 4 5) > java.lang.Exception: Unable to resolve symbol: lcm in this context > (NO_SOURCE_F > LE:2) > > Whats the problem here? Please help > > regards > vishy --~--~-~--~~~---~--~~ 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: Linear Algebra Package
Hi, I think http://sites.google.com/site/piotrwendykier/software/ parallelcolt">Parallel Colt has picked up where Colt left off. It's a very full featured library and forms the basis of the Clojure stats package http://incanter.org/>Incanter. Personally, I've used the sparse vector classes in Parallel Colt for a http://github.com/mreid/injuce/blob/inplace/sgd.clj";>simple machine learning algorithm and found it well designed and fast. Regards, Mark. On Oct 6, 7:22 am, CuppoJava wrote: > Hi, > I need to do some high performance numerical data crunching and was > wondering what libraries are popular. I have looked into Colt and > JAMA, but neither have had much development recently (Colt hasn't had > a release since 2004, and JAMA since 2005), and I'm not sure if > they're still alive. Clojuratica sounds promising, but I don't (yet) > own a Mathematica license. I would appreciate it if someone who's > familiar with the latest news about numerical processing in Java shed > some light on this topic. > > Thanks a lot for your help > -Patrick --~--~-~--~~~---~--~~ 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: Clojure Golf – Episode 2: Largest Prime Factor
Hi, On Sep 10, 3:52 pm, MarkSwanson wrote: > Just for fun I actually tried this: > > Clojure=> (time (lpf6b 1234567890123456789012345678901234567890)) > The prime factorization of 1234567890123456789012345678901234567890 > is :5964848081 > "Elapsed time: 5519.278432 msecs" > > I can't confirm the answer is correct. > 5.5 seconds sure beats 10 minutes. :-) Just thought you would like to know that Wolfram|Alpha agrees (in roughly the same time): http://www.wolframalpha.com/input/?i=factor+1234567890123456789012345678901234567890 Regards, Mark. -- http://mark.reid.name --~--~-~--~~~---~--~~ 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: Quirk with filter
Hi, The problem here is that filter is expecting a predicate and you are passing a set. When used as a function like so user=> (#{1 2 3} 2) 2 user=> (#{1 2 3} 5) nil the set returns the argument if it is in the set and nil otherwise. The problem you are observing is because the item being returned is false. That is, user=> (#{true false} false) false and the conditional test in the definition of filter is, naturally, failing for this value. I actually think the behaviour in the first case is wrong since the documentation for filter is Returns a lazy sequence of the items in coll for which (pred item) returns true. pred must be free of side-effects. Note it says "returns true" not "not nil nor false". The problem here is that the "if" special form used to define filter does the following: user=> (if 1 "yes" "no") "yes" As it currently stands, either "filter" needs to be redefined using (if (true? (p (first s) ...) or the documentation needs to be changed. Regards, Mark. On Aug 19, 9:37 am, Sean Devlin wrote: > Hello Clojurians, > I commonly use a set in my filtering operations, like the example > below. > > user=> (filter #{\a \e \i \o \u} "The quick brown fox jumped over the > lazy dog") > (\e \u \i \o \o \u \e \o \e \e \a \o) > > Today I found myself using the following code > > user=> (filter #{false} [true false false true]) > () > > Obviously, this is not what I intended. The best I could do was the > following > > user=> (filter (comp not nil? #{false}) [true false false true]) > (false false) > > Does anyone else have any other ideas? > > Sean --~--~-~--~~~---~--~~ 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 Math Question
Hi again, I misinterpreted the question first time around but here's another attempt. Given f, a0 and v, let b0 = (reduce f a0 v) = f( f( f( f(a0, v[1]), v [2]), ...), v[n]) Now define the function g to ignore its second argument and return its first. That is, g(x, y) = x. Then (reduce g b0 (reverse v)) = g( g( g( g(b0, v[n]), v[n-1], ...), v [1]) = b0 = x = (reduce f a0 v). This solution seems like a bit of a cheat but as far as I can tell it fits the problem description. A more difficult problem (I suspect impossible) would be to find a g and b0 that works for any v. That is, Given f and a0 find a g and b0 such that for *any* list of numbers v (reduce f a0 v) = (reduce g b0 (reverse v)) Regards, Mark. -- http://mark.reid.name On Jun 4, 6:42 pm, Daniel Lyons wrote: > On Jun 3, 2009, at 11:23 PM, CuppoJava wrote: > > > > > Hey guys, > > I'm really stuck on this math question, and I'm wondering if you guys > > know of any links that may help me. > > > Given: f(x,y), a0, a list of numbers v. > > Find: g(x,y) and b0 such that: > > > (reduce f a0 v) = (reduce g b0 (reverse v)) > > > Thanks for your help > > What math class is this for and what have you been studying lately in > it? :) > > I couldn't think of any fundamental functions that aren't commutative > besides - and /, which turn out to work like commutative functions if > you use ao = bo. > > My first thought was that if I had a really nasty function I could > maybe use 'flip' to fix it: > > (defn flip [f] > (fn [one two] (f two one))) > > This turned out to be useless. (I was trying with f = #(+ (* %1 %1) > (/ %1 %2)) ). No combination of flip + first/last could make [1 2 3 4 > 5] and [5 4 3 2 1] come out with the same answer that I could see. > > I am quite curious what the final answer turns out to be but I > couldn't come up with it in the ~20 minutes I spent on it. Let us know > when you figure it out! > > — > Daniel Lyonshttp://www.storytotell.org-- Tell 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: Help with Math Question
Hi, Maybe I'm missing something but doesn't + fit the bill (or any symmetric function)? (== (reduce + 3 [1 2 3]) (reduce + 3 [3 2 1])) ;; => true In this case f = g = + and a0 = b0 for any choice of a0 and v. Regards, Mark. On Jun 4, 3:23 pm, CuppoJava wrote: > Hey guys, > I'm really stuck on this math question, and I'm wondering if you guys > know of any links that may help me. > > Given: f(x,y), a0, a list of numbers v. > Find: g(x,y) and b0 such that: > > (reduce f a0 v) = (reduce g b0 (reverse v)) > > Thanks for your help > -Patrick --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Question about building modular code in Clojure
> What's wrong with this: > > user=> (ns test (:use [clojure.contrib.math :exclude (lcm)])) > nil > test=> (sqrt 2) > 1.4142135623730951 > test=> (lcm 3 6) > java.lang.Exception: Unable to resolve symbol: lcm in this context > (NO_SOURCE_FILE:3) > test=> (defn lcm [a b] 1) > #'test/lcm > test=> (lcm 3 6) > 1 > test=> I think a better example for Mark's concern about existing functions using a faster version of an algorithm would be redefining gcd as this is called by lcm. I tried the following: user=> (ns test (:use [clojure.contrib.math :exclude (gcd)])) nil test=> (gcd 4 6) java.lang.Exception: Unable to resolve symbol: gcd in this context (NO_SOURCE_FILE:3) test=> (lcm 4 6) 12 So it seems lcm is still compiled against the original gcd. Let's try to fix that: test=> (defn clojure.contrib.math/gcd [a b] 1) java.lang.Exception: Can't create defs outside of current ns (NO_SOURCE_FILE:8) test=> (ns clojure.contrib.math) nil clojure.contrib.math=> (defn gcd [a b] 1) #'clojure.contrib.math/gcd clojure.contrib.math=> (ns test) nil test=> (lcm 4 6) 24 Maybe a variant of ns could be written that allows the overriding of specific functions? e.g., (ns2 test (:use [clojure.contrib.math :redef (gcd [a b] 1) (lcm [a b] 2))) Regards, Mark -- http://mark.reid.name --~--~-~--~~~---~--~~ 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 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: Macros applied to entire programs
I should clarify: I asked my original question not because I wanted to actually write an optimiser but rather I was interested in how far the idea of code-modifying code could be pushed in a Lisp-like language such as Clojure. The example I gave was just the simplest thing I could think of that demonstrated what I was imagining. Basically, I wanted a little exercise to try to understand macro programming better and though this would be a fun exercise. I just didn't know where to start. Stuart's template is more or less what I was after. Konrad, I agree, it would make more sense to add simple optimisations like the one for addition to Clojure itself. However, the potential problem you mention regarding the clash of multiple definitions of `+` doesn't seem like that big an issue since an optimising macro can just call `resolve` against the first symbol and see if it is equal to `clojure.core/+`. Paul's suggestion also seems to get around this problem. Thanks for all the responses. Mark -- http://mark.reid.name --~--~-~--~~~---~--~~ 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 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: Macros applied to entire programs
Hi, I have read Graham's "On Lisp". That, and my background in Java and Haskell programming were the main reasons I was drawn to Clojure. Based on that article and others like it I had the impression that program transformations like the one I suggested were relatively easy in homoiconic languages like Clojure and macros seem to be the tool to do it. I guess what I'm really looking for now is the "how". Mark. On May 12, 1:54 pm, Sean Devlin wrote: > Macros are definitely the tool to do this. Take a look here at Paul > Graham's "The Roots of Lisp". In it you'll get an idea of why eval is > so powerful, and why macros are exactly the tool for the job you're > thinking of. > > http://lib.store.yahoo.net/lib/paulgraham/jmc.ps > > I'll let someone else answer "how" with respect to Clojure. > > Sean > > On May 11, 11:42 pm, Mark Reid wrote: > > > Hi, > > > I'm quite new to macros so forgive me if this is a naïve question, but > > is it possible to write macros that are applied to an entire Clojure > > program? > > > The reason I ask is that, in other threads in this group, some simple > > transformations to improve efficiency of Clojure programs were > > mentioned. In particular, it seems converting `(+ 1 2 3)` to `(+ 1 (+ > > 2 3))` can speed things up. Applying such a transformation to my own > > code would be a mindless pattern matching job, and thus perfect for > > automation. > > > Any suggestions how I might write a Clojure program that takes as > > input another Clojure program and outputs a third one that is > > optimised but semantically equivalent to the input? Are macros the > > right tool for the job in this case? > > > Thanks, > > > Mark. > > --http://mark.reid.name --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Macros applied to entire programs
Hi, I'm quite new to macros so forgive me if this is a naïve question, but is it possible to write macros that are applied to an entire Clojure program? The reason I ask is that, in other threads in this group, some simple transformations to improve efficiency of Clojure programs were mentioned. In particular, it seems converting `(+ 1 2 3)` to `(+ 1 (+ 2 3))` can speed things up. Applying such a transformation to my own code would be a mindless pattern matching job, and thus perfect for automation. Any suggestions how I might write a Clojure program that takes as input another Clojure program and outputs a third one that is optimised but semantically equivalent to the input? Are macros the right tool for the job in this case? Thanks, Mark. -- http://mark.reid.name --~--~-~--~~~---~--~~ 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 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: Can "for" be enhanced to not have to take a binding?
Hi Laurent, On May 10, 5:15 am, Laurent PETIT wrote: > So if you want to call it with a no-arg "predicate", you must adapt it : > > (repeatedly-while (fn [ _ ] (no-arg-pred)) f) > instead of > (repeatedly-while no-arg-pred f) I think that this is too convoluted a calling pattern. For my purposes, my preference is for the amended `repeatedly-while` function Miekel suggested. Thanks, Mark. --~--~-~--~~~---~--~~ 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 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: Can "for" be enhanced to not have to take a binding?
Hi Meikel, On May 10, 3:05 am, Meikel Brandmeyer wrote: > There is a mistake in this function: pred should be (pred) > as well as f should be (f). > Furthermore I would call it repeatedly-while. > > (defn repeatedly-while > [pref f] > (lazy-seq > (when (pred) > (cons (f) (cons-while pred f) > > Then this should work: > > (repeatedly-while #(.ready reader) #(.readLine reader)) Yes, that works now. Thanks. So the extra parentheses are there to force the evaluation of the predicate and function? Regards, Mark -- http://mark.reid.name --~--~-~--~~~---~--~~ 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 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: Can "for" be enhanced to not have to take a binding?
Hi Laurent, Thanks for the feedback. I'm still a bit stuck though since neither my proposal nor yours work for the type of application I had in mind. Here's a complete program which highlights the problems: ; Begin lazyread.clj (import '(java.io FileReader BufferedReader PrintWriter)) (def filename "test.data") ; Write out a small test file. Numbers 0 to 99, one per line. (with-open [data (PrintWriter. filename)] (dotimes [i 100] (.println data i))) ; An attempt at capturing the general idiom that doesn't work (defn cons-while [pred f] (lazy-seq (when pred (cons f (cons-while pred f) ; Another attempt that doesn't work (defn repeatedly-while [pred f] (take-while pred (repeatedly f))) ; A specific implementation for the problem at hand (defn lazy-read [reader] (lazy-seq (when (.ready reader) (cons (.readLine reader) (lazy-read reader) (print "lazy-read: ") (with-open [data (BufferedReader. (FileReader. filename))] (prn (take 10 (lazy-read data (print "cons-while: ") (with-open [data (BufferedReader. (FileReader. filename))] (prn (take 10 (cons-while (.ready data) (.readLine data) (print "repeatedly-while: ") (with-open [data (BufferedReader. (FileReader. filename))] (prn (take 10 (repeatedly-while #(.ready data) #(.readLine data) ; End lazyread.clj Running this will write out a small test file named `test.data` in the current directory with the numbers 0-99 one per line and then use three techniques to lazily read in the first 10 lines. The first technique, `lazy-read`, is an explicit use of the `lazy-seq` + `when` + `cons` combination I wish to generalise. The second one, `cons-while`, is the attempt I made and the third, `repeatedly-while` is your suggestion. Here's the output I get when I run this as a script from the command line: $ clj lazyread.clj lazy-read: ("0" "1" "2" "3" "4" "5" "6" "7" "8" "9") cons-while: ("0" "0" "0" "0" "0" "0" "0" "0" "0" "0") Exception in thread "main" java.lang.RuntimeException: java.lang.RuntimeException: java.lang.IllegalArgumentException: Wrong number of args passed to: user$eval--38$fn (scratch.clj:0) Unsurprisingly, the problem-specific method seems to work fine. The `cons-while` method returns the wrong output and the last technique fails because of issues surrounding the macro expansion of (.ready data) and the #(...) macro that have been discussed elsewhere. Is it possible to get the `repeatedly-while` version working with calls to Java without making the calling pattern too convoluted? Also, can anyone explain why the `cons-while` approach only appears to be repeatedly reading the first line? Finally, would a macro approach be better for this type of problem? Thanks, Mark. -- http://mark.reid.name --~--~-~--~~~---~--~~ 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 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: Can "for" be enhanced to not have to take a binding?
Hi, This `lazy-seq` over a `when` and `cons` idiom seems fairly common. Is there any reason there is not a function for it? For example: (defn cons-while "Lazily creates a sequence by repeatedly calling f until pred is false" [pred f] (lazy-seq (when pred (cons f (cons-while pred f) I haven't tested it but I suspect the following should now work: (cons-while (Mouse/hasEvent) (Mouse/getEvent)) Regards, Mark -- http://mark.reid.name On May 8, 7:44 am, Meikel Brandmeyer wrote: > Hi, > > lazy-seq to the rescue: > > (defn mouse-seq > [] > (lazy-seq > (when (Mouse/hasEvent) > (cons (Mouse/getEvent) (mouse-seq) > > Sincerely > Meikel > > Am 07.05.2009 um 23:40 schrieb CuppoJava: > > > > > > > Yeah (pred) is not supposed to depend on any items inside f. > > > This is why (take-while pred (repeatedly f))) > > won't work in this situation. > > > (take-while) will always take an element out of f, so that it can be > > tested using (pred). I don't want any elements of (f) to be looked at > > if (pred) is false. > > > USE CASE > > I'm using it in combination with some Java libraries. The following > > seems like a very clojure-ish way of doing things. > > > (for [:while (Mouse/hasEvent)] (Mouse/getEvent)) > > > so this returns a nice lazy stream of mouse events, which can be > > processed however i like. > > > > > > smime.p7s > 5KViewDownload --~--~-~--~~~---~--~~ 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 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: Abstract data types in functional languages
Hi, This is probably digressing a little from the original question but I was wondering if using namespaces here is a reasonable thing to do when designing ADTs. > SICP tells us that we should be defining accessor functions > immediately when we create a new data type. > > (defn make-fraction [n d] {:numerator n :denominator d}) > (defn fraction-numerator [f] (:numerator f)) > (defn fraction-denominator [f] (:denominator f)) Couldn't you define the functions like so: (ns fraction) (defn make [n d] {:numerator n :denominator d}) (defn numerator [f] (:numerator f)) (defn denominator [f] (:denominator f)) And then from outside the namespace call (def f (fraction/make 1 2)) (fraction/numerator f) ; => 1 This seems to me to be a fairly clean way to encapsulate an ADT and it doesn't cost any more characters than the prefix style of naming functions. Regards, Mark. -- http://mark.reid.name --~--~-~--~~~---~--~~ 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 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: The Path to 1.0
I'm a relatively new user of Clojure and thought I'd add my perspective to the pile regarding what I would expect from a 1.0 release. My biggest frustrations with Clojure as a newcomer were: 1. Setting it up so it was easy to use across projects 2. The API documentation While the documentation on the Clojure site made it very easy to open a REPL via a call to `java -cp ...`, it was much less clear how to make a simple command-line tool that could be run from anywhere to open a REPL, or run/compile a script. There is a bash script in clojure-contrib that does some of this and it would make sense to put this and maybe a similar Windows .BAT script in a 1.0 release. Along these line, most other languages I've used come with an optional installer for each major OS that sets up a standard operating environment including command-line tools and a library structure. Maybe Clojure 1.0 could have something similar? Compared to Javadoc documentation, I find the current Clojure API documentation a little terse and unorganised. In particular, I don't find the large table of contents bar down the side of http://clojure.org/api very useful. Some of the clojure.org pages, such as http://clojure.org/data_structures , have collections of "related functions" which I found very useful when feeling my way around the standard library. Perhaps this sort of thing could be formalised, extended and put into some easily navigable format? Though it is not as important, I've also had very good experiences with Git and GitHub after having used CVS and subversion for many years. I think the social infrastructure they created at GitHub adds a lot of value to Git as a SCM tool. I also agree with several of the other posters about a 1.0 release to coincide with Stuart's book. Regards, Mark Reid -- http://mark.reid.name --~--~-~--~~~---~--~~ 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 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: Contribs with dependencies
Hi, I'm not sure if this is relevant to this discussion but, as a newcomer, I was puzzled by the organisation of the clojure-contrib source. Why, for example, are ClojureCLR and clojurescript at the top of the trunk? Shouldn't these be in separate projects? Regards, Mark. -- http://mark.reid.name/ On Apr 14, 10:19 pm, Rich Hickey wrote: > I've been thinking recently about contribs with dependencies. > > I think it's very important to have layers - e.g. core depends only on > JDK 1.5, contrib only on core. Lately there have been some ideas > centering around Joda Time, [Parallel]Colt, AWS, JFreeChart, Fork/Join > etc. > > I'd like to start a discussion about how best to support the > contributions of libraries that depend on things not in the JDK. > > Obviously, without care and rules it could get crazy quickly, and I > want to avoid the kitchen-sink effect. It is very important that > things remain [truly, not just apparently] simple. > > Looking for suggestions, > > Rich --~--~-~--~~~---~--~~ 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 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: Porting Minilight to Clojure
Hi Laurent, Thanks for the feedback regarding namespaces. That's exactly the sort of thing I wasn't sure I was doing correctly. I currently don't use an IDE that automatically compiles files so wasn't aware of that problem. I prefer the solution that defines a main method. My only question now is, if I don't want to compile the test class, how do I call the main method from the command line? Regards, Mark. -- http://mark.reid.name On Apr 7, 7:35 pm, Laurent PETIT wrote: > Hello Mark, > > That's interesting, keep us informed of your progress! > > Since you say you welcome any feedback, here are my remarks : > > * namespace names: you could maybe use more qualified names, e.g. > qualifying them maybe with your own reversed namespace ( vec -> com.reid.vec > ). Indeed, one of the interests of namespaces is to avoid name clashes, and > it feels to me like creating namespaces of just one segment with such > generic names such as vec may not scale well, even for personal work ? > > * you have a file named test/test.clj . The corresponding namespace > declaration should then be (ns test.test ...) instead of (ns test ...). > > * function calls in namespaces : your namespace 'test directly executes a > call. This would be problematic for people using IDEs that automatically > regularly auto-compile or auto-load files to give user error/warning > feedback. > One alternative solution could be to just guard the call against compilation > by checking the value of the *compile-files* global var : > (when-not *compile-files* > (run-tests 'test.vec)) > Another alternative could be to completely get rid of the immediate call to > run-tests and place it instead in a -main method, so that the ns can be used > as an independent executable file: > > (ns test > (:gen-class) > (:use test.vec) > (:use clojure.contrib.test-is)) > > (defn -main [] (run-tests 'test.vec)) > > HTH, > > -- > Laurent --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Porting Minilight to Clojure
Hi, In the interests of learning Clojure I thought it would be fun to port the Minilight renderer to Clojure and write about the steps along the way. If you're interested you can have a look at my first post here: http://mark.reid.name/sap/minilight-clojure-vectors.html I've not programmed in a Lisp-like before (aside from hacking the odd .emacs files) and one thing I've noticed is just how flexible this type of language is. The downside, of course, is that there are many ways to do things sub-optimally or inelegantly so I welcome any feedback. Regards, Mark. -- http://mark.reid.name --~--~-~--~~~---~--~~ 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 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: Setting up Clojure on OS X
Just a quick note to say that I've added notes about the TextMate Clojure bundle to my tutorial. I've also put a concise version of the guide up on GitHub: http://github.com/mreid/clojure-framework/tree/master Regards, Mark. -- http://mark.reid.name --~--~-~--~~~---~--~~ 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 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: Setting up Clojure on OS X
Hi Sean, On Mar 30, 11:59 pm, Sean wrote: > As an OSX nerd, my main problem is getting an editor up and running. Maybe > you could add > a section on setting up an editor? That's a good point. I use TextMate with the Clojure bundle. I'll add a section with the appropriate links. Regards, Mark. -- http://mark.reid.name --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Setting up Clojure on OS X
Hi, I've just written a blog post describing how I set up Clojure on my Mac: http://mark.reid.name/sap/setting-up-clojure.html My main aims were to make it easy to configure the classpath for various projects while still having a single Clojure command I can run from anywhere to open a interactive session or run a script. Hopefully others might find this useful as well. Feedback is appreciated as I am new to Clojure and acutely aware that I may not be doing things in the most elegant way. Mark -- http://mark.reid.name --~--~-~--~~~---~--~~ 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 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: Turning a non-standard iterator into a seq
On Mar 26, 1:10 am, Stuart Sierra wrote: > Hi Mark, > You'll need to work at a lower level using cons and lazy-seq. > Something like this (untested): > > (defn bio-iterator-seq [iterator] > (lazy-seq > (when (.hasNextiterator) > (cons (.nextSequenceiterator) (bio-iterator-seqiterator) Hi Stuart, Thanks for that. Once I upgraded my clojure.jar to the latest release that code worked perfectly. Calling (def input (BufferedReader. (FileReader. "data/dm4p1/dm4p1.dEID"))) (def data (RichSequence$IOTools/readFastaDNA input nil)) (doseq [d (bio-iterator-seq data)] (prn 'Sequence (show d))) Printed all the sequences from the file, as required. Just to be sure, is `doseq` the correct way to pull items from a lazy sequence like this? Thanks again for your help, Mark -- http://mark.reid.name --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Turning a non-standard iterator into a seq
Hi, I am very new to Clojure and I am trying to turn a SequenceIterator from the BioJava library into a lazy Clojure seq. The interface has two methods `hasNext()` and `nextSequence()` which have very similar semantics to `hasNext()` and `next()` for the standard Java Iterator interface. I have looked into various seq related commands like `while`, `doseq`, `for` but cannot seem to find the right combination to wrap SequenceIterator so that it will lazily return the next item in a sequence until `hasNext()` is false. The closest I've got is: (repeatedly #(.nextSequence sequenceiterator)) which unfortunately throws when `hasNext()` is false. Any help would be greatly appreciated. Regards, Mark PS. Just so there is no confusion, the word Sequence in Sequence iterator has nothing to do with Clojure's seqs - read "SequenceIterator" as "ThingIterator" if it will make it easier. --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---