#clojure logs

2010-11-13

00:44kumarshantanu1hi, is it possible to attach documentation to an anonymous function?
00:44hiredmanno
00:44hiredmanbut you could never look up the docs, so who cares
00:45kumarshantanu1I want to be able to...in an internal system
00:45kumarshantanu1anonymous predicate function, that could tell why a boolean test failed -- from the doc
00:45hiredmanuh
00:45kumarshantanu1well anyway, since it is not possible...
00:46hiredmanbut you would never be able to get the doc
00:46kumarshantanu1hmm
00:46hiredmanthe question is almost nonsensical
00:47hiredmandocstrings are metadata on vars, anonymous functions are not held in vars, qed
00:48kumarshantanu1right
01:16gstampWhat does fn* do?
01:20tonylit is an internal implementation of fn
01:21tonylwhenever you see that just think it is fn, they are mostly used to bootstrap basic functionality for clojure i think
01:29DeranderWhat is that mouse chording text editor called?
01:30Deranderacme
02:08sandGorgonis anyone aware of any clojure wrappers for lucene ?
02:25sivajagsandGorgon: i am not aware of one
02:25sivajagbut thinking of writing
02:26sivajagu wanna join and do it?
02:36sandGorgonsivajag, sure... I actually took a look at the mailindex and clucy projects on github and am cranking out something. I want to index a load of XML files
04:13kjeldahlHow do I make and use a symbol with an embedded space in it?
04:14Raynes&(symbol "blah blah")
04:14sexpbot⟹ blah blah
04:14RaynesAs for using it...
04:15kjeldahl.. Incanter creates such headers by default when using read-data... :-)
04:16kjeldahlEh, I think I might meant keyword...
04:16kjeldahl:quotedate with a space in it.
04:20amalloy&(keyword "1 2")
04:20sexpbot⟹ :1 2
04:29kjeldahlOk thanks. For some reason (keyword "price"), (keyword "paper") etc works fine, but not (keyword "quote date") using Incanter. I'll keep digging.
04:30RaynesWhy would you need spaces in keywords?
04:30RaynesI mean, do you have a specific reason?
04:59kjeldahlRaynes: Yes, the read-dataset method in Incanter uses keywords for column headers by default.
05:23_ulisesmorning all
05:57_uliseshas anybody used suart sierra's clojure-hadoop lib in production?
05:57_ulises(sorry if this is a silly question)
05:57_ulisesalternatively, do you know of any "good" way of interfacing clojure w/hadoop?
05:58_ulisesI'm basically doing an investigation to see which are the available options and which ones are the best ones out there
05:58_ulises(I've done my share of googling, of course)
06:14sandGorgon_ulises, cascalog ?
06:15_ulisesonly read about it, how is it different from cascading for instance?
06:16sandGorgon_ulises, it IS cascading - just wrapped in clojurey way. I believe it is also being used in production in a couple of places, notably flightcaster
06:16_ulisesoh! :D
06:17_ulisesinteresting, I assume this is even a higher level of abstraction from stuart sierra's clojure-hadoop?
06:20sandGorgonI'm not sure - if I had an opinion about it, i would say they are the same level of abstraction .. done differently. But dont take my word for it
06:20esj_ulises: Nathan has a good presentantation on cascalog somewhere... lemme go find it.
06:20_uliseshum, I just read a bit more about cascalog and it seems like it is a language for querying large data
06:20_ulisesI think that I am more interested in running my own map/reduce jobs so perhaps I need something more low level?
06:22esj_ulises: perhaps this: https://github.com/clj-sys/cascading-clojure
06:23esjdid sandGorgon mention it, I've just joined the room, and it looks like he might have ?
06:24sandGorgonesj, well i mentioned cascalog
06:24_ulisesinteresting
06:24_ulisesthis looks good, thank you chaps
06:54mobile,(reduce inc (range 5))
06:54clojurebotjava.lang.IllegalArgumentException: Wrong number of args (2) passed to: core$inc
06:57Raynes&(map inc (range 5))
06:57sexpbot⟹ (1 2 3 4 5)
06:58mobile(loop [n 20] (recur (n-1))
06:58mobilewhops
06:59mobilehelp me out raynes :) im on the ipad :)
06:59RaynesWhat do you need help with?
06:59mobileapparently it does work for irc
06:59mobilei forgot the comma
07:00Raynes&(loop [n 20] (recur (n-1))
07:00sexpbotjava.lang.Exception: EOF while reading
07:00Raynes&(loop [n 20] (recur (n-1)))
07:00sexpbotjava.lang.Exception: Unable to resolve symbol: n-1 in this context
07:01mobile(dec n)
07:01sexpbot⟹ -1
07:01mobile(inc 1)
07:01sexpbot⟹ 1
07:01mobileis that the karma guess.
07:01RaynesYep.
07:03mobileis it supposed to be squares, or is that a missing character
07:30_uliseshum, where am I going wrong when I (require [clojure.contrib.json :as json]) ?
07:30_ulisesok, nm
07:40bartjis there a way to lazily generate a sorted set ?
07:41bartjis it? (lazy-seq (into #{} [1 2 3 4 5 6 7 8]))
07:43cemerickbartj: no, into is eager
07:43cemericksets are by definition not lazy
07:44RaynesEager to please!
07:44bartjhmm
07:46bartjlists are eager too!
07:47cemerickof course
07:47cemerickif they weren't eager, then lists would be lazy seqs :-)
08:04bartjcemerick, the only way seems to be to use lazy seq
08:04cemerickbartj: the only way to do what?
08:05bartjto generate a lazy sequence of unique elements of a list
08:06raek,(doc distinct)
08:06clojurebot"([coll]); Returns a lazy sequence of the elements of coll with duplicates removed"
08:07raekyes, lazy seq are the only things that are lazy
08:28bartjraek, thank you; is there anyway I can know a datastructure is lazy
08:29bartjraek, like lazy-seq? as we have seq?
08:50fliebelhrm, I just had Clojure read lines from a stream, and now I killed it and lost my history. Sad story :(
09:59fliebelHow can I do something after the return value of a function without that thing becoming the return value?
10:01chouserlet
10:01RaynesYou don't.
10:01RaynesWhy would you need to?
10:01chouser(let [x (rtn-value)] (something) x)
10:02fliebelI need to close an URLConnection, but that involves getting the stream first.
10:02fliebelSo simply using with-open wouldn't work.
10:02Raynesfliebel: let would probably work in that case.
10:03fliebelThanks, I will try some of that magic, but it felt a little ugly, so I thought I might ask before making something evil.
10:04fliebelI'm trying to do this: http://philippeadjiman.com/blog/2009/09/07/the-trick-to-write-a-fast-universal-java-url-expander/
10:06Rayneschouser: I've noticed you becoming more familiar with your & key lately. My heart pounds with glee each time.
10:10RaynesI'm considering setting it up so sexpbot emails me every time chouser finds his fingers closer to & than ,. I could claim that it's just usage statistics.
10:16fliebelWhat does it mean when I get a java.io.FileNotFoundException for an url? Something like 404?
10:59fliebel&(count (distinct (repeatedly 100 #(rand-int 100)))) ; can someone who knows his math tell me why this seems to average to somewhere near 63?
10:59sexpbot⟹ 62
11:14esjfliebel: this is the Bithday Paradox: http://en.wikipedia.org/wiki/Birthday_problem
11:15esjif you were to replace 100 with 365, and then instead of asking what is the probability of there being at least one shared birthday, asking what is the expected number of shared birthdays
11:16fliebelesj: Awesome :)
11:27esjfliebel: so, if you have N numbers, each drawn uniformly from [1,N], then the probability of there being n repeated numbers looks something like (N!/n!)(N-n)n/N^2, if I got my combinatorics straight (which is highly unlikely). Then to answer your particular question (which n is the most likely) you need to find the n that maximises this. I've forgotten how to do d/dn of a factorial, but you could plot the graph and see where
11:27esjtops out.
11:28fliebelouch...
11:32esjyou asked !
11:32pauldoowolfram alpha will be your friend for that kind of thing
11:33fliebelYea, I did :) Thanks! Now I have some reading to do...
11:33pauldoothe continuous version of factorial is the gamma function, so that'll help if you do decide to try and do derivatives
11:51jarpiain&(/ (- 1 (/ (count (distinct (repeatedly 10000 #(rand-int 10000))) 10000.0)))
11:51sexpbotjava.lang.Exception: EOF while reading
11:52jarpiain&(/ (- 1 (/ (count (distinct (repeatedly 10000 #(rand-int 10000)))) 10000.0)))
11:52sexpbot⟹ 2.7601435274634283
11:52jarpiainthat should approach e
11:52kumarshantanujarpiain: what is '&' for?
11:53fliebelkumarshantanu: sexpbot
11:53fliebelkumarshantanu: it evals all clojure prefixed with &
11:53esjjarpiain: pretty close !
11:54fliebel$google e
11:54sexpbotFirst out of 228000000 results is: E! Online - Entertainment News, Celebrity Gossip, Celebrity News
11:54sexpbothttp://www.eonline.com/
11:55raek,Math/E
11:55clojurebot2.718281828459045
11:56slyrustechnomancy: should "lein swank" work without a project?
11:56fliebelSo, from this we can draw the conclusion that Java is better than Google, but Google is better than Clojure :)
11:58kumarshantanufliebel: transitively, Java is better than Clojure? (Holy Cow!!) ;-)
12:00fliebelNo, because universe is bent in such a way that Clojure is actually better than both if you look at it from certain angles.
12:00jarpiain&(reduce + (for [x (range 20)] (/ (reduce * 1.0 (range 1 (inc x))))))
12:00sexpbot⟹ 2.7182818284590455
12:01raekbartj: (sorry for not responding earlier) no, there is no such function
12:02bartjraek, that is really ok...thanks again
12:09pauldoodo delays release the closure once they have been forced? (I'm interested if values in the expression now become eligeable for GC)
12:14bmhany vimclojure users about? I'm having a frustrating time with syntax highlighting
12:14opqdonutpauldoo: i see no reason why not
12:14opqdonutbut I'm not completely sure
12:17bartjbmh, what is your question...not sure if I would be able to help, though
12:18bmhbartj: Highlighting is too eager. If I have a function called empty-vertex-list, empty and list get highlighted because the syntax file thinks that they're builtins
12:20bartjbmh, doesn't highlight for me
12:20bmhbartj: hurumph. Something must be broken in my vimrc then. Thanks.
12:32LOPPweird
12:32LOPP1 million times: (conj [1 2 3] 4) = 107 msecs
12:32LOPP(conj '[1 2 3] 4) = 75 msecs
12:33LOPPwhy
12:34LOPPand (conj '(1 2 3) 4) = 27 msecs
12:34LOPPand here I thought vectors were faster than lists
12:34opqdonutconjing to the list is lazy
12:34LOPPin what sense?
12:34opqdonutvectors are faster than lists for random access
12:35LOPPthat much is obvious
12:35opqdonutlazy in the sense that it only allocates a closure
12:35LOPPok
12:35LOPPbut why is quoted vector conj faster
12:35opqdonutwhereas conjing to a vector pretty much allocates a new vector
12:35LOPPthan without conj
12:35opqdonutsince they are persistent
12:35opqdonuti have no idea about the quote
12:36opqdonutwhat does the benchmark code look like exactly? (dotimes [i 100000] (conj [1 2 3] 4))?
12:36LOPPyes
12:36opqdonutmaybe with quote the vector is only created once
12:36LOPPhere's what I have now
12:37LOPP(time (dotimes [n 1000000] (first (conj [1 2 3] 4))))
12:37LOPPto force evaluation
12:37hiredmanconj is not lazy
12:37opqdonuteven for lists?
12:37LOPPand now I have 117 for list, 209 for quoted vector and 243 for vector
12:37LOPPso no change even if list was lazy
12:38LOPPseems to me lists are just faster than vectors in clojure, except for random access
12:39hiredmanopqdonut: even for lists
12:39LOPPthe main reason I use vectors is because I can't add at the end of list
12:39hiredmanlists are a much simpler datastructure
12:39hiredmanwhy is it surprising that they would be faster?
12:39LOPPbecause they are not in java
12:40LOPPArrayList is much much much faster than LinkedList
12:40LOPPeven for inserting at the start, until you have 500000+ elements, arraylist outperforms linkedlist
12:41LOPPthat came as a surprise to me, since inserting at start is O(1) for linked list and O(n) for array list
12:42opqdonutthat is surprising
12:43LOPPseems that using arrays + System.arraycopy is lightning fast
12:43LOPPlinked list requires alocating a new node, which slows it down tremendously
12:44samxit's also not true
12:44LOPPreally?
12:49LOPPI got my data from some detailed benchmarks some guy did
12:49LOPPmight have been faulty though
12:50opqdonutif there's something I've learnt from twiddling with different languages, it's that allocation should be cheap
12:50LOPPsure
12:50opqdonutthe jvm is a PITA in this respect
12:50LOPPbut spawning tons of objects is bound to trigger more GC cycles
12:51LOPPnoticed when testing clojure performance that results of consequtive runs would vary a lot
12:51LOPPprobably because of GC
12:51LOPPGC doesn't only free up memory it also compacts memory
12:51LOPPwhich isn't that cheap
12:52KirinDaveWell, hopefully ojdk will start pursing more modern gc strategies.
12:54LOPPwell that's a riot
12:54LOPP:P
12:55LOPPhaven't seen any strong improvements in java, just piling up new libs into JRE
12:55LOPPlast big thing was (poorly) implemented templates
13:00LOPPhuh.... found a guy claiming that hashset is faster than list
13:03samxwell, there's lies, there's bigger lies, and then there's performance metrics
13:04LOPPto be honest I'd use sequences/lists all the time if I didn't need adding at the end so damn often
13:05LOPPgimme a list with pointer to the end and ability to add there and it's golden
13:09jarpiain&(let [que (repeatedly promise)] (dorun (map (fn [x q] (deliver (first q) x)) (range 10) (iterate next que))) (map deref (take 5 que)))
13:09sexpbot⟹ (0 1 2 3 4)
13:21LOPPis (iterate next que) needed? doesn't the map already iterate through a coll?
13:22jarpiainhmm, right
13:25raekjarpiain: looks similar to something I saw on cgrand's blog
13:26raekhttp://clj-me.cgrand.net/2009/11/18/are-pipe-dreams-made-of-promises/
13:49amalloyLOPP: well, with functional/immutable lists it's not really practical to add to the end
13:49amalloybut have you checked out chouser's finger trees?
13:58fliebelThis is weird. I'm profiling a Clojure script that is running at 1% CPU and presumably spends most of its time doing IO, but VisualVM tells me it's spending most of its time in hashmap functions like assoc.
13:59amalloyfliebel: allocation counts as io, doesn't it?
14:00fliebelamalloy: I don't know, but I'm fetching urls. ;)
14:01fliebelSo I was expecting to see all sorts of java.io and java.net functions, but I see none of them.
14:07fliebelI thought there was a function in core to reverse keys and values? Or a function to sort a map by values? I found snippets for both, but I'm sure they're at least in contrib somewhere...
14:09raekfliebel: the first one is in clojure.set: http://clojuredocs.org/clojure_core/clojure.set/map-invert
14:09fliebelthanks :) the other is only doable by sorted-map-by, I believe?
14:10raekregarding the second one, would it do the same thing as (sort-by val m)?
14:10raekwhat kind of data structure would you want from the second function?
14:11fliebelraek: except that it doesn;t return a map. But the other day someone said array maps guarantee order? so i can just do an into?
14:12raekwell, I have understood things correctly, array map is an optimized implementation for hash map for small number of entries
14:12raekI don't know if you can assume things about it
14:12raekif you conj enough elements into it, the result will be a hash map
14:12raekand the ordering will vanish
14:13fliebelreally?
14:13raek(class {:a 1})
14:13raek,(class {:a 1})
14:13clojurebotclojure.lang.PersistentArrayMap
14:13raek,(class (into {} [[:a 1]]))
14:13clojurebotclojure.lang.PersistentArrayMap
14:14raek,(class (into {} (for [i (range 100)] [i i])))
14:14clojurebotclojure.lang.PersistentHashMap
14:14raekseems so :)
14:14fliebelwowzers...
14:14raekif you want an ordered map, perhaps sorted-map-by is the best solution
14:15raekhow will you use the map, btw?
14:17fliebelraek: Not all that mappish, so I think sorted is fine for now.
14:19fliebelraek: but sort takes a comparator, not a predicate, so just val will not work.
14:20raekhrm, I think you could do something like #(< (val %1) (val %2))
14:21raekthere was something about functions and Comparator, anyway
14:31amalloyraek: #(max-key val %1 %2)
14:40LOPPamalloy why isn;'t it practical to add at end of immutable lists
14:41amalloybecause your pointer is to the front of the list. you can't change the list it's pointing to, so you have to create a new list for it to point to. the same logic holds for every node but the last, so you end up copying the whole list
14:42hircusLOPP: you can use a vector instead; a Clojure vector is designed to grow at the end
14:42hircus,(conj '(1 2 3) 'x)
14:43clojurebot(x 1 2 3)
14:43hircus,(conj [1 2 3] 'x)
14:43clojurebot[1 2 3 x]
14:50LOPPamalloy you can say that for every Object, the reference points to the start of it
14:50LOPPthe list object could easily have 2 references
14:50LOPPone to the head and one to the tail
14:50amalloyLOPP: yes. but you would have to modify the head element so that if you follow enough next pointers you get to the tail
14:51LOPPisn't that what happens now?
14:51LOPPif you take next enough times you get to the end of the list...
14:52amalloyLOPP: yes. but if you add something to the end without updating the head pointer that won't be true anymore
14:52LOPPI don't understand
14:54amalloy&(let [x '(1 2)] (identical? x (drop 1 (cons 0 x)))
14:54sexpbotjava.lang.Exception: EOF while reading
14:54amalloy&(let [x '(1 2)] (identical? x (drop 1 (cons 0 x))))
14:54sexpbot⟹ false
14:55amalloywell, that's probably a terrible example
14:55raekthe last cons cell of (1 2 3) has nil as its rest
14:55LOPPso what you are trying to say is that it's because you get a new list instance
14:56raekif you want to make the list (1 2 3 4), that cell's rest would have to change into the cell containing 3
14:56raekbut lists are immutable, so you aren't allowed to change it
14:56raek*containing 4
14:56LOPPI'll take your word that it isn't possible because of the way persistency is achieved on lists
14:57andreasmk2hello guys, is there a way to use clojure as a scripting language inside my java program? currently what I see is that clojure can call java methods but not the opposite.
14:57LOPPyou can call clojure from java just fine
14:58andreasmk2i mean calling clojure functions and passing arguments. do you have any urls for tutorials or documents ?
14:59LOPPI think you instantiate the Reader object and evaluate with that
14:59LOPPother people here probably know the details
15:00raekandreasmk2: http://en.wikibooks.org/wiki/Clojure_Programming/Tutorials_and_Tips#Invoking_Clojure_from_Java
15:00raekyou can also fetch the var object with clojure.lang.RT
15:00raekand then use its invoke method
15:01andreasmk2raek, this is what i need. thank you raek :)
15:05tonylhello
15:09LOPPis it possible to return an infinite sequence of prime numbers?
15:09LOPPusing Euler's Sieve for instance(http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes)
15:09amalloyLOPP: i think clojure.contrib.lazy-seq has a primes function
15:09tonyli think there is something in contrib for primes
15:10dnolenLOPP: http://clj-me.cgrand.net/index.php?s=Everybody%20loves%20the%20Sieve%20of%20Eratosthenes
15:11dnolenLOPP: infinite lazy version at the bottom.
15:12LOPPI wish I was as smart as cgrand :P
15:14LOPPhm enqueue?
15:14LOPP,(doc enqueue)
15:14clojurebotIt's greek to me.
15:15LOPPoh right, he declared it
15:18dnolenLOPP: I feel the same way, cgrand is a Clojure zen master
15:42LauJensenGents. Everybody looked at the new design for ClojureQL? Certain functions (disj!,conj!,take,sort) shadow core names, so either use (:use [clojureql :as cql]) or accept that there are shadow warnings when importing. Can I get some oppinions on wether we should rename these functions, or if these warnings are acceptable? (I say the warnings, because the functions can be made to behave the exact same was as those in core)
15:48morphlingLauJensen: I'd prefer renamed functions
15:51LauJensenvote registered
15:55fliebelLauJensen: I'd prefer familiar names, with sum multimagic to make it work as expected.
15:55fliebel*some
15:55LauJensenyea me too, so its 2 vs 3 votes so far
15:56fliebelI think it might help to make it clear you can do the refer-clojure thing, to get rid of the warnings.
15:56fliebelI didn't know about that until recently.
15:57fliebelLauJensen: Which of the 2 are the pro-shadow?
15:57LauJenseneither refer/exclude or use/as
15:57LauJensenfliebel: You and me, want conj/disj/sort/take etc, and ninjudd, pholdings nad morphling want insert-into, delete-from, sort-by, limit etc
15:58fliebelLauJensen: Is there some sort of setup fn involved which could automate the referring? (might be a bad idea nyway, just saying)
15:59LauJensenNo, the automated solution is simply accepting the warnings when you import the lib
15:59fliebelright :)
16:08pauldoocan I make mutually recursive functions using two defn statements? (I don't care about tail call optimization)
16:09pauldooI seem to run into an order of declaration type of problem.. ie the first defn body doesn't know about the not-yet-defined function
16:09fliebelpauldoo: oh, I'm to slow, I know this...
16:09LauJensenpauldoo: You can, but might run into stackoverflow problems. Use (declare y) to announce the 2nd function before defning the first
16:09pauldoobrilliant!,, declare it is :)
16:10fliebelRight, declare… I need to implement those fast hash lookups in my mind, and then touch typing.
16:10fliebelCan I get to the queue of an agent? I'm doing send-off to an agent, and I want to see if it can keep up with the flow or builds up a backlog.
16:11pauldoocan I declare a multimethod too? or does declare only work for defn and def?
16:11amalloypauldoo: another option is letfn, though i use declare myself
16:11pauldooletfn is local though right... like let..
16:11amalloypauldoo: you can declare any var
16:11pauldoohehe, so are multimethods vars?
16:12fliebelpauldoo: No but you keep them in vars, right?
16:12amalloypauldoo: no, but neither are functions. the names you def them with are vars
16:12pauldooright ok.. :)
16:13pauldooI'm new to clojure, I only create multimethods using defmulti
16:13pauldoohaven't encountered creating multimethod values (without defmulti)
16:14hircuspauldoo: think of generic functions as abstract method on steroid
16:14fliebelComing to think of it, there isn't just multi, is there? or let-multi ;)
16:14pauldoofliebel: that'll be why I haven't encountered them perhaps..
16:15amalloypauldoo: i've never tried it either, and it might not be possible, but it doesn't matter. just about every def wraps a var around a value
16:15pauldooamalloy: yes, indeed
16:15hircusamalloy: what you're calling "var" is probably what we call an identifier. "var" in clojure is something specific
16:15amalloythere is a function that gets all the multifn objects associated with a defmulti
16:15amalloyhircus: i'm well aware. i'm talking about vars
16:15amalloy&(class #'first)
16:15sexpbot⟹ clojure.lang.Var
16:16hircusah, yes
16:17tonylwhat is the difference between a var and a symbol?
16:17amalloytonyl: vars are a ref type
16:17tonylit might be something obvious, but I'm fairly new to lisp
16:17hircustonyl: a variable is bound to some value. a symbol is just a unique identifier
16:17amalloy&(deref #'first)
16:17sexpbot⟹ #<core$first clojure.core$first@36f7e6>
16:18tonylso the var (ref) can be rebinded
16:19tonylbut not a symbol
16:19hiredmana ref is not a var
16:19hiredmanby ref amalloy meant reference
16:19hiredmannot (ref ...)
16:19tonylok
16:19amalloyright, thanks hiredman
16:19tonylnot clojure's ref
16:19tonylthanks
16:19hircusa var can be rebinded with set! but that's discouraged in functional programming :)
16:20amalloy&(map class [#'first (ref first)])
16:20sexpbot⟹ (clojure.lang.Var clojure.lang.Ref)
16:20tonylwhat about with (binding ...)
16:20hircusbinding shadows the values bound to the variables
16:21tonylok
16:21hircussay you want to replace the function "first" with one that shouts out whenever it's called
16:21hircus(binding [first my-tracing-first] some-exp-that-uses-first)
16:21tonylso it doesn't change the values and changes them back
16:21hircusactually, dotrace in clojure.contrib.trace does that for you
16:21hircusthe changes happen only in the local scope
16:22tonylok
16:22hircusbut it does break the otherwise static scoping
16:22hircusone sec
16:23hircusso let's say I bind x to 42 -- (def x 42)
16:23tonylok
16:23hircusand then define a function that just returns this value. (defn foo [] x)
16:24hircusyou'd think this always returns 42, but now (binding [x 7] (foo)) => 7
16:24hircusbut outside the binding, (foo) => 42
16:25tonylthanks for the explanation
16:26hircusno prob :)
17:26Zeiris_What does Clojure/Lisp use to organize and structure code at a high level, higher than functions?
17:26Zeiris_I mean, Java uses objects. C has files/compilation units. Does Clojure also rely on files?
17:27tonylyou mean sequences
17:27tonylmaybe?
17:28tonylor list in lisp
17:28LauJensenZeiris_: primarily namespaces
17:29greghjava has files, too, which don't always map 1-1 with objects
17:29greghand clojure stores source code in files. :)
17:29Zeiris_Yeah, I should've said "classes". I think those map 1-1?
17:30greghyou can put more than one class declaration in a java source file
17:39dakronedefn: ping
17:44alpheusCan namespaces mutually require one another?
17:55technomancyalpheus: there are ways to make it work, but it's almost never worth the trouble
17:57dakronehey technomancy, can you delete a jar on clojars for me? I accidentaly renamed something incorrectly
17:58technomancydakrone: I'll take a look. I'm not sure quite how to but I can try.
17:58technomancywhat's the name?
17:58dakronetechnomancy: sent pm
18:02alpheustechnomancy: thought that was the case. Thanks.
18:02amalloygregh: java quite often winds up with more than one class per source file
18:04amalloybut clojure's main organizational unit is, as mentioned earlier, the namespace. these do have a 1-1 correspondence with files in practice, though (i think? technomancy?) it's possible to break that rule
18:04greghyes, particularly with inner classes
18:04amalloygregh: yep, exactly
18:05hiredmanclojure allows you group functions into protocols
18:07slyrusanyone know where the clojure dependency for clojure-contrib is specified?
18:07stuartsierraslyrus: in clojure-contrib/modules/parent/pom.xml
18:08slyrusah, parent... thanks stuartsierra!
18:08stuartsierrawelcome
18:09slyrusso why does current clojure-contrib get built with 1.3.0-SNAPSHOT not 1.3.0-alpha3-SNAPSHOT?
18:10slyrus(besides the obvious answer "because that's what parent/pom.xml says!")
18:11slyrusOr should I say: what's the rationale behind commit 6711b9e03f415d744594ce2a8faed48f9a2bc882?
18:11slyrusnot that I have a problem with it, it just seems odd to reset the dependency here when the clojure HEAD is still on 1.3.0-alpha3
18:13stuartsierraI think the clojure HEAD just hasn't been updated
18:13stuartsierrathat's probably a mistake
18:14slyrusah, OK, that makes sense
18:14slyrusit's a bummer that that commit requires so many lines!
18:15stuartsierrayeah, another reason for phasing out the multi-module contrib; release versions are too hard
18:16slyrusoh... I didn't quite get that you were phasing it out...
18:16slyrusguess I won't spend to much time having my stuff try to deal with the multi-module version then.
18:17stuartsierrawell, it will probably hang around for a while
18:17stuartsierrabut new contrib libs are getting their own repositories
18:17slyrusand the old ones?
18:22stuartsierradunno, don't have a plan for those yet
18:23stuartsierraProbably take the most popular ones and give them their own repos
18:23stuartsierraleave the rest in a "legacy" repo
18:28slyrusokey dokey
18:28slyruswould be nice to see it stabilize
18:32slyrusOk, so when I build clojure, everything looks good (the jars) and I get a pom.xml, but when I mvn install, I get empty jars in .m2/repository
18:35stuartsierrayeah, mvn install in Clojure doesn't work
18:35stuartsierraYou have to use Ant
18:36stuartsierraFirst download maven-ant-tasks.jar
18:36stuartsierraThen run ant -lib /path/to/maven-ant-tasks.jar ci-build
18:37stuartsierraOr try my branch with a proper Maven build: https://github.com/stuartsierra/clojure/tree/rebuild
18:37stuartsierraActually, don't try that until we get the parent POMs into central
18:38stuartsierrawhich we will in a few more days probably.
18:42slyruswhat's central?
18:43slyrusand I see your branch removes ant building support :( I was hoping that I could do ant ; mvn install and the right thing would happen. I guess not.
18:43clojurebotmost horrible thing is http://tinyurl.com/b65o8e
18:49stuartsierraslyrus: I might add back a simplified build.xml
18:49stuartsierrafor now just working on getting the Maven build to work so we can do faster releases
18:50stuartsierra"central" means Maven central, the default repository for the Maven / Ivy toolchain
18:52stuartsierraRight now, to build my branch, you first need to install the parent "pom.baseline" project locally.
19:42quizme(interleave [:a :b] [1 2]) gets turned into lists. How do I keep them as vectors? or should I just give in and use lists instead of vectors?
19:43quizmeand if i pass that result into partition, i get more sequences. I kinda feel like i'm fighting an uphill battle.
19:43tonylwith into
19:43jk_(vec (interleave [:a :b] [1 2])) ?
19:44quizmeoh
19:44quizmelemme try that
19:45jk_,(vec (interleave [:a :b] [1 2]))
19:45clojurebot[:a 1 :b 2]
19:45quizmejk_ (vec (partition 2 (vec (interleave [:a :b] [1 2]) )))
19:45jk_,(vec (partition 2 (vec (interleave [:a :b] [1 2]) )))
19:45clojurebot[(:a 1) (:b 2)]
19:46tonylyou dont need the double vec
19:46tonyl,(vec (partition 2 (interleave [:a :b] [1 2])))
19:46clojurebot[(:a 1) (:b 2)]
19:46quizmetonyl i want (:a 1) to be [:a 1]
19:47tonyloh mm..
19:47jk_,(map vec (partition 2 (interleave [:a :b] [1 2])))
19:47clojurebot([:a 1] [:b 2])
19:47MayDaniel,(map vector [:a :b] [1 2])
19:47clojurebot([:a 1] [:b 2])
19:49quizme(vec (map vector [:a :b] [1 2]))
19:49quizmei think that's what i want
19:50quizmebut again, should i just go with the flow and use lists ?
19:51quizmeit feels like i'm saying "really, I really want a vector, not joking.... yeah and keep that one as a vector too. Oh yeah, and that one."
19:51jk_do you, in fact, really want a vector? does it matter? like you want to add to it at the end efficiently or something?
19:52quizmejk_ that's what i'm wondering...
19:52tonylthey are not lists but map returns a seq, lazy seq specifically
19:53quizmeso it seems like i should just use lists unless I want specific performance guarantees...
19:57quizme(clojure.test/is (= [1 2] '(1 2)))
19:57quizmetrue
19:57quizmethat's kind of interesting
20:00_fogus_quizme: why?
20:01quizme_fogus_ cuz it's ignoring the type.
20:02_fogus_quizme: But it's not ignoring the equality partition.
20:02quizme_fogus_ and vectors aren't sequences from what i heard.
20:02quizme"partition" ?
20:05_fogus_quizme: so clojure determines equality along a number of "partitions" sequential, maps, and sets
20:06quizmeohh
20:06quizme (is (= #{1 2} [1 2 ])) ; => false
20:06_fogus_quizme: try it
20:07quizme,(is (= #{1 2} [1 2 ]))
20:07clojurebotjava.lang.Exception: Unable to resolve symbol: is in this context
20:07quizme,(test.clojure/is (= #{1 2} [1 2 ]))
20:07clojurebotjava.lang.ClassNotFoundException: test.clojure
20:07tonyl,(= #{1 2} [1 2])
20:07quizmeoops
20:07clojurebotfalse
20:09_fogus_,(= '(1 2 3) (doto (java.util.ArrayList.) (.add 1) (.add 2) (.add 3)))
20:09clojurebottrue
20:09_fogus_quizme: So you can see that other things also fall into the sequential partition
20:10quizme_fogus_ got it, thanks.
20:11quizme_fogus_ haven't read your book yet. ...
20:11_fogus_quizme: One final thing. Be very careful how you use predicates like seq? and sequential? as they are leaky abstractions
20:12quizmeleaky?
20:12_fogus_quizme: No worries. Hopefully you will one day. We devote a lot of space to this stuff. :-)
20:13quizme_fogus_ it's sitting on my computer, waiting for me.
20:14_fogus_Well in this specific case check out section 5.1 (I think -- the title is "Persistence, Sequences, and Complexity")
21:05amalloy&(identical? [:a] [:a])
21:05sexpbot⟹ false
21:05tonylthey are not the same object
21:07tonyl&(let [a [:a] b a] (identical? a b))
21:07sexpbot⟹ true
21:13tonyl"If init is supplied, it is evaluated, and the root binding of the var is set to the resulting value. If init is not supplied, the root binding of the var is unaffected"
21:13tonylwhat does this exactly mean in special_forms?
21:13tonylthe evaluated value of init in the metadata is the value for the var?
21:14amalloytonyl: (def x) vs (def x 1)
21:14tonyloh *facepalm* i didn't see the init? in the args
21:16tonylI see (def x) is virtually the same as (declare x)
21:36sproustHaving soem trouble with Leiningen tonight. The latest clojure is "1.3.0-master" isn't it?
21:40hiredman1.3 has not been released
21:40dysingeryay
21:40dysingeroh lol I thought you just sad HAD been released
21:40dysingers/sad/said
21:40sexpbot<dysinger> oh lol I thought you just said HAD been released
21:41sproustIs there a convenient way to use both Leiningen and a locally built Clojure? I find myself going back to the good old manual "create a makefile" approach way too often.
21:45dysingerYou can build clojure and install it into your local maven repo
21:45dysingerIt's been a long time since I've done that
21:45chouserI do it constantly
21:45dysinger:)
21:45dysinger^ there's your man
21:46chouserant -lib /your/path/to/maven-ant-tasks-2.1.1.jar ci-build
21:46dysingeror just put maven-ant-tasks jar in ~/.ant/lib/
21:48chouserthen when you refer to whatever version it built, lein will hopefully pull it from your local repo
21:49chousersproust: that's all for you ^^^
21:49sproustThanks Chouser.
21:49sproustI'm not sure I get everything, lots of Java-related lingo.
21:50sproustI don't havea "maven-ant-tasks" jar. Do I need one?
21:50sproustSo far the best approach has been to make my list of jars by hand and start clojure this way.
21:50sproustOR, just to use Leiningen.
21:51chousersproust: I can't speak to "best", I just do what I'm told.
21:51sproustBut now I want the bleeding edge Clojure, and with the Contrib all split up, I'll have a ton of libs to specify. Thinking about writing a stupid Python script to do it for me.
21:51sproustHmm, I meant "best thing that works for me without wasting a lot of time."
21:51chousersproust: if you're not making changes yourself, you should be able to use an alpha release of clojure and be pretty close to the bleeding edge
21:52chousermaking changes to clojure itself, I mean
21:52sproustWhat do I tell Leningen for its version number?
21:52sproustI tried 1.3.0-master, wouldn't work.
21:52sproustWhere do I find out what the allowable version strings are?
21:52chousertry 1.3.0-alpha3
21:52sproustThanks. That's the fish, mium. Now can you teach me how to fish for that number?
21:53chouserI can try
21:53sproustPlease :-)
21:54sproustSorry man, don't mean to give you a hard time :-) It's one of those nights where I finally get a few hours of life back to me so I can get back into hacking LISP and I find myself fixing how to launch my Clojure again instead of hacking code. Just a bit frazzled.
21:56sproust1.3.0-alpha3 works for Clojure; the Contrib libraries have changed now, have they? Do I have to specify each of them as a separate dependency in project.clj?
21:57chouserno, it's fine, I just don't actually know
21:57chouserthere's got to be some list of artifacts somewhere, but I don't know where
21:58chouserah, here you go: http://clojure.org/downloads
21:58sproustchouser: How do you use the new contrib libraries then?
21:58sproustI meant _you_.
21:58chouserum
21:59chouserI'm not sure I do
22:00chousereach one should have it's own "coordinate", name and version number
22:11sproustchouser: thanks.
22:31SirNickIs it valid to have a ref nested somewhere inside a structure of another ref? Say (ref x) where x references some hash map with refs in it or something. From the clojure refs page it seems this is not recommended or doesn't work. Is that correct?
22:33amalloySirNick: well...it certainly works, but i wouldn't often recommended it
22:33SirNickamalloy: Why's that?
22:34amalloyusually the system you're modeling can be modeled just fine with only one layer of indirection, and it's easier to manage with less immutability
22:34amalloyer, mutability
22:36SirNickamalloy: Hmm I see, but what about if you wanted to make something like a mutable tree that needs atomic actions preformed on it?
22:37amalloySirNick: then you definitely want only one reference-type thing involved. operate on a snapshot of the whole tree to create a new whole tree - no need to futz around with branches
22:38SirNickamalloy: Ah I see, makes sense. But you are saying that there is nothing about refs that would stop that from functioning correctly?
22:38amalloya ref is just an object like any other: an immutable pointer to an object
22:39SirNickamalloy: Alright thanks, I was just confused by this statement on the refs page: "The values placed in Refs must be, or be considered, immutable!! Otherwise, Clojure can't help you."
22:39amalloyaha
22:39amalloyhe means, don't put a java.util.HashMap in a ref
22:40SirNickAh yea I thought that's what he might of meant but I wasn't sure. Thanks
23:25quizmehttp://pastie.org/1296341 <-- is there a more elegant way to do this?
23:28quizmei'm just trying to just conj onto a deeply indexed hash.
23:32amalloy&(update-in {:a {:b {:c 1}}} [:a :b :c] conj 10)
23:32sexpbotjava.lang.ClassCastException: java.lang.Integer cannot be cast to clojure.lang.IPersistentCollection
23:33amalloy(doc conj)
23:33clojurebot"([coll x] [coll x & xs]); conj[oin]. Returns a new collection with the xs 'added'. (conj nil item) returns (item). The 'addition' may happen at different 'places' depending on the concrete type."
23:33amalloy&(update-in {:a {:b {:c [1]}}} [:a :b :c] conj 10)
23:33sexpbot⟹ {:a {:b {:c [1 10]}}}
23:33amalloyor assoc-in if you want to add elements to the list itself
23:33amalloyer, the hash
23:34amalloy&(assoc-in {:a {:b {:c {}}}} [:a :b :c] :d 1)
23:34sexpbotjava.lang.IllegalArgumentException: Wrong number of args (4) passed to: core$assoc-in
23:34amalloy&(assoc-in {:a {:b {:c {}}}} [:a :b :c :d] 1)
23:34sexpbot⟹ {:a {:b {:c {:d 1}}}}
23:35quizmeamaloy: thanks !
23:38amalloyquizme: and you don't actually have to have the whole structure to start with: ##(assoc-in nil [:a :b :c :d] 1)
23:38sexpbot⟹ {:a {:b {:c {:d 1}}}}