2010-12-23
| 00:05 | joshua__ | I'm using congomongo and I have a database with one record in it. Calling destroy! on that one record isn't doing anything. |
| 00:05 | joshua__ | Thoroughly confused. |
| 00:07 | amalloy | joshua__: you call destroy!, not on a record, but on a where clause, is my recollection |
| 00:07 | amalloy | a consequence of this is that (destroy! {}) will delete the whole database |
| 00:08 | amalloy | i mean, i guess a record evaluates to a where clause that identifies itself perfectly, so maybe that ought to work |
| 00:09 | scottj | on old congomongo I think you could do (destroy! :collection {}) |
| 00:09 | joshua__ | I figured that out just a second ago =). |
| 00:09 | joshua__ | amalloy, you right. |
| 00:10 | joshua__ | amalloy, the problem for me was that the examples didn't show a where clause they showed an object and as it turned out that object was simple enough that you could use it as the where clause safely. |
| 00:11 | joshua__ | amalloy, but my object was a bit more complicated |
| 00:11 | joshua__ | amalloy, so if I used the object as the where clause it didn't delete anything. |
| 00:11 | joshua__ | amalloy, deleting based on the key of the item I wanted to delete worked though |
| 00:12 | joshua__ | $(doc destroy!) |
| 00:12 | joshua__ | &(doc destroy!) |
| 00:12 | sexpbot | java.lang.Exception: Unable to resolve var: destroy! in this context |
| 00:13 | joshua__ | oh wells |
| 00:28 | ossareh | lo all |
| 00:32 | bhenry | am i doing something wrong or can i really not use cake without having ruby? |
| 00:39 | tomoj | any gloss users around? trying to figure out how to encode [[1 2 3] [4 5 6] [7 8 9] [10 11 12]] as "4,1,4,7,10,2,5,8,11,3,6,9,12", where the "4" at the beginning is a length prefix |
| 00:40 | tomoj | and actually, each tuple position has a different type, so you get one length prefix and then three lists of that length of different types |
| 00:41 | amalloy | tomoj: have you tried writing a function to do that in clojure, before worrying about how to do it with gloss? |
| 00:41 | tomoj | no, it's too late |
| 00:41 | amalloy | ? |
| 00:41 | tomoj | but that's fairly easy |
| 00:42 | tomoj | &((fn [v] (cons (count v) (apply mapcat vector v))) [[1 2 3] [4 5 6] [7 8 9] [10 11 12]]) |
| 00:42 | sexpbot | ⟹ (4 1 4 7 10 2 5 8 11 3 6 9 12) |
| 00:43 | amalloy | tomoj: and with such a function, you could give gloss a less complicated structure, right? just ask it to send all those numbers? |
| 00:44 | tomoj | hmm |
| 00:44 | joshua__ | What is gloss? |
| 00:44 | tomoj | https://github.com/ztellman/gloss/wiki |
| 00:44 | tomoj | I could use a function like that to compile a new frame dynamically upon receiving the length prefix |
| 00:44 | tomoj | but that would be slow |
| 00:45 | amalloy | tomoj: well, i've barely even looked at gloss, so i'm mostly just trying out ideas to see if any of them stick |
| 00:56 | amalloy | tomoj: you said the tuples have different types - those types are known at compile time, right? |
| 00:56 | tomoj | yes |
| 01:11 | amalloy | tomoj: it doesn't look possible to me without compiling a new frame on receipt. the gloss repetition primitives assume that they'll either have a built-in prefix, or will be allowed to consume everything it sees |
| 01:11 | tomoj | right |
| 01:11 | tomoj | I have cooked up something with header that seems to do the trick |
| 01:11 | amalloy | if the variance in sizes is small, you could precompile all the frames that you might need |
| 01:11 | tomoj | right |
| 01:12 | amalloy | tomoj: really? i'd like to see it, if you don't mind |
| 01:12 | tomoj | https://gist.github.com/0d834768928c7e484b38 |
| 01:13 | amalloy | ah. yeah, that's all i could come up with too |
| 01:13 | tomoj | then I call it like (tuple-list :int16 coordinate :byte :byte) to generate a codec which encodes a list of tuples like <coord, byte, byte> into a short-prefixed list of all coords, then bytes, then bytes |
| 01:15 | amalloy | right |
| 01:17 | tomoj | unfortunately I can't see how to make a coordinate codec that splits up bytes |
| 01:17 | tomoj | I think someday gloss/aleph/lamina will be pure awesome |
| 01:20 | amalloy | tomoj: like have 4-bit numbers, you mean? |
| 01:20 | tomoj | exactly |
| 01:21 | tomoj | I guess it's fairly easy with a custom Reader/Writer implementation |
| 01:41 | tomoj | s/I think someday // s/will be/are/ |
| 01:49 | amalloy | can someone help me understand the timing and execution-ordering, during syntax-quote/macro/eval stuff? https://gist.github.com/752664 is a brief example of something that seems like it "should" work but doesn't |
| 01:55 | zvrba | ok, i like the ideas behind the JVM and clojure, but i can't stand Javas crappy OO-API. is there a Clojure library that makes, at least, I/O and conversions as simple as in C? |
| 01:55 | zvrba | i'm talking about fopen/fgets/atoi/sprintf/sscanf/.. |
| 01:56 | zvrba | i don't want to spend an afternoon plowing through java docs just to open a file. |
| 02:03 | amalloy | zvrba: clojure.java.io isn't bad |
| 02:05 | amalloy | but you won't find fgets |
| 02:05 | zvrba | is there a better-formatted documentation than http://richhickey.github.com/clojure/clojure.java.io-api.html |
| 02:06 | amalloy | http://clojuredocs.org/clojure_core/clojure.java.io/reader is probably worse-formatted for quick reference, but has example usages and stuff |
| 02:06 | zvrba | oh |
| 02:06 | zvrba | nice |
| 02:07 | ngw | nice |
| 02:07 | ngw | didn't know that |
| 02:07 | amalloy | http://clojure.org/cheatsheet can be useful to find out what name to use for a function you're thinking of |
| 02:07 | amalloy | but it doesn't have clojure.java.io, just the core stuff |
| 02:08 | zvrba | ok, that cheat sheet is one of the best i've seen :-) |
| 02:09 | zvrba | now. i've started to write some small programs in common lisp. and i'd like to learn some lisp-like language. |
| 02:09 | zvrba | what would be the advantage of "switching" to clojure, if any? |
| 02:10 | zvrba | or. |
| 02:10 | amalloy | zvrba: well, it's better. duh :) |
| 02:10 | zvrba | amalloy: :) in what way? |
| 02:10 | zvrba | btw, does emacs slime work equally well with clojure as with CL? |
| 02:10 | zvrba | (note: i'm using windows) |
| 02:10 | amalloy | zvrba: quite well, but not equally well |
| 02:11 | zvrba | a year ago I tried to use netbeans/eclipse/jetbrains plugin for clojure, and none worked well. |
| 02:13 | amalloy | zvrba: clojure has more convenient names and syntaxes for almost everything; this really adds up over time. it's also very nice to (a) run anywhere java runs, and (b) be able to use any java library. the community is friendlier... |
| 02:15 | amalloy | it leans very heavily on functional programming and lazy sequences, which leads to some amazing conclusions, but it has good support for non-functional, mutable stuff for when a functional style would be unnecessarily tangled |
| 02:15 | zvrba | amalloy: can you give a concrete example of more convenient names? |
| 02:15 | zvrba | right, i wanted to get my hands more dirty with functional progrmaming. |
| 02:16 | zvrba | i guess clojure is better for that; it's way too easy to fall back to imperative style in CL |
| 02:16 | amalloy | well, it's been a while since i've used CL. but i seem to recall that CL's syntax for a hash-map is something like (hash-map 1 a 2 b) or something? |
| 02:16 | zvrba | you mean, hash literals? |
| 02:16 | amalloy | yeah |
| 02:16 | zvrba | i don't know, didn't need that yet :) |
| 02:16 | amalloy | heh |
| 02:17 | zvrba | i've written just small pieces of code in CL, no serious big projects |
| 02:17 | amalloy | well okay, even just lists/vectors |
| 02:17 | zvrba | i see that clojure is not uniform -- sometimes I have to use [], and sometimes () |
| 02:17 | zvrba | it seems kinda ugly and that I have to learn special cases of when to use what |
| 02:17 | amalloy | zvrba: i was about to get into that, actually. you will realize that it's "get to" |
| 02:18 | zvrba | "get to"? I didn't get that :) |
| 02:18 | amalloy | you "get to use" [] intead of() |
| 02:18 | zvrba | ah, so I can choose which i will use? |
| 02:19 | amalloy | if you want a list of a, 1, and the symbol 'c in CL, you have to write (list a 1 'c); that's available in clojure, but far more usual is [a 1 'c] |
| 02:19 | zvrba | ah |
| 02:19 | zvrba | one thing that annoyed me in CL: '(1 2 3) is a literal list that can be modified at run-time |
| 02:19 | zvrba | [a 1 'c] is literal list, but can it be modified at run-time? |
| 02:19 | amalloy | zvrba: hardly anything can be modified at runtime |
| 02:20 | zvrba | and is there a difference between (list a 1 'c) and [a 1 'c] ? |
| 02:20 | zvrba | (in CL, (list a 1 'c) *always* generates a new list) |
| 02:20 | zvrba | (whereas '(a 1 c) is a "singleton", in the lack of a better name) |
| 02:20 | amalloy | zvrba: there is! (list a 1 'c) is a linked list of cons cells; [a 1 'c] is a magic clojure data structure with fast random access as well as fast appends to the end |
| 02:21 | amalloy | well, i say "appends". like most clojure things, you don't actually change the vector, you just get out a new structure that's different |
| 02:21 | zvrba | mhm |
| 02:21 | zvrba | does Clojure also accept '(a 1 c) syntax? |
| 02:21 | amalloy | yeah |
| 02:21 | zvrba | goodie |
| 02:22 | amalloy | but that doesn't get you the value of a; it gets you the symbol a, just like CA |
| 02:22 | amalloy | CL |
| 02:22 | zvrba | i know |
| 02:22 | zvrba | or |
| 02:22 | amalloy | &(reduce + (map inc [1 2 3])) |
| 02:22 | sexpbot | ⟹ 9 |
| 02:22 | zvrba | uh |
| 02:22 | amalloy | is an example of something you can express much more succinctly and naturally in clojure than in CL |
| 02:23 | zvrba | i'd like to start with clojure, but I hesitate because I don't really want to mess with standard java API, but i must if i want to do anything useful :/ |
| 02:23 | zvrba | i seriously personally think that Java API is an abomination and an example of how NOT to design software |
| 02:23 | zvrba | amalloy: ah, function names are self-evaluating? |
| 02:23 | zvrba | no need for quoting? |
| 02:24 | amalloy | zvrba: mmmm, something in between |
| 02:24 | amalloy | clojure has one namespace that contains both functions and variables/locals/whatever |
| 02:24 | amalloy | so you don't have to use #' to specify which you mean |
| 02:25 | zvrba | ok |
| 02:25 | zvrba | which IDE is most stable? |
| 02:25 | amalloy | zvrba: meh. i like emacs |
| 02:25 | zvrba | :) |
| 02:25 | amalloy | it's most popular, but eclipse is getting traction |
| 02:26 | zvrba | does "apropos" and "describe" work? |
| 02:26 | zvrba | i don't want to use eclipse. |
| 02:26 | zvrba | period :) |
| 02:26 | amalloy | zvrba: i don't know |
| 02:26 | zvrba | ok, when you write (reduce ..) do you get sensible names as hints in the status-row? |
| 02:26 | amalloy | zvrba: yeah, eldoc works |
| 02:26 | zvrba | when I used CLISP, all I got was (reduce arg0 arg1..) which was totally useless |
| 02:27 | zvrba | with ClozureCL I get sensible names, e.g. (reduce function seq ...) |
| 02:27 | zvrba | ok, that was useful to know |
| 02:27 | amalloy | when i write (reduce ..), the minibuffer reads ([f coll] [f val coll]) |
| 02:27 | zvrba | good, that's what I was interested in :) |
| 02:28 | zvrba | do you use it under linux or windows? |
| 02:28 | zvrba | any hints about emacs setup? |
| 02:28 | amalloy | ubuntu 10.04 |
| 02:29 | Raynes | http://www.assembla.com/wiki/show/clojure/Getting_Started_with_Emacs |
| 02:29 | amalloy | ah, thanks Raynes |
| 02:31 | Raynes | It's a tiny bit outdated though. The elisp binaries for Clojure stuff are in phil's own repo. |
| 02:32 | Raynes | Newer versions anyway. |
| 02:32 | zvrba | ok, thanks |
| 02:33 | amalloy | zvrba: you can do a lot of stuff without having to call java libraries, if that bothers you, especially as a lot of them have clojure wrappers already |
| 02:36 | amalloy | i usually use the java builtins for things like strlen, but clojure.string contains equivalent stuff if you prefer |
| 02:37 | zvrba | i'd prefer wrappers around Java APIs for common stuff, yes |
| 02:40 | amalloy | &(count "a string") ; treats the string as a sequence of characters |
| 02:40 | sexpbot | ⟹ 8 |
| 02:45 | zvrba | what is leiningen ? |
| 02:46 | amalloy | zvrba: a build/dependency tool to save you from java |
| 03:45 | amalloy | zvrba: find anything you like? |
| 03:50 | zvrba | amalloy: haven't started yet. real-life chores, heh. i think i'll go with emacs. |
| 04:53 | LauJensen | Morning all |
| 04:54 | raek | Ningmor Lau |
| 05:28 | dsop | hmm it seems that (string (http-agent "http://foo" :method "POST" :connect-timeout 100)) hangs forever |
| 05:42 | AWizzArd | dsop: I also was using http-agent until recently. But this lib was stopped, and I suggest you to better switch to the Apache HTTP Client. |
| 05:42 | dsop | AWizzArd: hmm k |
| 05:43 | dsop | why do they stop libs in contrib? |
| 05:43 | AWizzArd | dsop: because a http client is a complex tool. It takes months and months to develop a feature rich one that is also stable. |
| 05:44 | Raynes | Why switch to apache-http-client direction? Check out clj-http. It's a nice wrapper and is designed similarly to ring. |
| 05:44 | mids | Raynes: I don't think clj-http allows you to set timeout values though |
| 05:45 | Raynes | There is no shorted of Clojure HTTP clients though. Might be one that does. |
| 05:46 | dsop | Raynes: afaik clj-http doesnt work on appengine |
| 05:48 | AWizzArd | Raynes: a wrapper is fine, but it still needs something substantial under the hood. This would be the Apache client, or maybe the one from JBoss. |
| 05:48 | AWizzArd | And the question is: does a wrapper significantly increase your productivity? |
| 05:49 | Raynes | Not having to read Java docs and learn a new Java API certainly does. At least for me. Nonetheless, if clj-http and clj-apache-http don't support timeouts, then there isn't much of a choice in the matter. |
| 05:50 | AWizzArd | Those wrappers can indeed help, for the most basic tasks. One will read a few minutes the docs and can start. Reading the Java docs might require the double time, such as 8 minutes vs 4. |
| 05:50 | AWizzArd | And for 20 minute projects this is a big win. |
| 05:52 | AWizzArd | But for real applications you have needs such as specifying that you can accept gziped replies, cookie management, NTLM Authentication, etc. |
| 05:53 | Raynes | My point is that Clojure is more accessible to Clojure programmers. If there is a Clojure library/wrapper library that does what you need, I wouldn't see the purpose of using a Java API directly unless there was some real need for it. Readers of your code will thank you. |
| 05:54 | dsop | I prefer clojure wrappers over java interopt |
| 05:54 | sandGorgon | while invoking lucene from clojure, I get back a TermEnum, which is a custom enumerator class with prev and next. Now I need to run a map on this TermEnum - which I can do because clojure " Don't know how to create ISeq from". How do I solve this ? |
| 05:54 | AWizzArd | Difficult to answer this in general. |
| 05:55 | sandGorgon | s/can/cant/ |
| 05:55 | sexpbot | <sandGorgon> while invoking lucene from clojure, I get back a TermEnum, which is a custom enumerator class with prev and next. Now I need to run a map on this TermEnum - which I cant do because clojure " Don't know how to create ISeq from". How do I solve this ? |
| 05:55 | AWizzArd | Wrappers have their own set of advantages and disadvantages. |
| 05:55 | raek | sandGorgon: you could make your own lazy seq |
| 05:55 | AWizzArd | I prefer what makes me more productive. This can be a wrapper, but this can also be the original API. |
| 05:56 | sandGorgon | raek, i thought something like that was the answer - any examples on that ? |
| 05:56 | _mst | sandGorgon: I usually do something like this: (take-while identity (repeatedly #(when (.next terms) (.term terms)))) |
| 05:56 | _mst | (where terms is your TermEnum) |
| 05:56 | raek | (defn term-seq [t] (when t (cons t (term-seq (.next t))))) |
| 05:57 | raek | sandGorgon: assuming .next returns nil when there are no next thing |
| 05:57 | raek | (defn term-seq [t] (lazy-seq (when t (cons t (term-seq (.next t)))))) |
| 05:57 | raek | I meant... |
| 05:58 | raek | it isn't very lazy without the lazy-seq part... :-) |
| 05:59 | sandGorgon | raek, ok.. good starting point. I'll figure it out from that - thanks! |
| 06:10 | raek | sandGorgon: I just peeked into the javadocs for TermEnum. it turns out .next does not return a new thing, but changes the object in-place. so you cannot use my approach |
| 06:10 | raek | also, that class is deprecated |
| 06:12 | sandGorgon | raek, oh ? thanks for doing that |
| 06:14 | sandGorgon | raek, the java code was something like "while(terms.next()){ Term term = terms.term();} . Why does in-place affect your code ? |
| 06:20 | raek | my snippet incorrectly assumed that terms.next would return a new "terms" object, rather than a boolean |
| 06:21 | raek | (defn term-seq [terms] (lazy-seq (when (.next terms) (cons (.term terms) (term-seq terms))))) |
| 06:21 | raek | this would work |
| 06:22 | raek | the resulting seq is also thread safe, if term-seq is the only thing that gets the terms instance |
| 06:23 | raek | but the underlying terms object is not |
| 06:23 | raek | so clojure fixes it :-) |
| 06:34 | sandGorgon | raek, awesome - thanks ! |
| 06:47 | AWizzArd | dsop, Raynes: the clj-http wrapper looks good and clean. The timeouts can still be set up through the API. The wrapper wraps the Apache HTTP Client. |
| 06:48 | Raynes | AWizzArd: Right. I figured that timeouts could be set *somehow*. |
| 06:48 | dsop | AWizzArd: I try it, but as said I ran into troubles using a couchdb wrapper that uses clj-http because some stuff was forbidden on appengine |
| 06:48 | dsop | so I hvae to check if clj-http works on appengine |
| 06:50 | AWizzArd | Ah okay, I missed the appengine part. |
| 06:50 | AWizzArd | But doesn't the appengine offer you a http client? |
| 06:50 | dsop | yes kindof |
| 06:50 | dsop | but I prefer getting a clojure version :) |
| 06:51 | AWizzArd | Well, the Apache Client seems to work. So in principle clj-http should too. |
| 07:33 | dsop | AWizzArd: just as a side note: http client v4 doesnt work on appengine out of the box |
| 07:38 | fliebel | morning |
| 07:49 | Dranik | I'm using swank-clojure. Trying to C-x, C-e on (println "Hello, World!") but nothing happens. How can I evaluate a clojure form? |
| 07:50 | mrBliss | Dranik: println returns nil, so you won't see the "Hello, World!" |
| 07:51 | AWizzArd | dsop: not nice |
| 07:51 | Dranik | mrBliss, so which command should I use? |
| 07:52 | mrBliss | Dranik: I don't think there is a version of print that also returns the string, but if you're just checking if C-x C-e works, you can just eval "Hello World" |
| 07:52 | Dranik | mrBliss, Bingo!! :-) |
| 08:13 | raek | Dranik: when evaluating (println "Hello, World!"), the text appears in the repl buffer (*slime-repl clojure*) |
| 08:26 | fliebel | What do the WP bloggers among you use to highlight Clojure? (or embed gists) |
| 08:29 | Raynes | fliebel: Syntaxhighligher works well. |
| 08:29 | Raynes | fliebel: Look for the "Syntaxhighlighter Advanced" or whatever plugin. |
| 08:30 | fliebel | Raynes: I found evolved, if that's what you mean. |
| 08:30 | Raynes | Yeah, that's it. |
| 08:30 | Raynes | I use it. |
| 08:30 | fliebel | *checks some code on Raynes site* |
| 08:32 | fliebel | Raynes: The only code I see is a rather ugly darkblue and has needless scrollbars :( But it seems it does Clojure just fine. |
| 08:33 | fliebel | *do |
| 08:33 | fliebel | no wait |
| 08:33 | fliebel | oh, whatever |
| 08:33 | cemerick | fliebel: WP.com has clojure highlighting baked in |
| 08:34 | Raynes | fliebel: All of that can be changed on the settings page. |
| 08:34 | fliebel | cemerick: I'm self hosting. But I think what Raynes mentioned is the same they use. |
| 08:34 | cemerick | yeah, probably |
| 08:35 | fliebel | cemerick: long live automation :) I'm planning to set up a multisite to manage sites for my clients as well. I fear some of them might be running WP 2.3 or something like that ;) |
| 08:36 | cemerick | I self-hosted WP for a couple of years. It seems like you really need to know php and the security bits around it to make it work well. |
| 08:37 | cemerick | The pain associated with always having to carefully port (necessary) tweaks given a new version of WP was what really pushed me off of it. |
| 08:38 | fliebel | cemerick: I know those :) What kind of tweaks? 'official' tweaks(plugins) are fairly consistent across versions as far as I know. |
| 08:39 | cemerick | fliebel: I'm sure I don't remember. This was years ago. |
| 08:40 | fliebel | cemerick: Good for you, if you can live with WP.com ;) |
| 08:42 | cemerick | Does it have downsides I don't know about? |
| 08:43 | Raynes | The only time I ever had to touch PHP was to define a couple of documented constants in the config file when I moved the site to new servers. |
| 08:48 | Gigaroby | guys is there any function to map every value of a list with a increasing number --> (index ("a" "b")) => ((0 "a") (1 "b")) |
| 08:49 | Gigaroby | I do know how to implement it but I was just wondering if there is any alredy made |
| 08:50 | mrBliss | Gigaroby: clojure.contrib.seq/indexed but I thought map-indexed also existed |
| 08:50 | fliebel | Gigaroby: I was also about to suggest map-indexed |
| 08:50 | Gigaroby | mrBliss, thanks but I do need the not-map indexed |
| 08:50 | Raynes | &(keep-indexed vector ["a" "b" "c" "d"]) |
| 08:50 | sexpbot | ⟹ ([0 "a"] [1 "b"] [2 "c"] [3 "d"]) |
| 08:51 | mrBliss | http://clojuredocs.org/clojure_core/clojure.core/map-indexed |
| 08:51 | fliebel | Raynes: keep will trow out nil values. |
| 08:51 | Raynes | fliebel: Who needs 'em |
| 08:51 | fliebel | &(keep-indexed vector ["a" "b" "c" nil "d"]) |
| 08:51 | sexpbot | ⟹ ([0 "a"] [1 "b"] [2 "c"] [3 nil] [4 "d"]) |
| 08:51 | Raynes | ;) |
| 08:51 | fliebel | hm |
| 08:52 | Raynes | fliebel: It doesn't because the result of the function will never be nil. |
| 08:52 | Raynes | Nonetheless, I guess map-indexed works just as well: ##(map-indexed vector ["a" "b" "c" "d"]) |
| 08:52 | sexpbot | ⟹ ([0 "a"] [1 "b"] [2 "c"] [3 "d"]) |
| 08:53 | Gigaroby | the first was fine thanks cause then I need to pass it to a (every? #(not= %1 %2) (whatever)) |
| 08:56 | raek | &(map vector (range) ["a" "b" "c" "d"]) |
| 08:56 | sexpbot | ⟹ ([0 "a"] [1 "b"] [2 "c"] [3 "d"]) |
| 08:56 | Gigaroby | turned out I need map cause I need to start from a number different from 0 |
| 08:57 | Gigaroby | still thank you guys |
| 08:58 | raek | if you just destructure the vector and pass the parts to a function, it can make sense to replace 'vector' with the consuming function |
| 08:59 | sandGorgon | i'm calling a function within a function - but the functions are defined separately. can I access the variables of the parent function from within the nested function's body ? |
| 09:00 | raek | a function that is created inside another can do that |
| 09:01 | sandGorgon | raek, actually I have a filter that is being used, which needs to access the variables of the parent function. but I cant pass more than one variable to a filter function right ? |
| 09:03 | raek | you could do something like this: (defn filter-divisible [n coll] (filter (fn [x] (zero? (mod x n))) coll)) |
| 09:04 | sandGorgon | of course ... i was hoping there was a better way. |
| 09:04 | raek | the anonymous function remebers (closes over) the environment where it was created |
| 09:06 | raek | if you have a complex function defined elsewhere you would like to use, you can "adapt it" with an anonymous function: |
| 09:06 | raek | (defn divisible [x n] (zero? (mod x n))) |
| 09:06 | raek | (defn filer-divisible [n coll] (filter #(divisible? % n) coll)) |
| 09:06 | Dranik | raek, well, my *slime-repl clojure* does not show anything... |
| 09:07 | raek | Dranik: for me, it appears _above_ the "user>" prompt |
| 09:07 | Dranik | it just prints the input line like USER> |
| 09:08 | sandGorgon | raek, what was your syntax - what is it doing exactly ? |
| 09:08 | Dranik | raek, yeah, that is supposed to be so. But my slime does not show it |
| 09:08 | Dranik | how did you prepare your emacs? |
| 09:08 | raek | #(divisible? % n) is the same as (fn [%] (divisible? % n)) |
| 09:08 | raek | % is just a symbol |
| 09:09 | raek | #(...) is just syntactic sugar for the fn form |
| 09:09 | raek | Dranik: what happens if you eval the println in the repl? |
| 09:09 | Dranik | user> (println "Hello, World!") |
| 09:09 | Dranik | Hello, World |
| 09:10 | raek | and ewhen evaluating that in another buffer, nothing happens? (besides the minibuffer displaying "nil" for a second) |
| 09:11 | raek | sandGorgon: that reader macro is documented here: http://clojure.org/reader |
| 09:11 | sandGorgon | raek, oh .. now I see what you have done. just one question : are "divisible" and "divisible?" interchangeable ? |
| 09:12 | raek | oh. no... that's just a typo :-) |
| 09:13 | raek | Dranik: also, is clojure-mode activated for that other buffer? |
| 09:13 | Dranik | raek, how to activate it? |
| 09:13 | Dranik | bcs something is happening when i press c-x, c-e |
| 09:13 | raek | M-x clojure-mode |
| 09:13 | Dranik | but definietely not what I supposed |
| 09:13 | raek | should happen automatically for .clj files |
| 09:14 | raek | Dranik: it could be that you are evaluating emacs-lisp... |
| 09:14 | Dranik | yep |
| 09:14 | Dranik | clojure-mode was activated |
| 09:14 | raek | I tested this with my very basic emacs setup (clojure-mode, slime and slime-repl from ELPA) |
| 09:14 | Dranik | the same |
| 09:15 | raek | note that only the output of print* works this way |
| 09:15 | raek | the return value is not displayed in the repl |
| 09:16 | raek | I usually enter what I want to evaluate in repl |
| 09:16 | raek | and use C-M-x or C-x C-e just for reevaluating definitions |
| 09:30 | Gigaroby | is there any way to get this (some = <stuff>) |
| 09:30 | Gigaroby | return faolse |
| 09:30 | Gigaroby | *false instead of nil |
| 09:31 | bhenry | Gigaroby: wrap it in boolean |
| 09:32 | bhenry | ,(boolean (some #{1} [2 3 4])) |
| 09:32 | clojurebot | false |
| 09:33 | Gigaroby | thanks |
| 10:11 | Gigaroby | (defn pair-equal? [[x y]] (= x y)) is that [[x y]] a valid destruct ? |
| 10:13 | chouser | yep |
| 10:13 | Gigaroby | ty |
| 12:10 | karthik6_ | any body is from india |
| 12:33 | Lajla | Yes |
| 12:33 | Lajla | any body is from india |
| 13:16 | dnolen | *unchecked-math* is nifty when you need it. |
| 14:53 | gju_ | hey |
| 14:54 | gju_ | how can i execute code sequentially? |
| 14:54 | technomancy | gju_: wrap it in a "do" form |
| 14:54 | gju_ | oh. |
| 14:55 | gju_ | sec, i try. :) |
| 15:00 | gju_ | well... i guess it works. but i have another question. |
| 15:00 | gju_ | when i use a method that doesn't return a value but instead changes one of its parameters. how do i express that in clojure? |
| 15:01 | technomancy | all functions return values. sometimes that value is nil. |
| 15:01 | gju_ | in this case its RandomAccessFile's read method which expects a buffer |
| 15:01 | gju_ | wel... yes ok. but do you know what i mean? |
| 15:02 | technomancy | not really. are you having trouble calling the .read method on a RandomAccessFile instance? |
| 15:02 | gju_ | yes. |
| 15:03 | gju_ | i try it like this |
| 15:03 | gju_ | (. file read buffer 0 3) |
| 15:03 | gju_ | but it says that "buffer" is unresolvable in this context |
| 15:03 | gju_ | but i actually don't know any better. |
| 15:05 | technomancy | gju_: you'll need to construct a byte array for that; something like (make-array Byte/TYPE 1000) |
| 15:15 | gju_ | works. nice. thanks. |
| 15:15 | gju_ | looks weird tho... |
| 15:21 | gju_ | maybe someone could give me some suggestions: |
| 15:22 | gju_ | http://pastie.org/1401445 |
| 15:23 | amalloy | gju_: (let) has an implicit do, and allows multiple bindings |
| 15:24 | amalloy | so you could write (let [x 1 y 2] (stuff) (more stuff)) |
| 15:25 | gju_ | ok |
| 15:25 | amalloy | there's also the handy-dandy doto macro: ##(macroexpand '(doto file (.seek 10) (.read buffer))) |
| 15:25 | sexpbot | ⟹ (let* [G__9287 file] (dot G__9287 seek 10) (dot G__9287 read buffer) G__9287) |
| 15:25 | gju_ | ah |
| 15:25 | gju_ | i guess i know what it does... |
| 15:25 | gju_ | sequences of method calles to a specific object? |
| 15:26 | amalloy | yeah, though technically it's more general than that |
| 15:27 | amalloy | i assume you're coming from a lisp background; clojure's = returns true or false, not t or nil |
| 15:28 | gju_ | i played with cl a litte in the past. so yeah kinda. |
| 15:33 | amalloy | gju_: so https://gist.github.com/1f671546d31182bc746c is probably how i would write it. the -> stuff at the end is a matter of taste; i don't think it's substantially better than the way you did it, but i'm putting it there to expose you to -> |
| 15:35 | amalloy | &(macroexpand-all '(-> buffer String. (.equalsIgnoreCase "TAG"))) |
| 15:35 | sexpbot | ⟹ (let* [obj-class__6346__auto__ (clojure.core/class (new String buffer))] (let* [temp__3586__auto__ (clojure.core/some (if (clojure.core/map? clojail.core/tester) (let* [map__9304 clojail.core/tester map__9304 (if (clojure.core/seq? map__9304) (clojure.core/apply cloj... http://gist.github.com/753516 |
| 15:36 | amalloy | oh god. i forgot the . calls turn into a huge mess when macroexpanding in sexpbot |
| 15:36 | amalloy | ignore that, gju_ :P |
| 16:06 | programble | anyone know how easy/hard it is to use Slick2d with clojure? |
| 16:20 | programble | is there a project.clj spec anywhere? |
| 16:30 | lrenn | programble: https://github.com/technomancy/leiningen/blob/master/sample.project.clj |
| 16:30 | lrenn | programble: that's about the closest thing there is. |
| 16:31 | programble | found that before you said it but thanks |
| 16:31 | programble | and that kinda sucks :\ |
| 16:31 | programble | i think i found what i needed though |
| 16:36 | technomancy | programble: what's wrong with it? |
| 16:37 | programble | it isn't exactly documentation |
| 16:37 | programble | and i think cake might have some extra ones that it has no docs for |
| 16:37 | technomancy | sure, can't help you there. |
| 16:58 | amalloy | programble: what info are you looking for? i use technomancy's sample for reference |
| 16:59 | programble | amalloy: nah i'm good, needed to know how to add another maven repo |
| 17:00 | amalloy | sounds like you found it anyway, but https://github.com/amalloy/clojopts/blob/master/project.clj#L7 |
| 17:01 | programble | grrr my internets broke |
| 17:02 | programble | :\ |
| 17:02 | programble | my router responds to pings and has port 80 open but i can't access its page |
| 17:07 | anthony_ | I'm trying to integrate clojure with SWT. On a MenuItem, you set the accelerator using setAccelerator, which takes an int parameter, such as SWT.MOD1 + 'A' (SWT.MOD1 is an int). I'm having trouble casting a char to an int in clojure, though. Am I missing something simple? |
| 17:07 | amalloy | &(int \A) |
| 17:07 | sexpbot | ⟹ 65 |
| 17:08 | amalloy | anthony_: that's what you want, right? |
| 17:08 | anthony_ | That's exactly what I want. I'm ashamed of myself. Thanks. |
| 17:08 | amalloy | welcome |
| 17:14 | anthony_ | I'm sure I have something fundamentally wrong. If I put this into the REPL: '(1 (+ 2 3) 4) why do I get (1 (+ 2 3) 4) instead of (1 5 4) ? I didn't quote the inner parenthesis. Is there any way to get it to return the list (1 5 4) ? |
| 17:15 | amalloy | anthony_: ' quotes an entire form. you probably want ##[1 (+ 2 3) 4] |
| 17:15 | sexpbot | ⟹ [1 5 4] |
| 17:15 | amalloy | er...i guess ## there might be confusing. that's just to tell sexpbot to eval, not part of the code |
| 17:16 | anthony_ | Gotcha. So I just use [ ] ? |
| 17:16 | amalloy | yeah, [] is the vector syntax, which is used for most non-lazy data structures |
| 17:16 | anthony_ | I didn't think about using a vector instead. I think that will work for me. |
| 17:17 | anthony_ | Okay, thanks. I have almost no Lisp exposure, but the little I do have has me always wanting to use lists when I shouldn't. :) |
| 17:17 | amalloy | heh |
| 17:17 | amalloy | it's very handy to have a non-quoting literal syntax for lists, for exactly the reason you describe |
| 17:19 | anthony_ | Definitely. I'm beginning to see the benefits of code and data being represented the same. |
| 17:23 | Derander | I really need to write my lispruby |
| 17:23 | Derander | I want to see if that works at all |
| 17:44 | raek | anthony__: if you really want a list, you can construct it with ##(list 1 (+ 2 3) 4) |
| 17:44 | sexpbot | ⟹ (1 5 4) |
| 17:44 | raek | vectors also has such a function: ##(vector 1 (+ 2 3) 4) |
| 17:44 | sexpbot | ⟹ [1 5 4] |
| 17:45 | raek | so a literal vector is very much like a call to 'vector', but a literal list does not behave this way |
| 17:46 | raek | but as amalloy said, [] is the usual way to do it |
| 17:48 | arohner | does anyone have any good tools for measuring cache misses? I'm not familiar with the tools available on OSX & JVM |
| 18:04 | programble_ | how do you do a float literal in clojure? |
| 18:07 | cemerick | programble_: you don't, AFAIK. ints and doubles are given priority. For interop purposes, you can use (float …) |
| 18:07 | tonyl | programble_: as far as i know there isn't |
| 18:07 | cemerick | ,(class (float 5.0)) |
| 18:07 | clojurebot | java.lang.Float |
| 18:08 | programble_ | that worked |
| 19:41 | anome | hi there |
| 20:26 | rata_ | hi all |
| 20:31 | rata_ | what was that? |
| 20:31 | Raynes | $google netsplit |
| 20:35 | amalloy | Raynes: sexpbot dropped too |
| 20:35 | rata_ | I have a performance problem with clojure... I've written a app that iterates and has a similar cost per iteration until 30 mins running... after that it loses the linear relation between number of iterations or steps and time |
| 20:35 | rata_ | Raynes: yes, but I've search for it by myself =) |
| 20:35 | Raynes | amalloy: I never would have guessed. |
| 20:36 | Raynes | ;) |
| 20:37 | amalloy | rata_: probably not cleaning up all the memory you're using |
| 20:37 | amalloy | and after ~30min it runs out of real memory and starts swapping everything |
| 20:37 | rata_ | and looking for the reason why after a certain number of steps it becomes slower, I used visualvm and it says sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run is using up to a 68% of the time |
| 20:37 | rata_ | ok... so how can I clean up all the memory I'm using? |
| 20:38 | amalloy_ | rata_: make sure not to keep references (direct or indirect) to objects you don't need. that's all it takes to get the gc to do the cleanup. afk now though |
| 20:39 | rata_ | amalloy_: but the gc is doing its task correctly... I doesn't throw an out of memory execptioin |
| 20:39 | rata_ | *exception |
| 20:40 | rata_ | should I use a more aggressive gc? |
| 20:40 | rata_ | is the sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run method related to the GC? |
| 20:41 | rata_ | (I'm not using RMI in my app) |
| 20:42 | rata_ | the problem seems to be that the GC can do its work, but it does it slowly |
| 20:52 | rata_ | amalloy_: ^ |
| 20:55 | amalloy | rata_: i would guess that ConnectionHandler is delegating to your app and isn't really using up much cpu itself, but this isn't an area i know a lot about |
| 20:59 | rata_ | mmm ok |
| 21:05 | rata_ | what's a good GC for persistent data structures? |
| 21:57 | rata_ | still wondering what are good GC options for a clojure app in which there is a huge record that contains several nested persistent data structures and changes constantly |
| 23:11 | rata_ | count is strict, right? |