#clojure logs

2011-01-06

02:04tomojis there any way for a macro that expands to a def to set the :file and :line metadata?
02:04tomojseems def ignores it and supplies its own
02:05qbgYou could expand to (do (def name ...) (vary-meta #'name ...))
02:06tomojouch
02:06tomojbut thanks
02:08amalloytomoj: that's exactly what defmacro itself does
02:08tomojalter-meta! I guess
02:08tomojamalloy: oh, hmm
02:08amalloyit has to set the :macro key of the def'd var
02:09tomojah, (list '. (list 'var name) '(setMacro)) ?
02:11amalloytomoj: yeah
02:12amalloyoh, i see it's not actually altering the meta directly; it's been a while since i looked at that
02:18amalloytomoj: but i guess (.setMacro x) is exactly equivalent to (vary-meta! x assoc :macro true)
02:24tomojyep, only expressed in 16 lines instead of one :)
02:25tomojer, that's not fair I guess
02:32Licensermorning!
02:34qbgLicenser: I see your morning and raise you a good night
02:52rooneyhi all, I'm a total noob trying to install labrepl, lein deps complains that it can't get org.clojure:clojure-contrib:jar:1.1.0-master-SNAPSHOT
02:52rooneywhat should I do?
03:00amalloyrooney: try changing project.clj to ask for clojure-contrib "1.2.0" instead of "1.1.0-master-SNAPSHOT"
03:02rooneyhi amalloy, it's already "1.2.0", I just cloned it and haven't changed anything
03:02tomojdoesn't labrepl's project.clj already ask for 1.2.0?
03:02rooneyyes, tomoj
03:02tomojsome dep is asking for the snapshot, I guess
03:05rooneythis is what lein says
03:05rooneyPath to dependency:
03:05rooney 1) org.apache.maven:super-pom:jar:2.0
03:05rooney 2) autodoc:autodoc:jar:0.7.0
03:05rooney 3) org.clojure:clojure-contrib:jar:1.1.0-master-SNAPSHOT
03:08tomojhuh.
03:08tomojit's fixed in autodoc's repo, but not in the latest autodoc on clojars
03:09tomojI imagine you can probably just remove autodoc from the dev-dependencies
03:12tomojwhy does labrepl dev-dep on autodoc, I wonder?
03:12rooneyhey that works, thanks tomoj!
03:13rooneyI have no slightest clue, I'm really noob about clojure
03:13tomojsee also https://github.com/trptcolin/labrepl/commit/f323292b5947932dbcb56bac3bfca56d781947d7
03:13tomojto keep autodoc but avoid the error
03:13tomojnot sure if there's actually any reason to keep autodoc...
05:42LauJensenMorning crew
05:42talios'lo
05:42talios16minutes till morning tho :)
05:56Leonidas(sort-by :upvotes {:foo {:upvotes 3} :bar {:upvotes 5} :baz {:upvotes 2}})
05:57Leonidas,(sort-by :upvotes {:foo {:upvotes 3} :bar {:upvotes 5} :baz {:upvotes 2}})
05:57clojurebot([:foo {:upvotes 3}] [:bar {:upvotes 5}] [:baz {:upvotes 2}])
05:59Leonidashmm, I think :upvotes is not the proper fn
06:03Leonidas,(sort-by (comp :upvotes second) {:foo {:upvotes 3} :bar {:upvotes 5} :baz {:upvotes 2}})
06:03clojurebot([:baz {:upvotes 2}] [:foo {:upvotes 3}] [:bar {:upvotes 5}])
06:04Leonidas,(sort-by (comp - :upvotes second) {:foo {:upvotes 3} :bar {:upvotes 5} :baz {:upvotes 2}})
06:04clojurebot([:bar {:upvotes 5}] [:foo {:upvotes 3}] [:baz {:upvotes 2}])
06:04Leonidaswhat is better to use: - in the key-fn or reverse on the resulting seq?
06:11Leonidasany why are there 2 planets, http://planet-clojure.org/ and http://planet.clojure.in/
06:13arbschtLeonidas: the latter is implemented in python, the former a rewrite in clojure
06:14arbschtI presume planet.clojure will be deprecated eventually
06:15Leonidasarbscht: and which one to use at the moment? the latter has a nicer UI and looks more "recent".
06:16arbschtLeonidas: I use planet.clojure.in, out of habit
06:17Leonidasarbscht: ah, ok, thanks
06:48Leonidascould someone please take a quick look at https://github.com/Leonidas-from-XIV/karmawhore/blob/master/src/karmawhore.clj ?
06:48LeonidasI'm rather new to clojure and therefore I suppose I did some stuff overly complicated
06:52Chousukelooks pretty good to me
06:52Leonidasbtw, is it possible that split-with and separate are exactly the same function, just implemented differently? and separate is twice in clojure-contrib?
06:53LeonidasChousuke: thank you :) I suspect I messed up in -main, with unpacking, repacking, unpacking again.
06:56Chousukeit seems you don't need summed-karma to be a map
06:56Chousukesince it gets sorted immediately afterwards
06:58Chousukealso is there a need for votes to be a map either?
06:58GOSUBLeonidas: the .org planet came later and was created as a hobby. not sure if it's maintained anymore.
06:59GOSUBarbscht: the former is not a rewrite per se, since it was written without any discussion with me.
06:59ChousukeLeonidas: oh, I just noticed you have a single-segment namespace. That can break some things.
06:59Leonidas,(val ["foo" "bar])
06:59clojurebotEOF while reading string
06:59Leonidas,(val ["foo" "bar"])
06:59clojurebotjava.lang.ClassCastException: clojure.lang.PersistentVector cannot be cast to java.util.Map$Entry
07:00ChousukeLeonidas: you should at least have leonidas.karmawhore or something :)
07:00Chousukepreferably one more, to avoid collisions
07:00LeonidasChousuke: yeah, but I really dislike the deep nesting that this causes.
07:00Chousukeyou'll dislike the problems more
07:00GOSUB,(val (first {"foo" "bar"}))
07:00clojurebot"bar"
07:01Leonidas,(second ["foo" "bar"])
07:01clojurebot"bar"
07:01Leonidashmm, second could be good enough as replacement
07:01ChousukeLeonidas: the issue is that since you only have a single segment in your namespace, it ends up in the default package :/
07:02Chousukeand that confuses IDEs and tools pretty often
07:02bartjI get garbage on my REPL when I do this
07:02bartj, (println "самарская обл.,")
07:02clojurebotсамарская обл.,
07:02Chousukebartj: your encoding is wrong
07:02LeonidasChousuke: oh, ok. I'll think about it. thanks for the information
07:03raekbartj: are you using a plain repl at the terminal, or a repl in an IDE?
07:03bartjraek, a plain REPL
07:03Chousukebartj: there's a switch you can give to java to specify the encoding by I don't remember it :/
07:03Chousukeit's usually something stupid by default
07:03Chousukelike macroman on OS X
07:03raekbartj: lein repl or java -jar clojure.jar clojure.main?
07:03Chousukewho uses that, anymore?
07:04LeonidasChousuke: I don't think it needs to be a map, but semantically i think a map "fits".
07:04raekif you use lein repl, install rlwrap (a command line tool)
07:04LeonidasChousuke: ---^ votes I mean
07:05ChousukeEverything should just use UTF-8 by default nowadays :(
07:05raekagreed
07:05Chousukeif anyone needs anything else, they can change it
07:05raeklein repl uses rlwrap if avaiable and jline otherwise, IIRC
07:06raekand jline chokes on UTF-8
07:07raekbartj: also, you have to set your terminal to use UTF-8 too
07:11raekhrm, I thought *in* and *out* were using UTF-8 in clojure, but it seems they are using the dreaded "Operating System Default Encoding"
07:12raekat least source code is interpreted as UTF-8
07:12bartjraek, still fighting UTF-8
07:13AWizzArdcemerick: do you know anything about Azuls Zing plattform as a cloud service?
07:13cemerickAWizzArd: not a bit
07:13raekbartj: are you using leiningen to start the repl?
07:13AWizzArdThey show so nice comparisons: http://www.azulsystems.com/sites/www.azulsystems.com/Response%20Time%20WEBeTailer2010%20rev2.jpg
07:13cemerickThough Azul + platform sounds interesting! :-)
07:13bartjraek, no
07:13AWizzArdcemerick: it does.. Amazon should buy a few of such.
07:13raekbartj: how do you start it?
07:14bartjraek, java -cp "libraries" jline.ConsoleRunner clojure.main $1
07:15bartjraek, I have that somewhere in an executable
07:15raekbartj: jline is broken.
07:15raekuse rlwrap if you can
07:15bartjraek, you mean a particular version?
07:16raeklast time I checked, it wasn't designed with multi-byte encodings in mind
07:16bartjsigh
07:16raekbut they might have done something about it
07:16cemerickraek: FYI, you can set the JVM's default encoding via the file.encoding system property.
07:16raek-Dfile.encoding=UTF8
07:17raekthis one?
07:17bartjI am going to sorely miss the "history" feature that jline gives my Clojure REPL
07:17cemerickyes
07:17cemerickno good?
07:18raekbartj: if you have rlwrap installed, you should be able to use it like "rlwrap java -cp ..."
07:19raekbartj: you might want to try adding the -Dfile.encoding=UTF8 option and checking the terminal's settings first
07:19bartjraek, thanks a ton;
07:19raekif you're lucky, the jline guys might have fixed it
07:20raekbartj: np
07:20bartjraek, I had rlwrap but didn't know how to use it - "rlwrap command" works
07:20raek"lein repl" has all this built in
07:21raekbut maybe you didn't wanted to use lein
07:24bartjraek, can you please point where I can see more features of lein repl?
07:24bartjraek, I don't know what I am missing
07:26raekbartj: well, basically it starts clojure, takes care of the classpath and wraps the repl in jline or rlwrap
07:26raekhttps://github.com/technomancy/leiningen
07:26raekhttp://groups.google.com/group/leiningen/browse_thread/thread/65ccdef10c4ed173
07:28raekI don't think there are many more features of lein repl
07:28raekwell, it starts a socket server too
07:28bartjraek, thanks again
07:49AWizzArdrhickey mentioned a link to an article about Zing in June or July 2010. Today they seem to have it available: http://www.azulsystems.com/products/zing/whatisit
07:50fyuryuanybody ever experimented with protocol buffers for real time communication via UDP?
07:54cemerickAWizzArd: do they host it? There's a form to request access to trial downloads.
07:55cemerickI'll bet it'll be serious $$, in either case.
07:55fyuryuas rhickey once said: if you have to ask, you can't afford it :-)
07:58AWizzArdcemerick: Unfortunately I don't know about the prices of this. They made me believe that it will be much cheaper than alternative solutions when your load is really big. I don't know how big 'big' is though ;)
07:58cemerickTB-sized heaps makes me think "big" means "BIG" :-)
07:59AWizzArdThough it could be interesting to take one of these Vega 3 machines with 864 cores and 768 GB of RAM and just share it for users that just need 1-20 cores and 1-20 GBs.
08:00AWizzArdFor hosting I found http://goo.gl/ugiOJ
08:02AWizzArdI get the impression that they are offering hosting.
08:02AWizzArdBut it may be possible that they don't target users with non-massive needs.
08:03cemerick"Customers can request a trial copy at…"
08:03cemerickThat screams on-premise.
08:03AWizzArdhttp://www.azulsystems.com/sites/www.azulsystems.com/azul/images/ZRC%20Screen%20Shot.jpg
08:03AWizzArdThis screen looks a bit like a management console for instances.
08:05AWizzArdCool would be if they simply allowed to sign up and buy some time on their instances. I would try it, even for 10$ per hour. Just out of curiosity to see how good my stuff runs there :)
08:43rak85hi, guys
08:43rak85what do i have to 'use' in order to use the thrush function?
08:47rak85sorry, the function is comp
08:47mrBliss,((comp #(* % %) inc) 1)
08:48clojurebot4
08:55AWizzArdrhickey: Would it make sense to let alter-mate! work on symbols too?
08:55AWizzArdI have a macro which generates a defn F. The parameter vector of F is automatically type-hinted. I first tried ~(alter-meta! arg-name assoc :tag class) but later on switched to the more complicated ~(with-meta arg-name (assoc (meta arg-name) :tag class))
08:56@rhickeyAWizzArd: no, symbols are values
08:56AWizzArdOkay, so with-meta was the right approach then.
08:58AWizzArdAnother thing: 'some' takes only one collection over which it iterates. Could this be extended to take n collections, like map (and CLs some)?
09:01bortrebI have a C++ program which I have written which analyzes videos and then outputs data about them to STDOUT
09:02bortrebWhat's the best way to get clojure to process this as sequence of records or whatever?
09:02bortrebor should I be using JNI or JNA or some other such thing??
09:07stuartsierraClojure can read STDIN like any other program
09:17bortrebI'm wanting to write a clojure function that takes in a File object and runs the program on it, returning a lazy sequence of records captured from the output of the program (which may go on for forever if it reads from a camera)
09:18bortrebbut I don't know how to invoke the program from the shell or capture the data in a sequence, especially as it might keep going
09:19bortrebdoes that sound reasonable/ how might I do such a thing?
09:21raekhttp://clojuredocs.org/clojure_core/clojure.java.shell/sh <-- this will probably do the "run the program on the file" part
09:22raekyou will get the whole output as one (possibly giant) string, though
09:24bortrebI've tried that, but the problem is that sh blocks until the process finishes, which may not ever happen
09:24bortrebor at least is inconvienent
09:25bortrebis there some way to make that into a lazy sequence?
09:25raekah, I see. communicating via a stream would perhaps be better
09:26raekyou should be able to make a function very much like sh, but which gives you a stream of the program's output instead
09:27bortrebstreams? what are these? are they lazy-seqs or something?
09:27raekhttp://download.oracle.com/javase/6/docs/api/java/lang/Runtime.html#exec(java.lang.String, java.lang.String[])
09:27raekjava.io.InputStream (for binary data) or java.io.Reader (for text)
09:28raekyou can call line-seq on a reader to get a lazy sequence of the lines in that stream
09:28bortrebso I'll have something like a backing lazy seq that gets realized in a seperate thread that runs the process "till completion" and then take things from that lazy-seq in my main thread?
09:29bortreband still use STDOUT or is there a more proper / better way to send data from the C++ program
09:29raekthe exec call will start the program in a spearate process
09:29bortreb?
09:29raekyou will get a Process object back (http://download.oracle.com/javase/6/docs/api/java/lang/Process.html)
09:29raekand you can access its stdin/out/err
09:30bortrebdoes that sound reasonable?
09:30raekwith this approach, you clojure program would start the C++ program
09:31raekwell, how do you want to start the C++ program?
09:31bortrebI think from the clojure function,
09:31raekif you want to pipe its output to the clojure program's stdin, then you can simply call line-seq on *in*
09:32raekthe exec call will not block
09:32raekso there is no need to start a separate thread here
09:33raekthe reason that sh blocks is that it wants to consume all the input before returning
09:36raekmy advise would be to start the process using java.lang.Runtime/exec (look at the source for 'sh', since the inerop can be tricky in this case) and return (.getInputStream the-process-returned-by-exec)
09:37raekyou can then use the methods of the InputStream to read the data
09:38raekyou could also make a function that returns a lazy sequence of the records by 'repeatedly' calling some 'read-record' function on the input stream
09:38bortrebthanks so much --- I'll start trying to piece something together
09:39raekif the data is text oriented, use Reader instead of InputStream
09:39raeksince bytes and characters are not the same thing in clojure
09:39raek(sorry for spaming, but I really want to stress that)
09:44afekz_is there an FAQ for the # here?
09:53AWizzArdbortreb: I used the approach raek mentioned. Started a binary from Clojure and follow its input stream to see what it outputs.
10:18mtopolnikquery sexpbot
10:31bortrebsuccess
10:35tonylbortreb: congrats, on whatever you are doing
10:38bortrebI made a modified version of sh as per raek's suggestions -- it's at https://gist.github.com/768026
10:39tonyloh interesting, lazyseq of the stdout
10:39bortrebbut, I still don't know how to fix it for long running processes that return a lot of data via STDOUT --- the javadoc for the reader says that Bad Things happen if you wait too long to read the buffer
10:40bortrebso I guess I'd run into that if the lazy seq wasn't consumed quickly enough....
10:45bortrebbut so far it seems to be doing well
10:50AWizzArdbortreb: You don't need a lazy-seq. You could have a thread that reads from the stream whenever you expect it to output something.
10:53bortreb:AWizzArd doesn't the lazy-seq help to decouple the reading from the processing, though?
11:05AWizzArdbortreb: How would it do this? Lazy seqs are an optimization technique that can save memory.
11:09raekbortreb: neat! also, I would recommend passing an additional agrument to the Reader constructor: the encoding
11:09raekif you don't know which one you want, pick "UTF-8"
11:09AWizzArdbortreb: in your case a lazy seq can even potentially cause memory problems, namely when your binary produces tons of output which you don't consume.
11:09bortrebok --- I shall add that
11:10bortrebit's true that the lazy seq can cause memory problems because of the caching action
11:10raekthe clojure.java.io/reader function can be used instead of nesting the two constructors
11:11raek(it's basically just sugar for making these kind of things shorter)
11:11AWizzArdbortreb: I have two futures that constantly read from the output and the error stream
11:11raek(io/reader (.getInputStream process) :encoding "UTF-8")
11:12AWizzArdI use the situation that .read blocks.
11:13AWizzArdThis way my infinit loop can just read everything the binary outputs, and run the parser on it and then recur to the loop head.
11:13raekalso: (def println-repl (bound-fn* println))
11:13AWizzArdThe future will sleep until your binary outputs something. As soon this happens the future wakes up, reads everything, parses it and continues to sleep until the next output arrives.
11:13raekor (alter-var-root #'*out* (constantly *out*)) ;; in the slime repl
11:14raek(io/reader will also wrap the Reader in a BufferedReader)
11:18bortreb:raek I edited the gist to reflect your changes
11:19bortreb:AWizzArd so then your futures dereference into a big string, or a list of lines, or a character stream?
11:20bortrebcould I see an example of using futures to read from STDOUT if it's convienent?
11:24AWizzArdbortreb: the code I wrote is not mine, I can not post it. But I can tell you that you basically need to decide how you think your binary will output data to the console: 1. it happens after you do something specific in Clojure or 2. it can happen at any time, parallel to your running Clojure program.
11:25AWizzArdIf it is 1. then you can simply trigger the action in Clojure and in that moment read from the input stream of the Process object. And then you have a String and can do with it whatever you want.
11:26AWizzArdIn the case 2. you will need a state object, such as an agent, which can be accessed from other threads. They will deref the agent to see its latest output.
11:27AWizzArdYou would send a reading/parsing function to the agent. The agent can call itself, which is the equivalent to the recur in my future.
11:31AWizzArdbortreb: basically have a byte array, say, 1 MB in size. Optimally it should be able to catch more than the binary can output at any time. Then you .read into that array, and see how much you read. Then make a string out of this, parse it and you have your data.
11:32AWizzArdAnd .read can immediately be called again, if it should be needed, depending on your app. It will block until the next output is available. And you can .interrupt it any time.
11:33bortrebwouldn't that have the same problem as the lazy-seq method in that you will not succeed if the program outputs too much?
11:34bortreboh, but you can set the buffer size with your method while you can't with the lazy-seq ethod?
11:34bortreband it doesn't necessarily cache anything
11:35AWizzArdYou can check how much data is .available and create an array on-the-fly of that size.
11:35bortrebhow can code that you wrote not be yours if you wrote it?
11:35AWizzArdBut if you expect that your output can be bigger than a (fixed) array size, just .read multiple times from it, until your data can be parsed in a meaningful way.
11:36AWizzArdbortreb: I wrote it while I was at work. It belongs my company.
14:22edwIs there a non-painful way to deal with including a jar that's not fetched from a lein repo? I'm writing to the AdWords API and would like to use the Google-provided jar.
14:22chouserI think you can symlink (or copy) the jar in to a specific place in your project dir
14:22amalloyedw: it's actually a maven repo, but ways exist
14:22amalloyeasiest for me is lein install
14:23amalloythough i think you have to do something special to install a raw jar
14:23edwHmm. Reading TFM...
14:24amalloyhttp://code.google.com/p/google-api-adwords-java/issues/detail?id=28 is an open issue (open for a long time) asking google to put the damn thing in maven
14:26edwSigh...
14:26amalloyedw: http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html
14:26edwThanks!
14:28amalloylein and cake both provide a convenient wrapper around this functionality, but i can never remember how to use it :P
14:31edwOMG this is insane. In order to add a jar to a classpath I need to create a POM file and add it to the local Maven repo. This is why I hate Java with a passion.
14:32amalloyedw: doesn't that mvn:install task create the pom for you?
14:32amalloywell. "for" you, after you specify all the crazy options it needs
14:32edwPerhaps. I specified a packaging type of 'jar'. Maven is heating up my laptop right now. Let's see what happened...
14:33amalloyjar should be right
14:33amalloynot that i'm a maven expert
14:37edwWell lein installed the jar from the local Maven repo, but I can't find the classes. I'll count this as a victory of sorts. (If I didn't, I'd be pulling out the bottle right now...)
14:38amalloy*chuckle*
14:39amalloyedw: if it's installed, you should be able to specify it as a dependency in project.clj, and then (import com.google.Blah)
14:47edwamalloy: I've specified it as a depenedency, and it appears in *classpath*, but I can't import any of the packages.
14:47amalloyhuh
14:47hiredmanhave you run lein deps? is the jar actually in libs/?
14:50edwYeah, I'm blowing through some of the Java sample code, looking to replicate something trivially simple in Clojure, but this is Java, so trivially simple is hard to find...
14:50rata_hi all
14:52edwHi rata_.
14:52pjstadigone
14:52pjstadigoops
16:01SoftwareMavenIs anybody using clojure for production web servers (beyond toy stuff, anyway)?
16:08lpetitSoftwareMaven: TheDeadLine , for one. And Google App Engine !
16:08lpetithttps://the-deadline.appspot.com/
16:09lpetithttp://www.slideshare.net/smartrevolution/using-clojure-nosql-databases-and-functionalstyle-javascript-to-write-gextgeneration-html5-apps
16:09lpetitand there's also the video related to this talk available somewhere
16:09lpetitI mean, google it and you'll find it :)
16:12benreesmananyone know the right way to get the last inserted id with clojure.contrib.sql?
16:16SoftwareMavenlpetit: I promise I tried Google first. It's always hard to figure out what keywords to try.
16:17SoftwareMavenlpetit: And thanks, too :)
16:18LauJensenbenreesman: I dont know about contrib, but in clojureql this might work @(project (table db :tablename) ["LAST_INSERT_ID()"])
16:18benreesmancool
16:18LauJensenAlso, this might work, if tht ID is also the highest id
16:18LauJensen(-> (project (table db :pages) [:id]) (sort [:id#desc]) (take 1) (pick! :id))
16:19LauJensenThat will return an integer
16:19LauJensen@ benreesman
17:38riddochcHey, I've got a curious thing going on with the tip of master on things in -contrib... When I do (use 'clojure.contrib.monads), I get the following:
17:38riddochcCompilerException java.lang.IllegalStateException: Can't dynamically bind non-dynamic var: clojure.contrib.macro-utils/protected-symbols, compiling:(clojure/contrib/monads.clj:195)
17:39amalloyriddochc: probably not all of contrib is updated for clojure 1.3.0
17:39riddochcI looked in macro-utils, and protected-symbols is defined like so: (defvar- ^:dynamic protected-symbols #{})
17:40riddochcIt *looks* like the metadata indicates it's dynamic.
17:41amalloyi notice that (str (promise)) prints "clojure.core$promise$reify__5542@1926603" (or similar), but (print (promise)) hangs until someone delivers to it. is there a reason for this?
17:44amalloyriddochc: that's the wrong syntax for dynamic, unless defvar- is doing some pretty surprising stuff
17:45amalloyshould be ^{:dynamic true}, i think. ^:dynamic is a type-hint, claiming the object's type will be :dynamic
17:45qbgamalloy: core uses that syntax
17:45qbg^<keyword> is equivalent to ^{<keyword> true} in 1.3
17:46amalloyqbg: oh, thanks; didn't realize that had changed. that's what i get for checking my work in a 1.2 repl
17:46qbgIt is a useful change too
17:46qbg^:private compared to ^{:private true} for example
17:46amalloyqbg: agreed
17:47amalloyriddochc: is the var perhaps getting re-def'ed somewhere else that doesn't include :dynamic?
17:47riddochcamalloy: I'm trying to find that out now...
17:50rata_amalloy: probably print includes in what it prints the value of the promise
17:51amalloyrata_: yeah, presumably. i'm just not sure how to go about finding that and either getting around it or adding an option
17:54rata_amalloy: maybe defining a method for print-method... what are you doing?
17:55amalloyrata_: sandboxing. if the user says (print (sandbox `(promise))), it hangs forever; the sandbox function contains a timeout, but here the print (and therefore deref) happen outside of the timeout context
17:57amalloyperhaps i could add an :as-string mode to the sandboxer, which uses pr-str before returning the result
17:59rata_and does it help to define a method for print-method like (defmethod print-method (class (promise)) [obj] (print (str obj)))?
18:00rata_sorry (d... [obj w] (.write w (str obj)))
18:00rata_amalloy: ^
18:00amalloyrata_: yes, that sorta fixes the problem - except that if the promise HAS been delivered to, you can't see its value
18:01rata_amalloy: well, if there's a predicate for testing if a promise has been delivered, you can handle that in the body of that method
18:04amalloyrata_: i looked around but i couldn't find one. i suppose i could deliver "Pending" to the promise and catch the exception if it's been delivered
18:05rata_can you deliver more than once to a promise?
18:06amalloyrata_: no; that's the idea
18:06amalloy&(let [x (promise)] (deliver x 1) (deliver x 2))
18:06sexpbotjava.lang.IllegalStateException: Multiple deliver calls to a promise
18:09amalloyrata_: thanks for the ideas. i'll meditate on my options
18:09rata_welcome
18:11drewrhow do you get-in in python?
18:12drewrand I don't mean d["foo"]["bar"]
18:12drewrI want a function that will take ["foo"]["bar"] and apply that to d
18:15rata_is there a way to know the fields of a class from clojure?
18:16drewr,(doc "methods")
18:16clojurebotjava.lang.ClassCastException: java.lang.String cannot be cast to clojure.lang.Symbol
18:16drewr,(doc methods)
18:16clojurebot"([multifn]); Given a multimethod, returns a map of dispatch values -> dispatch fns"
18:17drewrhm, I thought there was one for java
18:17drewryou can use show in c.c.repl-utils
18:23vijaykiranHi All .. (noob here) What's the best way to multiply two sequences in clojure ?
18:23rata_drewr: def get_in(d, ss): return reduce(lambda d, s: d[s], ss, d)
18:23rata_vijaykiran: in which way do you want to multiply those seqs?
18:24rata_(map * s1 s2) is one way
18:24drewrrata_: ah, nice
18:25rata_ss is an iterable of keys
18:25vijaykiranrata_: I want something similar to the effect of - for (int i = 1; i < 10; i++) { for (int j = 1; j < 10 ; j++) { println i*j }}
18:26rata_that is (dotimes [i 10] (dotimes [j 10] (println (* i j))))
18:27rata_mmmm... just realized you want it from 1... then (dotime [i 9] (dotimes [j 9] (println (* (inc i) (inc j)))))
18:27vijaykiranrata_: sorry for the wrong description - infact I want the collection of all the i*j
18:27vijaykiranrata_: is that possible using dotimes ?
18:27rata_no... then use for
18:28vijaykiranrata_: https://github.com/vijaykiran/project-euler-clojure/blob/master/Problem4.clj
18:28rata_(for [i (range 1 10), j (range 1 10)] (* i j))
18:28vijaykiranrata_: ok, let me try with for
18:29rata_drewr: that's for multifns, not for any object
18:32rata_amalloy_: according to the source code, I imagine you could use .hasValue as the predicate, but (.hasValue (promise)) doesn't work for me, don't know why
18:32rata_https://github.com/clojure/clojure/blob/master/src/clj/clojure/core.clj#L5951
18:33linusericssonwhat's the name of the nifty parenthesis autocompletition of Slime/emacs?
18:34linusericsson&& how can I enable ctrl (arrowup) in the slime REPL?
18:34sexpbotjava.lang.Exception: Unable to resolve symbol: & in this context
18:34amalloy_linusericsson: paredit
18:34amalloy_what do you want C-<UP> to do? command history? that's M-p by default
18:35linusericsson@amalloy_ Thx! && Thx!
18:36linusericssonyou seriously made my day!
18:36amalloyenjoy :)
18:40riddochcOkay, I've definitely narrowed this down. The definition of m-fmap in contrib/monads triggers the error, "Can't dynamically bind non-dynamic var"
18:41riddochcIt's not a problem with its use of m-bind, exactly, because the previous definitions of m-lift and m-join don't trigger the error.
18:43rata_amalloy: does (.hasValue (promise)) work for you?
18:44amalloyrata_: no, and (show (promise)) doesn't list a hasValue method either; where did you find it?
18:44rata_https://github.com/clojure/clojure/blob/master/src/clj/clojure/core.clj#L5951
18:48rata_amalloy: ^
18:50amalloyrata_: that might be a new 1.3 feature
18:52rata_amalloy: well, I think that's what you need =) or put the print inside the sandbox call (is it a macro or a fn?)
18:52amalloyrata_: it's a function, but either way i think it's equally simple
18:54rata_yes, it just that I don't know if the verb used for macros is to call also :P
19:05riddochcI bet someone else can figure this out a lot faster than I can.
19:15amalloyrata_: good question actually. call is probably wrong, technically, but who knows/cares
19:31woobymacros are functions, they're just called at compile time :)
20:00RaynesIf a Jira issue is marked as unresolved, but somebody somewhere has already fixed it and the fix is already in contrib, what does one to get that issue closed? Just comment that it's no longer applicable?
20:02amalloyRaynes: find the person who filed the issue and tell them to close it, right?
20:02RaynesI think commenting will suffice.
20:27devntrying out fnparse for the first time (or trying to... (while learning how to write a parser...))
20:27amalloydevn: fun. it's been a few years since i wrote any parsers
20:28devnthis is my first time
20:29devni just know that i want to write one to let people use HAML for their templates with clojure
20:29devnamalloy: any suggested reading?
20:30amalloydevn: ummmm, mine was in college. we had some assigned book or other, but it was really dry
20:30amalloyand i'm not sure how the functional/mutable divide affects things
20:32amalloybut parsers are the most interesting part of compilers, so reading up on compilers will probably help. finite automata and pushdown automata were useful things to understand when writing a mutable parser
20:33amalloymaybe see what kind of information flex/jflex and yacc/cups (c/java respectively) ask for when they build a parser
20:34devnyeah im starting to put bits and pieces together
20:34amalloyanyway i'm headed home now. good luck devn
20:34devnbut there looks to be a lot to know
20:34devnI can enumerate the tokens, but understanding how to handle indentation rules and such is difficult
20:34devnciao amalloy
20:44rata_devn: have you looked at the examples that come with fnparse?
20:45rata_devn: also, here's an interesting post http://slyrus.github.com/2010/09/17/parsing-smiles-with-fnparse.html
20:53devnrata_: cool, thanks
20:53devni've looked at the JSON parser but it is still a bit beyond my skill level I think
20:53fbru02when would guys recommend using STOMP instead of json ?
20:53devnfbru02: as soon as the girls do it ;)
20:54fbru02devn: are they hoy?
20:56rata_devn: welcome :) that link explain some bits of a parser step-by-step, hope it helps
20:57devnrata_: the info on hound so far is great
20:57devnthanks again
20:57rata_=)
21:12gfrlog,(eval (repeat 5 'vector))
21:12clojurebotDENIED
21:12gfrlog,(vector 'vector 'vector 'vector)
21:12clojurebot[vector vector vector]
21:12gfrlogI think that would be even more fun if my name were Victor
23:06riddochcI'm sure this is an easy question, but it's evading me... I'd like to have a lazy sequence of characters from a reader. There's line-seq, but not char-seq.
23:06riddochcI'm sure I can do this with a sequence function or two, but it's not coming to me.
23:07Zba2Y7Pr3$source line-seq
23:07sexpbotline-seq is http://is.gd/kgWop
23:08Zba2Y7Pr3riddochc: Surely, you can just adapt the line-seq (as defined above) into char-seq with ease.
23:08amalloyriddochc: (repeatedly #(.read r))?
23:08Zba2Y7Pr3riddochc: Just use (.read rdr) instead of (.readLine rdr).
23:08Zba2Y7Pr3(and not require rdr to be BufferedReader, but just Reader.)
23:09Zba2Y7Pr3riddochc: Cut and paste for the win, amirite?
23:10riddochcZba2Y7Pr3: Sure, I guess. I suppose I was going for something more like amalloy's solution, but I'll need to deal with EOF...
23:10amalloyriddochc: take-while will handle that
23:11riddochcamalloy: Cool, thanks.
23:12hiredman(doc instance?)
23:12clojurebot"([c x]); Evaluates x and tests if it is an instance of the class c. Returns true or false"
23:21riddochcamalloy: Hmm. repeatedly seems to give an infinitely repeating sequence of the results of calling the function once, rather than actually giving a sequence of the results of calling the function over and over. :)
23:22amalloy&(take 10 (repeatedly rand))
23:22sexpbot⟹ (0.5986945969999783 0.5934446983371355 0.17555572971645572 0.2200530400344024 0.4922304862838399 0.23857009757987335 0.8506081527117483 0.5500754080616745 0.4780380877552357 0.5879140724603221)
23:22riddochcEr, no, nevermind.
23:22riddochcHere's an interesting one...
23:22riddochcAhh. (repeatedly #(.read (reader r))) will continually re-open the stream.
23:23Zba2Y7Pr3Well, yeah. You don't want to do that. :-P
23:24riddochc(not= #(let [rdr (reader r)] (repeatedly #(.read %))) (fn [r] (repeatedly #(.read (reader r)))))
23:33amalloyriddochc: well, i guess if any of your files have at least one byte there would be a difference, yeah, but who needs such huge files
23:37riddochcamalloy: Heh. And I thought I was referring to the functions, not the output of them.
23:38amalloywellllll, your first example has nested #()s so it's not exactly a function :P
23:39riddochcamalloy: Eh, true. So, I'm not quite as up on Java as I am on other languages... it looks like .read returns an Integer, in the range 0-65535. It *looks* like it's reading bytes, but I'm not quite sure.
23:40amalloyriddochc: depends whether you're reading a Reader or a Stream
23:41riddochcThe implication seems to be that .read could really a variable number of bits, 16, or 8, or maybe something else, too, depending on the encoding.
23:42amalloyboth classes return an int: either some meaningful piece of data, or -1 for EOF
23:42amalloyStream.read "normal" values are 0-255 because they read bytes
23:42amalloyReader.read "normal" values are 0-65535 because they read UTF-8 characters
23:43amalloy&1
23:43sexpbot⟹ 1
23:43amalloyriddochc: try pasting that arrow into a text file: it's a two-byte character that (.read (reader foo)) will return in one go
23:44riddochcamalloy: Oh, fun. So, if I know I want to be working on bytes, because the format I'm working with can include binary data.
23:44amalloythen you don't want a reader
23:44amalloyyou want an inputstream
23:45riddochcHuh. That arrow comes up as 10233.
23:45amalloyhttp://clojure.github.com/clojure/clojure.java.io-api.html#clojure.java.io/input-stream
23:46amalloy&(int ⟹)
23:46sexpbotjava.lang.Exception: Unable to resolve symbol: ⟹ in this context
23:46amalloy&(int \⟹)
23:46sexpbot⟹ 10233
23:46amalloy&(char 10233)
23:46sexpbot⟹ \⟹
23:46riddochcYup.
23:50amalloy$source promise
23:50sexpbotpromise is http://is.gd/kh36e
23:53amalloyargh seriously, even in 1.3.x there's no class for promises? how can i find out if a given object is a promise?