#clojure logs

2010-11-21

00:17danlarkinjava crypto is enough to drive a person nuts
01:32livingstoncreating protocols and attaching them to classes / records is far easier than creating a ton of defmulti's but is there a way to put a default on a protocol function like I can for a defmulti, for something that doesn't have the specified behavior to return the default?
01:33technomancylivingston: you can extend Object.
01:33livingstonyeah i was thinking about that, but then I won't get all the native types? or will it autobox an int into an Integer to get the behavior?
01:34technomancyI think calls from Clojure would get autoboxed; I don't know about calls from Java
01:35technomancyISTR some discussion about the Conj re: reservations about extending Object, but I don't remember the details
01:36livingstonI think i'm ok with that... and the dispatch on protocols always picks the more specific type, if there are several applicable, I'm sure, right?
01:36livingstonoops I mean ok with clj code and java maybe maybe-not
01:37livingstonhmm maybe I should just keep this particular function as a defmulti instead of fighting with the protocol, since I pretty much want in to work for about anything
01:38technomancypersonally I find the semantics of defmulti to be much more straightforward
01:38technomancydefrecord attempts to straddle AOT and JIT worlds in ways that are still unpredictable to me.
01:40livingstonyes me too, but when you have a handful of functions that naturally fall in a group, then protocols seems pretty useful (I came from lisp, there was nothing like protocol it was all dispatch so I think that way)
01:40technomancyfor my purposes namespaces have served just fine as a way of grouping defmultis
01:41livingstonthe docs seem to imply if you can use protocols/records it's more efficient, but that's not exactly clear to me when there's still dispatch I would assume?
01:41technomancybut I could see the appear of the way protocols do it
01:41technomancyit's very rare for that level of optimization to be justified.
01:41technomancyunless you're writing clojure-in-clojure
01:41talios'lo technomancy
01:41technomancytalios: hi
01:43livingstontechnomancy: i don't have a problem grouping them or whatever, that's fine. some of what I'm working on will end up in pretty tight loops, if there's a bit to eek out of that, I'll take it now - why not, doesn't seem that much harder with protocols. but I hear you on defmulti just making sense
01:43taliosturns out spilling lemonade thru a macbooks keyboard isn't healthy for said macbook :(
01:43technomancytalios: time to get a thinkpad--built-in drainage in the keyboard =)
01:44livingstontalios: bummer. yeah and they don't have drains, because I'm sure Steve Jobs thinks things like drains and vents are ugly
01:44talioslivingston: yeh - hopefully the insurance will come thru and pay for a replacement ( which I could then upgrade to something more decent as well ).
01:44taliosdraintrays would be a wonderful thing. I see the new HPs have them too.
01:45livingstonI like my mac book. some things like that just make sense. like the mac power connector. there should just be basic things always included.
01:46technomancythey are nice, but I also like the fact that I can buy three thinkpad power supplies for the price of one apple power supply =P
01:46taliosthankfully I have 98% of everything backed up, and thankfully co-podcaster richard loaned me his old macbook pro. so at least I can continue to do stuff
01:47technomancysurely liquids can't damage the drive?
01:47livingstonit's not the power supply it's your laptop that goes flying when someone trips over the cord
01:47taliosI should be able to get the data off it. will find out when I get the machine back from the store where I was getting a repair/insurance quote
01:48livingstonyeah I would think last resort you could pull the drive. even if it had a drain there'd be some disassembly involved anyway to clean something like lemonade.
01:48technomancylivingston: I guess that would be a bummer if your laptop wasn't indestructible =)
01:49livingstontechnomancy: I've seen it happen more times than it should at conferences, sucks every time
01:49technomancyI have a 6-ft standing desk; I've pulled my laptop off it twice (from the ethernet cord, ironically) without a scratch.
01:50taliosimpressive
01:50livingstonlucky. hopefully your drive readheads parked themselves in time - you won't see the scratches there ;)
01:56technomancytalios: I was up really late last week and couldn't help being struck by how quiet things are on freenode in your timezone.
01:58taliosmmm, most of the people I know on IRC pride themselves with their idle times anyway :)
01:58taliosundernet seems to get more NZ users ( or used to at least ).
01:59livingstontalios: that's funny. I can't run idle we have it blocked at work, and this web client will crap out sooner or later.
01:59taliosI find it depends on the channel. Trying to get anyone from the codehaus servers to respond during my "awake" is impossible
02:00talioslivingston: ssh+irssi ;-)
02:00technomancyeven better: ssh+free EC2 micro instance
02:01taliosaltho now you've made me think about the time I realise it's past dinner time - no wonder i'm hungry :)
02:01livingstonI was just going to say I don't have anywhere to ssh to, but that's an interesting option
02:02technomancyfree for a year
02:02technomancycheck out http://github.com/dysinger/nanosat
02:02livingstona better client would be better, but running idle offers no major advantage, I mean it's all archived on the net
02:02technomancyyou can even get the machine provisioned using clojure
02:02technomancyERC works great on EC2
02:03livingstontechnomancy: what's ERC?
02:04trybeingarunEmacs Relay Chat
02:05livingstonoh right, yeah I started off looking into using that, and then found out about the silly firewall - "only "hackers" and bots use IRC, can't possibly be useful" -- I said, "I know, I'm a hacker - you've hired one, now help me out."
02:06technomancywell if they allow SSH then it's game over
02:06technomancyno point in blocking anything
02:07hiredmanssh even has a built in socks proxy
02:07technomancyheck; you can run an SSH server on the HTTPS port and get around anything
02:08taliostcp/ip over dns works as well :-) slow as all hell, but works.
02:08talioshttp://analogbit.com/tcp-over-dns_howto
02:08livingstonyeah, their avg. user doesn't know that here though. I don't know how smart their firewall is though, it may look for odd traffic like that.
02:08hiredmanit sure is slow
02:08technomancyor ICMP
02:10livingstonif it's something that's needed you can file paperwork and get it eventually - you should have seen what was involved for a skype exemption -- meanwhile I can just use webchat
02:10technomancygrumble... still no paredit 22 in elpa.
02:10technomancyI really need to get my own package server working.
02:10taliosbbl - going to find some dinner. I'm thinking Thai.
02:11hiredmantechnomancy: I built the latest emacs and the paredit from the starter kit stopped working (looked like a conflict with a paredit that came with emacs)
02:11technomancyparedit comes with emacs now... !
02:11technomancywat
02:12hiredmanmaybe, I did look that into it, I uninstalled the elpa paredit, stopped getting warnings, and still have paredit
02:12hiredmanI did not look
02:12hiredmanor something
02:12technomancyI'm not seeing it; must have been an older manual install
02:13technomancythe one in elpa is so old it doesn't really work with {} =(
02:13hiredmanright
02:13hiredmanand whatever I have now does
02:14technomancythe latest one has a new feature where you can configure it to sorta even work in JS without inserting those annoying spaces
02:16hiredmanweird, I cannot find a predit file in the emacs src, or in my .emacs.d, but I have predit
02:18technomancyM-x locate-lib
02:20hiredmanugh, it is in my .emacs.d, but I was running find $PWD, and $PWD was a symlink, so fail
02:36livingstoni hate having to either forward declare things or write code that seems upside-down.
02:43livingstonrecords will behave just like maps when it comes to accessors and keys, right?
02:44hiredmanrecords don't extend IFn if I recall
02:45livingstonhiredman: ok so you just have to make sure to do (:keyword record) instead of the other way around, right?
04:10fbru02Hi anyone around ?
04:11kumarshantanuhi, can somebody tell me if this is the right way to pass type hints? -- (fn [^java.util.Map m k] (.contains m k))
04:12kumarshantanuI am getting warning though
04:20livingstonyou can try putting the hint in the (.contains call
04:21livingston(.contains ^hint m k)
04:24kumarshantanulivingston: still not working :(
04:24kumarshantanu(fn [^java.util.Map m ^String k]
04:24kumarshantanu (.contains ^java.util.Map m ^String k))
04:37notsonerdysunnycan somebody help me understand clojure.zip/seq-zip with an example?
04:40_atokumarshantanu: java.util.Map has no .contains method
04:40_atohttp://download.oracle.com/javase/6/docs/api/java/util/Map.html
04:44kumarshantanu_ato: you are right! (wondering why .contains works nevertheless)
04:45kumarshantanu_ato: I changed it to .containsKey and it no more gives a warning
04:46_atomust be whatever concrete class is being passed in does have a .contains and Clojure is finding it via reflection at runtime
04:47kumarshantanu_ato: right
05:02fbru02hey can somebody try this and see if this is also failing for you?
05:03fbru02https://github.com/alexott/clojure-libs/blob/9a6bbe7b7cd1c299d05863d8c82ef2468cf0e706/mahout/project.clj
05:26Vinzentfbru02: yes
05:27fbru02Vinzent: cool , I thought i was the only one that got that failing , thanks
05:32Vinzentnp
06:44LauJensenI justed released a new jar on clojars in which ClojureQL now supports joins on multiple tables
06:44LauJensens/justed/just/
06:44sexpbot<LauJensen> I just released a new jar on clojars in which ClojureQL now supports joins on multiple tables
06:46_ulisesmorning all
06:55fbru02LauJensen: Cool
07:04fbru02i have a mvn question, i'm using lein, and i have a project that needs some other project. This second project has a pom with dependencies etc. Do i have to specify all the deps for the second project in my first project or is there a way of mvn/lein knowing how to resolve those?
07:06_atomaven/lein will do transitive dependency resolution. So if project A depends on B and B depends on C, then A will pull in C as well without you having to specify it explicitlyfff
08:01raekhrm, why do I get "Can only recur from tail position" when I do (when-let [y (f x)] (recur ...) (...))?
08:02raekah, nevermind...
08:02raek*if-let*
08:37joeyd81Hi, there has to be a better way to do AOT compilation than what I do : echo "(compile 'explore.perm)" | clj_compiler
08:38raekwhat is clj_compiler?
08:39raekI would use one of the build tools (Leiningen or Cake)
08:39raekwith Leiningen, it would be "lein compile", I think
08:40joeyd81exec java -server -d64 -cp ${JAR}/clojure-contrib.jar:${JAR}/clojure.jar:${JAR}/
08:40joeyd81jline-0.9.94.jar:/opt/clojure jline.ConsoleRunner cloj
08:40joeyd81ure.main $*
08:41joeyd81I am calling this stuff from within a Makefile
08:45kumarshantanucan anybody tell me if it's possible to type hint object arrays (non-primitive arrays)?
08:49edbondhow to println in -main?
08:55raekedbond: (defn -main [] (println "hello")) ?
08:58edbondraek, ha this doesn't print anything
08:59raekit will only print when -main is called. in what situation do you want it to be called?
08:59edbondraek, oops I use printf not println
09:00raek-main is usually for when you AOT compile your project into a jar
09:00joeyd81how do you test for 2 things being identical vs. equal in clojure?
09:01raekjoeyd81: identical? is for object identity
09:01joeyd81in Ocaml you have physical equality (==) vs. structural equality (=)
09:01raekjoeyd81: = means value-based equality for immutable types and identity-based equality for mutable types
09:02raek(this is the semantics for types introduced by clojure. for java types, = means java .equals and identical? means java ==)
09:02joeyd81I definite identical thus - the 2 things have the same address in memory and are equal, vs. equal - different addresses in memory
09:03raekjoeyd81: then clojure.core/identical? fits your definition of identical
09:03joeyd81ok, cool is there sugar for it?
09:04raekoh, sorry. I misinterpreted you statement. identical? is only same address in memory
09:05raekbut how could they not be equal if they are the same object?
09:05raek,(= [1 2 3] [1 2 3])
09:05clojurebottrue
09:05raek,(= [1 2 3] '(1 2 3))
09:05clojurebottrue
09:05raek,(= (atom [1 2 3]) (atom [1 2 3]))
09:05clojurebotfalse
09:06raek,(identical? [1 2 3] [1 2 3])
09:06clojurebotfalse
09:06raekyou could see = as sugar for identical? if you are comparing reference types
09:07joeyd81so when I store an object into a collection the address of it is stored, not the object itself, seems to me
09:07raekyes
09:07raekon the JVM, only primitives are stored themselves
09:07joeyd81good, thanks a lot raek
09:07raekobjects and arrays are reference types
09:09raektwo sequential collections are = if they are = element-wise and of the same size
09:09raek,(let [a (atom 1)] (= [0 a 0] [0 a 0]))
09:09clojurebottrue
09:10raek0 = 0, because they are the same value, a = a because they are the same object
09:10joeyd81then what is == used for
09:11joeyd81in clojure?
09:13joeyd81it seems to me that == is used solely for numerical comparisons in clojure
09:13edbondjoeyd81, read http://clojuredocs.org/clojure_core/clojure.core/==
09:14raek,(= 1 1.0M)
09:14clojurebotfalse
09:14raek,(== 1 1.0M)
09:14clojurebotfalse
09:15raekI have never used ==
09:15joeyd81ok, enough dumb questions for today, thanks everyone
09:15jarpiain,(== 1.0M 1.00M)
09:15clojurebotfalse
09:17raek~source ==
09:27joeyd81actually 1 more question and no more - how can I unify the repl definitions of -main and the AOT compiled version of same? Here is what I mean, in the repl the definition is (defn -main [args] .....) and it gets called (-main *command-line-args*) VERSUS compiled code the definition is (defn - main [& args] ......) . As you see args are passed in differently, hence I can't have the same -main code
09:28raekwhat code calls (-main *command-line-args*)?
09:28raek'cause that should indeed be (apply -main *command-line-args*)
09:28joeyd81The repl calls it
09:28raekleiningen?
09:28clojurebothttp://github.com/technomancy/leiningen
09:28joeyd81no, I don't use leinigen just yet
09:28raekhrm
09:29raekhow do you launch clojure?
09:29joeyd81java -server -d64 -cp ${JAR}/clojure-contrib.jar:${JAR}/clojure.jar:${JAR}/jline-0.9.94.jar:/opt/clojure jline.ConsoleRunner clojure.main $*
09:29raekso clojure.main calls the -main function?
09:30joeyd81yes I think
09:30raekthat's odd
09:30raekhow does it now in which namespace it should look for the -main var...=
09:31joeyd81I don't know but it looks like the answer is to call (apply -main *command-line-args*), I will give this a try
09:31raekwhat is in the $* variable?
09:31joeyd81represents the args to the -main
09:32raekyes, but what args do you pass it?
09:32joeyd81the argv[] array from the C world
09:34raekjoeyd81: is there any (-main *command-line-args*) call in your code?
09:34jarpiain,(doc clojure.main/main)
09:34clojurebot"([& args]); Usage: java -cp clojure.jar clojure.main [init-opt*] [main-opt] [arg*] With no options or args, runs an interactive Read-Eval-Print Loop init options: -i, --init path Load a file or reso...
09:35joeyd81I paste that code into the repl after the -main definition: (-main *command-line-args*)
09:35raekah.
09:36joeyd81but you said it should be (apply -main *command-line-args*) if -main takes [args] instead of [& args]
09:36raekyou should probably do something like ... clojure.main -e "(use 'the-namespace) (apply -main *command-line-args*)" ...
09:36raekif you have a call to -main in the source file, that will be run at *compile time* when you AOT compile your source
09:37joeyd81ok, let me give it a try, this chat room is awesome
09:37raek:)
09:38raekthere is a lein-run plugin for this (will be a part of leiningen itself in the next release, I think), if you happen to start using leiningen later on
09:43fbru02_ato: thanks for your answer I just came back to the computer
10:11cljbiehi everyone.
10:12cljbieanyone here also using python?
10:12cljbiepython has dir() method which lets me see what methods and attributes an object has, does clojure have anything like that?
10:15yacincljbie: maybe show in clojure.contrib-repl-utils?
10:16cljbieyacin: i only have clojure and don't know what that is
10:17yacinhow did you install clojure?
10:17yacinbut i'm sure show is what you want
10:17yacin,(show "str")
10:17clojurebotjava.lang.Exception: Unable to resolve symbol: show in this context
10:18yacin,(use 'clojure.contrib-repl-utils)
10:18clojurebotjava.io.FileNotFoundException: Could not locate clojure/contrib_repl_utils__init.class or clojure/contrib_repl_utils.clj on classpath:
10:18yacinhmm
10:19yacin,(use 'clojure.contrib.repl-utils)
10:19clojurebotjava.io.FileNotFoundException: Could not locate clojure/contrib/repl_utils__init.class or clojure/contrib/repl_utils.clj on classpath:
10:19cljbiethere is "inspect"
10:19cljbiei found that hmm
10:21yacin,(use 'clojure.contrib.shell)
10:21clojurebotjava.io.FileNotFoundException: Could not locate clojure/contrib/shell__init.class or clojure/contrib/shell.clj on classpath:
10:21yacinhmm, guess you can't import contrib
10:21yacinanyway, repl-utils' show is what you want
10:21yacinuser=> (show "str")
10:21yacin=== public final java.lang.String ===
10:21yacin[ 0] static CASE_INSENSITIVE_ORDER : Comparator
10:21yacin[ 1] static copyValueOf : String (char[])
10:21yacin[ 2] static copyValueOf : String (char[],int,int)
10:21yacin[ 3] static format : String (Locale,String,Object[])
10:21yacin...
10:23raek$(use '[clojure.contrib.repl-utils :only (show)])
10:23raek&(use '[clojure.contrib.repl-utils :only (show)])
10:23sexpbotjava.io.FileNotFoundException: Could not locate clojure/contrib/repl_utils__init.class or clojure/contrib/repl_utils.clj on classpath:
10:23raekwell, the bot's are limited... :)
10:25SergeyDHi! Is there a better way to translate [[3 4 5]] into [3 4 5] than "(apply map identity [[3 4 5]])" ?
10:25yacin,(flatten [[3 4 5]])
10:25clojurebot(3 4 5)
10:25cljbiethanks yacin
10:25yacinnp
10:25SergeyDoh, thanks :)
10:25yacinnp :)
10:26yacinor i guess you could just use first
10:26SergeyD,(first [[345]])
10:26clojurebot[345]
10:41cljbieyacin: i have a list. how can i loop through all of the elements and sum them all up?
10:43trybeingarun(defn sum-list [lst]
10:43yacin,(reduce + [1 2 3 4 5 6])
10:43clojurebot21
10:43trybeingarun(reduce + l))
10:45yacinthere's no reason to make a separate function
10:45yacinreduce is clear enough, imho
10:46trybeingarunyep. my bad :)
10:59cljbiealright :)
10:59cljbiei've written my first clojure function
10:59kumarshantanuis a type hint in a macro passed to ~@body ?
11:01cljbieyacin: http://paste.pocoo.org/show/294246/
11:01cljbie:)
11:02cljbiea question here. if i wanted to store "(+ 1 (count others))" part in a variable, how should i have done it and how could i use it in the calculation?
11:03raek(let [c (inc (count others))] ...calculations...)
11:05raekanother slight variation would be to let the function take a sequence rathern than multiple arguments
11:05trybeingarunThere is a version of reduce function which takes 3 args, [fn val coll] which is also useful
11:05raek(defn avg [coll] (/ (reduce + coll) (count coll)))
11:07raekcljbie: also, you usually indent like this: http://pastebin.com/dzTYsevH
11:07trybeingarunmake sure that you handle the case of empty collection, where (count coll) is 0
11:08raektwo spaces for def* forms and closing parens not on separate lines
11:09bhenryraek: (defn avg [& args] (/ (reduce + args) (count args))) would look nicer when calling imo
11:09silveenI'm trying to get ClojureQL running, but I'm getting SQLExceptions, "no suitable driver found". Any know anything about this if there's anything I've missed?
11:09bhenryi'm just coming in, so maybe i missed an important part of the discussion
11:09raekdepends on whether you make the call manually or get a sequence of values from somewhere else
11:10cljbiethanks raek
11:10trybeingarunOr trust your ide for indentation :)
11:11raekyes, you shouln't have to indent your code manually...
11:11raeki emacs: select the code and press tab
11:11cljbiei have not setup my vim for clojure yet
11:11trybeingarunMe 2 emacs!
11:11trybeingarunhow is vim's clojure support?
11:11bhenryM-q for the win.
11:11silveentrybeingarun: it's terrible
11:12cljbiethere is vim-clojure which i have not tried yet
11:12silveenI got slimv running last night. But it causes the entire window to flash like a disco lamp.
11:12trybeingarunI find emacs' clojure support very good
11:12trybeingarunI, however am facing a huge pain point
11:12silveenvim-clojure requires that dreadfull Nailgun server running
11:12trybeingarun(read-line) is not working in emacs
11:13trybeingarunAnybody managed to fix that (read-line) problem in emacs?
11:15trybeingarunraek: Dude, do you have any suggestions for (read-line) issue?
11:15kumarshantanuasking again...is a type hint in a macro passed to ~@body ?
11:16trybeingarunAt least in my setup (read-line) is not taking any user input
11:16raekyes, I never got that to work. but then, I haven't needed it yet
11:16trybeingaruncan you please share how you got that to work?
11:17trybeingarunI am sorry. Din't read ur reply properly. OOPS!!
11:19raekmaybe you could do something like (binding [*in* System/in] (read-line)) and type it in the swank terminal
11:19raekit's too bad that the swank protocol is mostly undocumented...
11:20trybeingarunlet me see if it works...
11:21trybeingarunwhat is the advantage of nRepl?
11:21raekhrm... how does one get the root binding of a var when it has a thread-local binding...
11:21raekit is a replacement for swank
11:22trybeingarunhm
11:22raekone of its goals is that it should be usable from any IDE
11:22raekand built for clojure
11:22trybeingarunthen that should be awesome!!
11:22raek(future (def in *in*)) ;; ouch!
11:23raek(binding [*in* in] (read-line))
11:23raekhrm... that didn't work
11:24trybeingarunI am getting an error saying "in" is not defined
11:24trybeingarunSystem/in is also not working for me
11:25raekbbl
11:25trybeingarun(future) What is that call? Never heard of that...
11:28bhenry,(doc future)
11:28clojurebot"([& body]); Takes a body of expressions and yields a future object that will invoke the body in another thread, and will cache the result and return it on all subsequent calls to deref/@. If the com...
11:28bhenry&(doc future)
11:28sexpbot⟹ "Macro ([& body]); Takes a body of expressions and yields a future object that will invoke the body in another thread, and will cache the result and return it on all subsequent calls to deref/@. If the computation has not yet finished, calls to deref/@ will block."
11:31trybeingarunThanks
11:44hiredman http://byteworm.com/2010/11/21/the-fastest-vm-bytecode-interpreter/ cute
12:25mrromanhi, i'm here first time.
12:26mrromani've got problem with using clojure.string
12:26tonylwelcome
12:26mrromani've got clojure 1.2 and i tried to start example of clojure.string/split from clojuredocs
12:27mrromanand i've got error message java.lang.ClassNotFoundException: clojure.string (NO_SOURCE_FILE:0)
12:28tonyldid you (use 'clojure.string) before calling it
12:28tonylsince it is in another namespace
12:29mrromanyes, but i used full path to function, clojure.string/split
12:29tonylor better use require since some functions' names would collide
12:29mrromanok
12:29hiredmanmrroman: clojure namespaces have to be explicitly loaded
12:30mrromanou
12:30mrromanok, thanks for help
12:30tonylhiredman: I never understood why is that, do you know?
12:32hiredmantonyl: I imagine the ultimate answer is it makes distinguishing between vars and classes easier for the compiler
12:32mrromanBTW, great number of members, 256
12:33mengu_what is the difference between (use 'clojure.inspector) and (:use 'clojure.inspector)?
12:33kumarshantanuis it possible to type hint non-primitive arrays?
12:33hiredman(:use 'clojure.inspector) is incorrect in all cases
12:33hiredman(use 'clojure.inspector) may or may not be
12:34hiredmankumarshantanu: yes but it is rarely useful
12:34kotarakkumarshantanu: ^"[Lyou.custom.Class;" the-array
12:34kumarshantanukotarak: I am trying the same technique, but it still warns me for reflection
12:35kotarakmengu_: use is a standalone function, :use is only used in the ns clause, :use is without '
12:35kumarshantanuhiredman: I am calling a Java method that accepts arrays
12:35hiredmankumarshantanu: ah
12:35mengu_kotarak: thats why :use did not work when i tried it then
12:35kotarakkumarshantanu: might depend on other arguments?
12:36kumarshantanukotarak: certainly not -- but curiously (1) that technique works for ^"[Ljava.util.Map;" but not for ^"[Ljava.lang.Object;" and (2) I am doing this inside a macro
12:38kotarakkumarshantanu: because you hint (unquote x). the list. Not x itself. You have to do ~(with-meta x {:tag 'String}) ....
12:39kotarakkumarshantanu: shameless self-promotion (although a little out-dated by now): http://bit.ly/a51mbM
12:41kumarshantanukotarak: what is {:tag 'String} for?
12:42kotarakkumarshantanu: This is was ^String does.
12:42kumarshantanuah
12:42kotarakkumarshantanu: ^String is short for ^{:tag String}
12:43kotarakkumarshantanu: Uh. I even had your problem as an example at the end. :)
12:44kumarshantanuso, for ^"[Ljava.lang.Object;" it should be {:tag '"[Ljava.lang.String;"} ?
12:44kumarshantanukotarak: it's working !!
12:44kotarakyup
12:44kotarak\o/
12:45kotarakActually without '
12:45kotarak'"bla" and "bla" are the same
12:46kumarshantanukotarak: thanks! I was struggling for the past two hours and finished watching a movie meanwhile due to frustration :)
12:46kotarakkumarshantanu: hehe :) That's a good approach. I do the same from time to time. :)
13:17rdeshpandehowdy
13:23mengu_hi rdeshpande
14:33LauJensenIm looking for a simple solid introduction to log4j logging on Tomcat - Got link?
14:37nickikdoes anybody know when the clojure conj videos will be available?
14:41raeknickik: here. have a strange loop talk by chouser while you wait. :-) http://www.infoq.com/presentations/Clojure-Expression-Problem
14:42nickiki allready watched that.
16:52joeyd81I still can't get my simple permutations program to work, http://pastebin.com/UrRfi124
17:00tufflaxjoeyd81 btw normally people don't have spaces between '(' and the operator, as on you line 4, and not newlines after ( and [ as in your line 12 and 13. And they normally just stack up ) behind each other, not using newlines for each like you have on lines 24-26. And I don't think it's a good idea to use defn within another function, use let or letfn instead.
17:01tufflaxI'll try to see what's wrong with your program but your style confuses me :P
17:01joeyd81ok, thanks for the feedback, I will rework it soon, I am just a newbie and the syntax betrays that
17:03tufflaxusing defn within a function doesn't work as you think, probably. I think it "creates" the function in the namespace just as if you had written it outside the function, but only when you run the function that contains the inner defn. So it's a side effect of running the outer function.
17:04joeyd81ok, so you're saying that I should replace it with letfn? Earlier I put it inside the let binding but the compiler complained that 'permute' is undefined
17:05_atoput all your functions at the top-level and use (declare permute) before (defn gen-perms ...) so that gen-perms knows permute exists
17:05tufflaxYes... It should work fine. Paste the code again if you change it and then get errors
17:06joeyd81ok, I will change it soon as you suggested but the stylistic issue aside, it would still yield the wrong answer
17:08ossarehjoeyd81: also, I think your recursion is done incorrectly. If the JVM had TCO then you can recurse as you are on line 23, however since it doesn't then in theory you could overflow the stack - this is what loop / recur is for, and given that you could in fact have your permute fn in the let before it.
17:09ossarehI guess, said a little more concisely, the assertion in the comment on line 10 is incorrect; your recursion is implemented in correctly.
17:10joeyd81ok, give me 5 minutes to move it in a letfn declaration and repost
17:11tufflaxjoeyd81 or do what _ato said, move the functions out completely
17:12ossarehtufflax: assuming there is a benefit to having a global var for that fn, then yes that is a good idea too.
17:12joeyd81but I like inner functions that refer to the closure in which they are defined
17:12tufflaxjoeyd81 also, why do you have a function called main? It should be easy to test the individual functions in a REPL
17:13joeyd81I have used the repl repeatedly to test the smaller functions
17:14tufflaxok good
17:18Raynes_ato: It speaks!
17:18Raynes_ato: Haven't seen you in a while. :<
17:18joeyd81ok, I made the changes that you guys suggested and I still get the wrong answer, http://pastebin.com/qbztx8LE
17:20_atoRaynes: hi
17:21_atojoeyd81: hmm, the first thing I notice is that gen-subsets' base case is inconsistent:
17:21_ato(gen-subsets #{1 2}) ;; => ((1 (2)) (2 (1)))
17:21_ato(gen-subsets #{1}) ;; => (1 ())
17:21_atoshouldn't (gen-subsets #{1}) be ((1 ())) ?
17:23joeyd81ok, I am thinking about it, not ignoring you
17:26joeyd81added (list ....) to the base case (1 el in set) and still got the same result
17:33_atojoeyd81: http://pastebin.com/ph73mKC0
17:35joeyd81great, your program works! How could you print each permutation on a separate line (i.e. vertically instead of horizontally)
17:37_atojoeyd81: just call println on each permutation?
17:37_atoeg: (dorun (map println (permute (range 1 4))))
17:38joeyd81ok, you're great, I am going away now to study your code, thanks and see you guys later
17:52tufflaxI'm using vimclojure with the nailgun server to get a repl. And then I try to eval "(ns pe)" by sending with <leader>et and it gives me the following error: java.io.FileNotFoundException: Could not locate pe__init.class or pe.clj on classpath... Writing it in the REPL works though. Does anyone know what's wrong?
17:54kotaraktufflax: you have to have the appropriate files set up on your classpath
17:55kotaraktufflax: vc reads the namespace to provide things like omnicompletion and such.
17:55tufflaxBut what's the difference between writing in into the repl by hand and sending it with <leader>et
17:55tufflaxok
17:55tufflaxhm
17:56kotaraktufflax: exactly that: writing in the repl does nothing but the command. Sending \et loads the namespace. Because vc can't know what you send, it has to set up everything so that all required functions are in place.
17:57tufflaxok, thank you
18:10jimdueyjoeyd81: I'm stepping into the middle of your conversation, but do you know about clojure.contrib.combinatorics?
18:10jimduey(use 'clojure.contrib.combinatorics)
18:11jimduey(println (interpose \newline (permutations (range 1 4))))
18:11joeyd81no, thanks for the link. I was just in the process of learning clojure by way of writing simple programs, that's all
18:11jimdueyexcellent. good way to start.
18:17CaseyShello all
18:51rata_hi
19:07ossarehI wonder why so many people use macro's where a fn would suffice.
19:07ossarehIs there some fundamental misunderstanding about macros?
19:09zakwilsonI think the misunderstandings are usually related to what can be accomplished with an ordinary function.
19:09joeyd81hey guys, does clojure support eta reduction, example of something I want to reduce is this: (my-map [f colls]
19:09joeyd81 (if (> (count colls) 8) (pmap f colls) (map f colls)))
19:09Rayneszakwilson: Indeed. You can be *really* creative with functions to accomplish things that you might assume are only possible with macros.
19:10Rayneschouser: Demonstrated this on the hotel shuttle at the Conj that I happened to be on when he and a group were off to the car rental place. He pointed out how 'or' and 'and' could be implemented using normal functions.
19:10Raynes<3 chouser
19:11zakwilsonI think the Right Thing is to do whatever is easiest to understand. Usually, that's a normal function, not a macro, but if lots of trickery is required for the function to work, go with the macro.
19:12_atoRaynes: they're implemented as macros so that they can short circuit. eg (or (foo) (bar)) doesn't need to execute (bar) if (foo) returns true. You can't do that with a function (unless you changed 'or' to take functions instead of values)
19:13Raynes_ato: I know. That's what I just said.
19:13RaynesWell, I didn't explain myself, but that's what I was talking about.
19:13_atoah, I see
19:13rata_is there anything like Python's "template %s" % ("strings") ?
19:13RaynesHe was talking about how and and or could be written as functions that take functions.
19:14_ato,(format "I %s food" "food")
19:14clojurebot"I food food"
19:14_atoRaynes: ^
19:15Raynes_ato: I'm not rata_
19:15rata_hahahaha thanks =)
19:15zakwilsonA lot of things we do with macros require macros because macros let you evaluate some or all arguments lazily. Haskell can do them without macros because it's lazy by default. It is also possible to do similar things with ugly syntax in any language that lets you pass something resembling a thunk.
19:15_atodamn.. channel is getting too crowded (ra<tab>) ;-)
19:16joeyd81Hey guys, what is a better way to write this function, so that repetition is reduced (defn my-map [f colls] (if (> (count colls) 8) (pmap f colls) (map f colls)))
19:17zakwilsonThat's pretty succinct as it is. What would you like to not repeat?
19:18joeyd81the args f coll
19:18ossarehagreed, only thing I see is potentially providing the map function - but then you start to introduce ambiguity
19:20_ato(defn my-map [f colls] ((if (> (count colls) 8) pmap map) f colls))
19:20_atoI prefer the original though
19:21joeyd81yes, you nailed it _ato, that's what I was looking for
19:21zakwilsonYou could write a macro somewhat resembling ->, which I'll call -:/ for purposes of this discussion that would allow you to write (defn my-map (-:/ [f colls] (count colls) pmap map)), but that would be pathological.
19:23joeyd81:), macros are too advanced for me, I'll study them in the context of a DSL implementation in clojure of a non-lisp language, if there is one such implementation pls feel free to provide a link
19:25dnolen,(let [x 5 y 4] `(+ ~x ~y))
19:25clojurebot(clojure.core/+ 5 4)
19:26joeyd81example: the DSL is the syntax in which you write Makefiles, input is a makefile, output is the interpretation of the actions in it
19:26dnolenjoeyd81: think of macros as "HTML templating" for code. DSLs are not the only usecase.
19:28zakwilsonjoeyd81: a macro would let you write a shorter version of the function you gave as an example, but it would be a mistake to write one for that situation because it would make the overall system more complicated and longer. If you had to write 10 functions that looked almost identical, macros might make short work of it.
19:29joeyd81yes, I understand that application of macros but to be really impressed I want to see them used to implement a DSL for a simple non-lisp language, I just don't know of any such implementations though I'm sure they exist
19:32zakwilsonIf you're going to make a non-lisp language, you really need a parser, not macros.
19:35joeyd81I thought you could write something like this http://www.venge.net/graydon/talks/mkc/html/index.html in lisp/clojure easier than in any other language
19:35joeyd81with macros alone
19:38zakwilsonWell, you probably *could* write a DSL that has to be wrapped in (eval-my-dsl ...) without writing a parser, but it's probably not a good way to go about it.
19:40zakwilsonThe most common use of macros is to delay evaluation of an argument so you can write control structures like if and when. Other common uses include making a Lisp-like DSL that outputs a non-Lisp language and making a template for often-repeated code that can't be optimized away by other means.
19:41joeyd81camlp4 macros are not any more powerful than lisp/clojure macros, it seems, the reason I mention it is because I want to explore the depths of what is possible with lisp/clojure macros
19:42zakwilsonI have minimal experience with ML, but I suspect an ML macro system is more limited than Lisp macros.
19:42zakwilsonFurthermore, Clojure macros are more limited than Common Lisp macros.
19:42joeyd81Yes, that's my point too. So if that guy in the link can write a DSL with camlp4 macros, the same should be possible with clojure
19:43joeyd81I just want to see a common lisp or clojure example of something like that
19:44zakwilsonI just picked a random slide and he was talking about writing a recursive-descent parser, which suggests that he DID use a parser.
19:46joeyd81he is not, camlp4 is the macro facility employed by the ocaml system, he is using a lexer but no parser
19:53zakwilsonhttp://www.venge.net/graydon/talks/mkc/html/mgp00021.html <-- here, he says he's using a recursive-descent parser. He uses pa_extend to write the parser, and while pa_extend comes with camlp4, it's not inherently part of a macro system; it's a parser library.
19:56joeyd81Just like in clojure macros have a narrower scope of application that you pointed out above, so does camlp4 primarily defined syntax extensions to the core language and is rarely if ever used for anything else. The guy who wrote the slides points out that it could be used for more than just staying within the confines of ocaml.... So I am not yet convinced that clojure macros may not be used to go outside the confines of the core langua
19:58joeyd81but I am not an expert on these matters, I just wish that an example would be provided in lisp or clojure of how you could do that, if it's possible
20:09zakwilsonjoeyd81: Clojure macros can't replace the entire syntax of the language directly. It looks like camlp4 can, but what it's doing is essentially the same as (eval-my-dsl (read some-file))
20:17joeyd81@zakwilson, so are you implying then that it's possible to write macros in clojure that implement a DSL, where neither the input is clojure nor the output is clojure? In the slides the input is a makefile, the output is an executable a.out program
20:20zakwilsonjoeyd81: it's possible, but the only reason to base the design of such a system around macros is to demonstrate that you can. The Right Thing is to write a parser and a code generator. Both will probably make use of macros to some degree.
20:22joeyd81I tend to agree that it's not the Right Thing to do but if there is such an example in Lisp or Clojure I'd love to study it because it pushes the limits of what is possible to achieve with macros
20:26jweiss_is there doc somewhere on how to get gen-class to add annotations? i saw some old mailing list posts, but I'm not sure if that was the proposed solution or the real deal
20:27jweiss_perhaps it works just like this? https://gist.github.com/377213
20:28zakwilsonjoeyd81: See an implementation of the Common Lisp loop macro for an idea of how to evaluate non-lisp inside a macro body. After that, it's just a matter of calling your macro on a list of the results of calling read on your non-lisp file until you hit EOF, though there are some limitations.
20:31joeyd81thanks zak, will definitely study it
20:33zakwilsonjoeyd81: another thing that's important to understand is that camlp4 seems to be a preprocessor, which is a bit different from Lisp macros. You could certainly write a Clojure program (with or without macros) that reads a file containing code written in a DSL, compiles that code to Clojure and uses that Clojure to spit out another language (though your OCaml example really only does the latter because the OCaml compiler can output C natively)
20:36joeyd81ok
21:17livingstonI have a multi method, lets call it foo for select user defined / 3rd party classes foo needs to do something but for all clojure native types foo can be the identity function. I can make that the default behavior but then I lose the fail-fast checking on when foo isn't implemented for a 3rd party type -- thoughts?
21:23livingstondo all the clojure native types implement any particular protocol/interface that I could dispatch on?
21:24tonylvar maybe
21:25tonylIVar
21:26livingstoni would assume that's only for vars? I'm more looking for the clojure-only equivalent of Object.
21:27jarpiainlivingston: http://tinyurl.com/clojure-classes
21:27jweiss_i cannot figure out how to get annotations onto the class i'm generating with gen-class. the classes always end up without them. is this supported?
21:29livingstonjarpiain: wow there's a lot of detail in there thanks.
21:30livingstoniObj may be what I want... although I still have to stare at that for a long time to be sure that java classes don't implement that too.
22:08ossarehother than java interop is there much benefit to a record over a structmap ?
22:08livingstonossareh: compiled in type information
22:09dnolenossareh: java interop is not the main benefit of records
22:09livingstonossareh: see the discussion here: http://clojure.org/datatypes
22:10dnolenossareh: consider structmap a legacy feature, you should just records here on out.
22:10dnolens/just/just use
22:12ossarehdnolen: thanks, so it turns out it is a performance thing too it seems?
22:12livingstonis there a way from the repl to see what interfaces/protocols an object instance is implementing?
22:12ossareh"one need not leave Clojure to get the highest-performing data structures possible on the platform."
22:12joshua__What is the best way to deal with forms when using appengine/compojure/enlive?
22:12dnolenossareh: yes that's another benefit
22:12rata_livingston: (supers (class thing))
22:13livingstonthat's not showing me any protocols there should be at least two in this guys list
22:14rata_livingston: well, I don't know what are you looking at, but (supers (class [])) shows every interface vectors implement
22:15dnolen,(supers (class []))
22:15clojurebot#{java.util.List clojure.lang.Seqable clojure.lang.Reversible clojure.lang.IEditableCollection clojure.lang.Sequential java.io.Serializable clojure.lang.Associative clojure.lang.IPersistentStack cloj...
22:16livingstonI have an instance of a Record, (show _) reports the correct type, (supers (class _)) doesn't give me the protocols I have attached to it, and I have extended two onto it at least
22:19_atoI don't think there's an efficient way to do it, since :impls is stored with the protocol, not the other way around
22:20livingstonso it's the protocols that know who implement themselves but no way to get from an object to a list of protocols (kinda makes sense since protocols don't monkey patch)
22:21_atoyeah, if you look at the source for extends? for example: https://github.com/clojure/clojure/blob/master/src/clj/clojure/core_deftype.clj#L444
22:21hiredmanprotocols don't create an is-a relationship
22:22livingstonmakes sense I suppose, I was just layering up a few of them on a thing, and I just want to make sure I was getting what I thought I was getting, and was hoping for some debugability even if ineffecient - oh well
22:27livingstoninteresting as a further oddity, if package foo has protocol P and record R it's foo/P and foo.R which is another differentiator between protocols behaving like classes/interfaces...
22:27hiredmanpackage?
22:27clojurebotamespaces are (more or less, Chouser) java packages. they look like foo.bar; and corresponde to a directory foo/ containg a file bar.clj in your classpath. the namespace declaration in bar.clj would like like (ns foo.bar). Do not try to use single segment namespaces. a single segment namespace is a namespace without a period in it
22:27hiredmansurely you mean namespaces
22:28livingstonhiredman: yes
22:28hiredmanwell then why didn't you use the word "package"?
22:30hiredmandid
22:31livingstonso if the protocol implementation isn't with the record, why is this more efficient, there's still dispatch right? or can the compiler find it ahead of time with type hints?
22:31livingstonor is the efficiency of protocols/records only in that the records can have accessors etc. compiled in?
22:33livingstonhiredman: I still think in common-lisp, the word is package over there -- force of habit
22:34_atolivingston: there's some discussion about it here: http://groups.google.com/group/clojure-dev/browse_thread/thread/59d2f3a1703cc09
22:35livingston_ato: thanks for the pointer, I'll look that over
22:37_atokind of cryptic, but basically, yes you're right that you get maximum performance from a inline definition (like a class implementing the protocol's interface, which presumably deftype does). But the protocol also caches the last used implentation, which should help the common case for extending after definition
22:41livingstoninteresting. so if I put the protocol implementation on with a defrecord I'll get better performance than if I do it with an extend?
22:54_atolooks like it
22:56livingstonI would not have expected find to do what find does, I was expecting more of a common-lisp find, although clj find happens to do exactly what I need
22:57livingstonmultiple return values would be really useful right about now too..
23:03livingstonwhat's the preferred idiom for mapping a function that could produce nil and removing the nils? (remove nil? (map fcn data))
23:05_ato,(doc keep)
23:05clojurebot"([f coll]); Returns a lazy sequence of the non-nil results of (f item). Note, this means false return values will be included. f must be free of side-effects."
23:05_atolivingston: ^
23:06livingstonthat's an extremely non-intuitive name, but ok.
23:06livingston_ato: thanks
23:06_atoheh, I agree about the name
23:07livingstonkeep sounds like it should be the opposite of remove and shouldn't inherently accumulate/map too
23:08tomojkeep? since when?
23:08tomoj,(:added ^keep)
23:08clojurebotUnmatched delimiter: )
23:08livingstontomoj: apparently 1.2
23:08tomojshucks
23:08tomoj,(:added (meta keep)) ;?
23:08clojurebot"1.2"
23:09tomojcool
23:09livingstonmy version of slime doesn't even recognize it as a reserve word (I probably need to update)
23:09tomojeh
23:10tomojI've come to accept that random colors will show up inexplicably
23:10livingstonthere have been a lot of weird names added with stuff like that, I was following the discussion and gave up (the intent was to be intuitive but many are not: find, keep, etc.)
23:10tomojfind too/
23:10tomoj?
23:10tomoj,(doc find)
23:10clojurebot"([map key]); Returns the map entry for key, or nil if key not present."
23:10tomojoh
23:11livingstonyeah that's the function I wanted, but I went looking for a "find" expecting to have to wrap it myself around a map
23:11tomojnaming is hard :(
23:14livingstonyeah, there's some stuff that's really confusing to me (lisp people?) in there, but it is what it is
23:15_ato'keep' needs a succinct name or you may as well just do (remove nil? (map ...)). I can't think of anything intuitive that's succinct
23:15livingston_ato "mapcon" ;)
23:16livingstoner mapcan I meant
23:18livingstonI wonder if the compiler is smart enough / produces equally efficient code for keep and (remove nil? (map ... ?
23:18_atohehe, intuitive for a common lisper maybe, but not for me
23:19_atonah I don't think the compiler's clever enough to avoid the intermediate lazyseq objects
23:19livingstonI'm not actually lobbying for that but it's not bad, it's basically "map" + "concatenate"
23:19_ato,(doc mapcat)
23:19clojurebot"([f & colls]); Returns the result of applying concat to the result of applying map to f and colls. Thus function f should return a collection."
23:19livingstonand it has parity with mapcar (map through the car (first) elements of a list) which is clojure's map
23:21livingstonyes mapcat is cl:mapcan - the 'n' was also used as a flag for being destructive in lisp, I don't know why.
23:27livingstonI wished the compiler would warn at least on non-local non-special variable being present in a function - dumb me just lost 30 min because I cut and paste some code that used a different variable name
23:51Deranderlivingston: does seem like that should be possible to statically check
23:52livingstonIt's possible I've corrupted my repl enough too that it hallucinated a bound symbol there too, but yeah