#clojure logs

2011-02-17

00:24simardbortreb: hum I only get to 87 ms
00:24simardwere you serious about 3 ms ? ;)
00:47tomojwhy aren't sorted sets and maps IEditableCollections, I wonder?
00:48bortrebI was doing the coderloop problem, which goes much higher than the euler ones
03:14TobiasRaedermorning
04:48iwilligis there a protocol that I can extend a Java class to take advantage of ISeq ?
05:03Dranikis there a way to save the current clojure application state and load it like in lisp?
05:23_2x2lDranik: how would you do it in CL?
05:24Dranik_2x2l, I don't know CL so well but I'm sure it is possible to save the current state and restore it after a while
06:28zmila#join compojure
07:17bmhI'm thinking of implementing sampling from the conditional multivariate normal distribution in Incanter and I want to make sure I get my interface right. Anyone involved with Incanter around?
07:27zmila_aoeu
08:59CozeyHi! I'm using 'contexts' with cake. Will I be able to set some configuration in a later generated jar? when I do cake jar @context it doesn't seem to place the cake namespace inside the jar
09:14_fogus_Looks like the documentation for #= has vanished. :-(
09:38ejackson_fogus_: the LHC is rumoured to be emitting particles of antidocumentrons.
09:39Fossithat'd be funny
09:57_fogus_CURSE YOU LHC!
09:58ejacksonits always the French.
10:13octei've noticed a pattern when i write clojure utils, i'll make a create/init function that returns a state-object that is usually a ref to a map, and a destroy/close function that releases any resources the state contains, and then a bunch of functions that takes the state as an argument and does various things
10:13octeis this a good pattern?
10:16Chousukehmm
10:17Chousukeif the functions operating on the actual ref is low, then I guess.
10:18Chousukeyour main concern should be writing functions that operate on the values of the ref, not functions that operate on the ref :)
10:19Chousukethough I have to say that sounds a lot like you're just emulating object-orientation
10:19Chousukewith a constructor, methods, mutable state, and a destructor :P
10:23octeChousuke, yeah, that's the feeling i get too.
10:24octesay for example i'm writing an irc client, i'll need to at least keep track of the socket (in the state object then)
10:24octeit feels inevitable
10:25octe1
10:29Chousukeocte: you can't avoid state entirely, the point is isolating it from the non-stateful stuff.
10:29Chousukeocte: which includes most processing of data
10:30octeyes
10:30Chousukeif you can tell which functions are stateful and which aren't given arbitrary parameters, you're doing fine I think :P
10:31octewell when there's io involved, they're all stateful i guess
10:31Chousukein a stereotypical OO program, there's just no reliable way to tell wtf exactly is happening. :)
10:31octeyeah
10:31Chousukeocte: only the IO itself is stateful, processing the stuff you read is not.
10:31octefeels like im falling into that trap with my state-objects
10:32octeah well
10:38dnolenocte: you could create a small paste gist isolating the particular pattern you find yourself using. it sounds unidiomatic to me.
10:54raekocte: I think one example could be to write (defn parse-line [s] (.split s ",")) (parse-line (read-line rdr)) instead of something like (defn get-and-parse-line [rdr] (.split (read-line rdr) ","))
10:54raeki.e. to as often as possible to all data processing in pure functions
11:09jkdufairanyone working/worked with appengine-clj?
11:11TobiasRaederthe freiheit one?
11:11TobiasRaederor appengine-magit
11:12TobiasRaeder*magit
11:12TobiasRaederbut i guess that would be appengine-magic and not -clj ;)
11:12TimMc*magic
11:12TobiasRaederty
11:12TobiasRaederlol
11:12TobiasRaederbut yeah actually i do
11:13ev4lhi there! did anyone here experienced the following error with swank-clojure: "swank-clojure-reset-implementation: Symbol's function definition is void: aput"
11:13ev4lit happens when run 'swank-clojure-project' to change the current project directory
11:14ev4l*it happens when i run*
11:17jkdufairi've been playing with appengine-magic but discovered appengine-clj. there are several forks and i wondered if anyone had experience with any of them. the datastore features in the r0man fork and below look pretty tasty
11:18TobiasRaederi just know the original (smartrevolution) one which is in kind of a big overhaul right now which is nearly done
11:19raekev4l: haven't heard of that problem, but I would recommend trying durendal (https://github.com/technomancy/durendal)
11:20raekit lets leiningen take care of starting swank, rather doing that from emacs
11:20jkdufairi've been using durendal and it works nicely
11:21raekI think you could say that it's the successor of swank-clojure.el
11:21TobiasRaeder@jkdufair you need any help with appengine-clj?
11:21raek"Previous versions of Swank Clojure bundled an Elisp library called swank-clojure.el that provided ways to launch your swank server from within your Emacs process. While swank-clojure is still distributed with the project, it's a much more error-prone way of doing things than the method outlined above."
11:21raek"If you have configured your Emacs to use M-x swank-clojure-project then it should still work, but it's not recommended for new users."
11:22raekwhen I started using durendal, I also had to add a lein symlink in /usr/local
11:23jkdufairTobiasRaeder: not help, per-se. just in choosing a fork. looks pretty self-explanatory otherwise. i'm building a RESTful JSON frontend to appstore entities
11:23raeksince it wouldn't use my custom PATH from by .bashrc
11:23jkdufairwrote a bunch of macros and such which look like was done better by appengine-clj
11:24TobiasRaeder@jkdufair okay, well i think the smartrevolution should be really nice specially after the next update (gonna try to force that to be published soon)
11:25jkdufairTobiasRaeder: Are you referring to smartrevolution/clj-gae-datastore?
11:26TobiasRaeder@jkdufair i thought there was an appengine-clj from that user aswell but doesn't seems that way. im kinda confused now :D gonna see if i can find what i mean
11:26TobiasRaeder@jkdufair because i thought there was more then just a datastore api
11:27octeraek, yeah, i try to do that
11:33ejacksonLets say I download some clojure library (say clojure-redis). Is it horrendous just create symlinks from my src/main/clojure/.... ?
11:33cemerickejackson: yes, just a bit :-)
11:33ihodesejackson: yes
11:33ejacksonI want to keep them separate, but also want to be able to use clojure-redis in my project without building and deploying jars each tim
11:33ejacksonso what's the technnique ?
11:33ihodesejackson: use lein, please
11:34cemerickejackson: lein, maven, gradle, ant……really, anything other than synlinks.
11:34ejacksonlets assume maven
11:34ejacksonnow what ? (sorry for this stupid question)
11:34cemerickheh
11:35ejacksondo I mvn package the clojure-redis
11:35ejacksonmvn install it
11:35cemerickejackson: one would hope it's in a repo somewhere already
11:35ejacksonand then use it as a dep in my pom.xml for the main project ?
11:36cemerickejackson: essentially, yes
11:36cemerickmaybe this is what you're after? http://clojars.org/redis-clojure
11:36ejacksonthis was just a minimal example. Really I have two projects that rely on substantially amounts of my own code
11:37ejacksoni've been balking at pulling those shared sections into independent libraries
11:37clojurebotlibraries is http://clojure.org/libraries
11:37ejacksonsymlinks are a cute solution, but felt evil
11:38cemerickThey are. It doesn't seem like it in the small and while you're working solo, but as soon as either change, it's a disaster.
11:38fliebelmorning
11:38ejacksoncemerick: thanks for the tips. I'll buckle down and sort this out...
11:39cemerickejackson: FWIW, of course. :-)
11:46ejacksoncemerick: am I correct in thinking that converting to a multi-module maven project is a reasonable approach ? It would allow me to make a .jar for each module of the current project, deploy em to the binary repo and use elsewher.
11:47ejacksonTo press my luck on the questions: Would bringing in some existing projects (like redis-clojure) and a module into a big project be a good move ?
11:48ejacksons/and a/as a/
11:48sexpbot<ejackson> To press my luck on the questions: Would bringing in some existing projects (like redis-clojure) as a module into a big project be a good move ?
12:08technomancyejackson: FWIW that's what "checkout dependencies" are for in lein
12:08ejacksontechnomancy: thanks, I'll examine that.
12:09technomancythat way changes in the checkout are available without doing the repackage/restart dance
12:10ejacksonyeah, that's what's irritating me right now
12:25fliebelWhat is a good data structure for storing positions where adjacent positions are nearby and easy to get to?
12:25AWizzArdfliebel: you can think about sorted-set-by
12:25AWizzArdfor those and on sorted-map-by's you can do subseq
12:27fliebelAWizzArd: Sorted by what?
12:27AWizzArd,(subseq (sorted-set-by #(< %2 %1) 1 2 3 4 5) < 3)
12:27clojurebot(5 4)
12:29AWizzArdYou can sort by position
12:29AWizzArd,(sorted-set-by compare (range 10))
12:29clojurebot#{(0 1 2 3 4 5 6 7 8 9)}
12:29fliebelI never really understood subseq, but it looks nice :) (as deos a hilbert curve, but I'm not sure that's of any use)
12:29AWizzArd,(apply sorted-set-by compare (range 10))
12:29clojurebot#{0 1 2 3 4 5 6 7 8 9}
12:30AWizzArd,(subseq (apply sorted-set-by compare (range 10)) >= 3)
12:30clojurebot(3 4 5 6 7 8 9)
12:30AWizzArd,(subseq (apply sorted-set-by compare (range 10)) >= 3 < 8)
12:30clojurebot(3 4 5 6 7)
12:30AWizzArdthose are >=3 and <8
12:31AWizzArdor you can have
12:31AWizzArd,(sorted-set-by #(.compareTo (str %1) (str %2)) :a :b :c :d :e :f :g)
12:31clojurebot#{:a :b :c :d :e :f :g}
12:31AWizzArdand then subseq on it with >= :c and <= :e
12:32fliebelAWizzArd: I am not sure I understand how this is useful, for say a 2D grid.
12:32AWizzArdI don't know if it is useful. It is just an idea to fetch nearby objects.
12:34fliebelokay, i'll think about it
12:40ev4lraek: thx!
12:43amalloyAWizzArd: isn't #(< %2 %1) identical to >= ?
12:43raek*>
12:44amalloymmf. i guess that's true. i always forget that reversing the order of args isn't the same as negating the operation :P
12:44amalloy&(doc subseq)
12:44sexpbot⟹ "([sc test key] [sc start-test start-key end-test end-key]); sc must be a sorted collection, test(s) one of <, <=, > or >=. Returns a seq of those entries with keys ek for which (test (.. sc comparator (compare ek key)) 0) is true"
12:51fliebeldnolen: ping
13:02dnolenfliebel: pong
13:04AWizzArdamalloy: yes, I just wanted to show how it can be used in principle.
13:05fliebeldnolen: It's diner time for me now, but after the break, I'd like to discuss some issues with the cond-i problem. some examples in the book do not work because of this.
13:05fliebelany-o for example.
13:10dnolenfliebel: yeah, I'm probably not going to address that. it's pretty easy enough to sort out what's going on in those examples anyhow.
13:12dnolenfliebel: Oleg has the version of miniKanren used in the book here, http://kanren.cvs.sourceforge.net/kanren/kanren/mini/mk.scm, copy and paste into Racket.
13:14dnolenLogicBlox use of Datalog seems really interesting: http://www.logicblox.com/research/presentations/arefdatalog20.pdf
13:15jweissi'm trying to figure out how clojure.zip/branch? is throwing NPE. I can't think of any input that would cause that. http://www.fpaste.org/5J8h/
13:16jweissmy branch fn is just #(contains? % :links), which i tested calling it with nil, doesn't throw NPE
13:17raekjweiss: the closing paren on line 7 looks suspicious
13:17amalloyraek: a fine point
13:18jweissraek: amalloy: it did the same thing before i added line 7
13:18raekalso, (if x (f x) nil) can be written as (and x (fx x))
13:18amalloyraek: damn, beat me to it
13:18amalloyjweiss: you wrote the if on line 7 wrong
13:18jweissi am kinda grasping at straws
13:18raekjweiss: your defn contains two expressions: (if (nil? z) nil) and (->> ...)
13:18amalloyshould be (if (nil? z) nil (->> ...)), not (if (nil? z) nil) (->> ...))
13:19jweissamalloy: doesn't matter. removing line 7 has no effect.
13:19jweissit was broken before i added it
13:20raekjweiss: having that expression there won't affect anything, since you discard the value of the 'if' and eval the ->> anway
13:21jweissraek: so z may in fact be the 'problem' nil on line 6
13:21raeklook carefully how the parentheses are arranged in amalloy's explanation
13:21jweisslet me fix and retry
13:25jweissraek: amalloy: http://www.fpaste.org/pAXq/
13:25jweissseems to have fixed my bad "if" but still has the same problem
13:25jweissit's a zipper problem i think since it's thrown from clojure.zip/branch?
13:26raekjweiss: if you reload the file with (reload 'com.redhat.qe.auto.navigate :reload) or (C-c C-k in emacs) you will get line numbers in the stack trace
13:26raek...for you own functions
13:26raek*(require ...)
13:26jweissraek: yeah i know, i already know what line # in my own functions it's thrown from
13:27raekwhich line is it in the paste?
13:27jweissit's line 7 in the paste
13:27amalloyjweiss: it's a problem with how you're using the zipper, anyway :P. (zip/next nil) will probably throw the same error
13:28jweissamalloy: hm... maybe it's because my zipper predicate returns nil instead of false?
13:30raekmaybe the lazy-seq from iterate will call zip/next one time too much
13:30raekand then it's too late to do the zip/end? test
13:30jweissraek: i don't think so, since zip/end? returns true on the last one
13:31jweissoh wait i think i may see what you mean
13:31jweissthe way zipper's docs say it, it should be ok
13:31jweissin fact, if there was a problem that you describe, my find-node would always fail
13:31jweissbut it doesn't
13:33jweissthe doc here is unclear: "children is a fn that, given a branch node, returns a seq of its
13:33jweiss children."
13:33jweissso i am supposed to return an empty seq if there are no children?
13:34amalloyjweiss: nill is probably the same as an empty seq
13:34raekmaybe the lib will only call that function for nodes where branch? is true
13:34amalloybut don't return a seq containing nil
13:36fliebeldnolen: easy?! :( Oh, well, I think I'll figure it out. What do you mean by "not going to address"? I don't expect you to make cond-i/e work differently in Logos, but maybe you could explain me a bit about the difference, and and why any-o does not work with Logos, as defined in the book.
13:37raekjweiss: have you tried defining a lazy-seq in some way like this: (defn traverse-tree [z] (lazy-seq (when-not (zip/end? z) (cons z (traverse-tree (zip/next z))))))
13:37raekI don't know if zippers are designed to be used this way
13:38raek(I have barely used tried them)
13:38jweissraek: you mean using next to create a lazy seq?
13:38jweissi figure next must be there to create a traversal
13:39raekI was thinking about putting next and end? at the same place
13:39raekto use them both to construct the seq in order to not walk outside the end
13:39raek(assuming that was the problem, which mich not be the case anyway)
13:47dnolenfliebel: sorry got disconnected.
13:48dnolenfliebel: I just don't have much interesting in supporting depth-first search in Logos. It's existence in TRS purely pedagogical, show you can see the benefits of an interleaving search.
13:49dnolens/show/so
13:49sexpbot<dnolen> fliebel: I just don't have much interesting in supporting depth-first search in Logos. It's existence in TRS purely pedagogical, so you can see the benefits of an interleaving search.
13:50fliebeldnolen: I wasn't asking if you could support it, but rather if there is a way to make things like any-o work with your cond-e.
13:51dnolenfliebel: can you paste the snippet so I can see what your talking about? I don't have my copy of TRS lying around.
13:51fliebel(defn any-o [q] (cond-e (q s#) ((any-o q))))
13:52dnolenfliebel: and how are you running that? (run 1 [q] (any-o q) ?
13:53fliebel(run 1 [q] (any-o s#) (== true q))
13:53fliebelno, wait...
13:53fliebelyea, like that
13:55fliebelI can imagine the because of interleaving, it tries q, recurs, and never reaches s#, but..
13:55fliebel(defn any-o [] (cond-e (s#) ((any-o)))) has the same result.
14:08dnolenfliebel: actually I think you found a legitimate bug :)
14:11dnolenfliebel: I created an issue, the interleaving is not right
14:16mprenticehappy thursday folks
14:25whrHello, i've got a question. Why doesn't this code: (try (map + '(a b)) (catch Exception ex 42)) catch the exception (it throws ClassCastException)? Similiar code, (try (throw (new ClassCastException)) (catch Exception ex 42)) returns 42
14:28mprenticeI need to differentiate between a map and a string. Ideally, (somefun {}) will return true, and (somefun "anystring") will return false. What is the idiomatic clojure way to do this? (I have a vector filled with maps and strings and i need to only do a lookup based on a key in the maps)
14:28Chousuke(doc map?)
14:28clojurebot"([x]); Return true if x implements IPersistentMap"
14:28mprenticeahhhhh, durr, yes, thanks much :)
14:39amalloywhr: map is lazy
14:39amalloythe exception doesn't occur during the call to map, but in the realization of the lazy seq that map returns, which is outside the lexical scope created by try
14:40amalloy&(try (map + '(a b)))
14:40sexpbotjava.lang.ClassCastException: Cannot cast clojure.lang.Symbol to java.lang.Number
14:40whramalloy: I see, thank you!
14:40amalloy&(try (map + '(a b)) (catch Exception _ 10))
14:40sexpbotjava.lang.SecurityException: You tripped the alarm! catch is bad!
14:41amalloymutter. anyway, you can put a (doall (...)) inside the try, if you want to catch and don't mind realizing the whole seq at once
14:41jcromartie&(take 2 (map inc '(3 9 a b c)))
14:41sexpbot⟹ (4 10)
14:41jcromartie&(take 3 (map inc '(3 9 a b c)))
14:41sexpbotjava.lang.ClassCastException: clojure.lang.Symbol cannot be cast to java.lang.Number
14:44dnolenfliebel: should be able to get that fixed later this evening. Looks like I'll be using delay to force interleaving, fun. Thanks for the report.
15:09jweissso (first (filter pred coll)) isn't lazy... how do i lazily find the first matching item?
15:10raekwhat do you mean by not lazy? does it force too many elements?
15:10raekjweiss: 'some' is made for that
15:10raek(some #(when (pred %) %) coll)
15:11jweissraek: sweet, that's it, thakns
15:11raekif the seq is chunked, maybe that won't make any difference
15:16monoraHi, I am experimenting with slime-clojure. But can't remember how to get the value of the last evaluated expression. Was it $1, $2,...
15:17jcromartie*1
15:17jcromartie*2
15:17monoraAh! Thanx
15:17jcromartieraek: is "some lazy?
15:25clizzinquick question about records and type hints: i declared (defrecord Foo [a b]) in (ns foo). then, in (ns bar), i have a function (defn bar [#^Foo f] ... ). but i didn't require or use the foo ns in any way. how come the bar function still compiles with the type hint even though the bar ns shouldn't recognise the Foo type?
15:25raekjcromartie: I don't think the term applies to it, since it does not produce a seq. however, I don't think it will force more of the seq than it needs
15:35jcromartieit's kind of strange that (first (filter pred coll)) seems to fully evaluate the seq
15:36jcromartie&(first (filter #(do (println %) %) (range 5)))
15:36sexpbot⟹ 0 1 2 3 4 0
15:36jcromartiethose 0 1 2 3 4 are printed
15:37jcromartiebut filter says it returns a lazy seq
15:39Scriptorjcromartie: print forces evaluation, maybe?
15:39jcromartiethat would be strange
15:39_fogus_&(second (filter identity (iterate #(do (println \.) %) 1)))
15:39sexpbot⟹ . 1
15:40raek&(first (filter #(do (println %) %) (range 100)))
15:40sexpbot⟹ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 0
15:40jcromartiehm
15:40raekranges come in chunks of 32.
15:40jcromartieit takes 32 eh
15:40Scriptorohh
15:40Scriptorright, it's an optimization
15:40jcromartieso what's lazy, filter, or range?
15:40_fogus_raek: beat me to it! :-)
15:40jcromartiewhat's lazy: filter, or range?
15:41Scriptorboth, I think
15:41_fogus_(inc raek)
15:41sexpbot⟹ 5
15:42raekboth return lazy sequences, but performing sequence operations of a chunked seq (e.g. one returned by range) happens 32 at a time
15:42jcromartie&(first (filter #(do (println %) %) (vec (range 100))))
15:42sexpbot⟹ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 0
15:42jcromartielooks like filter is returning a 32-chunked seq
15:42raekI don't know much more details than this
15:42jcromartieI could just look at the source I guess
15:42jcromartie:P
15:42raekover to you, _fogus_... :-)
15:42jcromartiesilly me
15:46cemerickOT: Any chance anyone here is an expert in the minutiae of options?
15:46_fogus_options?
15:46_fogus_stock options?
15:46cemerick_fogus_: of the financial sort
15:47jcromartie&(type (range 10))
15:47sexpbot⟹ clojure.lang.LazySeq
15:47jcromartie&(type (seq (range 10))
15:47sexpbotjava.lang.Exception: EOF while reading
15:47jcromartie&(type (seq (range 10)))
15:47sexpbot⟹ clojure.lang.ChunkedCons
15:48_fogus_cemerick: Sorry... not I
15:48cemerick_fogus_: yeah, it was a longshot. I've had good luck asking longshot OT questions here, though.
15:50jcromartielooks like seq returns chunked seqs
15:50jcromartiefor some types
15:51raekit just returns whatever was wrapped in the (lazy-seq ...) form inside the definition of range
15:59jweissi'm a bit confused about zippers. all my nodes are the name type - a map. each node can have a :links key, whose value is a seq of other nodes (children).
15:59jweissso isn't my "branch?" function (constantly true)?
16:00jweisssince all my nodes are branches (whether they actually have children or not)
16:00amalloyjweiss: yes. why is that confusing?
16:00amalloyand your children function is just :links
16:01jweissamalloy: well, it isn't but the zipper doesn't seem to work. each node (if i call zip/node) still has all the children in it.
16:01jweissi kinda expected not to see them
16:02amalloywhat do you mean, still has all the children? zip/node returns the exact data structure that you have it
16:03jweissamalloy: i am confused about the zipper model. it's calling it a node, when the way it behaves seems like it's returning the entire tree for which that node is a root.
16:03amalloyso if your map is {:name "test" :size 10 :children [{:name "foo"}]}
16:04amalloythen that map is the node
16:04jweisshm, ok. i was expecting all the nodes to be the same size as i walked from root to leaf.
16:04jweissbut they actually get smaller and smaller.
16:04amalloyit doesn't know how to "take out" the children-related data. how could it? it just knows that this map is a data point, and to get the children of that data point, it calls (:children the-map)
16:05jweissamalloy: yeah, i understand. it's the nomenclature that had me thinking the wrong way.
16:05jweissit's not a node, it's a branch.
16:05amalloyonly if you want to think of it that way
16:05robonoboHi guys
16:06robonoboHow would i find the index of the greatest element in a seq?
16:07amalloyrobonobo: you can do it, but usually messing with indexes is the wrong way to go
16:07jweissamalloy: what is the point of zip/path then? it returns [entire tree, subset, smaller subset, etc]
16:08amalloyjweiss: it gives you zip nodes, not your data elements
16:08jweissthe data element of the first item in the path is the entire dataset
16:08robonoboamalloy: I know, but it is pertinent in this context
16:08amalloy&(first (apply max-key second (map-indexed identity [4 1 6 8 0])))
16:08sexpbotjava.lang.IllegalArgumentException: Wrong number of args (2) passed to: core$identity
16:08amalloy&(first (apply max-key second (map-indexed vector [4 1 6 8 0])))
16:08sexpbot⟹ 3
16:09amalloy&(first (apply max-key second (map-indexed vector [4 1 6 -8 0])))
16:09sexpbot⟹ 2
16:09amalloyrobonobo: ^
16:09robonobowow, I would have thought that to be simpler
16:11amalloyrobonobo: perhaps there is a simpler way, but this is straightforward enough for me. why write a standard-library function to do something you should rarely do?
16:11robonoboamalloy: true
16:12amalloyand it's fairly clear what it's doing. turn a seq of data items into a seq of [idx, data] pairs; find the element with the largest data item; get the index of that element
16:30simardis there a way to do something like this (ie.: the problem seems to lie with the % signs) ? (map #(map #(identity %) %) (partition 5 big-number))
16:30simard Nested #()s are not allowed
16:30simardhum
16:30simardclear enough
16:31fogus_awaysimard: You don't need #() around identity
16:31brehautthe use of identity there is just a placeholder right?
16:31simardbrehaut: yeah just to make sure this is working
16:32brehautclojurebot: partition
16:32clojurebotpartition is probably not what you want; see partition-all.
16:33amalloysimard: i think fogus_away's point was that "#(foo %)" can be more concisely written as "foo"
16:33simardnah I really want partition :)
16:33amalloybrehaut: that's interesting; i usually want partition
16:34amalloyfor things like ##(partition 2 1 (range 6)) to get a seq of pairs
16:34sexpbot⟹ ((0 1) (1 2) (2 3) (3 4) (4 5))
16:34brehautamalloy: however a lot of people who dont realise both exists actually want partition-all
16:34brehautoh yeah for sure, partition-all is messy there
16:35amalloyi think partition-all would give me (5) as an extra "pair"
16:35brehautyeah it would
16:37ossarehafternoon all
16:37brehautossareh: its always morning in UGT
16:38ossarehUGT?
16:38clojurebotugt is Universal Greeting Time: http://www.total-knowledge.com/~ilya/mips/ugt.html
16:38ossarehah :)
16:38technomancy~botsnack
16:38clojurebotthanks; that was delicious. (nom nom nom)
16:39ossarehIn all my years on IRC I've never heard of ugt - awesome!
17:06TimMcI think it has been making the rounds again recently.
17:07TimMc...unless I first heard about it here, in which case it is not indicative of a trend. :-P
17:12simardis it possible to have a seq be indexed through (nth) without all elements before the nth element to be evaluated ? (it would depend of the seq of course, some are recursively defined, but others are not..) could anyone enlighten me on this ?
17:12simardor give a pointer anyway
17:17Cozeyis there some function to updated an element of a list using a predicate to determine which one? (the new value will also be calculated from old value + something else)
17:21brehautCozey: asside from (defn map-if [pred f s] (map #(if (pred %) (f %) %) s)) ?
17:23Cozeybrehaut: not bad!
17:23brehautCozey: it does strike me that a list is the wrong tool for the job though
17:24Cozeybrehaut: perhaps - but what if i want to manipulate some ordered collection of data? I'd like to keep the order
17:25brehautordered or sorted ?
17:27Cozeyordered
17:29CozeyI have a list of symbols and another equaly long list of classes. I want to create a structure like [ [class1 item1 item2 item3] [class2 item1 item2 item3... ] ... ] with items partitioned for each class. the order of classes should be the same as they 'appear' in list of classes, so if classes are: a c b b a a, it should be: a c b
17:30Cozey(if symbol has the same position as class in it's list, it belongs to that class)
17:35jweissis there some kind of gotcha in writing a closure like this? http://www.fpaste.org/Zz0y/ - the function it returns is behaving really oddly. seems to work fine when called from the repl directly, but when i call another function that calls it (with the same args), from the same namespace, it does nothing.
17:36jweissit could be a lot of things, but I suspected closure issues
17:37Chousukeshould work fine
17:37Chousukeare you sure there's no laziness involved?
17:37Chousukeor dynamic binding :P
17:38Cozeycontains? for vectors?
17:39Chousukesounds inefficient ;/
17:39Cozey:-) should i use a map then?
17:42brehautCozey: contains? doesnt do what you expect for vectors - it only tells you if the index is contained in the vector
17:43Cozeyyes but is there a function to check if vector contains a value?
17:43Cozeyor should I do this with some
17:43brehauti dont think there is
17:43brehautyou could do it with some
17:43brehautits linear search though
17:43Cozeyyes
17:44brehautim sure chouser has a finger trees solution for you ;)
17:47TimMcLooks like I can't :use namespace A in both B and C and then :use B in C.
17:47TimMcCan someone confirm/deny?
17:47brehautas long as its not circular i think you should be fine
17:48amalloyTimMc: yeah, that should work
17:49amalloyB won't re-export A's symbols, which would be a problem
17:51TimMcHah, I forgot to delete what I moved to A from their original home in C. >_<
17:51TimMcHitting save would help.
17:53amalloyCozey: if you want to keep an ordered list but also know what's in it at any given time, you can maintain in parallel a hashset of its values
18:00Cozeyi think this is what i'll do
18:28pdkhm
18:28pdkwould there be anything special to worry about for writing a multimethod with multiple arities
18:30amalloypdk: no. your dispatch function just needs to handle all the same arities
18:31pdkhm
18:31pdkin this case arity won't affect the dispatch values
18:31pdkso if i were to write the multimethod to take [x & y]
18:31pdkand one of the methods to take ([x] [x y]) i'm hoping it'd still interpret it right
18:32amalloyindeed, or [[x]]
18:32amalloy(instead of [x & y])
18:32pdkin this case it'll be 1/2 args
18:33pdkactually would there a quick way to inline default values for optional args with the destructuring syntax
18:33pdkor do i just stick (or optional-arg default-value) all over the place
18:39amalloypdk: it's easy for args that are passed in a map. i don't know how to do it otherwise
18:39amalloy&(let [{a :value b key :or {a 10}} {:key "hello"}] [a b])
18:39sexpbot⟹ [10 nil]
18:40amalloy&(let [{a :value b :key :or {a 10}} {:key "hello"}] [a b])
18:40sexpbot⟹ [10 "hello"]
18:40pdkit'd be nice if there was a guide that explained destructuring specifically in the context of fn argument lists
18:40amalloypdk: there's no need to
18:40pdksince i'm doubting everything given with destructuring for let bindings still applies with an arg list but
18:40amalloyit does
18:41pdk\o/
18:41amalloy((fn [a & b] 10) => (let [[a & b] [10]])
18:41amalloyie, just wrap the formal and actual parameters in a vector, and you're done
18:42amalloyfirst example should read ((fn [a & b]) 10)
18:45TimMcDo :import and :use etc. have the same parameter structure (modulo quoting) that import and use do?
18:46amalloyTimMc: yes
18:46pdki've never seen a case where they had to be different
18:46pdkaside from perhaps not needing '
18:46TimMcOK.
18:46amalloyand you don't need to quote either import or :import, btw
18:46TimMcreally?
18:47amalloy&(import java.util.ArrayList)
18:47TimMcWhere can I find an explanation of the complete syntax available in import, require, etc?
18:47sexpbot⟹ java.util.ArrayList
18:47pdkit used to be you needed to quote them in early versions
18:47pdkthey're changed to be macros now so you don't anymore
18:47TimMcI see a bunch of examples, but no complete grammar.
18:47amalloypdk: no
18:47amalloy&(meta #'import)
18:47sexpbot⟹ {:macro true, :ns #<Namespace clojure.core>, :name import, :file "clojure/core.clj", :line 2617, :arglists ([& import-symbols-or-lists]), :added "1.0", :doc "import-list => (package-symbol class-name-symbols*)\n\n For each name in class-name-symbols, adds a mapping ... http://gist.github.com/832984
18:47amalloyoh. hm, maybe so, sorry
18:47pdkneener neener
18:48amalloy*hang head in shame*
18:48amalloy&(meta #'use)
18:48sexpbot⟹ {:ns #<Namespace clojure.core>, :name use, :file "clojure/core.clj", :line 4871, :arglists ([& args]), :added "1.0", :doc "Like 'require, but also refers to each lib's namespace using\n clojure.core/refer. Use :use in the ns macro in preference to calling\n this di... http://gist.github.com/832985
18:49amalloyi don't get why it would be a macro though. i mean, you can use the classnames without quoting; is it just so that you get a symbol instead of a class object?
18:49amalloy&java.util.regex.Pattern
18:49sexpbot⟹ java.util.regex.Pattern
19:17cdddrThis is probably silly, but is there a magical way of getting a list of common elements on two *sorted* sequences, or am I safe in writing that alone? :)
19:21TimMcHa, someone (in meatspace) was just talking about being asked that as an interview question.
19:21TimMc(given two unsorted sequences, find the common elements -- the answer involved what you're doing)
19:22cdddrThis *is* trivial in any Lisp for sorted seqs, I'm just wondering if there's a neat way I didn't think of. :)
19:23DespiteI love catonmat.net's set operations in the unix shell page. intersection is 'comm -12 <(sort set1) <(sort set2) '
19:24DespiteI never realized how often I needed set ops until I read that page
19:24TheBusbycdddr: 10 different ways jump to mind. Are you looking for the fastest, shortest, or most clojuresque way?
19:25cdddrTheBusby: The clojuresque way, seeing as I'm still learning and this isn't time-critical.
19:26cdddrAlso - 10? Hah, I could only think of 3 off-hand. ;)
19:26TheBusbyare the elements unique in each set?
19:27cdddrYup.
19:27cdddrAhhh, I see.
19:27TheBusby"set" being the keyword ;)
19:28cdddrYeah, I got too focused on the sorted part to notice. :>
19:29TheBusbyit hides in 'clojure.set so I forget about it frequently as well
19:41simardwhat's better, (apply max (range 1 1000)) or (reduce max (range 1 1000)) ?
19:42cdddrI
19:45cdddrMax being explicitly defined with more, I'd go with the former.
19:46simardmakes sense.. both take the same amount of time
19:46simard(though)
19:46simardis there a way to measure the memory required ?
19:46simardin the same way you measure (time...)
19:47cdddrWell, I'd guess max is defined in terms of a macro for more arguments - one that's basically equivalent to the reduce.
19:47simardso you'd save one step
19:47cdddrSo they're likey to work just the same under the hood.
19:47simardthe macro expansion
19:48simard(well, one macro expansion)
19:48cdddrI'm with Knuth on optimization - if it works, stop caring. ;)
19:48simardsure :)
20:07Mec_,(isa? #() clojure.lang.IFn)
20:07clojurebotfalse
20:07technomancyMec_: you want instance?
20:08Mec_,(instance? #() clojure.lang.IFn)
20:08clojurebotjava.lang.ClassCastException: sandbox$eval1323$fn__1324 cannot be cast to java.lang.Class
20:08Mec_ah
20:08brehaut,(ifn? #())
20:08clojurebottrue
20:08technomancy,(instance? clojure.lang.IFn #()) ; yay consistency
20:08clojurebottrue
20:09Mec_ah thank you both
20:09brehautMec_ most of the standard types have predicates like that too
20:10brehaut,[(fn? #()) (fn? {}) (ifn? {}) (map? {})]
20:10clojurebot[true false true true]
20:12Mec_What's the difference between an Fn and an IFn?
20:12brehautnot all iFns are fns
20:12brehautyou can make anything act like afunction, but that doesnt make it a function
20:13brehaut,(apropos "?")
20:13clojurebotjava.lang.Exception: Unable to resolve symbol: apropos in this context
20:13brehaut##(apropos "?")
20:13sexpbotjava.lang.Exception: Unable to resolve symbol: apropos in this context
20:14brehaut##(use '[clojure.repl :only [apropos]])
20:14sexpbot⟹ nil
20:14brehaut##(apropos "?")
20:14sexpbot⟹ (superset? subset? alert-time? impl-enabled? enabled? logged-in? has-privs? -?>> .?. seqable? -?> is-blacklisted? is-command? leftmost? auto? rightmost? connection? keyword? chunked-seq? instance? sequential? fn? nil? string? sorted? false? true? odd? symbol? thread-... http://gist.github.com/833071
20:14Mec_##(doc -?>>)
20:14sexpbotjava.lang.Exception: Unable to resolve var: -?>> in this context
20:14brehaut-?>> is in clojure.contrib.core
20:15brehautits like ->> but if any of the forms return nil, the whole expression returns nil
20:15Mec_thats what i thought
20:15Mec_I use -> and ->> for everything so I don't have to read inside out, does that mean I'm doing it wrong? :D
20:16brehautnope
20:16brehautwell, depends what you mean by everything ;)
20:16brehautsometimes just using a let is clearer ;)
20:16Mec_just by assigning each step a name?
20:16brehautyeah
20:17Mec_makes sense
20:17brehautif each expression is complex its good, because then youve got cognitifve assistence for determing the what and why of each
20:18brehautalso if you are doing something like (-> mapmapmap :a :b :c) consider (get-in mapmapmap [:a :b :c])
20:21brehautMec_ and of course, if you have something like (defn foo [a] (-> inc inc)) you could do (def foo (comp inc inc))
20:21amalloybrehaut: meh. get-in doesn't strike me as much clearer really
20:21Mec_I was just thinking about using comp more, but its still a bit backwards
20:22brehautexactly why thrush should be in core :P
20:23technomancyyou let one bird in and all the others are going to want in as well; soon we'll have kestrels, larks, even doves clamoring for admission.
20:23technomancyerr--wait, we already have kestrel.
20:24brehauthah
20:24Mec_whats thrush
20:24brehaut~comp backwards
20:24clojurebotthe scala compiler | is | <reply> see: http://harrah.github.com/browse/samples/compiler/scala/tools/nsc/typechecker/ConstantFolder.scala.html#65760
20:24brehautwow that isnt something i expected
20:25brehautMec_: http://www.angelfire.com/tx4/cus/combinator/birds.html
20:25Mec_owe my eyes
20:25brehauthttp://blog.fogus.me/2010/09/28/thrush-in-clojure-redux/
20:26TimMcGiven a unary function, how can I easily iterate (f (f (f (f x)))) a set number of times?
20:26brehaut'owe my eyes' is using 'OpenLayers.Filter.Comparison.GREATER_THAN_OR_EQUAL_TO' as shorthand for ">="
20:27amalloyTimMc: try: ##(doc iterate)
20:27sexpbot⟹ "([f x]); Returns a lazy sequence of x, (f x), (f (f x)) etc. f must be free of side-effects"
20:27TimMcAnd then use nth?
20:28amalloyyeah
20:28TimMcHa, OK.
20:28amalloyTimMc: or if you want, ##((apply comp (repeat 10 inc)) 2)
20:28sexpbot⟹ 12
20:28TimMcI saw iterate, but passed it by -- I need to get more into functional thinking patterns.
20:29TimMcTHat's pretty cute.
20:29amalloyi stole it from technomancy, i think
20:30TimMccomp looks pretty useful.
20:30Mec_my favorite use of iterate is ##(take 10 (map first (iterate (fn [[a b]] [b (+ a b)]) [1 2])))
20:30sexpbot⟹ (1 2 3 5 8 13 21 34 55 89)
20:30technomancydinc!
20:31amalloytechnomancy: yeah, as soon as i hit enter i regretted using 10 instead of 8
20:32technomancyamalloy: well to be fair yours is 25% more effective than oinc.
20:32amalloytechnomancy: moore's law
20:32amalloyit's been a few months
20:33technomancyastounding.
20:37jnymo_hi
20:38Mec_I don't really see the benefit of thrush, it's seems like threading but every form has to be a function
20:38jnymo_I wonder if it'd be possible to do multi-threading with web-workers, for that cojure-js thing.
20:46simardclojurebot: partition
20:46clojurebotpartition is probably not what you want; see partition-all.
20:48technomancy~botsnack
20:48clojurebotthanks; that was delicious. (nom nom nom)
21:53simard`in this example, is def'ining just4 a problem for memory ? (def just4 (repeat 4)) (take 99999 just4)
21:54amalloyyes
21:54simardyes it's a problem ?
21:56amalloyyou asked a yes/no question and got a yes answer. what are you looking for by asking me again?
21:57simardjust to make sure I didn't miss anything when I left the channel actually.. :P
22:22TimMcHow is (repeat 4) memory-intensive?
22:23brehautTimMc: you are holding onto the head ofthe seq
22:23brehaut(probably)
22:23brehauteg (let [four (repeat 4)] (take 100000 four)) is memory intensive (take 1000000 four) is not
22:24TimMc(take 1000000 (repeat 4)) you mean?
22:24brehautyeah i do mean
22:25brehautmake sense?
22:25TimMcI need to learn more about seqs. I thought they were just generators that didn't hold any stuff beyond what they were given.
22:25brehautsort of
22:25brehautthey are (conceptually at least) immutable though
22:26TimMcAh, but internally cache stuff?
22:26brehautnah simplier
22:26brehautunlike an iterator/generatoe next/rest doesnt modify the seq you have,it returns a new seq
22:26brehautlike a lazy linked list
22:27TimMcOh!
22:27TimMcSo you are preventing the GC from collecting the intermediate nodes?
22:27brehautbingo
22:27TimMcsneaky
22:28brehautits teh one gotcha from having really good seqs
22:28brehautthey allow a lot more expressiveness than the traditional iterator
22:28TimMc(rest some-seq) holds a pointer to some-seq, yes?
22:29brehautno
22:29brehautseqs are singly linked
22:29brehautlike a cons cell
22:29TimMcI don't understand the object graph then.
22:29brehaut(cons 1 (cons 2 (cons 3))) ; the tail of each cons knows nothing about the cell its contained in
22:30TimMcsure
22:30brehautrest returns a new thing from a seq
22:30brehautthat new thing is the tail
22:30TimMcBut a seq like (repeat ...) is not a concrete linked list.
22:30brehautno
22:30brehautits a conceptual one
22:32brehautas you realise a lazy-seq it becomes concrete though
22:34TimMcOK, so (repeat x) is (lazy-seq (cons x (repeat x)))
22:34TimMc(reading the source)
22:34brehautyup
22:37TimMcSo wait... walking through that seq builds up a cons chain?
22:37brehautyes
22:37TimMcI'm having a little trouble understanding the mechanics behind realization.
22:37brehautok heres the interface for a seq
22:37brehauthttps://github.com/clojure/clojure/blob/1.2.x/src/jvm/clojure/lang/ISeq.java
22:38brehauti have no idea what more does
22:39TimMclazy-seq just looks like magic to me.
22:39brehauti tried to make an example with reify but i failed
22:39brehautit is
22:39brehaut;)
22:39brehautbasicly it creates a 'thunk'
22:39brehauta thunk is a promise to compute some value later
22:40TimMcyes
22:40brehautthat is then replaced with that value
22:40brehautthe mechanics of lazy-seq arent actually too important to grok what is going on
22:41simardhum nice job on clojars and leiningen.. it's really easy
22:44TimMcbrehaut: Oh! clojure.lang.LazySeq uses internal mutation.
22:45TimMcI'm not confused anymore.
22:45brehautyeah thats why its conceptually immutable
22:45TimMc...but can still build up an object graph extending from the head.
22:45brehautyeah you can do real tricky stuff with it
22:46brehautin haskell they have a trick they call 'tying the knot'
22:46brehautwhere you make the tail of one list its own head
22:47TimMcSo... seqs are "immutable" but can still do things that look like mutation, which means you have to treat them like realized lists in some ways.
22:47brehautdont think ofthem as tricky
22:47brehautthey _dont_ look like mutation
22:47brehautthats the cool part
22:47brehautthe tail of lazy-seq may contain unrealized values
22:48brehautas soon as its realized (ie observed for the first time) it has a value, and that value never changes
22:49TimMcSo I should think of any seq as "an existing singly-linked list that may be lazily computed."
22:49TimMcTHat covers the holding-onto-the-head problem.
22:50brehautyeah i think thats ok
22:56tomojI wonder if channels and seqs are dual
22:57tomojsimilar to IObservable/IEnumerable but better?
22:59brehautcould be eh
23:12simardhow do you guys start your inferior-lisp-process so that the classpath is set properly to that required by your current lein project ?
23:14amalloycake swank
23:14amalloyor lein swank
23:16semperosor just set inferior-lisp-program to "lein repl", if you don't use slime
23:37technomancythere's also lein classpath
23:37taliosand mvn clojure:swank
23:47simardhum running "lein swank" -> "That's not a task."
23:47simardswank-clojure is running though
23:47technomancyswank isn't used with inferior-lisp-process
23:48technomancyyou can just do java -cp `lein classpath` clojure.main as your inf-lisp
23:49pdk(doc take)
23:49clojurebot"([n coll]); Returns a lazy sequence of the first n items in coll, or all items if there are fewer than n."
23:49simardoh these backticks will work directly in that var ?
23:49simardnice
23:50technomancysimard: err--actually no
23:50simardoh well I'm connected with slime-connect to swank-clojure right now
23:52technomancyoh sure, if you want to use slime you don't need to set inf-lisp-anything
23:52pdk(doc repeatedly)
23:52clojurebot"([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"