2011-08-07
| 00:21 | seancorfield | on the subject of reflection... i was trying (and failing) to call setter on a Field the other day |
| 00:22 | seancorfield | i was working with the MongoOptions object - which is a class with all public fields with int and boolean types |
| 00:23 | seancorfield | and i wanted to be able to set them dynamically, mapping :auto-connect-retry true to the autoConnectRetry boolean field |
| 00:23 | seancorfield | i got the Field (easy) but couldn't use .set because that only works for non-primitive fields |
| 00:24 | seancorfield | so 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:25 | seancorfield | but i couldn't get it to work... kept failing to convert the now object value down to the primitive for the typed setter |
| 00:26 | seancorfield | in the end i copped out and wrote wrappers for .setInt and .setBoolean and just called those on the Field instead |
| 00:26 | seancorfield | for the amount of effort, i might as well have just written wrappers for all of the MongoOptions fields! |
| 00:44 | zvrba | the joy of clojure book says that javadoc function is automatically available in core |
| 00:44 | zvrba | as of version 1.2. yet, it is not. {:major 1, :minor 2, :incremental 1, :qualifier ""} |
| 00:44 | zvrba | the interpreter says "unable to resolve symbol" |
| 00:46 | seancorfield | ,(doc javadoc) |
| 00:46 | clojurebot | Titim gan éirí ort. |
| 00:47 | seancorfield | &(doc javadoc) |
| 00:47 | lazybot | java.lang.Exception: Unable to resolve var: javadoc in this context |
| 00:47 | seancorfield | &(doc clojure.java.javadoc/javadoc) |
| 00:47 | lazybot | java.lang.Exception: Unable to resolve var: clojure.java.javadoc/javadoc in this context |
| 00:48 | seancorfield | when i did (doc javadoc) in the REPL, that's where it said it was |
| 00:48 | zvrba | hmm? |
| 00:48 | seancorfield | and typing (javadoc java.lang.Thread) in the REPL takes me to the Java 6 page for Thread |
| 00:49 | seancorfield | zvrba: how are you you running "the interpreter"? |
| 00:49 | zvrba | i'm running REPL within emacs. started with clojure-jack-in |
| 00:50 | zvrba | i created a dummy project with leiningen just for that |
| 00:50 | zvrba | (as the docs say clojure-jack-in must be run from within a project) |
| 00:50 | seancorfield | i just fired up a bare REPL like this: java -cp clojure-1.2.1.jar clojure.main |
| 00:50 | seancorfield | it found javadoc just fine |
| 00:50 | seancorfield | and it finds it when i do lein repl as well |
| 00:50 | seancorfield | but i'm not familiar with emacs |
| 00:51 | zvrba | it works from lein repl too |
| 00:52 | zvrba | (it returns just an URL string) |
| 00:52 | seancorfield | it should open a browser to that URL |
| 00:52 | seancorfield | at least, that's what it does for me :) |
| 00:53 | zvrba | oh, it did that too |
| 00:53 | zvrba | opened a new tab in an opera window |
| 01:03 | seancorfield | i 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:03 | seancorfield | so it's something about emacs and clojure-jack-in i suspect |
| 01:22 | jimblomo | should I prefer binding to with-bindings unless I already have a map of Vars? |
| 01:37 | amalloy | yes, i think the only reason to use with-bindings is if you have var objects instead of their names |
| 01:39 | amalloy | (having just used with-bindings a bunch recently and not really liked it :P) |
| 01:47 | srid | the joy of clojure <- this is how programming books should be written. |
| 02:24 | jimblomo | is there a way to programatically create namespaces such that they can be (use) or (required)? |
| 02:25 | amalloy | &(doc create-ns) |
| 02:25 | lazybot | ⇒ "([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:25 | jimblomo | so in the repl, I created a namespace |
| 02:25 | jimblomo | but I still couldn't (use) or (require) it.. hmm maybe i'll try refer |
| 02:26 | amalloy | refer is the only one that's definitely wrong |
| 02:26 | amalloy | you should probably clarify what you actually did, because you've described something that in theory should work |
| 02:26 | jimblomo | user=> (create-ns 'my.new.namespace) |
| 02:26 | jimblomo | #<Namespace my.new.namespace> |
| 02:26 | jimblomo | user=> (use 'my.new.namespace) |
| 02:26 | jimblomo | user=> java.io.FileNotFoundException: Could not locate my/new/namespace__init.class or my/new/namespace.clj on classpath: (NO_SOURCE_FILE:0) |
| 02:27 | amalloy | ah. well, you've created it, so it's already loaded |
| 02:27 | amalloy | you don't have to require it |
| 02:28 | jimblomo | oh i see, so i can refer to it straight out |
| 02:32 | jimblomo | then i can use intern to set new Vars |
| 02:33 | amalloy | sure |
| 02:33 | amalloy | though if you're doing it programmatically and want to use intern, you don't need to refer |
| 02:33 | amalloy | refer is only a convenience for the programmer |
| 02:33 | amalloy | jimblomo: ^ |
| 02:34 | jimblomo | yea, i was thinking of how a user of my library would refer to the namespace |
| 02:34 | jimblomo | otherwise it would just be magically available. |
| 05:40 | thorwil | is there a variant of assoc that works on vectors and takes an update fn instead of a value? |
| 05:43 | triyo | When 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:44 | triyo | Like in Haskell, its common practice just to keep appending single quotes like so file-lst' ... file-lst'', file-lst''' |
| 05:45 | triyo | Its in the cases where giving it a unique name is meaningless. |
| 05:50 | thorwil | triyo: 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:51 | triyo | I 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:52 | triyo | so can't remember, or don't know some common practice. |
| 05:53 | triyo | So 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:53 | thorwil | triyo: you had a need to split a vector based on predicate yesterday, right? have a look at http://paste.pocoo.org/show/454088/ |
| 05:54 | triyo | thorwil: 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:55 | thorwil | triyo: no shame in adding -1, -2 ... or calling them a b c, though i would try to not handle any inbetween step explicitly |
| 05:55 | thorwil | triyo: if your passes are fns of the same arity, how about using comp? |
| 05:57 | thorwil | or simply (-> x fn1 fn2 fn3) |
| 05:58 | triyo | Thinking about your last comment, however its not functions, its bindings on (let [... |
| 05:59 | triyo | I could make them functions but there is abs no reuse required so an imperative, seqential, flow will do |
| 06:00 | triyo | *so a sequential flow will do |
| 06:00 | triyo | (let [parts (map ...) parts' (filter f parts)] ...) |
| 06:04 | triyo | thorwil: btw, that implementation of filter-split is much better than the commons lib one ;) |
| 06:04 | triyo | single pass on vector as expected |
| 06:05 | thorwil | heh, i do not know another implementation |
| 06:06 | shtutgart | I've just installed MongoDB and congomongo, enter this http://paste.org.ru/?gqz90o in the repl... and got NPE! Frustration! |
| 06:07 | shtutgart | What the hell is wrong with that code? It's from congomongo github page! |
| 06:07 | triyo | hehe would have been a bit more useful than npe |
| 06:07 | triyo | do you have the stack trace? |
| 06:08 | shtutgart | yes, sir: http://paste.org.ru/?4n99za |
| 06:09 | triyo | you running a particular version or latest source ver form github? |
| 06:09 | shtutgart | 0.1.7-SNAPSHOT, which is latest version on clojars. |
| 06:09 | triyo | cool |
| 06:09 | triyo | let me have a look quick |
| 06:12 | shtutgart | Clojure is 1.2, if it makes sense. |
| 06:15 | triyo | shtutgart: this is an NPE at driver level as far as I can tell. |
| 06:15 | triyo | Do yo have any MongoDB log by any chance? |
| 06:16 | shtutgart | nothing in the console output... |
| 06:17 | triyo | ok, so mongo db instance is running though? :) |
| 06:18 | shtutgart | yeah, it running and /bin/mongo works well, i mean - nothing suspicious |
| 06:18 | triyo | Have you tried `fetch` ? |
| 06:18 | triyo | just wan't to narrow the problem down |
| 06:19 | shtutgart | It looks like all commands (but mogno!) throwing npe |
| 06:20 | triyo | ok, thought it might. One sec. |
| 06:22 | triyo | Ok I know its IOException related |
| 06:22 | triyo | on the driver side. |
| 06:23 | triyo | Do you know what version of mongo java driver you running? |
| 06:23 | triyo | check /lib dir if you running leiningen |
| 06:24 | triyo | 2.6.3 |
| 06:24 | triyo | I checked the project.clj of congomongo prject |
| 06:26 | triyo | hehe |
| 06:26 | triyo | I can see the problem |
| 06:26 | shtutgart | hm, 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:26 | triyo | YUP |
| 06:26 | triyo | but |
| 06:26 | triyo | wait, there is more ;) |
| 06:27 | triyo | that driver that is used by congomongo, 2.6.3, has a bug in _error method :) |
| 06:28 | triyo | https://github.com/mongodb/mongo-java-driver/blob/r2.6.3/src/main/com/mongodb/DBTCPConnector.java#L287 |
| 06:28 | triyo | that first line doesn't check for null, which it can be, on _rsStatus |
| 06:29 | triyo | Now, the master, 2.7.0-pre -> https://github.com/mongodb/mongo-java-driver/blob/master/src/main/com/mongodb/DBTCPConnector.java#L295 |
| 06:29 | triyo | Fixed |
| 06:29 | triyo | That gives you a clue I think |
| 06:30 | shtutgart | wow, cool! |
| 06:30 | triyo | Server is not listening |
| 06:30 | triyo | or as you said on wrong port |
| 06:30 | triyo | I'll file a quick ticket on congomongo peoject |
| 06:30 | triyo | to switch to 2.7.0 when its viable |
| 06:31 | shtutgart | yeah, it's a good idea |
| 06:33 | shtutgart | so, thank you so much for finding out the problem! |
| 06:34 | shtutgart | but, hm, port is 27017 on both sides... |
| 06:38 | triyo | This is the problem, I think you could get a nice stack-trace depicting the actual exception if it wasn't for the NPE |
| 06:38 | triyo | I filed the bug: https://github.com/aboekhoff/congomongo/issues/30 |
| 06:39 | triyo | For now, need to get a bit creative. |
| 06:39 | triyo | :) |
| 06:39 | triyo | Ok is your mongo db on same server? |
| 06:39 | triyo | same host |
| 06:40 | triyo | whats the hostname in your config? |
| 06:40 | triyo | localhost, 127.0.0.1? |
| 06:44 | triyo | whats the hostname in your config? |
| 06:44 | shtutgart | triyo: I've just restarted db and now all works perfectly. Thank you again :) |
| 06:44 | triyo | np |
| 09:01 | sirn | If 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:03 | leonid | ,(apply concat [[(1 "a" "b") (2 "a" "b")] [(3 "a" "b") (4 "a" "b")] [(5 "a" "b") (6 "a" "b")]]) |
| 09:03 | clojurebot | #<ClassCastException java.lang.ClassCastException: java.lang.Long cannot be cast to clojure.lang.IFn> |
| 09:03 | leonid | hah |
| 09:04 | leonid | ,(apply concat [['(1 "a" "b") '(2 "a" "b")] ['(3 "a" "b") '(4 "a" "b")] ['(5 "a" "b") '(6 "a" "b")]]) |
| 09:04 | clojurebot | ((1 "a" "b") (2 "a" "b") (3 "a" "b") (4 "a" "b") (5 "a" "b") ...) |
| 09:05 | sirn | leonid: Awesome. Thanks! |
| 09:05 | shtutgart | sirn: flatten |
| 09:05 | shtutgart | ah, no, leonid is right. :) |
| 09:05 | sirn | shtutgart: flatten will make it [1 "a" "b" 2 "a" "b" ...] isn't it? |
| 09:05 | lucian | shtutgart: flatten is recursive |
| 09:05 | shtutgart | yeah |
| 09:08 | sirn | ,(time (apply concat [(range 10) (range 10)])) |
| 09:08 | clojurebot | "Elapsed time: 0.131 msecs" |
| 09:08 | clojurebot | (0 1 2 3 4 ...) |
| 09:08 | sirn | ,(time (flatten [(range 10) (range 10)])) |
| 09:08 | clojurebot | "Elapsed time: 0.223 msecs" |
| 09:08 | clojurebot | (0 1 2 3 4 ...) |
| 09:08 | lucian | sirn: huh? |
| 09:09 | sirn | lucian: just getting curious |
| 09:09 | lucian | is apply just slow? |
| 09:10 | Bronsa | is there a way to load a file into a string in clojurescript? |
| 09:10 | lucian | Bronsa: likely slurp |
| 09:16 | leonid | ,(time (apply concat [(range 10) (range 10)])) |
| 09:16 | clojurebot | "Elapsed time: 0.132 msecs" |
| 09:17 | clojurebot | (0 1 2 3 4 ...) |
| 09:17 | leonid | ,(time (mapcat identity [(range 10) (range 10)])) |
| 09:17 | clojurebot | "Elapsed time: 0.181 msecs" |
| 09:17 | clojurebot | (0 1 2 3 4 ...) |
| 09:17 | shtutgart | have someone tried to write desktop gui apps in clojurescript? |
| 09:18 | shtutgart | *has |
| 11:40 | crazyFox | is there a way to read past conversations? are they logged somehow? |
| 11:41 | Scriptor | crazyFox: this one, I think http://clojure-log.n01se.net/ |
| 11:45 | crazyFox | Scriptor: thx! |
| 12:03 | ericbmerritt | I am wondering if someone might be able to help me out with a couple of clojurescript questions this morning. |
| 12:13 | gtrak | how 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:15 | gtrak | it finds it at "resources/static/js/hello.js", but that'd be hard-coding |
| 12:16 | gtrak | I think it would break if I had to deploy in a WAR |
| 12:20 | thorwil | gtrak: isn't that what the resource function is good for? |
| 12:21 | gtrak | ah, hmm, I'll try it |
| 12:24 | gtrak | works 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:44 | raek | gtrak: the path you give to 'resource' should not have a leading slash |
| 12:45 | raek | trying to find where this is documented |
| 12:46 | raek | also, clojure.java.io/resource returns nil when the resource file does not exist |
| 12:47 | raek | resource paths always use / as the separator, regardless of the separator of the OS |
| 12:48 | raek | ah, here: http://download.oracle.com/javase/7/docs/technotes/guides/lang/resources.html |
| 12:58 | gtrak | raek, ah, thanks, I'm translating some code over from using spring's ClassPathResource, I think they adjust for that |
| 13:00 | gtrak | but 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:31 | crazyFox | given 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:33 | crazyFox | (large map meaning: 1 million entries) |
| 13:34 | jimblomo | max-key unless your map is sorted |
| 13:38 | crazyFox | ,(apply max-key #(val %) (seq {:c 1 :b 2 :a 3})) |
| 13:38 | clojurebot | [:a 3] |
| 13:38 | crazyFox | it does the job. nice. thx |
| 13:42 | jimblomo | np. maps will auto matically be seq'd, and val is already a function, so you can probably do |
| 13:43 | jimblomo | ,(apply max-key val {:c 1 :b 2 :a 3}) |
| 13:43 | clojurebot | [:a 3] |
| 13:47 | theignorati | is there an opposite of select-keys? |
| 13:49 | jweiss | is 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:49 | crazyFox | jimblomo: yeah, thats better |
| 14:03 | jimblomo | theignorati: dissoc, if you really need the seq, (apply dissoc ...) |
| 14:05 | jimblomo | jweiss: PriorityBlockingQueue may help |
| 14:07 | jweiss | jimblomo: 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:07 | jweiss | i don't see any way to check if an agent is busy |
| 14:14 | pschorf | I am having an odd macro issue...if an argument is a class name, it does not seem to be unquoted |
| 14:14 | pschorf | for instance, (mac "string") works, but (mac String) will fail because it treats the argument like a clojure.lang.Symbol |
| 14:19 | gtrak | what's the right way to do namespace configuration in clojure? I kind of miss spring's placeholder @Value annotations |
| 14:21 | gtrak | you can't really configure them from outside without making it stateful, right? |
| 14:24 | gtrak | for 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:25 | pschorf | i have a better version of the question, how do i do something like ~@(repeat ~n nil)? |
| 14:37 | thorwil | pschorf: i guess you could give a name to the (repeat ~n nil) in a let and then ~@name |
| 14:39 | pschorf | thorwil: i thought of that, but I had an "unambe to resolve symbol foo# in this context" |
| 14:43 | pschorf | ugh |
| 14:43 | pschorf | so, this works |
| 14:44 | pschorf | ~@(repeat (eval `(~n)) nil) |
| 14:44 | clojurebot | eval is DENIED |
| 14:44 | pschorf | but it feels so dirty |
| 14:47 | thorwil | pschorf: (defmacro nils [n] (let [x# (repeat n nil)] `(print ~@x#))) ? |
| 14:48 | pschorf | the issue is, it fails if i do something like |
| 14:48 | pschorf | (def foo 4) |
| 14:48 | pschorf | (nils foo) |
| 14:51 | thorwil | oh, it's completely beyond me why |
| 14:52 | pschorf | the 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:55 | thorwil | fixed: (defmacro nils [n] (let [x# (repeat (eval n) nil)] `(print ~@x#))) |
| 14:56 | pschorf | is that acceptable? i wasn't sure eval was super evil in clojure |
| 14:57 | thorwil | pschorf: eval is fine as long as you control what is being fed to it |
| 14:57 | pschorf | kk |
| 14:57 | pschorf | thanks |
| 14:58 | thorwil | np. clearly i have to work on my mental model of evaluation :) |
| 14:58 | pschorf | i know...this is my second macro ever, and I feel like taking a nap after writing it |
| 15:01 | thorwil | if you pastebin it, someone might have a look at it and suggest improvement |
| 15:05 | pschorf | any ideas to clean this up? http://pastebin.com/b2Hca9eU |
| 16:36 | Raynes | amalloy: Must have been some downtime today. |
| 16:37 | Raynes | amalloy: 4clojure is dead too. |
| 20:53 | Jarred | I don't understand why there are so many parentheses |
| 20:53 | Jarred | (in Clojure) |
| 20:53 | Jarred | but I also don't understand Lisp-style coding |
| 20:54 | scottj | Jarred: what have you done to understand? |
| 20:55 | Jarred | scottj Not enough |
| 20:56 | amalloy | style points for (in clojure) |
| 21:02 | leonid | rofl |
| 21:02 | amalloy | Jarred: a reasonable summary is that you have to have *some* punctuation (even pyhton's meaningful whitespace) |
| 21:02 | amalloy | lisp chooses parenthesis and prefix notation because it's very easy to manipulate code in macros |
| 21:04 | icey_ | 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:05 | icey_ | Jarred: i.e. function test() {body} vs (defn test [] body) |
| 21:08 | Jarred | Yeah, but those are separated via whitespace |
| 21:08 | Jarred | amalloy Ah I see |
| 21:09 | scottj | icey: I think that argument fails once arithmetic, assignment, and member access are considered |
| 21:09 | amalloy | scottj: i mostly agree, but arithmetic is a wash |
| 21:09 | amalloy | (+ 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:09 | clojurebot | #<RuntimeException java.lang.RuntimeException: java.lang.NumberFormatException: For input string: "+"> |
| 21:10 | leonid | what triggered clojurebot? |
| 21:11 | leonid | (+ 1 2) |
| 21:11 | clojurebot | 3 |
| 21:11 | amalloy | he's a lunatic. don't worry about him |
| 21:11 | leonid | ah i didn't know I could omit the , |
| 21:11 | amalloy | Jarred: 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:12 | wastrel | hi |
| 21:12 | scottj | a += 2/b.c++ vs (def a (+ (/ 2 (inc (:c b)))) for example |
| 21:12 | wastrel | (:c b) |
| 21:12 | wastrel | looks like an emoticon |
| 21:13 | amalloy | scottj: except those two expressions differ in other ways |
| 21:14 | amalloy | you're mutating a (intentionally), and (unintentionally, i'm just guessing) b.c |
| 21:15 | amalloy | and you left out the second occurrence of a in the clojure version |
| 21:15 | ibdknox | For any Noir users out there, I created a middleware to compile your cljs code on refresh: https://github.com/ibdknox/noir-cljs |
| 21:15 | scottj | amalloy: yeah, I was just trying to show the things I was talking about (assignment, arithmetic, member access) in quick way |
| 21:15 | amalloy | i guess. i think your code is a great example of how parentheses clarify things |
| 21:15 | amalloy | because there are at least three weird gotchas in the infix version |
| 21:16 | icey | scottj: 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:16 | scottj | I 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:17 | icey | i 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:17 | amalloy | yeah, 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:17 | amalloy | icey: i think people *believe* they care about number of parens, but what really bugs them is depth of parens |
| 21:18 | icey | amalloy: 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:20 | amalloy | not 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:20 | icey | amalloy: yeah, that's fair |
| 21:20 | scottj | the js case is not that much of an exaggeration though |
| 21:21 | amalloy | scottj: yeah, i carefully picked on the ruby example :) |
| 21:21 | scottj | I think other languages name intermediate steps more often |
| 21:22 | amalloy | i remember seeing a clojure user object to java's anonymous classes with something like "seeing );}}()); is a sure sign of a diseased language" |
| 21:22 | amalloy | seemed a bit hypocritical |
| 21:22 | scottj | actually 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:23 | icey | ibdknox: noir-cljs looks like it will be a pretty nice time-saver |
| 21:23 | ibdknox | icey: I hope so :) |
| 21:24 | ibdknox | also if you're doing cljs |
| 21:24 | icey | ibdknox: 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:24 | ibdknox | it's worth checking out pinot https://github.com/ibdknox/pinot |
| 21:24 | amalloy | hah, pinot |
| 21:24 | ibdknox | :D |
| 21:24 | icey | ibdknox: dude. that looks awesome |
| 21:25 | ibdknox | you can do some really cool stuff with hiccup generating actual dom objects |
| 21:25 | ibdknox | amalloy: is there really any other name I could've used? |
| 21:25 | ibdknox | amalloy: hehe |
| 21:25 | icey | ibdknox: i spent some time earlier today reading up on google closure's templates; i'm happy to not need to use them haha |
| 21:26 | ibdknox | yeah.. the entire goog library hurts me a bit :( |
| 21:26 | ibdknox | with wonderful functions like goog.dom.getElementsByTagNameAndClass |
| 21:26 | icey | ibdknox: is there a way to get access to the request headers from inside defpage? |
| 21:27 | amalloy | ibdknox: well, noir makes me think of film noir, not of wine |
| 21:27 | ibdknox | icey: intentionally no |
| 21:27 | ibdknox | amalloy: yeah, the running joke was that it should've been blanc |
| 21:27 | icey | ibdknox: interesting - why intentionally no?? |
| 21:28 | ibdknox | amalloy: I'm not sure what I could've done related to film noir that would make a good name |
| 21:28 | amalloy | i don't know either |
| 21:28 | ibdknox | icey: chances are if you need it, you should be writing middleware :) |
| 21:28 | ibdknox | icey: what's your usecase? |
| 21:28 | icey | ibdknox: haha, fair enough; i was just curious |
| 21:29 | icey | ibdknox: 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:30 | icey | ibdknox: 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:30 | ibdknox | icey: gotcha :) You have access to the full request in pre-routes and middleware |
| 21:31 | xiaolongxia | ibdknox: actually i have a pretty elementary question about javascript interop using goog libraries ... |
| 21:31 | ibdknox | xiaolongxia: shoot |
| 21:31 | xiaolongxia | https://gist.github.com/1131051 |
| 21:31 | ibdknox | that is an epic list |
| 21:31 | xiaolongxia | i'm trying to make this more idiomatic in clojure, that works though |
| 21:32 | xiaolongxia | that's a direct port from the URL in the description |
| 21:33 | xiaolongxia | so obviously (let [buttons (vector (. goog.editor.Command BOLD))] (...)) |
| 21:33 | xiaolongxia | would work |
| 21:33 | xiaolongxia | but I'm not familiary enough with interop in clojure |
| 21:34 | xiaolongxia | to understand how to go from ["BOLD" "ITALIC" .. ] to an interop compatible name(?) |
| 21:34 | ibdknox | ah |
| 21:34 | ibdknox | so this is particularly tricky in CLJS right now |
| 21:34 | xiaolongxia | ah |
| 21:34 | ibdknox | the best way to do it |
| 21:34 | ibdknox | is with aget |
| 21:34 | ibdknox | (aget goog.editor.Command "BOLD") |
| 21:34 | xiaolongxia | huh |
| 21:35 | ibdknox | I do it in pinot for event lookup |
| 21:35 | ibdknox | https://github.com/ibdknox/pinot/blob/master/src/pinot/events.cljs#L18 |
| 21:36 | ibdknox | took me a while to get to that though :/ |
| 21:36 | ibdknox | lol |
| 21:37 | xiaolongxia | let is throwing a stacktrace, i'll have to keep playing with it |
| 21:37 | xiaolongxia | but i see what your code is doing |
| 21:37 | xiaolongxia | thanks |
| 21:37 | ibdknox | np |
| 21:37 | xiaolongxia | i had never messed with the goog libraries before |
| 21:38 | xiaolongxia | but in general, the UI library is pretty nice |
| 21:38 | ibdknox | yeah, I'm sure their "controls" are probably ok to work with |
| 21:39 | scottj | is there a simple way to not have everything look like google? without recssing everything manually |
| 21:39 | ibdknox | hah |
| 21:39 | ibdknox | why wouldn't you want to look like google? They're so successful! ;) |
| 21:40 | xiaolongxia | scottj: what is it you don't want to look "googly" ? |
| 21:40 | ibdknox | Sadly, 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:40 | xiaolongxia | i'll i'm really interested in is the editor, and that looks like most other well done editors |
| 21:40 | ibdknox | but even that seems to be sparse |
| 21:54 | emacsen | with cljscript, how does one interface with an existing js library? |
| 21:56 | xiaolongxia | ala https://gist.github.com/1096382 |
| 21:56 | ibdknox | eh |
| 21:56 | ibdknox | you shouldn't use js* |
| 21:56 | ibdknox | anything in the global js namespace can be accessed through js/ |
| 21:56 | ibdknox | js/alert |
| 21:56 | xiaolongxia | ah! |
| 21:56 | emacsen | xiaolongxia, thx. ibdknox okay, then I need to rewrite whatever I want to use? |
| 21:56 | xiaolongxia | thanks |
| 21:57 | ibdknox | emacsen: huh? |
| 21:57 | emacsen | ibdknox, so let's say I want to make a complex app. And I want to leverage something like paper.js |
| 21:58 | emacsen | are you saying don't do it? |
| 21:58 | ibdknox | no? I said don't use the js* function :-p |
| 21:58 | ibdknox | :) |
| 21:58 | emacsen | ah. So what's the right way? |
| 21:58 | ibdknox | the example that was given in that gist |
| 21:58 | ibdknox | uses (js* "$") |
| 21:59 | emacsen | ibdknox, okay. |
| 21:59 | ibdknox | you use the js namespace: (js/JQuery "blah") |
| 21:59 | ibdknox | though that likely won't do what you expect once you turn on advanced optimization :( |
| 22:00 | xiaolongxia | ibdknox: 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:01 | ibdknox | are you sure the commands aren't functions themselves? |
| 22:02 | ibdknox | if they're "classes" they would be |
| 22:03 | amalloy | xiaolongxia: you probably meant vec, not vector? though probably you don't need either |
| 22:04 | xiaolongxia | http://pastebin.com/yK2jR8qn |
| 22:04 | amalloy | well...yes? that's what those say to do |
| 22:05 | amalloy | i wasn't trying to trick you when i said to use vec, not vector |
| 22:05 | xiaolongxia | amalloy: i wrot that paste before you said that ... |
| 22:05 | xiaolongxia | i'm trying to understand why the map doesn't work |
| 22:06 | amalloy | it works fine |
| 22:06 | xiaolongxia | no ... it doesn't |
| 22:06 | amalloy | though a (for) would be clearer |
| 22:06 | amalloy | the problem is that you're creating a one-element vector, which contains a list of buttons |
| 22:07 | xiaolongxia | ok, so it was vec vs vector |
| 22:07 | ibdknox | yeah |
| 22:12 | fbru02 | hey ! is there any function that is the same as doing first a map and then a reduce |
| 22:12 | fbru02 | ? |
| 22:16 | zmaril | Pardon 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:16 | zmaril | Here is the gist: https://gist.github.com/1131095 |
| 22:20 | amalloy | fbru02: you could write that function yourself in fewer characters than it takes to ask about it, so probably nobody's bothered |
| 22:21 | fbru02 | amalloy: makes sense :) |
| 22:26 | xiaolongxia | amalloy, ibdknox: thanks for your help. won't get any further than this for now, but it runs: https://gist.github.com/1131051 |
| 22:27 | ibdknox | xiaolongxia: any time :) |
| 23:01 | jsnikeris | Suppose 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:02 | jsnikeris | My example should return 9... |
| 23:09 | fullets | (fn [vs n] (first (filter #(> % n) vs))) |
| 23:09 | fullets | Not sure how idiomatic that is |
| 23:10 | jsnikeris | fullets: works for numbers. I just came up with: |
| 23:10 | jsnikeris | ,(second (drop-while #(not= 5 %) [0 3 5 8])) |
| 23:10 | clojurebot | 8 |
| 23:11 | jsnikeris | still kinda ugly though |
| 23:11 | leonid | is your sequence nondecreasing, or increasing? |
| 23:11 | jsnikeris | increasing |
| 23:11 | jsnikeris | well, decreasing |
| 23:13 | jsnikeris | What do you mean by nondecreasing? |
| 23:13 | leonid | by that i mean the sequence has duplicate elements |
| 23:13 | fullets | [1 2 3 4] increasing, [1 2 2 3 3 4] nondecreasing |
| 23:13 | jsnikeris | Oh, gotcha. No duplicates |
| 23:14 | jsnikeris | Its actually a sequence of blog entries, sorted by publication date. |
| 23:14 | jsnikeris | But that's neither here nor there |
| 23:15 | leonid | fullet's solution looks good enough |
| 23:16 | fullets | If you want if for comparables in general, you could use the compare fn rather than > |
| 23:17 | jsnikeris | OK, thanks for the help guys |
| 23:18 | leonid | i'm surprised there's no built-in function that does find-first |
| 23:18 | bortreb | how about (find-first (partial < 5) [1 2 3 4 5 6]) |
| 23:18 | bortreb | using clojure.contrib.seq/find-first |
| 23:19 | fullets | bortreb: well spotted :) |
| 23:19 | jsnikeris | even named the same! |
| 23:19 | leonid | oh didn't know we could use contrib functions |
| 23:20 | Scriptor | is this for 4clojure? |
| 23:20 | jsnikeris | Yes |
| 23:28 | amalloy | jsnikeris: if you have an actual sorted-set/map instead of a vector, you can use ##(doc subseq) |
| 23:28 | lazybot | ⇒ "([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:30 | amalloy | and of course if you want to *keep* it sorted, you should be using a sorted-map/set |
| 23:40 | jsnikeris | so 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:41 | amalloy | a sorted set (or map) still makes more sense to me |
| 23:41 | jsnikeris | sorted-set wouldn't know how to sort these maps though |
| 23:42 | amalloy | &(doc sorted-set-by) |
| 23:42 | lazybot | ⇒ "([comparator & keys]); Returns a new sorted set with supplied keys, using the supplied comparator." |
| 23:42 | jsnikeris | aha |
| 23:42 | amalloy | SHAZAM |
| 23:42 | jsnikeris | LOL |
| 23:42 | jsnikeris | literally |
| 23:42 | jsnikeris | nice |
| 23:44 | amalloy | speaking 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:44 | lazybot | ⇒ "([pred]); Returns an implementation of java.util.Comparator based upon pred." |
| 23:49 | jsnikeris | Could you give me an example of max-key in use? |
| 23:51 | amalloy | &(max-key :x {:x 1 :y 2}, {:x 10 :y 5}) |
| 23:51 | lazybot | ⇒ {:x 10, :y 5} |
| 23:55 | jsnikeris | Ah, ok. |
| 23:58 | jsnikeris | Sometimes 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:58 | jsnikeris | what it does, rather |