2009-10-21
| 00:15 | Calamitous | I have a newb question if anybody has a moment :) |
| 00:16 | Calamitous | I have a list of data [1 2 3]-- I'd like to send the elements of the list as params for a method (defn foo [& a] ... so that it comes out as though calling (foo 1 2 3) |
| 00:16 | Calamitous | but the method only acts as those I'm passing a single param (foo [1 2 3]) |
| 00:17 | Calamitous | Is there a way to pass the list elements in as individual params? |
| 00:17 | Calamitous | or am I completely barking up the wrong tree? |
| 00:19 | mikehinchey | apply |
| 00:20 | mikehinchey | ,(apply + [1 2 3]) |
| 00:20 | clojurebot | 6 |
| 00:20 | Calamitous | oh i gotcha |
| 00:21 | Calamitous | kewl, thanx! :D |
| 01:05 | tomoj | is there an idiomatic way to "loop" through a seq with indices? |
| 01:12 | slashus2 | tomoj: I guess you could use doseq and use range. What are you trying to do? |
| 01:13 | tomoj | I don't see how doseq would do it |
| 01:13 | cgrand | tomoj: there's indexed somewher in contrib. But iterating over a seq with indices isn't idiomatic. |
| 01:13 | tomoj | right |
| 01:13 | hiredman | (map (fn [v i]) some-seq (iterate inc 0)) |
| 01:13 | tomoj | sometimes I've needed to do it, though |
| 01:13 | tomoj | hiredman: ah, yes :) |
| 01:14 | cgrand | tomoj: agreed, sometimes you need it, often for interop |
| 01:16 | slashus2 | What do you all think of these macros? http://paste.lisp.org/display/89023 |
| 01:16 | tomoj | now I can't remember why I wanted it before |
| 01:17 | slashus2 | I have been pondering over the second macro. |
| 01:18 | slashus2 | Maybe it is my bad habits, but I sometimes find that I need to do side-effects inside transactions. This seems to do the trick. I would like to add the option to specify whether you want to do a send or send-off. |
| 01:20 | slashus2 | The first one I found useful for replacements of the while (n = something > 5) { interop thing |
| 01:20 | tomoj | aren't transactions exactly where you want to be doing side-effects? |
| 01:20 | tomoj | oh, you mean like printing stuff |
| 01:20 | slashus2 | You shouldn't do side effects in transactions because it may repeat. |
| 01:20 | slashus2 | But the transactions only sends to agents when the transaction is complete. |
| 01:20 | slashus2 | send* |
| 01:21 | tomoj | I count mutating state as a side effect. is it not? |
| 01:21 | hiredman | it is |
| 01:21 | cgrand | slashus2: Why do you introduce a pred# and use resolve? |
| 01:21 | hiredman | but you don't do that in a transaction |
| 01:21 | tomoj | you don't mutate state in a transaction? |
| 01:22 | tomoj | I thought that's what transactions were for? |
| 01:22 | hiredman | you take a an immutable value, produce a new immutable value, and when the transaction succeeds the new value is swapped in for the old |
| 01:22 | slashus2 | cgrand: Because I am not very good at writing macros... :-P It is when you actually take the pred argument as data. It needs to be resolved as a function. I think at least. |
| 01:22 | tomoj | yes.. that sounds like mutating state to me |
| 01:22 | hiredman | no |
| 01:23 | slashus2 | It is actually an atomic operation of pointing to a new object with potentially shared components. |
| 01:23 | cgrand | You shouldn't do *unmanaged* side effects in transactions because it may repeat. (managed side effects being send/send-off and anything that change refs) |
| 01:23 | tomoj | so it's atomic and the values are immutable, you're still changing the state, right? |
| 01:23 | hiredman | not within the transaction |
| 01:23 | tomoj | oh, I see |
| 01:24 | slashus2 | cgrand: Do you see where the when-commit macro could be useful? It even allows you to specify your own agent when needed. |
| 01:26 | cgrand | slashus2: haven't looked at it yet |
| 01:26 | slashus2 | okay |
| 01:27 | technomancy | tomoj: I've wanted doseq + counter like three times in the last week |
| 01:28 | technomancy | considering a patch to add it |
| 01:28 | technomancy | I'm using indexed right now, but adding it as another keyword arg to doseq/for would reflect intentions much more clearly. |
| 01:30 | tomoj | like (for [x aseq :index i] ...)? |
| 01:30 | slashus2 | Have you all ran into the case that my when-let macro solves a lot? |
| 01:30 | cgrand | slashus2: http://paste.lisp.org/display/89023#1 |
| 01:31 | slashus2 | Can't believe I missed that. Sometimes destructed binding skips my mind. |
| 01:33 | slashus2 | cgrand: Looks wonderful. Thank you. |
| 01:36 | slashus2 | cgrand: I don't think your second macro down there works properly. |
| 01:36 | slashus2 | neither one |
| 01:43 | slashus2 | cgrand: http://paste.lisp.org/display/89023#2 I think this fixes it. |
| 01:44 | slashus2 | Or you could do without the apply and your version would work. |
| 01:45 | cgrand | slashus2: right, apply here is plain wrong |
| 01:46 | cgrand | but I can't spot what you changed |
| 01:46 | cgrand | without apply http://paste.lisp.org/display/89023#3 |
| 01:46 | slashus2 | Instead of ~@, I did '~ |
| 01:46 | slashus2 | Meaning it still was in the list form |
| 01:46 | slashus2 | so apply could work on its contents. |
| 01:47 | slashus2 | Is the when-let macro well constructed? |
| 01:47 | slashus2 | I mean |
| 01:47 | slashus2 | when-commit |
| 01:51 | slashus2 | I am going to try to get Clojure working on a SR4 robot tomorrow. Need to figure out how to get clojure on the robot's module loader classpath. |
| 01:52 | hiredman | clojurebot: how can slashus2 get clojure on to the robot's classpath? |
| 01:52 | cgrand | ah ok, don't do that ('~) :-) and remove apply instead. '~ (and the induced resolve you had earlier) wouldn't behave like you expect: try with your last while-let: (while-let [x 0 > (+ 0 0)] (println "hello")) |
| 01:52 | clojurebot | clojure is a language to use if you want to up your game |
| 01:52 | hiredman | hmmmmm |
| 01:53 | hiredman | that was an awful lot of cpu time for that |
| 01:53 | slashus2 | cgrand: That is true.... |
| 01:54 | slashus2 | hiredman: Yes. I have to extend some DefaultModule class to be able to initialize the module. It sends the kernel's module loader to it. |
| 01:55 | slashus2 | Thought it would be cool to write a module using clojure. |
| 01:57 | hiredman | lisp is the language of ai |
| 01:58 | hiredman | something in clojurebot's fuzzy lookup logic is burning more cycles than I would like |
| 01:58 | cgrand | slashus2: http://paste.lisp.org/display/89023#4 you tend to do at runtime (in the expansion) things you can do better at compile-time |
| 01:58 | slashus2 | It is for my AI class. We are using XLISP in our class. I should have tried to convince the professor to use clojure. |
| 01:59 | hiredman | nice |
| 01:59 | slashus2 | cgrand: I see that now. |
| 02:00 | hiredman | I want to get pleo, and wire a gumstix to the debug port, then run clojure on it |
| 02:01 | hiredman | but that is well over my toy budget |
| 02:01 | slashus2 | These robots run a stripped down version of debian on ARM11 processors. |
| 02:02 | slashus2 | They have sonar, wifi, temperature gauges, etc. |
| 02:03 | hiredman | I google it :P |
| 02:03 | hiredman | looks like a beast |
| 02:03 | hiredman | man sonar |
| 02:03 | hiredman | wow |
| 02:03 | slashus2 | Looks sort of like R2D2 |
| 02:05 | slashus2 | I wish it had arms that could grab things. |
| 02:10 | slashus2 | hiredman: I mean I was able to start a clojure repl inside the robot's OS. I guess that was pretty cool. |
| 02:11 | slashus2 | Unfortunately, I couldn't control any of the robot's modules successfully during the time I tried. |
| 02:12 | hiredman | :( |
| 02:13 | hiredman | need a clojure <-> xlisp bridge |
| 02:14 | slashus2 | No, the robot runs java. |
| 02:14 | slashus2 | I was just commenting that we use xlisp for some of the smaller applications in the class. |
| 02:15 | hiredman | oh |
| 02:17 | slashus2 | hiredman: I tried to use :gen-class to make its main module, but, like I said before, I couldn't get clojure on the classpath. |
| 02:19 | slashus2 | Thought maybe there was a slight chance I could write my robot project in clojure. |
| 02:21 | hiredman | you might try writing a java class that creates your own classloader and use that to try and load clojure |
| 02:22 | slashus2 | Is that very difficult? |
| 02:22 | hiredman | http://java.sun.com/javase/6/docs/api/java/net/URLClassLoader.html |
| 02:22 | hiredman | I dunno |
| 02:22 | hiredman | URLClaassLoader looks simple enough |
| 02:23 | slashus2 | I will look into that. |
| 03:55 | AWizzArd | ~seen kotarak |
| 03:55 | clojurebot | no, I have not seen kotarak |
| 06:53 | AWizzArd | ~max people |
| 06:53 | clojurebot | max people is 187 |
| 06:53 | AWizzArd | cemerick: last was 185 :) |
| 06:53 | licoresse | the daily max people routine ;-) |
| 06:54 | cemerick | it's good, it's good |
| 06:54 | cemerick | I *still* wouldn't worry about it, tho. :-) |
| 06:55 | cemerick | I think the tipping point of (at least moderate) longevity is long since past. |
| 06:56 | AWizzArd | As long Rich is healthy and interested. |
| 06:59 | licoresse | :D |
| 06:59 | licoresse | plenty of brilliant people here |
| 07:08 | ambient | are there any ready-made macros for fast array processing? so i wouldn't have manually to aset aget everything? |
| 07:09 | ambient | like array-let and (set-array [a b c] my-array) |
| 07:39 | cgrand | ambient: apart from amap and areduce (which are not what you want), I don't know |
| 07:39 | cgrand | what are you trying to do? |
| 08:04 | ambient | cgrand a lot of stuff with arrays of doubles. audio digital signal processing, real time |
| 08:09 | AWizzArd | cgrand: in PersistentHashMap.java I see that count is of type int. Does that mean that hashmaps are limited to contain 4 milliard elements only? |
| 08:11 | cgrand | AWizzArd: on a 32 bit CPU it's a safe bet. Java collections have that limit too. |
| 08:11 | cgrand | ambient: ok, thx |
| 08:15 | AWizzArd | I see. So it is something for Java 8 or so, when it will be typical for business machines to have 0.5 TB RAM. |
| 08:22 | cgrand | AWizzArd: and int is signed so 2^31-1 items max |
| 08:30 | AWizzArd | cgrand: yes true, so it's even less |
| 08:30 | AWizzArd | fortunately we have no need for 2 milliard k/v pairs right now in one single map ;-) |
| 09:12 | dom1410 | hello i need some help. |
| 09:12 | dom1410 | i try to write a funktion which initializes a java object from a java class |
| 09:12 | dom1410 | like this |
| 09:13 | dom1410 | http://pastebin.com/m6871a4b8 but there is a java.lang.Exception |
| 09:14 | chouser | bla? |
| 09:14 | The-Kenny | dom1410: Are you sure the problem is this line? I don't see the symbol "bla" |
| 09:14 | dom1410 | ^^ i try to call the funktion like this "(new-model bla)" |
| 09:14 | chouser | ah |
| 09:15 | dom1410 | sorry.. |
| 09:15 | The-Kenny | dom1410: Use a macro. the repl tries to evalue bla before calling the function. |
| 09:15 | chouser | 'def' does not evaluate its first arg |
| 09:15 | dom1410 | ah ok.. |
| 09:16 | chouser | it always takes the symbol you give it as the literal name of the Var to create. |
| 09:17 | dom1410 | ok i so it's better to use a makro? |
| 09:17 | chouser | dom1410: also, it's generally discouraged to create new named Vars on the fly at runtime. |
| 09:17 | chouser | are you sure it's what you want to be doing? |
| 09:18 | dom1410 | hm.. we want to make our GUI programm running with a console using a repl |
| 09:19 | chouser | you might consider something like (def DGEModels (ref {})) |
| 09:20 | chouser | then new-model can store your DGEModel instances there with appropriate concurrency behavior. |
| 09:20 | chouser | and no need for macros. :-) |
| 09:21 | tmountain | hey guys, I have a general question regarding Java interop |
| 09:21 | dom1410 | that sounds nice... i will try..;) |
| 09:21 | dom1410 | thank you very much |
| 09:22 | tmountain | what's the typical approach in Clojure when working with Java classes that have side effects or aren't designed in a thread-safe fashion? |
| 09:27 | AWizzArd | tmountain: you should make sure to not use those classes in parallel then. |
| 09:28 | tmountain | AWizzArd: it's a hypothetical question really. I generally write almost everything side-effect free in Clojure, but some co-workers are interested in Clojure and probing into the theoretical what-ifs |
| 09:30 | chouser | tmountain: One general approach that is sometimes appropriate is to only mutute the object via a particular agent, to serialize access to it. (though that won't prevent reading it in a possibly invalid state) |
| 09:31 | tmountain | even when using a thread-safe class in Java, there are instances where you might have a conditional - if (!someVar.isSet()) { someVar.set(val); } |
| 09:31 | chouser | tmountain: but in my experience so far the biggest problem isn't accidental mutation of the object so much as keeping the stateful approach from leaking out into the rest of your program. |
| 09:31 | tmountain | and wrap that in a synchronized block from outside to make sure the whole operation is atomic |
| 09:32 | tmountain | chouser: when you say serialize access to it, are you referring to using a blocking-queue type mechanism to ensure that everything happens in sequence or something completely different? |
| 09:32 | chouser | tmountain: you can use 'locking' |
| 09:33 | chouser | tmountain: yes, what you said. |
| 09:33 | chouser | (def out (agent output-stream)) (send-off out #(.write % "hello world")) |
| 09:33 | tmountain | so, if you're stuck in that situation, you should basically develop some policies to avoid an ad-hoc spaghetti threading nightmare |
| 09:34 | chouser | tmountain: yes. or use a different java lib. :-) |
| 09:34 | tmountain | chouser: preferrably, yes ;-) |
| 09:34 | tmountain | so in the conditional example I posted above, you would use a lock, or the same agent approach? |
| 09:35 | chouser | I guess it would depend on the object and/or your desired usage. |
| 09:36 | tmountain | if you were to use a lock, what locking mechanism does Clojure provide? |
| 09:36 | chouser | 'locking' |
| 09:37 | tmountain | ahh, aptly named |
| 09:38 | tmountain | thanks for all the help guys. I've convinced at least one co-worker to use Clojure for his senior project and more are gaining interest, so that's a good thing |
| 09:39 | snowwhite07 | tmountain, Wow! thats really good |
| 09:39 | tmountain | snowwhite07: early adopters over here. I work at a startup with a lot of young people, so that helps |
| 09:40 | snowwhite07 | tmountain, nice |
| 10:13 | AWizzArd | Will contribs sql lib by default return cursers, so that doing a select that will return huge amount of data won't be a problem? |
| 10:15 | AWizzArd | uh, cursor :) |
| 11:22 | Licenser | hmm with the enclojure plugin for netbeans, is there a way to let it automatically add the second half of brackets? like typing ( and it adds ) after the cursor? |
| 11:23 | RomanRoe | Licenser: Wouldnt this be annoying when you want to wrap an existing form? |
| 11:24 | Licenser | RomanRoe: hmm I am used to it from TextMate, if I want to do it I just select what I want to wrap and then type ( so it autowraps it too |
| 11:24 | Chousuke | now you wish you had paredit.el :) |
| 11:25 | RomanRoe | Licenser: or the editor could be smart and only insert the ) when no character is behind the cursor |
| 11:25 | Chousuke | silly editors, thinking only in terms of characters... ;P |
| 11:25 | Licenser | Chousuke: I wish TM would work nicely with Clojure :P |
| 11:25 | RomanRoe | Chousuke: lol |
| 11:26 | The-Kenny | M-x mark-sexp ftw :) |
| 11:26 | Licenser | Sex? |
| 11:26 | arsatiki | yeaah |
| 11:26 | arsatiki | mark-sexp is The Thing missing from the TM plugin |
| 11:27 | Chousuke | emacs+paredit is so good that even though I can't use emacs at all I think I'm stuck with it forever for lisp editing. |
| 11:27 | The-Kenny | Licenser: No, sexp. from one ( to the corresponding ). |
| 11:27 | Licenser | oh okay |
| 11:27 | Chousuke | though even with paredit I can only use barf, slurp and kill-sexp |
| 11:27 | Chousuke | but it's still better than any other editor :P |
| 11:28 | Licenser | I want a good TM plugin :( |
| 11:28 | Licenser | Well for the start I |
| 11:28 | Licenser | d |
| 11:28 | arsatiki | Oh wow, there is a select enclosing brackets in TM \:D/ |
| 11:28 | Licenser | argh |
| 11:29 | Licenser | arsatiki: which plugin do you use, it seems that all I tried are broken or even more broken |
| 11:32 | arsatiki | Licenser: This one, I believe: http://github.com/stephenroller/clojure-tmbundle |
| 11:33 | The-Kenny | hm.. I never understand what's so cool about textmate. |
| 11:33 | arsatiki | Honestly, neither do I anymore. |
| 11:33 | Chousuke | it's sleek and maclike I guess. |
| 11:33 | arsatiki | Plz some1 rewrite emacs with clojure-lisp :-P |
| 11:34 | Chousuke | that would be fun |
| 11:34 | Chousuke | too bad emacs is basically core + eleventy billion libraries |
| 11:34 | The-Kenny | Just write a elisp-interpretet in clojure :p |
| 11:35 | The-Kenny | *an elisp-interpreter |
| 11:35 | The-Kenny | sorry, typing in bed isn't very easy. |
| 11:35 | Chousuke | and while rewriting the core is probably not too bad, it's the libraries that make emacs useful :P |
| 11:35 | The-Kenny | I remember someone has wrote an elisp-interpreter in common lisp and got it working. |
| 11:36 | Licenser | Nothing is really cool about textmate, it just integrates very nicely on OS X which is a big + in my eyes. It feels native to use and often the TM bundels are damn good |
| 11:36 | Chousuke | but if you write just an elisp interpreter, that won't help. /: |
| 11:36 | Chousuke | it'll still be elisp |
| 11:36 | arsatiki | I recently retried emacs after a 5+ year break |
| 11:36 | Licenser | write a elisp -> clojure compiler |
| 11:36 | saml | hey wanna teach me clojure over irc? |
| 11:36 | The-Kenny | Licenser: That's what I miss in aquamacs.. a better integration. |
| 11:37 | The-Kenny | (It doesn't support services, for example) |
| 11:37 | arsatiki | It's scary how well your fingers remember all the commands after all this time |
| 11:37 | Licenser | I admit I never got used to EMACS |
| 11:38 | Licenser | And at least for Ruby I didn't found a better editor yet |
| 11:38 | Licenser | (then TextMate) |
| 11:38 | Licenser | while there are a few things that horribly annoy me :P |
| 11:38 | stuartsierra | Some people tried to re-implement Emacs in Common Lisp. They never finished. |
| 11:40 | Maddas | One doesn't even finish such a task :-) |
| 11:41 | Licenser | I tell you a elisp -> clojure compiler is the way to go >P |
| 11:41 | tmountain | considering the current version is 23.1, there'd be a lot of ground to cover |
| 11:41 | Licenser | let it work a few days and you've emojure or how you want to call it |
| 11:41 | arsatiki | emacj |
| 11:41 | tmountain | I'm one of the heretics that writes Lisp code in Vim |
| 11:41 | The-Kenny | clomacs. |
| 11:42 | Maddas | tmountain: I use viper-mode (VI emulation), that works for me. Just don't mention it on #emacs. Or #vim. |
| 11:43 | Chousuke | heh |
| 11:43 | chouser | I've been disappointed by viper mode. |
| 11:43 | The-Kenny | tmountain: I tried that too.. it just didn't work for me. |
| 11:43 | Raynes | I am disappoint. |
| 11:43 | chouser | So I started my own repl+editor. It's disappointing me as well. |
| 11:43 | Maddas | Oh, chouser and Chousuke are two different people :-( |
| 11:44 | chouser | so true... |
| 11:44 | kunley | Hi. |
| 11:45 | chouser | kunley: welcome. |
| 11:45 | kunley | How to make Ctrl-c break current operation in a repl instead of leaving? |
| 11:45 | tmountain | probably have to trap SIGINT somehow |
| 11:45 | Licenser | okay time for me to eat see you later people |
| 11:46 | Chousuke | hmm, there's a java IDE for emacs |
| 11:46 | Chousuke | using CEDET |
| 11:46 | Chousuke | the plain java mode is a bit too plain... |
| 11:47 | rhickey_ | any proposals for a different name for 'implement' in protocols given :implements in datatypes is about interfaces? |
| 11:47 | The-Kenny | Chousuke: Just use slime and clojure :) |
| 11:47 | Chousuke | adopt? |
| 11:47 | chouser | kunley: there's a thing in repl-utils to do that |
| 11:47 | Chousuke | The-Kenny: I'm about to hack src/clj/clojure/lang/Compiler.java :P |
| 11:48 | The-Kenny | Chousuke: Heh, ok. |
| 11:48 | kunley | chouser: thx, will check. |
| 11:49 | arsatiki | rhickey: :follow or :follows, perhaps. |
| 11:51 | Licenser | I like follows that makes sense for a protocol |
| 11:52 | chouser | protocol should use :implement because it means the same as the Java word? |
| 11:52 | rhickey_ | we're looking for a word to go first here: (_____ AProtocol AClass ...) |
| 11:53 | Licenser | what about :supports |
| 11:53 | Maddas | :satisfies, perhaps? |
| 11:54 | rhickey_ | chouser: could be same/similar (AType :implements [AnInterface] ...), (implement AProtocol AClass ...) - too confusing? |
| 11:54 | arsatiki | If the name of the protocol does not actually contain the word "protocol", then :protocol might work. But it does seem odd that it is not a verb. |
| 11:54 | danlarkin | fulfill? |
| 11:54 | rhickey_ | arsatiki et al - not looking for a keyword here, but a function name |
| 11:54 | arsatiki | oh |
| 11:54 | chouser | will protocols sometimes have the same name as a matching Java interface? |
| 11:55 | rhickey_ | chouser: I hope not, but ns issues have to be clarified for both datatypes and protocols |
| 11:56 | rhickey_ | (___ Seqable String (seq [s] ...)) |
| 11:57 | Licenser | extend |
| 11:57 | rhickey_ | Licenser: extend has the same relationship to Java extends that implement has to Java implements |
| 11:58 | Licenser | Oh didn't knew java stole that word already :P my java is horribl. It just sounded good there |
| 11:58 | danlarkin | technomancy repeated this quote to me yesterday, "There are only two hard problems in computer science, naming and cache expiry." |
| 11:58 | rhickey_ | and implement is probably more correct |
| 11:58 | Licenser | very odd idea >P |
| 11:58 | Licenser | teach |
| 11:58 | arsatiki | I like danlarkin's "fulfill" after looking at the example |
| 11:59 | Licenser | (teach Sequable String (seq [s] ...)) |
| 12:01 | chouser | apply |
| 12:01 | rhickey_ | I guess a primary question is, is :implements/implement too confusing. If not, then that's it |
| 12:01 | chouser | :-P |
| 12:02 | danlarkin | yeah I think they're too similar |
| 12:02 | liebke | I don't think :implements/implement is to confusing |
| 12:02 | Licenser | I am confused what would be confusing, but likely because I'm not sure what to confuse them with |
| 12:02 | Licenser | and I |
| 12:02 | Licenser | m hungry, so see you later peopel |
| 12:03 | cgrand | rename :implements to :interfaces? |
| 12:03 | rhickey_ | conform |
| 12:03 | arsatiki | conform-to |
| 12:03 | chouser | implement/:implement is less confusing that map/map |
| 12:04 | arsatiki | Personally I don't think I'd be confused by implement |
| 12:04 | kunley | chouser: yeah, add-break-thread! does the trick. Your responsiveness is awesome btw |
| 12:04 | rhickey_ | cgrand: interfaces are a host thing, if people ask, how do I implement an interface and you say :implements, no surprises |
| 12:05 | chouser | kunley: glad it'll work for you. |
| 12:05 | arsatiki | Too bad implement-protocol is probably too long. |
| 12:05 | chouser | hm. with-protocol |
| 12:06 | kunley | The-Kenny: I left comments on your clojure-couchdb commits. Basically I was wondering if vi & emacs clojure modes give different indents, or just it was coincidence that we had them different |
| 12:06 | rhickey_ | chouser: mismatch given general (with-this do that) |
| 12:06 | cgrand | rhickey: true and the interface concept may not exist on the host (eg javascript) |
| 12:06 | chouser | using-protocol |
| 12:06 | chouser | apply-protocol |
| 12:07 | danlarkin | fulfill-protocol :) |
| 12:08 | The-Kenny | kunley: I've seen the comments and added some comments too. I don't know if there's a difference... The only thing I could do is telling my emacs to not use tabs for indent :) |
| 12:08 | arsatiki | Thesaurus suggested "effectuate" =) |
| 12:10 | chouser | realize |
| 12:22 | rhickey_ | unlike interfaces, you will be able to 'unimplement' a protocol, might help in thinking about it. When implementing a protocol you are both saying how to do it, and adapting/extending the dispatch to the new type. 'include' et al then come to mind |
| 12:23 | cgrand | specify |
| 12:23 | rhickey_ | cgrand: the defprotocol itself seems more like the spec |
| 12:28 | Luyt | Hello Rich, I've seen a few of your clojure talks videos, I like the way you *don't* say "eh...." dozens of times in every sentence, like so many people do ;-) |
| 12:29 | arsatiki | Haskell uses the term "instance declaration", but I can't get anything useful out of that |
| 12:29 | arsatiki | (except declare, but...) |
| 12:30 | rhickey_ | Luyt: :) |
| 12:32 | rhickey_ | adapt? |
| 12:33 | Luyt | Yes, and I'm now reading Stuarts book. I dabbled a bit with CL but I think clojure is more worthwhile learning - although I havent used it yet in any serious app |
| 12:34 | Luyt | BTW, the java interop works nicely, it's easy to call java objects from Clojure, but does it work the other way round too? |
| 12:42 | chouser | Luyt: you can create classes and interfaces in Clojure that can be used in Java without the Java user even knowing they're implemented in Clojure. |
| 12:42 | Luyt | chouser: Excellent. Thanks. |
| 12:43 | Luyt | All thanks to the JVM, I suppose? |
| 12:43 | tmountain | Luyt: you can also invoke Clojure from Java - http://en.wikibooks.org/wiki/Clojure_Programming/Tutorials_and_Tips#Invoking_Clojure_from_Java |
| 12:43 | chouser | well that certainly helps. :-) To make it transparent to Java users, you do have to do a bit of work in Clojure that you otherwise wouldn't bother with (gen-class and gen-interface to be specific) |
| 12:44 | chouser | tmountain: right, that's the other way to do it -- specify nothing special in the clojure code and require Java users to make foreign-looking calls. |
| 12:46 | tmountain | chouser: yeah, probably not the best way |
| 12:47 | tmountain | but I suppose it's nice to have options at least |
| 12:54 | eno | where can I find explanation of the '->' macro? |
| 12:55 | eno | i don't quite understand (doc ->) |
| 12:55 | The-Kenny | eno: It's really simple. Just play around with it a bit. You could also look in the source |
| 12:59 | tmountain | (-> 1 inc inc inc) would give you 4 |
| 12:59 | tmountain | just feeds the result of the last function in the the next |
| 13:01 | eno | tmountain: thx for the example |
| 13:02 | eno | so the parameters after the 1st one should all be functions, right? |
| 13:05 | eno | kinda like comp, just different order |
| 13:06 | technomancy | comp returns a function without calling its function arguments; this actually calls the functions |
| 13:07 | eno | right |
| 13:10 | cgrand | eno: parameteres after the 1st one they can be function + trailing args |
| 13:10 | cgrand | ,(-> 1 (+ 1) (+ 1) (+ 1)) |
| 13:10 | clojurebot | 4 |
| 13:11 | cgrand | ,(-> [] (conj 1) (conj 2) (conj 3)) |
| 13:11 | clojurebot | [1 2 3] |
| 13:12 | eno | so (+ 1) is like a partially applied function, except that it is only a form, not a function |
| 13:13 | eno | good to know this idiom |
| 13:13 | Chousuke | it's most useful with java interop I think |
| 13:13 | cgrand | yeah and that only the first arg is missing |
| 13:13 | cgrand | useful with nested data structures too |
| 13:14 | Chousuke | ,(-> "foobar" (subs 3) .toUpperCase); can intermix java methods and clojure functions, unlike .. |
| 13:14 | clojurebot | "BAR" |
| 13:14 | cgrand | ,(-> {:a {:b {:c 42}}} :a :b :c) |
| 13:14 | clojurebot | 42 |
| 13:15 | eno | cool |
| 13:15 | Chousuke | there's also ->> which is a variant of this :) |
| 13:15 | chouser | ,(->> (range 20) (remove #(< 5 15)) (filter even?)) |
| 13:15 | clojurebot | java.lang.RuntimeException: java.lang.IllegalArgumentException: Wrong number of args passed to: sandbox$eval--4434$fn |
| 13:15 | chouser | ,(->> (range 20) (remove #(< 5 % 15)) (filter even?)) |
| 13:15 | clojurebot | (0 2 4 16 18) |
| 13:15 | Chousuke | it's fairly recent though. |
| 13:16 | cgrand | ,(-> "hello" java.io.StringReader. java.io.BufferedReader.) |
| 13:16 | clojurebot | #<BufferedReader java.io.BufferedReader@14ec8d6> |
| 13:16 | Chousuke | what fun. I'm trying to compile emacs and it fails with a bus error... |
| 13:43 | konr | How do the clojure XML libraries work? Do they offer something similar to Xpath? |
| 13:47 | cgrand | konr: they turn the XML into a tree, tree which can be traversed using clojure.zip. zip-filter (in contrib) is XPath-like |
| 13:48 | jasapp | Someone just was working on xpath, weren't they? |
| 13:48 | jasapp | http://github.com/kyleburton/clj-xpath |
| 13:49 | cgrand | and (shameless plug) if your XML isn't namespace heavy enlive can allow you to query it with CSS-like selectors |
| 13:58 | Licenser | so how will it be called? |
| 14:47 | lpetit | rhickey: still searching a new name for implementation . |
| 14:47 | lpetit | ? |
| 14:50 | rhickey_ | lpetit: got one? |
| 14:51 | lpetit | rhickey_: not brilliant ideas, but thought I ought to share them now, and not complain later :) : defimpl, or defimplementation (but too long this last I guess) |
| 14:51 | lpetit | rhickey_: as defmulti / defmethod |
| 14:52 | rhickey_ | others have pointed out defmethod probably shouldn't be def- becasue it doesn't introduce any names, same with implement |
| 14:53 | lpetit | rhickey_ : I remember, but defmethod defines a method for the protocol, and has already opened the can of worms :-p |
| 14:53 | rhickey_ | time to close it |
| 14:54 | lpetit | rhickey_: want to rename defmethod ? |
| 14:54 | lpetit | rhickey_: ok. At least I tried :) |
| 14:55 | rhickey_ | also, I've reconsidered the array and field equality stuff from yesterday. Today I think default should just be = (so identity for arrays), when you want anything else, define equals |
| 14:55 | cemerick | was there another alternative? |
| 14:55 | lpetit | rhickey_: I myself am not to annoyed by :implements / 'implementation . After all, for people not dealing with host code, it's almost not an issue. And for people dealing with host code, it will just resemble the cascading extension capabilities of interfaces |
| 14:57 | rhickey_ | cemerick: lpetit had a neat suggestion for per-field flags - see bottom of: https://www.assembla.com/wiki/show/clojure/Datatypes |
| 14:58 | lpetit | rhickey_: I don't want to misunderstand you : it's just a change concerning array fields, or do you want to go back to a simple implementation with =, and specific equals for anything else (thus throwing away :equals metadata) ? |
| 14:59 | rhickey_ | in the end I think anything that encourages people away from compatibility with = and maps is something they have to take on themselves |
| 14:59 | rhickey_ | lpetit: right, no more :equals metadata |
| 14:59 | rhickey_ | I slept on it and it didn't survive the night |
| 14:59 | cemerick | Good idea -- seems like something a macro could take care of on top of deftype |
| 15:00 | mikehinchey | rhickey_: however, defmethod does modify the application code like other defs, rather than being function or state-changing, so defmethod seems consistent to me |
| 15:00 | lpetit | rhickey_ : grmlml :-) |
| 15:00 | mikehinchey | rhickey_: function -> functional |
| 15:01 | liebke | rhickey_: I don't think :implements/implement is too confusing, but what about bind, bind-protocol, or bind-impl? |
| 15:02 | rhickey_ | liebke: if it weren't for existing bind, maybe |
| 15:02 | liebke | fair enough |
| 15:03 | rhickey_ | I agree :implements/implement is probably not too bad, I wondered over lunch if people might try to stick protocols in the :implements list |
| 15:03 | rhickey_ | and if that would be wrong or not |
| 15:04 | liebke | interesting, that might make sense |
| 15:54 | danlarkin | I have a question about nested atoms: |
| 15:54 | danlarkin | is this safe? (swap! (@state account) assoc folder {}) |
| 15:55 | danlarkin | state is an atom for a map keyed on account, and the value is another atom keyed on folder |
| 15:55 | hiredman | you are interacting with two atoms there |
| 15:56 | danlarkin | right |
| 15:56 | hiredman | atoms are uncoordinated |
| 15:57 | danlarkin | I'm asking if I've done that wrong, I guess |
| 15:57 | lpetit | danlarkin: why ask if it's safe ? |
| 15:57 | hiredman | I think you meant to use refs :P |
| 15:57 | danlarkin | oh perhaps you're right about that |
| 16:00 | danlarkin | yes, you're right, I just have my nested maps in a ref and then all operations will be in a transaction and I don't have to worry aboot it |
| 16:00 | danlarkin | about it, that is |
| 16:02 | chouser | right, otherwise you might swap the outer atom while still retrying the inner one -- when the inner one succeeds its value would have already been lost |
| 16:03 | danlarkin | thanks for the brain-check guys :) |
| 16:04 | danlarkin | sometimes I think about what an awful mess this would make in another language |
| 16:25 | mikehinchey | With clojure.test, is there a way to make it stop testing? If my database is down, I don't want tons of repeated errors, just 1 error from a :once fixture. |
| 16:26 | technomancy | perform the check in your fixture? |
| 16:26 | stuartsierra | mikehinchey: you could (System/exit 1) in the fixture |
| 16:27 | stuartsierra | yeah |
| 16:27 | technomancy | just conditionally execute the argument to your fixture |
| 16:27 | stuartsierra | Yeah, that would work. |
| 16:28 | mikehinchey | the fixture is throwing the connection exception |
| 16:29 | mikehinchey | wait, that doesn't sound right, let me check more closely |
| 16:32 | mikehinchey | you're right, my connection isn't really happening until later, so I need a check in the fixture. thanks. |
| 16:37 | Licenser | hrm after working a bit with clojure in netbeans i get the feeling it tries to foce people into the java way of doing stuff, I already have like 3 packages and all that o.O meh |
| 16:40 | chouser | rhickey: so no per-field :equals flag in deftype? will always use = which is 'identical?' for arrays? |
| 16:42 | solussd | why does something like (range 100000) cause a outofmemory exception? |
| 16:43 | chouser | ,(last (range 100000)) |
| 16:43 | clojurebot | 99999 |
| 16:43 | chouser | solussd: ? |
| 16:43 | chouser | ,(reduce + (range 1e6)) |
| 16:43 | clojurebot | 499999500000 |
| 16:43 | mwoelker | ,(range 1000000) |
| 16:43 | clojurebot | Eval-in-box threw an exception:java.lang.OutOfMemoryError: Java heap space |
| 16:44 | mwoelker | don't use the whole seq at once i guess |
| 16:44 | chouser | well, you didn't want all those values printed anyway, I bet. :-) |
| 16:44 | solussd | seems to only throw the OutOfMemoryError when it is printed |
| 16:44 | mwoelker | probably not ;-) |
| 16:45 | chouser | set *print-length* or restrict the output in some other way. |
| 16:45 | Chousuke | solussd: that's because printing it holds the entire sequence in memory. |
| 16:45 | solussd | but I did... :) b/c I'm playing |
| 16:45 | mwoelker | it gets boring after the first three pages |
| 16:45 | technomancy | mwoelker: sssh; no spoilers |
| 16:45 | solussd | shutup! I'm looking for the pattern in the output of range |
| 16:45 | mwoelker | it was the butler... |
| 16:47 | solussd | the python interpreter will print ridiculously long lists generated by range for me. :) Maybe clojure is trying to stop me from wasting my time. |
| 16:47 | chouser | well, you can try starting your JVM with a bigger heap |
| 16:48 | chouser | ,(pr-str (range 1e5)) |
| 16:48 | clojurebot | "(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 1 |
| 16:48 | chouser | I actually don't get an exception here. |
| 16:49 | solussd | try 1e6 |
| 16:49 | solussd | i think the clojurebot has a bit more heap than i do |
| 16:49 | chouser | bah. takes 10 times longer. ;-) |
| 16:49 | solussd | ,(pr-str (range 1e6)) |
| 16:50 | chouser | clojurebot: ping? |
| 16:50 | clojurebot | PONG! |
| 16:51 | chouser | I guess he didn't want to do your pr-str for you. |
| 16:53 | cemerick | Aside from immutable data structures being preferable in general, is there any reason why putting mutable stuff in an agent is a Bad Thing? |
| 17:22 | arohner | If I want to read from multiple refs at the same time, and I want them to be consistent, will derefing them in a dosync do what I want? |
| 17:23 | arohner | i.e. (dosync [@foo @bar]) |
| 17:26 | eno | arohner: isn't it writer's responsibility to make sure the refs are consistent? |
| 17:27 | eno | as long as all writers dosync, reader does not need to worry about consistency? |
| 17:27 | arohner | hrm. In my case, the refs are two different views of essentially the same data |
| 17:28 | eno | then when will it be inconsistent? |
| 17:28 | arohner | each ref is consistent, but I want to read them both at at point when they are consistent with each other |
| 17:28 | arohner | if I do [@foo @bar] without a dosync, a transaction could run between the @foo and the @bar |
| 17:29 | arohner | maybe my data model is wrong. |
| 17:29 | eno | if there is one single ref |
| 17:30 | eno | holding a container of the two |
| 17:31 | arohner | yeah, I may have to do that |
| 17:31 | arohner | previously I didn't need to look at both of them at the same time |
| 17:31 | hiredman | arohner: you should get consistent information from (dosync [@a @b]) |
| 17:32 | arohner | hiredman: thanks |
| 17:33 | hiredman | http://clojure.org/refs |
| 17:35 | konr | Is there a function that prints a tree with indentation, or represents it visually, so I can get a clue on what it is? |
| 17:37 | eno | hiredman: thx, "a consistent snapshot ..." |
| 17:42 | dnolen | konr: you mean like pretty print? |
| 19:14 | gregoryg | /leave |
| 19:22 | regularfry | Evening all... anyone got clojure-project working on emacs-snapshot-gtk on jaunty? It's not working for me, and I'm a little stumped |
| 19:23 | technomancy | regularfry: what are you seeing? |
| 19:24 | regularfry | technomancy: Exception in thread "main" java.lang.NoClassDefFoundError: clojure/main in *inferior-lisp* |
| 19:24 | regularfry | clojure-src-root is correctly set |
| 19:25 | regularfry | and M-x slime works. Just not M-x clojure-project. |
| 19:25 | technomancy | regularfry: clojure-project is meant to work with self-contained projects |
| 19:25 | technomancy | so all the dependencies should exist in the project root |
| 19:25 | technomancy | either as jars in lib/ or unpacked in target/dependency |
| 19:26 | regularfry | Ah, maybe I've misunderstood something then - I thought it created/copied/managed that process. |
| 19:26 | technomancy | that should be better-documented I suppose... I forget that a lot of people don't use dependency management. =( |
| 19:27 | regularfry | No worries. I think I just assumed that since all the *other* tools manage everything for me, that must as well :-) |
| 19:28 | technomancy | yeah, doing M-x slime without a project is mostly for exploration etc. and for hacking on clojure/contrib itself |
| 19:29 | regularfry | That's what I figured. It just seemed odd that one worked but not the other. As long as it's not a weird version-interop problem (and I haven't screwed anything major up) then I'm happy as larry |
| 19:29 | technomancy | great. (assuming larry is happy) |
| 19:55 | Licenser | hrm the API documentation is a horror :/ |
| 20:01 | Licenser | technomancy: well you could put it that way |
| 20:01 | Licenser | I get the feeling you |
| 20:01 | Licenser | ... you've to know what you are looking for to find help in the API |
| 20:02 | dnolen__ | Licenser: yeah, fortunately there's not much to know. Have you looked at the cheat sheet? It's much more helpful |
| 20:02 | technomancy | s/to find help in the API// |
| 20:03 | Licenser | they are great to refresh ones memory but I find the documents often very unhelpful if you want to figure out what function to use especiually when function parameters have so very expressive names like m s re i or something like that |
| 20:03 | ataggart | does something like this (admittedly trivial) fn exist? |
| 20:03 | ataggart | (defn assocf [map key f] |
| 20:03 | ataggart | (assoc map key (f (map key)))) |
| 20:04 | technomancy | ataggart: maybe update-in? |
| 20:04 | ataggart | I *knew* it had to be there |
| 20:04 | ataggart | thx, I'm blind today |
| 20:14 | ataggart | (doseq [s (.split "hello world" " ")] (println s)) |
| 20:14 | ataggart | or use re-split from contrib |
| 20:23 | Licenser | ataggart: yes that works great if you have 1 rule, it gets quite complicated if you've more then 1 rule |
| 20:24 | Licenser | there isn't a scanner feature, at least I didn't find one |
| 20:25 | ataggart | too complicated for a regex? |
| 20:26 | Licenser | I want to tokenize sourcecode |
| 20:26 | Licenser | doing that in one single regexp is suicide |
| 20:26 | Licenser | Tried it, is the wrong way :P |
| 20:27 | chouser | most tokenizers use a regex for each token, don't they? |
| 20:29 | Licenser | chouser: yes but not one for all tokens |
| 20:31 | chouser | oh, I see. |
| 20:34 | Licenser | there we go, re-scis born! |
| 20:35 | Licenser | ugly uygly hack but it works |
| 20:51 | Licenser | hah it's working! |
| 21:06 | Licenser | hmm any hints about how I make a regexp multiline in clojure/ |
| 21:23 | Licenser | ah tricky found it |
| 21:42 | regularfry | technomancy: I'm not much cop at emacs lisp (yet... hopefully) but this does what I expect: http://gist.github.com/215647. Don't know if it'd be handy, consider it available equally for taking or ignoring |
| 22:58 | jlilly | how do you guys manage your jars? Do you guys all use that sort of run script I've seen about? |
| 23:03 | hiredman | jdk1.6 and beyond lets you put wildcards in the classpath |
| 23:03 | hiredman | so I just put jars in ~/.jars/ and set my CLASSPATH to "$HOME/.jars/*" |
| 23:11 | jlilly | I think that's my issue. looks to be v1.5 |
| 23:15 | wlr | hiredman: would putting symlinks in ~/.jars/ pointing to actual installed locations be a workable alternative? |
| 23:20 | jlilly | anyone know if openjdk6 translates into jdk1.6? |
| 23:44 | yangsx | wlr: it's workable (I'm using Linux system). |
| 23:47 | wlr | yangsx: thanks. i might give it a try. |
| 23:58 | jlilly | having some classpath issues. hoping someone might be able to give me a hand. http://dpaste.de/Eu3R/ |
| 23:59 | jlilly | that's a traceback showing my CLASSPATH, and the commands I'm attempting. |