2009-05-24
| 02:26 | unlink | If I have a class Foo, containing an enum Bar, with a field BAT, how do I access what would be Foo.Bar.BAT in java? |
| 02:26 | durka42 | try Foo$Bar/BAT ? |
| 02:29 | unlink | durka42: no such namespace |
| 02:29 | durka42 | did you import Foo$Bar |
| 02:29 | unlink | aha |
| 02:29 | durka42 | the $ names inner classes |
| 02:30 | durka42 | or whatever java calls them |
| 06:42 | StartsWithK | fyuryu: hi |
| 06:43 | porpoise | What version of clojure/slime/swank should I be using? |
| 06:44 | porpoise | I was getting some variables not found, swank.swank something, when starting up slime |
| 06:44 | porpoise | After I let ubuntu install libjogl-java and 50 megs worth of java stuff |
| 06:45 | porpoise | Then I removed that, used the sun jdk-1.6.0 and it worked again |
| 06:45 | porpoise | maybe add-classpath has problems with some java setups? |
| 06:47 | fyuryu | StartsWithK: Hi |
| 06:48 | StartsWithK | fyuryu: did you had a time to review the changes maybe? |
| 06:49 | fyuryu | StartsWithK: I just started looking at your repo - never used Ivy so give me a couple of minutes to figure out what's happening there |
| 06:50 | StartsWithK | np, not in a rush myself :) |
| 06:57 | porpoise | Is there a way to change the current path for load-file? |
| 07:02 | StartsWithK | porpoise: you can use add-classpath |
| 07:03 | porpoise | Does that affect load-file? I'm running someone else's code that uses (load-file "foo.clj") instead of the library system |
| 07:04 | StartsWithK | it will give load-file a new location to search for foo.clj, uff, thats for (load) i think, sorry |
| 07:06 | porpoise | I thought so. I'll have to fix the code to use ns and all that |
| 07:06 | porpoise | It'll be good practice for me anyway |
| 07:08 | StartsWithK | :) |
| 07:16 | fyuryu | porpoise: be careful with add-classpath, sometimes it doesn't work |
| 07:16 | fyuryu | porpoise: I don't know why, it probably has something to do with java class loaders |
| 07:17 | porpoise | I know... it's weird. I think that's why swank/slime got borked when I let ubuntu install jogl for me and it insisted on installing its own java (gcj and all that junk) which took precedence over the /opt/jdk1.6.0/bin that was also in my path |
| 10:03 | quidnunc | How can I apply a a function of n arguments to a single sequence such that the elements are consumed n at a time? e.g. (map-n #(+ %1 %2) [3 4 5 6]) => (7 11) |
| 10:08 | arbscht | quidnunc: perhaps (map #(apply + %) (partition 2 [3 4 5 6])) |
| 10:10 | quidnunc | arbscht: Thanks. |
| 10:10 | quidnunc | Also, does anyone know of something like drop-nth? |
| 10:17 | durka42 | ,(letfn [drop-nth [index coll] (concat (take index coll) (drop (inc index) coll))] (drop-nth 2 [1 2 3 4])) |
| 10:17 | clojurebot | java.lang.RuntimeException: java.lang.RuntimeException: java.lang.IllegalArgumentException: Don't know how to create ISeq from: Symbol |
| 10:19 | durka42 | um |
| 10:20 | durka42 | quidnunc: anyway, (concat (take index coll) (drop (inc index) coll)) |
| 10:20 | arbscht | ,(letfn [(drop-nth [index coll] (concat (take index coll) (drop (inc index) coll)))] (drop-nth 2 [1 2 3 4])) |
| 10:20 | clojurebot | (1 2 4) |
| 10:20 | quidnunc | Thanks durka42, make sense. |
| 10:31 | quidnunc | durka42: Actually, I want to drop *every* nth element |
| 10:31 | quidnunc | lazily |
| 10:31 | quidnunc | By the way, is there some automated way to check if a function is lazy? |
| 10:37 | kotarak | quidnunc: not that I am aware off... You can check whether it returns a LazySeq, maybe... |
| 10:37 | kotarak | (defn drop-nth |
| 10:37 | kotarak | [index coll] |
| 10:37 | kotarak | (let [seq-fn (fn seq-fn [step s] |
| 10:37 | kotarak | (lazy-seq |
| 10:37 | kotarak | (when-let [s (seq s)] |
| 10:37 | kotarak | (cond |
| 10:37 | kotarak | (and (= step index) (next s)) |
| 10:37 | kotarak | (cons (second s) (seq-fn 0 (rrest s))) |
| 10:37 | kotarak | (< step index) |
| 10:37 | kotarak | (cons (first s) (seq-fn (inc step) (rest s)))))))] |
| 10:37 | kotarak | (seq-fn 0 coll))) |
| 10:37 | kotarak | not tested |
| 10:48 | Raynes | I don't understand why people wont give up on Arc. :\ |
| 11:01 | rhickey | if I use git-svn it looks like I have to dcommit to the svn server to coordinate anyway |
| 11:02 | rhickey | according to the caveats at: http://www.kernel.org/pub/software/scm/git/docs/git-svn.html |
| 11:03 | ccmtaylor | (defn drop-nth [n s] (let [zip (partial map vector)] (for [[i x] (zip (iterate inc 0) s) :when (not= 0 (rem i n))] x))) |
| 11:04 | rhickey | I wanted to try git-svn for the next big Clojure feature |
| 11:05 | rhickey | looks like I'd have to work on only one machine while I did so |
| 11:14 | Chousuke | rhickey: you can share the commits between git repos normally, but then you can't easily sync with the SVN server. |
| 11:19 | Chousuke | since SVN doesn't keep the same information about commits as git does, the hash changes when you do a dcommit to the svn repo, and if you have shared the old commits to other git repos prior to dcommit, they will not be able to tell that the commits at the svn server are the same as what they have, because the hash has changed. |
| 11:22 | quidnunc | Thanks ccmtaylor |
| 11:25 | Chousuke | rhickey: however, until you actually do a dcommit to the SVN server (thus changing the commit hashes), you can use git like SVN didn't exist at all. |
| 11:27 | rhickey | Chousuke: sounds like trouble, thus the caveat section |
| 11:28 | Chousuke | yeah :/ |
| 11:29 | Chousuke | I suppose it should be possible to always keep a tracking branch for the SVN server, and then periodically rebase on top of it. |
| 11:30 | Chousuke | but that's not exactly trivial either |
| 11:46 | ccmtaylor | quidnunc: here's a better version: (defn drop-nth [n sequence] (mapcat butlast (partition n sequence))) |
| 11:47 | quidnunc | ccmtaylor: Nice, thans |
| 11:47 | quidnunc | thanks* |
| 11:47 | ccmtaylor | quidninc: the other one always drops the first item, so it probably doesn't do what you wanted anyway :) |
| 11:48 | quidnunc | ccmtaylor: Yeah I thought of that. But I thought that it should be consistent with take-nth |
| 11:49 | quidnunc | ccmtaylor: But there would seem to be no easy way to convert the first way into the second (when you didn't want to drop the first). |
| 11:52 | quidnunc | Actually I guess you could just prepend a dummy variable |
| 11:52 | quidnunc | s/variable/value |
| 11:54 | ccmtaylor | quidnunc: actually, never mind. I just found out that the second version I sent stops too early. |
| 11:55 | ccmtaylor | user> (drop-nth 3 (range 20)) |
| 11:55 | ccmtaylor | (1 2 4 5 7 8 10 11 13 14 16 17) |
| 11:56 | ccmtaylor | eh, (0 1 3 4 6 7 9 10 12 13 15 16) |
| 11:57 | Chousuke | that's because partition drops the tail if it isn't evenly divisible |
| 11:57 | Chousuke | there's a conservative variant somewhere in contrib I think. |
| 11:59 | StartsWithK | partition-all in seq-utils |
| 11:59 | ccmtaylor | Chosuke: yeah, but even then it would apply butlast to the tail, which is incorrect. |
| 12:06 | ccmtaylor | quidnunc: if you use (iterate inc 1) instead of (iterate inc 0) in the first version, it shold work: |
| 12:06 | ccmtaylor | user> (defn drop-nth [n s] (let [zip (partial map vector)] (for [[i x] (zip (iterate inc 1) s) :when (not= 0 (rem i n))] x))) |
| 12:06 | ccmtaylor | #'user/drop-nth |
| 12:06 | ccmtaylor | user> (drop-nth 3 (range 20)) |
| 12:06 | ccmtaylor | (0 1 3 4 6 7 9 10 12 13 15 16 18 19) |
| 12:08 | quidnunc | ccmtaylor: Yeah my point was that it would be nice to have a single version that could handle both cases easily. Dropping the first element is more consistent with take-nth but seems less useful (and surprising?). |
| 12:34 | danlarkin | Somehow I've got my emacs config all messed up. I used to be able to M-x slime and have it split the screen open the repl in the bottom buffer, but now it just opens *inferior-lisp* and *slime-repl clojure* in two new full sized buffers |
| 12:35 | danlarkin | any ideas from the crowd? |
| 12:49 | fyuryu | StartsWithK: I started importing some of your changes into cloak. Mainly changes to actions.clj and the dependency on commons.io lib. |
| 12:49 | fyuryu | but I'm not convinced to the way how code is organized. I don't want to rely on other source code, esp. when I have it in a separate project (but of course I'm fine with jars). |
| 12:50 | StartsWithK | fyuryu: to what code are you refering to? clj-unit or your graph/utils? |
| 12:51 | fyuryu | StartsWithK: both |
| 12:54 | StartsWithK | if i move everything under cloak namespace? like cloak.unittest and cloak.graph and remove external directory (that was kind of my plan from the begining) |
| 12:55 | StartsWithK | so cloak.unittest can be used as unit test framework for project using cloak |
| 12:55 | StartsWithK | organisation is lame, thats true, i didn't pay any attention to it for now |
| 12:56 | StartsWithK | problem with test-is, i can't make it automated |
| 12:57 | StartsWithK | same goes for rosado.math.graph and rosado.utils, i would need to patch libs4clj and have a .zip somewhere so i can create packager for it, it was easyer for me to just move 2 files in src/ |
| 13:03 | fyuryu | StartsWithK: what do you mean by "move"? changing the namespaces in clj-unit and moving the files to appropriate dirs? sounds scary - keeping it up to date would require work every time clj-unit has a "release". Ditto graph lib and so on. |
| 13:04 | fyuryu | StartsWithK: Well, for the whole thing to work, all deps should have a maven repo or something. |
| 13:05 | StartsWithK | fyuryu: there would be no updating, cloak.unittest would be a full fork, clj-unit looks fnished to me, i don't think there will be any big changes to it in the future |
| 13:05 | StartsWithK | i can strip clj-backtrace, but it gives such a nice colorful error messages :) |
| 13:06 | fyuryu | StartsWithK: colorful? on windows too? (I've never used clj-backtrace) |
| 13:06 | StartsWithK | fyuryu: i don't know about windows (don't think so, no term codes) |
| 13:07 | StartsWithK | i think it just displays them without any colors, but it also reformats tracebacks to be more human readable |
| 13:09 | fyuryu | StartsWithK: I automated test-is tests. That's how they're run via cloak (which simply means running a clojure script) |
| 13:10 | StartsWithK | fyuryu: but geting a contrib is not automated, it requires a manual step from the user |
| 13:10 | fyuryu | StartsWithK: ah, I see |
| 13:12 | StartsWithK | in worst case scenarion this could only be a temporary solution, once clj-unit and/or contrib get some kind of download site, they could be removed from cloak repo |
| 13:26 | fyuryu | StartsWithK: clj-unit.core uses clojure.contrib.except |
| 13:27 | StartsWithK | fyuryu: not it this fork |
| 13:28 | StartsWithK | i striped it out (it and clj-backtrace used only 2 lines from contrib) |
| 13:33 | slashus2 | Any idea why this concurrent solution is slower than my non-concurrent solution in most of my tests? http://paste.lisp.org/display/80748#2 |
| 13:34 | fyuryu | StartsWithK: I think just having necessary jars in the lib folder is a cleaner solution. I didn't put contrib in there only because I assume everyone has it and it weights 2.6 megs. But I might add clj-unit and clj-backtrace jars there. But that still leaves commons.io - but this one can be pulled via Ivy or Maven |
| 13:37 | StartsWithK | fyuryu: commons-io and clojure are downloaded by ivy in current setup, (and ant, commons-cli, ssh library).. |
| 13:38 | StartsWithK | but if you jar this clj-unit fork, isnt that the same thing in the end, it still lives in cloak repo |
| 13:38 | StartsWithK | with cloak.unittest there is a easy way to add testing actions |
| 13:39 | StartsWithK | and change them to fit cloak workflow (loggers and such) |
| 13:39 | slashus2 | A lot of time is spent on invoke and swap! in each function. |
| 13:44 | Chousuke | hm |
| 13:49 | memoize | all the common lisp guys at work think im crazy not using emacs/slime, is it that awesome? |
| 13:54 | gnuvince_ | memoize: Emacs and Slime *are* really nice. HOwever, it seems that right now, the Clojure support is broken :) |
| 13:55 | memoize | gnuvince_: how so? i got a slime prompt and did simple forms, but still need to lern emacs |
| 13:56 | gnuvince_ | memoize: maybe it's a combination of the versions I use, but some things like auto-doc, completion, etc. were not working. |
| 14:02 | memoize | mad thought: replumb as much of emacs elisp in clojure, remove the bits that don't have to do with editing and lisp :) |
| 14:09 | gnuvince_ | My recent mad thought: considering the performance of the v8 JavaScript engine, re-implement a new Emacs (with no compatibility with GNU Emacs) using JavaScript as an extension language. |
| 14:10 | danlarkin | everyone wants to rewrite emacs :) |
| 14:11 | gnuvince_ | Yeah |
| 14:12 | gnuvince_ | I thought that with everyone whining about Emacs Lisp being dynamically scoped and single-threaded and whatnot, JavaScript would not be a bad choice |
| 14:12 | gnuvince_ | Plus, you get a huge potential developer base :) |
| 14:13 | sohail | can't wait for scriptalicious for emacs! |
| 15:06 | bradford | I am trying to create a function that takes a map of functions and a map of data, and it applys each function in the function map to the entire map of data, the result is a map where keys are the keys in the function map, and the value is the result of the funtion application. |
| 15:07 | Chouser | each function takes the whole data map as a single arg? |
| 15:07 | bradford | it is like (merge-with #(%1 %2) fn-map data-map) ... but not quite because the arg to the functions is not the data in the associated key in the data map, it is the entire data map |
| 15:07 | bradford | chouser: right |
| 15:09 | Chouser | (into {} (for [[k f] fn-map] [k (f data-map)])) |
| 15:10 | fyuryu | StartsWithK: having clj-test in a jar also allows this; and adding testing actions to cloak would probably be done via functions calling clj-test code (maybe not - I'd like the import/require expr. in CLOAK files be small, but I know that's just aesthetics). |
| 15:10 | bradford | chouser: yep, excellent |
| 15:11 | bradford | I had: (into {} (for [key (keys fns)] (key ((key fns) data)))) |
| 15:11 | Chouser | sure |
| 15:11 | Chouser | 'key' is the name of a core function |
| 15:11 | bradford | i did not know that for comprehension syntax that you used for maps |
| 15:11 | bradford | that is really sweet |
| 15:12 | Chouser | yep, it's handy |
| 15:12 | Chousuke | it's just destructuring, really. :) |
| 15:12 | rhickey | git svn clone takes a while... |
| 15:13 | Chousuke | yeah, it does. |
| 15:13 | Chousuke | make sure not to lose your git repo after the first clone :P |
| 15:13 | rhickey | should I git gc after? |
| 15:13 | Chousuke | yeah, unless git does it automatically. |
| 15:14 | rhickey | Is this workflow sound? http://rcoder.net/content/daily-git-svn |
| 15:16 | rhickey | I'm not sure I completely understand it |
| 15:16 | Chouser | yeah, that's pretty good. |
| 15:16 | fyuryu | StartsWithK: for now, I can add your fork of clj-test as a jar. Without a use case, where its source is really needed I'm against having "alien" sources in the repo. |
| 15:17 | Chouser | His workflow is probably even better than mine. I use "master" as my svn-merge branch, and don't do much work in it. |
| 15:18 | fyuryu | what is going on here? rhickey converts to git? |
| 15:18 | Chouser | fyuryu: shh, don't spook him. |
| 15:18 | rhickey | what's the purpose of svn-merge if he merges it back into maste at the end? |
| 15:19 | Chousuke | rhickey: safety I suppse. if you screw up the merge somehow, you can just throw it away and restart. |
| 15:20 | Chouser | didn't paste.lisp.org have a link for "context in channel" for each paste? |
| 15:24 | StartsWithK | fyuryu: ok, i'll get back to you on that one when i'll have more code to show |
| 15:25 | StartsWithK | fyuryu: for now, i'm adding commons-cli to parse command line arguments, and i would split cloak execution from args parsing, that will help with testing too |
| 15:26 | StartsWithK | fyuryu: after that repl generation action and generator of completitons files, ivy and ant wrapper (this will take some time, they are large) |
| 15:27 | StartsWithK | what else.. scm from maven wrapper and some kind of documentation generation system |
| 15:27 | StartsWithK | i think thats about it |
| 15:28 | StartsWithK | ahh.. yes, ant build facade generator, so cloak can be used from netbeans or eclipse |
| 15:28 | rhickey | Chouser: so for a simpler workflow, I'd just create a local branch, work in it, commit etc, then eventually switch to master, rebase, then merge in local branch, then dcommit from master? |
| 15:29 | Chouser | rhickey: yes, I think that would work fine. |
| 15:30 | Chouser | if svn rebase in master pulls in changes, you'd want to rebase or merge those onto your local branch, I think, before merging into master and dcommiting |
| 15:30 | rhickey | that's where I get confused |
| 15:31 | Chouser | I don't want to sound too confident, because although I don't seem to have too much trouble, I feel like I'm mostly flailing around until I get the merges and logs that I want. |
| 15:31 | Chouser | well, if you just going to throw away that local branch, it shouldn't matter. |
| 15:32 | Chouser | but if you're going to keep working in the local branch, you probably want it to have commits in the same order as master |
| 15:33 | rhickey | I can rebase in the branch? |
| 15:33 | Chouser | if master has commit A, and local branch has A then B, then you merge svn change C into master, then merge local branch into master, master will have something like A C B, while local branch has A B |
| 15:34 | Chouser | if you then rebase local branch, it'll have something like A B C instead. I don't know if that causes any long term problems, but the diff for C from one branch might look different from the diff for C in another. and you might have to merge the same thing a couple different ways. kinda messy. |
| 15:35 | Chouser | so if master has A |
| 15:36 | Chouser | so if master has A C and branch has A B, I'd recommend "svn rebase master my-branch" so that branch has A C B. Then you can merge branch into master and have A C B in both, then dcommit. |
| 15:37 | rhickey | all the other examples I found didn't bother to make a local branch, which I thought was the git way - always work in local branches |
| 15:37 | Chousuke | it's good practice, but optional |
| 15:38 | rhickey | Chousuke: how else can I fix a bug without putting up my new features? |
| 15:39 | fyuryu | StartsWithK: sounds great :-) |
| 15:40 | rhickey | Chouser: so - create a local branch, work in it, commit etc, then eventually switch to master, rebase, switch to branch, rebase from master, switch back to master, then merge in local branch, then dcommit from master? |
| 15:40 | Chousuke | rhickey: I suppose you need a local branch for that :p |
| 15:41 | Chousuke | with a local branch you have complete control of it. after the branch is published, others might depend on changes in it, and you don't have as much freedom. |
| 15:48 | Chousuke | I suppose it's easier to think of in terms of commits. if you have published commits, you may not do anything that would change those commits (other than making a new commit, of course) |
| 15:50 | fyuryu | StartsWithK: I'll be doing the merge during the week; most likely after Tuesday. |
| 15:50 | Chouser | rhickey: yeah, that's about what I do. |
| 15:59 | StartsWithK | fyuryu: i'll try to clean the build.xml and add clojure related actions (maybe ivy wrapper) by then |
| 16:03 | rhickey | Chouser: wow |
| 16:03 | Chouser | rhickey: and of course update bug tracking, related docs, etc. go in there too. |
| 16:04 | Chouser | well, let's see -- that's what I've done for clojure, but that's mainly because I want to be able to cherry-pick commits so that I can re-create clean diffs against whatever version. |
| 16:05 | Chouser | for contrib and other projects, I often don't try to maintain a clean master. |
| 16:06 | Chouser | So in those cases my workflow is more: [stash, rebase, stash pop] every so often, and then [commit, dcommit] when I'm ready. But that doesn't allow for pushing branches around to working copies on other machines (which is not a common use case for me anyway) |
| 16:11 | Chouser | note it's not particularly difficult to switch from one flow to the other mid-stream. It's not uncommon for me to switch from the latter (lighterweight) process to the former when I realize this set of changes needs to be set aside for a while or something. |
| 16:11 | Chouser | gotta go. |
| 16:11 | rhickey | Chouser: thanks for your help |
| 16:42 | bradford | if I want to do something like this: (defn query [table & columns] (str "select " columns " from " table)) |
| 16:43 | bradford | then what do I need to do with columns in order to get it to stop resulting in this: "select (\"a\" \"b\") from x" |
| 16:59 | gnuvince_ | Clojure book just shipped! |
| 17:00 | danlarkin | neato |
| 17:02 | slashus2 | So beta 9 is the final? |
| 17:02 | bradford | this was the anwser to my question above: (defn query [table & columns] (str "select " (str-join " " columns) " from " table)) |
| 18:38 | gnuvince_ | If anyone feels like responding to this gentleman: http://uxul.wordpress.com/2009/05/25/clojure-performance-tips-wtf/ |
| 18:52 | danlarkin | gnuvince_: he's totally right though |
| 18:53 | gnuvince_ | I know |
| 18:53 | gnuvince_ | I agree that Clojure's compiler should be a lot better |
| 18:53 | slashus2 | I just tested Common Lisp for the (+ 1 2 3) thing, and it seems to be about the same as (+ 1 (+ 2 3)) |
| 18:53 | slashus2 | I was curious. |
| 18:53 | gnuvince_ | But I don't know if this person is aware of some of the time constraints put on Rich by people wanting to use Clojure right now for their profesionnal work and by Stuart's book. |
| 18:55 | duck1123 | it would be so funny if the only comment to that was rhickey saying simply "patches welcome" |
| 18:56 | gnuvince_ | How would that be funny? |
| 18:56 | danlarkin | duck1123: but unproductive |
| 18:58 | dreish | It would be nice if a symbol could be a macro for some arities and a function for others. That would solve the + problem. |
| 18:58 | slashus2 | symbol macros |
| 18:58 | slashus2 | ? |
| 18:59 | slashus2 | Something like constants would be nice for performance too. |
| 19:02 | danlarkin | I think the clojure compiler has a lot of room to get better |
| 19:02 | slashus2 | I am sure it will. |
| 19:02 | danlarkin | I think the idea is to rewrite it from java into clojure, and then start hacking on it |
| 19:04 | slashus2 | I know that Mr. Hickey stated that the upcoming invoke dynamics stuff won't help much, but would it help with the reflection performance? Does invokedynamic automatically do the reflection stuff? |
| 19:22 | slashus2 | Having sum and product in the API would be convenient. I can't find it in contrib, which leads me to writing (reduce + coll) and (reduce * coll). Not too much trouble, but sum and product would lead to less typing. |
| 19:53 | Chouser | that performance link above is interesting -- it seems like if you actually wanted to influence a project you would say (and hopefully mean) something like "if not for X, I would use it". Instead he says "I don't like it and it's a step in a bad direction. Also they should really fix X" |
| 21:17 | Drakeson | how do you compare two strings? |
| 21:18 | Drakeson | (> "a" "b") and (string> "a" "b") fail |
| 21:18 | stuhood | Drakeson: (=str1 str2) |
| 21:18 | stuhood | oh |
| 21:18 | Drakeson | sorry, I wasn't clear |
| 21:19 | slashus2 | ,(.compareTo "a" "b") |
| 21:19 | clojurebot | -1 |
| 21:19 | stuhood | that's interesting. i know you could just use the java method to compare them, but i hope there is a clojure way as well |
| 21:20 | stuhood | i guess (<) probably isn't overloaded for speed reasons |
| 21:20 | slashus2 | It would be neat if > and < were multimethods, but the performance aspects come first. |
| 21:20 | slashus2 | or overloaded.. yeah |
| 21:21 | Drakeson | common lisp has string> and string< |
| 21:23 | slashus2 | Drakeson: there is actually compare without having to do the . and it works with nil |
| 21:23 | slashus2 | ,(compare "hello" "goodbye") |
| 21:23 | clojurebot | 1 |
| 21:24 | Drakeson | cool. thanks. |
| 21:27 | Drakeson | unrelated to the previous question, is there an idiomatic way to write (sort #(> ((comp count second) %1) ((comp count second) %2)) things) ? |
| 21:29 | Drakeson | this might raises too often when you want to sort a collection based on some function applied to each element. |
| 21:30 | hiredman | you mean like, sort-by? |
| 21:30 | hiredman | ,(doc sort-by) |
| 21:30 | clojurebot | "([keyfn coll] [keyfn comp coll]); Returns a sorted sequence of the items in coll, where the sort order is determined by comparing (keyfn item). If no comparator is supplied, uses compare. comparator must implement java.util.Comparator." |
| 21:31 | hiredman | (all clojure functions implement Comparator btw) |
| 21:32 | Drakeson | oh, sorry for the noise. I didn't expect another function beside sort. |
| 21:32 | Drakeson | and thanks |
| 21:37 | danlarkin | I've got an API/opinion question for whoever cares to weigh in... so for this couchdb library there's all these functions that take a database (string) as the first arg... but I guess there's value in a with-database function or something |
| 21:37 | danlarkin | which you could sortof simulate using doto |
| 21:37 | danlarkin | or perhaps a modified version of doto that returns the value of the last form, instead of the database name, in this case |
| 21:38 | danlarkin | but that would limit the contents of the with-database form to only direct calls that take the db as their first arg |
| 21:38 | danlarkin | no ifs, no lets, etc |
| 21:40 | danlarkin | so that's not as useful...so then I was thinking oh maybe I can macroexpand the forms that are passed to with-database and search them all for functions in the library namespace, and stick in the database string as the first argument in the form? |
| 21:40 | danlarkin | but that just seems crazy |
| 21:40 | Chouser | yeah, crazy |
| 21:40 | Chouser | :-) |
| 21:41 | Chouser | a dynamic var and 'binding' or a 'with-database' that expands to 'binding' seems like a pretty good solution |
| 21:41 | Chouser | the biggest drawback I've found with APIs like that is when you want to switch between a couple different (in this case) databases. |
| 21:42 | Chouser | ...then an arg would be much less verbose than the several with-database calls you'd need. |
| 21:42 | danlarkin | mmmhmm |
| 21:43 | danlarkin | but there's no way to do both, that I can see |
| 21:44 | Chouser | are all your functions such that you could have an optional first arg? |
| 21:44 | Chouser | or take keyword args on the end? (query foo bar :database db1) |
| 21:45 | danlarkin | unfortunately no, since some functions take an optional last arg |
| 21:45 | danlarkin | mmmmmmmm |
| 21:46 | stuhood | php's solution is dumb on the surface: all of the database functions have versions that don't require a db object, and assume that the last db object you created is the one you wanted to use |
| 21:46 | stuhood | so a global *last-db* var |
| 21:48 | danlarkin | another option is to have all the functions take a map of args instead of ordered args, and if there's no :database key in the map then use the *database* binding |
| 21:49 | danlarkin | but that's so ugly |
| 21:53 | slashus2 | Maybe you can input all of the databases you will be using at the first, and be able to retrieve them from a map or something? |
| 21:54 | Chouser | what's ugly about :database falling back to *database*? |
| 21:56 | danlarkin | well it'd be ugly to have to pass a map for all the args to all the functions |
| 21:56 | danlarkin | but I guess as long as I don't have any functions that take varargs I can use :database "foo" on the end... |
| 22:01 | Chouser | or if they can't accept a keyword as their last arg (whether varargs or not) |
| 22:04 | danlarkin | I suppose I could also allow nil to be passed as the first arg, which would use *database*... but at that point is there really even a benefit |
| 22:04 | Chouser | eh, yeah. |
| 22:05 | cads | hey, there was a testing framework that allowed randomized testing, called fact. I was looking for examples of fact in use, and in the clojure group post where the author introduces fact, he mentions that for examples looks at the tests for enclojure |
| 22:05 | cads | but all of those have been recently rewritten using test-is |
| 22:06 | cads | since fact and enclojure are written by the same guy, I was wondering if he still intends fact for use, or if the community focus has come to be mostly on test-is and he's decided to go with that himself |
| 22:07 | danlarkin | I liked each function taking all the args because it seemed the most functional |
| 22:13 | cads | anyone know about randomized testing in test-is? |
| 22:13 | Chouser | cads: don't know, sorry. |
| 22:14 | cads | I think i'll make a fixture using the montecarlo monad :) |
| 22:15 | cads | and then create random streams to test the properties of my functions |
| 22:27 | duck1123 | cads: I think James abandoned fact because he felt it wasn't working out for him |
| 22:28 | duck1123 | there's a post about it in the compojure group |
| 22:28 | cads | I wonder if there aren't a lot of cases where you just have to create the test data by hand |
| 22:29 | cads | but I know that haskell's quickcheck works real well |
| 22:29 | cads | and that it's only like 200 lines of haskell |
| 22:30 | cads | though quickcheck might do crazy type-system wizardry |
| 22:30 | duck1123 | if i remember correctly, fact worked, but it was too much effort for too little usefulness |
| 22:31 | duck1123 | I never gave it a fair try, so I can't really say |
| 22:32 | cads | I think a combinator library for generating random test data is a good idea, and then you can specify invariants you want your functions to hold over those data |
| 22:37 | duck1123 | Yay, my compojure app is now building, testing, and running completely through maven |
| 22:37 | stuhood | good stuff |
| 22:38 | stuhood | i loved how easy clojure was to drop into an existing project that i build with ant |
| 22:38 | duck1123 | I wonder how many library projects would be willing to accept patches to move their directory structures around to follow maven conventions |
| 22:38 | stuhood | aside from the fact that our coverage testing library choked on clojure-generated bytecode |
| 22:39 | duck1123 | clojure can get nasty when you have many library dependencies |
| 23:03 | felzix | what should I do to evaluate a LazySeq? |
| 23:03 | duck1123 | yes |
| 23:03 | duck1123 | you should 'do |
| 23:04 | stuhood | use a function that you would use on any collection, and the sequence will be generated |
| 23:04 | stuhood | *as much as is needed |
| 23:04 | felzix | println doesn't seem to be working |
| 23:04 | felzix | since it's printing that it's a LazySeq instead of the contents |
| 23:05 | hiredman | felzix: prn-str |
| 23:05 | stuhood | ,(class (range 0 2)) |
| 23:05 | clojurebot | clojure.lang.Range |
| 23:05 | stuhood | ,(ancestors (range 0 2)) |
| 23:05 | clojurebot | nil |
| 23:06 | stuhood | hm, ignore me |
| 23:07 | danlarkin | ,(prn (lazy-seq "foobar")) |
| 23:07 | clojurebot | (\f \o \o \b \a \r) |
| 23:10 | felzix | doesn't seem to be working |
| 23:11 | felzix | now it's printing with quotes around it |
| 23:11 | stuhood | can you show us the code you are trying to run? |
| 23:12 | danlarkin | prn prints the quotes |
| 23:12 | danlarkin | perhaps you want println |
| 23:13 | felzix | http://pastebin.com/d5a0240a8 |
| 23:14 | felzix | the printing is actually for debugging |
| 23:16 | stuhood | this isn't related to your problem, but i'd recommend using (apply str (map...)) rather than (reduce str "" (map ...)), since the latter will create a bunch of intermediate strings |
| 23:16 | felzix | ah, that makes sense. thanks for the tip |
| 23:19 | felzix | oh, thinking about it, I don't think that code is really sufficient. The problem is that "middle" gets printed as a lazyseq |
| 23:20 | stuhood | what are you passing in as middle? |
| 23:23 | felzix | unfortunately, it's confusing. I think I got ahead of myself and need to test things more thoroughly |
| 23:23 | felzix | thanks, though |
| 23:24 | stuhood | np, good luck |
| 23:24 | felzix | thanks |
| 23:28 | vo | i noticed that the clojure api has "printf". it appears to return nil. is there a "printf-str" or something built-in that does formatted printing to a string? |
| 23:29 | slashus2 | ,(format "A string: %s" "yep") |
| 23:29 | clojurebot | "A string: yep" |
| 23:29 | vo | ooh, i see |
| 23:29 | vo | thanks |