#clojure log - Jan 08 2009

The Joy of Clojure
Main Clojure site
Google Group
IRC
List of all logged dates

1:19 knapr: user=> java.lang.ClassCastException: clojure.lang.LazilyPersistentVector cannot be cast to clojure.lang.Symbol (pg.clj:0)

1:19 user=>

1:19 (ns progs.netflix.pg

1:19 (:import (libs.name.choi.joshua [fnparse :as fnp]))

1:20 i have c:/clojure in the classpath

1:20 so but fnparse folder in c:/clojure/libs/

1:24 ah require

1:26 java.lang.Exception: namespace 'fnparse.src.name.choi.joshua.fnparse'

1:26 not found after loading '/fnparse/src/name/choi/joshua/fnparse' (pg.clj:

1:26 ?

1:29 hoeck: knapr: :import is for java classes only

1:30 knapr: yes i did (:require now

1:30 name.choi.joshua is the namespace

1:30 but the whole path is fnparse/src/name/choi/joshua

1:32 hoeck: aha, does your classpath contain "..../fnparse/src/"?

1:33 knapr: C:/clojure

1:33 then i added fnparse/src to the require

1:35 ok worked

1:35 hoeck: cool

4:13 Kerris7: Has there been any movement on the Planet Clojure front?

4:18 duck1123: Kerris7: I think there is a Yahoo Pipes for Clojure

4:18 Kerris7: duck1123: I guess that's no movement, then.

4:39 danlarkin: Kerris7: I want one too :)

5:22 I keep typing "prinln ..." in python... *sigh*

5:22 println I mean

5:35 djpowell: I'm using resultset-seq; Am I right in understanding that when I run code that runs over a seq, that if I'm iterating along the seq with doseq, and nothing is holding onto the head of the seq, that the seq will get garbage collected as I iterate it, and so I can iterate along infinitely longs seqs this way?

5:46 cgrand: djpowell: you're right

5:47 djpowell: cool, thought so - just a sanity check

5:48 I'd had an OutOfMemoryError caused exactly by what is currently being discussed on the mailing list regarding lazyness - hopefully not def'ing the lazy sequence will fix that

5:49 I'm basically using clojure to do some grouping of data from multiple database queries.

6:31 duck1123: clojurebot: braindump

6:31 clojurebot: I don't understand.

6:31 duck1123: that wasn't it

6:31 clojurebot: what do you know?

6:31 clojurebot: I don't understand.

6:32 cgrand: clojurebot: brain dump?

6:32 clojurebot: brain dump is http://clj.thelastcitadel.com/clojurebot

6:33 duck1123: thanks

6:33 cgrand: 404

6:33 :-(

6:34 duck1123: clojurebot: macro help?

6:34 clojurebot: macro help is http://clojure-log.n01se.net/macro.html

6:50 lisppaste8: duck1123 pasted "error trying to pass functions to be evaled and included" at http://paste.lisp.org/display/73288

6:51 duck1123: anyone willing to help me figure this out?

6:57 cgrand: duck1123: did you try with (eval %) instead of (%)?

6:57 duck1123: yes, I got a different error, one sec

6:58 hmm... It's different than the last time I tried, but I'm getting a NPE

6:59 cgrand: why is auth-handlers a fn?

6:59 since it's a fn, try (eval (list %))

6:59 duck1123: there we go: java.lang.ExceptionInInitializerError

7:00 auth-handlers is a fn so I can break them up into different sections. Now that I think of it, it doesn't need to be

7:01 kotarak: duck1123: check the backtrace. There should be something more useful then ExceptionInInitializerError

7:02 cgrand: well, here with ~@(map #(eval (list %)) handler-fns)

7:02 it works

7:03 lisppaste8: duck1123 annotated #73288 with "using eval" at http://paste.lisp.org/display/73288#1

7:06 duck1123: ok, that works somewhat. But now I'm getting quoting problems.

7:06 This may be more work than it's worth

7:06 lisppaste8: cgrand annotated #73288 with "dohandlers" at http://paste.lisp.org/display/73288#2

7:19 durka: is an atom a good choice for a "static variable" in the C sense?

7:19 i.e., a state that needs to be available, and possibly updated, each time the fn is called

7:20 (let [history (atom {})] (fn [...] ... (swap! history ...)))

7:23 s/fn/defn

7:30 Chouser: durka: probably. will it ever be called in a transaction?

7:31 durka: possibly, i suppose

7:31 to the caller it appears side-effect free

7:33 Chouser: if it gets retried in a transaction, 'history' will still contain the changes made by the previous try. Will that break anything?

7:36 durka: in the two places i'm using this so far, yes and no respectively

7:36 :)

7:36 one use case is remembering visited directories to avoid symlink loop while recursively scanning

7:37 the other is memoizing an algorithm

7:37 actually in the first case i think it's fine

7:38 danlarkin: durka: for memoizing you can use clojure.core/memoize

7:38 durka: because the atom is inside the defn, and passed to tree-seq, so if the whole function got retried by a transaction it would be recreated

7:38 danlarkin: there i go reinventing the wheel again

7:48 * danlarkin casually wishes calling (require ...) would return the value of the last form evaluated

7:49 Chouser: durka: good, then you're all set.

7:50 durka: if the chain of questions I asked leads to "a retry might break it", or even if you're just not sure, you can drop back to a ref and you're covered.

7:51 durka: so with a ref i would have to start inernal transactions

7:51 but those would get absorbed into any parent transaction?

7:52 Chouser: right

7:54 * durka notes that clojure.core/memoize is almost identical to my implementation, except as a fn instead of a macro, and that it uses an atom internally

8:04 durka: is add-classpath deprecated?

8:04 Chouser: always has been

8:05 Rich added it somewhat reluctantly, I think, to allow a little bit more flexibility at a REPL, but it's not meant to be used in programs.

8:06 technomancy: it would help if the docstring mentioned its deprecation.

8:07 or if it were fixed to work reliably; that'd be great too. =)

8:07 durka: i'm writing a program that really wants to know the full classpath, and there doesn't seem to be a way to find out what's been added with add-classpath without relying on the internal implenentation of clojure.lang.RT

8:14 technomancy: what's the reason behind the reluctance to write add-classpath?

8:15 it seems like a huge leap forward compared to defining your classpath in CLI args or environment variables, assuming it could be gotten to work correctly.

8:28 Chouser: technomancy: I don't fully understand it. It has to do with classloaders and delegation and other ugly details of the JVM.

8:31 technomancy: so he's not opposed to the idea, he's just opposed to the implementation because it can't be Done Right on the JVM?

8:31 Chouser: I couldn't say, but I guess that's my general impression.

8:36 technomancy: I can buy that.

8:37 rhickey: technomancy: what problems are you having with add-classpath? - made changes recently to fix problem with import

8:38 Chouser: I've hit some kind of wall regarding the reading of every post to the group.

8:38 technomancy: rhickey: I will try it again with a recent build if that implies that it's not deprecated.

8:39 pretty sure it was an import problem though; lisp code was working fine

8:40 replaca: Chouser: just an overload problem?

8:40 Chouser: replaca: :-) possibly.

8:40 Cark: question : it has been a little while since i used clojure so i updated everything but i get an error while starting up swank : No such var: clojure.lang.RT/ROOT_CLASSLOADER (basic.clj:261)

8:41 anybody having this issue ?

8:41 replaca: Chouser: bad for you, but maybe good for clojure. If clojure's successful, the group will end up being split, I'm sure.

8:41 Chouser: or maybe the sophistication of the members is such that each thread is more specialized into a corner I care less about, rather than general Clojure topics that I find compelling.

8:41 replaca: right, I don't mean to imply this is a bad sign for Clojure or anything. Just a sharing a little personal observation. :-)

8:42 replaca: Chouser: you mean like weird proxy ideas :-)

8:42 Chouser: Cark: ROOT_CLASSLOADER is inaccessible as of yesterday. Other code may need to be updated.

8:42 Cark: ah thanks !

8:42 hum any other way to access it ?

8:43 Chouser: Cark: I don't use swank, and don't know if fixes have been made.

8:43 Cark: you can try replacing "clojure.lang.RT/ROOT_CLASSLOADER" with "(clojure.lang.RT/baseLoader)"

8:43 Cark: chouser : ok thank you, i'll do that

8:43 Chouser: replaca: hm, dunno, maybe I haven't read that thread.

8:45 replaca: Chouser: and you're getting senile :-) Cause, you responded.

8:45 Chouser: replaca: ah! oh. hm.

8:47 replaca: Chouser: the thread to which I refer (in which we agreed that I was sick :-)): http://groups.google.com/group/clojure/browse_thread/thread/e51f75750da6cbb8/ab03fa5e5245194a?lnk=gst&q=faulhaber#ab03fa5e5245194a

8:47 Cark: chouser : would you beleive this was fixed as we were speaking !

8:47 Chouser: Cark: I would.

8:51 * achim_p hi all!

8:52 achim_p: that's a bug, right?:

8:52 user=> (- (Integer/MAX_VALUE) (int -1))

8:52 java.lang.ArithmeticException: integer overflow (NO_SOURCE_FILE:0)

8:52 but user=> (- (Integer/MAX_VALUE) (int -2147483648))

8:52 -1

8:56 durka: Gorilla=> (- Integer/MAX_VALUE -2147483648)

8:56 4294967295

8:56 Gorilla=> (- Integer/MAX_VALUE (int -2147483648))

8:56 -1

8:56 that's very strange...

8:59 achim_p: i think i'll post to the group

8:59 replaca: durka: clojurebot gives me -1 in both cases

9:00 ,(- Integer/MAX_VALUE -2147483648)

9:00 clojurebot: -1

9:00 durka: ,(class -2147483648)

9:00 clojurebot: java.lang.Integer

9:00 achim_p: i see why it's happening

9:01 Chousuke: I get -1 for both

9:03 achim_p: it's in Numbers/minus(int, int) the second xor doesn't work because if y = -MIN_INT then -y==y (unchecked)

9:16 Chouser: you have to check your code to make sure it doesn't use reflection if you want it to work as an applet.

9:17 durka: Chouser: did you see my report last night

9:17 on os x your applet works in appletviewer but not in browsers

9:17 Chouser: durka: no, I didn't see that.

9:18 durka-gone: here's a trace http://paste.lisp.org/display/73276

9:19 Chouser: whoa. final method what?

9:19 durka-gone: .

9:19 Chouser: huh

9:19 durka-gone: in the console it didn't have those boxes around the .

9:20 AWizzArd: is there a modulo function in Java/Clojure?

9:21 I don't want rem() but modulo

9:22 kotarak: AWizzArd: I think there was something on the list a few days ago.

9:25 mmcgrana: if I have an arbitrary string, is there a way to get a Pattern equivalent to the one that you would get with using that string in the literal pattern syntax. i.e. #"foo\\" <=> (??? "foo\\")

9:26 AWizzArd: mmcgrana: do you want regular expressions?

9:27 mmcgrana: if i understand you correctly, yes

9:27 Chouser: mmcgrana: re-pattern

9:28 expect then you'd need the literal string to be "foo\\\\" in order to get #"foo\\"

9:28 mmcgrana: Chouser: the syntax is different though, right?

9:28 AWizzArd: To learn more about regex themself have a look at http://www.regular-expressions.info/

9:29 Chouser: the syntax for building the string is different, but once you've built the string re-pattern will give you the equivalent regex Pattern

9:33 mmcgrana: I'm trying to build a tool that needs to take a string in the form of the literal regex syntax and convert it to a pattern. I understand that I need (re-pattern "foo\\\\") to get #"foo\\", but I'm not sure how to go from "foo\\" -> "foo\\\\" programatically.

9:34 danlarkin: mmcgrana: (.pattern #"foo\\")

9:34 Chouser: the problem is literal clojure strings cannot represent all of the possible regex literals. That's exactly why #"" now uses different escaping rules than ""

9:35 #"\w" is a legal regex literal. "\w" is NOT a legal string literal

9:35 mmcgrana: Chouser: ok, ic

9:36 danlarking: I think i was looking for the reverse of that

9:36 srry about the misspelling

9:37 Chouser: mmcgrana: now if you're reading the regex from a file or something, that's a different matter.

9:37 because then it doesn't have to be a legal Clojure string literal

9:38 mmcgrana: yeah, thats the idea. then I can just use re-pattern, right?

9:39 Chouser: yes

9:40 mmcgrana: ok, got it. thanks Chouser, danlarkin, AWizzArd for your help

9:40 hiredman: clojurebot: bit is <reply>0

9:40 clojurebot: Alles klar

9:40 hiredman: clojurebot: bit is also <reply>1

9:40 clojurebot: In Ordnung

9:40 hiredman: clojurebot: bit?

9:40 clojurebot: 0

10:02 aperotte: Chouser: I read on the google group that you were working on texture, how is it coming along?

10:02 Chouser: textjure*

10:03 Chouser: I'm pretty badly distracted by other things.

10:03 at this point it's mostly just another Swing repl

10:07 hiredman: clojurebot: a bit, one bit only!

10:07 clojurebot: 1

10:12 aperotte: Chouser: ok, is there anything I can do to help the project along?

10:13 Chouser: aperotte: sure, any code that leads to the goal would be very welcome

10:13 kotarak: Chouser: is there some repo online?

10:13 aperotte: Chouser: I have the general idea of the goal, but I'm not sure I know exactly what you had envisioned

10:13 Chouser: the goal (for now) is best possible integrated text editor and repl with no extrenal dependencies

10:15 for me, that includes vim-like keybindings, but I'd be content with emacs-like keybindings in a framework that would support vi-like bindings when someone gets around to it

10:15 here's what i've got so far: http://github.com/Chouser/textjure/tree/master

10:15 powr-toc: Is there anyway that clojure could evaluate and display only a small portion of a lazy-seq if (and only if) it was evaluated at the REPL?

10:16 sorry, to be clear I mean evaluated BY the REPL

10:16 hiredman: *print-length*

10:16 Chouser: powr-toc: you can (set! *print-length* 103) to prevent the repl from printing too much

10:16 powr-toc: cool

10:16 aperotte: Chouser: ok, I'll take a look and get back to you

10:17 Chouser: the "no external deps" is specifically to reduce installation complexity and reduce the possibility of breakage due to changes in deps.

10:18 gnuvince_: vi keybindings?

10:18 Chouser: gnuvince_: yes. they are the Right Way to run an editor. :-)

10:19 gnuvince_: In that case, somebody could use Vim. If the intention is to make an editor for people new to Clojure, I think it's fair to assume that a large majority of them will be coming from the Java world where they're used to modeless editing.

10:19 In which case going with the usual keyboard shortcuts would probably be less off putting.

10:19 hiredman: pffft

10:20 Chouser: I agree that should be the default, but I really want both.

10:20 kotarak: Yes! Please!

10:20 gnuvince_: If you can manage to stick them both in there, then there's no problem.

10:20 * abrooks really wants both

10:21 powr-toc: Does the REPL read a .clojure-config file where you can set parameters like *print-length* etc?

10:21 Chouser: I want this to (eventually) be powerful enough for me to use for at least a lot of my Clojure work, even if not for all programming work. Without that, this will always be a thing I'm creating for "other people" and it will be doomed.

10:21 gnuvince_: Do you see the project as a sort of IDLE for Python; a way for new users to test the thing, but most people eventually move away from it?

10:21 Chouser: powr-toc: no. there's a user.clj, but last I knew that gets checked too early.

10:22 gnuvince_: I think if we can get that, we've got a good start, certainly enough to release and support. But I have dreams...

10:23 gnuvince_: k

10:25 Chouser: the thing is, textjure has a lot of competition, primarily in the form of plugins for every IDE and editor under the sun: emacs, vim, netbeans, eclipse, jedit, etc. Which of course is fantastic.

10:25 And a lot of these can share and/or borrow a lot of code from each other, which is also great.

10:26 And it will be hard to lure away anyone who already has a serious investment in any of those, which is also fine.

10:28 danlarkin: Chouser: just build a textmate-like project drawer to emacs, and then it will be the perfect editor. what more could you want? ;)

10:28 Chouser: So the differentiator for textjure is two things: no external dependencies -- grab clojure, grab textjure (or maybe a single .jar with them bundled together) and you've got a solid environment.

10:28 hiredman: clojurebot: emacs?

10:28 clojurebot: but I like using notepad++!

10:29 Chouser: and: 100% clojure. No java code, no elisp code, no viml or ruby. If you know clojure you can tweak any part of it.

10:29 kotarak: Chouser: I would really be happy to see textjure (especially with vi bindings) take off.

10:30 powr-toc: Chouser: have you ever thought of enforcing structure editing (as available for drscheme)?

10:30 Chouser: oh, the no deps give you complete cross-platform support too, which seems to be difficult for a lot of the plugin systems to handle (enclojure sometimes doesn't quite work on Windows, clojure-box only works on windows, etc.)

10:30 kotarak: I like Vim. Bram did an awesome job. But it's limitation regarding external interfaces are starting to annoy me. (read "Gorilla")

10:30 Chouser: kotarak: yes. he was aiming for 100% backward compatibility with vi, which may have made sense at the time, but (for me at least) makes no sense now.

10:31 hiredman: that and vimscript

10:31 kotarak: ah. Vim with Clojure scripting..... *dream*

10:31 Chouser: powr-toc: What do you mean by "enforcing"? From the little i've seen of drscheme, paredit and such, I'd be very interested to have something like that to plug into textjure

10:33 powr-toc: Chouser: just that when run in that mode, free-form textual editing isn't supported, rather everything is managed directly in terms of the sexp AST

10:33 Chouser: powr-toc: how does that handle comments?

10:34 powr-toc: Chouser: no idea, I've never used it ;-)

10:34 http://uk.youtube.com/watch?v=GnQV4je9wTQ

10:34 DivaScheme is what I'm referring to

10:35 Chouser: yeah, I saw parts of a DivaScheme video. looks like it could be useful, but would take some extra effort to learn. So eventually, sure, but not a requirement.

10:37 kotarak: Every feature should be optional. In particular such a rather esoteric editing style.

10:37 powr-toc: Chouser: yeah, when I tried it I found the keybindings too confusing, so abandoned it... I still love the idea though! :-)

10:38 Chouser: I hadn't planned on soliciting help yet, so I don't know what patches I'd accept, but my personal plan is:

10:39 1. finish the keybinding infrastructure to support either default swing text editor bindings or very basic vi-like bindings

10:40 2. add editor commands (load, save, send-to-repl, etc.) to vi bindings, drop-down menus, and default-swing-mode hotkeys.

10:40 3. add syntax highlighting to editor and repl

10:40 4. add indentation support

10:41 I think that'd be enough to be useful to be worth releasing.

10:58 danlarkin: anyone have a quick breakdown of the java web app deal? what the heck is the difference between tomcat/jboss/jetty/looking glass/geronimo/etc? I've tried reading wikipedia but it's all buzzwords to me

11:00 technomancy: Jetty seems to have an emphasis on keeping it small and sane. Tomcat looks frighteningly complex.

11:00 ^ initial uninformed impressions

11:00 drewr: I'd say JBoss is probably the biggest beast in the list, but I'm no expert.

11:01 People seem to like Jetty these days.

11:01 It comes embedded in a lot of stuff I download.

11:01 technomancy: tomcat is written by a guy who thought executable XML should not be an offense punishable with jail time, which rules it out for me.

11:02 danlarkin: Hmm

11:03 Kerris7: lol technomancy

11:03 powr-toc: technomancy: yeah, it's a shame the Java world was obsessed with it for a while :-(

11:03

11:04 danlarkin: a few years ago for a job I had to install (drop some .wars in a directory) some java web apps on our server, at that point it seemed like *everyone* was using tomcat.

11:04 powr-toc: (executable XML that is)... ant, tomcat, various IOC schemes :-( even jetty has it :-\

11:05 technomancy: oh crap; jetty has it too? =(

11:05 walters: yeah, at least they've finally collectively realized dynamic languages make sense

11:06 powr-toc: technomancy: yeah... and it's configuration is possibly even more poorly documented than tomcat :-(

11:06 technomancy: huh... well I only use it through compojure

11:06 looks like jetty doesn't *require* xml, it just supports it.

11:07 powr-toc: technomancy: if you have to, the trick to groking it is to see how things fit together in terms of java interfaces (study the javadocs) and then translate it into the xml :-\

11:07 technomancy: but that does mean it implicitly suggests that it's not a horrible idea, which is incorrect.

11:08 powr-toc: technomancy: that's true... I always found jetty easier to plug together in plain java, but for some systems it's not an option to have configuration compiled in

11:09 technomancy: powr-toc: so far I've been able to let compojure handle all the details, and that's worked great

11:09 powr-toc: thankfully with clojure, you should be able to avoid it :-) though I suspect a thin layer of clojure functions/macro's might help

11:10 sweet! I've only briefly looked at compojure... I love sinatra, so compojure naturally appeals

11:10 danlarkin: and which backend does compojure use?

11:10 technomancy: powr-toc: it's a little weird just because it's so new and there's not a lot of guidelines on how to organize stuff or test stuff, but that just means you get to be involved in those decisions.

11:11 danlarkin: it uses jetty

11:11 Chouser: but people have gotten compojure servlets to work in tomcat, I believe.

11:11 hiredman: clojurebot: compojure?

11:11 clojurebot: compojure is http://github.com/weavejester/compojure/tree/master

11:11 technomancy: clojurebot: compojure is also a concise web framework inspired by Sinatra

11:11 clojurebot: Alles klar

11:12 gnuvince_: (doc lazy-seq)

11:12 clojurebot: Pardon?

11:13 danlarkin: and also pretty much *the* way to write a java web app is to make it a servlet? and then that can be run by a "servlet container"?

11:13 Chouser: (dov lazy-cons)

11:13 (doc lazy-cons)

11:13 clojurebot: Expands to code which produces a seq object whose first is first-expr and whose rest is rest-expr, neither of which is evaluated until first/rest is called. Each expr will be evaluated at most once per step in the sequence, e.g. calling first/rest repeatedly on the same node of the seq evaluates first/rest-expr once - the values they yield are cached.; arglists ([first-expr & rest-expr])

11:13 technomancy: helma (a JS/rhino web framework) uses jetty too, and some folks at work have been deploying rails apps on it.

11:13 since I'm not qualified to have an opinion on it, I'll steal one from others I trust.

11:14 hiredman: I like the idea of generating a war file and just droping in a directory somewhere, but I have no idea if that is how it works, or how to do that

11:14 powr-toc: technomancy: yeah, I used it as an embedded http server a couple of years ago... it's pretty awesome, though the docs could be better

11:15 technomancy: hiredman: I dunno; I prefer a non-violent approach.

11:15 hiredman: :P

11:15 technomancy: ...

11:15 my war file jokes are never as funny as they sound in my head

11:20 powr-toc: What would be the easiest way to address a 2D grid of vectors? [[:X :O :O] [:O :X :O

11:20 ]

11:20 ]

11:21 sorry pushed return too soon! It was supposed to be naughts and crosses grid

11:21 technomancy: ok... if you want a #() function to just return a vector, is there a cleaner way than #(identity [:foo % :bar]) ?

11:22 powr-toc: should I just use a nested nth on X and y?

11:22 hiredman: technomancy: vector

11:22 kotarak: #(vector :foo % :bar)

11:23 technomancy: hiredman, kotarak: of course; thanks

11:23 Chouser: (fn [x] [:foo x :bar]) ends up competing with #() for claity and brevity

11:23 sometimes I switch to using 'for' in these cases.

11:24 technomancy: "for" being list comprehensions?

11:24 Chouser: (for [x my-seq] [:foo x :bar]) instead of (map #(vector :foo % :bar) my-seq)

11:24 technomancy: yeah

11:24 technomancy: I like vector, but fn is better than identity.

11:25 huh... I kinda skimmed that section of the book since it reminded me of "we don't need no stinkin' lambdas" python, but I clearly need to look past my biases. =)

11:25 kotarak: clojurebot: for is not a loop

11:25 clojurebot: Ik begrijp

11:31 gnuvince_: kotarak: excellent blog post, congratulations.

11:31 kotarak: huh?

11:32 gnuvince_: Oops

11:32 Sorry

11:32 Similar names

11:32 I meant Mark Engelberg

11:33 But if you wrote a blog post, I'm sure it would be excellent ;)

11:33 kotarak: hehe ;D

11:43 powr-toc: are there any good code examples for test-is?

11:43 I know it has some included... but I mean, is there anything more substantial that uses it?

11:44 kotarak: There is the clojure test stuff in contrib, I think.

11:45 powr-toc: kotarak: thanks... looking through it now :-)

11:46 kotarak: presumably these are unit tests for clojure and it's library it's self right?

11:46 kotarak: yes

11:52 danlarkin: powr-toc: http://github.com/danlarkin/clojure-json/tree/master/test/test.clj I use it there... pretty basic usage though

12:42 billc: zakwilson: you around?

13:24 technomancy: this "laziness traps" blog post is really thought-provoking: http://programming-puzzler.blogspot.com/2009/01/laziness-in-clojure-traps-workarounds.html

13:26 hiredman: dunno

13:27 StartsWithK: how can i find url of resource that is in the same package as my .clj file?

13:27 hiredman: seems like Chouser's response to him on the group solved his problem, no fuss, no muss

13:27 technomancy: ah; I haven't made it through the thread yet

13:27 spoiler alert! =)

13:28 at least it's helpful to think about how these things work, even if the default doesn't change.

13:45 hiredman: 1d6+3

13:45 clojurebot: 8

13:48 vladsharp_: could anyone provide suggestions for sorting a collection by multiple "keys"?

13:48 of course, i could split the sort results from the first key, then sort the sub-sequences...

13:49 hiredman: reduce the keys into one key

13:50 also

13:50 (doc sort-by)

13:50 clojurebot: 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.; arglists ([keyfn coll] [keyfn comp coll])

13:50 hiredman: wait

13:50 that is not what I wanted

13:50 there is that other one someone was talking about

13:51 *shrug*

13:51 vladsharp_: i'm all ears (yes i could reduce the keys into one, and that would entail a string comparison and be reasonably easy to implement)

13:52 was wondering though if there was a built-in method for doing that, but the documentation didn't yield any results

13:54 danlarkin: there's merge-with..

13:54 (doc merge-with)

13:54 clojurebot: Returns a map that consists of the rest of the maps conj-ed onto the first. If a key occurs in more than one map, the mapping(s) from the latter (left-to-right) will be combined with the mapping in the result by calling (f val-in-result val-in-latter).; arglists ([f & maps])

13:56 danlarkin: I'm not sure exactly what you're asking for, vladsharp_, but would that help?

13:57 vladsharp_: it doesn't look like it

13:57 example: sort a list of strings first based on length, then in lexographic order

13:58 so (a apple b boo) would be sorted to (a b boo apple)

14:03 hiredman: you can use a custom comparator

14:03 (doc sort)

14:03 clojurebot: Returns a sorted sequence of the items in coll. If no comparator is supplied, uses compare. comparator must implement java.util.Comparator.; arglists ([coll] [comp coll])

14:03 hiredman: (doc comparator)

14:03 clojurebot: Returns an implementation of java.util.Comparator based upon pred.; arglists ([pred])

14:07 hiredman: ,(fn [a b] (if (> (count a) (count b)) a (.(defn roll-die [sides]

14:07 clojurebot: Eval-in-box threw an exception:EOF while reading

14:07 hiredman: (let [a (java.util.LinkedList. (range 1 (inc sides)))

14:07 _ (java.util.Collections/shuffle a)]

14:07 (first a)))

14:07 er

14:07 oops

14:08 ,(sort (comparator (fn [a b] (if (> (count a) (count b)) a (.compareTo a b)))) ["a" "apple" "b" "boo"])

14:08 clojurebot: ("a" "apple" "b" "boo")

14:09 vogelrn: hiredman: As I recently learned, you don't actually need comparator because clojure functions implement comparator anyway

14:09 lisppaste8: StartsWithK pasted "Get resource url" at http://paste.lisp.org/display/73303

14:09 hiredman: ,(sort (fn [a b] (if (> (count a) (count b)) b (.compareTo a b)))) ["a" "apple" "b" "boo"])

14:09 clojurebot: java.lang.UnsupportedOperationException: count not supported on this type: sandbox$eval__1885$fn__1887

14:09 StartsWithK: is there another way to get resource url, or is this the right one?

14:10 hiredman: ,(sort (fn [a b] (if (> (.length a) (.length b)) b (.compareTo a b)))) ["a" "apple" "b" "boo"])

14:10 clojurebot: java.lang.UnsupportedOperationException: count not supported on this type: sandbox$eval__1891$fn__1893

14:10 vogelrn: hmmm

14:12 Chouser: StartsWithK: you're trying to find the url to a namespace?

14:13 StartsWithK: Chouser: url to file in same package as my .clj file

14:13 Chouser: anyway, that's the same general procedure that I've used.

14:14 hiredman: ,((fn [a b] (if (> (.length a) (.length b)) b (.compareTo a b))) "a" "b")

14:14 clojurebot: -1

14:14 hiredman: ,(sort (comparator (fn [a b] (if (> (count a) (count b)) b (.compareTo a b)))) ["a" "apple" "b" "boo"])

14:14 clojurebot: ("a" "apple" "b" "boo")

14:14 StartsWithK: thanks

14:15 hiredman: oh

14:15 duh

14:17 vladsharp_: ,(sort (comparator (fn [a b] (if (> (count a) (count b)) nil (.compareTo a b)))) ["a" "apple" "boo" "b"])

14:17 clojurebot: ("a" "b" "boo" "apple")

14:18 vladsharp_: thanks for the hint :P

14:24 vogelrn: vladsharp_: I don't think that quite works

14:24 vladsharp_: vogelrn: i'm not sure why the nil is there, but it works on the example, no?

14:24 vogelrn: ,(sort (comparator (fn [a b] (if (> (count a) (count b)) nil (.compareTo a b)))) ["apple" "a" "booc" "aood"])

14:24 clojurebot: ("a" "booc" "aood" "apple")

14:25 vladsharp_: ah

14:25 lisppaste8: achim_p pasted "comparator cascade" at http://paste.lisp.org/display/73304

14:25 achim_p: vladsharp_: i solved a similar problem like this (see paste)

14:25 hiredman: ,(sort (comparator (fn [a b] (if (> (count a) (count b)) nil (.compareTo b a)))) ["a" "booc" "aood" "b"])

14:25 clojurebot: ("a" "b" "booc" "aood")

14:26 vogelrn: achim_p: that looks a bit complex

14:26 durka-gone: comp-cascade might not be the best name because clojure.core/comp has nothing to do with comparators

14:26 hiredman: ,(sort (comparator (fn [a b] (if (> (count a) (count b)) nil (not (.compareTo a b))))) ["a" "booc" "aood" "b"])

14:26 clojurebot: ("a" "booc" "aood" "b")

14:26 achim_p: durka: right

14:28 vogelrn: ,(sort (fn [a b] (cond (< (count a) (count b)) -1 (> (count a) (count b)) 1 :else (.compareTo a b))) ["a" "booc" "aood" "b"])

14:28 clojurebot: ("a" "b" "aood" "booc")

14:29 achim_p: vogelrn: it's a bit more generic, sorting by count and then lexicographically wasn't exactly what i needed to do

14:30 hiredman: ,(#(sort (list % %2)) "booc" "aood")

14:30 clojurebot: ("aood" "booc")

14:30 vogelrn: achim_p: ah, ok, I think I see what it does now

14:31 I had just glanced at it briefly

14:31 hiredman: ,(#(let [x (sort (list % %2))] (if (.equals (first x) %) 1 -1)) "booc" "aood")

14:31 clojurebot: -1

14:31 hiredman: ,(#(let [x (sort (list % %2))] (if (.equals (first x) %) 1 -1)) "booc" "aood")

14:31 clojurebot: -1

14:31 hiredman: ,(sort (comparator (fn [a b] (if (> (count a) (count b)) nil #(let [x (sort (list % %2))] (if (.equals (first x) %) 1 -1))))) ["a" "booc" "aood" "b"])

14:31 clojurebot: ("a" "b" "booc" "aood")

14:32 hiredman: damn you sir

14:32 vogelrn: what are you trying to do

14:32 hiredman: I don't know any more

14:33 vogelrn: the nil should be a 1, I don't know about the rest :P

14:36 oh, and there's a missing parenthesis before the anonymous function literal

14:37 I think it's checking if the function (rather than its return value) is true

14:37 vladsharp_: hmnnn is this a macro? (map #(% x y) cs)

14:37 vogelrn: (doc map)

14:37 clojurebot: Returns a lazy seq consisting of the result of applying f to the set of first items of each coll, followed by applying f to the set of second items in each coll, until any one of the colls is exhausted. Any remaining items in other colls are ignored. Function f should accept number-of-colls arguments.; arglists ([f coll] [f c1 c2] [f c1 c2 c3] [f c1 c2 c3 & colls])

14:38 vladsharp_: lambda, silly me

14:38 vogelrn: yeah, the #() is an anonymous function literal, with %/%1, %2, etc as the arguments

14:38 vladsharp_: this is pretty much my 3rd day of playing with clojure

14:39 vogelrn: I've been playing with it for a couple weeks, but that doesn't mean much :P

14:40 vladsharp_: hmmm it can be pretty fun (also my first lisp)

14:40 it's the point at which you go oooh so that's where feature x in javascript, ruby, language y comes from

14:41 to some extent, at least

14:41 vogelrn: yeah, although I'm somewhat concerned that it's distracting me from getting acclimated with java again :P

14:42 it's fun to learn, reviewing java stuff, somewhat less so

14:42 vladsharp_: who needs ... oh wait.

14:44 hiredman: clojurebot: give me a bit

14:44 clojurebot: 0

14:44 technomancy: clojurebot: give me a bit

14:44 clojurebot: 0

14:44 technomancy: clojurebot: give me a bit

14:44 clojurebot: 0

14:45 technomancy: hiredman: is it always the same bit?

14:45 hiredman: nope

14:45 technomancy: I was kind of hoping for a 1

14:45 vogelrn: lol

14:45 hiredman: brand spanking new bits each and every time

14:45 vladsharp_: clojurebot: give me a bit

14:45 clojurebot: 0

14:45 hiredman: unless someone futzed with it

14:45 vladsharp_: clojurebot: give me a byte

14:45 clojurebot: Titim gan �ir� ort.

14:46 vladsharp_: that's pretty good compression

14:46 hiredman: clojurebot: gimmie a bit oh that

14:46 clojurebot: 0

14:46 hiredman: huh

14:47 weird, anyway, it sent a 1 in privmsg

14:47 random numbers, go figure

15:15 rhickey: hiredman: fns used as comparators can be either simple predicates or fancier returning -1/0/1 - both work

16:02 murphy_tcc: Hello

16:02 Chouser: hi

16:04 murphy_tcc: Playing around a bit with multimethods in Clojure I wondered whether there was a way to specify the type hierarchy that is used by a multimethod.

16:05 Does someone know whether that's possible?

16:05 Chouser: you can add to the hierarchy

16:05 you're aware of 'derive'?

16:05 murphy_tcc: Sure, but I was wondering whether I could have multiple sets of multimethods that used different hierarchies.

16:08 Chouser: http://groups.google.com/group/clojure/browse_frm/thread/f8b1be403c927b03/a0ec60c2f11554b6

16:09 murphy_tcc: Chouser: Thanks, that's what I was looking for.

16:56 wlr: Chouser: apropos nothing... timestamps on clojure-log are 4h 38min behind the EST for corresponding messages in my chat client :-)

16:56 hiredman: thanks rhickey

17:13 Chouser: wlr: bleh. that server has issues.

22:35 knapr: how do I use standard javatyes? like double[][] for example?

22:38 Chouser: use them in what way?

22:59 zakwilson: knapr: You want a Java array of doubles? See make-array.

22:59 But Chouser has a point. Why do you want that?

23:01 vogelrn: you know, one of the pros of Clojure -is- supposed to be java interop :P

23:02 although maybe I misinterpreted the tone of that, had forgotten what Chouser originally said

23:03 zakwilson: I may have misread his intent. He seems to have been merely asking for clarification.

23:06 Chouser: yes, I didn't mean to be condescending or anything.

23:07 creating an array vs. using an array vs. type hinting an array, etc.

23:09 vogelrn: Chouser: yeah I misinterpreted zakwilson as being condescending until I bothered to look back at what he was referring to: what you said 20 minutes ago

23:20 zakwilson: I probably sounded a little condescending. I shouldn't have.

Logging service provided by n01se.net