#clojure logs

2009-04-22

00:04brennancis there anything like find-doc but that has just the function names. It's really hard to read it when it outputs 20 pages
00:09Jedi_Stannisbrennanc: not that I know of, shouldn't be too hard to write one
01:27joha1I'd like to use a syntax quote which doesn't try to resolve symbols. Is there any easy way of achieving this?
01:30hiredmanuh, quote?
01:30hiredman,'(a b @(c d))
01:30clojurebot(a b (clojure.core/deref (c d)))
01:30hiredmanor not
01:31hiredmanwhy do you want syntax quote?
01:33joha1building a function that generates code from a template, and I want to insert some values deep inside the vector. Perhaps there is a better way
01:35hiredmanzippers
01:36joha1what i'm looking for is something like `(xxx (yyy ~zzz))) -> (xxx (yyy 3)), but without symbol resolution (assuming zzz = 3)
01:36joha1zippers, eh? I'll see what I can find
01:36hiredmanclojure.zip
01:37hiredman,(require '[clojure.zip :as zip])
01:37clojurebotnil
01:37hiredman,(zip/zip-vec '[a b c])
01:37clojurebotjava.lang.Exception: No such var: zip/zip-vec
01:37joha1yes of course, that should work. I looked into zip just a few hours ago. thanks for the hint
01:37hiredman,(-> '[a b c] zip/vec-zip zip/root)
01:37clojurebotjava.lang.Exception: No such var: zip/vec-zip
01:38hiredmanbah
01:39hiredman,(ns-interns (find-ns 'zip))
01:39clojurebotjava.lang.NullPointerException
01:40hiredman,(find-ns 'zip)
01:40clojurebotnil
01:40hiredman,(ns-interns (find-ns 'clojure.zip))
01:40clojurebot{lefts #'clojure.zip/lefts, down #'clojure.zip/down, insert-left #'clojure.zip/insert-left, up #'clojure.zip/up, next #'clojure.zip/next, path #'clojure.zip/path, children #'clojure.zip/children, vector-zip #'clojure.zip/vector-zip, append-child #'clojure.zip/append-child, zipper #'clojure.zip/zipper, branch? #'clojure.zip/branch?, end? #'clojure.zip/end?, leftmost #'clojure.zip/leftmost, edit #'clojure.zip/edit, replace
01:40hiredman,(-> '[a b c] zip/vector-zip zip/root)
01:40clojurebot[a b c]
01:40hiredman,(-> '[a b c] zip/vector-zip zip/left zip/left zip/root)
01:40clojurebotjava.lang.NullPointerException
01:41hiredman,(-> '[a b c] zip/vector-zip zip/down zip/right zip/right (zip/replace 'z) zip/root)
01:41clojurebot[a b z]
02:06hiredmanhmmm
02:06hiredmanthat is three commits of autodocs for rev 687
02:08replacayeah, cause I'm doing more work on the robot than people are doing work on contrib
02:08replacaand google's lame-ass wiki doesn't have an offline preview tool
02:09replacaI can do some stuff editing in the text box and hitting preview, but only so much
02:09hiredmanI see
02:09replacaif you want too see the current product, go to http://code.google.com/p/clojure-contrib/wiki/OverviewOfContrib
02:10replacabut it still has a long way to go
02:10Carkwah nice stuff you're doing there
02:11hiredmannice
02:11replacathx
02:11replacadealing with the google wiki is kind of a bear
02:11replacaall sorts of limitations I wouldn't have in HTML :-(
02:15Carkah funny, so many functions in there i implemented on my own
02:15replacathe problem has been that contrib is so opaque! I'm trying to fix that
02:16noidithat's great!
02:16noidithe fixing, not the opaqueness ;)
02:16replaca:-)
02:16noidigrepping the sources gets old fast
02:18replacaknow whatchya mean
02:26cp2bah, i lost my uptime
06:49emacsenhey pjb3
08:50kadaverwhat are hashmaps internally? red-black-trees?
08:52cemerickkadaver: they're hash array mapped tries
08:52cemerickthe sorted hash maps are red-black trees, I think.
09:12rhickey_cemerick: right, sorted sets/maps are rb trees
09:22cemerickI haven't had a good brainfuck in a while, but implementing conses, lists, and map/reduce in terms of constraint propagation certainly qualifies...
10:49postithi. i need a litte advice on which order to read some books
10:50postit["On Lisp","Practical Common Lisp","The Clojure book"]
10:51Chouserif you've already decided to learn Clojure, I think I'd start with the Clojure book
10:51postiti know the basics of lisp and functional programming
10:51ChouserI've never read PCL, so someone that has may have a different opinion
10:51gnuvincePCL is nothing really special and it's really tailored for Common Lisp
10:51postitdo you know, does the clojure book just deal with syntax compared to other lisps?
10:52gnuvinceI'd start with the Clojure book as well and if you need to, On Lisp.
10:52gnuvincepostit: there's more to the Clojure book than just explanation of the syntax.
10:53postitive decided on clojure, but i wanted to get a good understanding of the "lispy" way to design things too
10:53arohnerpostit: I would look at SICP then as well
10:53gnuvincepostit: learn Clojure and read code by others
10:53gnuvinceYou'll pick it up.
10:54arohnerbut yeah, gnuvince is right. The clojure way of doing things is not exactly the same as CL or Scheme
10:54ChouserThe Clojure Book is aims at both Lispers and Java'ers, so it explains how and why to do idiomatic Clojure
10:54postiti was wondering that to. if i could learn enough clojure from the "clojure book" to port other stuff as i read
10:55RaynesThe Clojure book teaches Clojure very well. I learned out of it.
10:55Chouseryes, I think if you grok the clojure book material, "on lisp" will then still be useful and interesting.
10:55postitgreat, thanks guys!
11:04dliebkepostit: the author of Programming Clojure, Stuart Halloway, also wrote some articles on porting examples from PCL to Clojure. http://blog.thinkrelevance.com/2008/9/16/pcl-clojure
11:04rapido,(count [1 2 3])
11:04clojurebot3
11:05rapido~confluently persistent
11:05clojurebotIt's greek to me.
11:18postitis emacs/slime the preferred dev environment (at least if you use emacs)
11:21djpowellit is pretty good. i just use emacs + clojure-mode + the built-in M-x inferior-lisp
11:22djpowellclojuredev seems quite nice tho - i like the rainbow paren highlighting - anyway of doing that in emacs?
11:22djpowellclojure-dev for eclipse i mean
11:25arohnerpostit: if you're already an emacs user, then yes it's the best environment
11:25arohnerI use emacs + slime, though inferior lisp works pretty well
11:26arohnerwhat does rainbow paren highlighting do?
11:27Chousukedifferent colour for each paren pair.
11:27arohneron my emacs, if you put your cursor on a paren, bracket or brace, it highlights the matching one
11:27arohnerbut only when the cursor is on a paren
11:27arohnerand it highlights in a different color when there is no match
11:28djpowellthe rainbow paren thing in clojure-dev just syntax colors parens different colors depending on the nesting level - not only when the cursor is near them
11:31Chousukeanyway, it's pointless to ask if emacs can do something. you need to ask "where's the plugin?"
11:33Chouserand then, "why does it only work with xemacs"?
11:33arohneremacswiki.org has a section on paren modes: http://www.emacswiki.org/emacs/CategoryParentheses
12:42gnuvinceCan anyone answer a Java question?
12:43danlarkinwaste of a question :)
12:43gnuvinceWell, whatever
12:43gnuvinceI compiled a bunch of Java files.
12:43gnuvinceThat worked
12:44gnuvincewhen I do: java ClassName, I get an error telling my that package/ClassName is a "wrong name"
12:45gnuvinceExact message: $ java BinRepParser
12:45gnuvinceException in thread "main" java.lang.NoClassDefFoundError: BinRepParser (wrong name: hu/belicza/andras/bwhf/control/BinRepParser)
12:50hiredmangnuvince: what package is the class in?
12:51gnuvincehu.belicza.andras.bwhf.control
12:51hiredmanyou need to include the package
12:51hiredmanjava hu.belicza.andras.bwhf.control.BinRepParser
12:51gnuvinceah<
12:52gnuvincethanks
12:52brianh2gnuvince: yeah. look @ this http://www.jarticles.com/package/package_eng.html
13:03replacaFor those using emacs and slime, I strongly recommend paredit: http://mumble.net/~campbell/emacs/paredit.html, it's made for a huge leap in my programming happiness
13:03replaca(actually this is true even if you're not using slime)
13:14gnuvinceAAAAAAAAAAAAAAAAAAH!
13:17Lau_of_DKEvening gents
13:21technomancyparedit is amazing.
13:22technomancyit makes me hate editing non-lisp code.
13:23gnuvincetechnomancy: it's neat, but I could not get used to it.
13:23gnuvinceI'd need to spend more time using it
13:29technomancygnuvince: only in the long run
13:29stuhoodgnuvince: it waits longer to optimize, and can use more memory on optimizations
13:29danlarkin-server will use hotspot
13:29gnuvincetechnomancy: the largest bottleneck (20%) was FileInputStream.read; removing -server fixed the problem.
13:30p_lJVM 1.7 is supposed to always use the same optimization model as -server
13:31technomancygnuvince: are you talking about my extract-jar function?
13:33gnuvincetechnomancy: no, my Starcraft parser.
13:34technomancygnuvince: that was really weird, because I almost sent an email to the mailing list last night asking why a function that used FileInputStream.read was slow.
13:34technomancyI thought you were reading my mind.
13:34dnolengnuvince is your project a one time run thing?
13:34gnuvincetechnomancy: I thought that I was nearly 20x slower than Java; turns out my Java was faulty and I wasn't analyzing any file. The number is now ~2.5-3x slower. And when I profiled both programs, -server was about twice as slow as -client
13:34technomancynice
13:35gnuvincednolen: currently, yes; give a bunch of files on the command line and it parses them.
13:36dnolengnuvince: client speeds up startup time, server does really aggressive on the fly optimization. for long running processes server is usually better from what I understand.
13:36technomancyanyway, FileInputStream.read takes an array of bytes, but it won't accept a (make-array Byte 1000); it needs a (make-array Byte/TYPE 1000), but I have no idea what the difference is; I just copied it blindly. =)
13:37gnuvincetechnomancy: reference type vs value type. The first is a Byte[], the second a byte[] and apparently Java treats them differently.
13:38technomancystatic typing saves the day again
13:39technomancywho knows what horrors would occur if I sent it bytes when it wanted Bytes.
13:39technomancyor vice versa
13:39gnuvinceThat's more of a "let's have primitives and objects" problem.
13:39danlarkintechnomancy: this has nothing to do with static typing
13:39danlarkinit's strong typing vs weak typing, which is orthogonal to static vs dynamic
13:43technomancyoh, bytes are primitive, right.
13:46Chousukehaving the primitive types is a nasty JVM wart, but I guess there at least used to be a reason to have them :/
13:46gnuvinceI figure performance
13:47gnuvinceAlthough it seems like the kind of thing the compiler should take care of.
13:48Carkwell it really makes sense ti have a buffer made of real contiguous bytes
13:48Carkrather than byte objects or whatever
13:49danlarkinright, well it's an array of data structures rather than an array of pointers to classes with overhead etc
13:50danlarkinI agree it's a wart, but I /suppose/ I can see the rationale for having it
13:51Cark.net has the same thing m
13:51Carkmore or less
13:51Carkso i guess that's pretty much the way to go
13:56gnuvinceinstance? seems like a pretty quick operation, am I right?
13:56dnolenwhat kind of machine does clojurebot run on?
14:00Carkclojurebot has been on strike these days
14:00Carkclojurebot: are you there ?
14:00clojurebotHuh?
14:02cemerickgnuvince: as quick as Class.isInstance :-)
14:03gnuvincecemerick: that's what I wanted to know, that seems to be pretty fast, right?
14:03cemerickfor the job, it's all there is...
14:04cemerickthe speed of instance? is never going to be your bottleneck, if that's your question
14:04gnuvincecemerick: think again :)
14:04gnuvincerank self accum count trace method 1 37.54% 37.54% 3532 300290 java.lang.Class.isInstance 2 20.12% 57.66% 1893 300285 java.lang.Class.isInstance
14:04gnuvince 3 17.94% 75.60% 1688 300292 java.lang.Class.isInstance
14:04gnuvince 4 2.44% 78.04% 230 300308 java.io.FileInputStream.readBytes
14:04gnuvincewell, the output didn't come out too nicely :-/
14:05cemerickcan you paste the code that produces that mix?
14:05gnuvincehttp://bitbucket.org/gnuvince/clj-starcraft/src
14:05gnuvincecheck starcraft/replay/parse.clj
14:07cemerickwhere's the source of the instance? calls?
14:07Carkdid you set the *wern-on-reflection* variable ?
14:07Carkwarn
14:08gnuvinceCark: yes, there's none.
14:08gnuvincecemerick: most likely the call to vector? in read-field
14:11cemerickwhat's the overall runtime of the code that you profiled? I'm thinking if the overall runtime was very short, then instance? calls would likely still be reflective, and they could easily be a significant amount of runtime compared to a small disk read.
14:12Carkand the file must be in the cache too, so even faster to read
14:14gnuvincecemerick: ~110 seconds.
14:14gnuvincecemerick: it processed over a thousand files in that time frame.
14:16Carkwhat's the troughput ? how many megabytes in this time frame ?
14:17gnuvinceNot a lot
14:17gnuvince151 MB
14:18gnuvinceEach file is about 150 KB
14:18Carki remember seeing somewhere a way to read several buffers in one go
14:18Carkan array of buffers with different types
14:19gnuvinceCark: my hands are tied by the Java lib I use.
14:19gnuvinceI don't do the IO
14:19gnuvinceI take the file
14:19gnuvincepass it off to a Java method
14:19gnuvincegrab the ByteBuffer it returned
14:19gnuvinceand work with that.
14:24replacaI will attest to isInstance? being a bottleneck, it's also the slowest thing in the pretty printer (although I do do it a lot).
14:24Carkah too bad ...because with a FileChannel you have this method : read(ByteBuffer[] dsts)
14:24gnuvincereplaca: I do a lot of vector? calls too.
14:24Carkyou could then prepare wrapped buffers on top of that for each record type
14:25Carkfor each field type i mean
14:25gnuvinceI was thinking of changing my API slightly, but it seems that a comparaison of length or using try/catch are the same speed.
14:25Carkdoes your library do memory mapped files ?
14:26gnuvinceCark: not that I know of.
14:26gnuvinceas far as I can tell (not really a Java programmer), the guy just opens a FileInputStream, reads, and returns a ByteBuffer.
14:26Carkanyways that's not your problem ...you need to do less at run time
14:27gnuvinceyeah
14:27gnuvinceI define a field in a record like this:
14:27replacagnuvince: obviously the pretty printer needs to think about types a lot, cause it's making dynamic decisions based on type. BUt it does more work than it needs to. I'll need to deal with that when I revisit dispatch.
14:28gnuvince[:name 1 Byte] or [:name2 [1 Byte] Integer]. The vector? calls is to read the [1 Byte] and use the value as the number of Integers to read.
14:30gnuvince,(let [xs (repeat 1000000 [[1] [2 3]])] (time (doseq [x xs] (if (= (count x) 1) 1 2))))
14:30clojurebot"Elapsed time: 3834.042 msecs"
14:30gnuvince,(let [xs (repeat 1000000 [1 [2 3]])] (time (doseq [x xs] (if (vector? x) 2 1))))
14:30clojurebot"Elapsed time: 2458.336 msecs"
14:30CarkI would prepare that parsing before hand
14:31Carkyou know build a lambda
14:31Carkthere you're "parsing" the field spec during the actual processing
14:32gnuvinceSo turn these into lambdas instead of structs? http://bitbucket.org/gnuvince/clj-starcraft/src/tip/src/starcraft/replay/actions.clj
14:33Carkthat's nice and clean as it is
14:33Carkbut you could process this "DSL" before hand into lambdas to make it quicker to parse
14:36gnuvinceTo make sure I'm following, something like (compile-record [:name 1 Byte] [:name2 [1 Byte] Integer]) and that would return a fn that takes a ByteBuffer as its input?
14:37Carkright
14:38gnuvinceShould that be a macro or a function?
14:38cipherhey gnuvince what are you writing there--quick description
14:39gnuvincecipher: it's a library that reads a Starcraft replay file and returns information about the game (players, races, map, etc.) as well as all the actions done by the players. Players use those kinds of programs to analyse their games.
14:40cipherneat.
14:49gnuvinceCark: do you think compile-field should be a function or a macro? I'd prefer a function, but I'm not sure if I can do it...
14:50ciphergnuvince: did you see my PM?
14:50gnuvinceOh, yes.
14:50gnuvinceThanks
14:51cipherOk.
14:52gnuvinceDid you guys to bnetd?
14:52cipherwe have some involvement
14:52cipherhad*
14:53gnuvinceOK
14:53gnuvinceShame Vivendi pulled the plug on that project :(
14:53technomancyif I can't delete a file, should I raise an instance of Exception, or is there a more specific class I should use?
14:53gnuvincetechnomancy: IOException?
14:54technomancygnuvince: thanks; that sounds better
14:55technomancywhat do you think: does a delete-file-recursively function belong in contrib?
14:56technomancyhttp://p.hagelb.org/delete-file-recursively.html
15:03gnuvinceJava doesn't already have a method for that?
15:03technomancygnuvince: yeah, I was surprised, but I couldn't find one.
15:03technomancymaybe they just hid it really well?
15:05gnuvincePython's shutil.rmtree ftw!
15:05technomancyFileUtils.rm_rcf
15:05technomancy*rm_rf
15:05Chouserthat's the kind of thing apache commons provides
15:05leafwtechnomancy, gnuvince: no, java does not have a recursive file deletion command. I guess it meant too much potential for damage.
15:06technomancyChouser: yeah, but needing a 3rd-party dependency for something that basic is unfortunate.
15:06leafwat least it has File.mkdirs()
15:06Chousertechnomancy: yeah
15:06technomancythis functionality is pretty important for unit testing
15:06technomancysince you need to clean up after yourself
15:13technomancyposted it to the mailing list
15:13technomancycan create an issue/patch
15:13cemerickcontrib *is* a 3rd party dependency (or dependencies). Much more pleasant API than 99% of the stuff out there, but it's a dependency nonetheless.
15:15technomancyevery project I've worked with uses contrib already
15:15technomancyso it's not an additional dependency for most
15:15technomancyand it's not exactly 3rd-party
15:16ChousukeChouser: what's the plan with your clojure-compiler? I see you haven't worked on it in a while
15:17cemerickmy real point is that I think it'd be bad if stuff as generic (and as redundant w.r.t. existing libraries) as common IO operations starts leaking into contrib
15:20ChouserChousuke: I've got a new job and a lot less time to work on Clojure stuff
15:20Chouserso the plans the same, the pace is just way down
15:26Chousukethe code you have right now looks quite scary.
15:26Chouserhm. yeah, it's not gotten to the "clean up" phase yet. ;-)
15:43jayfieldshow can I return the first item from a collection that matches a predicate?
15:43jayfieldsother than (first (filter pred coll))
15:43kotarak(seq-utils/find-first pred coll)
15:43jayfieldscool. thanks.
15:44jayfieldsI take it that's in contrib?
15:44kotarakYup.
15:45cemerickChouser: hey, congrats! Is it hush-hush, or do we get to leer at your new employer's wares?
15:45Chouserhttp://sentryds.com/
15:59drewrChouser: Congrats!
16:00drewrAre you relocating to FL or working from IL/IN/wherever you are now?
16:01Chousertelecommuting full time now. We'll see how that goes. :-)
16:02drewrIt's definitely bittersweet.
16:03drewrI love it today because it's 65 and I'm on my porch.
16:03Chouserah, nice
16:09triddellfunctions are supposed to return early, right? I have a function that checks user security against authorized access roles. How should I return true after the first authorized match from a for list comphrehension?
16:10triddellare not supposed to return early that is
16:10hiredman(first (for ...))
16:11arohnertriddell: for returns a lazy list that is realized as necessary
16:12arohnerfirst "blocks" until the first element is returned from the lazy list
16:12technomancycemerick: I don't follow.
16:12technomancywhat's wrong with that?
16:13hiredman~literal [3] clojure
16:13clojurebota very attractive hammer with a nice heft to it
16:13hiredman^- now using fnparse
16:14cemericktechnomancy: there's a lot of java libraries that do a lot of things. Reimplementing capabilities (especially inherently-stateful stuff like IO) in clojure is counterproductive overall, IMO. Not having to do that sort of thing is why having fantastic java interop is a Good Thing.
16:14AWizzArd~ max people
16:14clojurebotmax people is 164
16:15triddellarohner & hiredman: thanks
16:15cemerickbeen that way for a long time now
16:15cemerickmaybe clojurebot should track the date that the last max was reached
16:16technomancycemerick: everyone's just going to re-implement it on their own anyway
16:16AWizzArdWell, it first was 164. Then Clojurebot forgot that number. After a few days it maxed out freshly on 162. But then I resetted it to 164 again. This is now a while ago.
16:16technomancycontrib is useful *because* it provides common I/O operations
16:17AWizzArdUntil that max number of users there was a funny correlation between the numbers of the GG and the number of users in here. That correlation was: for each 10 new users in the GG we got one more user here.
16:17cemericktechnomancy: really? At what point is pulling in well-tested libraries worthwhile, then?
16:17technomancycemerick: rm -rf ain't exactly rocket science
16:17AWizzArdFor some reason then the number of users here settled at +/- 125, while the GG got more users.
16:17technomancyyou'd pull in 3rd-party libs for tricky things like joda for date parsing
16:18cemerickI'm sure someone will reimplement date parsing in clojure, too. I'm just wondering where the line gets drawn.
16:19technomancycemerick: I did. but I realized it's a bad idea because it's impossible to get right.
16:19technomancyso it didn't go in contrib.
16:19technomancybut this is very, very different.
16:22cemerickTo each his own, I guess. Reinventing any otherwise well-tested wheel without getting a significant return on that work just seems like a waste to me. *shrug*
16:23technomancyeverybody who writes tests for code that writes to disk needs to delete whole directories. having to pull in an apache dependency to do this is... sad.
16:23cemericknot really -- we use ant to clean such temp spaces up.
16:24technomancyit's fewer lines of code to just implement the function than actual lines of XML necessary to express the dependency on apache commons io.
16:24technomancywhat about people who want to run tests from the REPL or from slime?
16:26cemerickthat largely doesn't make sense to me either :-)
16:27technomancyif you have to launch a new instance every time you want to run the tests, it totally kills your rhythm since you've got to wait a few seconds for the JVM to boot.
16:28technomancywhich is OK for integration tests, but totally unacceptable for unit tests where you need instant feedback
16:29technomancysee http://p.hagelb.org/06-clojure-test-mode.ogv
16:30cemericklike I said, to each his own. IMO, the REPL is phenomenal for interactive development, but any results from tests run in it aren't to be trusted -- too much opportunity for environment pollution that can skew them one way or another.
16:31technomancyyeah, it can't be your only method of testing; that's for sure.
16:31technomancybut to avoid testing with it is to give up a valuable tool.
16:33cemerickI don't avoid it...but then, I can't think of a single REPL-friendly test we have that uses any temp files.
16:37technomancymaybe that's because you don't have an rm -rf that works from the repl. =)
16:37cemerickheh
16:38cemericknah, we just don't generate files *shrug*
16:38cemerickif we did, I'd probably have to know my way around a shell way better than I do
16:41cemerickeverything we do is in-memory. GC cleans up after us :-)
16:42technomancythat's awesome if you can get away with it. =)
16:42cemerickI know :-D
16:58emacsenCan someone explain why I get an error that v doesn't resolve in the context: http://paste.lisp.org/display/79032
16:58emacsen(that's not the final code, but it's the simplest version I have right now)
16:59cemerickemacsen: each arity must be wrapped in parens....
16:59emacsencemerick, ah :)
17:00cemerickemacsen: http://paste.lisp.org/display/79032
17:00kotarakemacsen: and the (if (empty? ..) true) ( ... looks ominous. The if is basically useless.
17:00emacsenkotarak, the first one? you're probably right
17:01emacsenotherwise, well you need it to return true sometime right?
17:01emacsencemerick, thx
17:01kotarakAnd (cond ... :else false) can also be left out. cond will return nil of no clause matched, so it will count as false.
17:02emacsenThis also isn't the final code. It's going to do more than this, and will be lazy, but this is my first shot
17:02emacsenkotarak, for this version, true. Later versions, no, but you're right in what you see
17:02emacsen(because nil won't print as false in print I believe
17:05hiredman~ticker JAVA
17:05clojurebotJAVA; -0.06
17:12durka42~ticker ORCL
17:12clojurebotORCL; -0.18
17:13danlarkin~ticker CHINA
17:13clojurebotCHINA; +0.07
17:13danlarkintada!
17:14durka42china?
17:14p_l?
17:15kotarak~ticker CON.F
17:15clojurebotjava.io.IOException: Server returned HTTP response code: 400 for URL: http://www.google.com/finance/info?q=CON.F
17:15durka42CDC Corporation
17:15durka42(Public, NASDAQ:CHINA)
19:19cadshey, how do I use a namespace like clojure.set ? Neither (use clojure.set) or (use clojure/set) seem to work.
19:22technomancy(use 'clojure.set)
19:22Raynesuse 'clojure.set
19:22Raynestechnomancy: You win this time. :(
19:22technomancyor even better put (:use [clojure.set]) in your ns directive
19:26lisppaste8Rayne pasted "imports and uses in namespace example for cads" at http://paste.lisp.org/display/79041
19:28cadswhy do we quote it?
19:28cadswow, thanks for the example rayne
19:29Raynescads: No problem.
19:29technomancycads: because clojure.set is not bound to a value
19:29RaynesQuoting it keeps Clojure from trying to evaluate it.
19:29technomancytry just entering clojure.set into a repl; it doesn't mean anything
19:29Raynes^ what he said.
19:29cadsah
19:30technomancyit's a symbol that is used to look up a namespace
19:30technomancywhich is different from a var that's used to look up a value
19:30cadsI thought it would just pass the symbol in that case, but I remember the eval rules now
19:30technomancycads: if use were a macro, it could do that
19:31technomancybut use is a function
19:31technomancyns is a macro, which is why the evaluation rules are different there
19:37cgrandtechnomancy: hi! just noticed (while grepping irc logs) that you talked to cgrand-rec 2 days ago. cgrand-rec isn't me, it's a disconnected irssi logging the channel
19:37technomancycgrand: ah; good to know. =)
19:38technomancyI forgot what I said though.
19:38cgrandthat you were trying the new enlive
19:39technomancyoh, I was "use"ing enlive and was wondering if it might be better not to export any vars that conflicted with clojure core.
19:39unlinkWhat's the idiom for function definitions visible only inside another function?
19:39technomancyI've since decided to stick with "use :only" unless I have a reason not to
19:39technomancyunlink: define them in let bindings
19:40lisppaste8technomancy pasted "let-binding a function for internal use; see target-file" at http://paste.lisp.org/display/79044
19:40technomancyunlink: ^^
19:41unlinkboom
19:41stuhoodyou overwhelmed lisp.org with your awesome code, and it is throwing 500's...
19:41technomancyamazing
19:42technomancyif you want something done right, you have to do it yourself: http://p.hagelb.org/extract-jar.html
19:42dreishOr http://gist.github.com/
19:42technomancywitness the power of Static Files
19:42technomancydoes gist do clojure highlighting?
19:42dreishYes.
19:42stuhoodyea
19:42technomancycool
19:43technomancybut I prefer static files. =)
19:43dreishThey do Genshi highlighting.
19:43stuhoodspeaking of which, has anyone tried to get Clojure highlighting for Trac?
19:44dreishMaybe Genshi's not so obscure. (I'd never heard of it.) But anyway they cover something like 80 languages.
19:44cgrandtechnomancy: it bothers me to clash with clojure.core (eg CSS :not is 'but), I should rename 'complement back to 'complement-state (or 'negate or something else) and find another name for 'empty
19:45technomancycgrand: clashing in private defns is not as big of a deal
19:45unlinkSo def always (re)binds in the global namespace, regardless of the scope?
19:46technomancyyeah. you shouldn't use it at outside toplevel scope unless you have a really good reason to do it though.
19:46unlinkI guess I'm just used to scheme's scoping
19:46unlinkwhich is different
19:47technomancyin fact, you shouldn't do it after your application has loaded at all
19:47cgrandtechnomancy: I want to keep them (complement and empty) public
19:47technomancyor at least be aware that you're stepping outside the Golden Path
19:47unlinkright
19:48unlinkI think (def a [x] (def b [x] (+ x 1)) (b x)) is nicer syntax than (def a [x] (let [b (fn [x] (+ x 1))] (b x))) though
19:48unlinks/\<def\>/&n
19:49chessguyso i'm thinking about an interesting little project, but i'd really need a freaking good REPL to play with it. anybody got any good suggestions? is SLIME as good as it gets?
19:49dreishletfn would be handy.
19:49technomancychessguy: slime is rockin'
19:49unlinksee: factorial with recur
19:49technomancybe sure you use M-x clojure-install to set it up though.
19:50chessguyhmm. i don't remember if that's how i installed it or not
19:50chessguyhow would i tell?
19:50technomancychessguy: if you used it, you should have a call to clojure-slime-config somewhere in your personal .emacs setup.
19:51chessguydoesn't look like it
19:51chessguyjust (slime-setup)
19:51technomancyif you've already got it working you should be ok
19:51chessguyand slime-setup '(slime-repl)
19:51technomancyI was just thinking if you were going to install from scratch
19:51unlinkAm I writing this idiomatically? http://gist.github.com/100173
19:52dreishunlink: Maybe (letfn [inner [n m] ...] (inner n 1)) ?
19:52unlinkOh, there exists a letfn?
19:52dreishSince January, yes.
19:52chessguyi don't get it, when i M-x slime, it says something about connecting to a server? what is it connecting to
19:52unlinkoh
19:52unlinkhot
19:53technomancychessguy: a clojure instance is started that "serves" the Emacs instance over slime
19:53technomancythere's a socket connection between the two
19:53chessguyoh, a JVM environment?
19:54Raynestechnomancy: Stop being smarter than me. It's not nice. :|
19:54technomancyheh
19:54technomancychessguy: yeah, it's launched as a subprocess.
19:54chessguycool
19:54dreishunlink: Or just ((fn inner [n m] ...) n 1), but the double open parens can cause crossed eyes.
19:56chessguydoes slime store the result of the last evaluation anywhere that you can get at it?
19:56chessguye.g., for haskell, in ghci, if i do > 2 + 3, followed by > it == 5, i'd get true
19:56technomancychessguy: probably, but I couldn't tell you off the top of my head. the slime manual is really good though.
19:56chessguyoh ok, i'll take a look
19:57chessguythanks
20:15dysingerwhy does this work (straight java)
20:15dysingersonian.archive.aws=> (String/format "%s ran %d miles today" (to-array ["Stu" 8]))
20:16dysinger"Stu ran 8 miles today"
20:16dysingersonian.archive.aws=>
20:16dysingerand this one doesn't
20:16dysingersonian.archive.aws=> (format "%s ran %d miles today" ["Stu" 8])
20:16dysingerjava.util.MissingFormatArgumentException: Format specifier 'd' (NO_SOURCE_FILE:0)
20:16dysingersonian.archive.aws=>
20:16dreishRemove the []
20:16dysingerI know that works
20:17dysingerI am saying the internal code for (format converts to a java array and passes it to java like the 1st call
20:17dreishThe & turns the remaining args into a sequence.
20:18dysinger~(format "%s ran %d miles today" (seq ["Stu" 8]))
20:18clojurebotformat is http://github.com/tomfaulhaber/cl-format/tree/master
20:18dysingeroops
20:18hiredmandysinger: it works that way because [] does not make an array
20:18dysinger,(format "%s ran %d miles today" (seq ["Stu" 8]))
20:18clojurebotjava.util.MissingFormatArgumentException: Format specifier 'd'
20:19dreishdysinger: Why would you expect that to work?
20:19hiredman[] makes a persistent vector, which java's format doesn't know anything about
20:19dreishargs now contains (("Stu" 8)) -- a seq with only one thing in it.
20:19dysingerright
20:19dreishThat thing happens to be another seq, but it needs _two_ things.
20:19dreishNot _one_ seq.
20:20dysingerso the only way to format with a seq / vector / set is to use apply
20:20dreishSure, or you could do String/format yourself I guess.
20:21dysingery
20:21dreishIf you do it a lot, maybe write a formatseq?
20:21dysingertrue
20:21dreishI'd probably apply. It seems cleaner somehow.
20:21dysingery it works fine
20:21dysingerjust curious
20:22dysingerthe & args turning into a seq explains the magic
20:22dreishk
20:23dysingersorry for the bone-headed questions - I've been seriously programming clojure for 3 weeks.
20:23dysinger:)
20:23dreishnp
20:24dreishFor some reason I thought you'd been around for months, actually.
20:24dysingerI learn quick - but sometimes ask dumb questions
20:24dysingerand I did Java for 10 years and some lisp already :)
20:25dysingeram totally loving it though
20:25dysingerI rewrote some java today and shrank it 10:1
20:25dreishIt is nice.
20:27Raynesdysinger: Good evening.
20:27dreishWhenever I have to make a change to the existing Java part of my pet project, it's painful to have to deal with that language.
20:27dysingerheya Raynes
20:38chessguyhmm, i don't get how to use slime presentations to copy the previous results to the prompt
20:42gnuvince_Sometimes I hate dynamic typing...
20:50chessguyi'm reading http://common-lisp.net/project/slime/doc/html/Presentations.html and it says "Using standard Emacs commands, the presentation can be copied to a new input in the REPL", but it doesn't say WHAT standard Emacs commands
20:53technomancychessguy_: M-p
20:53slashus2try them all
20:54chessguyM-p takes me to the last one that matches what i've typed so far
20:55technomancyC-h m will show you what bindings are active for the current mode
20:59chessguynone of those seem to do what i want
21:03chessguy*sigh*
21:16unlinkHow do I pattern match based on whether the argument to a function was a vector or a scalar?
21:16durka42you could do something with multimethods
21:17durka42or you could just put an if statement at the top of the function
21:17dreishDestructuring isn't the same as pattern matching, in that it can't really do what you're asking for.
21:18unlinkoh
21:18hiredmanwell
21:18hiredmanit can
21:18unlinkThat was basically the #1 use case of pattern matching for me
21:19hiredman(defmulti f vector?)
21:19hiredman(defmethod f true [arg] do vector stuff)
21:19hiredman(defmethod f false [arg] do scalar stuff)
21:19dreishhiredman: That's a multimethod, as durka42 suggested.
21:20unlinke.g. fun g(a, b, c) = case a of [] => (round c) = 1 | 1::xs => not (null xs) | _ => b
21:22dreishI'm surprised no one has written a defpattern macro for contrib yet.
21:23unlinkObviously (fn ([[a b & c]] ...) ([_] ...)) doesn't work.
21:28Jedi_Stanniswhat are you trying to do?
21:31technomancychessguy: it might be a clojure repl feature rather than a slime feature
21:50chessguyJedi_Stannis, a simple example: if i've done user> (+ 2 3)
21:50chessguyand gotten back 5
21:51chessguyi want to be able to do user> (+ 5
21:51chessguyand then hit some combo
21:51chessguyto put the 5 from the previous evaluation into what i'm currently typing
21:51Jedi_Stannis*1
21:51Jedi_Stannis?
21:52Jedi_Stannis,(doc *1)
21:52clojurebot"; bound in a repl thread to the most recent value printed"
21:52chessguyoh cool!
21:52Jedi_Stannis,(doc *2)
21:52clojurebot"; bound in a repl thread to the second most recent value printed"
21:53Jedi_Stannis,(doc *3)
21:53clojurebot"; bound in a repl thread to the third most recent value printed"
21:53chessguy,(doc *42)
21:53clojurebotjava.lang.Exception: Unable to resolve var: *42 in this context
21:53Jedi_Stannislol
21:53Jedi_Stannisonly 1 - 3
21:53chessguyjust checking :)
21:53chessguy,(doc *4)
21:53clojurebotjava.lang.Exception: Unable to resolve var: *4 in this context
21:53chessguyboo
21:53chessguyok, better than nothing
21:53chessguythanks!
21:54Jedi_Stannisno problem
22:00ciphercan someone explain how to use the -> form
22:01unlinkI guess one simple example of what I'm trying to do would be a basic implementation of map, where it accepts two parameters, a function and a list. I would like to pattern match on whether the list is empty or not; in the former case, map returns (); in the latter case, it retuns (cons (f x) (map f xs))
22:01Jedi_Stannis,(macroexpand '(-> 1 (+ 2) (* 3))
22:01clojurebotEOF while reading
22:01Jedi_Stannis,(macroexpand '(-> 1 (+ 2) (* 3)))
22:01clojurebot(* (clojure.core/-> 1 (+ 2)) 3)
22:02Jedi_Stannisbleh, doesn't expand all the way:( * (+ 1 2) 3)
22:03Jedi_Stannisunlink: you can't really pattern match in clojure like you can in haskell or other functional languages.... need to write a conditional or write some sort of pattern matching macro
22:03unlinkoh.
22:04unlinkGood excuse to learn reader macros, I suppose.
22:04Jedi_Stanniscipher: so if you want an imperative style, you can start with your data structure and list the functions you want applied to it
22:04Jedi_Stannisunlink: umm, clojure also doesn't have reader macros
22:05Jedi_Stannis,(-> {} (assoc :a 1) (assoc :b 2) (assoc :c 3))
22:05clojurebot{:c 3, :b 2, :a 1}
22:05Carkhey how is it imperative to start with data structures ?
22:05unlinkI guess regular macros might be powerful enough?
22:05Jedi_Stannisyeah, it just will change the way you write it
22:09cipherso I can almost think of it like doto?
22:09unlinkThanks, Jedi_Stannis.
22:12Jedi_Stanniscipher: similar to doto, except instead of it applying methods to an object for side effects, it passes the result from one function call to the next, building up the result
22:13ciphergot it. alright thanks.
22:13Jedi_Stanniscark: its not really imperative, just lets you write things in the order they happen, instead of reverse order by having to nest all the calls
22:15Jedi_Stannisyour welcome
22:17emacsenI've just learned the comparison operators < and > don't work on strings
22:17emacsenIs there a deep reason for this?
22:17Carki'll take the bait : what do you expect from the < operator on strings ?
22:17ChouserI think performance of numeric operations are generally cited.
22:18Carkbyte by byte comparison ? character wise comparison ? what collating order then ?
22:18emacsenChouser, right but shouldn't < be defmulti-ed
22:18durka42emacsen: exactly. that would be slow(er)
22:18emacsenokay, so is there a generic function for this?
22:18gnuvince_Cark: by the way, thanks for the suggestion of "compiling" my records this afternoon. I'm doing some rough tests here, but performance went from 115 seconds on my home PC for 1000+ files to ~90
22:19gnuvince_lambda++
22:19Carkthat's not as good as i imagined gnuvince ='(
22:19gnuvince_Cark: well it is the first time I've done something like this, so I may have not been as efficient as I could.
22:19emacsenin other languages you can compare numbers, or dates, or strings and they use some inferior operator overloading. Is there a function I can use generically?
22:19gnuvince_Cark: I'll push the code in a little while if you want to see the code.
22:20Carkgnuvince : i'd love to
22:20Carkemacsen : to me it does not make sense to use the same operator for strings and for numbers
22:21Carkis some kenji symbol smaller or bigger than the letter B ?
22:21unlinkIs there a shorthand for (let [x (cond ...)] (if (nil? x) (...) x))
22:21unlinkOr maybe something more robust which lets me return nil from cond and still not evaluate the second (...)
22:22emacsenCark, Maybe. But then I guess I have to figure out the right function
22:22emacsenand I won't know that ahead of time
22:22Carkemacsen : you have the full java stack at your fingertips
22:22Carkand pretty good docs too =)
22:22emacsenCark, that's like saying "You have as much mud as you want to build the house of your dreams!"
22:23durka42:)
22:23Carkmaybe but that's efficient mud you dobn't need to recreate !
22:23durka42unlink: if-let maybe?
22:24unlinkI guess like cond-else in scheme
22:25Cark,you want some kind of when-not-let ?
22:25clojurebotjava.lang.Exception: Unable to resolve symbol: you in this context
22:28unlinkAfter some googling it appears that (cond) excepts :else in place of a condition.
22:29gnuvince_Cark: http://bitbucket.org/gnuvince/clj-starcraft/src/tip/src/starcraft/replay/parse.clj#cl-41
22:29emacsenokay, one last very dumb question. Why, if we have namespaces, can't I reuse names from the core?
22:29Carkgnuvince : checking it now
22:29emacseneg I can't use "val" in my functions as an argument because it's already used in the core
22:30Chouseremacsen: you can, but you have to explicitly exclude those core names from being referred into your new namespace
22:30Carkemacsen : you can but you have to specifically import core
22:30hiredman,((fn [val] val) 1)
22:30clojurebot1
22:30emacsenWow both those options suck ;)
22:31Carkthat's the same option =P
22:31emacsenThen it sucks twice as hard ;)
22:31unlinkHow is recur not 100% equivalent to using the name of the function in a tail position recursive call?
22:31Carkthat's CLish
22:32unlinkemacsen: I agree, the semantics are very surprising.
22:32hiredmanunlink: cond does not take :else, :else is just convient because it evals to not nil (true) all the time so if it is reached it's clause will run
22:32unlinkhiredman: oh, of course.
22:32Carkgnuvince : you still have the lookup in read-field
22:32hiredman,(cond (= 1 0) :foo 1 :bar)
22:32clojurebot:bar
22:32emacsenunlink, well it's just I have been writing code lately and finding out quickly that I need to change a lot variable names because they're already in the core
22:33emacsen"val" has always been my default single value argument name
22:33unlinkemacsen: I ran into the gotcha a few times today as well.
22:33emacsenand "seq" seemed like a good name for an argument which was a sequence passed in :)
22:33unlinkI think the idiom is "coll" for that.
22:33emacsenfair nuff
22:33gnuvince_Cark: the lookup to select the getting function?
22:33Carkright
22:34unlinkOk, I guess except for the use of recur with loop.
22:34Carkgnuvince : you could have a make-read-field function, then in compile record you prepare that function, and just use it in the returned lambda
22:35Carki usually name these lamba compiling functions like this : make-frobnicator-fn
22:35Carkas this is not really compiling
22:35gnuvince_ok
22:36Carkso that's one less lookup for you right there ...though i beleive this should not make a huge difference
22:36gnuvince_As for a make-read-field function, won't I need to lookup the type anyway to select the right one?
22:37Carkwell the type is already given in the field-specs right ?
22:37gnuvince_Yes
22:37Carkmhh let me make a paste with some untested code
22:37Carklisppaste8: url?
22:37lisppaste8To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.
22:40lisppaste8cark pasted "untitled" at http://paste.lisp.org/display/79053
22:40Carkthat's only to give the idea
22:40Carkand is actually completely wrong =/
22:41Carkyou want to prepare a list of functions
22:41gnuvince_I'll give it a whirl
22:41Carkvery wrong i put it in the returned lambda =P
22:41cipher,(make-array (. Byte TYPE) [1 2 3])
22:41clojurebotjava.lang.ClassCastException: clojure.lang.LazilyPersistentVector cannot be cast to java.lang.Character
22:41Carklet me anotate again
22:42cipherWhat's the right way to do that?
22:43Chouser,(into-array Byte/TYPE (map byte [1 2 3]))
22:43clojurebot#<byte[] [B@1eab16b>
22:44lisppaste8cark annotated #79053 "untitled" at http://paste.lisp.org/display/79053#1
22:44Carkthat's more like it
22:45lisppaste8cark annotated #79053 "untitled" at http://paste.lisp.org/display/79053#2
22:46Carkgnih
22:46gnuvince_All right
22:46gnuvince_I'll test it out tomorrow at work when I need to pretend like I'm working
22:47Carkdisregard the last one, i need to edit in emacs instead of firefox =P
22:47unlinkAm I missing some clojure programming construct which allows me to avoid writing a cond like this? http://gist.github.com/100253
22:47gnuvince_hehe ;)
22:48gnuvince_,(map even? [1 2 3 4 5 6])
22:48clojurebot(false true false true false true)
22:48gnuvince_,(mapgilter even? [1 2 3 4 5 6])
22:48clojurebotjava.lang.Exception: Unable to resolve symbol: mapgilter in this context
22:48gnuvince_,(filter even? [1 2 3 4 5 6])
22:48clojurebot(2 4 6)
22:49unlinkOk, yes, I know it is a bit contrived.
22:49gnuvince_unlink: the seq functions are prefered.
22:50unlinkBut the point of the function is not to return the even elements in the list, but rather the elements in even positions.
22:50lisppaste8cark annotated #79053 "untitled" at http://paste.lisp.org/display/79053#3
22:50Carkgnuvince : notice on how the vector? call is now out of the loop
22:51Carkerr though the first bracnh of the size if is wrong, you get the idea
22:52gnuvince_Yeah
22:52gnuvince_I've bookmarked the page
22:52Carkpretty hard to give a solution without rewriting a whole bunch of it
22:52gnuvince_One thing I've had to do to get more performance is to close over data instead of using vars.
22:52unlinkIn Haskell, you would do: evens [] = []; evens x = []; evens (x:y:xs) = y:evens xs
22:52Carkwell, the var there is only called once
22:53Carknot inside the loop
22:53gnuvince_Won't it be called every time I call make-read-field-fn?
22:54Carkyes, but you could do this a single time at compile time
22:54Carkor once a file
22:54gnuvince_unlink: you want only the even indexed elements?
22:54Carkonce for every field in every record type
22:54unlinkgnuvince: Yes.
22:54unlinkgnuvince: starting at 1
22:55gnuvince_,(take-nth 2 [1 2 3 4 5 6])
22:55clojurebot(1 3 5)
22:55gnuvince_This starts at zero however.
22:55gnuvince_,(take-nth 2 (cons nil [1 2 3 4 5 6]))
22:55clojurebot(nil 2 4 6)
22:55gnuvince_meh
22:56unlinkI'm actually looking for a way to mimic the Haskell construction.
22:56gnuvince_Cark: is there any good literature on using lambdas like that to optimize code and "compile" code?
22:56gnuvince_unlink: Clojure doesn't have pattern matching, so you're pretty much out of luck there.
22:57gnuvince_Go with the length
22:57unlinkSo (cond (nil? ...)) is the right construction?
22:57Carki don't know, i learned this reading the source code of cl-pcre (the common lisp regex compiler made by edi weitz which is faster than perl)
22:57unlink@gnuvince_
22:58gnuvince_Cark: ok.
22:59Carkgnuvince : too bad you don't have some test files in there, i would give it a go =)
22:59lisppaste8gnuvince pasted "evens" at http://paste.lisp.org/display/79054
22:59gnuvince_Cark: I have a script to get a bunch of them
23:00lisppaste8gnuvince pasted "Download Starcraft replay files" at http://paste.lisp.org/display/79055
23:00unlinkgnuvince_: That doesn't lazily iterate the list, though.
23:01unlinks/list/collection
23:01gnuvince_Cark: this is screen scrapping, so hopefully they didn't change their entire site.
23:01gnuvince_unlink: it's not too hard to change that
23:01Carkis this python ?
23:02unlinkgnuvince_: you mean and still not check whether car and cadr are nil?
23:04gnuvince_Cark: yes.
23:04Carki think i'll just download a couple files manually =P
23:06gnuvince_Cark: wait
23:06gnuvince_I'll put up an archive on a webserver
23:07lisppaste8gnuvince annotated #79054 "lazy evens" at http://paste.lisp.org/display/79054#1
23:07unlinkok, thanks, I have to run
23:10gnuvince_Cark http://www.studio-cdd.com/replays.tar.gz
23:10gnuvince_about 1050 files
23:10Carkquite a big file =)
23:11gnuvince_yeah
23:21replacagood evening, clojurians
23:21Carkhello replaca
23:51Carkare you still there gnuvince ?
23:54replacathis is the time of night when tumbleweeds begin to roll through #clojure
23:55Carkhehe