2011-08-03
| 00:08 | semperos | at the Slime repl I generally just work inside namespaces that I've loaded via a file, but for the first time I was using `in-ns` to create some throw-away namespaces |
| 00:09 | semperos | I thought when you switched to a new namespace with `in-ns`, you started with a "blank slate" |
| 00:09 | semperos | so nothing I had `require` or `use` in another namesapce with be available |
| 00:09 | semperos | is that not the case? |
| 00:14 | Pupeno | Hello. |
| 00:14 | pcavs | semperos: I believe that is the case, what makes you think that is not? |
| 00:14 | semperos | pcavs: working at the repl, switching between namespaces and not having a "blank slate" between namespaces |
| 00:14 | dnolen | :D tell me you don't want this awesomeness, https://gist.github.com/1121891 |
| 00:20 | pcavs | semperos: could you be more precise? certain core clojure libs are defaulted to being loaded in every ns |
| 00:21 | semperos | let's say I created a file with a namespace of foo |
| 00:22 | semperos | then at the repl, I enter a namespace bar by evaluating `(in-ns 'bar)` |
| 00:22 | semperos | while inside bar, I `(require 'foo)` |
| 00:22 | semperos | then, say I leave bar and go to the user namespace, `(in-ns 'user)` |
| 00:23 | semperos | what I'm experiencing at that point is the functions in my file's `foo` namespace, that I required while inside bar, are available in my user namespace at the REPL |
| 00:23 | pcavs | what if you change 'user to be 'baz |
| 00:23 | pcavs | same effect? |
| 00:25 | pcavs | semperos: I'm just thinking that there may be some defaults already loaded into the 'user namespace previously, which you forgot to wipe, or from leiningen/whatever you're using for your swank server |
| 00:25 | pcavs | since 'user is the default ns name |
| 00:25 | semperos | yes |
| 00:25 | semperos | that was just an example, the point is that when switching between namespaces, code `required` in one is available in another |
| 00:26 | semperos | possible "expected" behavior of swank, but it just doesn't make much sense to me |
| 00:26 | pcavs | semperos: interesting |
| 00:28 | lobotomy | having some problems with multimethods, trying type-based dispatch: http://pastebin.com/i2nHHUs7 |
| 00:28 | lobotomy | questions: 1) does this sort of "typing" thing make sense in clojure anyway? :) 2) why isn't it working? |
| 00:29 | brehaut | lobotomy: types definately exist in clojure, but the signatures of functions are not bound to them as they would be in java |
| 00:35 | brehaut | lobotomy: your definition for make-piece you have defmulti where you mean defmethod |
| 00:36 | lobotomy | ...oh ffs |
| 00:36 | lobotomy | thanks a lot :D |
| 00:36 | brehaut | np |
| 00:38 | semperos | lobotomy: for pure type-based dispatch, protocols might be a better fit |
| 00:38 | brehaut | semperos: hes doing multiple dispatch however, so multis is right in this case |
| 00:39 | tomoj | is it? |
| 00:39 | tomoj | I guess there are some missing parts maybe that justify the use of records and multimethods |
| 00:39 | brehaut | tomoj: for make-piece it is |
| 00:39 | tomoj | ok |
| 00:40 | brehaut | make-edge could definately be a protocol |
| 00:40 | semperos | yep |
| 00:40 | tomoj | oh, I guess there are going to be more implementations? |
| 00:40 | tomoj | :) |
| 00:41 | brehaut | oh, no tomoj you are right, it doesnt need to be multiple dispatch if its always expecting strings for second and third args |
| 00:42 | tomoj | I was looking at just that code thinking less than 5 lines do exactly the same thing, but the part left out is where else you're going with it |
| 00:42 | tomoj | (naturally..) |
| 00:44 | brehaut | lobotomy: if you dont care about the types of the second and third args, you dont need to make your dispatch function handle them. |
| 00:47 | lobotomy | tomoj, i don't know yet where i'm going with it :) right now though, nowhere |
| 00:47 | brehaut | lobotomy: which is to say (fn [[a & _] _ _] (type a)) would do for your dispatch function |
| 00:47 | lobotomy | hmm, destructuring. good point |
| 00:48 | tomoj | (comp type first vector) |
| 00:48 | brehaut | tomoj: that was my first though too :P but i think the destructuring is nicer in this case, because its explicit about the arguments |
| 00:48 | lobotomy | was also thinking where best to verify the validity of the given edges... a {:pre ...} in make-piece-from-edges i think? |
| 00:49 | brehaut | oh, tomoj ffirst rather than first |
| 00:49 | tomoj | right |
| 00:49 | lobotomy | my first version had a make-piece with a {:pre} that checked if the given things are strings, if so turned them into edges, and checked if they're valid for a piece, but that just seemed ugly |
| 00:49 | tomoj | lobotomy: .. so you aren't just using multimethods and records because it looks sorta like some OOP you're used to, are you? :) |
| 00:50 | lobotomy | well, the previous version of this program i wrote in java, so hm... ;) |
| 00:50 | lobotomy | yeah, i'm kind of contaminated that way, haha |
| 00:50 | brehaut | lobotomy you can actually scrap the entire multi for make-piece; |
| 00:51 | brehaut | (defn make-piece [e c n] (Piece. (make-edge e) c n)) |
| 00:51 | brehaut | if you (defmethod make-edge Edge [x] x) |
| 00:52 | tomoj | I doubt there is need for Pieces or Edges |
| 00:52 | Pupeno | I need an embedded database for my app, should I go with Derby? |
| 00:52 | tomoj | nor for make-piece |
| 00:53 | lobotomy | well, the use case is basically that i want to be able to say (make-piece ["00011" "10100" "00110" "00110"] "purple" "P1") and have it verify that the edges (or strings, whichever) match each other |
| 00:53 | brehaut | lobotomy: and if you have a fixed set of types that you need to coerce, you dont need late bound polymorphism, you can just use case (or other cond family form) |
| 00:53 | tomoj | why not just use the ints themselves, (filter #(<= 0 % 31)) them (or throw an exception if you insist..) |
| 00:53 | lobotomy | tomoj, not sure how things would be clearer without Piece or Edge at all? |
| 00:53 | lobotomy | i mean, at this point probably, but once i add the other zillion lines of stuff |
| 00:54 | tomoj | then just write {:edges [1 2 3 4] :colour "purple" :name "P1"} |
| 00:54 | tomoj | I suggest adding multimethods and records and these things after you notice you need them |
| 00:54 | lobotomy | how to do the error checking though with {}? |
| 00:55 | tomoj | before, they just turn 3 lines of code into 30 |
| 00:55 | lobotomy | for instance, "10101" "01101" is invalid since the corner between consecutive edges can't be both 1 and 0 |
| 00:56 | lobotomy | you're saying to do the make-piece just with that check, parseInt and that's all? i guess that could work too :] |
| 00:56 | tomoj | well, I don't know about any of that, was just looking at the code, so can't really say you don't need multimethods or records |
| 00:56 | lobotomy | yeah, the code isn't all, but the rest is rather unfinished |
| 00:56 | tomoj | but.. it is generally better to err towards not using them |
| 00:57 | lobotomy | in the (near) future i'll need to add a mutable version of edges and hmm... i'll need to link the mutable edges together |
| 00:57 | tomoj | ..guess that is not really useful advice, since them problem is just deciding whether or not you need them |
| 00:58 | tomoj | oh god |
| 00:58 | tomoj | wait |
| 00:58 | lobotomy | i think at that point it will be necessary to wrap the int in something |
| 00:58 | lobotomy | in the mutable edge i mean |
| 00:58 | tomoj | you mean mutable like clojure's reference types? |
| 00:59 | tomoj | or mutable like bad evil mutable? |
| 00:59 | tomoj | :) |
| 00:59 | lobotomy | i don't know. was thinking of using ref |
| 00:59 | lobotomy | what i'd do is build a wire frame kind of thing, for this puzzle solver |
| 00:59 | tomoj | whew, thought you meant really mutable |
| 00:59 | lobotomy | into which pieces are "added" as the solver proceeds |
| 01:00 | lobotomy | and the addition is probably a lot simpler by just changing the int inside the edge |
| 01:00 | semperos | tomoj: nothing inherently evil about mutable state; things get interesting with *shared* mutable state, but localized mutability can be used strategically |
| 01:00 | tomoj | what puzzle is it, anyway? was curious from the beginning |
| 01:00 | lobotomy | since the edge needs to be linked to other edges, and creating a new edge and transferring the links seems more complicated than modifying existing edge's int and not touching the links |
| 01:00 | lobotomy | http://www.happycube.com/ |
| 01:02 | brehaut | oh man. happy cubes |
| 01:02 | tomoj | neat |
| 01:02 | brehaut | so many hours of suffering and fun |
| 01:02 | tomoj | I can feel the frustration watching those flash videos |
| 01:05 | lobotomy | here's some ascii art: http://pastebin.com/mp3QNzHB |
| 01:06 | brehaut | tomoj: once you have the basic cubes solved, you get the frustration of assembling shapes from multiple cube sets |
| 01:07 | lobotomy | anyway, the java version of the solver simply has Edge, MutableEdge, Piece and Hole |
| 01:07 | lobotomy | and Structure, which is a bunch of holes plus the solver |
| 01:07 | brehaut | lobotomy: why are you repeating the corners? |
| 01:07 | lobotomy | why not? |
| 01:08 | brehaut | no i mean, what is the benefit you gain from it? |
| 01:08 | lobotomy | it's probably simplest to just repeat them :) |
| 01:08 | lobotomy | how else would you do it? edges and corners separately? |
| 01:08 | lobotomy | that's more complicated, but the benefit is... what? |
| 01:08 | brehaut | lobotomy: what about a vector of 16 bools? |
| 01:09 | lobotomy | with that, how would it work when you're modeling something like this: http://happysolver.sourceforge.net/realComplex.jpg |
| 01:10 | lobotomy | which bools in which vectors would correspond to which holes in the structure you're trying to build? |
| 01:11 | lobotomy | (i'm not saying my edge linking solution is the best, but it seems the most intuitive to me) |
| 01:12 | brehaut | lobotomy, the bools encode the same information your vector of strings does, but flattened |
| 01:12 | brehaut | and with the corners occuring only once |
| 01:13 | brehaut | (because the end of side of a piece is the beginning of the next side) |
| 01:13 | tomoj | in the solutions, are the pieces always arranged in (a subset of) a 3d grid? |
| 01:13 | brehaut | yes |
| 01:13 | tomoj | (like in the picture, in a single cube, in a flat arrangement) |
| 01:14 | lobotomy | brehaut, and why would i want the information flattened? |
| 01:14 | lobotomy | the 3d structure doesn't look very flattened... |
| 01:15 | brehaut | lobotomy: i like to choose the simplist representation possible; and the simplest one possible is the one i can apply more standard library function |
| 01:15 | tomoj | no need to validate that the corners in the input edges match up if there's no room for error because you only specify each corner once |
| 01:16 | lobotomy | no need to optimise that bit out since all pieces are immutable and specified only once |
| 01:16 | lobotomy | the more important point is the 3d (mutable) structure |
| 01:16 | tomoj | originally I was thinking your way made sense, if the pieces never change maybe I still do |
| 01:17 | lobotomy | brehaut, what then is the simplest representation possible for that big 3d case? i'm inclined to think flattened won't do |
| 01:17 | brehaut | lobotomy: consider this [false false false true true true false true false false false true false false true true false] |
| 01:17 | lobotomy | well, of course flattened is possible, but... |
| 01:18 | brehaut | so the case of rotations you just need to use cycle drop take |
| 01:19 | lobotomy | think about it this way: i have a piece, and a structure with a hole. task: find out if the piece matches the hole |
| 01:19 | lobotomy | now, you're saying that the structure is a flat vector of bools? |
| 01:19 | lobotomy | where in that vector is the hole? which bools? |
| 01:20 | lobotomy | my current solution simply has a Hole, which consists of 4 MutableEdges. done |
| 01:20 | lobotomy | when i find a matching piece, i modify the hole's mutable edges (and, possibly, their successor edges - since corners are shared) to incorporate it |
| 01:22 | tomoj | if you write the clojure like the java it's going to be ugly |
| 01:23 | tomoj | don't think most idiomatic solutions to this problem in clojure use any mutability or refs or multimethods or records |
| 01:24 | lobotomy | hmm, by "this problem" do you mean the entire problem, or just the (immutable) edges and pieces? |
| 01:24 | tomoj | ..but I just realized I've only been thinking of the puzzle, and have only a vague idea what an actual solver algorithm looks like, so.. dunno |
| 01:24 | brehaut | lobotomy: consider this ##(every? #(== 1 %) (map bit-xor [1 1 1 0 1] [0 0 0 1 1])) |
| 01:24 | lazybot | ⇒ false |
| 01:24 | tomoj | I meant the entire problem, for that specific puzzle (generalizations might make use of records/multimethods I suppose) |
| 01:25 | lobotomy | are you saying my solution is easier to do without mutability, or that there's an idiomatic solution where no mutability is needed? |
| 01:27 | brehaut | lobotomy: heres every rotation of a piece ##(take 4 (partition 16 4 (cycle [0 0 0 1 1 1 0 1 0 0 0 1 0 0 0 1 1 0]))) |
| 01:27 | lazybot | ⇒ ((0 0 0 1 1 1 0 1 0 0 0 1 0 0 0 1) (1 1 0 1 0 0 0 1 0 0 0 1 1 0 0 0) (0 0 0 1 0 0 0 1 1 0 0 0 0 1 1 1) (0 0 0 1 1 0 0 0 0 1 1 1 0 1 0 0)) |
| 01:27 | clojurebot | ,(let [testar (fn [x y] (if (= (reduce + (filter odd? (range 0 x))) y) (str y " is an square perfect")) )] (testar 10 25)) |
| 01:27 | lobotomy | (the solver algorithm is a simple depth-first search, not much mystery there) |
| 01:29 | tomoj | hmm |
| 01:30 | tomoj | if you have a partial clojure solution written with mutability in mind, I have no idea whether it is easier to write a different (more idiomatic) solution in clojure instead of just finishing it |
| 01:30 | lobotomy | are you sure that idiomatic clojure never has any mutability in it anywhere? :) |
| 01:31 | brehaut | idiomatic clojure strongly favors immutability |
| 01:31 | tomoj | I am sure that that is not true |
| 01:31 | lobotomy | i'm basically making a wireframe, then modifying that as the solver proceeds, and that seems like the most natural way of doing this |
| 01:31 | lobotomy | in the java version i have multiple solver threads, each creates its own private version of the wireframe |
| 01:31 | lobotomy | but the pieces are shared since those are immutable |
| 01:32 | brehaut | lobotomy: both breadth and depth first search are algorithms that naturally suits immutable implementation |
| 01:33 | lobotomy | and the wireframe is a thing that naturally suits a mutable implementation |
| 01:34 | tomoj | we should probably taboo "mutable" |
| 01:34 | tomoj | I don't think we're talking about the same things |
| 01:41 | tomoj | do you have any of the wireframe code written yet? |
| 01:42 | tomoj | well, is that your sourceforge project? |
| 01:44 | lobotomy | hmm, no, the sourceforge one is completely different |
| 01:44 | brehaut | lobotomy: are you wanting the solver to find arbitrary solutions, or to solve specific shapes? |
| 01:44 | lobotomy | mine is unreleased. just wrote it for fun, not looking at the sourceforge version :) |
| 01:44 | tomoj | ah |
| 01:44 | lobotomy | to solve specific shapes with given pieces |
| 01:45 | lobotomy | basically, the problem is: given a list of pieces, and a shape, print out (somehow) the solution, or indicate that one doesn't exist |
| 01:45 | lobotomy | my code just prints out the pieces in the solution with ascii art, in a predetermined order (depending on the shape) |
| 01:45 | lobotomy | so it's not quite as user friendly as the sourceforge solution ;) |
| 01:47 | brehaut | sure, thats the easier one than any arbitrary shape |
| 01:47 | lobotomy | my version supports arbitrary shapes actually |
| 01:47 | brehaut | you misunderstand |
| 01:48 | lobotomy | you mean, given these pieces, figure out which shapes can be built? |
| 01:48 | brehaut | yes |
| 01:48 | lobotomy | hmm... that could be done fairly easily with my solution: go through each shape, if shape requires at most n pieces, try to solve it with the given n pieces |
| 01:49 | brehaut | way more concise than the garbled explaination iwas typing :P |
| 01:49 | lobotomy | beyond a certain point the shapes start to require more than n pieces so this will eventually terminate ;) |
| 01:59 | tomoj | so you have some canonical order for holes |
| 01:59 | tomoj | a shape is a list of open hole indices |
| 02:00 | tomoj | eh.. a shape is a function from holes to sets of holes |
| 02:01 | tomoj | or neither of those but both mixed together, I dunno |
| 02:13 | tomoj | lobotomy: ok, does representing a shape as a list of hole coords make sense? |
| 02:14 | lobotomy | coords? do elaborate |
| 02:22 | tomoj | so the simple cube is, uh |
| 02:23 | tomoj | &(for [x [0 1] y [0 1] z [0 1]] [x y z]) |
| 02:23 | lazybot | ⇒ ([0 0 0] [0 0 1] [0 1 0] [0 1 1] [1 0 0] [1 0 1] [1 1 0] [1 1 1]) |
| 02:23 | tomoj | guess not, he |
| 02:23 | tomoj | eh |
| 02:28 | tomoj | I was thinking in 2d with a bad analogy, not going to understand this problem tonight :) |
| 03:33 | Cozey | Hello. How to run a multi module (reactor build) from leiningen's maven integration? Is it possible? I have a project A (lein) depending on B (maven) and I'd like to quickly update A's loaded dependencies (into lib/) when B changes. |
| 04:20 | peteriserins | (print) does not print to the screen in uberjar; should I have used Java prints instead? |
| 04:23 | raek | print should work... |
| 04:27 | peteriserins | ok, it was because of the System/exit call, I assume print uses BufferedWriter or something |
| 04:28 | brehaut | ,(doc flush) |
| 04:28 | clojurebot | "([]); Flushes the output stream that is the current value of *out*" |
| 04:49 | wall | hello |
| 04:52 | zarac | hi wall : 0 |
| 04:52 | wall | can anybody help me reduce code to simple |
| 04:52 | wall | code here http://paste.lisp.org/display/123754 |
| 04:52 | wall | i need convert 12 lines to doseq or any cycle |
| 04:53 | wall | index now id numbers from 0 to 11 |
| 04:54 | wall | id = is |
| 04:54 | opqdonut | use for and range |
| 04:56 | opqdonut | you can do something like (for [angle (range 0 Math/PI step)] (struct point-8 <stuff>)) |
| 04:58 | wall | super!!!!! |
| 04:58 | wall | thancs |
| 04:58 | wall | sorry my bad english |
| 04:59 | jonasen | A simple ClojureScript game, http://jonase.github.com/make-adder/ Enjoy! :) |
| 05:17 | Fossi | 99.65000000000224% yes ;D |
| 05:17 | Fossi | i guess your print needs a format :) |
| 05:18 | jonasen | Fossi: I agree, but I don't think its in clojurescript yet |
| 05:18 | Fossi | but nice |
| 05:18 | Fossi | real fun too ;) |
| 05:19 | jonasen | Fossi: thanks. |
| 05:50 | Pupeno_ | I think I'm starting to like http://clojuredocs.org. |
| 05:59 | MasseR | Pupeno_: Have you noticed, it doesn't find results with hyphens? |
| 05:59 | MasseR | Well the autocompletion finds |
| 05:59 | MasseR | But if you press enter you get 'no results' |
| 05:59 | MasseR | Try for example maybe-m |
| 05:59 | Pupeno_ | MasseR: clojuredocs.org? no... generally I arrive through google. |
| 05:59 | MasseR | Pupeno_: Ah. I use duckduckgo with !clojure bang pattern |
| 05:59 | MasseR | Makes it kind of useless |
| 06:00 | Pupeno_ | Yeap: http://clojuredocs.org/search?q=as-file |
| 06:01 | MasseR | Hmm.. I think it's an open source project on github.. issue time |
| 06:02 | MasseR | Ah it's a known issue |
| 06:02 | Pupeno_ | https://github.com/zkim/clojuredocs/issues/34 |
| 06:02 | MasseR | https://github.com/zkim/clojuredocs/issues/22 |
| 06:02 | Pupeno_ | Damn. |
| 06:03 | MasseR | :P |
| 06:03 | Pupeno_ | I been using sphinx way more than I like... maybe I could look into it later. |
| 06:04 | MasseR | Somehow python docs ruined sphinx for me |
| 06:05 | MasseR | I actually like hoogle and hayoo. Signature based searching, which works excellent on a static language such as haskell |
| 06:05 | MasseR | But then again haddock (haskell documentation) has troubles that clojure (whatever engine they use) has fixed |
| 06:14 | pyr | reading ring and compojure souce |
| 06:14 | pyr | source i mean |
| 06:14 | pyr | i'm not seeing how one differentiates request handlers from response handlers |
| 06:15 | pyr | meh, i see |
| 06:52 | wall | hello. help me please with my problem. how i must visit 2 sequence in code with equal offset. this code (let [a '(1 2 3) b '(4 5 6)] (for [x a y b] (println x y))) don't work I need (1 4 2 5 3 6) at result but this code produce multiple of set |
| 06:55 | jonasen | ,(interleave [1 2 3] [4 5 6]) |
| 06:55 | clojurebot | (1 4 2 5 3 ...) |
| 06:59 | manutter | ,(map (fn [a b] [a b]) [1 2 3] [:a :b :c]) |
| 06:59 | clojurebot | ([1 :a] [2 :b] [3 :c]) |
| 07:00 | manutter | ,(mapcat (fn [a b] [a b]) [1 2 3] [:a :b :c]) |
| 07:00 | clojurebot | (1 :a 2 :b 3 ...) |
| 07:10 | wall | how write code simple |
| 07:10 | wall | (defn paint2 [c g] |
| 07:10 | wall | (let [w (.getWidth c) w2 (/ w 2) |
| 07:10 | wall | h (.getHeight c) h2 (/ h 2)] |
| 07:10 | wall | (doseq [x (:circles *game*)] |
| 07:10 | wall | (let [col (interleave (:points x) (:colors x))] |
| 07:10 | wall | (doseq [i (range 0 (/ (count col) 2))] |
| 07:10 | wall | (draw g |
| 07:10 | wall | (ellipse (int (+ h2 (:x (nth col (* 2 i))))) (int (+ w2 (:y (nth col (* 2 i))))) (:r (nth col (* 2 i))) (:r (nth col (* 2 i)))) |
| 07:10 | wall | (style :background (*colors* (nth col (+ 1 (* 2 i))))))))))) |
| 07:11 | wall | ? |
| 07:11 | wall | with interleave its very long... |
| 07:12 | manutter | You would probably be better off using (map (fn [p c] [p c]) (:points x) (:colors x)) instead of interleave |
| 07:13 | manutter | This will give you a sequence of [p c] pairs that you could destructure to get the actual point and color |
| 07:14 | manutter | also by the way it's customary to use something like a github gist or similar service for long code snippets |
| 07:16 | manutter | hmm, looking at your code more closely you might like something like this... |
| 07:18 | manutter | wait, no, hrm that won't work |
| 07:34 | manutter | Yeah, try this: (doseq [{:keys [x y r]} x] (draw g (ellipse (int (+ h2 x)) (int (+ w2 y)) r r)... |
| 07:52 | wall | sorry, but map produce list, but i need only call functions (ellipse and style) |
| 07:52 | wall | how i can apply each element of 2 sequence to draw? |
| 08:03 | pyr | ok, got itre |
| 08:04 | pyr | oops |
| 08:17 | wall | no. iterate - not. i need samething like apply only for 2 sequence |
| 08:24 | wall | evrika!!!! |
| 08:24 | wall | (defn paint2 [c g] |
| 08:24 | wall | (let [w (.getWidth c) w2 (/ w 2) |
| 08:24 | wall | h (.getHeight c) h2 (/ h 2)] |
| 08:24 | wall | (doseq [x (:circles *game*)] |
| 08:24 | wall | (doseq [[y z] (map list (:points x) (:colors x))] |
| 08:24 | wall | (draw g |
| 08:24 | wall | (ellipse (int (+ h2 (:x y))) (int (+ w2 (:y y))) (:r y) (:r y)) |
| 08:24 | wall | (style :background (*colors* z))))))) |
| 08:26 | MasseR | That's not even hard to read |
| 08:46 | wall | sorry, stupid question - how change element in list? |
| 08:47 | Scriptor | wall: you don't, usually. Why do you need to change an element? |
| 08:49 | wall | other words - i must re-produce list with changed element? |
| 08:50 | MasseR | wall: Yes |
| 08:50 | MasseR | Immutable data structures |
| 08:50 | MasseR | But don't worry, it's done 'the right way', meaning that the two lists share a lot of common |
| 08:51 | Scriptor | wall: basically, but it's still a good idea to look at the problem from a more high-level persepctive |
| 08:51 | Scriptor | to see whether there's a better way of doing it |
| 08:51 | wall | а по русски никто не говорит? |
| 08:51 | wall | who speak Russia? |
| 08:51 | Scriptor | Greek? |
| 08:51 | Scriptor | oh |
| 08:52 | Scriptor | sorry, this channel is mostly english-speaking, I think |
| 08:52 | wall | i see |
| 08:52 | wall | but my english bad for describe problem |
| 08:52 | Scriptor | try anyway |
| 08:54 | wall | this is idea for my first game on clojure. Picture here http://gamehappy.ru/f/i/gamehappy/games/220/640-480_screenshot_3.jpg |
| 08:55 | wall | game consist of set of circle which describe set of points and list of colors of small ball |
| 08:55 | wall | now i write function move-left which must change state of circles |
| 08:56 | wall | function simple get next value in list, and change to previous in circle |
| 08:57 | wall | and now i don know how change elements in list |
| 08:59 | Scriptor | wall: so move-left changes the state of all the circles? |
| 08:59 | wall | no |
| 08:59 | wall | only linked circles |
| 09:00 | wall | my code here http://paste.lisp.org/display/123756 |
| 09:00 | wall | maybe simple think |
| 09:00 | dnolen | ,(update-in [{:points {:x 1 :y 2}}] [0 :points :x] inc) |
| 09:00 | clojurebot | [{:points {:y 2, :x 2}}] |
| 09:01 | dnolen | wall: ^ ? |
| 09:04 | wall | update-in work with hash |
| 09:04 | wall | not list |
| 09:04 | dnolen | ,(update-in '(1 2 3) [1] inc) |
| 09:04 | clojurebot | #<NullPointerException java.lang.NullPointerException> |
| 09:04 | Scriptor | wall: it's a list of colors, right? |
| 09:05 | dnolen | ,(update-in [1 2 3] [1] inc) |
| 09:05 | clojurebot | [1 3 3] |
| 09:05 | wall | yes |
| 09:05 | wall | Scriptor, yes |
| 09:05 | dnolen | ,(update-in (into [] '(1 2 3)) [1] inc) |
| 09:05 | clojurebot | [1 3 3] |
| 09:05 | Scriptor | yep, I think what you actually have is a vector |
| 09:05 | Scriptor | so update-in will work with that |
| 09:06 | wall | dnolen, (let [a '(1 2 3 4)] (update-in a [2] inc)) - not work |
| 09:07 | wall | Scriptor, i must rewrite using list to using vector? |
| 09:08 | Scriptor | wall: in the code you posted, isn't *colors* already a vector? |
| 09:09 | wall | not *colors*. see field :color in structure one-circle |
| 09:09 | wall | this field have info about state of circle |
| 09:09 | wall | *colors* need only then show circle on screen |
| 09:10 | dnolen | wall: you can't efficiently or easily update inside the middle of a list. |
| 09:11 | wall | ok. i'm rewriting use vector |
| 09:11 | Scriptor | good idea, lists are better for iterating through one by one |
| 10:10 | ambrosebs | I'm trying to perform this type of conversion: [1 2 3 4] -> [[[1 2] 3] 4] any hints of how to approach this? |
| 10:11 | ambrosebs | im trying to convert a function call into a lambda calculus function call, with only one argument |
| 10:11 | ambrosebs | (add 1 2) => ((add 1) 2) |
| 10:13 | Somelauw | Anybody already developing for android? |
| 10:15 | sthuebner | ambrosebs: do you mean something like this: |
| 10:15 | sthuebner | ,(let [add (fn [x y] (+ x y)) add-1 (partial add 1)] (add-1 2)) |
| 10:15 | clojurebot | 3 |
| 10:15 | sthuebner | or: |
| 10:15 | sthuebner | ,(let [add (fn [x] (fn [y] (add x y)))] ((add 1) 2)) |
| 10:15 | clojurebot | #<CompilerException java.lang.RuntimeException: Unable to resolve symbol: add in this context, compiling:(NO_SOURCE_PATH:0)> |
| 10:16 | sthuebner | ,(let [add (fn [x] (fn [y] (+ x y)))] ((add 1) 2)) |
| 10:16 | clojurebot | 3 |
| 10:16 | ambrosebs | I have the raw form (add 1 2), I want to transform it into the raw form ((add 1) 2) |
| 10:16 | ambrosebs | dont want to execute it |
| 10:17 | TimMc | some kind of reduce, maybe |
| 10:18 | dpritchett | Is it normal to restart one's interpreter every time you finish editing a function in your source file? |
| 10:18 | TimMc | ambrosebs: Can you guarantee at least 2 elements? |
| 10:19 | dpritchett | I went to #python and #django asking for advice on how to re-import classes loaded with "from myapp.models Person" without having to restart the interpreter and the unanimous response was "you have to restart your interpreter". |
| 10:19 | ambrosebs | TimMc: yes |
| 10:20 | ambrosebs | if it's a function call, it will have an argument |
| 10:20 | ambrosebs | at least |
| 10:20 | tufflax | ,(let [form '(add 1 2 3 4 5)] (reduce (fn [f x] (list f x)) (first form) (next form))) |
| 10:20 | clojurebot | (((((add 1) 2) 3) 4) 5) |
| 10:20 | ambrosebs | phew! |
| 10:21 | ambrosebs | tufflax: thanks :) |
| 10:21 | tufflax | np |
| 10:21 | TimMc | dpritchett: When you work from Emacs, it is not uncommon to have a REPL open in another pane and just keep sending your edited functions down to the REPL for reevaluation. |
| 10:22 | dpritchett | Exactly! I assumed that was doable in other interpreted languages too. Perhaps I just need to try #python at a different hour. |
| 10:22 | TimMc | I do things a little differently -- I use the REPL to refine a function, then paste it into my source files and run my unit tests. |
| 10:23 | dpritchett | That's pretty much what I do too tim |
| 10:24 | TimMc | I'm sure someone has cooked up (or will) a hot-swap thingy for Clojure, a la Eclipse. |
| 10:24 | TimMc | That's a joy to work with when doing Java servlet dev. |
| 10:24 | dpritchett | There's ring middleware for it, I discovered this on Noir |
| 10:25 | dpritchett | https://github.com/ibdknox/noir/blob/master/src/noir/server.clj#L8 |
| 10:26 | dpritchett | It's pretty sweet that my django *server* restarts itself automagically whenever i save a file on its path... not sure why the interpreter can't hot reload things without a full restart |
| 10:26 | dpritchett | Ah well... obviously this isn't really a Clojure question, I just wanted to get confirmation that the emacsy way of doing things actually worked the way i remembered it. |
| 10:33 | pepijn | ClojureScript bootstrap says script/bootstrap: 28: jar: not found |
| 10:33 | pepijn | Any ideas? |
| 10:34 | pepijn | Oh, and has anyone tried CouchDB with ClojureScript yet? |
| 10:46 | bsteuber | talking of clojurescript |
| 10:46 | bsteuber | without optimizing, shouldn't I be able to call cljs stuff from a javascript-console? |
| 10:47 | bsteuber | I can call stuff, but e.g. keywords don't work |
| 10:48 | bsteuber | cljs.core.name(cljs.core.keyword('foo')) => "î.'foo" |
| 10:48 | pepijn | end of wifi, good bye |
| 10:48 | bsteuber | however, the same works fine using brepl |
| 11:05 | icey | Is apache web server + tomcat the way most people deploy clojure web applications? |
| 11:09 | icey | (i'm familiar with lein-beanstalk and clojure on heroku; but I have a bunch of little single serve apps that i want to put online so i'd just as soon put them on a vps at linode or something) |
| 12:13 | zvrba | this complains on .isProbablePrime about no matching field found: (let [x (BigInteger. "13")] (.isProbablePrime x)) |
| 12:13 | zvrba | what am I doing wrong? |
| 12:14 | hiredman | zvrba: read the javadoc for the method you are trying to call |
| 12:15 | ejackson | hiredman: reading those things is usually where I go wrong :P |
| 12:15 | zvrba | ah! |
| 12:15 | zvrba | forgot the other mandatory argument |
| 12:16 | zvrba | when I write a dot and press TAB for completion, in which packages does slime look? |
| 12:19 | technomancy | zvrba: it's impossible to get instance methods for objects where the type is unknown |
| 12:19 | zvrba | i know |
| 12:19 | technomancy | slime's currently not hooked up to hinting, though it wouldn't be impossible |
| 12:19 | zvrba | what hinting? |
| 12:19 | technomancy | try C-h TAB in slime to find out what it's bound to |
| 12:19 | jweiss | can anyone suggest where i might find an algorithm that does the following - traverses a tree with n threads, such that no child node is processed before its parent? seems simple enough, but i can't seem to find one that honors the restriction and uses the threads efficiently. |
| 12:19 | technomancy | zvrba: slime could theoretically be tied into type hints |
| 12:20 | technomancy | nobody's bothered yet since the compiler's going to get chucked out and rewritten |
| 12:20 | zvrba | i get message about C-h TAB being undefined. |
| 12:20 | technomancy | sorry, C-h k TAB |
| 12:20 | technomancy | maybe in the future once the compiler does type inference and exposes it to tools, swank will tie into that |
| 12:20 | zvrba | slime-indent-and-complete-symbol |
| 12:20 | zvrba | does eclipse plugin do type inference? |
| 12:21 | zvrba | technomancy: though, I asked something much simpler: in which packages does completion look into? |
| 12:21 | zvrba | technomancy: I know that I simply get a list of all accessible methods, but from which Java packages? |
| 12:22 | technomancy | zvrba: hah; I didn't even know it did that. I don't know if that's intentional or not. |
| 12:22 | technomancy | no idea where it's coming from. |
| 12:23 | zvrba | and even better, it would be enough if each completed method name would be prefixed by its class |
| 12:23 | zvrba | that would go a long way before type inference is here |
| 12:23 | joly | jweiss: if a breadth-first search is ok, you could put make a nodes-to-visit queue and have the individual threads pull from it. As long as the node is processed before you put the children into the queue, it should work |
| 12:25 | jweiss | joly: yeah, that's the problem, i can't just queue up all the nodes at once. so how do i have the main thread wait to queue up the children? once the tree branches i'd need multiple threads doing queueing also |
| 12:26 | jweiss | the only (ugly) solution that would actually work that i came up with is to queue up all at once, and have the worker thread just re-queue an item if its parent hasn't been processed |
| 12:27 | joly | jweiss: the main thread would put the first item on the queue, any worker would retrieve it, process it, then put its (multiple) children on the queue. |
| 12:27 | hiredman | why not have the thread that processed a parent queue up it's children? |
| 12:28 | hiredman | e.g. put the root on a work queue n threads are pulling from, one thread pulls it off processes the root, and places the immdediate childred on the queue for work, rinse and repeat |
| 12:28 | jweiss | hiredman: that is a better idea |
| 12:28 | jweiss | it does require breadth first traversal, which since i'm using clojure.zip, i'd have to write, but that's ok |
| 12:30 | manutter | well, if each worker processes 1 node, and then puts the immediate children on the queue, that's breadth-first automatically |
| 12:30 | joly | exactly |
| 12:33 | joly | well, like breadth-first anyway. some threads could get easy tasks and pull ahead of those doing slower tasks |
| 12:33 | joly | and switching to a stack the threads pull from should give you something like depth-first |
| 12:34 | manutter | Yeah, the parallelism makes terms like "first" a bit ambiguous. |
| 13:35 | lobotomy | so i've figured out i probably want a (defstruct wire :name :i :inverted :successors), and with it a (defn set-wire! [wire i inverted successors] (dosync (alter wire assoc :i i :inverted inverted :successors successors))) |
| 13:35 | lobotomy | where the idea is that :inverted is another wire, and :successors is a vector of other wires |
| 13:36 | lobotomy | hmm, and of course (defn make-wire [name] (ref (struct wire name))) |
| 13:36 | lobotomy | so, should the :inverted be a ref to the other wire, or deref'd plain wire? |
| 13:36 | lobotomy | likewise for :successors |
| 13:37 | dnolen | lobotomy: defstruct is deprecated. |
| 13:38 | lobotomy | well damn :D |
| 13:38 | lobotomy | defrecord then? |
| 13:39 | lobotomy | hmm, (doc defrecord) tells me "Alpha - subject to change" |
| 13:45 | lobotomy | or just use a map instead of defrecord? hmm, that should be fine at this point |
| 13:55 | lobotomy | hmm... if i store the dereffed ref, it seems to copy the data? so that won't work |
| 13:56 | lobotomy | and when i do (dosync (alter w0 assoc :inverted w1)) then (dosync (alter w1 assoc :inverted w0)), i get a stack overflow |
| 13:56 | lobotomy | so: what's the correct way to do circularly linked datums in clojure? |
| 13:59 | dnolen | lobotomy: plain maps are fine. circularly linked data is not really possible. better to do this via some relational abstraction of one's own. |
| 13:59 | lobotomy | not really possible? what? |
| 13:59 | hiredman | dnolen: it is possible via mutable refs |
| 13:59 | lobotomy | are you serious? |
| 14:00 | dnolen | hiredman: yes, but not recommended by any means. |
| 14:00 | dnolen | lobotomy: or Java arrays etc. |
| 14:00 | technomancy | also possible with laziness IIRC |
| 14:00 | hiredman | lobotomy: please stop trying to print cyclic graphs |
| 14:00 | technomancy | but more trouble than it's worth |
| 14:00 | lobotomy | what is the recommended way of doing cyclic things then? |
| 14:00 | lobotomy | hiredman, good point ;) |
| 14:01 | dnolen | lobotomy: why do you need a cyclic data structure in this case? |
| 14:01 | joly | things like graphs can be done with maps: {:a [:a :c] :b [:c] :c [:a :b]} |
| 14:01 | technomancy | "doing cyclic things" isn't something you want to do |
| 14:01 | joly | the graph has a cycle even though the data structure doesn't |
| 14:02 | lobotomy | cyclicness is how i modeled it in java, seemed the most straightforward way |
| 14:02 | dnolen | lobotomy: cyclic data structure are code smell in Clojure from what I can tell. |
| 14:03 | lobotomy | this is a wireframe for a puzzle solver basically. e.g. a cube, with each "wire" an edge. edges are linked to each other (and to an inverted version of themselves) |
| 14:03 | dnolen | lobotomy: in order to have a cyclic data structure you need to have some notion of identity, in Clojure those can only be represented via low level facilities or reference types. |
| 14:03 | dnolen | but Clojure emphasizes values, not identities |
| 14:05 | lobotomy | the edges are linked to each other because that seemed the easiest way to deal with the corners, which are shared by more than one edge |
| 14:05 | dnolen | lobotomy: write graph using a map. |
| 14:05 | dnolen | write the |
| 14:05 | lobotomy | modify a wireframe edge => also checks the beginning or end of each linked edge and modifies that too if necessary |
| 14:06 | lobotomy | hmm, a 3-d graph with a map... need to think about that |
| 14:08 | lobotomy | hmm, joly's map example seems workable here |
| 14:09 | lobotomy | so i'd make one big map with the whole graph in it as symbols |
| 14:10 | lobotomy | the hardest part in this solver is building the wireframe, but that's probably just as hard (or easy) with the map as with the link-these-together method |
| 14:10 | dnolen | lobotomy: an it'll be sanely printable. |
| 14:11 | lobotomy | so's my circularly linked thing, as long as you only print the name of each successor/inverted |
| 14:12 | dnolen | lobotomy: but you had to write that conditional logic right? |
| 14:14 | lobotomy | what conditional logic? foreach edge in pile_of_edges: print edge " " edge.inverted " " (map name edge.successors) |
| 14:24 | devn | dnolen: So, forgive me if this is way off base, but is part of the goal of core.logic to have an ad-hoc type system in clojure? Sort of a drop-in typeclass system? |
| 14:24 | dnolen | lobotomy: oh yeah I see yr point there. |
| 14:24 | ambrosebs | dnolen has evil plans |
| 14:25 | dnolen | ha! |
| 14:25 | devn | dnolen: I was talking to a Scala guy at my Clojure meetup last night and he was talking about Scala's type system and I mentioned core.logic => ad-hoc type systems. I didn't have sufficient ammunition to sell him on the idea, so I'm curious if there's a blog post or a writeup somewhere that I could give to him. |
| 14:26 | devn | Then again, I might totally misunderstand the aims of core.logic, I just remember that being brought up at some point. |
| 14:27 | dnolen | devn: no I have no set plans as of yet. |
| 14:27 | devn | dnolen: but that doesn't mean you haven't considered it. :) |
| 14:27 | dnolen | open questions - 1) is it fast enough yet? 2) will Clojure provide the necessary hooks? 3) do we need constraint solver? |
| 14:28 | st3fan | hooks? |
| 14:28 | st3fan | yarrrrrr! |
| 14:29 | dnolen | devn: there is plenty of prior art - Typed Racket, H-M in Prolog, Qi/Shen, so to me it's not a matter of possibility, just time and interest |
| 14:30 | dnolen | however it also my experience that most FP people don't understand logic programming and can't see the relationship between their type checker and logic programming. |
| 14:31 | dnolen | not language implementors / researcher of course, but the users. |
| 14:31 | devn | dnolen: *nod*, so, I'm sure you've thought about this. Can you imagine a way to abstract the knowledge of logic programming in a way that would provide the benefits without the learning curve? |
| 14:31 | dnolen | devn: no |
| 14:32 | dnolen | logic programming is as deep and profound as object oriented and functional programming - there is no easy path. |
| 14:32 | ambrosebs | why would users need to know LP to use a type checker? |
| 14:32 | dnolen | ambrosebs: exactly. |
| 14:33 | dnolen | they don't, but since they're don't understand they're skeptical about ad-hoc type checker claims. |
| 14:33 | ambrosebs | ah |
| 14:33 | ambrosebs | so in a "generating interest" sense |
| 14:34 | ambrosebs | night everyone |
| 14:34 | jweiss | am i wrong to think clojure.zip is not suited for concurrent programming (since the notion of "current location" doesn't really make sense)? |
| 14:36 | hiredman | jweiss: how so? |
| 14:37 | jweiss | hiredman: well, if i have multiple threads going through the zipper and editing nodes, how do i merge them together? |
| 14:37 | hiredman | uh |
| 14:37 | hiredman | of that won't work, how did you think it would? |
| 14:37 | hiredman | of course |
| 14:38 | jweiss | i didn't. i used zippers when my app was single threaded, now i'm trying to make it multithreaded, so just confirming that i probably shouldn't keep using zippers |
| 14:39 | jweiss | i could use refs but the nature of my app is such that i don't want to repeat transactions |
| 14:39 | jweiss | and i shouldn't have to since there will never be conflicting changes |
| 14:44 | dnolen | devn: part of my interest in putting core.logic together was/is to get people excited about exploring Functional/OO/Relational concepts from the same language. Besides Mozart/OZ I'm not aware of another language that lets you do this so seemlessly. |
| 14:48 | dnolen | well non-Lisps, you have Allegro Common Lisp and Racket of course. |
| 15:06 | devn | dnolen: thanks for your comments. that gives me something to think about. |
| 15:24 | dnolen | devn: I'm definitely planning on revisiting the idea at after the pattern/predicate stuff is sorted. as with the pattern/predicate stuff there's a higher chance of success if people are willing to help contribute ideas/code to help push the project along. hopefully next year around this time there'll be something to show for. |
| 15:36 | netrealm | Question, how would I get "cake repl" to switch to my project's namespace automatically? |
| 15:38 | amalloy | netrealm: you can put a :startup form in your project.clj |
| 15:39 | amalloy | it gets evaled when you start the repl |
| 15:39 | user317 | is there a "type" function in clojure, like haskells/ghci's :t command |
| 15:39 | amalloy | &(type ()) |
| 15:39 | lazybot | ⇒ clojure.lang.PersistentList$EmptyList |
| 15:39 | amalloy | but of course clojure is dynamically typed, so that's the "runtime" type, not some sort of compile-time type like haskell has |
| 15:40 | user317 | &(type reduce) |
| 15:40 | lazybot | ⇒ clojure.core$r |
| 15:40 | user317 | thats not to usefull :( |
| 15:40 | amalloy | user317: well, functions don't have type signatures. not much you can do about that |
| 15:41 | amalloy | &(doc reduce) |
| 15:41 | user317 | is there any way to do that kind of intraspection from the interpreter? |
| 15:41 | lazybot | ⇒ "([f coll] [f val coll]); f should be a function of 2 arguments. If val is not supplied, returns the result of applying f to the first 2 items in coll, then applying f to that result and the 3rd item, etc. If coll contains no items, f must accept no arguments as wel... http://gist.github.com/1123583 |
| 15:41 | user317 | ah thank you |
| 15:41 | amalloy | for which, out of curiosity? telling you about doc, or that functions don't have type signatures? |
| 15:43 | user317 | telling me about the doc ;) |
| 15:43 | user317 | just need a way to explore the language, ghc's :t command was pretty useful when i first started coding in haskell |
| 15:44 | amalloy | *nod* just :t can tell you a lot about a function for sure |
| 15:45 | MasseR | Good to see other haskellists here |
| 15:45 | MasseR | *haskellers |
| 15:48 | user317 | what does the '^' symbol mean? |
| 15:48 | lobotomy | hey guys, what's a better way to do this: http://pastebin.com/Xug6HApt |
| 15:48 | dnolen | user317: for type-hinting |
| 15:49 | Chousuke | or arbitrary metadata actually |
| 15:49 | Chousuke | lobotomy: I'm not sure what that does :p |
| 15:50 | lobotomy | just creates a map of stuff |
| 15:50 | lobotomy | tried doing that with map, mapcat, concat and whatnot, but couldn't quite |
| 15:50 | mattmitchell | i'm trying to get :or working with de structuring a hash-map, I'm doing something wrong... is :or even possible in this scenario? https://gist.github.com/1123602 |
| 15:50 | Chousuke | well as long as you have a seq of [k v] pairs you can put that into a map |
| 15:50 | lobotomy | already the flatten in the keyword generation bit looks ugly to me |
| 15:51 | amalloy | i haven't looked at the code, but i heard someone say flatten and i'm 80% sure the code doesn't work |
| 15:52 | dnolen | Chousuke: true, I didn't actually realize the following worked. |
| 15:52 | Chousuke | so, given keywords, (into {} (map (fn [x] [x {:name (str x) :i (ref 0)}]) keywords)) |
| 15:52 | dnolen | ,(meta ^long []) |
| 15:52 | clojurebot | {:tag #<core$long clojure.core$long@fe0ce9>} |
| 15:53 | Chousuke | hm |
| 15:53 | Chousuke | that looks weird |
| 15:53 | Chousuke | why does the function long get put as the metadata |
| 15:54 | amalloy | mattmitchell: try https://gist.github.com/1123606 |
| 15:54 | mattmitchell | amalloy: oh man, duh :) thank you! |
| 15:57 | lobotomy | ,(into [] (map #(list (keyword (str "w" %)) (keyword (str "w" % "-"))) (range 2))) |
| 15:57 | clojurebot | [(:w0 :w0-) (:w1 :w1-)] |
| 15:57 | lobotomy | see, this is what i mean: looking for [:w0 :w0- :w1 :w1-] |
| 15:58 | lobotomy | tried getting there with map etc, didn't work, so i just wrote that simple loop |
| 15:58 | lobotomy | but there has to be a better way :) |
| 15:59 | lobotomy | i mean, you could add flatten to that i guess, but is that recommended? |
| 15:59 | dnolen_ | ,(apply concat (map #(list (keyword (str "w" %)) (keyword (str "w" % "-"))) (range 2))) |
| 15:59 | clojurebot | (:w0 :w0- :w1 :w1-) |
| 16:00 | dnolen_ | lobotomy: ^ |
| 16:02 | lobotomy | hmm, ok. isn't that essentially the same as with flatten? |
| 16:02 | lobotomy | or does flatten do an extra pass over the list? |
| 16:02 | amalloy | flatten is evil and sinful, and will trick you if you ever depend on it |
| 16:02 | user317 | whats the difference between (list 1 2) and #(list 1 2) |
| 16:04 | amalloy | compare ##(apply concat [[[1 2]] [3 4]]) and ##(flatten [[[1 2]] [3 4]]) |
| 16:04 | lazybot | (apply concat [[[1 2]] [3 4]]) ⇒ ([1 2] 3 4) |
| 16:04 | lazybot | (flatten [[[1 2]] [3 4]]) ⇒ (1 2 3 4) |
| 16:05 | dnolen_ | user317: # is shorthand for fn. |
| 16:05 | dnolen_ | ,(map #(* % 2) (range 10)) |
| 16:05 | clojurebot | (0 2 4 6 8 ...) |
| 16:05 | lobotomy | yeah i see, flatten happens to work here, but in general it might be overzealous |
| 16:05 | lobotomy | what about the rest of the thing then? ;) |
| 16:06 | user317 | dnolen_: so "*" is the implicit argument? |
| 16:06 | amalloy | % is |
| 16:06 | hiredman | erm |
| 16:06 | user317 | right ;) |
| 16:06 | hiredman | it is pretty explicit |
| 16:06 | amalloy | hiredman: is the implicit name of the argument, if you like |
| 16:07 | user317 | amalloy: so only 1 argument or does this support variable arguments as well |
| 16:07 | lobotomy | ooh, (into {} (for [k keywords] [k {:name (str k) :i (ref 0)}])) |
| 16:07 | lobotomy | it seems into is what i wanted here |
| 16:08 | user317 | &(#(* %1 %2) 3 2) |
| 16:08 | lazybot | ⇒ 6 |
| 16:10 | joly | ,(#(vector %&) 1 2 3 4 5 6) |
| 16:10 | clojurebot | [(1 2 3 4 5 ...)] |
| 16:12 | dnolen_ | ,(#(vector (* %1 %2) %&) 1 2 3 4 5) |
| 16:13 | clojurebot | [2 (3 4 5)] |
| 16:13 | user317 | dnolen_: cool, thanks |
| 17:05 | hiredman | clojurebot: ping? |
| 17:05 | clojurebot | PONG! |
| 17:06 | ibdknox | it's very excited about that ping. |
| 17:06 | hiredman | ~guards |
| 17:06 | clojurebot | SEIZE HIM! |
| 17:07 | ibdknox | lol |
| 17:07 | hiredman | ~\o |
| 17:07 | clojurebot | Excuse me? |
| 17:07 | hiredman | ~ o/ |
| 17:07 | clojurebot | \o ... High five! |
| 17:30 | gtrak | is there a simple way to move a bunch of values from one map to different keys in a second? |
| 17:31 | hiredman | ,(doc rename) |
| 17:31 | clojurebot | No entiendo |
| 17:31 | hiredman | ,(doc rename-keys) |
| 17:31 | clojurebot | Gabh mo leithscéal? |
| 17:31 | gtrak | ah, I'll have a look |
| 17:31 | hiredman | pffft |
| 17:31 | hiredman | ,(doc clojure.set/rename-keys) |
| 17:31 | clojurebot | Cool story bro. |
| 17:32 | hiredman | ,(use 'clojure.set) |
| 17:32 | clojurebot | nil |
| 17:32 | hiredman | ,(doc clojure.set/rename-keys) |
| 17:32 | clojurebot | "([map kmap]); Returns the map with the keys in kmap renamed to the vals in kmap" |
| 17:32 | gtrak | clojurebot is stateful? |
| 17:35 | hiredman | code loading (require,use,load,etc) is inherently stateful |
| 17:36 | lucca | In Xanadu did Kubla Khan / A stateful clojurebot decree... |
| 17:37 | hiredman | I've looked a little at throwing away the classloader used to load the clojure runtime that runs in the sandbox, and using a new instance of the clojure runtime every time but I have gotten it to work yet |
| 17:37 | hiredman | (or a new clojure runtime every 10 minutes or something) |
| 17:38 | lucca | does all the repetitive internal classloading leak memory? |
| 17:40 | hiredman | classloaders can be gc'ed once all the classes they have loaded have been gc'ed |
| 17:41 | lucca | hmmmmm. So in practice if you execute new incoming code in a loop (like clojurebot), it does... but there are ways around that by re-allocating the classloader. |
| 17:53 | technomancy | that's a good way to sum it up |
| 18:12 | vertegal | /clear |
| 18:15 | XPherior | Is it legal to use destructuring in doseq? |
| 18:16 | XPherior | I have a sequence, ([1 2] [3 4] [5 6] [7 8]) and I want to iterate over it, two elements at a time. |
| 18:17 | brehaut | ,(doseq [[a b] [[1 2] [2 3]]] (prn (+ a b))) |
| 18:17 | clojurebot | 3 |
| 18:17 | clojurebot | 5 |
| 18:18 | brehaut | XPherior: ^ |
| 18:18 | XPherior | Weird. Wonder why that isn't working for me.. |
| 18:19 | XPherior | Oh, wait. I lied. |
| 18:19 | XPherior | The data I want to iterate over is this: [1 2 3 4 5 6] |
| 18:19 | XPherior | ,(doseq [[a b] [1 2 3 4 5 6]] (prn (+ a b))) |
| 18:19 | clojurebot | #<UnsupportedOperationException java.lang.UnsupportedOperationException: nth not supported on this type: Long> |
| 18:19 | brehaut | XPherior: ##(partition 2 [1 2 3 4 5 6]) |
| 18:19 | lazybot | ⇒ ((1 2) (3 4) (5 6)) |
| 18:20 | XPherior | Oh man. Cool Clojure functions strike again. :) |
| 18:20 | XPherior | That does it for me. Thanks man. |
| 18:21 | brehaut | no worries |
| 18:22 | XPherior | Hm.. Can you iterate over two sequences at once? Such as [1 2 3 4] and [5 6 7 8]? |
| 18:22 | sritchie | ,(map vector [1 2 3 4] [5 6 7 8]) |
| 18:22 | clojurebot | ([1 5] [2 6] [3 7] [4 8]) |
| 18:24 | XPherior | Cool :) |
| 18:24 | XPherior | Functional programming blows my mind, heh |
| 18:25 | XPherior | Hm, okay. One more. Can you turn something like [1 2 3 4 5 6] into [(1 2) (2 3) (3 4) (4 5) (5 6)] ? |
| 18:26 | XPherior | Oh wait. I think I can actually do that one, haha |
| 18:26 | sritchie | ,(partition 1 2 [1 2 3 4 5 6]) |
| 18:26 | brehaut | ,(partition 2 1 [1 2 3 4 5 6]) |
| 18:26 | clojurebot | ((1) (3) (5)) |
| 18:26 | clojurebot | ((1 2) (2 3) (3 4) (4 5) (5 6)) |
| 18:26 | sritchie | whoops, wrong order! |
| 18:26 | XPherior | I was close. Thanks both. :) |
| 18:26 | brehaut | XPherior: keep in mind that partition-all might be useful in some case too |
| 18:27 | brehaut | ,(parition-all 2 [1 2 3]) |
| 18:27 | clojurebot | #<CompilerException java.lang.RuntimeException: Unable to resolve symbol: parition-all in this context, compiling:(NO_SOURCE_PATH:0)> |
| 18:27 | brehaut | ,(partition-all 2 [1 2 3]) |
| 18:27 | clojurebot | ((1 2) (3)) |
| 18:27 | brehaut | ,(partition 2 [1 2 3]) |
| 18:27 | clojurebot | ((1 2)) |
| 18:27 | XPherior | Ah, that's pretty cool! |
| 18:28 | XPherior | You guys are smart. |
| 18:30 | amalloy | i love (partition 2 1 ...) |
| 18:36 | XPherior | Thanks guys! See ya~ |
| 20:10 | st3fan | if i add a depencency to my project.clj and then run lein deps, lein swank, should those classes be available from the repl ? |
| 20:10 | st3fan | like i can access them with (new com.foo.bar.SomeClass) without having to import them? |
| 20:14 | st3fan | oh nevermind .. i see the real error now, in the window running lein swank |
| 20:24 | st3fan | is there an easy way to time the execution speed of some block of code? |
| 20:25 | Raynes | &(doc time) |
| 20:25 | lazybot | ⇒ "Macro ([expr]); Evaluates expr and prints the time it took. Returns the value of expr." |
| 20:28 | st3fan | yay |
| 20:43 | st3fan | is there something like (repeat 10 (foo)) .. to call a block of code N times? |
| 20:44 | technomancy | (doc repeatedly) |
| 20:44 | clojurebot | "([f] [n f]); Takes a function of no args, presumably with side effects, and returns an infinite (or length n if supplied) lazy sequence of calls to it" |
| 20:44 | st3fan | oh repeat already does something different |
| 20:44 | st3fan | ahh repeatedly :) |
| 20:44 | fullets | dotimes might also do what you want |
| 20:46 | technomancy | yeah, depends on if you want a return value or not |
| 20:46 | technomancy | functions named after adverbs are the best, amirite? |
| 20:47 | fullets | undoubtedly |
| 20:48 | technomancy | (is (definitely (process-finished?))) |
| 21:12 | darevay | Hi everybody. |
| 21:14 | groovy2shoes | oi, darevay |
| 21:15 | darevay | A while ago, I asked about proxy-super and reflection on the ML (http://goo.gl/1l1an). Sadly, no one responded so I'm asking here. |
| 21:17 | amalloy | it's a limitation of java, i think. you can't call super.foo(this) in a proxy |
| 21:17 | amalloy | uh. nm |
| 21:17 | amalloy | haha |
| 21:18 | ataggart | just got on, but is this about reflection inproxy? |
| 21:18 | darevay | ataggart: http://goo.gl/1l1an |
| 21:19 | ataggart | yep, easy to fix though |
| 21:19 | ataggart | one sec |
| 21:19 | ataggart | https://github.com/clojure/tools.logging/blob/master/src/main/clojure/clojure/tools/logging.clj#L141 |
| 21:19 | darevay | ataggart: that's what i like to hear :) |
| 21:20 | ataggart | the problem is that the "this" var doesn't have a known type |
| 21:20 | ataggart | it can't since proxy could be a lot of things |
| 21:20 | darevay | I could have sworn I tried that to no avail. I will try again now. |
| 21:27 | pschorf | has anyone worked with a websocket client using aleph (or another clojure library)? |
| 21:34 | hiredman | ataggart: but the runtime class of a proxy is generated at compile time, no? so this should be hintable |
| 21:35 | ataggart | which class? |
| 21:35 | ataggart | you can proxy n number of interfaces |
| 21:36 | hiredman | right, but (proxy ...) creates a class that implements and inherits from the specified class/interfaces and the creates an instance of that class |
| 21:36 | ataggart | ah I see what you mean |
| 21:37 | ataggart | not sure |
| 21:37 | hiredman | it may be trick because of update-proxy |
| 21:37 | hiredman | tricky |
| 21:37 | hiredman | you would be able to swap in your own fn without the proper hints |
| 21:45 | darevay | ataggart: thanks. I don't have it working yet, but I think I see what I was doing wrong. The proxy's actually in a macro, so inserting the hints is complicated. |
| 21:45 | st3fan | i'm looking at the source for clojure.sql |
| 21:45 | st3fan | does anyone know why there is both with-connection and with-connection* ? |
| 21:45 | st3fan | where the first calls the second |
| 21:45 | ataggart | it shouldn't be any more complicated than surrounding the proxy-super calls in a (let [^Foo this this] ...) |
| 21:49 | darevay | I've observer, maybe incorrectly, that the ^Hints get eaten by the reader (or something) so I have to use with-meta: http://w01fe.com/blog/2009/07/dynamic-type-hints-in-clojure-macros/ |
| 21:59 | currymj | what's the best way to learn how to use penumbra? I don't know opengl at all, should I try to learn it in C first? |
| 22:05 | darevay | ataggart: Actually, it's not the macro. It seems like the "let this" trick doesn't work when the method is protected. https://gist.github.com/1124352 |
| 22:06 | ataggart | ah, yes, you can't call protected methods |
| 22:06 | ataggart | does it work with the reflection when called? |
| 22:07 | darevay | Yeah. It works fine. I just want the reflection gone :) |
| 22:07 | ataggart | odd, I thought the reflector only pulled public methods |
| 22:07 | darevay | ... without gen-class |
| 22:07 | ataggart | I'm surprised it works at all |
| 22:09 | darevay | I guess it could be worse then. |
| 22:10 | darevay | Thanks for your help though. |
| 23:11 | darevay | Hi everybody. For Seesaw, there are some system-wide settings that a user of a Seesaw-based app might like to override, most notably the look & feel. I was thinking of having a ~/.seesawrc.clj file or something where they could put that stuff. Is that a dumb idea? Should I just stick with Java system properties or a properties file? |
| 23:36 | st3fan | what does it mean if my macro fails with "Can't let qualified name" |
| 23:36 | st3fan | does that mean i need to generate the name? |
| 23:37 | cemerick | st3fan: you're trying to establish a local binding in the code emitted by a macro? Use a gensym. |
| 23:38 | st3fan | `foo# ? |
| 23:38 | cemerick | You are emitting a let form, right? In that case, `(let [foo# (some-fn)] (do-something-with-foo foo#)) |
| 23:41 | st3fan | i'm doing this now: http://pastie.org/2317797 |
| 23:42 | amalloy | st3fan: that's fine, but a little unidiomatic, in two ways |
| 23:42 | amalloy | as cemerick says, you could more easily write `(if-let [value# (get ~key)] value# ...) |
| 23:43 | st3fan | is that 'auto gensym' ? |
| 23:43 | amalloy | indeed |
| 23:43 | cemerick | yes |
| 23:43 | amalloy | &`(let [foo# 1] foo#) |
| 23:43 | lazybot | ⇒ (clojure.core/let [foo__14246__auto__ 1] foo__14246__auto__) |
| 23:43 | st3fan | yeah cool |
| 23:43 | amalloy | in this particular function, though, you can be even more clear with `(or (get ~key) (set ...)) |
| 23:44 | cemerick | There's nothing there that will let a qualified name, though. Presumably there's a `get` macro you're also defining (since the core get fn won't take a single arg)? |
| 23:46 | st3fan | hm yeah i have get/set/delete .. this is a little memcache wrapper |
| 23:47 | st3fan | i'm doing this: |
| 23:47 | cemerick | right; so, you're not using a gensym where you should be |
| 23:47 | st3fan | http://pastie.org/2317814 |
| 23:47 | amalloy | st3fan: are those macros? there's no reason they couldn't be functions |
| 23:47 | st3fan | they are functions indeed |
| 23:47 | amalloy | then they're not letting qualified names either |
| 23:49 | amalloy | fwiw, there's not much point in & body and ~@body if you're not wrapping them in a (do) at some point |
| 23:49 | amalloy | or, at any rate, there could be plenty of use; but more likely what happens would surprise you |
| 23:50 | st3fan | yeah something is not right there |
| 23:51 | st3fan | should the macro wrap the body in (do) or should the caller do that? |
| 23:53 | st3fan | yeah sorry |
| 23:53 | st3fan | let me fix it and i'll post it |
| 23:57 | st3fan | cool this works pretty well |
| 23:57 | st3fan | the code is at http://pastie.org/2317844 |
| 23:58 | amalloy | st3fan: i don't really see why memoize should be a macro either |
| 23:59 | st3fan | hm how would yo prevent the body from being evaluated then? |
| 23:59 | amalloy | (memoize "foobar" 60 #(do (Thread/sleep 2500) (* 2 21))) ;; more composable, i suspect |
| 23:59 | st3fan | oh |
| 23:59 | st3fan | :-) |