Chrono date library
This was posted about a little while ago, but a great deal more has happened. Basically, Phil Hagelberg and I have been working on a nice little date library for Clojure that doesn't rely on anything but the Java date APIs. Last time I posted about this, a few people brought up Joda time, which we are aware of. This library is meant for those who want a nice Clojure API with no external dependencies and (usually) no need to dip into Java. It supports: - Creating dates - Accessing date fields similar to maps - Relative dates with earlier and later - Getting the time between dates - Formatting and parsing dates using multimethods The code is available in either mine or Phil's github forks of clojure- contrib: http://github.com/cooldude127/clojure-contrib/ http://github.com/technomancy/clojure-contrib/ We'd like to hear opinions and whether people are willing to admit this into clojure-contrib. Phil has already done his CA, I should submit mine soon. --~--~-~--~~~---~--~~ 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: fitness
what about memoizing the fitness function? call fitness on your structs, and if it's memoized, it will return the cached value as long as the struct is the same value. if it's changed, then it will recompute. somebody correct me if this doesn't account for something, but it sounds like the right approach. On Mar 5, 7:47 pm, Dan redalas...@gmail.com wrote: Thanks for the advice, I never noticed delay existed! It turns out I cannot put the fitness directly into the struct that contains individuals. It would mean that every mutating function would need to reset the fitness computation to avoid propagating a misleading fitness and that's clearly not their job. I can put it in the metadata and then it will not be carried on when I assoc and dissoc things in the struct. However, adding meta returns a new object that's the same as the old but with the meta added so I cannot add the fitness function to the metadata just before computation because other threads holding the data would keep their old objects. Beside burdening my mutation functions with keeping the fitness up to date, I don't see what I can do. Is there something I'm missing? --~--~-~--~~~---~--~~ 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: pretty-printing?
I say go for it. maybe swank could use it for macroexpansions and stuff. the lack of pretty-print drives me crazy! On Jan 27, 10:56 am, Mike DeLaurentis delauren...@gmail.com wrote: Hi, Is anyone aware of a pretty-print function for Clojure? I saw there was some discussion about it on this thread a while ago, but I don't seem to see anything related to pretty-print in either the core or clojure-contrib. If no one's working on implementing it, I might take a stab at it. Thanks, Mike --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com 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: def vs. intern
yes, that is why. On Jan 27, 9:55 am, Mark Volkmann r.mark.volkm...@gmail.com wrote: On Mon, Jan 26, 2009 at 8:19 PM, James Reeves weavejes...@googlemail.com wrote: On Jan 27, 2:08 am, Mark Volkmann r.mark.volkm...@gmail.com wrote: Let's see if I've got this straight. (def foo 1) creates a Var in the default namespace with a value of 1. (create-ns 'com.ociweb.demo) ; creates a new namespace (intern 'com.ociweb.demo foo 2) ; creates another Var named foo, but it's not in the default namespace But the last line gives a java.lang.ClassCastException. What's wrong with that line? Because it should be: (intern 'com.ociweb.demo 'foo 2) Gotta quote that symbol :) Thanks! What's the rationale for treating foo differently than in a def? I'm referring to the need to quote foo in an intern, but not in a def. Is it just because def is a special form whereas intern is a function? -- R. Mark Volkmann Object Computing, Inc. --~--~-~--~~~---~--~~ 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: namespace concept
1) use and require differ in that use does what require does, loads a library, but it also refers to the symbols in that lib in the current namespace. So essentially if you want to use clojure.contrib.def/defvar, if you (require 'clojure.contrib.def), you would have to say (clojure.contrib.def/defvar ...), whereas if you did (use 'clojure.contrib.def), you could then do (defvar ...) 2) dots separate portions of a namespace. they are the same as how dots separate java packages. Slashes separate the namespace and the symbol name when you refer to symbols. they are not included in the name of a namespace (and can't be). 3) yes namespaces can be nested. that's the purpose of the dots, to separate levels of nesting. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Any way we can get this in clojure-contrib?
Under the suggestion of some people in the #clojure channel, I started working on a date library for Clojure since the built-in Java one is kind of a mess. It's not totally complete, but I think it could be quite useful. It supports getting the current date and time, and creating dates based on input. It also has excellent date formatting and parsing support, which allows users do define they're own custom date formats as well as using the built-in java ones. The code is here: http://gist.github.com/49656 I was wondering if this could get added to clojure-contrib. I'm not really sure how things work for the project, but I figured this would be the best place to ask. Dates are a pretty basic data structure, so I think many would benefit from having this. --~--~-~--~~~---~--~~ 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: Any way we can get this in clojure-contrib?
By the way, I'm in the process of sending in my contributor agreement. Just so you know :) --~--~-~--~~~---~--~~ 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: Any way we can get this in clojure-contrib?
We discussed Joda Time, but it was decided that it wasn't a good idea to add another dependency, since this is something so integral to the language. I don't know what other people think, though. This was just an informal decision on #clojure. On Jan 23, 12:05 am, Nick Vogel voge...@gmail.com wrote: That sounds interesting; you might take a look at Joda Timehttp://joda-time.sourceforge.net/. Although I've never used it myself, from what I've heard it's the Java library that people actually use for dates/times (I do know that Google uses it). Doing a quick search, it looks like Mark McGranaghan is working on a Clojure wrapper for Joda Time herehttp://github.com/mmcgrana/clj-garden/tree/masterunder clj-time. On Thu, Jan 22, 2009 at 11:51 PM, Matt Moriarity matt.moriar...@gmail.comwrote: By the way, I'm in the process of sending in my contributor agreement. Just so you know :) --~--~-~--~~~---~--~~ 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 Clojure functions be anonymous, curried and allow composition?
1 is actually an example of partial application of functions more than it is currying. Haskell's currying makes partial application far more natural though. In Clojure you can use the (partial ...) macro to do this: user= (def f (partial + 1)) user= (f 1) 2 2 is done using the (fn ...) special form. It should be noted that (defn ...) to define named functions is actually just a macro that translates basically to (def name (fn ...)) user= (def f2 (fn [x] (* x 2))) user= (f2 2) 4 3 is done with the (comp ...) macro: user= ((comp f2 f) 3) 8 Hope this helped! Matt On Nov 24, 5:54 pm, dokondr [EMAIL PROTECTED] wrote: How can I write the following examples in Clojure that in Haskell will be: -- 1) Curried function: Prelude let f = (+) 1 Prelude f 1 2 -- 2) Anonymous function: Prelude let f2 = \x - x * 2 Prelude f2 2 4 -- 3) Function composition: Prelude (f2 . f) 3 8 Prelude --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Can Clojure functions be anonymous, curried and allow composition?
comp composes functions just like the dot operator On Nov 24, 6:14 pm, dokondr [EMAIL PROTECTED] wrote: On Nov 25, 2:06 am, Jarkko Oranen [EMAIL PROTECTED] wrote: ... -- 3) Function composition: Prelude (f2 . f) 3 8 Prelude 1) (def fn1 (partial + 1)) 2) (def fn2 #(* % 2)) or (fn [x] (* x 2))) 3) ((comp fn2 fn1) 3) -- Jarkko And what is 'comp'? --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: POLL: Domain name for project hosting site.
my vote is for projecture or clojects --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Newbie question: converting a sequence of map entries into a map
what you're looking for i believe is into (into {} (list [:a 2] [:b 3])) {:b 3, :a 2} On Oct 28, 3:05 pm, samppi [EMAIL PROTECTED] wrote: I'm new at Clojure, but I'm really liking it, though. I'm having trouble with using map on a map, and turning the resulting sequence of map entries into a new map. In other words, how can you turn this: ([:a 2] [:b 3]) ...into... {:a 2, :b 3}? Thanks in advance. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Evaluation of arguments in a macro
I am trying to write a macro to rewrite something like this: (set-props my-jframe :title blah :visible true) Into calls to the setter methods. I finally settled on this: (defmacro set-props [obj props] (let [prop-map (apply hash-map props)] `(do ~(for [[key val] prop-map] `(~(keyword-to-method key) ~obj ~val)) ~obj))) where keyword-to-method just converts :title into .setTitle. The problem is that I also want to have helpers for swing objects like frames that use this: (defn frame [ props] (let [f (javax.swing.JFrame.)] (apply set-props f props) f)) except of course this doesn't work because set-props is a macro so i can't use apply. I tried doing this instead: (defmacro set-props-unflat [obj props] `(set-props ~obj [EMAIL PROTECTED])) (defn frame [ props] (let [f (javax.swing.JFrame.)] (set-props-unflat f props) f)) but this also doesn't work because the props in the set-props-unflat call isn't evaluated so i'm just trying to splice in the symbol props. how can i make this work? --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---