#clojure logs

2011-01-11

00:22qbgPerhaps I can make an alpha2 release of syntax-rules tonight
00:44amalloy$mail cemerick it occurs to me your first-draft benchmark was a nice satirical comparison of clojure to java: clojure takes N seconds to get something done; java takes 2N and returns null :)
00:44sexpbotMessage saved.
00:56qbgYes, new release out
01:27Berengal_work_Is there a way to apply a java method the way you apply regular functions?
01:27Berengal_work_As in the function "apply"
01:37bortrebwhat's the latest clojure resource for reading from a file blazingly fast in map-reduce style?
01:38bortrebsomething that can do parallel line processing of a 50 Gb log file for example?
01:39amalloyBerengal_work_: i don't think so
02:10Berengal_work_int
02:10Berengal_work_oops
02:23vIkSiThi all
02:23vIkSiTi'm currently using the randomAccessFile java class to tail a file - but it stops working if the log file rotates. Does anyone know how to ensure that the class keeps track of the new file?
02:24vIkSiThttps://gist.github.com/774156 is what i use
02:25amalloyvIkSiT: do you want it to follow the new, rotated-in file, or the rotated-out file with the new name?
02:26vIkSiTthe rotated-in file.
02:26vIkSiTso if i tail current.log, then it should always follow current..
02:27amalloynot that i really have any idea how to solve your problem :P
02:27vIkSiThehe
02:27amalloywell, once java has the file open, it has a pointer to the file's id, not its name
02:27vIkSiTi'm trying to figure out what to google for - rotating files or following files
02:27amalloyjust like any other process
02:27vIkSiTamalloy, right
02:27vIkSiTexcept - the inode changes
02:27amalloyvIkSiT: i just tried both of those searches
02:27vIkSiTso there has to be some way to keep track of the linked to file
02:27vIkSiTamalloy, hehe
02:28amalloyperhaps see what log4j does?
02:31vIkSiThmm yes thats an idea
02:34amalloyor actually the unix tail command. i think it just polls/stats the filename every so often
02:36amalloy*chuckle* $ tail -F mylogfile | java -cp .....
02:36LauJensenIs there a tool to convert a standalone jar to an .exe ?
02:37amalloyLauJensen: why? don't windows installs come with a file association for jars these days?
02:38LauJensenFor some reason its a requirement of USB vendors to have applications delivered as .exe files in order to split it and hide parts of it on the drive itself
02:38amalloythat is priceless
02:39amalloyint main(void) {exec("java -cp ...");}
02:41LauJensenhehe
03:41amalloyraek: exceptions are making me weep at the moment. are we getting your map exceptions, or something similar, soon?
03:42tomojmap exceptions?
03:44amalloytomoj: https://github.com/raek/map-exception
03:44amalloycontributed as an idea to clojure.core, but from the sound of http://dev.clojure.org/display/design/Error+Handling+Comparisons?focusedCommentId=950796 we'll end up with something else
03:45amalloy(that is, i already know we won't be getting these things in a huge hurry, but i want raek to make soothing noises)
03:46Raynesamalloy: Don't count your chickens before they hatch. raek has been rewriting Irclj's message parser for the better part of 2010. ;)
04:09LauJensenRaynes: Always great with some of that Alabama wisdom :)
04:11ejacksonLauJensen: you're right about my blog. All the ideas I've had for it would take too long to do and I'm being lazy
04:12LauJensenejackson: well, at least you're man enough to admit it :)
04:13ejacksoni have a few kettles in the fire, and at least one of them will end up on the blog
04:13LauJensenwell, dont sell your kettles before they burn as Raynes would say
04:14ejacksonor my teapots will come home to roost...
04:14LauJensenhehe
04:14bortrebanyone know of a good resource to learn about processing huge log files in clojure?
04:15LauJensenbortreb: depends on what you mean by good. Alex Osbourne has a blog that shows how to parse 45 Gb in about 8 minutes. I have a blogpost about parsing 50Gb weather data
04:16greghbortreb: try http://stackoverflow.com :)
04:16bortrebI was wondering if there was some clojars library or something I am overlooking
04:16bortrebis 45gb in 8 minutes "good" ?
04:16LauJensenbortreb: no, its fast
04:16ejacksonbortreb: nathanmarz's cascalog is a tool that might be useful for you
04:17LauJensenRuby took 45 hours I think
04:17LauJensenejackson: casalog for parsing logs?!
04:17ejacksondepending on how sophisticated your definiton of parsing is :)
04:17ejacksonand how big your logs
04:17LauJensen..and how much syntax you want to learn
04:18raekthe plan seems to be to define the "map exception"/condition class first
04:18LauJensenIsnt casalog that query language that looks like [?age <> ?person >-@> ::filter] ?
04:18amalloyLauJensen: that looks more like clojure than most things do :P
04:18LauJensenFor you know. When you what the age of the person to be confused for a fish swimming towards a filter
04:18ejacksonyeah,
04:19greghI've had good success recently processing big file by memory mapping them (on a 64-bit machine)
04:19ejacksonit allows pretty arbitrary logic statements to be executed against gigantic files on a hadoop system
04:19LauJensengregh: Thats nice - It sucks when you have 'bad success' doing that
04:19LauJensenejackson: Man you'll earn your money as a consultant if you point people to Hadoop and Casalog when all they want is to parse a log file
04:19bortrebmaybe bad success is getting handed more log parsing jobs because you're sooooo good at it?
04:20afekznaah, "bad success" is probably some jazz term or something
04:20ejacksonok, i was misled by the 'huge' in bortreb's query. I'll admit its probably overkill :)
04:20LauJensenjazz is bad sucess :)
04:20bortrebthanks, I'll read the blog then :)
04:20LauJensenejackson: no no - While you're at it, get him an internship at Google so he can parse the logs on their hardware, thats really the only way to go
04:21LauJensenEverytime I need to skim a logfile, I always get an internship somewhere :)
04:21ejacksonLauJensen: naaah, that's to 2009 - Twitterface or something.
04:21TobiasRaedermorning :)
04:22LauJensenMorning :)
04:22ejacksonyello
04:23TobiasRaederAnyone here using align in emacs?
04:23jwr7Is there a way to specify a timeout on an agent action? My agents perform network I/O which (as it turns out) may hang — I'd like to have a way of getting an exception if I/O takes too long.
04:24jwr7…and the obvious solution (use futures in agent actions) seems overly complex.
04:24raekjwr7: why not use (future ....) instead of send?
04:24amalloyjwr7: the obvious solution is to set a timeout on the network io itself
04:25raekfuture objects have a .get method that acccepts a timeout value
04:25jwr7raek: well, the agent metaphor works really really well for me.
04:26jwr7amalloy: well, this would mean using futures to perform I/O operations, lots of additional complexity.
04:27amalloyjwr7: there's no reason it should mean that
04:27raekok, if you need to asynchronously keep track of some state rather than synchronously (ref/atom), then I guess agents are the best fit
04:27jwr7I was actually surprised there isn't a way to specify a timeout when calling send/send-off — I thought people would have ran into this already.
04:27amalloyjwr7: http://download.oracle.com/javase/1.4.2/docs/api/java/net/Socket.html#setSoTimeout%28int%29
04:27raekagents are not the main mechanism for "sending off stuff for running in another thread"
04:28raeks/main/most basic/
04:28sexpbot<raek> agents are not the most basic mechanism for "sending off stuff for running in another thread"
04:28jwr7amalloy: the network I/O I do accesses Amazon S3 using the jets3t library…
04:29jwr7raek: in my case agents are a perfect fit. I need serialized async operations on a data structure.
04:29raekok. then agents sounds perfect.
04:30raek(agents tend to be somewhat over-used)
04:30jwr7so I guess the answer to my original question ("Is there a way to specify a timeout on an agent action?") is "no"
04:30jwr7raek: yes, I know — but in this case they are really perfect. I would be reimplementing agents if I chose anything else.
04:30raekjwr7: yes, that is true. how should the action be aborted?
04:31raekthe simplest way is to make the action cooperative and let itself be interrupted
04:31jwr7raek: I'd expect a java.util.concurrent.TimeoutException which would cause an agent error.
04:31jwr7…which the rest of my application already knows how to deal with.
04:32raekexception handling is tricky when doing asynch stuff
04:32jwr7put differently, I'd like an agent implemented using futures — and I actually thought that is exactly what send-off does
04:32raekyou can of course catch it in the action, and store it somewhere
04:33raekyes, agents are implemented on top of two ExecutorServices
04:33jwr7raek: as I said, the application already has to deal with agent errors and it does. It's tricky, but all concurrent systems are.
04:34jwr7so the obvious way to implement what I need would be just to wrap my action in a future call with a timeout.
04:34jwr7but that means I'd be creating twice the necessary number of threads, for no good reason
04:35raekhrm, yes
04:35jwr7…and I might end up doing it anyway, as it is the only solution I can think of right now.
04:36raekwhat should the operation on the data structure be in case of a timeout?
04:36jwr7raek: nothing — no change at all.
04:37jwr7raek: agent semantics — either the action succeeds or it doesn't, you don't get states in between.
04:38raekand the lib does not provide any way of setting a timeout?
04:38raek(the network IO thing)
04:39raekeverything would have been simple if the blocking IO call could just throw an exception if it takes too long time
04:40jwr7raek: I'm going through the docs right now. But I'd like a more reliable mechanism, as in "whatever happens, there is a global timeout".
04:40jwr7raek: socket timeouts won't kick in if the data starts dribbling at 5 bytes a second for 2 days.
04:40jwr7raek: so I'd much rather have an absolute limit on the amount of time an agent action may take.
04:40raekthen you pretty much need a thread that you can inerrupt
04:41raekalso, it's too bad that blocking socket operation do not throw an InterruptedException when the thread is interrupted
04:42raekbut another thread can close the socket, which will stop the blocking op
04:42jwr7raek: I think I'll try a macro that wraps an agent action in a future with a timeout on deref. E.g. instead of defn'ing my agent actions I'll defagentaction them.
04:43raekdon't forget to future-cancel it
04:44jwr7raek: hmm — what do you mean? I don't understand that?
04:44raekfutures provide a way of signalling that you don't care about the result anymore
04:45raekthat will try to interrupt the thead if possible
04:45raekmost blocking operations (except sockets) will then throw an InterruptedException
04:46raekso if the network operation takes too long time, you'd want to signal it that it can stop doing what it does, since you don't care about the result anymore
04:48raek(let [ftr (future ...)] (try (.get ftr 1 TimeUnit/MINUTES) (catch TimeoutException e (future-cancel ftr) (throw e))))
04:49raekalso, I really recommend the book http://www.javaconcurrencyinpractice.com/
04:59shortlordis there any elegant way to test if a coll contains at least one logical true value? It seems strange to use 'some' and then check for 'nil?' and 'false?'
05:00mrBlissshortlord: (some identity coll)
05:00nathanmarzLauJensen ejackson: cascalog can be used for local, in-process computation. I do that a lot when developing or when I have a small enough dataset to poke at
05:00LauJensenreally? interesting
05:00LauJensenguess I dont get to make fun at ejackson then :(
05:00nathanmarzLauJensen ejackson: at some point it will have a fork-join implementation which will be even better
05:01ejacksonnathanmarz: that's awesome news
05:01ejacksonLauJensen, nathanmarz : I'm glad not to be totally wrong - I usually default thus.
05:02nathanmarzit just runs hadoop in "local mode", which just means it's in process and there's no daemons to deal with
05:02LauJensennathanmarz: Have you got some docs on this somewhere?
05:03nathanmarzon running it in local mode?
05:03LauJensenOn the whole setup
05:04nathanmarzthere's nothing to running it in local mode, just include it as a dependency in leiningen and open up a repl
05:04nathanmarzthis post: http://nathanmarz.com/blog/news-feed-in-38-lines-of-code-using-cascalog.html talks about using it on a real cluster
05:05nathanmarzoh and you'll want hadoop as a dev dependency: [org.apache.hadoop/hadoop-core "0.20.2-dev"]
05:05nathanmarzsetting up a good wiki is a priority over the next month :)
05:07ejacksonnathanmarz: I saw from some tweets that you were playing with redis. Any joy ? I've been using it recently in clojure and have been v. impressed with it.
05:07ejacksonpersisting a sorted set directly is magic
05:08nathanmarzejackson: i haven't played with redis at all... or tweeted about it
05:08ejacksonhmmm......
05:08nathanmarzi know the runa guys use it
05:09ejacksoni must be losing my mind, going to examine the logs.....
05:09ejackson(not with cascalog...)
05:10ejacksonugh, whatever.
05:10LauJensennathanmarz: thanks
05:20nathanmarzLauJensen: sure thing
05:31shortlordit's not possible to set 2 validators for one single ref, is it? which means I would need to 'and' both functions, right?
05:40ejacksonshortlord: that's what i'd do.
05:44LauJensenshortlord: Likely you'll use cond or condp and make a list of requirements for validation
05:45LauJensenor you could take ejacksons advice and simply let the validator log the event, upload it to Google Docs and then inspect the logs manually with your coworkers via a VPN connection implemented in C
05:47shortlordLauJensen: the google docs thingy is a hell of a great idea! thx a lot, I'll do that :)
05:47LauJensenwell, thank ejackson :)
05:47ejacksonlmao
05:47shortlordthx, ejackson :)
05:47ejacksonyour invoice in the post - BOTH of you
05:48LauJensenyea ejackson's a _real_ consultant :)
05:48shortlord^^
05:48ejacksonLauJensen: i've got a _special_ rate for you buddy.
06:21shortlordis it possible to validate a ref based on the old and the new ref value?
06:23bsteuber1,(doc set-validator!)
06:23clojurebot"([iref validator-fn]); Sets the validator-fn for a var/ref/agent/atom. validator-fn must be nil or a side-effect-free fn of one argument, which will be passed the intended new state on any state change. If the new state is unacceptable, the validator-fn should return false or throw an exception. If the current state (root value if var) is not acceptable to the new validator, an exception will be...
06:25bsteuber1so I guess no
06:29raekshortlord: pre- and post-conditions for the state transition function could perhaps do something similar
06:30jwr7The docstring for future says "…yields a future object that will
06:30jwr7 invoke the body in another thread, and will cache the result…" — cache it until when? What if my future returns a 1GB object and my heap is 3GB?
06:30shortlordraek: ok, that will do, thx
06:30jwr7assuming I don't hold on to the ref, will the result still be stored somewhere?
06:31raekjwr7: what it means is that evert time you dereference it you will get the same value (it is only computed once)
06:31raekit will only be around as long as you hold a reference to the future
06:31jwr7raek: oh, that's cool then.
06:32raekcaches in java are often implemented with some variant of weak references, whose entries will be GC'ed when no-one else has a reference to the object
06:32raekso it probably wouldn't be a problem even if it was holding it in a cache
06:33jwr7raek: thanks. That sounds ok.
06:54raekI've dropped my old .emacs file and started to use emacs starter kit, but I'm getting stuck on one detail:
06:55raekwhen doing C-x C-f, it enters some fuzzy matching mode (whis is very nice) but sometimes I want to visit exactly what I have written
06:56raeke.g. create the file foo-project/src/util.clj instead of reopen my old bar-project/src/util.clj
06:56raekhow can I do this? what am I missing?
06:56Chousukehm.
06:57Chousukeit should allow that
06:57Chousukejust type the full path
06:58Chousukeand be quick enough that the search doesn't trigger :P
06:58Chousukeit has a timeout after you stop typing.
06:58raekwhen I finnish ".clj" it replaces the path with my other file
06:58bsteuber1raek: try C-f when in the minibuffer
06:59bsteuber1at least that works with my fuzzy completion there
06:59raekah, wonderful!
07:00raekChousuke, bsteuber1: thanks
07:00bsteuber1yeah, I was also quite happy after finding this :)
07:00raekbeing quicker-than-emacs worked, but C-f is much more convenient... :-)
07:07Raynescemerick: Morning.
07:07cemerickmorning :-)
07:09raekRaynes: regarding irclj: guess what... I got stuck on the error handling.
07:10Raynesraek: That statement was promptly accompanied by a rimshot by the house band. :p
07:10bsteuberwhen debugging gui apps from swank, closing the applications main window always kills the swank process - any idea how to prevent this?
07:11tomojisn't there some flag you set for what to do on close?
07:12tomoj.setDefaultCloseOperation
07:13tomojthe default shouldn't be EXIT_ON_CLOSE, though...
07:13raekcreating a JFrame, showing it and closing it does not do that for me
07:13raekthe slime-swank session remains alive
07:15bsteuberhmm, so maybe my application does sth. special - it's quite big and chaotic (and not mine)...
07:16tomojif it's swing, grep for EXIT_ON_CLOSE
07:16tomojor DISPOSE_ON_CLOSE maybe
07:17tomoj..ON_CLOSE should do it
07:18bsteubertomoj, raek: found it, there's a custom listener calling System.exit - so thank you :)
07:46ejacksonhello cemerick
07:51cemerickejackson: good afternoon :-)
07:52ejacksoncemerick: indeed :D
07:55cemerickamalloy: pling?
08:41edw`Could someone give me an example usage of `longs'? I'm trying to create an array of unboxed numbers.
08:44chouseredw`: 'longs' just casts. you probably want (long-array [1 2 3])
08:45edw`Ah. Thanks.
08:53Dranikchouser, does long-array create an array for unboxed values?
08:54chouser,(long-array [1 2 3])
08:54clojurebot#<long[] [J@413be>
08:54chouseryep, an array of primitive longs.
08:59Dranik,(int-array [1 2 3])
08:59clojurebot#<int[] [I@1288e12>
08:59Dranikwow! :-)
09:07SomelauwI really don't like scala.
09:08Scriptorwhy not?
09:11SomelauwIt is too complicated.
09:11SomelauwIt's errors are unclear
09:11SomelauwAnd it is hard to read.
09:12SomelauwIt looks ugly
09:12LauJensenhttp://michid.wordpress.com/2010/08/24/so-scala-is-too-complex/
09:13SomelauwAnd it is has too much impliciteness.
09:14SomelauwI will read it, but it probably won't convince me.
09:14clgvyou do have example for what you claim? It would be interesting to see.
09:14cemerickLauJensen: That's a silly post. Verbosity ≠ complexity.
09:15LauJensencemerick: They are very related, though I dont agree with that posts conclusion of course. Scala is waay too complicated
09:16AWizzArdLauJensen: but this guy from the blog was cheating a bit in the Java version.
09:16AWizzArdHe could have made the fields public, so no getters/setters were needed.
09:16cemerick"Complicated for what" is the better question.
09:17cemerickLauJensen: But, verbosity and complexity are *entirely* orthogonal, if they're to mean anything at all.
09:17AWizzArdHe could also import scala and call the same functions as in the Scala example.
09:18AWizzArdThe Java code would still be longer, but way shorter than what he presented in his blog.
09:18SomelauwHis java code, isn't idiomatic java, but he is just converting all scala functions to java first.
09:18LauJensencemerick: Assembly code is very simple, every line does only one thing. But if I tasked you to read the source for Notepad written in Assembly, Im sure you'd think it was complex because of the shear vastness of code. So ytou see, they are related
09:19LauJensenhttp://grep.codeconsult.ch/2010/08/26/so-java-is-more-complex-than-scala-you-must-be-kidding/
09:19Fossiall there is to say about scala: "+: fail"
09:19cemerickLauJensen: No, I'd think it was verbose.
09:19LauJensencemerick: You're too stubborn for reason
09:20cemerickLauJensen: Words mean particular things; just stating that A is related to B doesn't make it so.
09:21cemerickPerhaps one may not like a language because it tends to encourage/require verbosity, but that doesn't mean that the language is simple, or complex.
09:22AWizzArdLauJensen: yes good, this second post shows a more realistic scenario.
09:23LauJensenYou guys remember this one?
09:23LauJensenlife1d=: '_#'{~ (3(2=+/\) 0,],0:)^:a:
09:24AWizzArdMaybe one could say that complexity is introduced when there are "many cases".
09:24LauJensenAWizzArd: Generally speaking, you could say "complexity is introduced, shortly after cemerick is introduced" :)
09:24SomelauwLauJensen, Java code can be much shorter than your example suggests: http://pastebin.com/FkswZt96
09:25SomelauwIt won't compile since it is quickly written.
09:25LauJensenSomelauw: You have to type slow for the compiler to work? crazy....
09:26SomelauwNo, it won't compile since I am too lazy to debug it, but it demonstrates that java doesn't have to be written in the way your article suggests.
09:26LauJensenIts not my article
09:27shortlordcan I use 'loop' without 'recur'? My function is not linear-recursive, so recur is not an option
09:27SomelauwYou posted it.
09:27Chousukeshortlord: no.
09:28RaynesI like it when I'm looking for something that I figure wont exist only to find out that precisely what I'm looking for does exist. c.s/trim-newline for example.
09:28Chousukeyou can call your function in the loop but it needs a recur to actually be a loop. :P
09:29cemerickshortlord: you can also recur to the head of your function, but I presume that's not suitable either
09:29hoeckSomelauw: nice, thats what I thought too
09:29shortlordChousuke: so I'd have to do alle my bindings first, then create another function within the main function and call that inner function manually?
09:29Chousukeshortlord: you can call the main function too?
09:29Chousukeshortlord: ordinary recursion works normally, it just won't be optimised
09:29shortlordbut I don't want the bindings to be overwritten
09:30ChousukeI'm not sure what you need to do :/
09:30ChousukeBut using loop without recur sounds weird. :P
09:30shortlordI am doing some dereferencing in the first entry, which should not happen in the first recursion
09:30LauJensenshortlord: it sounds like you're on an imperative path
09:30Chousukewhat point is there in looping if the loop variables are constant?
09:31raekyou could use a helper function
09:31shortlordthe loop variable is not constant
09:31raek...which would call itself
09:31Chousukemaybe you should come up with some example code illustrating what you need.
09:32Chousukethen it's easier to tell you if there's a better way.
09:33shortlordok
09:33shortlordwhere can I find a good pastebin with clojure highlighting?
09:34Chousukegist is good
09:34cemerickgist.github.com is good
09:34Chousuke:P
09:35shortlordhttps://gist.github.com/774476
09:36shortlordthe last line is where the recursion should eventually occur, but the important thing is the 'let'
09:36shortlordI only want to do that binding once
09:36shortlordand not every time I use that function recursively
09:37shortlord'loop' sounds like the perfect match, but I can't use 'recur' since the function won't be linear recursive
09:37shortlordso I guess the only way to do is would be a helper function, right?
09:37Chousukeusing an inner helper function sounds like it would work. Close it over the let binding
09:38shortlordChousuke: ok, thx
09:41fliebelmorning
09:41fliebelHm, seems I'm back to fliebel again. Whatever.
09:45ejacksonfliebel: you been dabbling in schizophrenia or MPD ?
09:45fliebelejackson: No, just trying to / nick pepijndevos
09:46cemerickfliebel: it takes some doing to change default nicks.
09:46cemerickor, it took me a few days to figure out the magic combination between NickServ and my irc client.
09:47fliebelcemerick: Meh, probably not worth the effort and trouble.
09:57Raynesfliebel: What is 'fliebel'?
09:58RaynesWhat does the name mean, I mean.
09:58fliebelRaynes: Nothing, well, uuuhm. *goes up to translate.google.com*
09:58Raynessexpbot can do that.
09:59Raynes$trans es en hola
09:59sexpbothello
09:59fliebel$trans nl en fliebel
09:59sexpbotfliebel
10:01fliebelIt's a bit of a made-up word, but what I usually mean with it, is 'something', usually something random, or a small extension, like a candle pit.
10:02RaynesInteresting.
10:02fliebelreally?
10:02RaynesAmericans don't make up words.
10:03fliebelRaynes: But you do have slang I believe? That's the same thing.
10:03RaynesWell, yeah.
10:05markskilbeckAmericans don't make up words? "Color", "Humor", "Weapons of Mass Destruction"...
10:08fliebelmarkskilbeck: You're saying American *is* slang? ;)
10:08gtrak$trans en ru hello
10:08sexpbotпривет
10:09cemerickRaynes: I daresay we're produce new words more efficiently than we should ;-)
10:10Raynescemerick: Indeed. Slang completely slipped my mind.
10:11cemerick"Proper English" *is* slang until it's "proper". :-)
10:12RaynesNot isn't always the creation of new words as much as they are repurposing of old words. For example, "ice" is slang for crystallized methamphetamine.
10:17fliebelPython is hard, mainly due to misplaced braces and missing commas.
10:18cemerick__all__ _the under_scoring ended up bothering me after a while.
10:18clgvand messed up tabs ;)
10:19fliebel__these__ methods are magic though :)
10:19cemerickyeah, but you end up writing and using them a fair bit to do certain things
10:19clgvbut there is a great library in python for algebra and other fields of computational mathematics :)
10:20clgvI did work with it 2 years ago while writing my thesis...
10:20fliebelHm, I was looking for a specific property of Python lists, which they don't have. I thought I could do some_list[300] = 3 and it would do that on a list 5 items.
10:22fogus`Anyone have a favorite way to map a function to every other value in a seq (without using take-nth)? i.e. (map-eo - [1 2 3 4]) ==> [1 -2 3 -4]
10:23fliebelfogus`: Why not take-nth?
10:23opqdonutthe simplest is just to write out map-eo using loop
10:23fogus`fliebel: Because that's what I already use and was hoping for a better way
10:24fliebelfogus`: ##(map (comp - last) (partition 2 [1 2 3 4 5 6]))
10:24sexpbot⟹ (-2 -4 -6)
10:24mrBlissnot so pretty: ##(mapcat (fn [[a b]] [a (- b)]) (partition 2 [1 2 3 4]))
10:24sexpbot⟹ (1 -2 3 -4)
10:24AWizzArdIf you want to do it index based then an index would be required. But if you have one then for can be used for that.
10:25AWizzArdfor can combine map+filter.
10:25opqdonut,(map #(%1 %2) (cycle [inc identity]) [1 1 1 1 1])
10:25clojurebot(2 1 2 1 2)
10:25opqdonutI kinda like that
10:25opqdonutis there a better name for #(%1 %2) ?
10:27AWizzArd,(map-indexed #(if (even? %1) %2 (- %2)) [10 20 30 40])
10:27clojurebot(10 -20 30 -40)
10:27AWizzArdthis could also work for you fogus`
10:27fogus`BTW, map-eo shouls also work like this: (map-eo - [1 2 3 4] [1 2 3 4]) ==> (1 0 3 0)
10:27opqdonuterrrr
10:27opqdonutshould it choose the first or the second?
10:27opqdonutconsider (map-eo - [1 2 3 4] [5 5 5 5])
10:29fogus`It should work just like map, but only on e every other elem
10:29opqdonut...
10:29AWizzArdfogus`: what would happen for (map-eo - [10 20 30 40] [1 2 3 4]) ?
10:29fogus`(10 18 30 36)
10:30AWizzArdso, for even indexes it should just return the object from its first argument-sequence?
10:31opqdonut,(let [app (fn [f & rest] (apply f rest)) fst (fn [f & rest] f)] (map app (cycle [fst -]) [10 20 30 40] [1 2 3 4]))
10:31clojurebot(10 18 30 36)
10:33fogus`AWizzArd: right. First seq is special in that way
10:35raekfogus`: why include n/2 dummy values in the second seq?
10:36raek(map-eo - [10 20 30 40] [:dummy 2 :dummy :4])
10:37fogus`raek: ?
10:37AWizzArdfogus`: I would probably suggest to go with map-indexed if you have one argument seq and probably map when you have several and just do the checking yourself
10:38AWizzArd,(map-indexed #(if (even? %1) %2 (- %2)) [10 20 30 40])
10:38clojurebot(10 -20 30 -40)
10:38AWizzArd,(map #(if (even? %1) %2 (- %2 %3)) (range) [10 20 30 40] [1 2 3 4])
10:38clojurebot(10 18 30 36)
10:39fogus`AWizzard: oooo
10:40opqdonut(my solution is general!)
10:40opqdonut(yes, it's also somewhat horrible)
10:41mrBliss,(letfn [(map-eo [f & colls]
10:41mrBliss (apply map #(%1 %&) (cycle [first #(apply f %)])
10:41mrBliss colls))]
10:41mrBliss (map-eo - [10 20 30 40] [1 2 3 4]))
10:41clojurebotEOF while reading
10:42mrBlissI shouldn't copy paste it from a repl ##(letfn [(map-eo [f & colls] (apply map #(%1 %&) (cycle [first #(apply f %)]) colls))] (map-eo - [10 20 30 40] [1 2 3 4]))
10:42sexpbot⟹ (10 18 30 36)
10:42AWizzArdfogus`: although, if you require it often then maybe something like (def map-eo (fn [f & args] (apply map #(if (even? %1) %2 (apply f %2 %&)) (range) args))) would be handy
10:44fogus`These are pretty nice... but now how to make map-eo-nth :-O ;-)
10:45AWizzArdThat is left for the interested reader.
10:46ejacksonexercise for the student...
10:46fogus`LOL
10:46ejacksonor, if it was really written by an academic: the extension to map-eo-nth is trivial.
10:46fogus`Thanks all. It was fun
10:47AWizzArdfogus`: plus you would need to specify if F should be applied to every nth element, or if every nth element is the one to which F will *not* be applied.
10:48AWizzArd(map-eo-nth 3 - [10 20 30 40 50 60 70 80 90]) ==> (-10 20 30 -40 50 60 -70 80 90) ?
10:48AWizzArdOr (10 -20 -30 40 -50 -60 70 -80 -90)?
10:48fogus`AWizzArd: Which makes me very happy that Clojure has avoided the proliferation of kwargs
10:49fogus`i.e. (map - [10 20 30 40 50 60 70 80 90] :from 0 :every 4)
10:50AWizzArdBut what would be the result?
10:51AWizzArdFrom your map-eo I would interpret it as: F is *not* applied to every n-th element, but to all others.
10:51AWizzArdSo (map-eo-nth 3 - [10 20 30 40 50 60 70 80 90]) should result in ==> (10 -20 -30 40 -50 -60 70 -80 -90)
10:53fogus`AWizzArd: No idea... I was just playing
10:54Guest66680does anybody know if clojureql can do "select ... where column in(v1,v2,v3...)"?
11:06Guest66680answer to own question: it can be done by using clojureql.predicates/in directly; clojureql.core/where doesn't seem to support it
11:30zanesI have some confusion about using Clojure with Emacs and swank. I just finished setting everything up and when I evaluate an expression with C-x e the output goes to the minibuffer rather than the REPL buffer. Is that normal?
11:30mrBlisszanes: perfectly normal
11:31mrBliss(although you probably mean C-x C-e :)
11:31LauJensenGuest66680: You're on a dated version, 1.0.0 does support (where (in ....))
11:33fliebelFunny, this morning I thought sorting was a strange thing. Sorting as I knew it involved pretty much comparing every element to every other element, while the way I sort a pile of cards is much simpler. So I wrote a Clojure function to do that, and then found out it's called pigeonhole sort. Anyway, here's my implementation: https://gist.github.com/774664
11:36Berengal_fliebel: Sorting can be pretty interesting
11:36fliebelSad thing is that it is still slower than the built in sort.
11:38Berengal_What does the built-in sort use?
11:38fliebelNo idea...
11:39ScriptorI wonder if it's optimized depending on what the list is like
11:39Berengal_Probably
11:39fliebelBerengal, Scriptor: http://download.oracle.com/javase/6/docs/api/java/util/Arrays.html#sort(byte[])
11:40BerengalIs that what clojure uses?
11:40Scriptorah, quicksort
11:40fliebelBerengal: Yes
11:40Scriptorhttps://github.com/clojure/clojure/blob/b578c69d7480f621841ebcafdfa98e33fcb765f6/src/clj/clojure/core.clj#L2329
11:41Berengalfliebel: How does that work when clojure structures are trees?
11:41Scriptorthere's the exact clojure code, looks like it basically wraps Array.sort
11:41mrBliss"The java.util.Arrays.sort function officially uses a Dual-Pivot Quicksort, though the OpenJDK implementation recently switched from a modified mergesort to a Timsort."
11:43BerengalI don't think the Timsort version has been officially released yet
11:43mrBlissI got it from this interesting comparison: http://stringoftheseus.com/blog/2011/01/10/api-sorting-algorithms/
11:45BerengalSeems there are some good benefits to be had from specializing sort on certain structures
11:45BerengalParticularly lists and vectors
11:46fliebelWhat would be then main reason my sorting thing is a lot slower than Java sort?
11:49SomelauwYou can't quicksort a linked link, can you?
11:49mrBlissSomelauw: it would be slowsort :)
11:50BerengalSomelauw: Depends on how you define quicksort. You can't do the clever swapping during partitioning
11:50mrSpecHello! I have function thats returns list of structures. But max-key doesnt takes list as argument, but structures. Is it possible to put all elements from list as argument into this function?
11:51Somelauwapply
11:51mrBliss,(apply max-key first [[1 2] [4 3] [2 3]])
11:51clojurebot[4 3]
11:51mrSpecthanks!
12:07ymasory_clojurebot: (println (count (str (filter (fn [ch] true) "abc"))))
12:07clojurebotCounterclockwise aka ccw at http://code.google.com/p/counterclockwise/
12:08ymasory_why would that be 26 and not 3?
12:08mrBliss,(str (filter (fn [ch] true) "abc"))
12:08clojurebot"clojure.lang.LazySeq@1ecc1"
12:09mrBliss,(println (count (apply str (filter (fn [ch] true) "abc"))))
12:09clojurebot3
12:10ymasory_i still don't understand
12:11ejackson,(str (filter (fn [ch] true) "abc"))
12:11clojurebot"clojure.lang.LazySeq@1ecc1"
12:11ejackson,(count (str (filter (fn [ch] true) "abc")))
12:11clojurebot26
12:12mrBlissymasory_: str on a seq serializes it, i.e. "clojure.lang.LazySeq@1ecc1", you have to 'apply' str. ##(doc str)
12:12sexpbot⟹ "([] [x] [x & ys]); With no args, returns the empty string. With one arg x, returns x.toString(). (str nil) returns the empty string. With more than one arg, returns the concatenation of the str values of the args."
12:12ejacksonyou need to use apply like mrBliss says
12:12raekor use pr-str
12:12ymasory_i see thank you
12:12raek,(pr-str (filter (fn [ch] true) "abc"))
12:12clojurebot"(\\a \\b \\c)"
12:20S11001001,(String. (into-array Character/TYPE (filter (constantly true) "abc")))
12:20clojurebot"abc"
12:59mrSpecCan't I do: (subvec (sort ...) 0 5) ? What should I use instead of subvec?
13:00qbg(take 5 (sort ...))
13:01mrSpeco! thanks :)
13:01hiredmansort doesn't return vector, subvec works on vectors, why would you expect that to work?
13:04mrSpecyes, so I was looking for some other function which would work.
13:20BerengalIs there a way I could have a function drop into a repl and let me manually return a value?
13:24opqdonut(eval (read)) ?
13:25opqdonutfor example, user=> (defn f [] (+ 1 (eval (read)))) (f) ENTER (+ 1 1) ENTER evaluates to 3
13:25raekread does not work very well if you try to use it in the emacs repl
13:26opqdonutok, sure
13:26BerengalNor is it a proper repl, where you can muck around as much as you like
13:27opqdonutwell you can spawn a repl using some mechanism and then use refs or something for communication
13:27raekopqdonut: you could also use swing (consider the ask part): https://gist.github.com/480608
13:27opqdonutheh
13:27raek...in case that program has access to an X display
13:28Berengalraek: A safe assumption, considering it's mostly useful for development
13:28opqdonutbut that's not a real repl either
13:28BerengalNo, indeed not
13:29raekhow would a real repl respond?
13:29Berengal(exit return-value)
13:29Berengalor something
13:29raek(def *query*)
13:29opqdonutBerengal probably wants to be able to evaluate a bunch of exprs and see the results and then say (the-final-answer-is foo)
13:30BerengalYes.
13:31raek(let [p (promise)] (later-var-root #'*query* (constantly p)) (deref p)) ;; receiver end
13:31raek(deliver *query* 123) ;; sender end
13:31BerengalThat would probably work just fine
13:32raeka bit ugly, since it only allows one pending query
13:32BerengalThat can be hidden with some queuing and plumbing functions
13:32BerengalAnd it won't be a problem if there's only one thread anyway
13:33Berengal(It will be a problem if it's the same thread as the repl thread)
13:33raekyou could perhaps generate a unique number for each, print a message to the user containing that, and let him answer with (answer <id> <value>) or something
13:33raekok, just generalizing... :-)
13:35BerengalWell, implementing some queuing and a decent interface, such as switching from one query to another, automatically binding query-locals and whatnot should only be a couple of lines of code anyway
13:38BerengalNow I only need to figure out how to instantiate an arbitrary class with arbitrary args
13:39raekBerengal: you need java reflection to do that at run-time
13:40Berengalraek: Nothing like (apply .newInstance class args)?
13:41BerengalOh, neat, java.lang.reflect.Constructor takes an Object[] :)
13:42raekno, since 'new'/dot-at-the-end is a special form
13:43raekif compile-time is fine, you could always make a macro that expands into a 'new' form
13:43amalloyBerengal: clojure.lang.Reflector does the things you want, yes?
13:43Berengalamalloy: Hadn't looked at that. Thanks for the tip
13:43Berengalraek: I know, but I was hoping there was an equivalent alternative
13:46amalloy,(clojure.lang.Reflector/invokeConstructor java.util.Date (into-array [10 10 10]))
13:46clojurebot#<Date Thu Nov 10 00:00:00 PST 1910>
13:46amalloyBerengal: tada!
13:46Berengalamalloy: nice :)
13:49signalseekerCan someone refer me to an uptodate post on setting up clojure with emacs/slime? Thanks
13:49technomancysignalseeker: if the swank-clojure readme doesn't cover it please mention what's missing/confusing on the mailing list.
13:51signalseekertechnomancy: I was looking for a starting point because there are tons of blog posts about it. Let me give it a shot
13:51raek(jochu's repo is first on google, but technomancy's one is the up to date one)
13:53raektechnomancy: are your changes always pulled into jochu's repo?
13:54technomancyraek: no; I need to push a deprecation notice to jochu's readme.
13:59BerengalHas anyone tried the clojure maven plugin on windows?
14:01BerengalI tried it today, but couldn't get it to start swank. I found a couple of issues on github regarding errors in command-line handling, but they were both solved
14:54mrSpecone more newbie question... what is the name of funtion remove-if in clojure? I've used it but forgot its name :(
14:55hiredmanyou mean remove?
14:57mrSpecsorry, not remove remove-if-not
14:57ossarehmy love for -> / ->> grows daily
14:58kotarak(->> "Strange things happen" println (when fiasco))
14:58mrSpecI have list: '({:a 1 :b 2} {:a 3 :b 4}) and I'd like to get elements where :a is 1
14:59raekmrSpec: filter
14:59mrSpecthanks!
15:00ossarehmrSpec: filter, map, apply and reduce are really really helpful functions - definitely where I'd start a book where I writing one.
15:01dakrone,(filter #(= (:a %) 1) '({:a 1 :b 2} {:a 3 :b 4}))
15:01clojurebot({:a 1, :b 2})
15:21danwernerhi there
15:22danwerneri'm trying to find a var in clojure.core: letfn*
15:22kotarakletfn* is a special form, IIRC
15:24danwernerkotarak: that's interesting. do you know why it wasn't implemented as a macro?
15:24LauJensenhey danwerner
15:24kotarakdanwerner: no. Probably because you can't get the mutual recursiveness from Clojure's other constructs.
15:25danwernerkotarak: yes, makes sense. thanks meikel
15:26danwernerLauJensen: hey lau. hope you got some calm & peace during the christmas celebrations
15:27LauJensendanwerner: I sure did - Especially since I dont celebrate christmas :) Have you put Clojure to good use at the work place yet?
15:31danwernerLauJensen: I might have found just the opportunity. we'll have to build a web scraping cron job thingy that doesn't depend on the rest of the code base, and isn't mission-critical, so I'll try to convince my superior to give Clojure a shot
15:31LauJensenGreat, that sounds like a perfect fit
15:32danwernerLauJensen: Yes, especially with enlive -- I'm glad you convinced me to give it another try
15:33LauJensenYea scraping with Enlive is really a treat
15:35danwerneris there a general word about how clojure-in-clojure is coming along?
15:35LauJensendanwerner: I dare not even ask anymore
15:43fliebeldanwerner: Someone else has done a unofficial CinC.
15:44danwernermhh, i wonder whether it would make sense to incrementally convert the java part of the implementation to deftype/def{interface,protocol}, a naive almost 1:1 port of the current structure that could then be refined
15:45danwernerfliebel: nice. do you have an URL or something?
15:45fliebelI'm searching
15:46fliebelah! https://github.com/jarpiain/cljc
15:47SergeyDSlightly off-topic question: what does it mean "ANN:" in the beginning of a Clojure email subject?
15:47danwernerSergeyD: ANN = announcement
15:47fliebeldanwerner: If you use it, please tell me how it goes, or blog about it or something.
15:47SergeyDdanwerner: thanks :)
15:51goodmike_mhDoes anyone know why I would be unable to require clojure.string? I'm in a swank session I started from lein swank, in a project that lists [org.clojure/clojure "1.2.0"] as a dependency.
15:52goodmike_mhbut I get "Could not locate clojure/string__init.class or clojure/string.clj on classpath"
15:52goodmike_mhI swear I've been here before.
15:53ossarehgoodmike_mh: could you throw your ns statement into a gist or pastebin or something?
15:54ossarehgoodmike_mh: string is definitely available to you - likely it is either a syntax issue or a conflict in bringing it in (I think replace occurs in both string and core)
15:54goodmike_mhIf I just try '(require '[clojure.string :as str])' at the REPL, it fails
15:54goodmike_mh(require '[clojure.string :as str])
15:55goodmike_mhI can pastie the project.clj
15:55Licensergoodmike_mh: be careful with that, str is a function :)
15:55Licensercal it cs that is what I usually do
15:56ossarehgoodmike_mh: the problem isn't going to be in project.clj - string is part of c.core
15:56goodmike_mhright
15:56Licenseranyway I need to go to bed :) take care and good luck with fingind that strings of yours
15:57brehautLicenser: i didnt think requiring a namespace with an alias overrides a var with the same name?
15:57brehautLicenser: or do you just mean its bad style?
15:57ossarehgoodmike_mh: fwiw that form evals for me - so likely to be something else.
15:57goodmike_mh@Licenser It's common to see clojure.string required as str
15:58ossarehwhat ns are you in when you do that? is it a new ns?
15:58goodmike_mhE.g. the project I'm working in is fogus's Marginalia
15:58goodmike_mhuser
15:59danwernerossareh: did you try something like lein clean; lein deps to rebuild your dependencies? i seem to recall that accidentally having different clojure versions mixed in your libs can cause problems
15:59ossarehgoodmike_mh: for you ^
15:59goodmike_mhdanwerner: I'll try, thanks.
15:59danwerneroops ;)
15:59ossareh=)
16:02goodmike_mhdanwerner: ran lein clean then lein deps then lein swank ...
16:02goodmike_mhIn the terminal window I see Could not locate clojure/string__init.class or clojure/string.clj on classpath
16:03danwernerfliebel: thanks for the link to cljc. i'm looking for a way to write clojure on top of javascript, but cljc seems out of my league (complexity wise). especially not porting it to js :)
16:03technomancygoodmike_mh: what's *clojure-version* say?
16:03fliebeldanwerner: There is already a basic project that does some Clojure to JS.
16:03brehautgoodmike_mh: eval *clojure-version* in your repl
16:03danwernerfliebel: i'm looking at https://github.com/kriyative/clojurejs right now
16:04goodmike_mhtechnomancy: {:interim true, :major 1, :minor 2, :incremental 0, :qualifier "master"}
16:04fliebelIf you can get that to a state where it compiles Cljc, you're there, I think.
16:05BerengalSo a promise looks very much like an I-var. Is there any discussion around adding M-vars too?
16:05goodmike_mhDoes leiningen create your own sandbox of dependencies per project? Or could it be getting confused because of other versions of Clojure or other libraries?
16:05danwernerfliebel: it doesn't have persistant data structures, though, and really only translates a clojure-like language to javascript. (which in itself is pretty cool already.)
16:05technomancygoodmike_mh: it does, but *clojure-version* confirms you have the right one
16:06goodmike_mhI blame fogus for everything.
16:07amalloymrSpec: i was at lunch, but it looks like you got only a vague answer re filter
16:08amalloy&(filter (comp #{1} :a) [{:a 1 :b 2} {:a 3 :b 4}])
16:08sexpbot⟹ ({:a 1, :b 2})
16:08amalloymrSpec: ^ is the easiest and most idiomatic way to do what you were trying to do
16:10goodmike_mhSo, here's what I did. Would someone like to run through these steps to reproduce (or not?)
16:10goodmike_mh1. git clone https://github.com/fogus/marginalia.git
16:10danwernergoodmike_mh: is the error message caused by "lein swank", which then refuses to run?
16:10goodmike_mh2. cd marginalia
16:10goodmike_mh3. lein deps
16:10goodmike_mh4. lein swank
16:11technomancy3 is actually unnecessary now
16:11goodmike_mhdanwerner: error comes from swank
16:11goodmike_mhtechnomancy: really? lein swank will pull in deps?
16:11technomancygoodmike_mh: you only need to call deps manually when you change project.clj
16:12technomancyeven that should be unnecessary in lein 2
16:12goodmike_mhbut if you've just cloned a project repo, you would need to lein deps to start, right?
16:13technomancyno
16:13goodmike_mhwow
16:13danwernergoodmike_mh: followed your steps, got "Connection opened on local port 4005\n#<ServerSocket ...>
16:13technomancygoodmike_mh: just cloned marginalia; works for me
16:13danwernergoodmike_mh: i used lein 1.3.1 though
16:14goodmike_mhOh well. The gods are against me.
16:14technomancygoodmike_mh: is it any different in lein repl vs swank?
16:14goodmike_mhgood question...
16:14goodmike_mhno difference. same error message, although REPL starts.
16:16goodmike_mhdanwerner: Leiningen 1.3.1 for me too.
16:16danwernergoodmike_mh: do you perhaps have any stale swank processes open that use the wrong clojure version?
16:16technomancygoodmike_mh: no reason not to run the latest; try "lein upgrade"
16:17goodmike_mhdanwerner: killing my terminal windows and emacs...
16:17goodmike_mhrunning 'lein upgrade'
16:18goodmike_mhNow running Leiningen 1.4.2 on Java 1.6.0_22 Java HotSpot(TM) 64-Bit Server VM
16:18danwernertechnomancy: lein 2 is not yet "stable", is it?
16:18mrSpecamalloy: Ok, thanks! :)
16:18goodmike_mhlein repl gives me the same error
16:18technomancydanwerner: it has maybe two commits on that branch so far
16:19technomancyfogus`: you want to set :eval-in-leiningen true in marginalia's project.clj if you want tests etc. to run in the same process as lein
16:19danwernertechnomancy: lein swank gives "That's not a task" if i don't do "lein deps" before
16:20technomancydanwerner: oh right; that would only work if you had swank installed for your user
16:20goodmike_mhI just tried lein repl in a new project made from lein new, and no error message.
16:20technomancybut in general lein will know to run deps when it's needed
16:21danwernergoodmike_mh: "ls lib/" for me says "clojure-1.2.0.jar clojure-contrib-1.2.0.jar dev/ hiccup-0.3.0.jar markdownj-1.0.2b4.jar". is it the same for you?
16:21goodmike_mhin Marginalia?
16:22goodmike_mhclojure-1.2.0.jar dev markdownj-1.0.2b4.jar
16:22goodmike_mhclojure-contrib-1.2.0.jar hiccup-0.3.0.jar
16:22goodmike_mhyuck
16:22danwernergoodmike_mh: yes. "ls lib/dev/" is: "clojure-1.2.0.jar hiccup-0.3.0.jar jsch-0.1.42.jar lein-clojars-0.5.0-20091119.123056-6.jar markdownj-1.0.2b4.jar clojure-1.2.0.jar hiccup-0.3.0.jar jsch-0.1.42.jar lein-clojars-0.5.0-20091119.123056-6.jar markdownj-1.0.2b4.jar"
16:22goodmike_mhclojure-1.2.0.jar dev markdownj-1.0.2b4.jar clojure-contrib-1.2.0.jar hiccup-0.3.0.jar
16:23goodmike_mhdanwerner: looks the same, yes
16:25danwernermystifying
16:27fogus`technomancy: Is the lack of :eval-in-leiningen causing issues?
16:27technomancyfogus`: it's complicating things since there are two processes where there should be one.
16:28technomancyit's unlikely it's causing issues, but it could be masking the causes of issues like the above
16:28fogus`technomancy: sold
16:28fliebelfogus`: How far along is JoC?
16:29fogus`fliebel: done
16:29fliebelfogus`: "Softbound print: February 2011 (est.)"
16:29cow_can someone tell me what is the right function to compare to java byte arrays? (byte[])
16:29fogus`fleibel: Sounds about right to me
16:30cow_s/to/two/
16:30sexpbot<cow_> can someone tell me what is the right function two compare two java byte arrays? (byte[])
16:31cow_i have two separate arrays with the same contents and (=) returns false.
16:31fogus`technomancy: this is what you mean correct? https://github.com/fogus/marginalia/commit/f9f212ffbfa5e8f9d1556eeca240a20803d4aa80
16:31fliebelcow_: Uh? .equals?
16:31technomancyfogus`: quite
16:31fogus`Thank you sir
16:31technomancyfogus`: also, for plugins the convention is to put a one-liner in the namespace docstring and the longer version in the defn's docstring
16:31technomancymakes the lein help output prettier
16:32technomancynp
16:32fogus`OK. I will take care of those other changes tonight.
16:32cow_,(.equals (.getBytes "abc") (.getBytes "abc"))
16:32clojurebotfalse
16:32amalloy&(apply = (repeatedly 2 #(into-array Byte/TYPE (range 10))))
16:32sexpbotjava.lang.IllegalArgumentException: argument type mismatch
16:33technomancyfogus`: minor point, but I thought I'd mention it.
16:33cow_(= (.getBytes "abc") (.getBytes "abc"))
16:33cow_,(= (.getBytes "abc") (.getBytes "abc"))
16:33clojurebotfalse
16:33amalloycow_: java arrays don't implement equals by value
16:33amalloytry seq-ing them first
16:33cow_amalloy: right... i'm trying to discover if there is a function
16:33cow_ahhh... ok
16:33amalloy&(= (seq (.getBytes "abc")) (seq (.getBytes "abc")))
16:33sexpbot⟹ true
16:34amalloycow_: kinda a hack imo, but it will work
16:34cow_amalloy: thanks. i forgot all about that
16:34goodmike_mhI can require other core libraries, e.g. (require '[clojure.walk :as walk]) is fine.
16:35goodmike_mhwhat's special about string?
16:35danwernergoodmike_mh: IIRC it got promoted to core in 1.2. what happens if you require clojure.contrib.str-utils2?
16:36goodmike_mhdanwerner: It works fine
16:36goodmike_mh(require '[clojure.contrib.str-utils2 :as foo])
16:36goodmike_mhno errors
16:37danwernergoodmike_mh: okay, works for me as well. it's deprecated but hasn't been removed yet
16:39goodmike_mhThanks, danwerner and technomancy, for the help. I'll try coming back to the problem in a bit.
16:41dakrone,(.compareTo (java.nio.ByteBuffer/wrap (.getBytes "abc")) (java.nio.ByteBuffer/wrap (.getBytes "abc")))
16:41clojurebot0
16:41dakrone,(.compareTo (java.nio.ByteBuffer/wrap (.getBytes "abc")) (java.nio.ByteBuffer/wrap (.getBytes "nth")))
16:41clojurebot-1
16:41dakronecow_: ^^
16:42amalloydakrone: goodness, that seems like much heavier machinery than necessary
16:43dakroneamalloy: may be :)
16:54TakeVI have a list of structs, and each struct has a list of hash maps. How do I filter the top list so that I get just a list containing structs with a certain component in their hash maps?
16:55goodmike_mhOK, so when I unpack the clojure JAR file in my project's lib directory, there is no string.clj in there
16:55amalloyTakeV: this sounds like what mrSpec was doing an hour or two ago
16:56danwernergoodmike_mh: wow
16:56goodmike_mhyeah
16:56goodmike_mhI must be special.
16:58danwernergoodmike_mh: do you have string$*.class ?
16:58goodmike_mhnope
16:59TakeVamalloy: Hmm, I don't see it.
16:59amalloyTakeV: do you really mean each struct has a *list* of hash-maps (like foo is {[{:a 1} {:b 2}]}), or do you mean something more normal like the values in your struct are hash-maps?
16:59danwernergoodmike_mh: i'd rid my ~/.m2/repository/org/clojure directory from all evil by deleting it
16:59goodmike_mhhmm. decisive action.
16:59danwernergoodmike_mh: then lein clean; lein deps would be forced to acquire new jars
16:59TakeVamalloy: Sorry, each struct has a list of hash-maps.
17:00amalloyTakeV: and that one list is always under the same key, like :maps or something?
17:00danwerneris there any way to import functions marked as :private true in another namespace?
17:01danwerner'use and 'require both complain
17:01TakeVamalloy: Yes. :components
17:01qbgdanwerner: Sounds like a bad idea
17:02TakeVamalloy: I want to split off a list from the top level by what components the bottom levels has, update them, then remerge them back into the main list.
17:02danwernerqbg: i'd like to use clojure.core/assert-args without copying it
17:03goodmike_mhdanwerner: nuking the maven repo file seems to have worked.
17:03qbgIts probably a bad idea to use something that is not part of a documented interface
17:03qbgBut if you really need to, you can go through the var
17:03danwernergoodmike_mh: cool. no missing clojure.string anymore?
17:03goodmike_mhIt can't hide from me anymore!
17:04amalloy(filter (comp #(some #{:a} (mapcat keys %)) :components) all-the-structs) maybe?
17:04qbgThough I'm not sure how well that will work considering it is a macro
17:04qbgProbably won't
17:06amalloyTakeV: ^
17:06qbgYou could do (def ^{:macro true} assert-args @#'clojure.core/assert-args)
17:06TakeVamalloy: Sorry, trying to figure out what that does.
17:08amalloyheh, me too
17:08TakeVamalloy: What does "#{:a}" do?
17:08amalloy&(class #{})
17:08sexpbot⟹ clojure.lang.PersistentHashSet
17:08danwernerqbg: nice hack. i've seen somebody else use assert-args before, and he copy&pasted it as well. might be worthwhile to add it to the public interface since it's so useful
17:08amalloy&(map #{:a} [:a :b])
17:08sexpbot⟹ (:a nil)
17:09amalloyTakeV: constructs a set containing the single keyword :a. when called as functions, sets return something truthy iff the set contains the function argument
17:10TakeVamalloy: Oh, right. Sorry, I was parsing that as a fn macro.
17:11S11001001&(#{false} false)
17:11sexpbot⟹ false
17:11S11001001false
17:11amalloyS11001001: yeah, i know. very sad
17:11amalloyso if you want to include false, you can put a (complement nil?) at the front of that comp
17:11S11001001better to remember that it returns the thing, then
17:12S11001001or just use (partial contains? #{...})
17:14tomojamalloy: would you rather sets returned booleans?
17:15amalloytomoj: i'm not sure. it seems rare that i use the self-returning feature, and common that i use it in a filter, but that could be sampling bias
17:16tomojseemed rare to me too
17:17amalloysame thing with (some), really - i never want (f x) back, i always want x
17:17amalloycan call f my damn self if i want :P
17:20Berengalraek: That drop-into-repl thing? Works like a charm
17:26BerengalAre there any persistent dequeues around?
17:30amalloyBerengal: chouser's finger trees would work, but i'm not sure how stable they are
17:30amalloy$google chouser github finger tree
17:30sexpbotFirst out of 30 results is: Chouser/talk-finger-tree - GitHub
17:31sexpbothttps://github.com/Chouser/talk-finger-tree
17:31amalloyBerengal: it's actually at https://github.com/Chouser/finger-tree - not sure why google finds the wrong one
17:32qbgMaybe the talk is more interesting than the code
17:32amalloyqbg: chris is an interesting talker
17:32BerengalThey aren't already in core/contrib?
17:32BerengalOoh, talk, where?
17:32amalloyBerengal i don't think they are, no
17:33qbgI think they the finger trees might move to contrib after 1.3
17:36BerengalI can't really depend on something that isn't automagically downloaded...
17:36arohneris there a preduce anywhere?
17:36BerengalDo vectors support easy adding at the front?
17:37tonyllist do
17:38BerengalBut lists don't support easy adding at the end
17:38amalloyBerengal: it's probably in clojars
17:39amalloywell, i guess not
17:39Berengalamalloy: I couldn't find it there
17:39S11001001well "easy", if it just does (vec (cons elt vec)) then what is it doing really?
17:40S11001001hmm, there's a binding problem there
17:40amalloyBerengal: you can download it and put it there yourself, if you want to make it available for auto-download
17:40Berengalamalloy: What, even though I'm just some random person on the internet?
17:41amalloyBerengal: indeed!
17:41BerengalQuite the free-for-all :)
17:42amalloyBerengal: just don't make it look like an official finger-tree release
17:42amalloyput it under berengal/finger-tree instead of (chouser|finger-tree)/finger-tree
17:42BerengalAh, ok
17:43BerengalEh... Cons doesn't implement IPersistentStack?
17:44BerengalGuess that means it's time for bed
17:45tomojS11001001: seems if you call vec at all you've already lost
17:49amalloytomoj: ##(nth (iterate vec (range 100)) 10000) doesn't cost too much :)
17:49sexpbot⟹ [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99]
17:52tomojthat's a very short vector
17:52amalloytomoj: but i suspect (vec [...]) is a no-op
17:52tomoj(vec (conj v x)) can be hundreds of times slower than just (conj v x)
17:52tomojfor a long vector
17:52tomojI would've thought so too
17:52tomojmaybe I screwed my test up
17:53tomoj,(let [v (vec (repeat 1000000 0))] (time (when (vec (conj v 0)))) (time (when (conj v 0))))
17:53amalloy$source vec
17:53sexpbotvec is http://is.gd/kAbaj
17:53clojurebotExecution Timed Out
17:53qbg,(class (vec [1 2 3]))
17:53clojurebotclojure.lang.PersistentVector
17:54qbg,(class (vec '(1 2 3)))
17:54clojurebotclojure.lang.PersistentVector
17:54danwerneris there a manual for sexpbot/clojurebot somewhere? =)
17:54amalloytomoj: wow, you're right
17:54amalloy$help
17:54sexpbotYou're going to need to tell me what you want help with.
17:54amalloybah
17:54tomoj,(apply identical? ((juxt identity vec) [1 2 3]))
17:54clojurebotfalse
17:55ossarehhttp://github.com/Rayns/sexpbot/wiki/Plugin-quick-start-guide
17:55amalloydanwerner: usage manual or dev manual?
17:55danwerneramalloy: usage, e.g. what's the difference between & and ##
17:56amalloydanwerner: & only works at the beginning of a string, whereas ##(inc 1)-style requests are allowed ##(inc 2) anywhere
17:56sexpbot(inc 1) ⟹ 2
17:56sexpbot(inc 2) ⟹ 3
17:58danwerneramalloy: thanks
17:58amalloydanwerner: np. i added the ## feature, and i'm more or less the only person who uses it :)
17:59danwerneramalloy: well, ##(identity "not anymore") ;-)
17:59sexpbot⟹ "not anymore"
18:00ossareh#("image we only spoke through sexpbot")
18:00ossarehfail.
18:00amalloyossareh: it's so hard to hit the same key twice in a row, eh?
18:01ossarehhah, that or I really don't know the difference between 3 and 7
18:01danwerner##"any form"
18:02amalloydanwerner: actually ## only triggers on ##(
18:02danwerner##(str "ah" "not" "any" "form")
18:02sexpbot⟹ "ahnotanyform"
18:02amalloyit's on my todo list
18:02amalloyfor sometime in 2011
18:06danwerneramalloy: have you looked at the clojurebot source II lately? it now uses conduit for its data shoveling
18:08amalloydanwerner: not lately, but i remember seeing the conduit thing
18:10danwerneramalloy: most of the people i've asked who used monads in clojure at times, eventually discontinued to do so. have you used monads in clojure yet?
18:11amalloyno. read about them a few times and sorta understand what the idea is, but i haven't internalized them enough to notice when i ought to use them
18:33raekwith all the on-by-default goodies of emacs-starter-kit, I am king of the world.
18:36danwernerraek: does that include proper paredit support for clojure? i remember i had to patch something up manually
18:37raekyes, it includes fixes for { }
18:37raekat least that was what I had to patch
18:38arohneris there a preduce implemented anywhere?
18:39amalloyarohner: preduce can't work unless your function is associative, so i don't think there's a built-in
18:39amalloyit might even have to be commutative? i'm not sure
18:40arohneramalloy: yes, it has to be commutative. That's pretty standard. Google's map reduce has no problems running massively parallel
18:40arohnerrhickey has a couple of side projects that contain preduce, but both require jsr166, which I can't find anywhere
18:48ossareharohner: is jsr166 the fork/join stuff?
18:48arohnerossareh: yeah
18:50ossarehhttp://gee.cs.oswego.edu/cgi-bin/viewcvs.cgi/jsr166/src/jsr166y/
18:50ossareharohner: ^
18:51arohnerossareh: thanks. I've seen that, still trying to figure out how to make clojure happy with it :-(
19:00danwernerarohner: i've never tried it, but it should be sufficient to put http://clojure.googlegroups.com/web/jsr166y.jar on your classpath
19:02arohnerdanwerner: aha, thanks
19:02arohnerdanwerner: that's a different version from the 'official' one
19:06danwernerarohner: in what way different?
19:06arohnerdanwerner: the ParallelArray.class is in a different namespace/package
19:07arohnerapparently the up to date official version has it in a different location than it was when rhickey built that one
19:07danwerneri see
19:07arohnerand clojure.parallel imports the old location
19:08danwernerarohner: have fun then, and a good night
19:09arohnerdanwerner: I will! thanks for the tip
19:26Zane19hi
20:32a_strange_guy /msg NickServ identify w3r5z7
22:00currentBso if I want a program to continually print lines while it's running, what's the best way to avoid the nil that's being returned to constantly be shown in the repl?
22:01amalloycurrentB: don't evaluate that line at the repl top-level?
22:01currentBk
22:01amalloy&(do (println 10) "not nil")
22:01sexpbot⟹ 10 "not nil"
22:01amalloy&(do (println 10))
22:01sexpbot⟹ 10 nil
22:13amalloychouser: is https://github.com/Chouser/finger-tree the state of the art on finger trees, or has development moved somewhere else?
22:16dnolenamalloy: I thought fingers-tree were here, https://github.com/clojure/data.finger-tree
22:17amalloydnolen: aha, thanks
23:46gtechif you evaluate a buffer in emacs of a series of expressions is it normal that only the last output is printed?
23:46gtechlast expression*
23:53gtechah using, pr doesn't newline so it overwrites the output