#clojure logs

2010-10-09

00:02TeXnomancyscottj: nice work with clojars
00:03TeXnomancyI kinda thought alex wasn't accepting patches, being MIA or something
00:03TeXnomancykotarak submitted some fixes that didn't seem to go anywhere
00:08scottjTeXnomancy: he said he's been really busy
00:09scottjI made sure he was willing and able to merge the changes before I started working on them
00:11scottjhe's also just provided better docs and a dump of the db for running and testing locally
00:13scottjTeXnomancy: actually you were the reason I made those changes :) with multiple ppl committing to swank-clojure I was getting upset not knowing if you'd pushed them to clojars
00:19TeXnomancycools
00:20TeXnomancymaking it easier to run/test clojars locally is really important for getting contributors, I'm glad it works better now
00:20TeXnomancyjust added you to the swank clojars group
00:21TeXnomancyoh... I can run a local clojars for my conj talk and demo scp uploads without needing a network connection... slick.
00:25TeXnomancywe really need to get clojars on a server where others can help admin it though
00:28scottjthere's a mailing list (1 member) and a maintainers list mentioned on the clojars-web repo readme so he's probably moving that way just waiting for someone to volunteer
00:28TeXnomancyactually four people have volunteered
00:29TeXnomancyhe just hasn't given anyone access yet because it's still on a shared server that he's not the owner of
00:29TeXnomancygotta get things moved over to the VPS at new.clojars.org
00:31scottjahh
00:56TeXnomancythe similarities between John Rose's "larval" ideas and Rich's pods are pretty striking: http://blogs.sun.com/jrose/entry/larval_objects_in_the_vm
00:56TeXnomancyVM-level support for podlike behaviour would be great
02:08slyrus_TeXnomancy: what do you mean by VM-level support for podlike behavior?
02:29amalloyslyrus_: did you read the article? i don't know a lot about pods, but larva seem like useful thing for clojure to have
03:00amalloymorning ohpauleez
03:01ohpauleezevening for me
03:01ohpauleezJust wrapped up a small host party
03:01ohpauleezhouse*
03:01amalloyfwiw i decided not to use clojure-hadoop, at least not yet. it looked a lot harder to modify it to read input from cassandra than it would be to adjust cassandra/contrib/wordcount to do the processing i need to do
03:01ohpauleeznonetheless, morning amalloy
03:02amalloyheh, well, evening for me too. but you just signed on, it's morning!
03:02ohpauleezI've had pretty good experiences with cassandra
03:02ohpauleezI have a high performance wrapper on my github
03:03tomojooohh
03:03ohpauleezBut I think I need to push the final working project
03:03tomojwhat's your github account name?
03:03ohpauleezI'll check in about 8-10 hours
03:03tomojI have been greedily eyeing cassandra
03:03ohpauleezI believe ohPauleez, full name will be Paul deGrandis
03:03ohpauleezit has some weird long term running behaviors
03:04ohpauleezbut for a simple key value store that scales with writes
03:04ohpauleezit's an awesome choice
03:04ohpauleezMongo is real nice too, the company I work with is pushing forward with mongo. And the old company I built uses it for things
03:05amalloyi looked at cassandra-wrapper on github, but it didn't look very good. that one's not yours, is it?
03:06ohpauleeznope
03:06ohpauleezcassaforte is mine
03:07ohpauleezI just checked, I need to push the final code, it's currently just a bunch of random hacks
03:07ohpauleezbut I've had issues with clj and cassandra, and ended up using the Thrift java wrapped
03:08ohpauleezwhich is what led me to generalize and make cassaforte
03:09amalloyhmm. well, when i get finished with the "what the hell is hadoop" experimentation phase, i'll give cassandraforte a closer look
03:10ohpauleezif you have a map reduce problem, hadoop is a bunch of fun
03:11amalloyyeah, we're just chewing through a large set of logs to generate aggregate data for the existing SQL code
03:11amalloyposter child for hadoop and cassandra both
03:12carkhso you managed to reach the "scaling limit" of sql ?
03:12carkhor is it just for learning ?
03:13amalloycarkh: well, i joined the company a few months ago, and while we could scale sql for another year or two if we had to and could spare the money...
03:13carkhwhat database engine were you using ?
03:13carkh(if i may ask)
03:14amalloyummmm, myisam in production, i think, and maybe transitioning to innodb
03:14amalloy(on mysql)
03:14carkhright
03:14carkhdamn you must be processing an awefull lot of transactions
03:15ohpauleezcarkh: I have scaled out MySQL and Postgres in HUGE deployments. The truth is, if you're facing a system that has a scaling problem and doesn't require certain needs, mongo or something similar is nice
03:15ohpauleezif you have to number crunch or build a search index on something huge
03:16ohpauleezhadoop is a gem
03:16amalloycarkh: ~100k per hour, i think? 400k at super-peak times
03:17ohpauleezreally just tools in a tool box
03:17ohpauleezjust like RBDMSs
03:17carkhi'm not doubting your needs ... I just personally never needed anything more than sharding, but that's only me
03:18ohpauleezwhatever fits the problem space
03:18amalloycarkh: oh, i'm sure we could shard too, but since we're keeping a bunch of unrelational data, cassandra is better-suited
03:18ohpauleezcarkh: Depending how those transactions happen, and how you grow, "just sharding" can be hard, even with mysql
03:19ohpauleezI'm not a nosql fanboy, very much the opposite
03:19ohpauleezbut I have ran into scenarios where it fit nicely into the solution space
03:20carkhso, cassandra or haddoop ?
03:20amalloyboth
03:20amalloycassandra for storage, hadoop for processing
03:20carkhand how many computers are participating in your "cluster" ?
03:20ohpauleezamalloy: if you're not extremely write heavy, I would caution with cassandra. But do some tests and look at the numbers
03:21amalloycarkh: not sure yet - it's still in the development phase, and i imagine we'll do performance testing to see how many nodes we need
03:22ohpauleezfor sure
03:22ohpauleezamalloy: ping me if you need any help or insight. More than happy to pass along tips
03:22amalloythanks ohpauleez
03:22carkhwell, good luck on your projects, seems interesting
03:23amalloyi know you have experience with hadoop and cassandra; have you used them together? that's what i'm currently stumbling on
03:25ohpauleezI haven't used them both directly together
03:25ohpauleezI used one for a stats reporting, and I fed that to another data store that later fed into hadoop for BI and number crunching
03:45notsonerdysunnyI keep getting ... "/home/sunil/bin/cake:307: warning: Insecure world writable dir /media/disk/user in PATH, mode 040777" is there a way to disable this?
03:47amalloynotsonerdysunny: take that directory off your PATH...? it's a warning because anyone could put a malicious program named, for example, ls into that directory, and when you typed ls it would run that program with all your permissions
03:48notsonerdysunnyhmm.. I realize that .. but is there a way to suppress it...
03:49notsonerdysunnyI am the only user of this computer...
03:49amalloywhat's in that directory that you want to be able to execute?
03:49notsonerdysunnyk .. I guess I will remove it from path
03:50amalloyor chmod o-w /media/disk/user
03:52amalloyer, a-w? something like that
03:52fhdHi. Is there a pair datatype in Clojure? In Emacs Lisp I could use (1 . 2) or (cons 1 2), doesn't work in Clojure.
03:53amalloy,(vector 1 2)
03:53clojurebot[1 2]
03:53amalloy,[1 2]
03:53clojurebot[1 2]
03:53fhdclojurebot: That's not exactly a pair, is it?
03:53clojurebotIt's greek to me.
03:53fhdclojurebot: I mean, this would be possible: [1 2 3 4]
03:53clojurebotTitim gan éirí ort.
03:53amalloylol, i'm not clojurebot
03:54fhdoh, reading helps :)
03:54fhdamalloy: is that the way to use pairs in Clojure?
03:54fhdamalloy: I've seen the intimidating syntax necessary to create a cons...
03:55amalloyfhd: usually, if you want to return a group of data, you can return a hashmap, or a list, or a vector. i don't think there's much need for an explicit pair
03:55fhdamalloy: Wouldn't hurt I guess, just got used to it. Would a list or a vector be better then?
03:55hiredmanif you want pairs you can create a pair protocol and extend it to vectors, hashmaps, lists, and seqs
03:56fhdhiredman: I'd rather go with the existing language features for the simple stuff I'm doing ATM.
03:56amalloy,(cons 1 [2]) ; if you like the reassuring cons syntax :)
03:56clojurebot(1 2)
03:57_atofhd: to answer your question directly, no there's no pairs
03:57kumarshantanu,(doc cons)
03:57clojurebot"([x seq]); Returns a new seq where x is the first element and seq is the rest."
03:57amalloyfhd: i think it depends on what you want. if your pair represents two different things, maybe you want a map
03:58fhdI wouldn't use that weird syntax. (1 . 2) is okay, but I find even (cons 1 2) too long, so I'll probably go with [1 2]
03:58amalloy,(let [pair {:x 10, :y 11}] (pair :x))
03:58clojurebot10
03:58fhd,(* 2 10)
03:58clojurebot20
03:58fhdI see.
03:59hiredman(cons 1 2) won't even work
04:00amalloyhiredman: it will in CL, which he was saying he finds too long
04:00fhdhiredman: Yeah, that's the problem. One has to create a seq or something, I'll pass.
04:00hiredmanin clojure cons doesn't not create a "cons cell" it only adds an element to the start of seq
04:00amalloyit's been a while since i wrote CL; is (1 . 2) actually legal? it seems like the reader ought to try to evaluate 1 as a function
04:00fhdamalloy: I know that from Emacs Lisp to be honest, never did much CL.
04:01fhdamalloy: That's true, I always found it a bit weird too.
04:01amalloyfhd: well, there you go! an excuse to get away from inconsistent syntax :)
04:02kryftHow is clojure for shell scripting, btw?
04:02fhdamalloy: Yeah. BTW, it has to be quoted, so it's kinda legal '(1 . 2)
04:02amalloyah
04:02amalloy,'(1 2)
04:02clojurebot(1 2)
04:03fhd,'(1 . 2)
04:03clojurebot(1 . 2)
04:03fhdHM.
04:03amalloyfhd: that's a list with three elements
04:03amalloy,(count '(1 . 2))
04:03clojurebot3
04:03fhdamalloy: Ah, lol :)
04:04fhdI'll just go with a vector I guess, nicest syntax.
04:04amalloythe vector syntax is convenient for longer lists too, since you don't have to quote the whole list to avoid calling it
04:05amalloy,(let [a 10] ['f a 'a])
04:05clojurebot[f 10 a]
04:05_atokryft: Clojure is terrible for shell scripting, the JVM is really unsuited to that sort of thing due both to startup time and the lack of unixy IO functions (no way to create a symlink for example, at least until JDK 7 is released).
04:06_atoat least if you mean actuing like a traditional shell anyway ;-)
04:09amalloyanyway good luck fhd. i'm often around if you want some more unhelpful answers, but for now i'm off to bed
04:09fhdamalloy: Yeah, thanks!
04:09fhdI'll have to continue working, so I'm off as well :)
04:11kryft_ato: Actually I guess 'shell scripting' was a bit misleading; I was thinking of stuff that I'd normally do with a python script (as opposed to stuff that I'd do with a bash script)
04:16kryft_ato: I typically use python for mangling data (machine learning research); the scripts often do require some IO (writing files and maybe creating symlinks) once the mangling is done.
04:17hiredmanthe jvm is generally not so good for short running processes, the startup time being prohibitive
04:19_atoI tend to use Pythoon/Ruby/Perl for quick-running stuff, or stuff that needs to do unixy things (fork, posix IO etc). For longer running text processing (like parsing log files and generating stats) I'll use Clojure
04:20_atoit depends though, often I just run things out of an emacs buffer so there's no startup time there. But it's not so easy to pipe into other commands and that sort of thing
04:40lypanov_ato / hiredman: whats wrong with using cake or nailgun to solve the startup time issue?
04:41quizmehttp://pastie.org/1209316 <--- :~(
04:41quizme*sniff*
04:41quizmeis there a function version of and?
04:41quizmelogical and
04:42quizmeand in general what do you do if you want to use a macro in apply?
04:42quizmewrite a function version of the macro?
04:56sandGorgonI was looking at the alioth shootout between F# Mono and Clojure - CPU performance quite similar... but F#/Mono uses drastically less memory : in some cases 61X less memory!
04:56sandGorgonhttp://shootout.alioth.debian.org/u32q/benchmark.php?test=all&amp;lang=fsharp&amp;lang2=clojure
05:07lypanovsandGorgon: clojure on mono or jvm?
05:08sandGorgonlypanov, I think it is the jvm clojure that alioth uses. Is the clojure-on-clojure work done ? because I guess that would be the precursor to clojure being implemented on a lot of backends
05:09lypanovsandGorgon: could just be that sun/oracle suck. :) ;)
05:55quizmehow do you do this? (apply and '(true true false))
05:57mrBliss,(every? identity '(true true false))
05:57clojurebotfalse
05:57mrBlissquizme: you can't apply macros
05:57jarpiainis there a function that returns a seq on a sorted-map starting from a given key?
05:58mrBlissjarpiain: you could use (drop-while #(not= % the-key) the-sorted-map)
05:58jarpiainmrBliss: but that takes O(n) to find the key
05:59mrBlissyou're right
05:59quizmemrBliss is there a way to turn a macro into a function so that it can be applied?
06:00quizmeor does that not make sense ?
06:00mrBlissquizme: rewriting the macro as a function ;-)
06:00_ato,(subseq (sorted-map 1 :a 2 :b 3 :c 4 :d) > 2)
06:00clojurebot([3 :c] [4 :d])
06:00_atojarpiain: ^
06:00mrBlissquizme: when you want to apply a macro, you don't have enough information at compile time
06:01quizmemrbliss right...
06:01_atoquizme: http://richhickey.github.com/clojure-contrib/apply-macro-api.html :p
06:02mrBlissbut remember:^^ "This is evil. Don't ever use it."
06:04jarpiain_ato: thanks, somehow missed that
08:09madahi all!
08:12madaI am building a small recipe database and have a question. In Clojure, if I want to loop over all the ingrediences in a number of recipies and summarize the ammount of each, assuming each recpipe is just a list/seq on the form (name number measure), what would be the standard way to do it? In elisp or other more imperative lisp I would just define a list variable with let and then increase each unique ingredient, but
08:12mada in Clojure things are immutable (apart from defs) so how would it work there?
08:13carkhyou might use reduce
08:14madacarkh: k, will look that up
08:14carkh(let [summary (reduce add-receip-list-to-map-result {} receipes)] (print-summary summary))
08:14jaleymada: map the collection of recipes to a collection of amounts, then reduce with +
08:25jaleyis there a function to break a map into a collection of [key value] vectors? i'm using (for [[k v] m] [k v]) right now, just wondering if it's necessary?
08:26mrBliss,(seq {:a 1, :b 2})
08:26clojurebot([:a 1] [:b 2])
08:26jaleymrBliss: that's better - thanks!
08:43LLLLLhey guys
08:44LLLLLwhere do I read about ~' in macros, how does it work
08:44LLLLLseems to me like it doesn't do anything
08:46mrBliss,(let [x 1] `(x))
08:46clojurebot(sandbox/x)
08:46mrBliss,(let [x 1] `(~x))
08:46clojurebot(1)
08:46mrBlisscan you see what ~ does? It evaluates x
08:47LLLLLit wasn't what I was looking for
08:47LLLLLfor instance you have a long macro `( some code blah blah then ~'something)
08:48LLLLL,(let [x 1] `(~'x))
08:48clojurebot(x)
08:48LLLLLlike this
08:48mrBlisssorry, I didn't read it well enough
08:49mrBliss,(let [x 1] `(x))
08:49clojurebot(sandbox/x)
08:49mrBlissthe sandbox/ is the difference
08:49LLLLLI can see it lacks namespace, but I'm unsure what that's used for
08:49carkhit allows you to capture the symbol name in order to make it available to your macro user
08:50mrBlissif the x you want is in another namespace. I'll try to come up with a good example
08:52LLLLLi get it now
08:52LLLLLthx
09:25jaley(doc min)
09:25clojurebot"([x] [x y] [x y & more]); Returns the least of the nums."
11:15neotykHi Clojurians
11:15neotykanyone here using org-mode?
11:15abrenkyeah
11:16neotykI'm trying to get second Wed of every month into my agenda <%%(diary-float t 3 2)>
11:16abrenkneotyk: sorry, that's more than I ever wanted
11:16neotykwhy it doesn't appear in agenda view
11:16neotyk:(
11:16neotyk#org-mode is silent
11:17neotykgoogle doesn't know
11:17neotyksource code will talk to me
11:17phaerneotyk: It works for me. Maybe you missed some settings in your agenda file? the org mode mailinglist is much more responsive than the irc channel
11:18neotykagenda file?
11:18neotykI generate agenda from org file
11:22phaerneotyk: Ah sorry, i was talking about the agenda settings in your .emacs[.d] like "agenda-files".
11:30neotykphaer: I do C-c a L
11:35phaerneotyk: Don't you have an org-agenda-file setting in your .emacs? I have one which includes serveral org files. And i've got a binding of "org-agenda-list" to f2. And if i press f2 i see all my tasks including the repeating one for which i use <%%(diary-float t 6 1)> etc.
11:39neotykphaer: no org-agenda-file
11:39neotyklet me create one
11:46Guest74051How can I turn ((("banana" 3) ("apple" 2)), (("banana" 1) ("apple" 4) ("orange" 2))) into (("banana" 4) ("apple" 6) ("orange" 2))?
11:48raek,(merge-with + {:banana 3, :apple 2} {:banana 1, :apple 4, :orage 2}) ; a slightly different variant
11:48clojurebot{:orage 2, :banana 4, :apple 6}
11:50raekmada: normally the map data structure is used. there are many useful functions for them.
11:52raekI happened to use keywords as keys here, but you can use strings (or anything, actually) for keys if you like
11:53neotykphaer: with org-agenda-files it works
11:53neotykphaer: thank you
11:53neotyk+1 phaer
11:54madaraek: I plan to get the input as strings from a user, won't that be a problem?
11:54madaraek: sorry, I see now what you added :)
11:54raekthen strings would be fine
11:54madagreat
11:54madaraek: and I assume I can convert a list of pairs like this into a map easily?
11:56jarpiain,(into {} '(("banana" 3) ("apple 2")))
11:56clojurebotjava.lang.ClassCastException: java.lang.String cannot be cast to java.util.Map$Entry
11:58raek,(into {} (map (fn [[k v]] [k v]) '(("banana" 3) ("apple" 2))))
11:58clojurebot{"banana" 3, "apple" 2}
11:59jkkramer,(into {} '(("banana" 3) ("apple" 2))) ;misplaced quote
11:59clojurebotjava.lang.ClassCastException: java.lang.String cannot be cast to java.util.Map$Entry
11:59jkkramerok guess not
11:59raek,(into {} (map vec '(("banana" 3) ("apple" 2))))
11:59clojurebot{"banana" 3, "apple" 2}
12:00madaraek: excellent! thanks!
12:00raekthe thing conjed to a map has to be a MapEntry or a IPersistentVector of size 2
12:01jkkramerthe norm is to keep data in vectors rather than lists
12:02jkkramer,(into {} [["banana" 3] ["apple" 2]])
12:02clojurebot{"banana" 3, "apple" 2}
12:02madajkkramer: I see, a bit different than what I am used to but I guess it works as well.
12:03madajkkramer: does a vector have any major disadvantages compared to a list for simple things like this?
12:03jkkramermada: nope
12:04raekit is ideomatic to use vectors for literals for sequential things
12:04jkkramerlists are normally only used for code forms and special circumstances
12:05raek,(seq {"banana" 3, "apple" 2}) ; you can go the other way around too
12:05clojurebot(["banana" 3] ["apple" 2])
12:07madak, thanks both of you!
12:07phaerneotyk: np :)
12:30LLLLLis there any good clojure API list like java has javadoc of whole Java 5 Api
12:30LLLLLjust to see what functions are out there and what do they do
12:30MayDanielclojure.github.com/clojure ?
12:30LLLLLsince I keep finding myself programming functions just to find out they already exist
12:31raekhttp://clojuredocs.org/Clojure%20Core and http://clojuredocs.org/Clojure%20Contrib
12:31kumarshantanuLLLLL: you may try (1) (doc form), (2) ClojureDocs or (3) Autodoc
12:31LLLLLok
12:31raekand http://clojuredocs.org/quickref/Clojure%20Core
12:32raek(by category)
12:32raekand this http://faustus.webatu.com/clj-quick-ref.html
12:32raek:-)
12:32kumarshantanuor perhaps this cheatsheet -- http://clojure.org/cheatsheet
12:33LLLLLthanks a lot
12:37LLLLLhm I seem to be missing a lot of namespaces
12:37ohpauleezLLLLL: What do you mean?
12:38raeksome of the clojure.* namespaces was added in 1.2
12:38LLLLLwell I can't find clojure.inspector
12:38LLLLLwhich is 1.0 I believe?
12:39LLLLLsays it can't find inspect function
12:39raekhow do you access things in them?
12:39LLLLL(ns test (:require clojure.inspector))
12:39LLLLL(inspect some-thing)
12:39raekLLLLL: use use in that case :)
12:39KirinDaveYou know, something that I've been wondering...
12:40KirinDaveis it possible in an ns declaration to alias a namespace with only 1 path component?
12:40LLLLLwhat's the difference?
12:40KirinDavelike let's say
12:40raekwith require, it is (clojure.inspector/inspect some-thing)
12:40KirinDave(alias e 'example1)
12:40raekor (ns test (:require [clojure.inspector :as ins])) (ins/inspect some-thing)
12:40LLLLLworks now thanks
12:40ohpauleezLLLLL: or you can use the ns qualifer. (ns test (:require clojure.inspector :as inspector))(inspector/inspect some-thing)
12:40raek(ns test (:use clojure.inspector)) (inspect some-thing)
12:41LLLLLthe thing that worries me is if I write just
12:41LLLLLclojure.
12:41LLLLLand hit autocompletel
12:41raek(ns test (:use [clojure.inspector :only (inspect)])) (inspect some-thing)
12:41LLLLLit offers me very few namespaces
12:41KirinDaveLLLLL: How many?
12:41KirinDaveLLLLL: Should be just a handful.
12:42raekLLLLL: could e because they haven't been loaded. after a require or use, they should appear
12:42LLLLLshows me 10
12:42raekohpauleez: you need to have a vector there, right?
12:42ohpauleezyes
12:43ohpauleezI messed it up
12:43LLLLLok seems I need to load them with before they appear
12:43raekyes, I think it queries the clojure runtime for existing namespaces
12:43raekwhich only gets added if they are loaded
12:43LLLLLok
12:44LLLLLgood to know that
12:44LLLLLso "use" adds the functions of the namespace to use as unqualified
12:44raekyes
12:45raeka process called "referring"
12:45raek"use" is basically "require" and "refer"
12:46raekrefer is very rarely used manually, though
12:47raekheh, I discovered C-c M-p yesterday... ("Switch the repl namespace to match the current buffer")
12:47KirinDaveOh.
12:47raekno need to write (in-ns 'se.raek.some.of.my.insanely.long.namespace.names) anymore...
12:47KirinDaveThat's a good key
12:48KirinDaveI finally got autocomplete working in all my slime buffers. :\
12:48KirinDaveIt's still sorta janky how I do it, but it works!
12:48raekall the ones listed at http://github.com/technomancy/swank-clojure are very handy
12:49KirinDaveC-c C-k is one I _never_ use.
12:49raekit's neat for getting line numbers for the fns
12:50LLLLLC-c TAB is autocomplete? Just TAB works for me
12:50raekthey are not set if one sends them for evaluation with C-M-x
12:50raekI think that different in repl and code buffer for me
12:52_uliseshello all
12:54ohpauleezhi _ulises
12:55_ulisesI have the newbie's dillema
12:55_ulisesI have read Programming Clojure and I'm about to read The Joy of Clojure
12:56_uliseshowever, I don't feel like I'm doing enough progress
12:56_ulisesI know it sounds silly, but after learning the basics of Clojure and learning how to write simple code, I'm sort of stuck using only clojure.core and following a semi-imperative semi-fp style
12:56ohpauleez_ulises: You'll the most from working through an entire project
12:56_ulisesso, got any ... ah! good stuff ...
12:57ohpauleezThe Joy of Clojure will help answer the "when" questions for you
12:57ohpauleez_ulises: What do you typically work on
12:57_ulisesI am suffering the problem described here: http://prog21.dadgum.com/80.html
12:57_uliseswell, I work on many things really
12:57_ulises:S
12:58ohpauleezI think a parallel web-scraper, that collects data, performs some ops on it, and does some viualization with it, is fun and a good project
12:58_ulisesoh
12:58_ulisesnice
12:58carkhhow about something that helps you
12:58_ulisesI could try a port of scrappy (a cawler written in python)
12:58ohpauleezBuilding a web system is fun too, let's deal with data and you have a usable product afterwards
12:58_uliseswell, that blog post actually says: if you don't know what to work on, just work on something you would use
12:59ohpauleez_ulises: Porting might lead you the wrong way
12:59_ulisesI feel rather silly coming to you with such dillemma :)
12:59ohpauleezbecause you'll try to take an imperative approach and force it into a functional one
12:59ohpauleezDon't ever feel silly
12:59_ulisesohpauleez: well, not strictly porting, but writing something similar, that's what I mean :)
12:59ohpauleez_ulises: Take a look at Enlive
12:59_ulisesyeah, I guess I'm too eager
12:59_ulisesI've only started learning/working with Clojure 1 1/2 months ago
12:59ohpauleezThing about how you can use futures, maybe promises, perhaps agents
13:00ohpauleezand pmap
13:00_ulises,(doc pmap)
13:00clojurebot"([f coll] [f coll & colls]); Like map, except f is applied in parallel. Semi-lazy in that the parallel computation stays ahead of the consumption, but doesn't realize the entire result unless required. Only useful for computationally intensive functions where the time of f dominates the coordination overhead."
13:00_ulisesooh
13:00_ulisesnice
13:00ohpauleezThen take a look at incanter,
13:00ohpauleezand do some nice data visualization with it
13:01_ulisesinteresting
13:01tomojif you want it to be parallel, look at aleph too
13:01ohpauleeztomoj: You're beating me to it!
13:02_ulisesI am writing the ant demo at the moment just to get my dev-env set up properly and warm up
13:02ohpauleez_ulises: I would, generally speaking, just think about fun projects or areas I always wanted to play in (machine learning, AI, web stuff, etc), and just do a small project
13:03ohpauleezonce you move forward, you'll get more ideas on other things you want to do
13:03_ulisesthat's a nice approach
13:03_ulisesI think that my ultimate goal is to learn the language inside out
13:03_ulisesand I think that by coding in it you do that
13:03_ulisesso, yeah, great stuff, thanks ohpauleez :)
13:04ohpauleez_ulises: totally happy to help
13:04_ulisesI will take a look at those libs/projects you mentioned and see what I can come up with
13:04carkhalso when you feel your code is too imperative when it shouldn't, come here and show us, there are many helpfull people here
13:05_ulisesah, yes, that'd be very valuable
13:05ohpauleezfor sure
13:05_ulisesI've also realised that I tend to overcomplicate solutions
13:05_ulisespretty much all the time
13:05ohpauleezeven those of us who do lot of clojure will post snippets for opinions
13:06_ulisesthere was this email to the ml about an fn that would take an input like [[:foo [1 2 3] [:bar [\a \b \c]]] and it would produce ({:foo 1 :bar \a} {:foo 2 :bar \b}...)
13:06_ulisesand I came up with a really long and convoluted solution :/
13:08ohpauleez_ulises: That has more to do with familiarity of apply functions than anything else
13:08ohpauleezs/apply/applying
13:09_ulisesheh, my solution involved lots of (apply map fn ...)
13:09_uliseson the happy side of things, I learnt that a sequence of apply will unpack a nested list structure
13:09_uliseswhich is awesome :D
13:09raek_ulises: I think the best way to learn and familirize with the libs is simply to code a lot.
13:10_ulisesraek: yes, that's what I think as well, but when you don't know what to code, you're stuck reading blogs and trying silly things out in the repl but not much more
13:10_ulisesraek: and at the same time I don't want to create any more abandon ware
13:10_ulises*abandonware
13:10tomojunavoidable
13:10_ulisesbut ohpauleez has a point: I will just play with stuff I've always wanted to to and learn that way
13:10raekmy first big project was a web system for tracking debts between the persons in my circle of friends
13:11tomojgreat idea
13:11raeklately, I have been coding on an IRC library
13:11tomojmath is usually hard when I owe my friends money
13:12_uliseshah
13:12raeknot much libs in that project. it used compojure, refs and files, basically
13:12yavuzraek: hmm...sounds like you could be the clearing house to net the debts and pocket a small fee...many a financial fortune is based on that idea ;P
13:14_ulisesanyway, thanks for the advice chaps
13:14_ulisesperhaps I should pay you for the psycoanalysis session :)
13:15defnwow this sucks.
13:15defnno more rooms left for clojure-conj
13:15defnim screwed.
13:20Raynesdefn: I'll cry myself to sleep tonight. :(
13:20defn@clojure-conj tweeted that we had until the 11th and that there were plenty of rooms available. *sigh*
13:21defnI have a damn ticket, taboot.
13:21defnNot sure what I'm going to do now...
13:21RaynesA ticket to what? The conj?
13:21Raynes:o
13:22defnYeah I have a conj ticket
13:22defnbut no room
13:22RaynesAnd nobody has offered you the floor of their room yet?
13:22Raynes:\
13:23_ulisesdefn: did you see the email from the chap wanting to share a room?
13:23_ulisessorry, to the ML
13:23carkhmaybe there is a park around with a comfortable bench =)
13:24Raynescarkh: It's in a park. :p
13:25LauJensenHi guys :)
13:25_uliseshi LauJensen
13:26esjEvening Lau
13:27RaynesAfternoon, LauJensen.
13:27defn_ulises: i didnt but ill check it out
13:28_ulisesdefn: recently there was this chap wanting to share a room and his last email was along the lines of "ok, booked a room, it'll be $X for whomever wants to share it w/me"
13:28_ulises:)
13:29Raynesdefn: If that doesn't work out, if you post an ML thread, I'm sure there is someone who would be happy to let you use a sofa bed or something. I mean, I'd happily let you sleep in our room if it came down to it, but I'm not sure they'll be anything in there but the floor for you.
13:30_ulisesesj: whereabouts are you?
13:30_ulises(if you don't mind me asking)
13:30defn_ulises: if you can point out where that thread is id be obliged
13:30defnsearching for clojure conj is somewhat difficult on the ML :)
13:30_ulisesdefn: sure, one sec.
13:31Raynesdefn: http://groups.google.com/group/clojure/t/5d147246206ff586
13:31esj_ulises: Her Majesty's Green and Pleasant Land
13:31_ulisesesj: heh heh, that makes two of us I guess
13:32_ulisesdefn: what Raynes just said :)
13:33defn_ulises: got it, thanks Raynes -- email sent.
13:34defnlate*
13:34_ulisesdefn: g'luck
13:35defnthanks :)
13:41Raynesdefn: Keep me posted.
13:51yayitsweihello.
13:51yayitsweihow do i iterate through every two elements in a list: for example (1 2 10 11) i want (1 2) (2 10) (10 11)
13:52yayitsweii want to remove numbers that are within 1 distance of the previous-- in the above case, the correct answer would be (1 10)
13:53Raynes-> (partition 2 (range 11))
13:53sexpbot⟹ ((0 1) (2 3) (4 5) (6 7) (8 9))
13:53Raynes-> (partition-all 2 (range 11))
13:53sexpbot⟹ ((0 1) (2 3) (4 5) (6 7) (8 9) (10))
13:53hiredman,(iterate rest [1 2 10 11])
13:53hiredmaner
13:53clojurebotExecution Timed Out
13:53_uliseswoot! I've been needing that fn all along and wrote my own :(
13:53yayitsweiah, partition .. thanks
13:53hiredman,(take-while identity (iterate rest [1 2 10 11]))
13:53yayitsweihaha _ulises
13:54clojurebotExecution Timed Out
13:54hiredman,(take-while (comp identity seq) (iterate rest [1 2 10 11]))
13:54clojurebot([1 2 10 11] (2 10 11) (10 11) (11))
13:54_ulises:'(
13:55RaynesPartition doesn't do quite what you want here.
13:55RaynesI didn't read your message thoroughly enough.
13:55hiredman,(map (partial take 2) (take-while seq (iterate rest [1 2 10 11])))
13:55clojurebot((1 2) (2 10) (10 11) (11))
13:55hiredman,(butlast (map (partial take 2) (take-while seq (iterate rest [1 2 10 11]))))
13:55clojurebot((1 2) (2 10) (10 11))
13:59mfex,(partition 2 1 [1 2 10 11])
13:59clojurebot((1 2) (2 10) (10 11))
13:59Raynes-> (doc partition)
13:59sexpbot⟹ "([n coll] [n step coll] [n step pad coll]); Returns a lazy sequence of lists of n items each, at offsets step apart. If step is not supplied, defaults to n, i.e. the partitions do not overlap. If a pad collection is supplied, use its elements as necessary to complete last partition upto n items. In... http://gist.github.com/618424
13:59RaynesOh! a step!
13:59RaynesAwesome.
14:00_ulisesindeed
14:00yayitswei,(partition 2 1 [1 2 10 11])
14:00clojurebot((1 2) (2 10) (10 11))
14:02_ulises,(partition 2 (interleave [1 2 3] [\a \b \c]))
14:02clojurebot((1 \a) (2 \b) (3 \c))
14:02_uliseswoop
14:02_ulisesgood bye map
14:05yayitsweiok, so I got this
14:05yayitswei,(keep #(if (< 1 (- (last %) (first %))) (last %)) (partition 2 1 [1 2 10 11 20 21]))
14:05clojurebot(10 20)
14:06yayitsweia very newbie way of doing I'm sure, and it misses the first element
14:06xcthulhuIs there a way to use clojure to do concurrent programming (ie, map-reduce) over a bunch of computers on a LAN?
14:06yayitsweishould be (1 10 20)
14:06yayitsweibut otherwise it does what I want
14:11hiredman,(map first (filter #(= 1 (- (apply max %) (apply min %))) (butlast (map (partial take 2) (take-while seq (iterate rest [1 2 10 11 20 21]))))))
14:11clojurebot(1 10 20)
14:15LauJensenxcthulhu: Well, there's clojure-hadoop, and terracotta to look at
14:16xcthulhuLauJensen: Thank you! :D
14:16LauJensenxcthulhu: np. I actually have a blogpost on how to get started with clojure-hadoop of you need a kick start
14:17LLLLL(butlast "12345")
14:18LLLLL,(butlast "12345")
14:18clojurebot(\1 \2 \3 \4)
14:18LLLLL,(str (\1 \2 \3 \4))
14:18clojurebotjava.lang.ClassCastException: java.lang.Character cannot be cast to clojure.lang.IFn
14:18LLLLLhm
14:18LLLLLhow do I get it back into string again
14:18LauJensen,(->> "12345" butlast (apply str))
14:18clojurebot"1234"
14:19LauJensenLLLLL: Or in short, instead of str, use (apply str (\1 \2...
14:19LLLLLwhats ->> ?
14:19LauJensen->> threads the first item through the remaining forms as the last argument of them
14:19sexpbot⟹ #<core$_GT_ clojure.core$_GT_@189c698>
14:19LauJensen(->> 3 (+ 2)) becomes (+ 2 3)
14:20LauJensen(apply str (butlast "1234")) is the same as (->> "1234" butlast (apply str))
14:22LLLLL,(apply str (\1 \2 \3))
14:22clojurebotjava.lang.ClassCastException: java.lang.Character cannot be cast to clojure.lang.IFn
14:22LLLLL,(apply str '(\1 \2 \3))
14:22clojurebot"123"
14:23LLLLL(str '(\1 \2 \3))
14:23LLLLL,(str '(\1 \2 \3))
14:23clojurebot"(\\1 \\2 \\3)"
14:23LLLLLthis clojure is funny shit
14:23LLLLL:P
14:23kumarshantanu,(apply str '(\1 \2 \3))
14:23clojurebot"123"
14:24LLLLLso many ways one can screw up
14:24kumarshantanuLLLLL: the key is - you should know what you are doing :)
15:09yayitsweihiredman: just saw your solution.. thanks!
15:12ordnungswidriganybody using rainbow-parens?
15:13amalloyordnungswidrig: i am, though i'm probly gonna stop soon
15:13hiredmanI am getting used to having it off, it really bogs down moving around in a large file or a deeply nested expression
15:14ordnungswidrigfor me it conflicts with clojure-test-mode
15:16ordnungswidrighiredman: what slows me down more is that fontifying the slime compilation buffer takes longer than the compilation itself...
15:16ordnungswidrighiredman: even for "0 compiler notes". Any chance to improve that?
15:17RaynesI still have rainbow parens. No particular reason. I don't look at parens anymore. I just haven't bothered to turn it off.
15:20hiredman*shrug*
15:21ordnungswidrig*shrug* who?
15:33jaleyhi guys! would I be right in thinking the easiest way to use a SOAP service from clojure will be javax.xml.soap? I did some googling and couldn't find anything obvious in clojure...
15:51LauJensenjaley: Judging from the silence I think javax.xml.soap is your best bet :)
15:52jaleyLauJensen: heh thanks.. actually I realized that's server-side now. seems apache axis is my best bet
15:52LauJensenAh ok. Ive worked with Axis in the past. Was a little painful as I recall
15:52jaleyLauJensen: d'oh...
15:53LauJensenjaley: Homer, is that you? :)
15:53jaleyLauJensen: Marge?
15:54ordnungswidrigMaggie?
15:56RaynesBart?
16:12DeranderI am new to clojure. I have a list of CommPortIdentifiers from a java library. I have converted it to a lazy seq. I want to return a specific object from the list if it matches a predicate, and throw an exception if the object I'm looking for isn't in the list
16:14DeranderWhere should I look to figure out how to do this? Would it be idiomatic to filter it with reduce, return the result if there is one or throw an exception if the size is 0?
16:15Raynes-> (some #(= 4 %) (range 11))
16:15sexpbot⟹ true
16:15RaynesBad example.
16:15Deranderhttp://gist.github.com/618562 <-- this is the code that I'm trying to make better.
16:15Deranderthe goal is to return the CommPortIdentifier that matches the name I'm looking for
16:16Raynes-> (some #(and (= 4 %) %) (range 11)) ; was what I was trying to do.
16:16sexpbotjava.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Symbol
16:16DeranderRaynes: reaing clojure doc on some
16:16MayDaniel,(some #{4} (range 11))
16:16clojurebot4
16:16Deranderhhaha.
16:17RaynesMayDaniel: hi5
16:17RaynesI knew I was forgetting something. :\
16:18Raynes-> (some #(and (= 4 %) %) (range 11))
16:18sexpbotjava.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Symbol
16:18RaynesThat must be a sexpbot bug.
16:18Raynes,(some #(and (= 4 %) %) (range 11))
16:18clojurebot4
16:19RaynesAnyways, some returns the first truthy result of applying the predicate function to an element of the list. You should be able to do what you want with it.
16:19Deranderhttp://gist.github.com/618562
16:20Deranderis what I came up with. it returns true if it finds the match. I'm not sure how you're getting some to return the actual value
16:20RaynesI used and.
16:20Raynes-> (and true "a value")
16:20sexpbotjava.lang.ClassCastException: java.lang.Character cannot be cast to clojure.lang.IFn
16:20RaynesWhat the hell, sexpbot.
16:20Raynes,(and true "a value")
16:20clojurebot"a value"
16:20Deranderoh, I see.
16:20Derandermissed the second %
16:21Raynes#(and (= (.getName %) port-name)) %) will do the trick.
16:21Deranderyeah.
16:21DeranderI didn't see the significance of the "and" and the %
16:21Derandersecond %
16:21RaynesMinus one of the inner closing parens, anyway.
16:22DeranderRaynes, MayDaniel: thanks for your help.
16:23RaynesAlso, if you're curious about his #{4} trickery, it's because sets are functions that look up their argument within themselves and return it if it exists, or nil otherwise.
16:24Raynes-> (#{4} 4)
16:24sexpbot⟹ 4
16:24Raynes-> (#{4} 3)
16:24sexpbot⟹ nil
16:24Deranderthat's nifty.
16:24RaynesWhen you're checking a sequence for literals, it's perfect.
16:26Deranderclojure is frustrating because I'm used to writing in ruby. and ruby has a semi-functional style when it's idiomatic, so I recognize the names and concepts but can't implement them in clojure
16:26Deranderbecause I don't know clojure's vocab yet.
16:32yayitsweiwhat's the recommended way to deal with dates in clojure- joda? or is there a clojure date class
16:33Raynesyayitswei: The Java way. joda is a popular option. Check out clj-time.
16:33yayitsweiraynes: ah, perfect. thank you
16:37jk_does anyone here know how the clojure run-time manages redefinining vars in a running program? is it atomic? is it safe to do "in production"? would the new values only get used for new threads? etc. maybe there is a good place to read about this.
16:39ordnungswidrigjk_: http://clojure.org/vars
16:40ordnungswidrig,(doc set!)
16:40clojurebotexcusez-moi
16:41ordnungswidrigjk_: you might want to use refs or atoms
16:41jk_ordnungswidrig: thanks. i had read that earlier but i'm wondering about the safety of, for example, using a remote repl into a running server app to redefine functions on-the-fly, like you might do in erlang. i don't get a good feel for how that works from this reading. it's not a local binding but rather redefinining a global
16:42ordnungswidrigjk_: ah, I see.
16:42jk_ordnungswidrig: more like applying bug fixes as hot code swaps
16:43ordnungswidrigso your question is more about the thread safety of (def)
16:44jk_well, as i understand it, all you are doing is binding to a var in def, defn, etc
16:44jk_ordnungswidrig: i mean when you are providing a value, obviously :)
16:44ordnungswidrigyes, it's a root bound var.
16:44yayitsweienlive question: how do you select for the working node? something like "self" ?
16:46jk_ordnungswidrig: so yes, i guess the question is about the thread safety of changing a root bound var.
16:47ordnungswidrigjk_: I think using (def foo x) works like (alter-var-root foo constantly x) and for alter-var root only atomicity is given. which means that every thread will see the change instantly.
16:47yayitsweifor example the model is <li>some stuff</li> and I want to set the id attribute, <li id="1">some stuff</li>
16:47ordnungswidrigjk_: http://richhickey.github.com/clojure/clojure.core-api.html#clojure.core/alter-var-root
16:47jk_ordnungswidrig: is it normal to try doing this kind of thing on a running system in production?
16:49ordnungswidrigjk_: for lispers in general yes. I don't know how safe it's in clojure, to be honest
16:50jk_ordnungswidrig: ok, thanks. and i didn't know about alter-var-root so that's good to know
16:50ymasorywhy does "" count as true in an if expression but not when you compare them using =?
16:51amalloyymasory: *everything* but nil and false counts as true in an if
16:51amalloybut "" is not equal to true, because they are clearly different values
16:52ymasoryoh i see, so if isn't really looking for a boolean result necessarily
16:52bhenry,(boolean "")
16:52clojurebottrue
16:52jk_,(= "" "")
16:52amalloyright. i think it actually coerces to boolean, but that coercion turns almost everything to true
16:52clojurebottrue
16:54ymasory_thanks amalloy
16:54jarpiain,(if (Boolean. false) "foo" "bar")
16:54clojurebot"foo"
16:54jarpiainit compares against null and the literal false, which is the same as Boolean/FALSE
16:55jarpiain,(identical? false Boolean/FALSE)
16:55clojurebottrue
16:55jarpiain,(identical? false (Boolean. false))
16:55clojurebotfalse
16:55bhenry,(identical? false (boolean false))
16:55clojurebottrue
16:56amalloy(the lesson here is if you ever see Boolean. in your code you might as well commit suicide now and save yourself the trouble)
17:00jk_,(if (.booleanValue (Boolean. false)) "foo" "bar")
17:00clojurebot"bar"
17:01ordnungswidrigjk_: you shall not use (Boolean.) :-)
17:01jk_i guess if you run out of memory, jarpiain's call might produce "bar" :)
17:02jk_ordnungswidrig: yes, there's no good reason to, unless some java interop demands it i guess. but calling a constructor isn't going to return nil or false in any case
17:02ordnungswidrigI hope oom throws and oome
17:04AWizzArd_ato: hi
17:18AWizzArdhow can I type-hint a local with a primitive initializer in Clojure 1.3? I put a ^:static after defn, but this didn't work. I can’t say: (dotimes [^int i 80] ...)
17:20ordnungswidrigAWizzArd: Integer/TYPE
17:21AWizzArdproduces the same error message
17:21AWizzArd"Can't type-hint a local with a primitive initializer."
17:24LauJensenAWizzArd: (defn ^:static [^long i] (dotimes [x i] ...)) If you want to make a primitive long inside the code, use (long 80)
17:24hiredmanAWizzArd: (int 80)
17:24KirinDaveAnd thus begins the perf poisoning.
17:24hiredmanthats how you always type hint a local
17:25KirinDaveIn which everyone suddenly thinks that static binding is the _single most important_ feature of your code.
17:25AWizzArdyes, int 80 is what I use, but my aset is surprisingly slow
17:25LauJensenIIRC in 1.3 (class (int 3)) is Long
17:25LauJensenAWizzArd: Probably due to reflection then ?
17:25AWizzArdyesterday _ato pasted http://gist.github.com/616655 - look at the microbench-nolock
17:25AWizzArdLauJensen: I get no reflection warning.
17:25LauJensenAWizzArd: Which is the danger of arrays, they dont always warn on reflection
17:25hiredmanthen jump on one of the many "this is surprisingly slow on the alpha release of the code I am using" threads on the mailing list
17:26AWizzArdFor _ato writing into a byte[] was 9x faster than writing into a ByteArrayOutputStream. For me writing into a baos is a bit faster than writing into an array.
17:26ordnungswidrigAWizzArd: you may publish my paste if you like.
17:28AWizzArdordnungswidrig posted this too: http://clojure.pastebin.com/6Z0sW00E
17:30LauJensenAWizzArd: Both Christophe and I have posts where we show how to speed up slow asets which arent giving reflection warnings
17:31jk_is it idiomatic in clojure to use underscore '_' for unused parameters?
17:31AWizzArdLauJensen: you don’t happen to have a link, do you?
17:31MayDanieljk_: Yes.
17:31LauJensenAWizzArd: no, but I can find them, sec
17:31KirinDaveI'm slowly approaching the finish line for the first chapter I'm writing of my clojure book.
17:32AWizzArd,(let [ba (byte-array 100000000)] (time (dotimes [i 80000000] (aset ^"[B" ba (int i) (byte 0)))))
17:32clojurebotjava.lang.OutOfMemoryError: Java heap space
17:32AWizzArdwell, this is what I tried
17:32LauJensenAWizzArd: http://clj-me.cgrand.net/2009/10/15/multidim-arrays/
17:36AWizzArdhiredman: can you compare (let [baos (java.io.ByteArrayOutputStream. 100000000)] (time (dotimes [i 80000000] (.write baos 0)))) vs (let [ba (byte-array 100000000)] (time (dotimes [i 80000000] (aset ba i (byte 0))))) ?
17:36AWizzArdFor me baos is faster, but I need to say (int 0)
17:36AWizzArdLauJensen: maybe you can paste those two too?
17:36AWizzArdinto your repl
17:37LauJensen1) 558ms, 2) 93ms
17:37NikelandjeloIs there a functions, which for seq (1 2 3 ) will return sequence of it's subseq, starting from beginning? f( [1 2 3] ) -> ( (1) (1 2) (1 2 3) )
17:38MayDanielNikelandjelo: I doubt it.
17:38AWizzArdLauJensen: excellent, exactly what I would expect. Because the BAOS is doing 80 mio calls that need to be locked, as .write is synchronized. But on my machine I get with Clojure 1.3: 1050 msecs for baos vs 1400 msecs byte[]
17:39LauJensen,(reductions vector [1 2 3])
17:39clojurebot(1 [1 2] [[1 2] 3])
17:39LauJensenNikelandjelo: almost :)
17:40AWizzArdLauJensen: and please one more timing: (let [bb (java.nio.ByteBuffer/allocate 100000000)] (time (dotimes [i 80000000] (.put bb (byte 0)))))
17:40LauJensenAWizzArd: 163ms
17:41AWizzArdas expected
17:41AWizzArdthanks for trying those
17:43MayDanielNikelandjelo: (reductions #(conj %1 %2) [] [1 2 3]) is close.
17:44LauJensen,(letfn [(f [s] (reduce (fn [acc _] (conj acc (take (-> acc count inc) s))) [] s))] (s [1 2 3]))
17:44clojurebotjava.lang.Exception: Unable to resolve symbol: s in this context
17:44LauJensen,(letfn [(f [s] (reduce (fn [acc _] (conj acc (take (-> acc count inc) s))) [] s))] (f [1 2 3]))
17:44clojurebot[(1) (1 2) (1 2 3)]
17:45NikelandjeloThanks :)
17:52jaleyis it idiomatic to just call setters on a java object in a (do ) form? it makes me sad
17:53TeXnomancyjaley: doto is more common, but yes, sadness is a documented side-effect of side-effects.
17:54LauJensenDoto really helps make interop tolerable
17:55jaleyTeXnomancy: :) I guess doto just saves me typing the object name a squillion times?
17:55TeXnomancyjaley: and it clearly delineates the extent of the setup of the java object
17:56jaleyTeXnomancy: ah i see it returns the object, so presumably one would typically use it in a let?
17:57jaleyTeXnomancy: then you're done with the nasty
17:58LauJensenjaley: exactly. The returning of the object is the key to happyness
18:00iisjmiiBit of a newbie question; I trying to install swank-clojure, for which I need swank-clojure.jar but I can't find it anyhwere. Where do get it? Do I need to compile it?
18:00amalloy,(drop 1 (reductions conj [] [1 2 3]))
18:00clojurebot([1] [1 2] [1 2 3])
18:00amalloyLauJensen, Nikelandjelo: ^ seems nicer
18:01LauJensenamalloy: no doubt :)
18:01LauJenseniisjmii: ELPA
18:02iisjmiiLauJensen: I installed swank-clojure via ELPA succesfuly, when I start slime I get the question if I want to install clojure, it fails to do this, so I want to do it by hand, but I can't find swank-clojure.jar
18:03LauJenseniisjmii: http://github.com/technomancy/swank-clojure - should be easily buildable
18:03iisjmiiLauJensen: Thx, I try and build it
18:03jaleyiisjmii: I had issues with ELPA too - I pulled the code down from LauJensen's link, built it and stuck a symlink in ~/.clojure to the target jar
18:04iisjmiijaley: Thx, I try that
18:04TeXnomancyiisjmii: "lein install swank-clojure 1.3.0-SNAPSHOT" will do it
18:04TeXnomancythen you can just do "swank-clojure" at the shell and have it launch a standalone swank server
18:04TeXnomancyM-x slime-connect works from there
18:04clojurebothttp://haacked.com/images/haacked_com/WindowsLiveWriter/IConfigMapPathIsInaccessibleDueToItsProt_1446B/works-on-my-machine-starburst.png
18:05TeXnomancyclojurebot: got some attitude today, I see
18:05clojureboteveryday is Rich Hickey Appreciation Day
18:05mrBlisshttp://graphjam.com/2010/10/09/funny-graphs-lonely-black-sheep-of-the\
18:05iisjmiiTexnomancy: thx!
18:09kutkuim trying to run: (def text (slurp "./text.txt"))
18:09kutkuwhere should I put that file?
18:10amalloykutku: try this to find out: (.getCanonicalPath (java.io.File. "."))
18:11kutku"C:\\Program Files\\NetBeans 6.9.1"
18:11kutkuso I put the file there I assume :)
18:11amalloywell then, that's where to put it
18:11Adamantis Rich Hickey on here at all?
18:12amalloyAdamant: ping rhickey and find out (ie, he is here sometimes, but maybe not now)
18:12Adamantlol, that's all I needed to know
18:13LauJensenkutku: also see (System/getProperty "user.dir")
18:14kutkuhes in :)
18:15iisjmiijaley: Thx it works
18:18kutkuthank you
18:34AWizzArdhiredman: yes yes, I just tried Clojure 1.2 stable vs 1.3 from build.clojure.org, and 1.2 is much faster on aset
18:34AWizzArdmust be cause of Alpha
18:42gilbertleunghi, i have a question regarding keys in clojure
18:42gilbertleungfor example, if my map has keys ":key" and ":value"
18:42gilbertleung(sorry, just the key ":key")
18:42gilbertleungwould it not be error prone to type ":key" all over my code
18:43gilbertleungif i make a typo ":keyy", then the value would be nil
18:43gilbertleungand it wouldn't be so obvious that i have made the mistake
18:43gilbertleungis there any good practice to solve this problem?
18:44iisjmiigilbertleung: what would you want to happen?
18:44jarpiain,(doc clojure.contrib.map-utils/safe-get)
18:44clojurebotI don't understand.
18:44hiredmangilbertleung: well you are just as likely to mistype the name of a function
18:44gilbertleungit seems to me that if i mistype the name of a function
18:44gilbertleungi'd probably get an error that's more noticeable
18:44hiredmanit depends
18:45gilbertleunge.g "symbol blah not found"
18:45hiredmanunless the symbol exists and is bound to something else
18:45gilbertleungwhere as if i mistype a key, i'd run into no troubles unil the "nil" value screws sth up
18:47AWizzArdgilbertleung: you are right, this is a source of error. So, do a: (def my-key :key)
18:47AWizzArdand then access your map with my-key
18:47gilbertleungjarpiain: yes, i guess safe-get does kinda solve my concern
18:47AWizzArdThis will be your constant, and if you make a typo, then there is a good chance that Clojure will catch it.
18:47gilbertleungAWizzArd: i considered doing that also
18:48AWizzArdIn principle, a constant name should be surrounded by +’s
18:48gilbertleungbut that would make it impossible to destructure a map in the function params
18:48AWizzArd(def +key+ :key)
18:49AWizzArdThis is one of the disadvantages when working with flexible maps.
18:49AWizzArdMore room for typos.
18:49TeXnomancyAWizzArd: you're thinking of Common Lisp
18:50gilbertleunghmm, okay thanks
18:50AWizzArdTeXnomancy: it makes senso to follow the established patterns of naming def’ed things with stars, and constants with +. It informs the reader and is good style.
18:50gilbertleungguess life can't be perfect
18:50AWizzArdgilbertleung: you can work with deftype, which needs predefinde keys
18:51TeXnomancyAWizzArd: calling some things "constant" and others not is leftover baggage from non-functional language
18:52AWizzArdTeXnomancy: objects that live in a def’ed var can change. This is why Clojure is not doing type inference on them. When I (let [something ..] ...) then something is known to be immutable and its type can be inferred, hints are not required. The pluses are a nice thing for people to catch.
18:53AWizzArdStars and pluses allow me to fast see what is local and what is not. And what I have in stars might be changed in bindings, or for different program runs. What I see in plusses never changes.
18:53TeXnomancyAWizzArd: they don't change at runtime unless (a) they are reference types, in which case it will be obvious for other reasons or (b) you're doing something very wrong.
18:53AWizzArdthe wrong thing could be (binding [hi ...] ...)
18:53TeXnomancyif you're rebinding you use earmuffs, because that's a special case
18:53TeXnomancyconstants are not a special case
18:54AWizzArdThey are a special case. I want to explain readers of my code what is fixed in the world.
18:54AWizzArdIt is just good style and friendly for readers.
18:54_atohehe.. in Clojure the default is constant so you mark the things that can change
18:55_atoin other languages the default is non-constant so you mark the things that are constant
18:55AWizzArdEverything named with *var* is subject to change, be it by binding or by changing the parameters for a program run.
18:55AWizzArd_ato: things that you (def ..) can hold different objects, even of different types via binding.
18:56_atoTeXnomancy: by the way, cut Clojars over to the new server last night. Were having trouble SSHing to it?
18:56_atos/having/you having/
18:56sexpbot<_ato> TeXnomancy: by the way, cut Clojars over to the new server last night. Were you having trouble SSHing to it?
18:56TeXnomancy_ato: oh sweet! no, I haven't tried yet.
18:56AWizzArdOr people are supposed to edit the values. Or like in the ant.clj example of Rich we use the run variable at runtime on the repl, to stop the program.
18:56AWizzArd(def *running* false)
18:56TeXnomancy_ato: thanks for getting it moved over; I'm happy to see progress on that front
18:57TeXnomancyAWizzArd: everyone agrees about stars around rebound vars; it's the plusses for constants that are non-idiomatic
18:57AWizzArdI can agree that they are not used often. This is very rare indeed. But it definitly is cleaner to have a naming style for constants. And there are constants used from time to time.
18:58AWizzArd(def +second+ 1) (def +minute+ 60) (def +hour+ (* 60 +minute+)), etc
18:58TeXnomancyok, I'm just saying that most people when they see that are going to think, "Oh, this code was written by a CL user, not someone who's gotten used to Clojure."
18:59AWizzArdWhen I see it then I think: oh, how nice of her to give me more information :-)
18:59_atodo you name functions like that as well? (defn +format-time+ ...) for they are also constants :p
19:00AWizzArdThey are not.
19:00AWizzArdOften I start writing one, and later change it.
19:00AWizzArdI fix bugs, etc.
19:00AWizzArdPi I never change.
19:00AWizzArdOr 16 I never change.
19:00_atoah, so you only use it for magic numbers?
19:01_atothat sort of thing
19:01AWizzArdit is very rare
19:01AWizzArdBut sometimes I def things and I know that there will never be a patch or bugfix or need to ever change them.
19:01AWizzArdMy intention about this should be documented.
19:02AWizzArdFor example, even if declaring something as 'final' in Java would never give performance advantages, I would still strongly suggest to use it always.
19:03AWizzArdThis info is more useful than getting more performance (which is also nice of course)
19:03TeXnomancythat's because java is a language that encourages mutability
19:03AWizzArdThere it is even more important.
19:03AWizzArdBut in Clojure i can not know 100% that something will never changed.
19:04AWizzArdThere could be patch that changes stuff
19:04AWizzArd(def x 19) might be (def x 22) in a week
19:04_atoI wouldn't call "things that are never changed in the source code" constants (that's not what final means). I don't know what I'd call them though, I guess the "stable API" but that just refers to the interface (their existence) not their value.
19:05TeXnomancywell, pi might be calculated with more accuracy in a future JDK; since it's irrational your representation of it is only an approximation
19:06AWizzArdI would even think about naming it π
19:06AWizzArdAnyway, naming constants with + is doing no harm, it is no loss of productivity, and well tell readers that something does not change.
19:06iisjmiiWhen I edit a clj file in emacs and use C-c C-c to compile it I get the error "No such namespace:". I can prevent this by first compiling (in-ns 'clojure.core) in that file but it is annoying. Is this normal?
19:07TeXnomancyyou're free to use your own coding conventions in your code, as fogus elegantly puts it: http://blog.fogus.me/2010/08/30/community-standards/
19:07TeXnomancyiisjmii: a) you need an ns form in your file and b) try C-c C-k for compiling in Emacs
19:07AWizzArdIt is not my coding convention alone, but pretty much globally a convention for lisps
19:08TeXnomancynever seen it in elisp
19:08AWizzArdBut sure, if somebody dislikes it, she can omit the +’s.
19:08iisjmiiTeXnomancy: Ah thx
19:09AWizzArdSomething that worries me much more is that I have seen so much Clojure code, and trillions of fns that don’t have doc strings.
19:09AWizzArdGood that at least in Clojure and Contrib nearly everything has one.
19:13dnolenBeyond JavaScript Prototype Chains, http://dosync.posterous.com/beyond-javascript-prototype-chains, comparing JS prototype chains and Clojure ad-hoc type hierarchies
19:13dnolenfeedback appreciated as usual
19:14AWizzArddnolen: did you spend a bit time with diving into types and Clojures way of handling them?
19:15dnolenAWizzard: yeah I'm suing the ad-hoc type stuff in a current project, so I got interested in doing a series comparing to JS, in particular because I know JS well and JS is popular, but has a different take on OO
19:15dnolens/suing/using
19:15AWizzArdBecause I got a maybe interesting question, and you may be able to shed some light on it.
19:16dnolenAWizzard: shoot
19:16AWizzArdFor my high-performance Clojure serialization library I want to implement a new type. It will act mostly like a (java.io.DataOutputStream. (java.io.BufferedOutputStream. stream)), but much more efficient for serialization.
19:16AWizzArdNow there are many ways to do this. I could do it in Java, and it would be pretty clear how to do it.
19:17AWizzArdI want to do it in Clojure, and there I could use deftype.
19:17AWizzArdBut: deftype can not inherit from classes, such as java.io.OutputStream.
19:17AWizzArdThen I thought that rhickey did this by purpose, because he understands that inheritance can lead to big problems.
19:17AWizzArdNow my question is: why can it lead to problems?
19:18AWizzArdWhy is it good that the is-a of a type should come from Interfaces/Protocols, while classes should go into a has-a relationship?
19:18AWizzArdWhen I deftype this, there could be three slots: :output-stream :buffer and :counter, while the :counter will be mutable.
19:19dnolenAWizzard: I thought about this today and have only my own perspective, before and after methods in CL are a symptom of a problem
19:19AWizzArdThe result is that my deftype will *not* be an OutputStream, and can not be used in such places.
19:19dnolenpeople think before and after methods are cool, but they actually are there to a problem that sucks
19:19dnolenwhen you override a inherited method you have to know "when" to call it
19:20AWizzArddnolen: yes, because those before/after methods can sit in totally different files, and I also stumbled upon this in the past. Very dangerous, as suddenly my state changed, and I did not understand why, until I found the after modifier.
19:20dnolenparticular nasty during construction or tear down
19:20dnolenbut it's a direct results of inheritance
19:21AWizzArdSo, this basically means that Sun should have made OutputStream an Interface I guess.
19:22dnolenin Objective-C it rears it's ugly head in the notion of the "designated initializer"
19:22AWizzArdConcretly for my situation I have to decide what I want: high-performance deftype, but this will not be an OutputStream then. Or I can go with gen-class and have a :state slot, but this would be a ref as I understand it, and is not as efficient as deftypes mutable slots.
19:22dnoleninheritance is basically effed
19:24dnolenAWizzard: but defrecord is plenty fast, if you don't mind a bit of memory tradeoff I think, if you're not making a bunch of them it's not a big deal.
19:24AWizzArddeftype.. I think I will go with deftype.
19:25dnolenAWizzard: why are you making many instances?
19:25AWizzArdno, but I will probably need a counter.
19:25AWizzArdAnd that needs to be mutated
19:27_atodnolen: I'm enjoying your Javascript/Clojure series. The way you're comparing them really makes for an interesting read. :-)
19:27dnolen_ato: thx!
19:27kutkuI assume this is the definition of a clojure function, can someone please explain what attr-map is?
19:27kutku(defn name doc-string? attr-map?
19:27kutku([params*] body)+ )
19:28chouserkutku: I think that's just metadata
19:28chousera map that will be applied as metadata to the var and function
19:28kutkuok, ill leave that for now then
19:29kutkuand also, what does the + sign after body men?
19:29kutkumean*
19:29chouserone or more
19:29AWizzArddnolen: also it is about the idea behind my type. It feels more baic to me, so it should be a deftype, not a defrecord.
19:29AWizzArdIO streams don’t feel like maps.
19:29dnolenAWizzard: that's true
19:29chouserkutku: you can have multiple param-body pairs for different number of params
19:30ataggartanyone run into an issue with cake/lein trying and failing to find org.apache.maven:super-pom:jar:2.0
19:30AWizzArdBut the issue stays: when Sun decided to go with an abstract base class, then my deftypes can't be an is-a of that type.
19:31kutkuchouser: ok thanks, similar to a java consuctor?
19:31AWizzArdand it is even a bit more complicated, because a deftype can not even have-an instance of such class
19:33TeXnomancyataggart: super-pom just means "the thing you're trying to build". you've probably got a typo in :dependencies
19:33ataggartI haven't touched the project.clj file gen'd by lein.
19:34ataggartI used lein new <proj name>
19:34ataggartcd to that prooject, run lein repl, it starts downloading, then dies on the above
19:34TeXnomancymust be a network glitch
19:36chouserkutku: sure, or any java method. but you don't repeat the name of the method in the source code, and the overloading is only on the *number* of args, not their types.
19:38kutkuok thanks!
19:41kutkuis it true that functions with names ending with ? only return true or false?
19:42chouserkutku: that is a recommended naming scheme, but not enforced by the language in any way
19:42RaynesThat is a convention for functions that return either true or false. That doesn't mean that everybody will adhere to the convention, and it isn't enforced.
19:42Rayneschouser: You beat me by 3 seconds thanks to my verbosity. :(
19:42chouserAs the gentleman from Alabama said.
19:43TeXnomancykutku: they return a value that's intended to be interpreted as truthy or falsey, not necessarily *the* true/false value
19:43kutkuthx
19:44RaynesIt appears that the convention is to name functions with a question mark *only* if they return true or false. As demonstrated by every? and some in clojure.core.
19:44RaynesAt least, that's what I gathered.
19:44amalloyclojure surely has an exponentiation function built in, doesn't it? i can't find it
19:44freakazoidYeah, they're called predicates.
19:45TeXnomancyRaynes: clojure.core/some shouldn't be taken as a paragon of naming; it's a terrible name taken from common lisp
19:45freakazoidamalloy: presumably in clojure.contrib.math
19:46chouseramalloy: Math/pow
19:46chouserit's built into Java. :-)
19:46amalloyoh, that silly java
19:46amalloywon't get integers back though, for large integral base
19:47AWizzArdamalloy: you can also try BigDecimals .pow
19:47AWizzArd,(.pow 2M 16)
19:47clojurebot65536M
19:48amalloyi found it in clojure.contrib.math
19:48kutkuhow come this does not work:
19:48TeXnomancyis there a subvec for arrays?
19:48kutku,(re-split #"\W+" "A fine day it is" )
19:48clojurebotjava.lang.Exception: Unable to resolve symbol: re-split in this context
19:48AWizzArdI thought that one is a static method
19:48bhenryamalloy: this isn't so hard (defn pow [x y] "x to the y" (apply * (repeat y x)))
19:48amalloykutku: you need to escape the \, i think
19:48AWizzArdTeXnomancy: no, not as you probably want
19:48kutkuohh, I need to import the function
19:49freakazoidbhenry: that would be quite slow
19:49freakazoidparticularly with bignums
19:49bhenryah true
19:54chouserTeXnomancy: you could use (PersistentVector/create the-array) and subvec that.
19:55chouseroh, nm
19:55TeXnomancychouser: thanks... I think I should be working with strings instead of byte arrays anyhow here in retrospect
19:55chouserthat used to return a PersistentArrayVector or something I think -- now it's basically just (into [] the-array)
19:58AWizzArdwhat about a (vector-of :byte)?
19:59AWizzArd,(doc vector-of)
19:59clojurebot"([t]); Creates a new vector of a single primitive type t, where t is one of :int :long :float :double :byte :short :char or :boolean. The resulting vector complies with the interface of vectors in general, but stores the values unboxed internally."
20:09karmazillaare there any known issues with the combination of defprotocol, reify and AOT compilation?
20:10scgilardimail
20:38kutkuhttp://pastebin.com/hLwXBy38
20:38kutkuthat outputs to console right, how do I output to file?
20:42bhenry,(doc spit)
20:42clojurebot"([f content & options]); Opposite of slurp. Opens f with writer, writes content, then closes f. Options passed to clojure.java.io/writer."
20:43kutkuI was thinking about using Java I/O
20:46bhenrykutku: http://gist.github.com/487537
20:46bhenryyou should get the idea from that
20:49kutkutxh
20:52kutkubhenry: I found this code online, how can I use it?
20:52kutkuhttp://pastebin.com/edW73fi5
20:53bhenrylooks like that's how you'd create an output stream without using clojure.java.io/output-stream the way i did in that gist.
21:22gilbertleunghi
21:22gilbertleungis there anyway to "throw an error" in clojure
21:22scottj(Exception.)
21:26ataggart(throw (Exception.))
21:28scottjI always forget that part :)
21:29kutkuim suprised that you don't need a println or system.out to print strings in clojure
21:31scottjhow do you print them w/o a println?
21:31kutku(defn is-small? [number]
21:31kutku(if (< number 100) "yes" "no" ))
21:32kutkuor maybe im missing something here
21:32scottjit just displays in the repl
21:33scottjit wouldn't actually print to the screen in a running program
21:33kutkuwhat's the difference?
21:33kutkuoh..
21:33kutkuit's like printing to console
21:34scottjit's like a function that returns a string
21:34scottjs/like//
21:34sexpbot<scottj> it's a function that returns a string
21:41ataggartanyone know of non-trivial examples/documentation for compojure?
21:44kutkusrsly, what does this mean: This is an example of a side effect. The println doesn’t contribute to the
21:44kutkureturn value of is-small? at all. Instead, it reaches out into the world
21:44kutkuoutside the function and actually does something.
21:50amalloykutku: functions return things. in an ideal world, what they return would be the thing they did
21:51amalloyif the behavior of functions depends on, or influences, external factors, then it becomes much harder to confirm that they will always do what you expect
21:52amalloy*would be the ONLY thing they did
21:52kutkuok makes sense thanks
21:55kutkuwhat does conj do?
21:56amalloy,(doc conj)
21:56clojurebot"([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."
21:56kutkutx
21:56kutkuthx
21:57kutku.... (recur (conj result x) (dec x))))
21:57kutkuwhat triggers first, dec or conj?
21:57amalloykutku: conj, probably, but it doesn't matter because neither of them has side effects
21:58kutkuhmm, I need to get into that way of thinking
21:58kutkuI would of guessed dec, conj and then recur
21:59blbrown_win3_can I do a static import on a class in the default package. import static Function.compose;
21:59amalloykutku: in C, it would look like recur(conj(result, x), dec(x)), right?
21:59kutkuor ur right, they are paremeters to the function recur, so it does not matter
21:59kutkuya
21:59kutkuI see it now.
21:59blbrown_win3_well that is wacky. http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4989710
22:02amalloyblbrown_win3_: java discourages the use of the default package. if something doesn't work for the default package, you probably shouldn't be doing it anyway :)
22:07kutkuwhat is mutable
22:15kutkuwhat does it mean when they say "no direct mutable variable"
22:15amalloykutku: modifiable
22:15kutkuthx
22:16brweber2hey, anyone around?
22:16amalloykutku: i'm not paying much attention to irc, but if you say amalloy it'll make some noise and i'll check back for your question
22:16kutkuthats very nice of you, thanks
22:27kutkuit is important that I cover metadata?
22:40amalloykutku: eventually, it's probably a good idea. but i have only a vague idea of how it works and i get by