#clojure logs

2010-11-20

09:58defnlet the +b's commence
10:03krumholthi is there a way to create the primitive datatype byte in clojure? when i do (byte 1) i get a Byte not a byte
10:04Chousukekrumholt: it's a byte, but when you pass it to a function it gets boxed
10:04krumholtcan i prevent that?
10:05krumholtim reading image data and its really slow. i think boxing every byte is the problem
10:06Chousukeyou need a primitive array or a vector I suppose
10:06Chousukeno way to do primitive function args in 1.2
10:07krumholtbut i could use a native array?
10:07Chousukeremember to remove reflection first though.
10:07Chousukethat's usually the biggest slowdown
10:07tonylwhat about (.byte
10:07tonylwhat about (.byteValue (byte 1))
10:08Chousuketonyl: that's even slower :P
10:08Chousukeit gets boxed just to call the method on the Byte, and then it returns the byte
10:08krumholtChousuke, uh thanks. i added #^java.lang.Byte and the speed increased by 1000%
10:08tonylyeah true mmm...
10:08Chousukekrumholt: hehe
10:09krumholtit went from 14 seconds to 1,8 seconds
10:09BahmanHi all!
10:23Chousukekrumholt: It's good to bind *warn-on-reflection* to true when developing :)
10:23krumholtChousuke, i will do that thanks
10:24Chousukein the repl you can actually use set! to set it to true, so you don't need binding
10:27krumholtChousuke, thanks for answering my next question before i could ask it :)
10:28cmiles74Does anyone have a Clojure language handler for Google Code Prettify?
11:03Lajlaraek, but if it works, then surely it must be just a reader thing, right?
11:03LajlaAnd that means that rich LIES on his page.
11:03LajlaRich' Shadow deserves no worship then
11:08Chousukewtf are you talking about? :P
11:10LauJensenLajla: You should really try out scala and #scala - report back here in 18 months :)
11:12LajlaChousuke, what constitutes a symbol on clojure.
11:12LajlaThe point is that the main page says that symbols can't contain spaces et cetera or . or what-not.
11:12LajlaBuuut
11:12LajlaMy claim is that that is just reader praecidence.
11:13LajlaLike (symbol "I worship his shadow") works.
11:13LajlaAnd (symbol? that) answers true.
11:13LajlaAlso,
11:13Lajlayou can even use eval on that
11:14LajlaLike (let [funnysymb (symbol "I worship his shadow")] (eval (list (symbol "defn") funnysymb [(symbol "x")] (symbol "x"))))
11:14LajlaAnd then you can actually use (eval (list (symbol "I worship his shadow") 3)))
11:16ChousukeLajla: that's because there is no validation of symbols
11:16Chousukethe symbols are illegal still
11:17Chousukeas in, you're not supposed to use them
11:17Chousukebecause then things might break
11:35LajlaChousuke, what things?
11:35LajlaIf some things might break then, some one should mail rich to tell him that his type safety sucks an instead he should learn finnish to talk with me and Chousuke about deer and shadows to worship
11:37ChousukeLajla: it's not a type safety problem
11:37ChousukeLajla: it's just there being no check against the user creating stupid symbols
11:39LajlaChousuke, I'd say that's a type safety problem. symbol claims to output symbols from strings, if you give it input from which it cannot produce a symbol, it should produce a runtime error.
11:39LajlaInstead of just going on with it and producing something which is apparently 'garbage'
11:39ChousukeLajla: well, duh
11:39LajlaWhich strangely eval also accepts.
11:39LajlaA bit sloppy, some would say.
11:39LajlaBut I think
11:39ChousukeLajla: the thing is, no-one has yet come up with a patch to implement such validation
11:40tonylLajla: are you joking around or is this for real?
11:40Lajlathe best wat is to just let symbols contain any and all characters strings can contain.
11:40Chousukeand since it's not a big issue, there's no rush to implement one
11:40LajlaAnd just have no reader syntax for it.
11:40Lajlatonyl, I am f0 real.
11:40tonylok
11:40LajlaI am very theoretical.
11:40LajlaI like to know the finer things about programming langauges before I write a Hello World.
11:40LajlaLike these things
11:40tonylhehe that is interesting
11:41LajlaI am very interesting.
11:41LajlaNahh, I actually tried out in C if "string"+1 did what I expected it to do before I wrote a hello world.
11:41ChousukeLajla: Allowing arbitrary characters has also been considered.
11:41LajlaChousuke, what were the arguments against?
11:41ChousukeLajla: but since it has so far been a non-issue, it's not implemented
11:41LajlaI think in most lisps they say that arbitrary chars can make symbols, but there is just no reader synta for it.
11:42Chousukeno arguments, just that no-one has had a need for the feature.
11:42LajlaChousuke, well, it seems to work so far, do you have a place where it might screw you up?
11:42ChousukeLajla: the "screw up" is that symbols with whitespace in them are not readable
11:42LajlaAhh
11:42Lajlayou mean writing and then reading?
11:43Chousukeie, you can't do (read-str (pr-str weird-symbol))
11:43Lajla&(write (symbol "I worship your shadow"))
11:43sexpbotjava.lang.Exception: Unable to resolve symbol: write in this context
11:43Chousukeand get weird-symbol
11:43LajlaYeah.
11:43Chousuke,(print (symbol "foo bar"))
11:43clojurebotfoo bar
11:43LajlaAhhh, print.
11:43Chousukesee the problem? :)
11:43LajlaClojure makes no difference between write and print, like cl does?
11:43ChousukeI'm not sure what the difference is in CL
11:43LajlaWell, does clojure make the claim that reading back always gives the same as what you print?
11:44Chousukeno
11:44Chousukethere's pr
11:44Chousuke,(pr "foo")
11:44clojurebot"foo"
11:44Chousuke,(print "foo")
11:44clojurebotfoo
11:44LajlaWell, basically write gives out the 'external repraesentation' and print accepts only strings and chars I think.
11:44LajlaAhh
11:44Lajlathen pr is write
11:44LajlaBut like
11:44Lajla&(pr (fn [I-worship-your-shadow] (+ 3 I-worship-your-shadow)))
11:44sexpbot⟹ #<sandbox6621$eval8180$fn__8181 sandbox6621$eval8180$fn__8181@110710>nil
11:45LajlaIf I read that back in
11:45Lajlado I ge the same function back?
11:45LajlaDoes it guarantee that in each case, you get the same thing back?
11:45Chousukeno
11:46Chousukesome things are not readable.
11:46Chousuke(#<foo>)
11:46Chousuke#< throws an error if you try to read it
11:46LajlaBut does it guarantee it for symbols?
11:46Chousukefor legal symbols yes
11:47LajlaHmm
11:48LajlaAnd does the symbol function guarantee that ...
11:48Lajlawho am I kidding man
11:48LajlaI'm talkinga bout a language which has no formal specs.
11:48LajlaBut a 'reference implemtnation'
11:48LajlaThere are no guarantees, carry on, carry on, every bug is a feature.
11:48ChousukeYou need to be less theoretical :P
11:50LajlaThat comes as no surprise from someone who believes in conceptual programming. =)
11:50LajlaBut hey, your Finnish is very good.
11:51LajlaI just like to know these things before I start, I don't like to hack and slash around before I know exactly what mechanically is supposed to happen with my code.
11:51LajlaAnd since Cloj has no specs, I'm just reverse-engineering it by using the bot.
11:51ChousukeMy Finnish is good because I am Finnish :P
11:51Chousukethough on second thought, that is no guarantee
11:55trybeingarunhey guys
11:56trybeingarunDo monads and continuations have any practical value or are they simply theory stuff?
11:56trybeingarunI am having a headache trying to understand them.
11:59trybeingarunanybody there?
11:59Chousukesure they have applications
11:59Chousukeyou can think of monads as an API
12:00Chousukefor composition
12:00Chousukeof operations
12:00LajlaChousuke, do you have good finnish for a fin though?
12:00LajlaHigh literary standard?
12:00Chousukeyes
12:00LajlaHmm
12:00Lajlaclojure has monads and continuations?
12:00LajlaHow can continuations work if there is no TCO?
12:01trybeingarunWhy do i need an API for compositions when i can write small wrapper code and use them for compositions
12:01LajlaWouldn't that keep on infinitizing the stack frame.?
12:02trybeingarunDudes, before u guys go into depths of these can anybody point me to any useful tutorial (beginner friendly) which won't punch a hole though my brain??
12:03raektrybeingarun: this is a Clojure + monads tutorial I know of: http://onclojure.com/2009/03/05/a-monad-tutorial-for-clojure-programmers-part-1/
12:04raekI have never used monads in clojure so far myself, though
12:04trybeingarunhm
12:04raekoh wait... you wern't looking for a tutorial... sorry
12:05trybeingarunthanks raek. I will see how much I understand those concepts
12:05trybeingarunno. in fact I was looking for a tutorial
12:05raekas for continuations, clojure does not have a call/cc
12:06raekbut the ring web framework uses a control technique that I think is a bit similar to CPS
12:06trybeingarunokay.
12:09raeka handler is a function that takes a request map and returns a response map. a middleware fn takes a handler function and returns a new function
12:09raekthe reurned function will most often proxy the request to the given handler, but might also do something else (like render an error message)
12:10raek(defn some-middleware [handler] (fn [request] (if (valid-request request) (handler request) (render-some-error))))
12:10trybeingarunokay
12:10notsonerdysunnythe swank-clojure I am using, which is 1.3.0-snapshot, to try out the 1.3.0-alpha3 seems to be having problems .. Is anybody else facing similar problems?
12:19_ulisesafternoon gents
12:27Lajlaraek, but how does that work without TCO?
12:27LajlaI mean, obviousy loop/recur is a limit example of continuations, all languages have them, but when people say 'continuations', they generally mean 'fully general continuations'
12:27Lajlalimited
12:35raekLajla: you can only have limited levels of nesting, due to the lack of TCO
12:36Lajlaraek, but continuations are abstracted as ordinary functions, right?
12:36LajlaCPS would fill the stack pretty fast.
12:37LajlaI am a theorete and feel no shame!
12:40raekyes
12:43Lajla&(+ 1 "string")
12:43sexpbotjava.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Number
12:43LajlaHmm
12:43Lajlano "tring" like in C
12:43Lajla&(+ "string" "string")
12:43sexpbotjava.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Number
12:43Lajlahmm
12:43Lajla&(+ \a \b)
12:43sexpbotjava.lang.ClassCastException: java.lang.Character cannot be cast to java.lang.Number
13:21LajlaChousuke, can you cite me the part where it makes that reader / pr guarantee for legal symbols?
13:31LajlaChousuke, totele minua, sinä orjani.
13:32mattmitchellis there a library that will take a url/string and parse it out into fields like, host, path, query etc.?
13:33technomancy,(bean (java.net.URL. "http://technomancy.us:80&quot;))
13:33clojurebotjava.lang.reflect.InvocationTargetException
13:33technomancyಠ_ಠ
13:33Raynes(bean (java.net.URL. "http://technomancy.us:80&quot;))
13:33Raynes&(bean (java.net.URL. "http://technomancy.us:80&quot;))
13:33sexpbot⟹ {:path "", :protocol "http", :authority "technomancy.us:80", :host "technomancy.us", :ref nil, :content #<HttpInputStream sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@9d4b24>, :class java.net.URL, :defaultPort 80, :port 80, :query nil, :file "", :userInfo nil}
13:33technomancyaha
13:34RaynesThat's pretty cool.
13:34DeranderI wish map but for hash-map values was in core
13:35mattmitchellwow awesome thanks!
13:35technomancyclojurebot: clearly you need to lighten up a bit.
13:35clojurebot1
13:36rata_hi
13:36rata_which fns can give me a PersistentList when I give it a LazySeq?
13:37ChousukeLajla: there is no such guarantee.
13:37ChousukeLajla: except that if you don't use illegal symbols, you won't get any illegal symbols from pr/read either.
13:37ChousukeLajla: the only way you can create an illegal symbol is manually by calling "symbol", so it's a non-issue
13:38Raynes&(type (into '() (lazy-seq [1 2 3])))
13:38sexpbot⟹ clojure.lang.PersistentList
13:38RaynesThat doesn't quite work like you might expect.
13:38Raynes&(into '() (lazy-seq [1 2 3]))
13:38sexpbot⟹ (3 2 1)
13:38technomancyrata_: you don't want just doall?
13:39technomancyyou shouldn't care about the class, just whether its contents have bene realized
13:39technomancy*been
13:40chousera PersistentList though is different than a seq. Knows its count, for instance.
13:40chouser& (apply list [1 2 3])
13:40sexpbot⟹ (1 2 3)
13:40technomancytrue
13:41rata_technomancy: the bottleneck of my program was a the function rand-nth, then I change to use it vectors for fast random-access, but now the bottleneck is vec :(
13:42thearthurwhere can I find out more about the new contrib modular structure (google is failing me)?
13:43thearthurwhen i build from github i get a modules directory and am not sure what to add to classpath where in order ot use it
13:43raekrata_: if you are using lazy seqs, nothing will get computed until it is needed
13:43LajlaChousuke, but where is that written?
13:44raekrata_: rand-nth or vec might be the first functions that need the values, and in the calls to them, the seq will be forced
13:44LajlaMissä se on kirjoitettu? =(
13:44raekrata_: you could try to add (doall ...) around each thing that returns a lazy-seq to see where the bottleneck really is
13:45rata_raek: I think it's easier to use visualvm to detect the bottleneck... it doesn't fail in saying that most of the time the program was computing vec or rand-nth
13:46ChousukeLajla: nowhere, it's obvious
13:46ChousukeLajla: the reader is not stupid, nor is pr :P
13:47ChousukeLajla: though if you can find a way to get the reader to produce an illegal symbol, report that as a bug
13:49LajlaChousuke, then where does it say that such symbols are illegal?
13:50LajlaI mean, whence can you deduce that because the reader can't read them they are illegal.
13:50rata_Raynes: I'm not using (into '() ...)
13:50Lajlaa lot of lisps explicitly state that various data do not have a reader syntax, but are still valid data.
13:50rata_do you know of any other fn that can return a PersistentList from a LazySeq?
13:51ChousukeLajla: that's the definition of illegal :P
13:52Chousukerather, the docs state what is legal
13:52Chousukeand everything else, even if it happens to work when you call symbol, is illegal.
13:52raekrata_: what would be the benefit of making a PersistentList from a LazySeq? constant time count?
13:52LajlaChousuke, maybe the docs conflict
13:53LajlaFor instance, what do the docs say about the symbol? procedure
13:53Chousuke(doc symbol?)
13:53clojurebot"([x]); Return true if x is a Symbol"
13:53LajlaIf the docs say at one hand that symbols cannot contain spaces, but at the other hand THAT THERE ABOVE
13:53LajlaTHen obviously the docs contradict itself.
13:53rata_raek: no... I don't want it to be converted... but somewhere in my code a fn is converting it
13:53ChousukeSymbol, not a symbol
13:53LajlaAhh
13:53LajlaHmm
13:53Chousukethat means it returns true if it's an instance of the class.
13:53LajlaAhhh
13:53LajlaSo Symbol and symbol are destinct?
13:53chouserraek: Did you see that (apply list a-seq) returns a PersistentList?
13:54LajlaSo, symbol in fact returns a Symbol?
13:54Chousukeyes
13:54LajlaAhhh
13:54ChousukeLajla: in a way, because you can have instances of Symbol that represent illegal symbols
13:54LajlaI can live with that.
13:54Chousukebecause there's no validation (yet)
13:54LajlaFuck symbols
13:54LajlaI like Symbols more.
13:54chouserrata_: sorry, that was for you not raek
13:54LajlaThey can do more.
13:55rata_chouser: yes, but I'm not doing that either
13:55chouserrata_: how do you know you're getting a
13:55chouserPersistentList?
13:55rata_there's a function in my code that's converting my LazySeqs to PersistentLists
13:55rata_with class
13:56raekchouser: btw, is your extend-multimethod macro that you mentioned in your strange loop talk availabe somwhere?
13:56chouserraek: I'll look.
13:57chouserhm, is there a way to grep all versions of all files in a git repo?
13:59rata_I'm just using map, keep, conj and remove over my LazySeq afaik, yet I get a PersistentList
14:00raekconj will preserve the type, the other will produce lazy-seqs, IIRC
14:00chouserconj on a lazy-seq returns a Cons
14:01rata_yes, but Cons is not PersistentList
14:01rata_this conversion thing is so weird
14:04raekchouser: don't worry if you don't find it. i just thought it was an interesting idea, and I think it would be pretty easy to write myself
14:04Chousukechouser: git has a grep command I think.
14:04Chousukechouser: maybe you can use that?
14:06Lajla&(pr (symbol "I worship His Shadow"))
14:06sexpbot⟹ I worship His Shadownil
14:06Lajlanil
14:06Lajla?
14:06LajlaOhhhh
14:06Lajlareturn value.
14:06LajlaYou sort of would want like nil on failure or something.
14:06LajlaOr like
14:06Lajlanil on success, and some error message on failure.
14:06LajlaYeah, that'd work too.
14:12Lajla&nil
14:12sexpbot⟹ nil
14:12Lajla(symbol? 'nil)
14:13Lajla&(read-str (pr-str (symbol "nil")))
14:13sexpbotjava.lang.Exception: Unable to resolve symbol: read-str in this context
14:13LajlaHmm...
14:13LajlaChousuke, what'sthe name?
14:15raekread-string
14:15raekhrm. that's a bit asymmetric
14:22Lajla&(read-string (pr-str (symbol "nil")))
14:22sexpbot⟹ nil
14:22Lajla&(symbol? (read-string (pr-str (symbol "nil"))))
14:22sexpbot⟹ false
14:23Lajlaraek, =(
14:23LajlaIt is true
14:23Lajlaraek, let's talk about our love.
14:25tonylpr-str returns a string not a Symbol
14:25tonylwait scratch that
14:26tonylnil is not a Symbol :P it's a value
14:27Chousukenil is null
14:27tonylyeah
14:27Chousukeit's not a symbol at all
14:27Chousuke'nil is nil too
14:27Chousukestill not a symbol :)
14:28jackdempseychouser: making my way through the joy of clojure. great stuff!
14:29ChousukeWhen was the dead-tree version supposed to be ready?
14:29RaynesI still haven't finished that book.
14:30jackdempseyyea, it's been a nice progression from programming clojure to practical clojure, and now some joy
14:31jackdempseyi need to stop reading and code something tho :-)
14:31jackdempseyanyone around SF and going to the meetup in a few weeks?
14:31Lajlatonyl, that was the point
14:31LajlaBut (symbol "nil") is a symbol
14:31Lajla&(symbol? (symbol "nil"))
14:31sexpbot⟹ true
14:31LajlaWell, evaluates to
14:31Lajlatechnically it's a list
14:34LajlaChousuke, what is the environment that eval uses though?
14:34LajlaJust the top level?
14:34Lajla&(eval '(and 1 2 3 4))
14:34sexpbotjava.lang.SecurityException: You tripped the alarm! eval is bad!1
14:34LajlaHmm
14:35LajlaInterestng
14:36chouserjackdempsey: thanks!
14:36chousertoday I'm updating the lazy qsort code -- cgrand improved it.
14:37ChousukeLajla: yeah
14:37LajlaChousuke, does it also expand macros?
14:37LajlaAnd can you give it an environment argument?
14:37chouserChousuke: Hopefully January or before for the book
14:37ChousukeLajla: yes?
14:37ChousukeLajla: no env arg
14:38Chousukechouser: ok
14:38Lajla=(
14:38LajlaI want you as my environment baby
14:38LajlaIf you get what I mean
14:38Chousuke:P
14:39LajlaChousuke, I wasn't talking to you
14:39LajlaI was talking to myself.
14:39LajlaNarc
14:39LajlaYou're so full of yourself.
14:39tonyl(symbol "nil") is a Symbol but once you pass it to pr-str it becomes a string "nil" which read-string evaluates to nil
14:40jackdempseychouser: is there a site setup to report typos and such?
14:40chouserjackdempsey: yes, the Manning forums. But if I were you don't know that I'd bother right now.
14:41jackdempseychouser: ok...? :-)
14:41chouserThe version you can get is a bit out of date regarding typo fixes and stuff -- that's mainly what we're doing right now
14:41jackdempseygiven they're probably all....yea
14:41jackdempseyk
14:41chouserthe opportunity to contribute in that way has essentially passed
14:42jackdempseycool
14:42chouserwhen then "final" version is out in a couple months here, we can start collecting errata for subsequent versions. :-P
14:42apgwoz2does clojars not allow you to change your password/key?
14:42jackdempseythx btw for writing something beyond a beginning/primer. its hard to get deeper into newer languages at times, so the pace and depth of getting into things has been great
14:42jackdempseycool
14:42chouserbut hopefully anything you're finding now has already been fixed
14:43jackdempseyyea i'd imagine so
14:43Chousukedamn ustream. Causes Flash to gobble gigabytes of memory :/
14:43chouserjackdempsey: thanks, glad you're enjoying it.
14:43ChousukeI just closed firefox and Freed 2GB :P
14:43apgwoz2i should rephrase my question, is clojars currently broken when it comes to editing password/public key?
14:55dnolenapgwoz2: it seemed to be working last time I had to do that.
14:56apgwoz2dnolen: hmmm. i'm getting an error for both email address and password not being set... but even when they're not.
14:56apgwoz2oh well
14:56apgwoz2in lieu of just publishing to clojars, what's the best way to depend on another library with leiningen?
14:56dnolenapgwoz2: lein install
14:57dnolenapgwoz2: just get a checkout of the library source, and run lein install from it's dir
14:58apgwoz2ah, ok. and then just add it as a dependency?
14:58dnolenapgwoz2: yup
14:58apgwoz2easy enough
14:58apgwoz2thanks
14:59shafiahmedbdHi
15:02shafiahmedbdDo you know of any clojure web scraper?
15:02apgwoz2shafiahmedbd: checkout tag soup
15:03shafiahmedbdThanks
15:03apgwoz2there's also https://github.com/brool/beaujiful-soup, which is a more clojure like lib for using tag soup
15:05bobo_shafiahmedbd: enlive can be used for scraping aswell
15:07Lajlatonyl, sure, but were were testing that.
15:07LajlaMaybe a reader syntax like |nil| would be nice.
15:07LajlaTell Rich to add it.
15:07LajlaI will hug you all day long.
15:13raekshafiahmedbd: enlive even uses tagsoup under the hood
15:14dnolenshafiahmedbd: enlive is probably best for easiest scraping, you can pull out elements with CSS3 syntax.
15:15Lajla&(eval 3)
15:15sexpbotjava.lang.SecurityException: You tripped the alarm! eval is bad!1
15:15dnolenCSS3-like, with some interesting additions
15:15LajlaHow can I get eval to work?
15:15raekLajla: java -jar clojure.jar on your own computer
15:16Lajla=(
15:16LajlaBut I wamnt to steal your cycles.
15:16LajlaI don't have the JVM installed right now.
15:27mattmitchellin ruby, you can do something like: my_hash[:key] ||= [] -- which sets :key to a new array if :key is nil, is there something like this in clojure?
15:30Lajlamattmitchell, if there isn't, you can write a macro I guess.
15:31LajlaBut I guess it will more be like
15:31raekmattmitchell: (assoc m (get m key []))
15:31Lajlareturning nil if it's not nil, and already exists.
15:31LajlaAnd return the updated, if it didn't already exist.
15:32raek(assoc m key (get m key []))
15:32raeksome had a neat example using update-in and fnil
15:33mattmitchellexcellent thanks
15:34mattmitchellwould someone mind taking a stab at this? https://gist.github.com/708130
15:34mattmitchelli'm messing with reduce now, just trying to learn how it works. i think reduce is the right way?
15:35raekI guess you could use merge-with in this case
15:36raek,(merge-with concat {:id 1, :f ["a"]} {:id 1, :f ["b"]})
15:36clojurebotjava.lang.IllegalArgumentException: Don't know how to create ISeq from: java.lang.Integer
15:36raekoh, sorry
15:37raekhrm
15:37mattmitchelldon't be, merge-with is something i'm looking into now
15:38raekit would work if you had the data on the form {1 ["a"]} {1 ["b"]}
15:39mattmitchellraek: i see
15:40dnolen,(merge-with concat {1 "a"} {1 "b"} {2 "c"})
15:40clojurebot{2 "c", 1 (\a \b)}
15:41dnolen,(let [f (fn [a b] (if (vector? a) (conj a b) (conj [a] b)))] (merge-with f {1 "a"} {1 "b"} {2 "c"}))
15:41clojurebot{2 "c", 1 ["a" "b"]}
15:44mattmitchelldnolen: thanks, i'll have a play with that
15:44raek,(reduce (fn [m [id f]] (assoc m id (conj (get m id []) f))) {} [[1 "a"] [1 "b"] [2 "c"]])
15:44clojurebot{2 ["c"], 1 ["a" "b"]}
15:45raek,(reduce (fn [m {:keys [id f]}] (assoc m id (conj (get m id []) f))) {} [{:id 1, :f"a"} {:id 1, :f "b"} {:id 2, :f"c"}])
15:45clojurebot{2 ["c"], 1 ["a" "b"]}
15:47raek,(map (fn [[id fs]] {:id id, :f (vec fs)}) (reduce (fn [m {:keys [id f]}] (assoc m id (conj (get m id []) f))) {} [{:id 1, :f"a"} {:id 1, :f "b"} {:id 2, :f"c"}]))
15:47clojurebot({:id 2, :f ["c"]} {:id 1, :f ["a" "b"]})
15:47raekthere. :)
15:47dnolennice
15:48raekI would prefer using for here, but it gets messy do edit code of this length in one line...
15:48mattmitchellnice! that's a full days study lesson for me.
15:48raek(for [[id fs] result-of-reduce] {:id id, :f (vec fs)})
16:08raekhrm, the order doesn't matter, you could replace the (assoc m id (conj (get m id []) f)) part, with (update-in m [id] conj f), since nil (the default value for get) work as () with conj
16:09mattmitchellraek: ok i'll try that. now what if I had hash-maps that had lots of keys, but I only wanted to append the :f key into a vector, but keep the rest?
16:09mattmitchellraek: for a little background... this is a sql result set, using joins
16:13raekmattmitchell: how should {:id 1, :f "a", :x "y"} and {:id 1, :f "b", :x "z"} be merged?
16:13mattmitchellraek: oh they will always be the same values
16:13raekmattmitchell: also, have you checked out the new version of ClojureQL?
16:13mattmitchellraek: no, only using the clojure.contrib.sql
16:14mattmitchellraek: i'll check out ClojureQL
16:14raekhttp://bestinclass.dk/index.clj/2010/11/clojureql--1.0.0-now-in-beta.html
16:15mattmitchellthat's looking good :)
16:23Lajlaraek,
16:23Lajlaif I paid you handsomely
16:23Lajlawould you write a formal spec of clojure?
16:23LajlaThat answers all my problems
17:31LajlaChousuke, why aren't you in casual?
17:31LajlaWe miss you.
17:31LajlaWe're talking about you're high literary standard now.
17:45ChousukeLajla: your :P
17:45LajlaChousuke, that is because mine is bad. =(
17:45hippiehunterCan someone point me in the right direction? I'm trying to define and throw an exception, but clojure complains that it cant find the class. I'm using lein and I've tried setting the exception classes to be aot compiled but without any luck.
17:51raekhippiehunter: has the .class file appeared in the classes/ directory?
17:52hippiehunteryes
17:52raekhave you imported it in the clojure code?
17:53hippiehunteri have (:use [bla.bla myexception])
17:53hippiehunterin my ns
17:53raek(although, that shouldn't be needed, if you use the fully qualified name)
17:53raekah, since it's a java class and not a var in a namespace, you have to :import it
17:53raek(:import bla.bla.myexception)
17:54raek(assuming "myexception" is the name of the generated class)
17:54raeki.e. you should have a classes/bla/bla/myexception.class file
17:54hippiehunternow it just complains at the :import instead of where i try to instance it
17:54hiredmanhippiehunter: the problem is the clojure code that throws the exception is being compiled before the code that generates the exception
17:55hiredmanyou can use clojure.lang.Reflect (Relector?) to get around it
17:55hippiehunterin my project.clj I put the exception classes first in the aot list
17:55hippiehunteran based on the output to the console its making them first
17:55hippiehunterand*
17:55RaynesReflector is right
17:59hippiehunterwhen i do an import do i have to replace the -'s with _'s?
18:00hippiehunterlooks like yes
18:01hippiehunterthat is mildly unpleasant
18:05hiredmanyou can't have - in a java class name
18:07hippiehunterit seems inconsistant that i can define things with - in clojure but depending on how i use them it might not work
18:08hiredmanif you define something for java interop (a java class) you have to follow java rules
18:10hippiehunterI would agree with you but then it should be throwing an error at definition time when i do the :gen-class
18:11hippiehunteror possibly when I do (:import [bla.bla my-exception-with-dashes])
18:12hippiehunterwell i suppose it is throwing an error on the import its just not a very helpfull one, anyway thanks for the assistance
18:24harishtellaanyone know why I can't use "." as the function in map? (map . (repeat 2 javaclass) '(javafn javafn))
18:25RaynesBecause '.' is a special form.
18:25RaynesSpecial forms and macros cannot be used in places where functions can, like as the argument to map.
18:25harishtellaany other way to collect results from calling function on a java obj
18:25harishtelladifferent functions
18:28raekinstead of (map .method sequence-of-objects) you have to write (map #(.method %) sequence-of-objects)
18:28raeki.e. create an anonymous function that does the interop call
18:30harishtellaoh got it, thanks
18:46hiredman. is not a function, thats why you can't use it as one
18:47harishtellaanyway a can eval a set of symbols without applying the first symbol as function rule (foo bar) ; where foo and bar are strings
18:47harishtellaI want a seq of strings
18:49raekif you want to evaluate an expression that is given in string form, you could do something like (eval (read-stirng the-string))
18:50raekbut if you are writing a code-evaluating bot or something, you should use a sandbox lib (like clojail)
18:51raekharishtella: could you give an example of what your input look like, and what you want to get called?
18:55harishtella I should just ask my real question I trying to figure out;
18:56harishtella(def foo "Green") (map #(. foo %) '(toUpperCase toLowerCase))
18:56harishtellaand say I want a list back like ("GREEN" "green")
20:07ossarehis anyone able to explain why my meta data :foo exists sometimes and not others? https://gist.github.com/708322
20:08ossarehclj 1.2 fwiw
20:10raekto attach metadata, either do (defn ^{...} foo "docs" ...) or (defn foo "docs" {...} ...)
20:10raeknot the lack of ^ in the latter case
20:10raekstrange behaviour, though...
20:10technomancydoes anyone use the lein interactive task?
20:12technomancywell, if you do, try the latest git master; it's a lot nicer.
20:13ossarehso I guess in the case where I have no "docs" (the fn is super simple and the name describes it accurately) I have to do the ^{} version ?
20:13ossarehtechnomancy: I'll take a look - I'm not sure if I'm ready for a major upgrade though
20:14ossarehlast time I did that I lost a fair amount of time :/ (1.1 -> 1.2)
20:14technomancyossareh: you can keep 1.3.1 around for regular use; it's easy to just experiment with both in parallel
20:14ossarehI'm on 1.2
20:14technomancyright; you don't need to replace what you have is what I mean
20:14ossareh... partly because that is what lein gives me ;)
20:15technomancyoh, clojure 1.2?
20:15technomancyyeah, you can use lein with any clojure version, no upheval required
20:16ossarehyup, am aware of that - I'll give 1.3 a shot in the morning - right now I can just leave my meta data angle out
20:17ossarehraek: same flakiness https://gist.github.com/708322
20:52talios'lo
20:53ossarehwhat is the recommended way to get clojure mode into emacs these days? I last used elpa
21:17devinuswill clojure begin to implement more basic core functions for e.g. parsing integers and such as part of it's transition to clojure in clojure ?
21:19Lajladevinus, that is your burning issue with a langauge that does not yet support TCO?
21:19LajlaI'm so going to tell chousuke, and then he'll eat you. n.n
21:19LajlaAnd I will win
21:20Chousukedevinus: probably not until there's a real need for it.
21:21ChousukeLajla: and you need to stop being so annoying :P
21:23devinusChousuke: there was a blog post i read, i think it was coder who says py, on his thoughts on clojure i've gotta agree with. i don't care at all that it uses the jvm, i just hate how much it seems you use the jdk
21:23devinusneed a cdk :P
21:24Lajlajava digit ... konvention?
21:24LajlaWhat does the k stand for?
21:24Lajladevinus, you wil answer this quaestion, which since the dawn of times has been etched upon my mind.
21:24LajlaFor long I searched the answers which I need, so that I may give purpose to my own existence.
21:25LajlaI journeyed long across the stars, bore witness to the rise and fall of many a civilization, beheld the birth of negative suns.
21:25ChousukeYou're being stupid on purpose.
21:25Chousukeplease just stop.
21:25LajlaI just want ot know what jdk stands for. =(
21:26Chousukegoogle it :P
21:26Chousukedevinus: Writing wrappers for the jdk is not very productive.
21:26hiredmanChousuke: you can put him on ignore, I have, and I have clojurebot ignoring him, it's great
21:27Chousukedevinus: but if there's a real need for such a library I'm sure it'll get written :)
21:27devinusChousuke: sure, it'd feel pretty tedious
21:27ChousukeBut now I need to get some sleep :P
21:27devinusgnight
21:28ChousukeAlso, I wish the ustream flash player wasn't so horrible.
21:28Chousukeit gobbled up 2.5GB of memory and now my system feels like it's going through tar while everything is fetched from swap into memory again
21:29ChousukeIt must be doing something idiotic like caching the whole stream in memory or something
21:29Chousukebecause it never stops growing.
21:29Chousukeanyway, good night :P
21:46krumholtat what time will calls to java static methods evaluated?
21:46krumholt+be
21:55krumholtwhere can i find the source code for the dot macro?
21:55hiredmannot a macro
21:56Rayneskrumholt: It's a special-form, of which you cannot find the source. The implementation would be in Java.
21:56krumholtRaynes, and can i find the java code somewhere?
21:57RaynesSure, but I have no clue where. :\
21:57hiredmanit's a special form so it is implemented in the compiler
21:57RaynesRight, the compiler.
21:58krumholtok thanks
21:59Rayneskrumholt: All of the Java stuff is here: https://github.com/clojure/clojure/tree/master/src/jvm/
22:01paulrosaniahttps://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Compiler.java
22:01paulrosaniaL692
22:01paulrosaniaGood luck :)
22:05RaynesMy eyes!
22:06paulrosaniathere's a lot of commented-out code in there
22:22ossarehzz... 1.3.0-alpha3 returns nil on (meta some-fn-with-md)
22:22ossarehpreviously it would at least return :doc , :file, etc.
22:34ossarehOK, fixed - I was not prefixing my fn with #' - i.e. (meta #'some-fn-with-md)
22:49krumholtok i found my problem
22:49krumholtmacroexpand will create static fields?
22:50krumholtso if a class has static fields they will be created at macroexpansion time?
22:50hiredmannope
22:52joeyd81hi, in which clojure channel should beginners go?
22:53krumholtok import creates static fields?
22:53hiredmanno
22:54krumholthiredman, i wrote a simple testclass http://pastebin.com/t9QLtfQp
22:54technomancyjoeyd81: here is fine
22:54hiredmankrumholt: good for you
22:54krumholtevaluating (ns myns (:import Test)) will print output to the repl
22:55krumholtthe string "output"
22:55krumholtor "Test"
22:56hiredmanthat is not "creating" the static field, that is initializing, I suggest you google "static field initialization"
22:56krumholtok so import initializes the static fields?
22:57hiredmanno
22:57hiredmanwhich is why I suggested you google and read
22:57technomancyah static; a perfect "you keep using that word; I do not think it means what you think it means" example.
23:04krumholtok, so evaluation (ns myns (:import blub.Test)) will create the static fields of Test?
23:04krumholti was not expecting that
23:04hiredmanit does not
23:04krumholti just tried
23:05hiredmanthat is not "creating" the static field, that is initializing
23:05krumholtok it initizlises them. still not what i expected
23:06hiredmanwell, then you don't know anything about the jvm
23:07krumholtif i import something in java that will not initialise the static fields. the first creation of an object will
23:09krumholtor a static method call
23:13joeyd81Hi, I am a beginner trying to learn clojure by writing simple programs, for example all permutations of a collection. Can somebody tell me where I am going wrong in function "permute" on http://pastebin.com/LCSR3nwM
23:14technomancyjoeyd81: first thought: each defn should be independent at the top-level, not nested
23:15technomancyjoeyd81: the formatting of the code makes it hard to follow
23:16technomancyinside my-fun you should use destructuring instead of let-binding first and rest explicitly
23:17technomancyflat1 and my-fun would be easier to test if they were top-level defuns as well; perhaps private ones
23:17technomancyyou probably want apply concat instead of just concat on line 33
23:17technomancyis that enough? =))
23:18joeyd81thanks for the feedback, I will study it, can you just clarify what you mean by " should use destructuring instead of let-binding..."
23:19technomancysure. (let [[f & rst] param] ...) is the same as (let [f (first param), rst (rest param)] ...)
23:20joeyd81ok, cool thanks, I will be back here to seek help if I can't make progress by noon tomorrow, good night folks
23:20technomancyjoeyd81: it will be easier to debug if you write and test the smaller functions first
23:21technomancyand then compase them into larger pieces once you know they work
23:21technomancy*compose
23:21joeyd81I usually do that in the repl
23:21technomancysure; I just mean make sure the little pieces work before bothering to stitch them together
23:28tramzeeexit
23:28tramzeeexit
23:28tramzeequit
23:33krumholtok i found my problem. The RT looks up classes in the classForName method with Class.forName(name, true, baseLoader()) which will initialise the class. is there a reason this is done for import expressions?