#clojure logs

2011-08-07

00:21seancorfieldon the subject of reflection... i was trying (and failing) to call setter on a Field the other day
00:22seancorfieldi was working with the MongoOptions object - which is a class with all public fields with int and boolean types
00:23seancorfieldand i wanted to be able to set them dynamically, mapping :auto-connect-retry true to the autoConnectRetry boolean field
00:23seancorfieldi got the Field (easy) but couldn't use .set because that only works for non-primitive fields
00:24seancorfieldso I got the (primitive) type of the field and got the setter name (setInt, setBoolean) and tried to dynamically invoke that using .invoke method field object-array
00:25seancorfieldbut i couldn't get it to work... kept failing to convert the now object value down to the primitive for the typed setter
00:26seancorfieldin the end i copped out and wrote wrappers for .setInt and .setBoolean and just called those on the Field instead
00:26seancorfieldfor the amount of effort, i might as well have just written wrappers for all of the MongoOptions fields!
00:44zvrbathe joy of clojure book says that javadoc function is automatically available in core
00:44zvrbaas of version 1.2. yet, it is not. {:major 1, :minor 2, :incremental 1, :qualifier ""}
00:44zvrbathe interpreter says "unable to resolve symbol"
00:46seancorfield,(doc javadoc)
00:46clojurebotTitim gan éirí ort.
00:47seancorfield&(doc javadoc)
00:47lazybotjava.lang.Exception: Unable to resolve var: javadoc in this context
00:47seancorfield&(doc clojure.java.javadoc/javadoc)
00:47lazybotjava.lang.Exception: Unable to resolve var: clojure.java.javadoc/javadoc in this context
00:48seancorfieldwhen i did (doc javadoc) in the REPL, that's where it said it was
00:48zvrbahmm?
00:48seancorfieldand typing (javadoc java.lang.Thread) in the REPL takes me to the Java 6 page for Thread
00:49seancorfieldzvrba: how are you you running "the interpreter"?
00:49zvrbai'm running REPL within emacs. started with clojure-jack-in
00:50zvrbai created a dummy project with leiningen just for that
00:50zvrba(as the docs say clojure-jack-in must be run from within a project)
00:50seancorfieldi just fired up a bare REPL like this: java -cp clojure-1.2.1.jar clojure.main
00:50seancorfieldit found javadoc just fine
00:50seancorfieldand it finds it when i do lein repl as well
00:50seancorfieldbut i'm not familiar with emacs
00:51zvrbait works from lein repl too
00:52zvrba(it returns just an URL string)
00:52seancorfieldit should open a browser to that URL
00:52seancorfieldat least, that's what it does for me :)
00:53zvrbaoh, it did that too
00:53zvrbaopened a new tab in an opera window
01:03seancorfieldi just tried a REPL in Eclipse with CCW and it works just fine there (it even managed to open a browser window which surprised me)
01:03seancorfieldso it's something about emacs and clojure-jack-in i suspect
01:22jimblomoshould I prefer binding to with-bindings unless I already have a map of Vars?
01:37amalloyyes, i think the only reason to use with-bindings is if you have var objects instead of their names
01:39amalloy(having just used with-bindings a bunch recently and not really liked it :P)
01:47sridthe joy of clojure <- this is how programming books should be written.
02:24jimblomois there a way to programatically create namespaces such that they can be (use) or (required)?
02:25amalloy&(doc create-ns)
02:25lazybot⇒ "([sym]); Create a new namespace named by the symbol if one doesn't already exist, returns it or the already-existing namespace of the same name."
02:25jimblomoso in the repl, I created a namespace
02:25jimblomobut I still couldn't (use) or (require) it.. hmm maybe i'll try refer
02:26amalloyrefer is the only one that's definitely wrong
02:26amalloyyou should probably clarify what you actually did, because you've described something that in theory should work
02:26jimblomouser=> (create-ns 'my.new.namespace)
02:26jimblomo#<Namespace my.new.namespace>
02:26jimblomouser=> (use 'my.new.namespace)
02:26jimblomouser=> java.io.FileNotFoundException: Could not locate my/new/namespace__init.class or my/new/namespace.clj on classpath: (NO_SOURCE_FILE:0)
02:27amalloyah. well, you've created it, so it's already loaded
02:27amalloyyou don't have to require it
02:28jimblomooh i see, so i can refer to it straight out
02:32jimblomothen i can use intern to set new Vars
02:33amalloysure
02:33amalloythough if you're doing it programmatically and want to use intern, you don't need to refer
02:33amalloyrefer is only a convenience for the programmer
02:33amalloyjimblomo: ^
02:34jimblomoyea, i was thinking of how a user of my library would refer to the namespace
02:34jimblomootherwise it would just be magically available.
05:40thorwilis there a variant of assoc that works on vectors and takes an update fn instead of a value?
05:43triyoWhen reiterating over a binding in Clojure like so: file-lst* (map manip-fn file-lst) ... the asterisk seems to be the common practice. As I continue doing this, do I keep appending asterisks?
05:44triyoLike in Haskell, its common practice just to keep appending single quotes like so file-lst' ... file-lst'', file-lst'''
05:45triyoIts in the cases where giving it a unique name is meaningless.
05:50thorwiltriyo: i thought the asterisk thing in clojure is rather to add an asterisk to functions that are "raw", to then write wrappers of the same name, without *
05:51triyoI think you are right. I've gotten back in to working with clojure few days ago and had a gap for over a year
05:52triyoso can't remember, or don't know some common practice.
05:53triyoSo as far as you know, what is the common way to do this? You have a sequence that you need to make a few passes, what name do you bind the returned result to?
05:53thorwiltriyo: you had a need to split a vector based on predicate yesterday, right? have a look at http://paste.pocoo.org/show/454088/
05:54triyothorwil: thanks for the link. On my second iteration of the implementation though, I managed to do without the split at all with a single pass.
05:55thorwiltriyo: no shame in adding -1, -2 ... or calling them a b c, though i would try to not handle any inbetween step explicitly
05:55thorwiltriyo: if your passes are fns of the same arity, how about using comp?
05:57thorwilor simply (-> x fn1 fn2 fn3)
05:58triyoThinking about your last comment, however its not functions, its bindings on (let [...
05:59triyoI could make them functions but there is abs no reuse required so an imperative, seqential, flow will do
06:00triyo*so a sequential flow will do
06:00triyo(let [parts (map ...) parts' (filter f parts)] ...)
06:04triyothorwil: btw, that implementation of filter-split is much better than the commons lib one ;)
06:04triyosingle pass on vector as expected
06:05thorwilheh, i do not know another implementation
06:06shtutgartI've just installed MongoDB and congomongo, enter this http://paste.org.ru/?gqz90o in the repl... and got NPE! Frustration!
06:07shtutgartWhat the hell is wrong with that code? It's from congomongo github page!
06:07triyohehe would have been a bit more useful than npe
06:07triyodo you have the stack trace?
06:08shtutgartyes, sir: http://paste.org.ru/?4n99za
06:09triyoyou running a particular version or latest source ver form github?
06:09shtutgart0.1.7-SNAPSHOT, which is latest version on clojars.
06:09triyocool
06:09triyolet me have a look quick
06:12shtutgartClojure is 1.2, if it makes sense.
06:15triyoshtutgart: this is an NPE at driver level as far as I can tell.
06:15triyoDo yo have any MongoDB log by any chance?
06:16shtutgartnothing in the console output...
06:17triyook, so mongo db instance is running though? :)
06:18shtutgartyeah, it running and /bin/mongo works well, i mean - nothing suspicious
06:18triyoHave you tried `fetch` ?
06:18triyojust wan't to narrow the problem down
06:19shtutgartIt looks like all commands (but mogno!) throwing npe
06:20triyook, thought it might. One sec.
06:22triyoOk I know its IOException related
06:22triyoon the driver side.
06:23triyoDo you know what version of mongo java driver you running?
06:23triyocheck /lib dir if you running leiningen
06:24triyo2.6.3
06:24triyoI checked the project.clj of congomongo prject
06:26triyohehe
06:26triyoI can see the problem
06:26shtutgarthm, if io, maybe it's something stupid, like, i've db running on different port? although i'd expect congomongo has the same defaults as mongo itself, but nobody can guarantee that, right? let me check it...
06:26triyoYUP
06:26triyobut
06:26triyowait, there is more ;)
06:27triyothat driver that is used by congomongo, 2.6.3, has a bug in _error method :)
06:28triyohttps://github.com/mongodb/mongo-java-driver/blob/r2.6.3/src/main/com/mongodb/DBTCPConnector.java#L287
06:28triyothat first line doesn't check for null, which it can be, on _rsStatus
06:29triyoNow, the master, 2.7.0-pre -> https://github.com/mongodb/mongo-java-driver/blob/master/src/main/com/mongodb/DBTCPConnector.java#L295
06:29triyoFixed
06:29triyoThat gives you a clue I think
06:30shtutgartwow, cool!
06:30triyoServer is not listening
06:30triyoor as you said on wrong port
06:30triyoI'll file a quick ticket on congomongo peoject
06:30triyoto switch to 2.7.0 when its viable
06:31shtutgartyeah, it's a good idea
06:33shtutgartso, thank you so much for finding out the problem!
06:34shtutgartbut, hm, port is 27017 on both sides...
06:38triyoThis is the problem, I think you could get a nice stack-trace depicting the actual exception if it wasn't for the NPE
06:38triyoI filed the bug: https://github.com/aboekhoff/congomongo/issues/30
06:39triyoFor now, need to get a bit creative.
06:39triyo:)
06:39triyoOk is your mongo db on same server?
06:39triyosame host
06:40triyowhats the hostname in your config?
06:40triyolocalhost, 127.0.0.1?
06:44triyowhats the hostname in your config?
06:44shtutgarttriyo: I've just restarted db and now all works perfectly. Thank you again :)
06:44triyonp
09:01sirnIf I have a vector like: [[(1 "a" "b") (2 "a" "b")] [(3 "a" "b") (4 "a" "b")] [(5 "a" "b") (6 "a" "b")]], what's the best way to convert it into [(1 "a" "b") (2 "a" "b") (3 "a" "b") (4 "a" b") (5 "a" "b") (6 "a" "b")] ?
09:03leonid,(apply concat [[(1 "a" "b") (2 "a" "b")] [(3 "a" "b") (4 "a" "b")] [(5 "a" "b") (6 "a" "b")]])
09:03clojurebot#<ClassCastException java.lang.ClassCastException: java.lang.Long cannot be cast to clojure.lang.IFn>
09:03leonidhah
09:04leonid,(apply concat [['(1 "a" "b") '(2 "a" "b")] ['(3 "a" "b") '(4 "a" "b")] ['(5 "a" "b") '(6 "a" "b")]])
09:04clojurebot((1 "a" "b") (2 "a" "b") (3 "a" "b") (4 "a" "b") (5 "a" "b") ...)
09:05sirnleonid: Awesome. Thanks!
09:05shtutgartsirn: flatten
09:05shtutgartah, no, leonid is right. :)
09:05sirnshtutgart: flatten will make it [1 "a" "b" 2 "a" "b" ...] isn't it?
09:05lucianshtutgart: flatten is recursive
09:05shtutgartyeah
09:08sirn,(time (apply concat [(range 10) (range 10)]))
09:08clojurebot"Elapsed time: 0.131 msecs"
09:08clojurebot(0 1 2 3 4 ...)
09:08sirn,(time (flatten [(range 10) (range 10)]))
09:08clojurebot"Elapsed time: 0.223 msecs"
09:08clojurebot(0 1 2 3 4 ...)
09:08luciansirn: huh?
09:09sirnlucian: just getting curious
09:09lucianis apply just slow?
09:10Bronsais there a way to load a file into a string in clojurescript?
09:10lucianBronsa: likely slurp
09:16leonid,(time (apply concat [(range 10) (range 10)]))
09:16clojurebot"Elapsed time: 0.132 msecs"
09:17clojurebot(0 1 2 3 4 ...)
09:17leonid,(time (mapcat identity [(range 10) (range 10)]))
09:17clojurebot"Elapsed time: 0.181 msecs"
09:17clojurebot(0 1 2 3 4 ...)
09:17shtutgarthave someone tried to write desktop gui apps in clojurescript?
09:18shtutgart*has
11:40crazyFoxis there a way to read past conversations? are they logged somehow?
11:41ScriptorcrazyFox: this one, I think http://clojure-log.n01se.net/
11:45crazyFoxScriptor: thx!
12:03ericbmerrittI am wondering if someone might be able to help me out with a couple of clojurescript questions this morning.
12:13gtrakhow do you open a file from the classpath with java.io.file? it doesn't seem to find it. (.exists (file "static/js/hello.js")) always returns false, and the file exists at lein project root/resources/static/js/hello.js
12:15gtrakit finds it at "resources/static/js/hello.js", but that'd be hard-coding
12:16gtrakI think it would break if I had to deploy in a WAR
12:20thorwilgtrak: isn't that what the resource function is good for?
12:21gtrakah, hmm, I'll try it
12:24gtrakworks great, except it fails when there's a leading slash, is there a quick shortcut to fix that so I don't have to build two paths?
12:44raekgtrak: the path you give to 'resource' should not have a leading slash
12:45raektrying to find where this is documented
12:46raekalso, clojure.java.io/resource returns nil when the resource file does not exist
12:47raekresource paths always use / as the separator, regardless of the separator of the OS
12:48raekah, here: http://download.oracle.com/javase/7/docs/technotes/guides/lang/resources.html
12:58gtrakraek, ah, thanks, I'm translating some code over from using spring's ClassPathResource, I think they adjust for that
13:00gtrakbut I have to say, I thought I was going to miss spring and DI, but clojure is so much more powerful without the magic
13:31crazyFoxgiven a large map with numeric (and distinct) values. what would be a good way to find the one *map entry* with the greatest value?
13:33crazyFox(large map meaning: 1 million entries)
13:34jimblomomax-key unless your map is sorted
13:38crazyFox,(apply max-key #(val %) (seq {:c 1 :b 2 :a 3}))
13:38clojurebot[:a 3]
13:38crazyFoxit does the job. nice. thx
13:42jimblomonp. maps will auto matically be seq'd, and val is already a function, so you can probably do
13:43jimblomo,(apply max-key val {:c 1 :b 2 :a 3})
13:43clojurebot[:a 3]
13:47theignoratiis there an opposite of select-keys?
13:49jweissis there a simple or recommended way of having multiple agents work off of a single queue? I looked at java's Executors, but doesn't give any way I can find of specifying a per-thread setup/teardown
13:49crazyFoxjimblomo: yeah, thats better
14:03jimblomotheignorati: dissoc, if you really need the seq, (apply dissoc ...)
14:05jimblomojweiss: PriorityBlockingQueue may help
14:07jweissjimblomo: how do the agents pull items off the queue? (or some other thread figure out which agents are free and send work to them)?
14:07jweissi don't see any way to check if an agent is busy
14:14pschorfI am having an odd macro issue...if an argument is a class name, it does not seem to be unquoted
14:14pschorffor instance, (mac "string") works, but (mac String) will fail because it treats the argument like a clojure.lang.Symbol
14:19gtrakwhat's the right way to do namespace configuration in clojure? I kind of miss spring's placeholder @Value annotations
14:21gtrakyou can't really configure them from outside without making it stateful, right?
14:24gtrakfor instance say I want a cache that lives in a var to be off for development, the ns has to lookup the constant somewhere else, or I can pass it as a parameter to a function, or I make it become stateful via a init() method
14:25pschorfi have a better version of the question, how do i do something like ~@(repeat ~n nil)?
14:37thorwilpschorf: i guess you could give a name to the (repeat ~n nil) in a let and then ~@name
14:39pschorfthorwil: i thought of that, but I had an "unambe to resolve symbol foo# in this context"
14:43pschorfugh
14:43pschorfso, this works
14:44pschorf~@(repeat (eval `(~n)) nil)
14:44clojureboteval is DENIED
14:44pschorfbut it feels so dirty
14:47thorwilpschorf: (defmacro nils [n] (let [x# (repeat n nil)] `(print ~@x#))) ?
14:48pschorfthe issue is, it fails if i do something like
14:48pschorf(def foo 4)
14:48pschorf(nils foo)
14:51thorwiloh, it's completely beyond me why
14:52pschorfthe reason it came up was the macro needs to operate on classes, but for some reason java.util.List is a Symbol instead of a class in the macro
14:55thorwilfixed: (defmacro nils [n] (let [x# (repeat (eval n) nil)] `(print ~@x#)))
14:56pschorfis that acceptable? i wasn't sure eval was super evil in clojure
14:57thorwilpschorf: eval is fine as long as you control what is being fed to it
14:57pschorfkk
14:57pschorfthanks
14:58thorwilnp. clearly i have to work on my mental model of evaluation :)
14:58pschorfi know...this is my second macro ever, and I feel like taking a nap after writing it
15:01thorwilif you pastebin it, someone might have a look at it and suggest improvement
15:05pschorfany ideas to clean this up? http://pastebin.com/b2Hca9eU
16:36Raynesamalloy: Must have been some downtime today.
16:37Raynesamalloy: 4clojure is dead too.
20:53JarredI don't understand why there are so many parentheses
20:53Jarred(in Clojure)
20:53Jarredbut I also don't understand Lisp-style coding
20:54scottjJarred: what have you done to understand?
20:55Jarredscottj Not enough
20:56amalloystyle points for (in clojure)
21:02leonidrofl
21:02amalloyJarred: a reasonable summary is that you have to have *some* punctuation (even pyhton's meaningful whitespace)
21:02amalloylisp chooses parenthesis and prefix notation because it's very easy to manipulate code in macros
21:04icey_Jarred: I think if you were to compare code with a C-like language (Java, C++, C#, etc) that the amount of parenthesis and brackets are pretty similar
21:05icey_Jarred: i.e. function test() {body} vs (defn test [] body)
21:08JarredYeah, but those are separated via whitespace
21:08Jarredamalloy Ah I see
21:09scottjicey: I think that argument fails once arithmetic, assignment, and member access are considered
21:09amalloyscottj: i mostly agree, but arithmetic is a wash
21:09amalloy(+ 1 2) is longer than 1 + 2, but (+ 1 2 3 4 5 6) is a lot nicer than 1 + 2 + 3 + 4 + 5 + 6
21:09clojurebot#<RuntimeException java.lang.RuntimeException: java.lang.NumberFormatException: For input string: "+">
21:10leonidwhat triggered clojurebot?
21:11leonid(+ 1 2)
21:11clojurebot3
21:11amalloyhe's a lunatic. don't worry about him
21:11leonidah i didn't know I could omit the ,
21:11amalloyJarred: i wrote an article at http://hubpages.com/hub/What-is-Clojure some time ago. the main focus is really on lispiness, not clojure specifically, so you might find it useful
21:12wastrelhi
21:12scottja += 2/b.c++ vs (def a (+ (/ 2 (inc (:c b)))) for example
21:12wastrel(:c b)
21:12wastrellooks like an emoticon
21:13amalloyscottj: except those two expressions differ in other ways
21:14amalloyyou're mutating a (intentionally), and (unintentionally, i'm just guessing) b.c
21:15amalloyand you left out the second occurrence of a in the clojure version
21:15ibdknoxFor any Noir users out there, I created a middleware to compile your cljs code on refresh: https://github.com/ibdknox/noir-cljs
21:15scottjamalloy: yeah, I was just trying to show the things I was talking about (assignment, arithmetic, member access) in quick way
21:15amalloyi guess. i think your code is a great example of how parentheses clarify things
21:15amalloybecause there are at least three weird gotchas in the infix version
21:16iceyscottj: I get your point when talking about a specific operation, but lisp makes up ground by not needing parens for method calls (for example)... my point is just that it doesn't seem like there are significantly more parens / brackets in c-like code than lisp
21:16scottjI don't dispute that, just that the 1 to 1 stu and others like to point out really only applies to function calls and maybe class defs
21:17iceyi always thought infix notation would be a bigger sticking point than # of parens; it's weird that people are still talking about parens when most editors make them a non-issue
21:17amalloyyeah, i guess thinkig about any nontrivial code i've written, it has a lot more grouping operators in clojure than it would in java
21:17amalloyicey: i think people *believe* they care about number of parens, but what really bugs them is depth of parens
21:18iceyamalloy: I think you're right; but don't you think it's odd that you don't see many complaints about "end end end end end end" in ruby or "});}});});});}" in javascript?
21:20amalloynot being a ruby user myself, i doubt you see "end" seven times in a row anywhere near as often as you see ))}))))}])) in clojure
21:20iceyamalloy: yeah, that's fair
21:20scottjthe js case is not that much of an exaggeration though
21:21amalloyscottj: yeah, i carefully picked on the ruby example :)
21:21scottjI think other languages name intermediate steps more often
21:22amalloyi remember seeing a clojure user object to java's anonymous classes with something like "seeing );}}()); is a sure sign of a diseased language"
21:22amalloyseemed a bit hypocritical
21:22scottjactually since naming doesn't require parens and in coffeescript you don't need parens for function calls or objects, you could probably write it paren free
21:23iceyibdknox: noir-cljs looks like it will be a pretty nice time-saver
21:23ibdknoxicey: I hope so :)
21:24ibdknoxalso if you're doing cljs
21:24iceyibdknox: i'm hoping to dip my toes into some ClojureScript later this week, I'll probably use this to do it (so I don't forget to recompile)
21:24ibdknoxit's worth checking out pinot https://github.com/ibdknox/pinot
21:24amalloyhah, pinot
21:24ibdknox:D
21:24iceyibdknox: dude. that looks awesome
21:25ibdknoxyou can do some really cool stuff with hiccup generating actual dom objects
21:25ibdknoxamalloy: is there really any other name I could've used?
21:25ibdknoxamalloy: hehe
21:25iceyibdknox: i spent some time earlier today reading up on google closure's templates; i'm happy to not need to use them haha
21:26ibdknoxyeah.. the entire goog library hurts me a bit :(
21:26ibdknoxwith wonderful functions like goog.dom.getElementsByTagNameAndClass
21:26iceyibdknox: is there a way to get access to the request headers from inside defpage?
21:27amalloyibdknox: well, noir makes me think of film noir, not of wine
21:27ibdknoxicey: intentionally no
21:27ibdknoxamalloy: yeah, the running joke was that it should've been blanc
21:27iceyibdknox: interesting - why intentionally no??
21:28ibdknoxamalloy: I'm not sure what I could've done related to film noir that would make a good name
21:28amalloyi don't know either
21:28ibdknoxicey: chances are if you need it, you should be writing middleware :)
21:28ibdknoxicey: what's your usecase?
21:28iceyibdknox: haha, fair enough; i was just curious
21:29iceyibdknox: getting the user-agent string server-side. it's not a big deal, for this i'm just using compojure since it's a single-serve app
21:30iceyibdknox: i.e. I don't have a need for it in noir... I was just curious if there was a way to do it that i missed :)
21:30ibdknoxicey: gotcha :) You have access to the full request in pre-routes and middleware
21:31xiaolongxiaibdknox: actually i have a pretty elementary question about javascript interop using goog libraries ...
21:31ibdknoxxiaolongxia: shoot
21:31xiaolongxiahttps://gist.github.com/1131051
21:31ibdknoxthat is an epic list
21:31xiaolongxiai'm trying to make this more idiomatic in clojure, that works though
21:32xiaolongxiathat's a direct port from the URL in the description
21:33xiaolongxiaso obviously (let [buttons (vector (. goog.editor.Command BOLD))] (...))
21:33xiaolongxiawould work
21:33xiaolongxiabut I'm not familiary enough with interop in clojure
21:34xiaolongxiato understand how to go from ["BOLD" "ITALIC" .. ] to an interop compatible name(?)
21:34ibdknoxah
21:34ibdknoxso this is particularly tricky in CLJS right now
21:34xiaolongxiaah
21:34ibdknoxthe best way to do it
21:34ibdknoxis with aget
21:34ibdknox(aget goog.editor.Command "BOLD")
21:34xiaolongxiahuh
21:35ibdknoxI do it in pinot for event lookup
21:35ibdknoxhttps://github.com/ibdknox/pinot/blob/master/src/pinot/events.cljs#L18
21:36ibdknoxtook me a while to get to that though :/
21:36ibdknoxlol
21:37xiaolongxialet is throwing a stacktrace, i'll have to keep playing with it
21:37xiaolongxiabut i see what your code is doing
21:37xiaolongxiathanks
21:37ibdknoxnp
21:37xiaolongxiai had never messed with the goog libraries before
21:38xiaolongxiabut in general, the UI library is pretty nice
21:38ibdknoxyeah, I'm sure their "controls" are probably ok to work with
21:39scottjis there a simple way to not have everything look like google? without recssing everything manually
21:39ibdknoxhah
21:39ibdknoxwhy wouldn't you want to look like google? They're so successful! ;)
21:40xiaolongxiascottj: what is it you don't want to look "googly" ?
21:40ibdknoxSadly, I don't think so, if you look around you can find some CSS people have already written to make some things look prettier
21:40xiaolongxiai'll i'm really interested in is the editor, and that looks like most other well done editors
21:40ibdknoxbut even that seems to be sparse
21:54emacsenwith cljscript, how does one interface with an existing js library?
21:56xiaolongxiaala https://gist.github.com/1096382
21:56ibdknoxeh
21:56ibdknoxyou shouldn't use js*
21:56ibdknoxanything in the global js namespace can be accessed through js/
21:56ibdknoxjs/alert
21:56xiaolongxiaah!
21:56emacsenxiaolongxia, thx. ibdknox okay, then I need to rewrite whatever I want to use?
21:56xiaolongxiathanks
21:57ibdknoxemacsen: huh?
21:57emacsenibdknox, so let's say I want to make a complex app. And I want to leverage something like paper.js
21:58emacsenare you saying don't do it?
21:58ibdknoxno? I said don't use the js* function :-p
21:58ibdknox:)
21:58emacsenah. So what's the right way?
21:58ibdknoxthe example that was given in that gist
21:58ibdknoxuses (js* "$")
21:59emacsenibdknox, okay.
21:59ibdknoxyou use the js namespace: (js/JQuery "blah")
21:59ibdknoxthough that likely won't do what you expect once you turn on advanced optimization :(
22:00xiaolongxiaibdknox: ok, what am I doing wrong here? this results in an array of anon functions, but not anon function calls: http://pastebin.com/ZfrNQj8g
22:01ibdknoxare you sure the commands aren't functions themselves?
22:02ibdknoxif they're "classes" they would be
22:03amalloyxiaolongxia: you probably meant vec, not vector? though probably you don't need either
22:04xiaolongxiahttp://pastebin.com/yK2jR8qn
22:04amalloywell...yes? that's what those say to do
22:05amalloyi wasn't trying to trick you when i said to use vec, not vector
22:05xiaolongxiaamalloy: i wrot that paste before you said that ...
22:05xiaolongxiai'm trying to understand why the map doesn't work
22:06amalloyit works fine
22:06xiaolongxiano ... it doesn't
22:06amalloythough a (for) would be clearer
22:06amalloythe problem is that you're creating a one-element vector, which contains a list of buttons
22:07xiaolongxiaok, so it was vec vs vector
22:07ibdknoxyeah
22:12fbru02hey ! is there any function that is the same as doing first a map and then a reduce
22:12fbru02?
22:16zmarilPardon me, I am working through Joy of Clojure and have gotten fairly stuck. I am trying to get the a* search example to work but every time I try to run the function it says that there is an error in the compare library.
22:16zmarilHere is the gist: https://gist.github.com/1131095
22:20amalloyfbru02: you could write that function yourself in fewer characters than it takes to ask about it, so probably nobody's bothered
22:21fbru02amalloy: makes sense :)
22:26xiaolongxiaamalloy, ibdknox: thanks for your help. won't get any further than this for now, but it runs: https://gist.github.com/1131051
22:27ibdknoxxiaolongxia: any time :)
23:01jsnikerisSuppose I have a sorted sequence, and I want to know what is the next item in that sequence after a given item. So (f [1 3 5 9] 5) -> 5. Is there a better way to do this than to find the index of n, and then traverse the list again to find the next item after n? In Java, I'd use an iterator, but not sure what to do in clojure. Any ideas?
23:02jsnikerisMy example should return 9...
23:09fullets(fn [vs n] (first (filter #(> % n) vs)))
23:09fulletsNot sure how idiomatic that is
23:10jsnikerisfullets: works for numbers. I just came up with:
23:10jsnikeris,(second (drop-while #(not= 5 %) [0 3 5 8]))
23:10clojurebot8
23:11jsnikerisstill kinda ugly though
23:11leonidis your sequence nondecreasing, or increasing?
23:11jsnikerisincreasing
23:11jsnikeriswell, decreasing
23:13jsnikerisWhat do you mean by nondecreasing?
23:13leonidby that i mean the sequence has duplicate elements
23:13fullets[1 2 3 4] increasing, [1 2 2 3 3 4] nondecreasing
23:13jsnikerisOh, gotcha. No duplicates
23:14jsnikerisIts actually a sequence of blog entries, sorted by publication date.
23:14jsnikerisBut that's neither here nor there
23:15leonidfullet's solution looks good enough
23:16fulletsIf you want if for comparables in general, you could use the compare fn rather than >
23:17jsnikerisOK, thanks for the help guys
23:18leonidi'm surprised there's no built-in function that does find-first
23:18bortrebhow about (find-first (partial < 5) [1 2 3 4 5 6])
23:18bortrebusing clojure.contrib.seq/find-first
23:19fulletsbortreb: well spotted :)
23:19jsnikeriseven named the same!
23:19leonidoh didn't know we could use contrib functions
23:20Scriptoris this for 4clojure?
23:20jsnikerisYes
23:28amalloyjsnikeris: if you have an actual sorted-set/map instead of a vector, you can use ##(doc subseq)
23:28lazybot⇒ "([sc test key] [sc start-test start-key end-test end-key]); sc must be a sorted collection, test(s) one of <, <=, > or >=. Returns a seq of those entries with keys ek for which (test (.. sc comparator (compare ek key)) 0) is true"
23:30amalloyand of course if you want to *keep* it sorted, you should be using a sorted-map/set
23:40jsnikerisso right now, I've got a function called get-entries that grabs a bunch of blog entries off the disk, and returns a sequence of entries (maps). My idea was to sort this sequence before returning it, so I could use it when calling (next-entry entry) and (prev-entry entry). Also, once I got everything working I would have get-entries cache the entries. What do you think about this approach?
23:41amalloya sorted set (or map) still makes more sense to me
23:41jsnikerissorted-set wouldn't know how to sort these maps though
23:42amalloy&(doc sorted-set-by)
23:42lazybot⇒ "([comparator & keys]); Returns a new sorted set with supplied keys, using the supplied comparator."
23:42jsnikerisaha
23:42amalloySHAZAM
23:42jsnikerisLOL
23:42jsnikerisliterally
23:42jsnikerisnice
23:44amalloyspeaking of which, am i the only one who thinks ##(doc comparator) is a lot less useful than something that turns a key-function (as in max-key) into a comparator?
23:44lazybot⇒ "([pred]); Returns an implementation of java.util.Comparator based upon pred."
23:49jsnikerisCould you give me an example of max-key in use?
23:51amalloy&(max-key :x {:x 1 :y 2}, {:x 10 :y 5})
23:51lazybot⇒ {:x 10, :y 5}
23:55jsnikerisAh, ok.
23:58jsnikerisSometimes the docs are so terse I struggle to understand how a fn is used. And then, once I figure it out, I'm like oh, yah, that's a perfect explanation of how it works.
23:58jsnikeriswhat it does, rather