2010-05-23
| 00:00 | scgilardi | a mouse crossed technomancy's path once... once. |
| 00:11 | johnmn3 | looking at Lau B. Jensen's prototurtle blog entry (http://bestinclass.dk/index.clj/2010/04/prototurtle-the-tale-of-the-bleeding-turtle.html), I noticed the example of defrecord has no default implementation. Just a signature. He could have built the protocol first and built the defrecord with an implementation, right? |
| 00:14 | _na_ka_na_ | Hi all |
| 00:15 | _na_ka_na_ | Any one answer http://groups.google.com/group/clojure/browse_thread/thread/ea39801f8e907640 ? |
| 00:31 | johnmn3 | _na_ka_na_: sorry, I don't know about that |
| 00:31 | _na_ka_na_ | johnmn3: thx for looking anyway |
| 00:34 | johnmn3 | is reify, deftype, or defrecord preferred over proxy now? |
| 00:36 | technomancy | johnmn3: reify replaces most uses of proxy |
| 00:37 | johnmn3 | clojure.org/datatypes: "reify is preferable to proxy in all cases where its constraints are not prohibitive." |
| 00:37 | johnmn3 | bah, thanks technomancy |
| 00:38 | johnmn3 | that page also says: "mutability should be the default |
| 00:38 | johnmn3 | and is the only option for records" |
| 00:39 | johnmn3 | but lau put's gui components into defrecord... which are mutable. perhaps it means only the keys are immutable? |
| 00:43 | technomancy | no, records are immutable |
| 00:49 | johnmn3 | technomancy: k, thanks |
| 01:05 | johnmn3 | I'm trying to translate a java class to clojure. this class has fields that aren't passed to the constructor but are created in the body of the class. |
| 01:05 | johnmn3 | they can be accessed like object.myString |
| 01:06 | johnmn3 | the constructor for the class, though, only takes one gui component. |
| 01:08 | technomancy | johnmn3: if you are just learning Clojure, I'd advise against making a gui app your first project. |
| 01:08 | johnmn3 | is it possible for the implementation within a defrecord to generate an accessible field? or do they all have to be specified in the params to the defrecord? |
| 01:10 | johnmn3 | yea, I hear ya, technomancy. I just really want to make this program. It's a lot of fun |
| 01:10 | technomancy | sure, don't let me dissuade you from having fun. =) |
| 01:10 | johnmn3 | dealing with GUIs arent. |
| 01:12 | johnmn3 | oh, I'm thinking about this all wrong. this example I've been working with.. it starts with an abstract class, then another extends it. |
| 01:14 | johnmn3 | rich stated not to extend concrete implementations (if I read that correctly). so this example doesn't map to clojure that way |
| 01:15 | johnmn3 | "you cannot derive datatypes from concrete classes, only interfaces" |
| 01:16 | johnmn3 | meaning, I won't be able to create a "default implementation" and then extend that implementation by simply adding or changing method definitions. |
| 01:16 | johnmn3 | if I understand correctly |
| 02:08 | hsuh | hm, clojure.org not working |
| 02:26 | johnmn3 | how does one refer to fields from within a record's definition? |
| 02:26 | johnmn3 | like this: |
| 02:26 | johnmn3 | (defrecord R [arg] P (foo [] arg)) |
| 02:26 | johnmn3 | or: |
| 02:26 | johnmn3 | (defrecord R [arg] P (foo [] (:arg this))) |
| 02:26 | johnmn3 | ? |
| 02:41 | hoeck | johnmn3: I would prefer to use the former, except when the fieldname clashes with an argument name |
| 02:42 | hoeck | there is even a third possibility (least preferred, I guess): (.arg this) |
| 02:45 | johnmn3 | hoeck: in that example "arg" is not an argument to the method.. the method is trying to refer to the value of the field. so that is allowed? |
| 02:48 | hoeck | of course, (.arg this) refers to the field named "arg", though it seems that it prefers to call a method "arg" if both, the method and the field exist |
| 02:49 | johnmn3 | ok.. that makes things easier |
| 02:51 | johnmn3 | and if one of the methods calls another method within the same type/protocol, we use the literal word "this"?? like, (.other-method this) |
| 02:51 | johnmn3 | ? |
| 02:51 | hoeck | no, the this is defined in the signature of the method |
| 02:52 | hoeck | (defrecord X [..] P (method [this, args ...] )) |
| 02:52 | johnmn3 | well, as per Lua Jenson's prototurtle example, he put "this" in the signature of the protocol, but not the record. |
| 02:53 | johnmn3 | http://bestinclass.dk/index.clj/2010/04/prototurtle-the-tale-of-the-bleeding-turtle.html |
| 02:53 | sexpbot | "Best In Class: ProtoTurtle - The tale of the bleeding turtle" |
| 02:53 | hoeck | yeah, there used to be a :this parameter to the defrecord some weeks ago |
| 02:53 | johnmn3 | aaah |
| 02:54 | johnmn3 | ok, so keep the "this" param in both the protocol and the record/datatype? |
| 02:55 | hoeck | the :this parameter is gone, and each method takes the current object as the first argument |
| 02:56 | johnmn3 | ok |
| 02:57 | johnmn3 | so does that mean I have to do this: (defrecord R [arg] P (foo [this] (:arg this))) ?? |
| 02:57 | hoeck | note how Lau, in extend-protocol, uses destruction on the first argument to move (the actual "this" argument) |
| 02:57 | hoeck | right, or (foo [_] arg) |
| 02:58 | hoeck | or (foo [t] (:arg t)) |
| 02:59 | johnmn3 | in your first example there.. clojure knows that arg is a field on the record? |
| 03:00 | johnmn3 | I see what you're saying about the destructuring there |
| 03:01 | hoeck | yeah, because the thing is defined in a defrecord context: (defrecord X [arg] P (foo [_] arg)) |
| 03:02 | johnmn3 | cool.. thanks hoeck! |
| 03:09 | danlarkin | I destruct my args all the time |
| 03:09 | danlarkin | they're like nooooooooo and I'm like destructttttttttt |
| 03:09 | hiredman | your args are very destructive |
| 03:10 | hiredman | arg(ument)s |
| 03:21 | emptist | (* 10 20) |
| 03:21 | clojurebot | *suffusion of yellow* |
| 03:21 | Fossi | :D |
| 03:21 | pjstadig | (* 1 1) |
| 03:21 | clojurebot | 1 |
| 03:21 | danlarkin | ,(dinc 1) |
| 03:21 | clojurebot | java.lang.Exception: Unable to resolve symbol: dinc in this context |
| 03:21 | danlarkin | WHAT |
| 03:21 | pjstadig | heeh |
| 03:22 | pjstadig | $(dinc 1) |
| 03:22 | sexpbot | DENIED! |
| 03:22 | danlarkin | sexpbot I hate you |
| 03:23 | pjstadig | $learn sexpbot and danlarkin are feuding |
| 03:23 | sexpbot | My memory is more powerful than M-x butterfly. I wont forget it. |
| 03:23 | drewr | $(println "/me huggles danlarkin") |
| 03:23 | sexpbot | => /me huggles danlarkin nil |
| 03:23 | pjstadig | $sexpbot |
| 03:23 | sexpbot | Command not found. No entiendo lo que estás diciendo. |
| 03:23 | danlarkin | $(System/exit 1) |
| 03:23 | sexpbot | DENIED! |
| 03:24 | Fossi | what the hell is M-x butterfly? |
| 03:24 | danlarkin | $#=(System/exit 1) |
| 03:24 | sexpbot | Command not found. No entiendo lo que estás diciendo. |
| 03:25 | danlarkin | $(list #=(System/exit 1)) |
| 03:25 | sexpbot | EvalReader not allowed when *read-eval* is false. |
| 03:26 | Fossi | i doubt you can break it *that* easily |
| 03:28 | danlarkin | that was ingenious! |
| 03:28 | pjstadig | $*clojure-version* |
| 03:28 | sexpbot | Command not found. No entiendo lo que estás diciendo. |
| 03:28 | danlarkin | $(clojure-version) |
| 03:28 | sexpbot | => "1.2.0-master-SNAPSHOT" |
| 03:29 | pjstadig | $System |
| 03:29 | sexpbot | Command not found. No entiendo lo que estás diciendo. |
| 03:31 | danlarkin | $(dotimes [_ 30] (doto (Thread. #((fn this [] (try :foo (finally (this)))))) .start)) |
| 03:31 | sexpbot | DENIED! |
| 03:32 | johnmn3 | $(read-string '(System/exit 1)) |
| 03:32 | sexpbot | DENIED! |
| 03:32 | johnmn3 | $(read-string '(+ 1 1 2)) |
| 03:32 | sexpbot | DENIED! |
| 03:34 | johnmn3 | $(future (inc 1)) |
| 03:34 | sexpbot | DENIED! |
| 04:13 | dysinger | sexpbot: $(+ 1 1) |
| 05:36 | johnmn3 | is there a clojure.contrib that auto-resolves imports? |
| 07:17 | hoeck | johnmn3: what do you mean by "auto-resolving" imports |
| 07:30 | angerman | if I have a set of functions f1,...,f4 and a value x. How'd I construct (x, f1(x), f2(f(1(x),....,f4(f3(f2(f1(x))))) |
| 07:30 | angerman | ? |
| 07:33 | Borkdude | maybe use (indexed [f1 f2 f3 f4]), comp and use (for [r (range 4)] (range r)) |
| 07:34 | Borkdude | hmm, don't even have to use indexed |
| 07:35 | Borkdude | ,(for [r (range 4)] (range r)) |
| 07:35 | clojurebot | (() (0) (0 1) (0 1 2)) |
| 07:35 | angerman | Borkdude: hmm that's right. I'm still wondering weather or not one could just use the last value. |
| 07:35 | Borkdude | ,(doseq [r (range 5)] (range r)) |
| 07:35 | clojurebot | nil |
| 07:35 | hoeck | wild guess: (reductions #(apply %2 %1) x [f1 f2 f3 f4]) ??? |
| 07:36 | Borkdude | hmm |
| 07:36 | angerman | hoeck: that sounds not too bad |
| 07:36 | Borkdude | hoeck: that might be it |
| 07:37 | angerman | ,(let [f #(%+1)] (reductions #(apply %2 %1) 1 [f f f f])) |
| 07:37 | clojurebot | java.lang.IllegalArgumentException: Don't know how to create ISeq from: java.lang.Integer |
| 07:37 | Borkdude | ,(let [f #(inc %)] (reductions #(apply %2 %1) 1 [f f f f])) |
| 07:37 | clojurebot | java.lang.IllegalArgumentException: Don't know how to create ISeq from: java.lang.Integer |
| 07:38 | Borkdude | ,(let [f #(inc %)] (reductions #(%2 %1) 1 [f f f f])) |
| 07:38 | clojurebot | (1 2 3 4 5) |
| 07:38 | hoeck | ,(reductions #(apply %2 %1) x [f1 f2 f3 f4]) |
| 07:38 | clojurebot | java.lang.Exception: Unable to resolve symbol: x in this context |
| 07:39 | hoeck | ,(reductions #(%2 %1) 10 [inc inc inc dec]) |
| 07:39 | clojurebot | (10 11 12 13 12) |
| 07:39 | Borkdude | great :) |
| 07:39 | hoeck | right, the apply was wrong |
| 07:39 | Borkdude | I'll have to save this example for my Twitter account @cleotd |
| 07:39 | hoeck | yes, reductions is cool, and its even in core now! |
| 07:40 | angerman | hm. |
| 07:40 | Borkdude | I already had it scheduled, but this is a nice application of it |
| 07:41 | angerman | Hm. #(%2 %1) is #(%2 %) :D |
| 07:42 | Borkdude | not much improvement in readability imho;) |
| 07:42 | angerman | 1 char saved on twitter :D |
| 07:42 | Borkdude | angerman: haha that's true |
| 07:45 | Borkdude | is there a set that allows for duplicate values, otherwise called a bag in clojure? |
| 07:46 | angerman | While I did hear about that bag structure from a fellow student. I still don't really get what I'd use it for |
| 07:46 | Borkdude | angerman, Euler problem 5 |
| 07:46 | Borkdude | I have to remember that I need thrice a factor 2 |
| 07:47 | Borkdude | let me explain my problem some more |
| 07:47 | Borkdude | the factors of 8 are [2 2 2] |
| 07:48 | Borkdude | the factors of 4 are [2 2], so if I join the common factors of 8 and 4 I have to get [2 2 2] |
| 07:50 | angerman | so you basically have key:count? |
| 07:50 | angerman | well of factor:mulitple |
| 07:50 | Borkdude | angerman: I could do it like that |
| 07:51 | Borkdude | I might as well do that |
| 07:52 | Borkdude | is there a simple update, instead of update-in? |
| 07:54 | Borkdude | can I do: (update-in map [factor] inc), without having to check if factor is already there |
| 07:54 | Borkdude | and if it's not there, it will be inserted with default value 1 |
| 07:57 | Borkdude | I mean like this: (defn update-or-insert [m k f d] |
| 07:57 | Borkdude | (if (contains? m k) |
| 07:57 | Borkdude | (update-in m [k] f) |
| 07:57 | Borkdude | (assoc m k d))) |
| 07:57 | Borkdude | |
| 07:58 | Borkdude | (update-or-insert {} 3 inc 1) => {3 1} |
| 07:58 | Borkdude | (update-or-insert {3 1} 3 inc 1) => {3 2} |
| 08:00 | Chousuke | Borkdude: you could also wrap inc so that it handles nil. |
| 08:02 | hoeck | Borkdude: deftype rocks for such datastructure creations |
| 08:02 | hoeck | Borkdude: http://gist.github.com/410875 |
| 08:06 | Borkdude | Chousuke: ok - hoeck: tnx, will look into it later. |
| 08:06 | Borkdude | gtg now |
| 08:17 | angerman | ok, just a very qick and extemely stupid reality check. |
| 08:17 | angerman | Assume M to be a square Matrix. |
| 08:18 | angerman | if \lambda v = M v. v Is eigenvector for eigenvalue \lambda, no? |
| 08:22 | moshisushi | hello! i wanna discuss side effects.. is it up to the programmer to make sure that side effects are avoided inside of transaction? |
| 08:23 | angerman | me shoots himself |
| 08:24 | angerman | just in case anyone is going to use decomp-eigenvalue from incanter |
| 08:25 | angerman | don't try to get the eigenvectors using nth on the (:vectors part of the result). Your are going to get the rows of the eigenvector matrix instead of the eigenvetors you'd want. :/ |
| 08:35 | hoeck | moshisushi: right, the programmer takes care |
| 08:40 | Chousuke | moshisushi: you can use the io! macro to mark code blocks that do IO |
| 08:40 | Chousuke | moshisushi: if such code is executed in a transaction, an exception is thrown |
| 08:41 | angerman | hmm. Clojure + JReality + Incanter is quite some fun :D |
| 09:19 | angerman | what does "no dispetch macro for: p" mean? |
| 09:20 | angerman | I assue it chokes on `(let [#ps (. ~ev getPointSet) |
| 09:20 | angerman | I though #ps was for gensym |
| 09:21 | angerman | ahh post |
| 09:21 | angerman | not pre |
| 09:51 | moshisushi | Chousuke: ah |
| 09:51 | moshisushi | Chousuke: because quoting the "programming clojure" book: In Clojure, side effects are |
| 09:51 | moshisushi | explicit and unusual. do is one way to say “side effects to follow.” |
| 09:52 | moshisushi | but i would say that (defn foo [] (println "hello")) is a function that returns nil, and happens to have the side effect of printing |
| 10:02 | Chousuke | moshisushi: right. |
| 10:03 | Chousuke | moshisushi: though if you want to be precise, it's not a function, it's a procedure. :) |
| 10:04 | Chousuke | and its return value is irrelevant. |
| 10:05 | moshisushi | Chousuke: ugh, i'm not quite sure i understand the difference :) |
| 10:05 | Chousuke | the point the book tries to make I think is that side-effects should be rare and isolated, not commonplace like in imperative and object-oriented languages. |
| 10:06 | moshisushi | Chousuke: right. i come from a Haskell background so i just have to loosen up my approach to side effects :) |
| 10:07 | moshisushi | in that STM, there's just no way to sneak in an io operation in a transaction |
| 10:07 | Chousuke | moshisushi: a procedure is something that has side-effects. a function doesn't. |
| 10:07 | Chousuke | but usually people just say "function" and "pure function" :P |
| 10:08 | Chousuke | yeah, the type system takes care of that. |
| 10:08 | Chousuke | but clojure doesn't have that, so the programmer has more responsibility |
| 10:09 | moshisushi | Chousuke: well there are benefits to not having to fight a type system too.. so i guess io! is sufficient :) |
| 10:09 | Chousuke | yeah. |
| 10:10 | moshisushi | Chousuke: "defn is a macro that makes defining functions a little simpler." |
| 10:10 | moshisushi | i think the terminology is a bit messed up :) |
| 10:10 | Chousuke | how so? :) |
| 10:11 | Chousuke | you can define functions without defn |
| 10:11 | moshisushi | Chousuke: yeah but you just said that defn creates procedures :) |
| 10:11 | moshisushi | or well, procedures is maybe not part of the clojure lingo at all |
| 10:12 | Chousuke | well yeah, *I* make the distinction sometimes but most people don't |
| 10:13 | moshisushi | yeah ok hehe.. so defn is pretty much def:ing an implicit lambda function? |
| 10:13 | Chousuke | yeah |
| 10:13 | Chousuke | hmm |
| 10:14 | Chousuke | I think clojurebot will complain to me if I try to demonstrate it |
| 10:14 | Chousuke | $(macroexpand '(defn foo [x] 1)) |
| 10:14 | Chousuke | hm, what happened to sexpbot's evaluator :P |
| 10:14 | moshisushi | Chousuke: just paste it and i'll try for myself in emacs |
| 10:15 | Chousuke | moshisushi: well, try the above. |
| 10:15 | moshisushi | user> (macroexpand '(defn foo [x] 1)) |
| 10:15 | moshisushi | (def foo (clojure.core/fn ([x] 1))) |
| 10:15 | Chousuke | macroexpand is useful :) |
| 10:15 | moshisushi | yeah, a fn |
| 10:15 | Chousuke | C-c C-m does macroexpand in emacs I think |
| 10:15 | Chousuke | hm |
| 10:16 | moshisushi | Chousuke: yeah it does |
| 10:16 | moshisushi | much cleaner too |
| 10:17 | moshisushi | i.e, no unnecessary namespace stuff, it looks |
| 10:17 | Chousuke | did it expand to fn*? |
| 10:17 | moshisushi | (def foo (fn ([x] 1))) |
| 10:18 | moshisushi | that's the expansion with SLIME Macroexpansion |
| 10:18 | Chousuke | hmm, I guess you have the pretty-printer working then |
| 10:18 | moshisushi | Chousuke: probably.. i have a pre-packaged thing called Clojure Box |
| 10:18 | moshisushi | emacs+slime+whatnot |
| 10:19 | Chousuke | I wonder if there is a way to turn off pretty-printing for the macroexpand. sometimes it matters :) |
| 10:19 | Chousuke | well, the namespace-dequalification anyway |
| 10:20 | Chousuke | sometimes you might want to generate code from a macro that explicitly does not have qualified symbols and that makes it hard to tell if you've succeeded or not |
| 10:20 | moshisushi | Chousuke: if i use (macroexpand 'myfun) i don't get prettyprinting |
| 10:20 | Chousuke | I suppose that's good enough. |
| 10:21 | moshisushi | unless there's something in (def foo (clojure.core/fn ([x] 1))) that's also prettyprinted |
| 12:32 | chouser | I just added a var to my repl config so I can (set! *pprint* false) when necessary |
| 12:49 | programble | hm... |
| 12:50 | kotarak | sososososo |
| 12:54 | chouser | VC? |
| 12:54 | chouser | oh, sorry |
| 13:00 | kotarak | chouser: yeah, it's not perfect. But it has some nice things under its belt. :) |
| 13:39 | replaca | moshisushi: yeh, prettyprint is built into slime, but not included in the regular macroexpand |
| 13:57 | moshisushi | replaca: i see! thnx |
| 14:12 | OForero | hi |
| 14:13 | OForero | I am wondering if there is any command that can reset a REPL (connected through Swank) |
| 14:14 | OForero | instead of having to stop and start it |
| 14:38 | Borkdude | how do I create a sorted-map from a map? |
| 14:39 | Borkdude | I have a function (factors), that takes a number and keeps a map of the factors found so far... is it better to use a sorted-map to begin with? I only need to have the end result sorted |
| 14:40 | kotarak | Borkdude: (into (sorted-map) the-map) |
| 14:47 | Borkdude | kotarak: do I have to return a sorted-map everywhere in the factors fun, or there a more clever way to do it? |
| 14:47 | Borkdude | http://gist.github.com/411154 |
| 14:47 | Borkdude | I could use an inner fn and then sort its return val |
| 14:48 | kotarak | (doc fnil) |
| 14:48 | clojurebot | I don't understand. |
| 14:48 | kotarak | pff |
| 14:52 | kotarak | Borkdude: well you can use a sorted-map to begin with. |
| 14:52 | kotarak | Borkdude: but don't ask me, what is better |
| 14:53 | Borkdude | kotarak: ah well, I only have to replace {} with (sorted-map) |
| 14:53 | Borkdude | not too bad |
| 14:59 | Borkdude | if you try this code: (doseq [in (repeatedly #(read-line)) :while in] (print in)) |
| 14:59 | Borkdude | is there any way to get out of this? |
| 15:00 | kotarak | no |
| 15:01 | kotarak | Borkdude: you can do (let [stop? (atom false)] (doseq [in (repeatedly #(read-line)) :while (and in (not @stop?))] (print in))) |
| 15:01 | kotarak | Borkdude: and reset! stop? to true from some other thread |
| 15:15 | Borkdude | kotarak: yes, tnx |
| 15:27 | Borkdude | btw, I don't know why, but if I begin a line with ; in clojure-mode, type and press enter, the line gets indented 40 positions |
| 15:43 | OForero | lein help is failing with this message |
| 15:43 | OForero | http://paste.pocoo.org/show/217486/ |
| 15:43 | OForero | any idea of what could be broken_ |
| 15:43 | angerman | how do I join two lists? |
| 15:50 | angerman | hmm. ok. I had reduce and cons mixed up :/ |
| 15:53 | Raynes | $(concat [1 2 3] [4 5 6]) |
| 15:53 | sexpbot | => (1 2 3 4 5 6) |
| 15:53 | angerman | $(concat '(1 2 3) '(4 5 6)) |
| 15:53 | sexpbot | => (1 2 3 4 5 6) |
| 15:53 | angerman | aye |
| 16:04 | pedroteixeira | anyone knows how to call something like (apply new Class [arg1 arg2]) |
| 16:04 | pedroteixeira | ? |
| 16:08 | pedroteixeira | is "new" a normal function or macro, or is it a special reader macro? |
| 16:10 | Raynes | (doc new) |
| 16:10 | clojurebot | I don't understand. |
| 16:10 | Raynes | pedroteixeira: It's a special form) |
| 16:11 | pedroteixeira | ok, thanks.. trying to figure it out how to instantiate a class with a Seq of args. |
| 16:11 | pedroteixeira | will just use reflection for now.. |
| 16:11 | triyo | you can wrap the special form in fn form and then apply... |
| 16:24 | Borkdude | Is (not (some pred ...)) the same as (every? pred ...), I guess so yes? |
| 16:27 | chouser | no |
| 16:28 | chouser | hm. |
| 16:28 | triyo | hehe |
| 16:28 | chouser | no |
| 16:29 | chouser | ,(not (some odd? [2])) |
| 16:29 | clojurebot | true |
| 16:29 | chouser | ,(every? odd? [2]) |
| 16:29 | clojurebot | false |
| 16:29 | chouser | (not (some ...)) is the same as (not-any? ...) |
| 16:37 | Borkdude | chouser: of course, doh |
| 16:37 | Borkdude | useful to know, there is not-any |
| 16:37 | Borkdude | with question mark |
| 16:38 | Borkdude | One more question, is :default and :else more or less the same in cond? |
| 16:40 | chouser | sure, anything that's always true would work, including 'true'. But :else is idiomatic -- please use it. |
| 16:40 | Borkdude | ah yes, alright |
| 16:42 | Borkdude | If I find myself doing a lot of (first (filter pred coll)), should I use a different construct maybe? |
| 16:47 | mabes | ,(source find-first) |
| 16:47 | clojurebot | java.lang.Exception: Unable to resolve symbol: source in this context |
| 16:47 | mabes | ,(doc find-first) |
| 16:47 | clojurebot | "clojure.contrib.seq-utils/find-first;[[pred coll]]; Returns the first item of coll for which (pred item) returns logical true. Consumes sequences up to the first match, will consume the entire sequence and return nil if no match is found." |
| 16:48 | mabes | Borkdude: ^ find-first does what you are doing |
| 16:48 | Borkdude | mabes, great, tnx |
| 17:28 | OForero | what will be the equivalent of overriding toString? |
| 17:29 | OForero | I want to have a different print routine for one of my defined strings |
| 17:41 | empt | are there any free but complete book for latest clojure? |
| 17:42 | Raynes | The closest thing to a 'book' around is the ociweb tutorial. |
| 17:42 | Raynes | That's free, anyway. |
| 17:43 | empt | ok I'll check to find if I've looked at it before |
| 17:43 | Raynes | Otherwise, you have The Joy of Clojure (7 chapters in the MEAP already). |
| 17:43 | Raynes | http://java.ociweb.com/mark/clojure/article.html |
| 17:43 | sexpbot | "Object Computing, Inc. - Java News Brief - March 2009" |
| 17:43 | Borkdude | empt: I got a free ebook |
| 17:43 | empt | hi Borkdude |
| 17:43 | Borkdude | empt: from someone on Twitter, let me search his address |
| 17:44 | Borkdude | empt: satish.talim@gmail.com, just send him a mail and he'll send you his ebook |
| 17:45 | empt | thank you and Raynes |
| 17:45 | Borkdude | empt: don't know how good this ebook is, haven't read it |
| 17:46 | empt | that's ok thanks |
| 17:48 | OForero | is there any way to make println behave differently for a self defined struct_ |
| 17:48 | OForero | ? |
| 17:53 | riddochc | OForero: Differently how? |
| 17:54 | OForero | I have a stuation were structs reference eachothers .. and if I do println at the REPL ends up in a stack overflow |
| 17:55 | OForero | I was wondering if I can then define a custom println (that does not do a deep print) for one of them |
| 17:56 | riddochc | Ah, you want to set *print-length* or *print-level* |
| 17:57 | riddochc | That controls a lot of the printing functions, including println. Generally helpful at the REPL. |
| 17:58 | OForero | ## |
| 17:59 | OForero | do I just def them_ |
| 18:03 | riddochc | I think you want to use (set! *print-length* ...) |
| 18:03 | riddochc | They're already def'd. |
| 18:11 | ihodes | hi all – is anyone familiar with String->java.util.Date->String kinda stuff? |
| 18:13 | ihodes | or could point to where i might find some nice info on it? |
| 18:18 | ihodes | people are less chatty then they used to be? |
| 18:21 | Raynes | At the moment. |
| 18:39 | dnolen | ihodes: have you look at the Joda time Clojure wrapper? |
| 18:40 | ihodes | I have not–where is that at? |
| 18:40 | dnolen | ihodes: http://github.com/clj-sys/clj-time |
| 18:40 | ihodes | oh nice, that looks like it may work |
| 18:41 | ihodes | thank you very much. i have an additional question, though. i'm having trouble calling static methods in clojure: i (import (java.text.DateFormat)) and then, for example, cannot for the life of me figure out how to call... getTimeZone, for instance. |
| 18:41 | ihodes | is there something i'm missing? |
| 18:42 | dnolen | DateFormat/getTimeZone |
| 18:42 | ihodes | (. DateFormat getTimezone) or (. java.text.DateFormat getTimezone) or (DateFormat/getTimeZone) all don't work |
| 18:42 | ihodes | java.lang.NoSuchFieldException: getTimeZone (NO_SOURCE_FILE:17) is what i get |
| 18:45 | dnolen | ihodes: getTimeZone is not a static method |
| 18:46 | dnolen | try (DateFormat/getDateInstnace) |
| 18:46 | ihodes | crap.... i'm sorry then :\ . I'll try that, then |
| 18:47 | dnolen | ihodes: (. (DateFormat/getDateInstance) getTimeZone) |
| 18:47 | dnolen | works for me |
| 18:47 | dnolen | ,(. (java.text.DateFormat/getDateInstance) getTimeZone) |
| 18:47 | clojurebot | #<ZoneInfo sun.util.calendar.ZoneInfo[id="America/Los_Angeles",offset=-28800000,dstSavings=3600000,useDaylight=true,transitions=185,lastRule=java.util.SimpleTimeZone[id=America/Los_Angeles,offset=-28800000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=2,startDay=8,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=3,endMonth=10,endDay=1,endDayOfWeek=1,endTime=7200000,endTimeMode=0]]> |
| 18:47 | quizme | what is ->> ? |
| 18:48 | Borkdude | ,(doc ->>) |
| 18:48 | 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." |
| 18:48 | ihodes | works for me! thank you so much |
| 18:48 | dnolen | ,(->> "last" (str "second") (str "first")) |
| 18:48 | clojurebot | "firstsecondlast" |
| 18:50 | dnolen | ,(macroexpand '(->> "last" (str "second") (str "first"))) |
| 18:50 | clojurebot | (str "first" (clojure.core/->> "last" (str "second"))) |
| 18:50 | dnolen | ,(macroexpand '(str "first" (clojure.core/->> "last" (str "second")))) |
| 18:50 | clojurebot | (str "first" (clojure.core/->> "last" (str "second"))) |
| 18:53 | leifw | anyone familiar with clj-processing or know where I can find people that do? |
| 18:53 | leifw | I'm getting a segfault in X when I try to run one of the examples |
| 18:53 | leifw | I could swear I got it working once but never again |
| 18:54 | dnolen | liefw: what os are you on? |
| 18:54 | leifw | linux |
| 18:55 | leifw | ubuntu, kernel is 2.6.32 |
| 18:55 | leifw | X version is 1.7.6 |
| 18:55 | dnolen | hmm, I've only tried it on os x |
| 18:55 | leifw | dang |
| 18:55 | leifw | I really really want this working :-/ |
| 18:56 | leifw | ooh looks like it's somewhere in the intel drivers |
| 18:56 | leifw | blech |
| 18:56 | dnolen | fwiw, Penumbra is pretty nice if you want to do interactive graphics and it's known to work on windows/linux/os x |
| 18:56 | leifw | ooh I'll have to check that out |
| 18:57 | leifw | the eclipse plugin? |
| 18:57 | dnolen | http://github.com/ztellman/penumbra |
| 18:58 | leifw | aha |
| 18:58 | leifw | neato |
| 18:59 | dnolen | it's opengl, but penumbra makes it enjoyable/fun, comes with examples of Tetris (< 250 LOC) and Asteroids (< 500 LOC) |
| 18:59 | leifw | cool |
| 18:59 | leifw | I'll have to try that out |
| 19:00 | dnolen | on ubuntu, it "just worked" for me. |
| 19:00 | dnolen | well under parallels anyway :) |
| 19:00 | somnium | dnolen: what video card? |
| 19:00 | dnolen | NVIDIA GeForce GT 330M |
| 19:01 | somnium | ah |
| 19:02 | somnium | I never suspected open source intel drivers could crash X so often when I got this laptop :/ |
| 19:02 | quizme | new discovery for me: (for [x (range 2) y (range 3)] [x,y]) |
| 19:02 | quizme | :) |
| 19:02 | quizme | dnolen thanks |
| 19:03 | dnolen | quizme: np |
| 19:10 | Borkdude | ,(for [x (range 10) y (range 5) :when (= y 4) :while (< x y) :let [p (* x y)]] p) |
| 19:10 | clojurebot | (0 4 8 12) |
| 19:18 | dnolen | I was impressed by this Haskell snippet: let rightTriangles' = [ (a,b,c) | c <- [1..10], b <- [1..c], a <- [1..b], a^2 + b^2 == c^2, a+b+c == 24] , from learn you a haskell |
| 19:18 | dnolen | ,(let [r (range 1 11)] (for [c r b r :while (< b c) a r :while (< a b) :when (and (= (+ (* a a) (* b b)) (* c c)) (= (+ a b c) 24))] [a b c])) |
| 19:18 | clojurebot | ([6 8 10]) |
| 19:23 | Borkdude | ,(for [c (range 1 11) b (range 1 c) a (range 1 b) |
| 19:23 | Borkdude | :when (and (= (+ (* a a) (* b b)) (* c c)) |
| 19:23 | Borkdude | (= (+ a b c) 24))] |
| 19:23 | Borkdude | [a,b,c]) |
| 19:23 | clojurebot | EOF while reading |
| 19:23 | Borkdude | damnit |
| 19:24 | Borkdude | ,(for [c (range 1 11) b (range 1 c) a (range 1 b) :when (and (= (+ (* a a) (* b b)) (* c c)) (= (+ a b c) 24))] [a,b,c]) |
| 19:24 | clojurebot | ([6 8 10]) |
| 20:02 | riddochc | Hmmm... Var clojure.core/unquote is unbound. |
| 20:09 | somnium | ,~42 |
| 20:09 | clojurebot | java.lang.IllegalStateException: Var clojure.core/unquote is unbound. |
| 20:10 | somnium | ,(macroexpand '~42) |
| 20:10 | clojurebot | (clojure.core/unquote 42) |
| 20:12 | somnium | ,(binding [unquote (fn [x] (* x x))] ~42) |
| 20:12 | clojurebot | 1764 |
| 20:21 | riddochc | Hm. So it's only bound within a macro's backquoted list, for my purposes. Must be a local function in the macroexpansion, then. |
| 21:07 | defn | is it correct to use the term niladic these days? |
| 21:09 | durka42 | can I set java.library.path for lein repl? |
| 21:11 | durka42 | got it - $JAVA_OPTS |
| 21:25 | somnium | niladic? |
| 21:36 | defn | somnium: i believe it comes from APL |
| 21:36 | defn | niladic, monadic, dyadic |
| 21:36 | defn | (computing) Of an operator or function in a program, having no arguments. |
| 21:37 | defn | ^-niladic |
| 21:41 | pastorn | i wanna try clojure out... is there a .deb somewhere that gives me all i need? |
| 21:44 | pastorn | silly me |
| 21:44 | TheBusby | Ubuntu 10.04 appears to have a something in the repo, more detail here: http://bit.ly/b1dO1l |
| 21:44 | sexpbot | "Clojure Programming/Getting Started - Wikibooks, collection of open-content textbooks" |
| 21:44 | pastorn | there was a 'clojure' package (apropos didn't say anything) |
| 21:45 | pastorn | in the repl, is there a 'reload' command? |
| 21:47 | TheBusby | ,(doc load-file) |
| 21:47 | clojurebot | "([name]); Sequentially read and evaluate the set of forms contained in the file." |
| 21:49 | pastorn | how do you program in clojure? i'm used to mostly doing haskell |
| 21:49 | pastorn | so i write som stuff in gvim, alt-tab to the repl; :r to reload and test my new functions |
| 21:49 | pastorn | then back to the source file and write more stuff |
| 21:50 | pastorn | is that the way you work when programming clojure as well? |
| 21:50 | TheBusby | I use emacs, but I think clojurebox does that for Vi |
| 21:50 | TheBusby | nmind |
| 21:50 | pastorn | TheBusby: nah, i'm pretty comfortable with the unix principle |
| 21:50 | TheBusby | the link I provided earlier has a section on setting up clojure and vim |
| 21:50 | pastorn | (it should do one thing and do it well) |
| 21:51 | pastorn | my editor is my editor and the repl is the repl... also: don't know any of vims window splitting commands |
| 21:52 | TheBusby | more details here if you're interested, http://kotka.de/projects/clojure/vimclojure.html |
| 21:52 | sexpbot | "Kotka : Projects : Clojure : VimClojure" |
| 22:09 | pastorn | hang on here... |
| 22:09 | pastorn | (map + [1 2 3] [4 5 6]) |
| 22:09 | pastorn | that doesn't make sense... that's zipwith |
| 22:12 | pastorn | it feels weird that it takes three arguments :/ |
| 22:15 | tomoj | it's n-ary zipWith :) |
| 22:15 | pastorn | haha |
| 22:15 | pastorn | there's zipWith as well? |
| 22:16 | tomoj | zipWith from haskell I meant |
| 22:16 | pastorn | yeah |
| 22:20 | pastorn | so where should i start reading to learn clojure? what's good? wikibooks? |
| 22:20 | pastorn | (the wikibooks doesn't seem to have a very consistent design :( ) |
| 22:20 | pastorn | *wikibooks articles* |
| 22:27 | pastorn | TheBusby: i can't get ,(doc load-file) to work |
| 22:27 | pastorn | ,(doc Test.clj) <-- this doesn't work :( |
| 22:27 | clojurebot | java.lang.ClassNotFoundException: Test.clj |
| 22:28 | pastorn | almost; i get "Unable to resolve var" |
| 22:39 | TheBusby | pastorn: does (doc use) work? |
| 22:39 | TheBusby | load-file is clojure core, at least in 1.1.0 |
| 22:39 | pastorn | it seems to print some help stuff |
| 22:40 | TheBusby | arg, brb |
| 22:40 | pastorn | do i need to declare a module name in the file for this to work? |
| 22:41 | pastorn | this is my file: http://paste.lisp.org/display/100334 |
| 22:42 | pastorn | reload that page now... |
| 22:48 | defn | pastorn: how do mean module name? |
| 22:48 | defn | as in a namespace? |
| 22:48 | pastorn | defn: something like that |
| 22:49 | defn | like (ns pastorn.hello-world) |
| 22:49 | pastorn | in haskell if you have i.e. Stack.hs, then the first line in that file should be "module Stack where" |
| 22:49 | defn | are you planning on reusing your hello [name] function in other places? ;) |
| 22:49 | pastorn | so that when you import you write 'import Stack' and not 'import "Stack.hs"' |
| 22:49 | defn | pastorn: short answer is: it depends |
| 22:50 | pastorn | defn: no, i just wont clojure-repl to reload my file in which i've placed some new functions |
| 22:50 | defn | (load-file "myfile.clj") |
| 22:50 | pastorn | java.lang.Exception: Unable to resolve symbol: define in this context (Test.clj:7) |
| 22:50 | defn | err i think, maybe im thinking elisp |
| 22:52 | defn | pastorn: are you using "define" somewhere in your Test.clj? |
| 22:52 | pastorn | oh siht |
| 22:52 | defn | ;) |
| 22:52 | pastorn | yay! |
| 22:52 | defn | going back to a movie, ill try and check back if you need anything |
| 22:52 | defn | ciao |
| 22:52 | pastorn | i've been playing around some in DrScheme, so i'm a bit damaged... |
| 22:52 | defn | hey no worries |
| 22:52 | defn | enjoy your clojure :) |
| 22:53 | pastorn | hehe |
| 23:00 | pastorn | what is this? no long comments? |
| 23:01 | Raynes | pastorn: (comment comment goes here) |
| 23:01 | pastorn | haha |
| 23:01 | pastorn | nasty :D |
| 23:01 | Raynes | You can also comment out individual forms with #_. |
| 23:02 | Raynes | But that's usually only useful for debugging. |
| 23:02 | pastorn | Raynes: form = (expr) ? |
| 23:02 | pastorn | (+ 1 2 #_3) ;; cool |
| 23:03 | Raynes | $(println #_"this one just snuck in here." "ohai") |
| 23:03 | Raynes | $(println #_(meow) "ohai") |
| 23:03 | sexpbot | => ohai nil |
| 23:03 | sexpbot | => ohai nil |
| 23:03 | pastorn | Raynes: what's the $? |
| 23:04 | Raynes | It tells sexpbot to evaluate whatever is passed to it in parens. If you need to evaluate something that isn't in parens, you can use $eval (e.g $eval 'meow) |
| 23:04 | Raynes | We also have clojurebot, which does evaluation as well with , as the prepend (e.g ,(println "hai")) |
| 23:05 | pastorn | eval/apply are the same as the ones in scheme? |
| 23:05 | Raynes | Never used Scheme. |
| 23:05 | pastorn | looking here: http://java.ociweb.com/mark/clojure/article.html#Syntax |
| 23:05 | sexpbot | "Object Computing, Inc. - Java News Brief - March 2009" |
| 23:05 | pastorn | there's no lambda? |
| 23:06 | Raynes | $(apply + [1 2 3 4 5]) |
| 23:06 | sexpbot | => 15 |
| 23:06 | dysinger | like we need another bot in here :/ |
| 23:06 | pastorn | in haskell you're able to do 'map (\x -> x + x*x) [1,2,3,4])' |
| 23:06 | pastorn | s/)'/' |
| 23:06 | Raynes | $((fn [x] (* x x)) 10) |
| 23:06 | Raynes | dysinger: Yeah, it's only been in here for around two months now. |
| 23:06 | sexpbot | => 100 |
| 23:07 | Raynes | pastorn: fn is lambda. |
| 23:07 | pastorn | oh, nice |
| 23:07 | dysinger | Raynes - why what's the point - we already have had clojurebot for years |
| 23:07 | pastorn | $(map (fn [x] (+ x (* x x)) [1 2 3 4 5]) |
| 23:07 | sexpbot | EOF while reading |
| 23:07 | pastorn | $(map (fn [x] (+ x (* x x)) [1 2 3 4 5])) |
| 23:08 | sexpbot | DENIED! |
| 23:08 | pastorn | :( |
| 23:08 | dysinger | annoying |
| 23:08 | pastorn | ,(map (fn [x] (+ x (* x x)) [1 2 3 4 5])) |
| 23:08 | clojurebot | java.lang.IllegalArgumentException: Wrong number of args passed to: core$map |
| 23:08 | pastorn | ,(map (fn [x] (+ x (* x x))) [1 2 3 4 5]) |
| 23:08 | clojurebot | (2 6 12 20 30) |
| 23:08 | pastorn | there we go :) |
| 23:09 | Raynes | dysinger: At least a few people thought the title scraping was useful, and sexpbot does do a few things that clojurebot doesn't. Doesn't matter, I'll take him out of here. I'm tired of all the remarks. |
| 23:09 | pastorn | ,(map (+ %1 (* %1 %1)) [1 2 3 4 5]) |
| 23:09 | clojurebot | java.lang.Exception: Unable to resolve symbol: %1 in this context |
| 23:09 | pastorn | ,(map #(+ %1 (* %1 %1)) [1 2 3 4 5]) |
| 23:09 | clojurebot | (2 6 12 20 30) |
| 23:10 | pastorn | i'll stop spamming now :) |
| 23:10 | sexpbot | Bai! |
| 23:10 | dysinger | We've all written bots |
| 23:10 | dysinger | I have also |
| 23:10 | pastorn | can you reload clojure code for running programs like in erlang or scheme? |
| 23:10 | dysinger | having several of them in the room is ... not needed |
| 23:10 | dnolen | pastorn: yup |
| 23:11 | programble | having you in the room is ... not needed |
| 23:11 | programble | no offense |
| 23:11 | programble | but it is true |
| 23:11 | dysinger | lol |
| 23:11 | Raynes | dysinger: Until yesterday, nobody seemed to care. Hell, people seemed to like him a little. It's alright. He's gone, wont be coming back. |
| 23:11 | Raynes | :) |
| 23:11 | programble | so i think your argument proves useless |
| 23:11 | pastorn | dnolen: and it doesn't involve weird hacks like in haskell (where you need to import the compiler to make it work) |
| 23:11 | pastorn | ? |
| 23:12 | dysinger | programble: whatever |
| 23:13 | dnolen | pastorn: nope. everything you enter in the REPL in Clojure is compiled |
| 23:13 | pastorn | dnolen: but what if it's a big nasty function that i need to have in a file? |
| 23:14 | pastorn | can the calls to that function be replaced with the new definition on runtime? |
| 23:14 | dnolen | pastorn: use an IDE that lets you send only that definition to the REPL |
| 23:14 | dnolen | pastorn: yes. |
| 23:14 | pastorn | nice :) |
| 23:16 | pastorn | you're much friendlier in here than in #scheme :) |
| 23:34 | programble | danlarkin and dysinger are butt-buddies, rite? |
| 23:37 | programble | dysinger: hello? |
| 23:39 | dysinger | programble: ignored |
| 23:39 | dysinger | what are you guys ? 12 ? |
| 23:41 | programble | dysinger: are you and danlarkin? |
| 23:57 | rava | good eve |
| 23:59 | rava | any way in emacs/swank-clojure to find out what line in the source file is causing the compile to blow? |