#clojure logs

2008-10-21

00:00crathmanis there a random function? (or do I need to use Java's?)
00:02sohailunderneath, is lazy-cons an iterator?
00:02arohnercrathman: use java's
00:03arohnersohail: what do you mean by iterator?
00:03sohaillike Java's Iterator interface
00:04arohnerit looks like LazyCons just implements the clojure seq interface, but seq is a java iterator
00:20sohailyep, that's what I'd expect
00:23Chousercrathman: or (rand-int 10)
00:23ChouserJava iterators mutate, don't they? Seqs don't.
00:23crathmanChouser: thanks
00:24arohnerChouser: ASeq.java has a function called iterate() that returns an Iterator
00:25Chouserah, so they provide an iterator, but aren't iterators themselves?
00:25arohnerlooks that way. ASeq does not implement iterator
01:53PupenoGood morning.
02:16Lau_of_DKMorning gents
05:46Lau_of_DKIs dotimes purely for side effects, or can I do something similar to :collecting i in it ?
06:10Lau_of_DKAnybody remotely awake?
06:10tWipyes
06:10Lau_of_DKGood, just checking, good to see you again :)
06:10Lau_of_DK(truth is, I just solved it)
06:14ccmtaylorLau_of_DK: try for: (for [i (range 10)] i)
06:20Lau_of_DKuser=> lst
06:20Lau_of_DK((1 2 3) (1 2 3 4) (1 2 4 5 6) (1 2 3 4 5))
06:20Lau_of_DKIf I have a list of lists - How do I reduce it, so that I only retain the one with the longest count ?
06:27hoeckLau_of_DK: (reduce #(if (< (count %) (count %2)) %2 %1) foo)
06:27hoeckoops, where foo == your list-of-lists
06:28Lau_of_DKAnd that works with more than 2 ?
06:29hoeckyes
06:29Lau_of_DKThanks alot Hoeck!
06:31alvin-xwould somebody mind commenting on the style of the code here: http://paste.lisp.org/display/68926
06:31alvin-xi started writing clojure yesterday
06:32hoeckLau_of_DK: always a pleasure to help you!
06:32Lau_of_DKGlad you feel that way! :)
06:40hoeckalvin-x: looks good!, maybe convert the single-arg anonymous functions into #()-style for better readability
06:41AlephInf alvin-x: also you can say (ObjectName. bean-name) instead of the (new ..) if you prefer, Also, don't need the nil in the else of the (if .. ) since it defaults to nil anyway.
06:42alvin-xhoeck: i didn't see anything yet on clojure.org about #()-style... can you give me a link?
06:42jdzAlephInf: in which case one should use 'when'
06:43jdzand #( reader is not always better than fn
06:44Lau_of_DKHoeck :) Can you lend a hand again please.
06:44Lau_of_DKuser=> (combos 41)
06:44Lau_of_DK6
06:44Lau_of_DKuser=> (reduce max (map #(combos %) (range 1 45)))
06:44Lau_of_DKjava.lang.IllegalArgumentException: Wrong number of args passed to: combos--5722$fn
06:44Lau_of_DKI dont get it - I get this error whenever I call combos from another func
06:46jdzLau_of_DK: you can safely replace (map #(combos %) ...) witch (map combos ...)
06:46Lau_of_DKoh
06:46jdzLau_of_DK: that's in case it accepts only one argument.
06:46jdzLau_of_DK: from the error message it looks like it wants more
06:46Lau_of_DKSame error
06:47Lau_of_DKAs you can see from my manual call to combo, it takes 1 integer
06:47hoeckLau_of_DK: can you paste combos, cause combos--5722$fn looks like an inner function of combos
06:47Lau_of_DKI sur ecan
06:47jdzjust what i would suggest next...
06:48lisppaste8Lau_of_DK pasted "Prime components" at http://paste.lisp.org/display/68927
06:50jdzLau_of_DK: look at your recur expression
06:50jdzoh wait, scratch that
06:51Lau_of_DKCould this be bcause partition might throw nil ?
06:51jdzbut it seems to me that loop's and function's recur points conflict...
06:52Lau_of_DKIf you try (combo 17) or (combo 41) you'll get good results
06:52jdz(which seems unlikely)
06:52Lau_of_DKI think its partition
06:52Lau_of_DK(combo 2) throws the same error
06:52jdzi think it's reduce
06:52Lau_of_DKHow do I work around it ?
06:53Lau_of_DKthats right, it might be reduce
06:53Lau_of_DKyes
06:53Lau_of_DKthat was it
06:53hoeckalvin-x: Anonymous function literal, http://clojure.org/reader
06:53Lau_of_DKby initiating th vector result with [(list n)]
06:54Lau_of_DKthe problem is solved
06:54Lau_of_DKThanks guys, you ask good questions
06:55jdzLau_of_DK: the way you have written your function leaves no space for optimizations (e.g., memoization)
06:56jdzand I might be talking nonsense, of course
06:56jdzjust ignore
06:56Lau_of_DKNo no youre right
06:56Lau_of_DKIm working on that atm
06:57jdzLau_of_DK: and instead of writing (doall (take-while ...)) you should have just written (take n)?
06:57jdz(or at least (doall (take n ...))
07:05alvin-xhoeck: thanks, that's a good place to shorten the fn
07:06alvin-xwhat's the usual tab/indent width level here... 2? or, is there some style guide?
07:06alvin-xach, tab/indent width*
07:07jdzalvin-x: i'd guess it's the usual lisp style, which happens to be mostly 2 spaces
07:10Lau_of_DKjdz, do all forces computation, which speeds up things ALOT when we get into the higher numbers
07:21alvin-xi tried a lot of other dynamic JVM languages before sitting down to write something in clojure; i don't miss any of them now.
07:33Chouseralvin-x: did you see (doc bean)? It might help you out (or might not if I'm misunderstanding your goal)
07:38Chouseralvin-x: Dunno if you saw my comment before your client logged off. Do you know about (doc bean)?
07:39alvin-xChouser: i saw it :) brb
07:40Chouserok
08:01alvin-xChouser: sorry, something came up at work. My goal is to have a few easy to use functions for calling remote JMX beans; you'll see the normal java code i'd have to write here: http://java.sun.com/javase/technologies/core/mntr-mgmt/javamanagement/best-practices.jsp#mozTocId805713 ("Code without a proxy").
08:03alvin-x(I can't use the proxy example there, as I don't have java interfaces. Not sure if it would work if I wrote the interfaces myself.)
08:05alvin-xI'm a middleware sysadmin, working on a short term solution for monitoring some app servers.
08:09jdzLau_of_DK: my comment was not about doall, but about 'take' instead of 'take-while'
08:20Lau_of_DKcan I assign a glob-var in a local scope, with some syntax tricks?
08:37achim_pLau_of_DK: binding perhaps?
08:39achim_p(in case thread-locally shadowing the value is enough ...)
08:41AWizzArdMoin Leute
08:46AWizzArdbtw, is it normal that it takes several hours until a posting appears in the google group?
08:46jdzwhen collecting stuff in loop, is it better to use cons + reverse at the end with lists or conj with vectors?
08:46cemerickAWizzArd: yeah, it can take a long time. It's sporadic, especially if you post via email.
08:47AWizzArdjdz: I would suggest vectors in general
08:47H4nsAWizzArd: i think the group silently drops postings from email addresses that are not members
08:47lisppaste8Lau_of_DK pasted "Optimize me! (primes)" at http://paste.lisp.org/display/68933
08:47H4nsAWizzArd: has bitten me multiple times, that.
08:47AWizzArdI see
08:47Lau_of_DKFriends - I need help! :)
08:48AWizzArdalso when I joined the group.. it took hours until the member counter went up
08:48Lau_of_DKThis seems to generate correct results. Try (combos 17) (combos 41) and so on. (euler-50 1000) also runs pretty descently. But the target is 1000000 and here I experience incredible slowdowns
08:48Lau_of_DKHow do I optimize this ?
08:50AWizzArdcemerick: also a map could be nice for you.. you would not need to reverse it, depending on your algorithm
08:50AWizzArdand if you use just numbers it will have around O(1) access time, as the hashes will always go into unit buckets
08:51lisppaste8Lau_of_DK annotated #68933 with "Forgot a little something" at http://paste.lisp.org/display/68933#1
08:51AWizzArdLau_of_DK: your indentation style is truly unique... ;-)
08:52Lau_of_DKYes, its Notepad++ at its best - Sitting at work atm :)
08:53AWizzArdBtw, in slime+clojure the auto indentation style of IF is not so nice. Is that only for me?
08:53Lau_of_DKI'll tell you if you optimize my routine
09:02AWizzArdI guess this Euler stuff is only interesting to young people, and only for some time.
09:02gnuvinceProject Euler is pretty fun to learn a language.
09:02AWizzArdyeah
09:03AWizzArdhowever, I mean it's nothing that you would like to do the coming four years
09:03Lau_of_DKachim_p, you can come work here, Ive resigned my position :)
09:03achim_pthat's true for work in general, in my case
09:09Lau_of_DKany takers?
09:12Lau_of_DKSomebody do a Sieve or something! :)
09:15AWizzArdLau_of_DK: can you develop a newsready for the Clojure google group? So that I can read messages and keep track of which I already read, without the need to use my browser for that?
09:15AWizzArdnewsreader
09:15Lau_of_DKYou dont like Thunderbird?
09:18AWizzArdi like it, but GG doesn't offer nntp
09:18H4nsAWizzArd: i read the group in my mail reader
09:18H4nsAWizzArd: nntp is so 1990ies
09:19AWizzArdH4ns: how do you do it?
09:19H4nsAWizzArd: with my eyes! :)
09:19achim_pLau_of_DK: if you'd bother translating your algorithm to plain english, i'd give it a shot in a couple of minutes, but first i'll have to wrestle with john nash some more
09:19H4nsAWizzArd: you can have the group send the articles by mail
09:19Lau_of_DKAWizzArd, I had Googlegroup in my Thunderbird inbox
09:19Lau_of_DKWorked like a charm
09:19Lau_of_DKJohn Nash ?
09:20achim_pyeah, he's here on my desk
09:21jdzcan anybody quickly tell how to create a Java byte array (byte[])?
09:23AWizzArdI just would have preferred if I could see all news ever written in that group.
09:23achim_pjdz: make-array with Byte/TYPE, or to-array on a collection of bytes should work
09:24jdzachim_p: well, what's the Byte/TYPE magic?
09:25achim_pthat's java weirdness. there are some types which are both primitives and class-based types in java
09:25achim_pa byte isn't directly an instance of Byte, as far as i understand it
09:25jdzachim_p: ok, something like (make-array (. Byte TYPE) 4096), right?
09:26Lau_of_DKor (to-array ...)=
09:26cemerick(make-array Byte/TYPE 4096) is fine
09:26jdzLau_of_DK: the point is i want to create an empty buffer..
09:26cemerickstatic fields and functions can use the slash notation
09:26jdzcemerick: oh, cool. didn't know that.
09:27jdzthanks guys.
09:27jdz(it works :)
09:29lisppaste8Lau_of_DK pasted "Optimize me! (primes)" at http://paste.lisp.org/display/68934
09:29Lau_of_DKOk, thats pretty well commented, I think! :)
09:32fogusHas anyone used the J text editor in the past?
09:32cemerickfogus: isn't it just a vehicle for ABCL?
09:33fogusYes, but I wonder if it would be possible (nevermind worthwhile) to use Clojure as a stand in
09:34cemerickpossible, maybe. I don't remember there being much worthwhile in J itself (although ABCL is quite the conformance-engineering feat).
09:35fogusThat was the crux of my question... usefulness.
09:35cemerickI think there could be a lot of possibility in building a framework on top of netbeans to allow for clojure-driven scripting, UI construction, etc. I'm sure the enclojure guys have thought a lot about this.
09:37lisppaste8jdz pasted "Reading .gz files (if anybody cares)" at http://paste.lisp.org/display/68935
09:39jdzi think the Clojure's slurp function could be better defined using slurp-byte-stream
09:40jdzmaybe i'll look into java.nio if there's anything useful for this purpose
09:41jdznever done anything with it, though. only heard good rumors.
09:43jdzand then there is a bug in my code. it does not handle the case if the first read from stream returns -1
09:45aperottehello everyone, had a question. I read in the api that there are some subtleties in how clojure deals with protected members of classes. If a library requires that I subclass and set a protected member that was inherited from a superclass, is this something that's possible?
09:46aperottespecifically, I'm trying to translate the Hello World jME tutorial into clojure http://www.jmonkeyengine.com/wiki/doku.php?id=starter:hello_world
09:47lisppaste8jdz annotated #68935 with "Updated version of slurp-byte-stream (almost untested)" at http://paste.lisp.org/display/68935#1
09:48jdzi long for fill-pointers a bit
09:51Pupeno-GWas there a special name to give to a file inside a jar so that Clojure would pick it up and run it automatically without a little main in Java?
09:52Chouseruser.clj
09:52Pupeno-GChouser: so, how does it work? there's a little main already in Clojure.jar?
09:55ChouserI think you still need to specify clojure.lang.Script on the command line
09:55Pupeno-GChouser: oh, ok.
09:55Pupeno-GUnderstood now.
09:58Chouseraperotte: you can overload protected methods using proxy
10:46aperotteChooser: thanks. I'm going to give it another go.
10:49aperotteChooser: Are you saying that I should just override it to make it public? What's happening in my particular case is that there's a super-class that defines a protected member, that is inherited by the class the library expects me to extend. So the protected member isn't even defined in the class I'm inheriting from, it's defined in the class it inherits from.
10:50rhickeyHi all from Nashville airport - on my way back from Lisp 50
10:50Chouseraperotte: and is this member a method you want to override, or a field you're trying to set or something?
10:50Chouserrhickey: Hi! How'd it go?
10:51aperotterhickey: I'm new, but hello anyway :)
10:51rhickeyIt went great. A really long day, I didn't talk until almost 8pm (started at 8:30 am)!
10:51aperotteChouser: It's a field, that is itself an object that I'd like to call a method on
10:52rhickeyLots of seminal Lispers talked about the history, lots of reminiscing
10:53Chouseraperotte: ah. hm... I'm sure it's possible, but it may not be pretty.
10:53AWizzArdhi Rich
10:53rhickeyPascal Costanza's the only talk about current work in CL, Will Clinger on the state of Scheme
10:53rhickeyThen, last, Clojure, about which many of them knew nothing
10:54AWizzArdthis will change in 2009... it will be a well known secret :-)
10:54asbjxrnDon't know too much about the programme, but with a name like Lisp 50, it's not that strange that it was a look back.
10:54aperotteChouser: haha ... thanks, that makes me feel better. I thought I was just missing something simple.
10:54rhickeyLots of skepticism at the start, but by the end I got so much good feedback , essentially validation that this is the right way to bring Lisp forward - make a break, address current problems etc
10:54gnuvincerhickey: what did the heavy weights (Gabriel, Steele) think?
10:54asbjxrnI thought it would be reasonably well known today, at least among lispers.
10:56rhickeyThere were lots of nice compliments during questions and after - had a long conversation with JoL White and others
10:56gnuvincerhickey: was your presentation video-taped?
10:57gnuvince(or video-digitalized, I'm not sure how to say that in a world where tapes almost don't exist anymore)
10:57rhickeyI still have never gotten any feedback from Guy Steele - he left during the panel that followed my talks and wasn't at either of the Lisper dinners, although I saw him gesturing with 2 thumbs up during part of my presentation, but he may have just been agreeing with a particular point I made
10:58rhickeyDan Weinreb has become a fan, and was talking it up to many others before my talk
10:59rhickeyOverall I think it went great - it represents such a sea change for that community but they were very gracious in accepting the new ideas
10:59rhickeyOf course, in 45 minutes I can barely scratch the surface of Clojure
10:59gnuvinceGood job :)
10:59aperotteCongratulations
11:00Chouseraperotte: you might need gen-class -- look at the :exposes feature
11:01rhickeyThere was videotaping and I signed a release... but I think the Boston Lisp talk was more comprehensive, if 4x as long
11:02gnuvincerhickey: it's still nice to have this, that's another Clojure post on reddit ;)
11:03AWizzArdgrats
11:03rhickeythanks
11:03lisppaste8jdz annotated #68935 with "The correct version of slurp-byte-stream (hopefully :)" at http://paste.lisp.org/display/68935#2
11:04aperotteChouser: thanks, I'll take a look
11:04Chouserrhickey: Sounds great. Soak it up! In another couple years you may have to be spending all your time on standards committees as everyone tries their own implementations of the Next Big Language. :-)
11:05cemerickrhickey: congrats on the trip/talk going so well.
11:05rhickeyChouser: I'm hoping the community will stay focused on the core implementation, as they have for Python and Ruby
11:06cemerickyeah, I think we can dispose with the standards committees :-P
11:06rhickeyOne thing was clear - standards stopped innovation in Lisp. Steele and Gabriel's talk enumerated so many dialects before the standards
11:07ChouserThat's an excellent point. Did everyone "get" it?
11:07AWizzArdwell yes, today it seems languages benefit from a dictator *g*
11:07asbjxrnMany dialects may not be what you want, though?
11:07asbjxrnDid scheme fare that much better?
11:07H4nsasbjxrn: as hardware and environments change, language innovation is needed to cope with that
11:08ChouserWell a good dictator is hugely imporant, but I think an open-source implementation makes it possible. The codebase *is* the standard.
11:08rhickeyasbjxrn: It's less the dialects than the innovation - I think we can innovate in few dialects, but can't innovate a standard - it's fixed
11:08asbjxrnI definately agree.
11:08asbjxrnThe trick is to get innovation without forks.
11:09rhickeyChouser: right, but differs from an actual standard in not being fixed on paper
11:10rhickeyasbjxrn: Being open source and not wanting forks forces the core to be responsive to the community
11:12asbjxrnYup, and so far you're doing great :) I'm not critizising (sp?), I'm just not sure that many lisp dialiects are better than one. I would assume that it would reduce the number of usable libraries.
11:13rhickeyasbjxrn: well, I expect Scheme and CL to continue indefinitely
11:13asbjxrnBut of course I do see the point that once the standard is printed, you're stuck. I just think that lisp may have been so fragmented that a common spec was good.
11:14AWizzArdIn my opinion Clojure has the greatest potential to become more or less the best programming language.
11:15gnuvinceI don't know about "best" (or even what it means), but I agree that if I had to put money on a relatively unknown language that would become extremely popular in the coming years, Clojure would be it.
11:16AWizzArdSince I began doing Common Lisp in 2003 this (Clojure) is what excited me most.
11:17AWizzArdThis is especially amazing, because typically every 3 months someone comes to show his/her new Lisp, and it is always total useless $#|~
11:18asbjxrnI thought that nick looked familiar...
11:19ChouserAWizzArd: you mean like arc? :-)
11:20asbjxrnHang around in comp.lang.lisp for a while, and you'll see a handful, it's not just arc.
11:20AWizzArdChouser: well yes, only that the development of Arc took just 4 years. Paul Graham managed to come up with a little improved scheme. Wow. *sigh*
11:21gnuvinceI guess it takes a lot of time to come up with shorter names
11:21Chousergnuvince: not just that -- it has a reader macro for [ ]
11:22gnuvinceChouser: right.
11:23Chouser:-)
11:34asbjxrnUhm, clojure equivalent of progn?
11:34jdzdo
11:36asbjxrnThanks, I was sure I had tried that before with moderate success. Probably confused with a lazy sequence operation inside the do or something. That still trips me up every now and then
11:36asbjxrn(Having to use doall, for sideeffect stuff, that is.)
11:41ChouserHeh. "do" is the one use of "do" that's not for side-effects.
11:43jdzdoes anybody have a bit of sample concurrency code? i want to have a small pool of workers, then loop over my data set giving work to the first available worker (and waiting for a free one if all workers are busy).
11:46AWizzArdjdz: (pmap ...)
11:46AWizzArdit is like map, only that it divides the mapping to all available processors
11:46AWizzArdlook at its code in the boot.clj
11:47jdzAWizzArd: thanks. i was already looking at java.util.concurrent.SynchronousQueue :)
12:00AWizzArdHow can I count the number of occurrences of an object in a collection?
12:00Chouser(count (filter #{an-obj} coll)) ?
12:01AWizzArdSure, but I mean there is nothing like that in the standard lib yet, right?
12:02cemerickno, but it seems like something simple enough to not include in the stdlib (IMO)
12:03asbjxrnThat hash lookup trick is almost too sneaky, though.
12:04Chouserone of my gripes about CL (not that anyone should care what a noob like me thinks about CL) is the overwhelming number of built-in functions.
12:04Chouserasbjxrn: yes, except that it's "an idiom" now. It should be documented as such, I suppose.
12:04cemerickChouser: agreed.
12:04asbjxrnYou don't have to use them all ;)
12:04jdzChouser: how is that different from java's standard lib?
12:04gnuvinceHmmm
12:04gnuvinceAfter the API page, there ought to be an Idioms page
12:04cemerickI wouldn't say that there's anything sneaky about certain objects implementing IFn.
12:04gnuvinceThat'd be nice
12:05Chouserasbjxrn: no, but to write "correct" code you have to know about them all.
12:05jdzChouser: how' s that different from Java' s standard lib?
12:06asbjxrnNo, I like the hash as function idea, I use it a lot to lookup stuff. I've never thought of using it as an argument to filter, though. I had a little "huh" moment there.
12:06Chouserand it seemed to me that reading CL code without a manual at your fingertips would be impossible until I had been at it for a long time.
12:06gnuvincejdz: he meant built-in as in the global namespace.
12:06jdzgnuvince: what do namespaces have to do with it?
12:06Chouseryeah, the global namespace is certainly part of it.
12:07gnuvincejdz: look at PHP with its 4,000 functions in the same namespace.
12:07Chouserjdz: I'm not exactly a proponent of Java either, though I imagine the same question could be asked about any standard lib.
12:07jdzgnuvince: isn't that the problem of not having any name-separation capabilty?
12:08jdzChouser: you can' t program C if you don' t know stdlib. same with CL.
12:09ChouserOne little difference (and I don't know how important this is) is macros. In C or Java you may not know what a function does, but you know the args are evaluated and you may be able to "black-box" it for a moment in your mind while trying to get your bearins in the rest of the code.
12:09ChouserNot so with lisps.
12:11jdzChouser: well, with lisp you have nice developement environment that can instantly tell you whether the symbol is a function or a macro
12:11jdzand then there are naming conventions.
12:11jdzand in most cases you don' t even care
12:12Chouseryeah, that's what I meant about "tools". I guess I was often reading code on a printed page.
12:22AWizzArdIs there a correct way to express (defn foo ([n []] 5) ([n [x & xs]] 6))? What I want is: (foo something empty-col) ==> 5 and (foo something col-with-something-inside) ==> 6
12:23jdzAWizzArd: you want functional language style pattern matching?
12:25jdzAWizzArd: you can go a bit along the way with destructuring, but there is no pattern matching in Clojure as far as i know
12:25Chouser(defn foo [n [x & xs :as allxs]] (if (seq allxs) 6 5))
12:26ChouserI believe that's idiomatic. I don't know of any "correct" name for xs or allxs.
12:28asbjxrnHow is that different form (defn foo [n x] (if (seq x) 6 5)) ?
12:29Chouserit's not, unless you want to destructure the seq into x and xs
12:30Chouserwhich clearly aren't being used in this example, but I assumed AWizzArd wanted them for his actual code -- thought I'd show how to use :as in that case.
12:36AWizzArdasbjxrn: and also (seq x) is true only if x is a list. But not if x is a vector
12:38Chouserno, (seq []) is true
12:39AWizzArdah okay, I read (seq? x)
12:39asbjxrn? In my repl (seq []) is nil.
12:39Chouserseq returns a seq object (acts like true) for any non-empty collection. For empty collections seq returns nil.
12:40Chouseryes, seq? is a bit different -- it returns true for ISequences like lists, lazy-cons, etc.
12:41Chouserand as you meant, seq? returns false for vectors, maps, etc. whether empty or not.
12:43danlarkinand is this reasonable? (seq? '()) == false
12:43AWizzArdChouser: I think that's what I said.. (seq? x) is only true if x is a list.
12:44ChouserAWizzArd: or if x is a lazy-cons or other ISequence.
12:46Chouserdanlarkin: hm, I think not. EmptyList probably should implement ISeq.
12:49cemerickChouser: Yes, definitely. I've hit that one a couple of times.
12:51Chouserhttp://groups.google.com/group/clojure/browse_frm/thread/1ca1e57ce509b81c
12:51ChouserI guess I'm wrong.
12:51cemerickwell, well
12:55lisppaste8achim annotated #68832 with "... with partitioning" at http://paste.lisp.org/display/68832#1
12:56danlarkinInteresting
13:05lisppaste8achim annotated #68832 with "correction" at http://paste.lisp.org/display/68832#2
13:22fyuryuis dispatch based on meta data considered a good practice?
13:30Lau_of_DKEvening gents
13:32danlarkinafternoon
13:35billcare there logs of the #clojure irc channel available?
13:36fyuryubillc: http://clojure-log.n01se.net/
13:36billcfyuryu: thanks!
13:36duck1123that really should be part of the channel's topic
13:37Lau_of_DKHas anybody had some luck optimizing my routine from earlier today ?
13:52Lau_of_DKAlright, lets say I have a nested list like this
13:52Lau_of_DKuser=> (take 5 lst)
13:52Lau_of_DK(((1000 1001 1002) (4330 4331 4332) (7660 7661 7662)) ((1001 1002 1003) (4331 4332 4333) (7661 7662 7663)) ((1002 1003 1004) (4332 4333 4334) (7662 7663 7664)) ((1003 1004 1005) (4333 4334 4335) (7663 7664 7665)) ((1004 1005 1006) (4334 4335 4336) (7664 7665 7666)))
13:53Lau_of_DKAnd I want to filter out those lists wherein all 3 numbers are prime. (filter #(every? prime? %) ) doesnt work on nested lists, so what are my options?
13:56danlarkinnest your filters?
13:57Lau_of_DKMaybe. I'd prefer some sort of flatmap solution
13:57Lau_of_DKThis wouldnt even be a problem if I could get partition to work with concat, its because Im conjoing seqs
13:58devinusdos clojure support OOP?
13:59devinusdoes*
13:59danlarkindevinus: it supports encapsulation, type hierarchies...
13:59devinusdanlarkin: what about reflection capabilities?
13:59danlarkinand if you really need to you can make a custom object by using the gen-class functions
13:59AWizzArddevinus: Clojure gives you building material to implement oop the way you like it, if you want.
14:00AWizzArddevinus: but Paul Graham explained: functional programming + macros outperform oop
14:00danlarkindevinus: what sort of reflection? clojure has the concept of metadata
14:00devinusdanlarkin: could you find the name of your function out within the function?
14:01AWizzArddevinus: you can simply use a map, where the keys are the fields of your class, and the information *what* class you want goes into metadata.
14:01AWizzArddevinus: Clojure supports macros. You can even write a function from which you can see the source code during runtime.
14:03AWizzArdjust expand it into a defn and write the source code into the metadata
14:03cemerickdevinus: remember that clojure is hosted on java, and has a lot of ways to interoperate with java artifacts
14:04Chouserfyuryu: I don't think you should automatically rule out dispatch on meta-data if it makes sense for your situation.
14:05danlarkinLau_of_DK: how about this: (filter #(every? (fn [coll] (every? prime? coll)) %) lst)
14:06danlarkinLau_of_DK: it's a naive algorithm, though, I admit
14:06Lau_of_DKnaive?
14:07danlarkinLau_of_DK: inefficient
14:07Chouserlooks ok to me.
14:07ChouserI think "every?" will bail as soon as it gets a false.
14:08Chouserindeed it does.
14:08Lau_of_DKuser=> lst
14:08Lau_of_DK((2 3 5 7) (11 17 41 8) (2 4 6 8))
14:08Lau_of_DKuser=> (filter #(every? (fn [coll] (every? prime? coll)) %) lst)
14:09Lau_of_DKThen throws illegal argument exception
14:09Chouseryou'd want "prime?" to remember it's conclusions (memoize)
14:09Lau_of_DKHow do I do that Chouser ?
14:09danlarkinLau_of_DK: store it in a hash
14:09Chouserclojure.contrib.memoize
14:10Lau_of_DKk thanks - any insights into why the filter breaks on that list of lists
14:10danlarkinLau_of_DK: can you paste your prime? function so I can test?
14:11Lau_of_DKhttp://clojure-euler.wikispaces.com/The+Optimal+Toolkit
14:15wwmorgan_Lau_of_DK: the first and second lists that you posted have different levels of nesting
14:15Lau_of_DKhang on
14:15Lau_of_DKthe first is the correct, I made the 2.nd by hand
14:16Lau_of_DK(defn euler-49
14:16Lau_of_DK []
14:16Lau_of_DK (filter #(every? (fn [coll] (every? prime? coll)) %)
14:16Lau_of_DK (loop [ n 1000 result [] ]
14:16Lau_of_DK (if (< n (- 9999 3330))
14:16Lau_of_DK (recur (inc n) (conj result (partition 3 3330 (range n 9999))))
14:16Lau_of_DK result))))
14:16Lau_of_DKreturns "nil"
14:16Lau_of_DKThat doesnt seem very likely ?
14:20Lau_of_DKIf I remove the filter and go through the sequence, I can see that partition is making mistakes
14:21Lau_of_DKIts not putting 3330 between the offsets...
14:21Lau_of_DKoh wait
14:21Lau_of_DKYes it is, I thought it to be the offset between each item, not each list, my bad
14:21Lau_of_DKI'll rework it
14:25Lau_of_DKOk, I got everything working now, thanks alot for the input everybody
14:27danlarkinLau_of_DK: how did you end up using filter?
14:27Lau_of_DKchanged the nesting away from partition, so (filter #(every? prime? %) ...) works
14:28Lau_of_DKBut you taught me a new thing :)
14:32danlarkinLau_of_DK: cool!
14:34tWipa project euler wiki? that makes me sad
14:34Lau_of_DKtWip, why ?
14:34tWipI find that the most fun part of it trying to solve things yourself
14:34gnuvincePeople will just get the solution pre-made instead of researching it.
14:34gnuvinceYeah
14:34Lau_of_DKhehe
14:35fogusThat doesn't stop you from figuring these solutions yourself
14:35Lau_of_DKGentlemen, you dont have to follow those solution (some of them are not very bright)
14:35gnuvinceIt's absolutely infuriating at times, but so nice when you finally get a solution working in less that 18 hours.
14:35Lau_of_DKIts meant as an inspiration to use Clojure in different ways, especially good for newbies
14:35tWipagreed
14:35tWipwith what gnuvince said, that is
14:35Lau_of_DKNo later than today, I pointed a first-timer in Clojure to the wiki, which gave him an easy start
14:40fyuryuChouser: I'm considering it but something in me whispers "don't do it!"
14:42Chouserfyuryu: I by no means feel I have a complete sense of when to use metadata, but one thing to hang onto is the concept of equality.
14:43arbschtgnuvince: it's also fun to improve upon other solutions, or find ones better than yours
14:43ChouserIf a particular piece of data for an object can be different but you would still want them to be equal, then it must be metadata.
15:14Lau_of_DKNow that the filter works, I get an output like ((1234 4321 1234) (2345 5432 2345))
15:15Lau_of_DKI've made a routine that checks if every number is a permutation of 2 others, so
15:15Lau_of_DK(permutation? 1234 4321 3214)
15:15Lau_of_DKtrue
15:15Lau_of_DK(permutation? 1234 3456 3646)
15:15Lau_of_DKfalse
15:15Lau_of_DKHow do I filter for permutations?
15:16wwmorgan_(filter (partial apply permutations?) coll-of-colls)
15:18Lau_of_DKMy goodness
15:18danlarkinwwmorgan_: tricky
15:18Lau_of_DKThat worked...
15:19AWizzArdhow can I do (num "123") ==> 123 ?
15:20Chouser(Integer. "123")
15:20wwmorgan_AWizzArd: is arbitrary precision required?
15:20ChouserThat's a constructor of the Integer class.
15:21AWizzArdwwmorgan_: please show both ways if possible :-)
15:21wwmorgan_Lau_of_DK: how are you detecting numeric permutations? There's an awesome fast algorithm for that.
15:22Lau_of_DK(defn permutation?
15:22Lau_of_DK [x y z]
15:22Lau_of_DK (let [test (apply sorted-set (str x y z))]
15:22Lau_of_DK (= (count test) (count (str x)))))
15:22wwmorgan_AWizzArd: (BigInteger. "12323849728239473") => 12323849728239473
15:23wwmorgan_since you're solving the euler problem, I guess it's OK that (permutation? 1 11 111) returns true
15:24AWizzArdwwmorgan_: why is it (BigInteger. ) and not (.BigInteger)? Why is it (.hashCode) and not (hashCode.)?
15:24danlarkin(ClassName.) is syntax for (new ClassName)
15:25wwmorgan_(.method object) or (.field object) is syntax for (. object field) or (. object method)
15:27Lau_of_DKwwmorgan_, do you have something better?
15:28wwmorgan_I don't know which would be faster, given that (permutations? 1 11 111) => true is acceptable
15:28Lau_of_DKIf you want that to return false is just a matter of checking (what I assume) that all args are same length
15:30wwmorgan_pasting...
15:32gnuvinceHow about (= (sort xs) (sort ys))?
15:34wwmorgan_nm on the paste. What you do is allocate an array of the first 10 primes, then, for each number, map each digit to the respective prime and multiply all the digits together. If every number has the same product, by the Fundamental Theorem of Arithmetic, the numbers are permutations, and if they don't, they're not
15:35wwmorgan_so not only is it O(n) in the number of digits, you can fall out early without even looking at later numbers
16:02danlarkinclojure/partial is totally sweet
16:04Chouserseems kinda old-school to me. I usually prefer #()
16:06Chouserbut take you're pick -- whatever works! :-)
16:06gnuvincepartial is gonna appeal to the Haskellers
16:06Lau_of_DKpartial is nasty
16:06wwmorgan_(partial even?) takes more characters than #(even? %) but I think it's slightly more readable
16:07kotarak#() is more powerfull since you can choose the argument positions.
16:07gnuvincewwmorgan_: yeah, but who would use either one? :) (filter even? (range 20))
16:08wwmorgan_gnuvince: whoops, you're right. Change my example to (partial = foo) and #(= foo %)
16:08Lau_of_DKAnybody here know of a Java func to load an entire website into a string or something like that
16:08Lau_of_DK(slurp www.slashdot.org)
16:08Lau_of_DK?
16:09gnuvincewwmorgan_: fwiw, I'd use the latter, because it's shorter and clearer IMO.
16:09Chouserpartial might win me over for varargs. (partial + 10) vs. #(apply + 10 %&)
16:10chmu_Is there an eager (map) in clojure. I had some trouble with map and I/O.
16:11Chouserwrap any lazy thing in (doall ...) to make it eager.
16:11hoeckLau_of_DK: look at http_client.clj in the google groups
16:11wwmorgan_chmu_: you may want to look at doseq for I/O as well
16:11Lau_of_DKhoeck, thanks
16:11Lau_of_DKhoeck, did you have a crack at this? :) http://paste.lisp.org/display/68934
16:12chmu_thanks
16:19devinuscan you use dashes in fn names?
16:19Chouseryes
16:19gnuvincedevinus: yes.
16:20gnuvincedevinus: dashes are the standard way to separate words in an identifier in Lisp languages.
16:22devinuscan you use underscores and Capital letters
16:22devinusor even other identifiers, since, really, only parens are needed
16:23devinuslike (look@something ...)
16:23devinus(compute$amt ...)
16:23devinus(%ofsomething ...)
16:23Chouseryou can use underscores and capitals, but if you're doing so for any reason other than interacting with Java, you'll have to put up with people calling your code ugly. :-)
16:23devinus(pinch&poke ...) ?
16:23gnuvincedevinus: I don't know the complete list, but underscore and capitals are definitely permitted, slashes are OK
16:24devinusok
16:24Chouseraren't slashes reserved for namespace separation?
16:24gnuvinceYes for ampersands.
16:24gnuvinceOh right.
16:24gnuvinceSorry
16:24Chouserquestion marks are frequently used at the end of a function name to indicate it returns boolean
16:25Chouser! at the end suggests it mutates something
16:25gnuvinceok
16:25gnuvinceI got the list
16:25devinusi know set!
16:25gnuvincealphanumeric, *, +, !, -, _, ?
16:25devinusi'm going to have to manually check for everything else
16:25Chousergnuvince: nice, thanks!
16:26gnuvincehttp://clojure.org/reader
16:26gnuvinceUnder "Symbols"
16:28devinusdoes clojure work under java 7?
16:31hoeckLau_of_DK: ahh, i see, euler number 50, i have already a primfac function at hands from my early clojure hackings
16:32hoeckLau_of_DK: but that has to wait until tomorrow, need some sleep
16:32Lau_of_DKOkay :) Sleep tight
16:35devinusOk, so you can use these symbols: ! # $ & * . = + ?
16:36devinusoh and :
16:37devinusand |
16:37devinusYou cannot use these symbols in a fn: ~ ` @ % / \ < > [ ] { } ( )
16:37devinusand here's a really curious one
16:37devinusyou can define some var with a period in it
16:37devinus(def some.var 3)
16:37devinusbut when you try to access it you cannot
16:38Chouserdots are reserved for java interop when you try to access them
16:38Chouserwould be nice to get a warning when you try to def it, I suppose.
16:39wwmorgan_(var-get (var some.var))
16:39Chouserewww
16:39Chouser:-)
16:39wwmorgan_ya thats a good one
16:40devinusit would also be nice to be able to use ~ ` @ % / \ < > { } in variable names
16:40devinusespecially @
16:40devinus~ too would be nice for approximations
16:40devinus~area-of-disk
16:40devinusis @ used in clojure?
16:41Chouser~ and ~@ are used for inserting stuff in back-quote expressions
16:41Chouser(usually used when writing macros)
16:41danlarkinIt'd be nice to name things like str->int
16:43devinusmmm indeed
16:43devinusi like that
16:43wwmorgan_(defn str->int [s] (Integer. s)) (str->int "123") => 123
16:44danlarkinoh... so then < and > are legal in identifiers.. that's what I get for opening my mouth before I check.. d'oh
16:45wwmorgan_but it looks like > is reserved though, so I think don't do that
16:45Chouserwwmorgan_: why do you say that?
16:45Chouser-> is just a regular macro in boot.clj
16:45ChouserI used xml-> so if that's bad I should change it.
16:46wwmorgan_Chouser: I was going off http://clojure.org/reader but you're right
16:47wwmorgan_the -> macro makes it clear that > is supported
16:55Lau_of_DKI've used xml-> in a larger program without any problems
18:34AWizzArdWithout trying it in the repl, if you say (def x (agent [10 20 30])) and then (send x map inc), what do you expect, to what will @x evaluate?
18:35gnuvince_[11 21 31]?
18:35AWizzArdI agree
18:35Chouserafter you give it sufficient time to execute?
18:35AWizzArdyes
18:36Chouser(11 21 31)?
18:36AWizzArdI think so, yeah
18:36Chouserlazy seq
18:36AWizzArdnow try it please
18:37Chouserah, of course.
18:37AWizzArdenlighten me please
18:37Chouserthe agent gets passed as the first arg
18:38Chouser(map @x inc)
18:38ChouserAWizzArd: try: (send x #(map inc %))
18:39AWizzArdright, thanks
18:57AWizzArdThe code of (dispatch ...) is not written in Clojure, right? Used by send and send-off for example.
19:05Chouserright, dispatch is a method of the Agent class, written in Java.
19:08AWizzArdwould be interesting to know what happens if there is a blocking agent in a send-off
19:25lisppaste8achim annotated #68934 with "..." at http://paste.lisp.org/display/68934#1
20:13gnuvince_lukego: Luke Gorrie?
20:20lukegohowdy
20:21gnuvince_Nice to meet you :)
20:21lukegohey I've been your neighbour in #lisp for years and years :)
20:22lukegoI saw the clojure talk at OOPSLA yesterday so thought I'd take it for a test drive :)
20:22gnuvince_Nice to see you here.
20:23drewclukego: how was lisp50? (jerk)
20:23lukegodrewc: overall very good but some low moments. subject of upcoming blog entry :)
20:23drewclooking forward to reading it :)
20:24gnuvince_lukego: so I guess that means you're no longer in Thailand
20:25lukegoI'm in LA en route to New Zealand and Australia at the moment, more or less, but still moving around quite a lot at this stage. I could use a year off this travel business but not quite yet :)
20:26lukegothe error message is a bit unfriendly when swank-clojure-jar-path is set wrong (NoClassDefFoundError). probably obvious to java people but "file not found" wasn't my first thought
20:30sohaillukego, I had the same problem :-)
20:30lukegowhat did you do about it? :)
20:31jao/whois sohail
20:31jao
20:31jaooop
20:31jaos
20:31gnuvince_lukego: rhickey said he was working towards making error messages less arcane
20:31sohaillukego, I moved the setting around in the file according to the documentation
20:31sohailand then stared at the file name for a long time
20:32sohailthen finally saw that I was off by a directory
20:32lukegothis isn't really a clojure error message, it's the JVM reporting that it can't find the entry class to clojure (because I had the wrong path to clojure.jar set)
20:32sohailya
20:32lukegoright, me too
20:32lukegoI thought you meant you had a solution to the travel problem, not the jvm problem :)
20:33sohailah
20:48drewcsohail: that is a good solution
20:48drewcwfm too
20:49sohaildrewc, good work if you can get it :-)
20:50drewcsohail: indeed :)
20:51sohaildrewc, the next step is to stop working
20:51sohailthat one is proving hard
20:52drewcyeah, that one is a little tougher.
20:53drewcwell, there's a few easy ways, but they are not at all pleasant.
20:53sohailor legal
21:30gnuvince_I'm trying to solve #4 of Project Euler with Clojure, but I always get a StackOverflowError
21:31gnuvince_Could anyone take a quick look?
21:34Chouserwhere is it?
21:34gnuvince_Chouser: just trying something with loop/recur first...
21:35Chouserok
21:37gnuvince_Ah
21:37gnuvince_There we go
21:38gnuvince_~paste
21:38gnuvince_@pastebin
21:39gnuvince_lisppaste8: pastebi
21:39gnuvince_lisppaste8: pastebin
21:39gnuvince_lisppaste8: paste
21:39gnuvince_damn, what's the frigging command?
21:41lisppaste8gnuvince pasted "Euler #4: how does that look?" at http://paste.lisp.org/display/68966
21:41gnuvince_Chouser: there it is.
21:42gnuvince_How does it look?
21:44drewclisppaste8: url?
21:44lisppaste8To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.
21:44drewc:)
21:54lisppaste8sunwukong annotated #68966 with "How about this?" at http://paste.lisp.org/display/68966#1
21:55gnuvince_sunwukong: good one
21:56Chousergnuvince_: yeah.
22:04lukegohm so my first idea for a closure program is something that's hard to do in a functional language :-) any tips on a simple graph data structure?
22:06Chouserhm! a graph built of persistent data structures?
22:06gnuvince_lukego: how many people were present during Rich's presentation?
22:06lukegoneed an indirection somewhere
22:07lukegowell it was a small workshop. I'd estimate 50
22:08gnuvince_Not bad
22:09Chouserhash with "id" keys, each val is a vector of adjecent node ids?
22:09Chouserthat would be a directed graph, I suppose.
22:09lukegohe did very well in telling the audience "This, this, and this have to be removed from Lisp in this day and age. This, this and this have to be added" to an audience that includes Guy Steele, Dick Gabriel, etc :)
22:10lukegomust be an amazing salesman to have made me install a JVM
22:11gnuvince_lukego: you're not the only one :)
22:12gnuvince_Although I must admit that it *is* astonishing what people on the mailing list say they're doing with a language that's only one year old.
22:14sohailgnuvince_, what are they saying they are doing?
22:15gnuvince_sohail: people using it to build GUIs, web sites, database applications and whatnot.
22:15sohaillukego, what did he say has to be added?
22:15lukegoconcurrency primitives, living on a popular virtual machine are what come to mind
22:19sohaillukego, did he talk about how he expects people to live without inheritance and other OOP goodies?
22:20sohail(I know the multiple-dispatch is very general, which is cool)
22:20gnuvince_sohail: which goodies?
22:21lukegono, I heard this talk was very much shorter than what's usual. but Im a CLOS'trophobe and always have been anyway
22:22sohailgnuvince_, none really!
22:22gnuvince_lukego: you can go to clojure.blip.tv and watch the Boston Lisp User Group presentation
22:22gnuvince_It's three hours long
22:23lukegoI'm a bit bummed by lack of mutation for graphs right now :)
22:25sohaillukego, do it in Java ;-)
22:25lukegogah :)
22:26danlarkinlukego: what do you need mutations for? graphs are just representations of data
22:27danlarkinor are you talking about the graphing code itself?
22:27lukegowell I need some kind of an indirection to represent the circularity. names might do nicely
22:27lukegoI mean graph as in nodes and vertices
22:28danlarkinDAG?
22:29lukegoa circuit, so more like a DG
22:30lukegoI'm thinking a nice representation is probably a dictionary of named vertices, with edges being represented as symbols (vertex names)
22:31Chouseryou might find keywords to be a comfortable alternative to symbols
22:31danlarkinhow about just a map of edges, {:a :b, :b :c, :c :d}
22:37lukegoit's a circuit so the vertexes need type information, i.e. they need to be able to compute output values from input values (to implement AND, NOT, etc)
22:41danlarkinlukego: I don't quite understand, could you give an example?
22:41lukegosoon :)
22:42arohneris there a macro that collects the results from several expressions?
22:42danlarkinit's been a while since I took formal automata in university :-D
22:43arohnerlike (accumulate (foo) (bar) (baz)), and then returns the list of return values from the expressions?
22:43danlarkin(list (expr1) (expr2)) ?
22:43arohneroh, duh
22:43arohnerthanks
22:43danlarkinarohner: :)
23:28AlephInfHello, the clojure.org front page says "Every feature supported by Clojure is supported at runtime." I don't understand what it implies. Isn't it always true? I am a lisp newbie, so may be I missing something.
23:29arohnerI think that means there is no difference between compile time and run time, like say, C
23:31AlephInfSo to twist that statement around, is it fair to say that all the clojure features are also supported at "compile time". That means macros can use agents, STMs and all the clojure goodness?
23:33arohneryes, sort of
23:33arohnermacros return code
23:34arohnerand that code can make calls to agents, STMs etc
23:34lukegohow do I find out what I can do with strings? is there a "who specializes"? I want to know how to concat them :)
23:35arohneralso, macros are expanded when the function that uses the macro is eval'd
23:39AlephInfarohner: thanks. I guess I'll have to try attacking On Lisp again.
23:40arohneryeah, so do I
23:42danlarkinlukego: still waiting on your digraph example :D
23:42lukegoI'm still trying to write it :)
23:43arohnerlukego: what is 'who specializes'? Is that a CL thing?
23:43lukegobut here's an example that was prepared earlier: http://mitpress.mit.edu/sicp/full-text/sicp/book/node64.html
23:44lukegoarohner: yes. it means "give me a list of methods that dispatch on type <x>" e.g. tell me every method that wants a string. (iirc anyway)
23:45arohnerthat sounds pretty cool
23:45lukegoit's in the family of cross-reference facilities who-calls, who-binds, who-sets, etc
23:45lukego`C-c C-w ...' in SLIME :)
23:45arohnerthis is my first exposure to slime, and I'm just happy with C-c C-d C-d
23:46danlarkinlukego: are the who-* functions part of SLIME?
23:47lukegothat I don't know. ideally they're just bindings but in the old days at least there was a lot of hairy stuff in the per-implementation backends
23:50danlarkinthey're not in ANSI CL, at least
23:53lukegoa common-ish extension though. cmucl, sbcl, clozurecl at least support them
23:55danlarkinyeah it seems neat
23:56lukegohow do I get a var that I can set! at the repl?
23:56arohnerlukego: def
23:56arohnerbut you can only set! inside of a binding
23:58lukegoI want to have something that looks like a "global variable" to the repl and Emacs commands. maybe I'm on the wrong track. can you give a hint?
23:58lukegoit does not have to be shared with other threads
23:58arohnerthat sounds like you want a var
23:58lukegoisn't that what I have?
23:59arohneryeah
23:59lukego(def foo 1) (set! foo 2) worketh not
23:59arohnerright, your set can only appear inside the "scope" of a (binding)