2009-10-02
| 00:02 | arbscht | hm, rfirst and rrest were replaced with nfirst and nnext during the lazy merge |
| 00:08 | adityo | good morning folks |
| 00:08 | arbscht | hi |
| 02:34 | konr | Is there a particular http client I should use? |
| 02:35 | arbscht | what are your requirements? |
| 02:36 | konr | hmmm... support for cookies... nothing much more complicated than that |
| 02:41 | arbscht | you could probably build on c.c.http-agent. if you want automatic cookie management maybe apache's httpclient |
| 03:07 | Fossi | hi |
| 03:12 | konr | HI, Fossi |
| 03:40 | sfuentes | chouser: so your scala adventures are over? |
| 03:45 | hiredman | ~scala ((x: Int) => x + 1)(3) |
| 03:45 | clojurebot | Int = 4 |
| 03:57 | hiredman | sfuentes: http://gist.github.com/199542 |
| 03:58 | hiredman | or something like it |
| 04:03 | sfuentes | hiredman: thanks for the sample :) |
| 04:05 | hiredman | it maybe help to note that resources are loaded via the classpath and the classpath has little to do with filesystem locality |
| 04:12 | sgtzx | anyone using Enclojure here? |
| 04:13 | sgtzx | I am trying to learn Clojure while using Enclojure in NetBeans, but it is acting very strangely. |
| 04:14 | sgtzx | for example if I have (let [frame (JFrame. "Celsius Converter" ... then later I do (doto frame (.<I apply tab completion here and it seems to not be able to infer that frame is JFrame> |
| 04:48 | Fossi | wouldn't it make sense to make all io methods and java calls to use an implicit io!? |
| 04:49 | konr | How do I send a file using http.client? I'm using (File. "/foo/bar.jpg"), yet apparently the field is being dropped |
| 05:04 | spuz | LauJensen: hey |
| 05:04 | LauJensen | Hey spuz |
| 05:06 | spuz | Just running your brain sim now :) |
| 05:06 | LauJensen | How's it going? |
| 05:06 | spuz | There's a few things I didn't quite understand in your description though.. |
| 05:07 | spuz | for example, you mention pmap, but where do you actually use it? |
| 05:07 | spuz | also, how does it work? |
| 05:08 | LauJensen | Second line in "step" is "pmap (fn [window]" |
| 05:08 | LauJensen | ~def pmap |
| 05:10 | LauJensen | As you can see it splits the computation into bits which are passed to 'futures' running in their own threads |
| 05:14 | spuz | interestingly, it appears to be creating 2 more threads than there are available processors |
| 05:17 | yason | spuz: it's a common idiom: two processes per processor perform better in case the processes are less than 100% cpu-bound; otherwise it's just 50/50. |
| 05:17 | eevar2 | I think processor count * 2 might have been a better choise |
| 05:17 | eevar2 | granted, you get more context switches, but |
| 05:17 | yason | spuz: doubling, that is. Not +2, although if you have a dual-core system then it's probably *2 and not +2 :) |
| 05:21 | spuz | well, if you see the code for pmap, it sets n to numprocessors + 2. I'm not exactly sure what it does with 'n' after that but I assume that's the number of threads that is created... |
| 05:28 | spuz | LauJensen: also, could you explain what the step function does? I'm not quite getting the third line. Could you maybe expand it with an example of the input and output that goes into each part of the function? |
| 05:30 | LauJensen | spuz: I doubt I could you more input than what you get from setting the board dimensions to 3x3, re-eval 'board' and then do it step by step, you'll see how it is mapping windows on windows |
| 05:30 | spuz | ok good idea |
| 05:35 | sgtzx | LauJensen: brain sim is cool |
| 05:35 | sgtzx | LauJensen: you mentioned there is a performance hit due to that it's a functional language, how much do you think it is? |
| 05:36 | LauJensen | sgtzx: Glad you think so :) |
| 05:36 | LauJensen | With the current model, which is simple to reason about, the performance hit is huge, the way we work the board, the way the board is allocation, the massive allocation that comes with 'partition' and the strain on the GC that puts... Its a huge hit |
| 05:37 | LauJensen | I'm considering doing a revised version with blazing performance, but I figured I'd wait a few days and see what the commentators come up with :) |
| 05:37 | sgtzx | LauJensen: I would love to see that |
| 05:41 | sgtzx | LauJensen: out of curiosity, what IDE do you use, or do you use emacs and slime for clj dev? |
| 05:41 | vy | I'd expect concat to behave same as lazy-cat and there would appear no lazy-cat? Aren't they functionally identical, except laziness? |
| 05:42 | LauJensen | sgtzx: Emacs |
| 05:43 | LauJensen | ,(class (concat 1 2)) |
| 05:43 | clojurebot | clojure.lang.LazySeq |
| 05:43 | hiredman | ,(first (concat [1] (println :foo))) |
| 05:43 | clojurebot | 1 |
| 05:44 | clojurebot | :foo |
| 05:44 | hiredman | ,(first (lazy-cat [1] (println :foo))) |
| 05:44 | clojurebot | 1 |
| 05:44 | vy | So what's the difference between lazy-cat and concat? |
| 05:44 | hiredman | lazy-cat has an extra layer of laziness |
| 05:44 | vy | Ooops! lazy-cat is just a macro over concat! |
| 05:45 | vy | [& colls] `(concat ~@(map #(list `lazy-seq %) colls)) |
| 05:45 | hiredman | concat is a function, so it's arguments are evaluated |
| 05:45 | hiredman | lazy-cat is a macro, so it controls the evaluation of its arguments |
| 05:46 | hiredman | which it does by wrapping them in a call to lazy-seq |
| 05:47 | vy | I'd still expect "concat" to work as "lazy-cat". Anyway... |
| 05:48 | hiredman | well, if you read the docstrings, the difference is explained there |
| 05:48 | hiredman | so I don't know why you would expect something other than what is documented |
| 05:48 | vy | Why would somebody prefer concat over lazy-cat? |
| 05:49 | hiredman | concat is a function |
| 05:49 | hiredman | so you can apply it |
| 05:49 | hiredman | etc |
| 05:50 | rsynnott | also, lazy-cat sounds like some form of lolcat |
| 05:52 | ambient | so does concat ;) |
| 05:53 | Fossi | repost (;-)): wouldn't it make sense to make all io methods and java calls to use an implicit io!? |
| 05:55 | jdz | Fossi: what is an implicit io? |
| 05:56 | hiredman | ,(doc io!) |
| 05:56 | clojurebot | "([& body]); If an io! block occurs in a transaction, throws an IllegalStateException, else runs body in an implicit do. If the first expression in body is a literal string, will use that as the exception message." |
| 05:57 | vy | I'm reading clojure cheat sheet... While there appears "frest", and "rrest" in the documentation, there are no such functions supplied by the core, AFAIK. Am I missing something? |
| 05:57 | hiredman | the cheat sheet is old |
| 05:57 | hiredman | the are fnext and something else now |
| 05:58 | hiredman | rnext? |
| 05:58 | hiredman | ,rnext |
| 05:58 | clojurebot | java.lang.Exception: Unable to resolve symbol: rnext in this context |
| 05:58 | hiredman | ,nnext |
| 05:58 | clojurebot | #<core$nnext__3833 clojure.core$nnext__3833@1daa156> |
| 05:59 | vy | I love languages that are getting trimmed by time. |
| 06:03 | sgtzx | ,nnext |
| 06:03 | clojurebot | #<core$nnext__3833 clojure.core$nnext__3833@1daa156> |
| 06:13 | jdz | there still is not any function like CL's find, is there? |
| 06:15 | vy | jdz: (first (filter f coll)). |
| 06:15 | jdz | vy: right. |
| 06:20 | liwp | any slime experts here? |
| 06:21 | liwp | if I type e.g. "(fn" into the repl and hit tab, I get a completion suggestion buffer and point has been moved in front of 'n' which I find really annoying |
| 06:22 | liwp | Is there a way to stop point from moving or can I somehow overwrite the 'n' when I carry on typing? |
| 06:30 | jdz | i don't observe the behaviour you describe... |
| 06:31 | LauJensen | jdz: phew - I thought something had happend to you, since I hadn't received a flamemail for my last blog post yet :) |
| 06:32 | liwp | jdz: urgh, I'll need to look into my slime setup then... |
| 06:34 | vy | liwp: Same as jdz in here. |
| 06:35 | liwp | vy & jdz: what do you get then? the completion buffer, but the point stays at the end of the line? |
| 06:35 | liwp | i seem to recall that I didn't see this behaviour sometime in the past, but I can't be sure |
| 06:36 | vy | liwp: Yup. |
| 06:37 | liwp | thanks |
| 06:38 | vy | Could somebody tell me more about the "with-local-vars"? I couldn't get the difference between "with-local-vars" and "binding". |
| 06:45 | liwp | vy: looking at the source it seems to me that with-local-vars creates new vars for the bindings, whereas binding rebinds the existing vars |
| 06:45 | liwp | I don't know what practical difference that makes |
| 06:46 | liwp | I guess if you call code in the body that uses global vars then with-local-vars will not work, i.e. it's not rebinding those global vars |
| 06:49 | pixelman | I'be been thinking about this lazy stuff -- does can clojure somehow cache stuff that's explicitly lazy? |
| 06:50 | yason | pixelman: what do you mean, like (memoize) ? |
| 06:50 | pixelman | I'm using compojure, and I would like to cache the result of certain calls to (html [... |
| 06:50 | pixelman | the app would be snappier |
| 06:51 | liwp | vy: and one major difference is that, as the doc string says, you have to use (var-get) and (var-set) to access the var in with-local-vars |
| 06:51 | pixelman | looking at memoize |
| 06:51 | vy | liwp: I see. Thanks. (Reading the sources...) |
| 06:52 | yason | pixelman: (memoize your-page-generation-fn) and store that somewhere |
| 06:52 | liwp | vy: with with-local-vars you can set the var value in the body with (var-set) |
| 06:53 | yason | liwp: what's the point in that, i.e. what can you do that you can't with binding? |
| 06:53 | pixelman | yason: pretty cool! will try that. |
| 06:53 | liwp | yason: dunno, I'm trying to figure it out ;) |
| 06:54 | yason | liwp: IIRC in Practical Clojure there was a paragraph that usually vars and symbols can be mingled together but for certain cases it's important to recognize the difference -- ain't figured that out yet :) |
| 06:54 | liwp | definitely one major difference is the fact that with-local-vars does not rebind vars globally (as the name suggests) |
| 06:55 | yason | liwp: hmmm, but (binding) isn't global either, right? |
| 06:56 | liwp | yason: if you call a function from the binding body that reads a var that you've rebound, you'll get the new value rather than the orig value |
| 06:56 | liwp | i.e. (def a 1) (defn foo [] a) (binding [a 2] (foo)) will return 2 |
| 06:58 | liwp | ,(def a 1) (defn foo [] a) (binding [a 2] (foo)) |
| 06:58 | clojurebot | DENIED |
| 06:59 | liwp | ,(do (def a 1) (defn foo [] a) (binding [a 2] (foo))) |
| 06:59 | clojurebot | DENIED |
| 06:59 | liwp | have it your way then |
| 07:01 | LauJensen | Does anybody know who's behind disclojure.org ? |
| 07:02 | yason | liwp: I know binding but an example of with-local-vars would be enlightening |
| 07:04 | liwp | ,(with-local-vars [bb 1] (var-get bb)) |
| 07:04 | clojurebot | 1 |
| 07:04 | liwp | are slightly useless example :) |
| 07:05 | liwp | the interesting bit is that you have to use var-get and var-set to access the var |
| 07:05 | LauJensen | nvm |
| 07:29 | pixelman | I'm looking for a logging framework, should I just use log4j or is there some wrapper or such for clojure? |
| 07:30 | lpetit | ataggart created one in clojure.contrib |
| 07:30 | LauJensen | pixelman: You can wrap log4j using 1 macro, and I recommend that approach :) |
| 07:31 | pixelman | tnx! |
| 07:45 | vy | LauJensen: Were you the one who was asking yesterday how to log to a file via c.c.logging? |
| 07:48 | LauJensen | No, but I remember the talk @ vy |
| 07:51 | vy | Then do you know the answer? I couldn't figure out it too. |
| 07:51 | LauJensen | To me the answer is using log4j , for you, it may be patching c.c.logging |
| 07:52 | vy | LauJensen: You mean directly using log4j without c.c.logging wrapper? |
| 07:52 | LauJensen | That's what I did |
| 07:52 | LauJensen | I'm not saying it's for you though, I just try to stay out of contrib as far as possible |
| 07:58 | pixelman | c.c logging worked fine when the loglevel was accepted by log4j but crashed when I tried a :notice. still pretty slick though. I just want to log some stuff. :) |
| 07:58 | Fossi | out of curiosity: why's that? |
| 07:58 | Fossi | LauJensen: out of curiosity: why's that? |
| 08:00 | LauJensen | Fossi: A lot of the code in contrib are small helpers/wrappers/utilities which help you abstract your problem - I get the best feel for the problem when I write these myself and sometimes that helps me refactor the code - if I didn't have all the code in my POV all the time, I don't think I'd refactor like I do, and I don't think I'd have as good a feel for it... and oh.. then there's the SQL thing :) |
| 08:01 | Fossi | understandable. in case you still look for new topics, i'd love a more elaborate blog post on that ;) |
| 08:02 | pixelman | what is the SQL thing? |
| 08:02 | LauJensen | I'm always looking for new topics :) |
| 08:02 | Fossi | kinda just explained the reasoning for the method of operation in the last few |
| 08:03 | Fossi | *to me |
| 08:03 | Fossi | ok, maybe that wasn't even an understandable sentence |
| 08:03 | LauJensen | pixelman: Kotarak and myself have developed ClojureQL which is a nice way to interact with databases, in contrib there's also an SQL wrapper, which I politically view as competition :) (just kidding) |
| 08:06 | pixelman | LauJensen: interesting, gotta look up your project :) I'm using the stuff in common now and finding it pleasant to use, but it's nice to see other approaches. |
| 08:07 | LauJensen | clojureql is radically different, because it lets you stick with your normal syntax, (query table1 [item id cost] (< cost 500)) for instance |
| 08:07 | spuz | LauJensen: very interesting, is that then just parsed and converted into normal SQL? |
| 08:08 | LauJensen | In some ways it's a matter of taste, in other we really provide functionality that you won't normally get, like specific backends for Mysql and Derby that provide FULL JOIN functionality etc etc, but read all about it on Gitorious :) |
| 08:08 | LauJensen | ~clojureql |
| 08:08 | clojurebot | clojureql is http://gitorious.org/clojureql |
| 08:09 | LauJensen | Then that's saved as a syntax tree, which you can do stuff with, like (group-by foo (query table ...)) and when you ask to have it executed, it's transformed to a valid SQL string and run through JDBC's .nativeSQL, and then executed |
| 08:10 | pixelman | can I access data lazily from mysql? |
| 08:11 | LauJensen | Yep, (run *con* (query table [x y z])) gives you a lazy result-sequence, instead of LIMIT you can then do (take 50 ) on it, instead of OFFSET you can use (drop) but that's costly, we're still working on that. When you've fully realized the seq, the connection closes |
| 08:11 | LauJensen | (drop was costly, not limit) |
| 08:12 | pixelman | neat! |
| 08:12 | spuz | LauJensen: that's very nice |
| 08:15 | LauJensen | Glad you think so - My last blog post is already 8.th on Dzone.com, it's amazing the interesting functional programming/clojure is generating these days - wonder if Rich's JVM talk has something to do with it :) |
| 08:15 | snowwhite | Does clojure have classes? |
| 08:15 | Chousuke_ | yes and no. |
| 08:15 | spuz | LauJensen: was that the one about OO and time? |
| 08:16 | snowwhite | Chousuke_, as in? |
| 08:16 | LauJensen | spuz: A functional Brians Brain simulator |
| 08:16 | Chousuke_ | snowwhite: it has classes because the JVM has them; however, actually directly making classes yourself is not very idiomatic. |
| 08:16 | spuz | LauJensen: I mean the jvm talk, there was one called Are we there yet I think. Is that the one you mean? |
| 08:16 | Chousuke_ | snowwhite: the ability to create classes is mainly used for interop with Java. |
| 08:17 | LauJensen | spuz: To my great disappointment I still haven't heard the talk(s) but I'm thinking the OO vs Time could be it |
| 08:17 | snowwhite | Chousuke_, Can you show an example by pasting some code somewhere? |
| 08:18 | Chousuke_ | snowwhite: hm |
| 08:19 | snowwhite | Chousuke_, thanks |
| 08:19 | Chousuke_ | I don't have a gen-class example at hand right now :/ |
| 08:19 | snowwhite | Chousuke_, :( |
| 08:19 | LauJensen | ~sofiaba |
| 08:19 | clojurebot | sofiaba is http://wiki.github.com/Lau-of-DK/sofiaba |
| 08:19 | LauJensen | snowwhite: I was forced to use gen-class in that :) |
| 08:21 | spuz | heh, I'm not sure a full blown 3d game is the kind of example snowwhite was looking for :p |
| 08:21 | Chousuke_ | snowwhite: behind the scenes there are of course classes generated everywhere but you can accomplish quite a lot with Clojure without writing a single named class :) |
| 08:21 | LauJensen | I didn't implement Duke Nukem, so it's not full blown :) |
| 08:22 | Chousuke_ | snowwhite: for example, every clojure function is its own class. |
| 08:22 | Chousuke_ | snowwhite: but you don't need to care about that :) |
| 08:22 | snowwhite | Chousuke_, hmm, but a small example could clarify a bit more? |
| 08:22 | spuz | it's interesting to see the classes generated by clojure, I put a very simple example through a decompiler to see what the byte code was doing and there's a lot more going on behind the scenes than you might think |
| 08:22 | Chousuke_ | ,(class (fn [])) |
| 08:23 | clojurebot | sandbox$eval__5228$fn__5230 |
| 08:23 | Chousuke_ | but of course, that's not very interesting to you. |
| 08:23 | Chousuke_ | for interop, you can often use proxy too |
| 08:24 | spuz | snowwhite: have a look at this for more info on class generation: http://clojure.org/compilation |
| 08:26 | Chousuke_ | snowwhite: for interop without gen-class, you can have code like (.addListener someswingthing (proxy [ActionListener] [] (actionPerformed [e] ...))) ... proxy generates a class implementing ActionListener, but you don't need to care about what exactly it is called :) |
| 08:27 | snowwhite | Chousuke_, cool |
| 08:27 | snowwhite | Chousuke_, :) |
| 08:27 | Chousuke_ | I guess gen-class enters the picture when people in Javaland need to be able to use it directly (and not through an interface) |
| 08:28 | Chousuke_ | or if you're implementing a main method. |
| 08:55 | Drakeson | is completion broken with slime + swank-clojure ? |
| 08:55 | Drakeson | or is it just my setup that's broken? |
| 08:56 | cschreiner | Drakeson: at the repl? |
| 08:56 | cschreiner | works fine |
| 08:56 | cschreiner | in the buffer, not so |
| 08:56 | cschreiner | (for me) |
| 08:56 | Drakeson | it doesn't comlete even in the repl |
| 08:57 | Drakeson | I updated everything couple of hours ago |
| 08:57 | cschreiner | did you first M-c k the file? |
| 08:58 | Drakeson | what is M-c k ? it is unbound here. |
| 08:58 | cschreiner | ah, C-c k, sorry |
| 08:58 | cschreiner | I'm sure you did |
| 08:59 | Drakeson | that's unbound, too |
| 08:59 | cschreiner | did you start slime? |
| 09:00 | Drakeson | sure |
| 09:00 | liwp | try C-h k TAB |
| 09:00 | liwp | in the repl |
| 09:00 | liwp | that should say that tab is bound to slime-indent-and-complete-symbol |
| 09:01 | Drakeson | liwp: it is. |
| 09:01 | jdz | LauJensen: i have not seen your latest blog entry, sorry |
| 09:01 | liwp | then I'm out of ideas :) |
| 09:02 | liwp | Drakeson: and it doesn't mentione any before or after advice? |
| 09:02 | Drakeson | well, if I could be sure that it is my setup that is broken, not the upstream ... |
| 09:03 | pixelman | what to use to read in config files? wrap properties? or yaml |
| 09:05 | liwp | pixelman: Properties can be dumped into a clojure map so it's definitely an easy way to get something working fast |
| 09:06 | Drakeson | liwp: I am trying to edebug the completion functions ... |
| 09:06 | liwp | ,((into {} (System/getProperties)) "path.separator") |
| 09:06 | clojurebot | java.security.AccessControlException: access denied (java.util.PropertyPermission * read,write) |
| 09:06 | liwp | blah |
| 09:06 | pixelman | liwp: yep, that's nice |
| 09:07 | liwp | the downside is that the keys are strings rather than keywords |
| 09:08 | ambient | anyone have the problem that after running a swing app, slime disconnects and I have to restart/reload everything? |
| 09:09 | liwp | ambient: many swing apps bind the close button to System/exit which will then kill your JVM and the slime connection |
| 09:09 | liwp | it's very frustrating when running stuff via slime |
| 09:10 | LauJensen | liwp, can't you just override it ? |
| 09:10 | ambient | it's ok if i just comment out the EXIT_ON_CLOSE part? |
| 09:11 | ambient | i don't know how to lessen the amount balls i have to juggle in air while trying to code swing/clojure with emacs/slime/clojure-mode |
| 09:11 | liwp | ambient: I think so, I think the default behaviour is to close the window and that's exactly what you want |
| 09:11 | liwp | LauJensen: sure, it just annoys me when I try out someone's clojure/swing app and closing it kills my repl |
| 09:12 | LauJensen | ok :) |
| 09:15 | ambient | heh, searching for 15 minutes on how to indent clojure code in emacs and a simple mark region + press tab does it :D |
| 09:15 | ambient | my google-fu is seriously lacking |
| 09:16 | liwp | ambient: also M-x indent-region would work |
| 09:16 | Drakeson | press tab? use M-C-\ after marking region. |
| 09:16 | Fossi | Meta-Q |
| 09:17 | Fossi | indents the current region |
| 09:17 | Fossi | no selection needed |
| 09:17 | danlei | I most often use C-M-q at the start of a sexp |
| 09:18 | Fossi | yeah, sorry, meta-q is paredit-indent |
| 09:19 | liwp | Drakeson: thanks for that - I'll have to try to remember it in the future |
| 09:20 | liwp | M-C-q also sounds good although I usually don't have to re-indent clojure code |
| 09:21 | danlei | I nedd it all the time :) |
| 09:21 | danlei | *need |
| 09:21 | liwp | I'm not sure why I don't need it, maybe it's because of paredit or because my yank reindents the yanked code |
| 09:22 | danlei | hm, I use paredit too |
| 09:22 | liwp | maybe I just leave my code in a massive mess and don't notice it 8-I |
| 09:22 | Drakeson | I rarely need that (maybe I press TABs too often). I only do a few C-x h C-M-\ during the day. |
| 09:22 | danlei | :) |
| 09:24 | danlei | liwp: self-reindenting yank sounds nice |
| 09:24 | danlei | should make mine behave like that too |
| 09:24 | liwp | danlei: it's very good with e.g. C++ and friends when you move stuff out of blocks |
| 09:25 | danlei | sure is |
| 09:25 | liwp | I can't remember where I picked it up from, probably emacs wiki |
| 09:25 | Drakeson | ok, what does (slime-eval '(swank:completions "ma" "user")) produce? |
| 09:26 | Drakeson | it doesn't give me any completion, and results in: (nil "ma") |
| 09:26 | liwp | Drakeson: I get a whole list of stuff, e.g. macroexpansion-1 |
| 09:27 | liwp | (("macroexpand" "macroexpand-1" "main-page" "make-array" "make-hierarchy" "map" "map-invert" "map-str" "map?" "mapcat" "match-method" "match-uri" ...) "ma") |
| 09:27 | Drakeson | liwp: thanks. now I know there is something wrong with either swank-clojure or my setup. |
| 09:28 | liwp | this is the main problem with emacs: things sometimes break and it's difficult to figure out what's broken simply because your emacs setup is unique in the world |
| 09:28 | danlei | liwp: something like (lambda () (yank) (save-excursion (exchange-point-and-mark) (indent-sexp))) should work for lisp code |
| 09:29 | pixelman | ,(map #( list (keyword (% 0)) (% 1) ) {"foo" "FOO" "bar" "BAR"}) |
| 09:29 | clojurebot | ((:foo "FOO") (:bar "BAR")) |
| 09:29 | pixelman | how can I build a map instead? |
| 09:29 | liwp | danlei: isn't your mark going to be in the wrong place when you're yanking? |
| 09:30 | danlei | it's untested, but I think it should work |
| 09:30 | liwp | pixelman: with reduce |
| 09:30 | pixelman | liwp: ok! |
| 09:30 | liwp | pixelman: something like (reduce #(assoc %1 (first %2) (second %2)) {} ...) |
| 09:31 | liwp | danlei: the yank-indent hack that I use adviced the existing yank, I'll see if I can find the URL for it |
| 09:32 | danlei | liwp: thanks. my thingie works, btw |
| 09:32 | danlei | but it should do everything pasted, not only a sexp (although that's what I most often paste) |
| 09:32 | danlei | s/do/indent/ |
| 09:33 | liwp | danlei: http://trey-jackson.blogspot.com/2008/03/emacs-tip-15-indent-yanked-code.html |
| 09:33 | danlei | liwp: thanks! |
| 09:34 | liwp | np |
| 09:37 | danlei | ah, now I see what you meant, should move to the beginning of the line, too :) |
| 09:38 | pixelman | ,(reduce #(assoc %1 (keyword (first %2)) (second %2)) {} {"foo" "FOO" "bar" "BAR"}) |
| 09:38 | clojurebot | {:bar "BAR", :foo "FOO"} |
| 09:38 | danlei | (or just press tab before yanking) |
| 09:39 | pixelman | liwp: thanks for the pointer :) |
| 09:41 | Chousuke | ,(into {} (map (fn [[k v]] [(keyword k) v]) {"foo" :bar})) |
| 09:41 | clojurebot | {:foo :bar} |
| 09:45 | liwp | Chousuke: what's the best way to turn a java HashMap<String, String> into a clojure map with keyword keys? |
| 09:46 | liwp | i.e. we talked above about using Java Properties for config and I can turn that into a clojure map with into, but I'm left with String keys |
| 09:47 | liwp | I could use your above code to change the keys to keywords except that the items in a Properties object are not pairs |
| 09:47 | chouser | what's wrong with string keys? |
| 09:47 | liwp | chouser: you can't do (:foo my-map) |
| 09:47 | liwp | not a big deal, but still |
| 09:47 | Chousuke | liwp: you can do (my-map "foo") though :) |
| 09:47 | liwp | yeah, I know |
| 09:48 | liwp | and also, I guess some of the strings won't be legal keywords anyhow |
| 09:48 | rhickey | ah, finally! - http://www.infoq.com/presentations/Value-Identity-State-Rich-Hickey |
| 09:48 | Chousuke | (let [m {"foo" "FOO" "bar" "BAR"}] (zipmap (map keyword (keys m) (vals m)))) |
| 09:48 | Chousuke | ,(let [m {"foo" "FOO" "bar" "BAR"}] (zipmap (map keyword (keys m) (vals m)))) |
| 09:48 | clojurebot | java.lang.IllegalArgumentException: Wrong number of args passed to: core$zipmap |
| 09:48 | Chousuke | hmm |
| 09:48 | Chousuke | ah, damn |
| 09:48 | Chousuke | ,(let [m {"foo" "FOO" "bar" "BAR"}] (zipmap (map keyword (keys m)) (vals m)))) |
| 09:48 | clojurebot | {:bar "BAR", :foo "FOO"} |
| 09:49 | Chousuke | I'm too used to paredit taking care of the parentheses :( |
| 09:49 | chouser | "Presented by Rich Hickey on Oct 01, 2009" Oops. |
| 09:49 | liwp | Chousuke: that'll work, thanks |
| 09:59 | spuz | What's the best way to add two vectors? I could do something like (map + [1 2] [3 4]) => (4 6) but this returns a list rather than a vector |
| 09:59 | Chousuke | just call vec on that :) |
| 10:00 | spuz | ok :) |
| 10:00 | spuz | I wonder if there is a more efficient way but we'll see if it is a performance problem later :) |
| 10:01 | ambient | vectors are often just arrays so you could use an actual array |
| 10:01 | Chousuke | arrays are mutable though. |
| 10:01 | Chousuke | vector aren't. |
| 10:01 | Chousuke | spuz: I don't think there's any more efficient way, besides using mutable data structures. |
| 10:01 | Chousuke | and you probably don't want that. :P |
| 10:01 | spuz | ok |
| 10:02 | ambient | using the GPU for numeric work |
| 10:02 | ambient | or dedicated math libs |
| 10:14 | namor | What is the advantage of STM over a synchronized "swap!" function? |
| 10:14 | chouser | namor: coordinated accees/mutation of multiple references. |
| 10:15 | liwp | namor: you can change multiple things as an atomic transaction |
| 10:15 | namor | Ok, i get it. Thanks. |
| 10:16 | raek | if I want to write yaml/load instead of org.ho.yaml/load (org.ho.yaml is a java package) how do I do it? |
| 10:16 | liwp | raek: import org.ho.yaml |
| 10:16 | liwp | yaml is the java class? |
| 10:17 | raek | no, the package |
| 10:17 | liwp | what's the clas? |
| 10:17 | raek | oh whait |
| 10:17 | raek | org.ho.yaml.Yaml is the class |
| 10:17 | raek | load is a static method of that class |
| 10:17 | raek | then there's no problem :) |
| 10:17 | liwp | ok |
| 10:19 | raek | user=> (Yaml/load *in*) |
| 10:19 | raek | - a |
| 10:19 | raek | - b |
| 10:19 | raek | - c |
| 10:19 | raek | #<ArrayList [a, b, c]> |
| 10:19 | raek | yay! |
| 10:20 | liwp | cool |
| 10:21 | liwp | is that all you have to do? Is the yaml lib easy to use from clojure? |
| 10:21 | raek | I have no idea... :) this is my first experience with yaml in clojure |
| 10:22 | raek | the java containers can be used with clojure's sequence library |
| 10:23 | raek | so traversing the yaml data shouldn't be any problem |
| 10:24 | konr | does (:import (java.awt *)) work? |
| 10:24 | Chousuke | no. |
| 10:24 | konr | Chousuke: hmm, is there an alternative? |
| 10:25 | Chousuke | no. |
| 10:25 | Chousuke | :) |
| 10:25 | chouser | konr: you're not going to use *all* the awt classes. Just list the ones you use. |
| 10:26 | somnium | it seems some libraries use def and namespaces to emulate mutable objects, though this is religiously discouraged. is there a run time difference between this and doing, for example, (ns config) (def config-state (atom {})) and using swap? |
| 10:27 | Chousuke | somnium: people expect defs to be immutable, or at worst thread-locally bound. :P |
| 10:27 | Chousuke | if it's an atom, it's *explicit* that it can change. |
| 10:28 | somnium | compojure defines an explicit redef that preserves metadata, for example |
| 10:29 | chouser | ew. really? |
| 10:29 | somnium | I'm new enough to lisp that I don't have any 'religious beliefs' about def, but I want to adopt best practices. I was just wondering if they're absolutely equivalent but one breaks convention and one doesn't |
| 10:29 | somnium | yeah, in control.clj |
| 10:30 | Chousuke | in any case, using def anywhere except top-level is wrong. |
| 10:30 | somnium | I'm not sure how it's used, they |
| 10:30 | somnium | also an immigrate macro but that just takes all the vars from a list of namespaces and puts them into one for convenience |
| 10:31 | Makoryu | Would it be possible to print warnings for any non-top-level use of def? |
| 10:32 | chouser | oh, I see. I think compojure's just doing that during app setup. That's slightly less evil. |
| 10:32 | somnium | I asked about doing that but was told it was absolutely evil and to use atoms :) |
| 10:33 | somnium | is there a way to list all the classes in a java package? |
| 10:33 | chouser | somnium: no |
| 10:33 | chouser | somnium: you can look at all the .class files in a directory or in a jar |
| 10:36 | somnium | hmm, thinking of a dirty way to do import org.foo.* by using the classpath to find all the classnames |
| 10:37 | somnium | anyway, under the hood, is evil-redeffing and atom swapping equivalent? |
| 10:38 | chouser | not quite |
| 10:38 | chouser | def uses a lock on the var. atoms do atomic-set-and-check |
| 10:39 | somnium | ok, so no reason not to use atoms when configuring state before launching the main loop to be explicit? |
| 10:41 | chouser | sure. |
| 10:42 | chouser | another benefit of using atoms is that if you decide later it needs to be a ref (to coordinate with other refs) much of your code will be very similar |
| 10:42 | chouser | replace swap! with alter, wrap in a dosync, done. |
| 10:42 | chouser | if you were redefing vars, you'd have to go find where you need to add @, fix your def calls, etc. |
| 10:44 | ambient | how do i refactor this into a shorter form? (Color. (bit-xor x y) (bit-xor x y) (bit-xor x y)) |
| 10:44 | liwp | ambient: (let [c (bit-xor x y)] (Color. c c c)) |
| 10:44 | ambient | ah.. *slaps forehead* |
| 10:45 | liwp | heh |
| 10:45 | somnium | I'm thinking of the way rails plugins go in and alter whatever core classes they're changing, it should be simple to decorate atoms with a logger to go and see exactly what happens during config |
| 10:45 | chouser | you wanted something trickier, perhaps. (#(Color. % % %) (bit-xor x y)) |
| 10:45 | liwp | chouser: slightly shorter as well I think ;) |
| 10:45 | ambient | that seems oddly readable :o |
| 10:46 | liwp | (apply Color. (replicate 3 (bit-xor x y))) ? |
| 10:46 | chouser | plus it generates a whole new class for you under the covers. |
| 10:46 | spuz | chouser: I missed ambient's question, what is x and y? |
| 10:46 | ambient | image coordinates |
| 10:47 | ambient | xor function gives a cool image for testing purposes |
| 10:48 | spuz | heh, an image of what though :) |
| 10:48 | Fossi | xor |
| 10:48 | liwp | and x and y |
| 10:48 | Fossi | it plots the function :) |
| 10:49 | ambient | it's kinda the simplest fractal that i know of |
| 10:50 | spuz | I have a question, how can I get the decimal representation of a Ratio? |
| 10:50 | chouser | ,(double 7/3) |
| 10:50 | clojurebot | 2.333333333333333 |
| 10:51 | spuz | chouser: thanks |
| 10:53 | rhickey | That infoq talk is one of my favorites |
| 10:54 | chouser | I'm watching it now. Did you just watch it? |
| 10:54 | rhickey | yep |
| 10:54 | rhickey | slight slide lag in a couple of places, but I love that they sync the slides like that |
| 10:54 | liwp | must be weird watching yourself give a talk |
| 10:55 | chouser | yeah, that's good practical tech. |
| 10:55 | liwp | rhickey: yeah, that's a really nice feature |
| 10:56 | Fossi | repost (again ;-)): wouldn't it make sense to make all io methods and java calls to use an implicit io!? |
| 10:56 | rhickey | Fossi: no, many are functional |
| 10:56 | rhickey | also overhead |
| 10:56 | Chousuke | rhickey: I just finished it. They cut out the question part at the end though (or were there really no questions? :/) |
| 10:57 | rhickey | they don't usually include the q/a part |
| 10:57 | rhickey | there were a few, Joe Armstrong was in the audience :) |
| 10:59 | Fossi | too bad :( |
| 11:00 | somnium | what's the url? |
| 11:00 | rys | Joe is the Erlang guy? |
| 11:00 | liwp | rys: yep |
| 11:01 | liwp | somnium: http://www.infoq.com/presentations/Value-Identity-State-Rich-Hickey |
| 11:01 | rys | Watched a nice thing with him and SPJ recently, can't rememeber the site though. InfoQ? |
| 11:01 | liwp | rys: this: http://www.infoq.com/interviews/armstrong-peyton-jones-erlang-haskell |
| 11:01 | liwp | ? |
| 11:01 | liwp | I haven't watched it yet |
| 11:01 | rys | Yeah, that's the one |
| 11:01 | rys | It's quite funny |
| 11:01 | Chousuke | the thing about needing to model time hadn't quite sunk in before I watched that presentation, but I think it's clear now. good stuff, anyway |
| 11:02 | rys | Joe's really animated and SPJ just sits there, dead still |
| 11:03 | liwp | SPJ gets animated when he's launching missiles |
| 11:04 | sproingie | naw he's just lazy :) |
| 11:04 | liwp | ;-) |
| 11:27 | spuz | rhickey: hey, just watching your qcon talk. You say you made a talk the previous day, what was that talk about? |
| 11:27 | rhickey | spuz: an introduction to Clojure |
| 11:27 | spuz | is that available somewhere? |
| 11:27 | rhickey | not yet |
| 11:28 | rhickey | the one they put up is the important one, new compared to all others |
| 11:28 | spuz | ok |
| 11:28 | rhickey | the intro has a lot of overlap with other talks I've given |
| 11:34 | spuz | rhickey: what kind of feedback do you get from people after these talks? Do you think you're winning the battle of converting people away from OO? |
| 11:34 | liwp | rhickey: should into be changed take multiple from collections as args? e.g. (into [] [1] [2] [3]) |
| 11:35 | liwp | mark volkman was asking about it on the group |
| 11:35 | liwp | and is this an appropriate impl: (apply into (into x y) zs))) |
| 11:38 | rhickey | spuz: I think that talk was one of the more popular at QCon. There's a whole other set of issues in converting people... I'm not trying to do that, just explaining the ideas behind Clojure |
| 11:43 | rhickey | liwp: I'm not sure about multiple args, not that important. could use (reduce into dest [xs ys zs]) |
| 11:43 | Drakeson | liwp: can I ask you when you last updated your swank-clojure ? |
| 11:43 | liwp | sure |
| 11:44 | liwp | Drakeson: not too long ago I don't think |
| 11:44 | liwp | rhickey: I was looking for low hanging fruit to contribute. Is there anything urgent in assembla that no one's looking at? |
| 11:45 | sproingie | speaking of converting people from oo, there a doc out there about functional ways to replace is-a relationships? |
| 11:45 | sproingie | i have a few tricks but it all feels pretty ad-hoc |
| 11:46 | rhickey | ,(derive ::square ::rect) |
| 11:46 | clojurebot | nil |
| 11:46 | rhickey | ,(isa? ::square ::rect) |
| 11:46 | clojurebot | true |
| 11:46 | ambient | square and rect are a good example of a devious not is-a relationship iirc |
| 11:47 | rhickey | liwp: anything marked for next release without patches is fair game |
| 11:47 | ambient | (a bit off-topic) |
| 11:47 | sproingie | square and shape then |
| 11:47 | rhickey | ambient: only in the face of mutation |
| 11:47 | liwp | Drakeson: maybe I haven't updated after all... git log gives me c1e309dfe53cb45149258404c4db5b53fb5c81b7 from april 17th |
| 11:47 | sproingie | the square/rectangle problem is a classic trick question. it _has_ no "right" answer |
| 11:47 | chouser | what? |
| 11:48 | rhickey | in what way is a square not a rectangle? |
| 11:48 | sproingie | if the contract for shapes says they have optional constraints, then there's a right answer |
| 11:48 | sproingie | one-arg constructor to square violates substitution principle |
| 11:49 | rhickey | sproingie: you don't have an object yet when you call the ctor |
| 11:49 | rhickey | so no substitution |
| 11:50 | sproingie | constructors usually aren't polymorphic anyway, so there's some argument that substitutability doesn't apply |
| 11:50 | sproingie | wonder what liskov would say to that |
| 11:52 | sproingie | been teaching myself scala for this whole week. love the syntax sugar, but soooooo much syntax. |
| 11:52 | sproingie | i'd probably be half-done with my project if i started it in clojure instead |
| 11:53 | Fossi | any language with a construct like +: 1 2 fails :D |
| 11:53 | Fossi | poor mans macros |
| 11:53 | somnium | I couldn't stand the syntax, too similar-yet-different to ruby |
| 11:53 | Makoryu | Fossi: Eh? What language would that be? |
| 11:54 | sproingie | eh my day job is perl, so i'm used to crazy syntax all over |
| 11:54 | Fossi | Makoryu: you could define +: as a prefix + operation in scala |
| 11:54 | Makoryu | Fossi: Ah |
| 11:55 | Fossi | the last char in the name defines the binding |
| 11:55 | Fossi | excellent idea... |
| 11:55 | sproingie | +: would define a right-associative infix operator |
| 11:56 | sproingie | you can't really define new prefix operators, they're hardwired to +-! |
| 11:56 | sproingie | oh and ~ |
| 11:56 | Fossi | ah. well. same, same really |
| 11:57 | Fossi | pretty mad |
| 11:57 | vy | chouser: Any progress on " http://www.assembla.com/spaces/clojure/tickets/149-pop-does-not-preserve-meta-data (Actually, I'm just wondering the patch.) |
| 11:57 | vy | #149 |
| 11:57 | vy | pop does not preserve meta-data |
| 11:57 | Makoryu | I still think the APL family has the craziest syntax |
| 11:57 | sproingie | i thought it was kind of crazy that ending with : would make a method right-associative. sort of flies in the face of what you'd expect for an operator that looked smalltalkish |
| 11:57 | Fossi | and absolutely overengineered and artificial |
| 11:58 | Drakeson | liwp: thanks. |
| 11:58 | Makoryu | Every function, regardless of the name, is either prefix or infix |
| 11:59 | sproingie | J makes perl look like cobol |
| 11:59 | Makoryu | Yep |
| 11:59 | liwp | Drakeson: yeah, I don't think I've upgraded since my slime-macroexpand-all work just fine. It got broken when some stuff got moved from contrib to core |
| 11:59 | liwp | although it might have been fixed now in swank-clojure head |
| 12:01 | chouser | vy: had totally forgotten about it |
| 12:02 | chouser | liwp: how's that for low-hanging fruit? |
| 12:03 | somnium | I wonder how hard it would be to emulate ruby semantics with clojure, wrap hash-maps with method missing, convert instance vars to atoms. maybe use | as a delimiter instead of ; due to the reader. |
| 12:03 | liwp | chouser: I thought it would be relatively simple to implement |
| 12:04 | liwp | chouser: then I noticed that the current implementation special cases transients and I wasn't so sure anymore ;-) |
| 12:04 | chouser | ahhh. :-) |
| 12:04 | somnium | as an example for the conversion from OO battle. I'm assuming C-syntax to lisp and OO to functional are separate battles |
| 12:06 | liwp | chouser: if you don't mind calling (transient) and (persist!) separately for each collection then it's easy, but calling them only once for the into call requires some more thinking |
| 12:09 | liwp | how do i get git to tell me where my repo was cloned from? |
| 12:16 | weissj | liwp: look in .git/config |
| 12:16 | liwp | weissj: thanks. There's nothing like 'svn info'? |
| 12:16 | weissj | liwp: there might be a command to show you that as well, but i don't know what it it |
| 12:16 | weissj | is |
| 12:17 | liwp | ok, thanks |
| 12:18 | Chousuke | git remote show origin |
| 12:20 | liwp | Chousuke: thanks. I'm sure I've seen that before. |
| 12:20 | Chousuke | one of my favourite features of git is the ability to have multiple remotes |
| 12:21 | Chousuke | makes it easy to track multiple repositories :) |
| 12:21 | liwp | Chousuke: with clojure are you working with a direct clone of rich's github repository? |
| 12:21 | Chousuke | well, yes and no. |
| 12:22 | liwp | I had my own clone on github and I cloned my working copy from that, but I'm not sure if that's the right thing to do w.r.t. patches |
| 12:22 | Chousuke | I have rich's repo as origin but I have my own github fork as a remote called "public" :P |
| 12:22 | liwp | this is some sort of higher git magic that I haven't seen yet |
| 12:23 | Chousuke | it's not too difficult |
| 12:23 | liwp | so if you branch locally, do you push those branches then to your gh repo? |
| 12:23 | Chousuke | sometimes |
| 12:23 | Chousuke | some I keep local |
| 12:23 | liwp | that was my main reason for having my own clone on gh, that I could save my branches somewhere |
| 12:24 | Chousuke | if I make bugfixes and such I base them on origin/master but then for example my reader branch tracks public |
| 12:24 | liwp | makes sense |
| 12:24 | liwp | just yesterday I nuked my gh clone and now I'm thinking I should recreate it and do something similar to what you're doing |
| 12:25 | Chousuke | git help remote, then :) |
| 12:25 | liwp | yep, I'll need to do some reading |
| 12:25 | Chousuke | (well, actually it's just git remote add remotename url-here) |
| 12:26 | liwp | so you clone a working copy from rich's repo and then add another remote to it (for example)? |
| 12:26 | Chousuke | that's one way |
| 12:26 | Chousuke | the repos actually don't even have to be related :P |
| 12:26 | liwp | and is there some easy way to push branches back to the remote? I managed to make it work, but it didn't seem obvious to me |
| 12:27 | liwp | that makes sense, but is also slightly scary at the same time :) |
| 12:27 | Chousuke | git push remotename localbranch:remotebranch |
| 12:27 | Chousuke | you can also make a branch "track" a remote branch so that you can just "git push" and "git pull" |
| 12:27 | liwp | will that possibly give the branch a different name on the remote? |
| 12:27 | Chousuke | yeah |
| 12:28 | Chousuke | you can omit the :remotebranch if you don't need that |
| 12:28 | liwp | I think that's what I did last time (tracking), which is actually what I wanted |
| 12:28 | Chousuke | so most of the time just git push remote branch |
| 12:28 | Chousuke | many scary things are possible with git ;) |
| 12:29 | liwp | so a 'git push' after a 'git push remote branch' will not push the branch changes to the remote? |
| 12:29 | liwp | since the branch is not tracked? |
| 12:30 | Chousuke | correct. but you can always configure the defaults afterwards |
| 12:30 | liwp | that's nice |
| 12:30 | Chousuke | git config branch.<branchname>.remote and .merge or something IIRC. |
| 12:31 | liwp | so you would recommend keeping my own clone on gh? I tend to do stuff both at home and at work so being able to share the repo via gh is nice. |
| 12:31 | Chousuke | well, I won't recommend anything... but it's what I do. :P |
| 12:31 | liwp | I was just worried about patches in that scenario, but it seems that having rich's repo as another remote fixes that |
| 12:31 | liwp | :) |
| 12:32 | liwp | thanks, I'll think about it |
| 12:32 | liwp | gott go |
| 12:32 | liwp | s/gott/gotta/ |
| 12:33 | Chousuke | even with just one remote patches will not be a problem... unless you let your clone get too old so that you end up fixing things that are already fixed :P |
| 12:35 | liwp | Chousuke: I thought that might be the case, but I wasn't sure |
| 12:36 | liwp | I thought maybe the diff wouldn't apply in some cases if there were subtle changes so it would be safer to produce patches against the main repo |
| 12:36 | liwp | anyhow, now I really gotta go :) |
| 12:38 | danlei | about remote brances: I find it more convenient to "push origin foo", "co master" "branch -f foo origin/foo" that way, everything tracking is setup correctly and one hasn't got to mess with git config ... |
| 12:38 | Chousuke | -f? |
| 12:38 | danlei | force, yes |
| 12:39 | Chousuke | ah, right. |
| 12:39 | Chousuke | well, that's one way |
| 12:39 | danlei | the other thing works as well, of course, but I find it more convenient like this |
| 12:46 | steiger | (contains? [[1 2] [3 4]] [1 2]) -> false . is it a bug? |
| 12:48 | Chousuke | no. |
| 12:49 | Chousuke | contains? doesn't test whether a value is in a collection |
| 12:49 | Chousuke | it tests whether said collection has a value for a certain key :) |
| 12:49 | Makoryu | , (contains? {:foo bar} :foo) |
| 12:49 | clojurebot | java.lang.Exception: Unable to resolve symbol: bar in this context |
| 12:49 | Makoryu | , (contains? {:foo 'bar} :foo) |
| 12:49 | clojurebot | true |
| 12:50 | Makoryu | , true |
| 12:50 | clojurebot | true |
| 12:50 | steiger | oh |
| 12:50 | steiger | I see |
| 12:50 | Makoryu | ^ Is that defined as (def true 'true)? |
| 12:50 | steiger | the docs are a little bit confusing |
| 12:50 | Chousuke | Makoryu: no |
| 12:50 | Chousuke | Makoryu: it's special to the reader |
| 12:50 | Makoryu | Right |
| 12:50 | Chousuke | ,(class true) |
| 12:50 | clojurebot | java.lang.Boolean |
| 12:50 | Chousuke | ,(class 'true) |
| 12:50 | clojurebot | java.lang.Boolean |
| 12:50 | steiger | Chousuke: is there a function that tests wether a VALUE is present in the given collection? |
| 12:51 | Makoryu | ,(class 'pizza) |
| 12:51 | Chousuke | hmm |
| 12:51 | clojurebot | clojure.lang.Symbol |
| 12:51 | Chousuke | steiger: I'm actually not sure about that. |
| 12:51 | hiredman | (.contains '(1 2 3) 2) |
| 12:51 | hiredman | ,(.contains '(1 2 3) 2) |
| 12:51 | clojurebot | true |
| 12:51 | Chousuke | oh, right, the Collection method :) |
| 12:51 | hiredman | ,(.contains '(1 2 3) 3) |
| 12:51 | clojurebot | true |
| 12:52 | steiger | hm, java contains |
| 12:52 | steiger | thank you guys |
| 12:58 | ben_m | Anyone have some example code for using sdljava with Clojure? |
| 13:31 | scottj | I often have trouble recognizing when to use map, reduce, loop, for, or lazy seqs that iterate or something. Anyone know of a tutorial (not necessarily in clojure, other functional languages would be fine) that focuses on helping imperative programmers to recognize when to use these methods? |
| 13:31 | ben_m | I've got a class Foo and a method bar that returns void (java interop). I'd like to create an object of Foo and call the method on it but return the created object, not the return value of bar ... is that possible? |
| 13:32 | vy | ben_m: What's wrong with (do (.bar foo) foo)? |
| 13:32 | ben_m | uh |
| 13:32 | sproingie | scottj: find out what the sources of events in your program are. now picture them as an infinite stream of events. |
| 13:33 | ben_m | vy: Not familiar with do, so I don't know. I'll look it up |
| 13:33 | sproingie | scottj: basically anything you can visualize as a timeline of state changes or events or messages or whatever you can convert to a sequence |
| 13:36 | sproingie | reduce is handy for consuming a stream whenever you need to keep the previous state handy. probably not as necessary with STM tho. |
| 13:36 | sproingie | *a stream of states |
| 13:38 | ambient | i wonder if asynchronous events will map 1-1 into seqs |
| 13:39 | ambient | it's something i've still yet to wrap my head around in fp |
| 13:42 | scottj | sproingie: thanks, but I guess what I'm looking for is a tutorial that breaks down common ways of using for/while loops and shows how to do them in fp |
| 13:42 | sproingie | you can block on a read of the event queue. there are probably better high-level constructs for that tho |
| 13:43 | sproingie | i'm not entirely sure what they are myself. i'm only halfway-FP myself :) |
| 13:49 | technomancy | scottj: reduce is for when you want one value from a sequence; map is to transform one sequence into another. |
| 13:49 | sproingie | scottj: you can always break down for/while into recursion, which we have loop/recur for |
| 13:50 | technomancy | scottj: for is just syntax-sugar for map |
| 13:50 | technomancy | doseq is like for, but intended for side-effects |
| 13:50 | sproingie | technomancy: reduce is also good when you never need the value back, but you want to derive the next action from the previous one |
| 13:50 | sproingie | you can get a pipeline by reducing apply over functions, for example |
| 13:50 | technomancy | sure |
| 13:50 | ambient | doseq doall and dorun still confuse me |
| 13:51 | technomancy | or when you need something more specific (map, set) than a seq from a sequence |
| 13:51 | sproingie | right, like for building a tree |
| 13:52 | sproingie | cons an empty tree onto the list and reduce the insert func over it |
| 13:52 | technomancy | sproingie: reduce takes an optional initial value; no need to conj it to the list |
| 13:53 | sproingie | yah i haven't translated all my idioms to clojure yet :) |
| 13:54 | ben_m | Is there something like an infinite loop in clj? (gameloop in my case) |
| 13:54 | sproingie | more useful with the optional arg since you don't have to screw up a nice homogeneous collection that way |
| 13:54 | sproingie | ben_m: a loop/recur with no base case |
| 13:54 | sproingie | or a for or reduce over an infinite sequence |
| 13:54 | chouser | ben_m: (fn [] (recur)) or (while true ...) |
| 13:54 | ben_m | Ah, didn't know while exists. Thank you :) |
| 13:55 | sproingie | or just plain while, yah. havent memorized the API yet :) |
| 13:55 | sproingie | ben_m: http://clojure.org/api |
| 13:55 | chouser | 'while' is very rarely used |
| 13:55 | ben_m | I think the best way would be to use loop, since i'm using let anyways |
| 13:55 | sproingie | actually that probably doesn't have control structures in it, since those are usually special forms |
| 13:55 | chouser | but it yells "imperative" which can be useful |
| 13:55 | sproingie | but that page has a link to those |
| 13:56 | technomancy | anyone want to fix up swank-clojure's eldoc to indicate macros differently? |
| 13:56 | technomancy | or am I going to have to implement that myself? =) |
| 13:57 | sproingie | just don't infinitely loop by mapping over an infinite sequence. unless you like space leaks :) |
| 13:57 | chouser | map will just return a lazy seq and do nothing. |
| 13:58 | sproingie | something would have to consume that. which i guess can't be map. |
| 13:59 | chouser | right. would have to be something like (loop [xs (map ...)] (recur (next xs))) ... which wouldn't leak anything |
| 13:59 | Drakeson | what does (remove-ns 'swank.commands.completion) do at the begining of the file? |
| 14:00 | chouser | though it would churn memory needlessly. |
| 14:00 | chouser | (doc remove-ns) |
| 14:00 | clojurebot | "([sym]); Removes the namespace named by the symbol. Use with caution. Cannot be used to remove the clojure namespace." |
| 14:01 | Drakeson | it is being used before defining (na swank.commands.completion ...), and I don't understand the intent |
| 14:03 | Drakeson | (not to mention that swank completion is broken here, since the revision from around Sept 15) |
| 14:04 | technomancy | Drakeson: can you give an example of the breakage? |
| 14:04 | ben_m | Trying to do SDL programming with Clojure is pretty hard if you don't know Clojure that well and sdljava is pretty ... strange. |
| 14:05 | Drakeson | technomancy: I am looking at swank_c_p_c.clj, (a small file) |
| 14:07 | Drakeson | in the definition of `completions' there is a try..catch that aborts the completion in case of any error. I change it to actually see the error. |
| 14:07 | Drakeson | (well, I forget to say, the initial problem was that I was getting no completions) |
| 14:08 | Drakeson | the error message was this: "java.lang.IllegalStateException: Var swank.commands.completion/potential-completions is unbound." |
| 14:08 | sproingie | so when i hit C-c C-k in slime and it tells me there are errors, how do i make it actually show me the error? |
| 14:08 | technomancy | sproingie: they should be shown in the *inf-lisp* buffer |
| 14:09 | hoeck | ben_m: you can try processing, there is rosado's clj-processing, a thin clojure wrapper around it, using it with success for a small clojure space duel game |
| 14:10 | technomancy | clj-processing is awesome |
| 14:10 | ben_m | Oh, I've heard about processing. |
| 14:10 | ben_m | I'll take a look at it, thank you :) |
| 14:10 | technomancy | might not be as performant as sdl |
| 14:10 | sproingie | shown and then some. massive traceback obscures the actual error |
| 14:10 | ben_m | sdljava is a pain to use ... I'm getting a link error now for some reason |
| 14:11 | ambient | i could be possible just to use java sound and io api, plus straight opengl |
| 14:11 | ambient | or jmonkeyengine |
| 14:11 | Drakeson | I just copied the functions from swank.commands.completion into swank_c_p_c.clj, and it works. I just don't understand the mechanism that is supposed to load the stuff in swank.commands.contrib/ |
| 14:13 | ben_m | ambient: Can't use OpenGL at the moment because my video card broke :/ |
| 14:14 | ben_m | Else I'd probably use one of the available Java game libraries |
| 14:15 | Drakeson | is the line (remove-ns 'swank.commands.completion) at the begining of swank.commands.completion really necessary? |
| 14:16 | technomancy | Drakeson: my guess is that it's not necessary for regular usage, but it might be needed to hack on swank-clojure itself interactively |
| 14:16 | technomancy | I'm not too familiar with the completion mechanism though; I find that "dumb" dabbrev is enough for me |
| 14:17 | Drakeson | when I remove it, it can successfully load swank.commands.contrib.swank-c-p-c. |
| 14:18 | Drakeson | it is not really a matter of completion. I just don't understand what that defslimefn swank-require in swank/commands/contrib.clj was supposed to work. |
| 14:18 | Drakeson | it might be missing something |
| 14:18 | deafmacro | Hi! I tried righting "member?" to get a hang of using loop/recur. I would appreciate it if someone could review it. Here's the link http://pastie.org/639697 |
| 14:20 | Chousuke | the x loop parameter is redundant :) |
| 14:20 | Chousuke | otherwise that should be okay. |
| 14:21 | Chousuke | though, (some (partial = x) coll) does the job :P |
| 14:21 | ben_m | How do I fix an UnsatisfiedLinkError? |
| 14:22 | ben_m | Do I miss something on the classpath, or .. ? |
| 14:22 | deafmacro | Chousuke: ah true :) |
| 14:22 | Drakeson | wow! I didn't know about java completion in swank ... that's neat. |
| 14:23 | technomancy | Drakeson: I heard about that but haven't gotten a chance to take a look yet |
| 14:23 | technomancy | imho that's much more valuable than lisp-level completion. =) |
| 14:24 | deafmacro | Chousuke: but I would still have to bind write (loop [coll coll] ... since it requires even args? |
| 14:24 | ben_m | I thought defn is like an implicit loop? |
| 14:25 | Drakeson | technomancy: it does not complete java.lang.Inte<TAB>, yet, but it completes java.lang.Integer/<TAB> |
| 14:25 | technomancy | cool |
| 14:26 | technomancy | is that using the same C-c TAB? |
| 14:26 | Drakeson | no, just TAB |
| 14:26 | technomancy | Drakeson: you must have rebound it; needs C-c TAB here |
| 14:26 | technomancy | TAB is for indentation. =) |
| 14:26 | Drakeson | well, I am in repl now |
| 14:27 | ambient | I do C-c I for Java classes, which inspects them. almost as good as completion, but not quite. don't know of a better way |
| 14:27 | technomancy | Drakeson: oh, gotcha. |
| 14:27 | technomancy | C-c I is really great too |
| 14:32 | deafmacro | Chousuke: never mind. figured it out. thanks! |
| 14:37 | durka42 | deafmacro: you have a brilliant username. that is all. |
| 14:53 | ben_m | Is there a way to import everything from a namespace? |
| 15:07 | weissj | can someone recommend a library or strategy for storing clojure data in a db? i am working on a defect tracking system, one feature i intend to have is user-created record types, so it's a bit more dynamic than straight db tables. |
| 15:08 | weissj | i checked out clj-record, that might work for me, is there anything else? |
| 15:09 | tmountain | weissj: strategies for storing data, or data serialization? |
| 15:09 | weissj | storing data |
| 15:11 | weissj | the data structure isn't complex, but i want it to be dynamic - can remove fields from a record or add them during runtime |
| 15:11 | tmountain | weissj: AFAIK, clojure-contrib has a sql library (JDBC wrapper), there's persist (Java lib), and also Berkeley DB |
| 15:11 | tmountain | weissj: BDB is more of a key / value store IIRC |
| 15:11 | weissj | tmountain: yeah that's a bit too simple for my purposes |
| 15:14 | tmountain | weissj: have you seen datalog? |
| 15:27 | roberto_ | ping |
| 15:34 | chouser | (.show (proxy [java.awt.Frame] [] (paint [g] (dotimes [y 256] (dotimes [x 256] (.setColor g (#(java.awt.Color. % % %) (bit-xor x y))) (.fillRect g x y 1 1)))))) |
| 15:36 | chouser | also nice with bit-and or bit-or instead of bit-xor |
| 15:46 | crios | 'night |
| 15:47 | ambient | how would i go about making a graphics element into a repl that i could asynchronously draw different stuff? like (start-graphics g) (draw-line g 10 10 20 20) etc... |
| 15:50 | chouser | ambient: (def g (.getGraphics (doto (java.awt.Frame.) .show))) |
| 15:51 | chouser | position that window so you can type into your repl with obscuring it |
| 15:51 | chouser | then: (.drawLine g 100 100 200 200) |
| 15:51 | ben_m | When I try to compile my program (clj -cp /usr/share/java/sdljava.jar sdl.clj) I get the following error: "Exception in thread "main" java.lang.UnsatisfiedLinkError: sdljava.x.swig.SWIG_SDLEventJNI.new_SDL_Event()J (sdl.clj:1)" Code: http://sprunge.us/KJJC |
| 15:52 | ambient | chouser thanks :) |
| 15:52 | chouser | ben_m: you have to have the swig-generated .so in your OS library path. I think that's the most likely cause. |
| 15:53 | ambient | my previous attempt was to draw a line (10 10 20 20) which I thought didn't work because it was drawn under the window border |
| 15:54 | ben_m | chouser: sigh ... :/ |
| 15:54 | chouser | (.show (proxy [java.awt.Frame] [] (paint [g] (dotimes [y 256] (dotimes [x 256] (->> (+ (* x x) (* y y)) (* 0.01) Math/sin inc (* 127) int (#(java.awt.Color. % % %)) (.setColor g)) (.drawLine g x y x y)))))) |
| 15:56 | ben_m | What's that ->>? |
| 15:56 | chouser | It's a macro a bit like -> |
| 15:57 | chouser | (->> a (foo b) (bar c)) becomes (bar c (foo b a)) |
| 15:57 | chouser | that is, each expression is inserted as the last arg of the next expression |
| 15:58 | ben_m | Did you define it, or is that in Clojure? |
| 15:58 | chouser | it's new, in Clojure |
| 15:58 | ben_m | ooh :) |
| 15:58 | chouser | (doc ->>) |
| 15:58 | clojurebot | excusez-moi |
| 15:59 | chouser | too new for clojurebot |
| 15:59 | ben_m | too new for me too :) |
| 16:12 | hiredman | clojurebot: ant? |
| 16:12 | clojurebot | is equivilant to addresing the bot by name is equivilant to addresing the bot by name |
| 16:12 | hiredman | clojurebot: ant is dumb |
| 16:12 | clojurebot | You don't have to tell me twice. |
| 16:13 | hiredman | ugh |
| 16:14 | hiredman | I've started to see errors like java.lang.NoSuchMethodError: clojure.lang.RestFn: method <init>()V not found (fnparse.clj:1) everywhere |
| 16:15 | chouser | hiredman: clean and rebuild fnparse, probably. |
| 16:15 | hiredman | that was from starting clojurebot just now, but I have was seeing something very similar when trying to get ant to build something for appengine |
| 16:15 | hiredman | and fnparse was not used there |
| 16:16 | chouser | I see those all the time from contrib because I keep hoping between various versions of clojure. |
| 16:16 | chouser | hopping |
| 16:17 | hiredman | ah |
| 16:17 | hiredman | the error went away when I rebuilt contrib |
| 16:17 | hiredman | ,(doc ->>) |
| 16:17 | clojurebot | "([x form] [x form & more]); Threads the expr through the forms. Inserts x as the last item in the first form, making a list of it if it is not a list already. If there are more forms, inserts the first form as the last item in second form, etc." |
| 16:18 | hiredman | damn |
| 16:18 | hiredman | sorry |
| 16:18 | kotarak | huh? ->>? hoorray! |
| 16:21 | chouser | , (->> (range 256) (filter #(or (<= 65 % 90) (<= 97 % 122))) (map char) (apply str)) |
| 16:22 | chouser | oh, whoops |
| 16:22 | chouser | ,(->> (range 256) (filter #(or (<= 65 % 90) (<= 97 % 122))) (map char) (apply str)) |
| 16:22 | clojurebot | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" |
| 16:22 | hiredman | handy dandy |
| 16:22 | ambient | ,(* 0.01745329252 180) |
| 16:22 | clojurebot | 3.1415926536 |
| 16:23 | crios | clojurebot: logs |
| 16:23 | clojurebot | logs is http://clojure-log.n01se.net/ |
| 16:25 | chouser | ,(.show (java.awt.Frame.)) |
| 16:25 | clojurebot | java.awt.HeadlessException: No X11 DISPLAY variable was set, but this program performed an operation which requires it. |
| 16:25 | chouser | oh, right. |
| 16:27 | crios | hi, I already posted this question but it seems it get lost in the net: did anyone read "Structure and Interpretation of Computer Programs", by Abelson, Sussma? If yes, do you think it could be an worth introductory "clojure" concepts textbook? |
| 16:28 | crios | [this one: http://mitpress.mit.edu/sicp/full-text/book/book.html] |
| 16:28 | ambient | i've read some of it and it has helped |
| 16:28 | johnmn31 | when doing (defn add1 [x] (+ x 1)) |
| 16:28 | kotarak | someone made a blog with translations of the code. (maybe the book-Stuart?) |
| 16:28 | crios | I believe, for a Java programmer an introductory "Lisp" world book would help |
| 16:29 | crios | thanks ambient |
| 16:29 | johnmn31 | does this "expand" at runtime to (defn add1 ([x] (+ x 1))) ? |
| 16:29 | kotarak | crios: touch yourself scheme in fixnum days |
| 16:29 | kotarak | teach |
| 16:29 | hiredman | johnmn31: no |
| 16:29 | ambient | clojure doesn't just have functional style, it has immutable data structures and strong concurrency constructs |
| 16:30 | crios | kotarak: "fixnum days" ? |
| 16:30 | johnmn31 | hiredman: well, defn "expands" to (def (fn [.. right? |
| 16:30 | ambient | crios it's going to take a lot of work (at least it did for me) to grok it all, but i think it's worth it |
| 16:30 | johnmn31 | I mean (def foo (fn [... |
| 16:31 | crios | kotarak: I got it: http://www.ccs.neu.edu/home/dorai/t-y-scheme/t-y-scheme-Z-H-1.html |
| 16:31 | kotarak | crios: well, I didn't choose the title. ;) In Scheme numbers are stored in fixnums, that is in 32 (or 64) bit. When the grow larger they are saved in Bignums. |
| 16:31 | hiredman | johnmn31: yes |
| 16:31 | johnmn31 | k thanks |
| 16:32 | arohner | is there a clojure.contrib fn for calling (read) on a string? |
| 16:32 | kotarak | crios: it's for Scheme, but that should be sufficient for lispiness. |
| 16:32 | hiredman | johnmn31: macroexpand and macroexpand-1 |
| 16:32 | kotarak | ,(doc read-string) |
| 16:32 | clojurebot | "([s]); Reads one object from the string s" |
| 16:32 | ambient | crios you've looked at this, right? http://java.ociweb.com/mark/clojure/article.html |
| 16:32 | arohner | kotarak: thanks |
| 16:32 | arohner | that's new since the last time I needed to do this |
| 16:33 | crios | ambient: yes, and read also "Clojure Programming". But I feel I'm missing something |
| 16:33 | ambient | just write some code |
| 16:34 | johnmn31 | hiredman: tried that, but (macroexpand add1) didn't get me what I expected. |
| 16:34 | hiredman | johnmn31: that is not how you use macroexpand |
| 16:35 | kotarak | ,(macroexpand-1 '(defn add1 [x] (+ x 1))) |
| 16:35 | clojurebot | DENIED |
| 16:35 | crios | ambient: yes, I write some code, but I feel I miss perhaps the right "conceptual" world's view - a shared vocabulary |
| 16:35 | ambient | sicp lectures were quite eye opening in some parts |
| 16:35 | johnmn31 | ah, ok, I forgot the ' |
| 16:36 | crios | ambient: ok, I'll read it (keeping to check also your blogs and chat, sure :) ) |
| 16:37 | johnmn31 | ahah! it does add parens: |
| 16:37 | johnmn31 | (def add1 (clojure.core/fn ([x] (+ x 1)))) |
| 16:38 | hiredman | but not in the defn form |
| 16:38 | johnmn31 | so one could make mulit-arity lambdas as well then... |
| 16:39 | hiredman | sure |
| 16:39 | johnmn31 | sweet |
| 16:41 | chouser | Revenue on T-shirt sales is rolling in at a steady clip of about $2.50 per month. |
| 17:35 | ambient | does clojure in future have some more revealing ways of communicating about errors? |
| 17:36 | ambient | im just having a bit of a difficulty in debugging |
| 17:36 | ambient | (which is happily easier in functional style because i can test each piece of my program separately) |
| 17:40 | arbscht | ambient: c.c.trace can help debugging in some cases |
| 17:47 | hiredman | wheee |
| 17:47 | hiredman | appengine app built (hello world page) |
| 17:48 | hiredman | and it runs on the local dev server thing |
| 17:48 | ambient | with clojure? grats |
| 17:48 | arbscht | compojure? |
| 17:48 | hiredman | yeah |
| 17:48 | arbscht | neat. a few people have been doing that lately |
| 17:49 | hiredman | the shellscript for launching the local dev server of course has #!/bin/bash but if you change it to #!/bin/sh it runs fine |
| 17:49 | ambient | hmm, i wonder how that works in windows... |
| 17:49 | ambient | probably not at all |
| 17:49 | hiredman | there is a seperate .cmd script for launching it on windows |
| 17:50 | ambient | got to try that someday soon |
| 17:50 | ambient | on my list of things to do |
| 17:51 | hiredman | I followed a howto I fould googling "clojure appengine" |
| 18:07 | somnium | hiredman: do you have the repl setup for it? |
| 18:07 | somnium | http://www.hackers-with-attitude.com/2009/08/intertactive-programming-with-clojure.html |
| 18:08 | somnium | it shows how to setup the appeninge api for the thread you run the devserver in, so you do live lispy development without any recompiles locally |
| 18:09 | ben_m | Alright guys, this is driving me insane. |
| 18:10 | ben_m | I've got /usr/share/sdljava.jar and a lot of *.so files in /usr/lib/sdljava/ ... I try to run a little example like this: clj -Djava.library.path=/usr/lib/sdljava/ -cp /usr/share/java/sdljava.jar SDL.clj |
| 18:10 | ben_m | When I leave out the -D line, I get an UnsatisfiedLinkerError |
| 18:10 | ben_m | When I include it, I get Exception in thread "main" java.io.FileNotFoundException: -Djava.library.path=/usr/lib/sdljava/libsdljava.so (No such file or directory) |
| 18:11 | ben_m | Without the libsdljava.so at the end, that was the wrong line I pasted, but yeah, same error |
| 18:11 | ambient | "/usr/share/sdljava.jar" "/usr/share/java/sdljava.jar" different directory |
| 18:11 | ben_m | ambient: I'm using the right ones when I try it, sorry. |
| 18:11 | ben_m | Just typed them here incorrectly. |
| 18:13 | ambient | are the binaries compatible? |
| 18:14 | ambient | JVM & libsdljava.so etc |
| 18:14 | ambient | i got some weird errors using 32 bit libs in 64 bit environment |
| 18:15 | ben_m | uhm |
| 18:15 | ben_m | All the .so files are 32bit libs, and I'm on 32 bit too. |
| 18:17 | ben_m | Errors + Source + commands I run: http://sprunge.us/ZdTU |
| 18:21 | ambient | i wonder how two -cp commands work in java executalbe, do they replace or concatenate |
| 18:21 | ambient | it might be in the clj script, just a thought |
| 18:22 | hiredman | yeah |
| 18:22 | hiredman | the clj script is trying to pash the -D stuff as a file name argument to java |
| 18:22 | hiredman | pass |
| 18:22 | hiredman | use java -Dwhatever directly |
| 18:31 | ben_m | I'll try. |
| 18:33 | ben_m | I get the same UnsatisfiedLinkError :( |
| 19:24 | somnium | is there support for variable arity multimethods? |
| 19:27 | arbscht | somnium: yes |
| 19:28 | somnium | could you give a simple example? I wasn't able to improvise the syntax |
| 19:30 | somnium | (defmulti foo (fn (....) (....)) and then (defmethod foo ([a] ...) ([a b] ...)) ? |
| 19:31 | arbscht | http://gist.github.com/200252 |
| 19:32 | somnium | ah, thank you |
| 19:56 | rsynnott | anyone know is there a way to view repl history in enclojure with keyboard shortcuts? |
| 20:01 | danlei | ctrl+uparrow |
| 20:02 | danlei | (if you meant input hist) |
| 20:03 | danlei | plain pgup otherwise |
| 20:06 | rsynnott | ah, thanks :) |
| 20:07 | rsynnott | CTRL-SHIFT-UP on the mac, oddly |
| 20:07 | rsynnott | (I'm mostly an EMACS/slime person, but giving this thing a go) |
| 20:08 | danlei | I have it installed, but use emacs almost exclusively (wanted to know at least one alternative) |
| 21:16 | cschreiner | clojure needs to be distributed together with emacs as a one-install-package targeted newcomers |
| 21:17 | hiredman | ~google clojurebox |
| 21:17 | clojurebot | First, out of 28 results is: |
| 21:17 | clojurebot | Clojure Box, alpha - Clojure | Google Groups |
| 21:17 | clojurebot | http://groups.google.com/group/clojure/browse_thread/thread/6fd17fb97f058192 |
| 21:18 | cschreiner | for mac? |
| 21:18 | arbscht | iirc, clojure-mode has an install routine that makes it quite easy to get started |
| 21:19 | cschreiner | arbscht: you're missing my point |
| 21:20 | cschreiner | it's too easy to get lost in emacs |
| 21:20 | cschreiner | but when you get use to it, it rocks the world |
| 21:21 | cschreiner | and when you are adding "common" components, like compojure, or this 3d thing, I don't recall; (penumbra?) you have to deal with the ugliness of classpaths, in addition! |
| 21:22 | Raynes | If you want to use Emacs, you're probably better being committed to learning Emacs, rather than wanting and expecting to be spoon-fed Emacs with a dumbed down installation. If you don't want to learn Emacs, Enclojure is always an option. |
| 21:22 | arbscht | I'm not convinced there is any way around that -- such is emacs. even if there was, it has little to do with clojure, which is independent of any editor |
| 21:22 | cschreiner | from the perspective of a beginner, this is daunting |
| 21:23 | albino | emacs is like any other piece of technology, the learning curve has a pay off |
| 21:23 | arbscht | a beginner would do well to learn emacs first, or avoid it altogether |
| 21:23 | albino | I would vote for avoidance so you're not trying to learn two big technologies at the same time, but that's just me |
| 21:23 | Raynes | arbscht: Exactky. |
| 21:23 | cschreiner | my point is to get up and running with clojure (with most of the libraries preinstalled) in as little time as possible |
| 21:23 | Raynes | exactly* |
| 21:24 | Raynes | cschreiner: Then you would want to just install Enclojure. |
| 21:24 | Raynes | Or Clojure-dev, or whatever. |
| 21:24 | cschreiner | but are they good? |
| 21:24 | cschreiner | and what about customization? |
| 21:24 | arbscht | they're suited to your constraint :) |
| 21:24 | Raynes | Enclojure is fine, Clojure-dev leaves a lot to be desired, and La Clojure is pretty good. |
| 21:25 | cschreiner | ~google enclojure |
| 21:25 | clojurebot | First, out of 248 results is: |
| 21:25 | clojurebot | enclojure - home |
| 21:25 | clojurebot | http://enclojure.org/ |
| 21:25 | Raynes | cschreiner: You need to decide what you want. Do you want superpowers and customization, or do you want to get up and running with Clojure really fast? |
| 21:26 | Raynes | You can't really have one or the other unless you're already an Emacs user. ;) |
| 21:26 | cschreiner | first up and running, then superpowers |
| 21:26 | cschreiner | everybody wants to have superpowers |
| 21:26 | cschreiner | most geeks anyway |
| 21:29 | cschreiner | enclojure seems to suit my needs, thx |
| 22:25 | Drakeson | how can I get a lazy random sequence? |
| 22:28 | chouser | ,(take 20 (repeatedly #(rand-int 100))) |
| 22:28 | clojurebot | (45 59 66 15 15 27 40 4 29 10 74 77 17 99 17 12 13 33 31 83) |
| 22:29 | Drakeson | thanks |
| 23:32 | Drakeson | how can I apply a function to all vals of a hashmap and obtain a "transformed" hashmap? |
| 23:33 | chouser | ,( |
| 23:33 | clojurebot | EOF while reading |
| 23:34 | chouser | ,(let [m {:a 1, :b 2, :c 3}] (zipmap (keys m) (map #(* 5 %) (vals m)))) |
| 23:34 | clojurebot | {:c 15, :b 10, :a 5} |
| 23:35 | Drakeson | right now I am doing (defn map-map [h f] (apply hash-map (mapcat (fn [[k v]] [k (f v)]) h))), which looks inefficient |
| 23:35 | Drakeson | chouser: thanks |
| 23:35 | Drakeson | is there a function for that? |
| 23:39 | kevin__ | are (keys m) and (vals m) going to have a stable ordering? |
| 23:42 | slashus2 | only in a sorted-map |
| 23:42 | slashus2 | well.. |
| 23:44 | kevin__ | that's what i figured, so calling them seperatly to map a hash would be unsafe right? |
| 23:46 | slashus2 | ,(keys (apply hash-map [6 8 1 2 3 4 5 6])) |
| 23:46 | clojurebot | (1 3 5 6) |
| 23:46 | slashus2 | I am not sure... hmm |
| 23:46 | hiredman | ,(let [h {:a 1 :b 2} f (fn [f v] (reduce #(conj %1 [(key %2) (f (val %2))]) {} v))] (f inc h)) |
| 23:46 | clojurebot | {:b 3, :a 2} |
| 23:49 | slashus2 | ,(keys (apply hash-map [:c 8 :a 2 :b 4 :d 6])) |
| 23:49 | clojurebot | (:a :c :b :d) |
| 23:49 | slashus2 | ,(keys (apply sorted-map [:c 8 :a 2 :b 4 :d 6])) |
| 23:49 | clojurebot | (:a :b :c :d) |
| 23:50 | ngoc | How to remove element from a hash? I can use "remove", but it is long way because it takes a function. |
| 23:50 | kevin__ | ,(let [h {:a 1 :b 2 :c 3 :d 4}] [(keys h) (vals h)]) |
| 23:50 | clojurebot | [(:a :b :c :d) (1 2 3 4)] |
| 23:50 | kevin__ | ,(let [h (apply hash-map [:a 1 :b 2 :c 3 :d 4])] [(keys h) (vals h)]) |
| 23:50 | clojurebot | [(:a :c :b :d) (1 3 2 4)] |
| 23:51 | hiredman | ngoc: dissoc |
| 23:51 | kevin__ | same wrong order this time, i guess that's ok |
| 23:51 | slashus2 | :-( |
| 23:53 | ngoc | hiredman: thanks |
| 23:53 | kevin__ | i was concerned that since they were unordered, keys and vals might be unordered in different ways |
| 23:54 | kevin__ | so if you zipmap'ed them back you would associate the wrong keys and vals |
| 23:55 | hiredman | some future IPMap migth do that |
| 23:59 | ngoc | hiredman: I also notice that "remove" changes the class of the hash to sequence |
| 23:59 | ngoc | (def h {:a 1, :b 2}) |