#clojure logs

2011-05-07

00:01seancorfieldpr, prn, print, println, print-dup, pr-str, prn-str, print-str, println-str, print-simple, printf...
00:01technomancymakes it easier to spot stuff that only got checked in by accident
00:04technomancyanyone use native-deps and want to test something for me?
00:09trptcolini use prn almost exclusively too
00:10technomancywell if you do, please try the latest leiningen from git, it should handle them transparently
00:10trptcolinoh you meant the printing fn - i was talking about something else ;)
00:10trptcolin*rimshot*
00:15technomancyI'm confused... the native-deps task seems to be doing the exact same thing as the deps task.
00:16technomancyhttps://github.com/swannodette/native-deps/blob/master/src/leiningen/native_deps.clj where exactly is the "native" magic?
00:17technomancyoh, it's the unjar part; I see.
00:54technomancythat looks like it did the trick.
00:54miwillhiteIs the asterisk a convention for something?: (defn get-object*
00:56technomancymiwillhite: it means "this is like get-object, but not quite, and I couldn't come up with a better name for the function, so whatever."
00:56miwillhiteha okay thx
00:58TheMoonMasterMight sound like an odd question, but how would one turn a list of numbers like (1 2 3 4 5 6 7 8 9 10 11 12) into pairs of 6 like ([1 2 3 4 5 6] [6 7 8 9 10 11 12])?
00:59tomojis the last one supposed to have 7
00:59TheMoonMasterErm, yeah that was an accident, sorry, it's late.
00:59tomoj,(doc partition)
00:59clojurebot"([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 case there are not enough padding elements, return a partition with less than n items."
01:00TheMoonMasterThanks!
01:00tomojor perhaps partition-all
01:00TheMoonMasterI'll check it out, I appreciate the help.
01:02tomojor do you always want to split it in half?
01:02TheMoonMasterThat did exactly what I wanted it to do.
01:31semperosdlh: it actually put the repo inside the .git folder
01:31semperosso <project name>/.git/src, README, .git, etc.
07:08Matt324Newbie qn: I'm trying to follow some examples from http://lisperati.com/vijual/ at the repl. I've cloned the repo, run lein deps & lein repl, but I can't call any of the functions
07:09Matt324e.g. (vijual/draw-graph [[:a :b]]) gives "java.lang.Exception: No such namespace: vijual (NO_SOURCE_FILE:1)"
07:09raekMatt324: have you required the namespace? in clojure, namespaces are not loaded until needed.
07:11Matt324raek, Ah, right, thanks, that works now.
07:28kzarHas anyone used the google calendar api from clojure?
07:40kzar(nevermind I figured it out)
08:25kzarIf I want to use com.google.gdata.client.calendar.CalendarService, I should add (:import [com.google.gdata.client.calendar CalendarService]) in my ns declaration and then just refer to CalenderService right?
08:33raekkzar: yes, but with ( ) instead of [ ]
09:37gfrlogis it true that all the classic macro-hate doesn't apply to private macros?
09:39mduerksengfrlog: what is the "classic macro-hate?" :)
09:39gfrlogthe first rule of macro club is don't use macros
09:40raekit's not like some people simply hates macros, it's more like "The main reason for beginners is: you don't need it."
09:40raekthis is a very interesting thread re. eval, which has a very similar reputation: http://stackoverflow.com/questions/2571401/why-exactly-is-eval-evil
09:40gfrlogwell there was also some talk at the last conj about how it makes composability hard
09:41gfrlogwhich made me think that macros have at least two distinct usage -- one as API sugar, which the conj talk referred to, and the other as a private internal thing that just makes your own code succincter
09:42raekcouldn't those cases be the same?
09:42gfrlograek: not if one is inherently public and the other is inherently private
09:43gfrlogwell maybe I wasn't specific enough about the private case
09:43gfrlogmore specifically..
09:43gfrlogI'm thinking of macros that are essentially def-helpers
09:43gfrlogthey make your defs more succinct, so in some sense they're only used at compile time.
09:44gfrlog(please note that I don't have a good idea of what "compile time" means)
09:46gfrlog(I used to think I did but every time I say anything about it hiredman starts contradicting me)
09:47raekif you need to generate defs, then you need macros
09:48mduerksengfrlog: i would say is an appropriate way to use macros. my take on this topic is: since i'm coming from imperative background, i often forget the elegance of funktional programming, so i before i use a macro, i ask myself: how could this be accomplished with pure funktions? if that's not possible/feasable, i use a macro. if i would build an API, which is intended to be used be others, i would think 3 times :)
09:48gfrlogwell there's not necessarily a 'need' -- it just keeps the code dry
09:48raeksince you cannot 'apply' special forms programmatically
09:49gfrlogfor example in the html helpers in hiccup, the author wants all functions to take an optional initial hash argument; rather than repeating that for every function, he creates a 'defelem' macro and uses that instead of 'defn'
09:50gfrloghe didn't HAVE to do it that way to get the same functionality, but it kept the code dryer, and doesn't have any composability dangers that I can see
11:04g4borhi, which is the "more official" planet clojure? http://planet-clojure.org/ or http://planet.clojure.in/ ?
12:23FrozenlockIs there a way to send ethernet packet with clojure?
12:25gfrlogFrozenlock: is there a way to send ethernet packet with java?
12:28Frozenlockgfrlog: I honestly don't know. My Java's knowledge is a huge void.
12:32TheMoonMasterFrozenlock: I am really new to Java and Clojure, but try PCAP for JAva
12:33Frozenlockthemoonmaster: Will do, thanks!
12:44mduerksencan "doseq" or "for" be iterated indexed similar to map-indexed?
12:48Bob__hello, anyone out there?
12:50FrozenlockYes
12:58Raynesmduerksen: Not directly, but you can do something like this ##(let [s ["a" "b" "c" "d"]] (for [[i e] (map vector (range (count s)) s)] [e i]))
12:58sexpbot⟹ (["a" 0] ["b" 1] ["c" 2] ["d" 3])
12:59RaynesThe magic of laziness makes that less costly than you might expect.
13:28gfrlog,#=(inc 12)
13:28clojurebotEvalReader not allowed when *read-eval* is false.
13:28gfrlog,(binding [*read-eval* true] #=(inc 12))
13:28clojurebotEvalReader not allowed when *read-eval* is false.
13:29gfrlog,(binding [*read-eval* true] *read-eval*)
13:29clojurebottrue
13:29gfrlogah right
13:30gfrlogdoes clojure 1.2 not have the ^:private syntax?
13:56KineticShampoo_Hi guys
13:57kzarI'm toying around with google calendar, I thought (class calendarEventFeed) is the clojure equilavent of CalendarEventFeed.class but I'm not sure that it is behaving that way. What do you think?
13:57kzarKineticShampoo_: Hi
13:58KineticShampoo_Check out this wallpaper I made :3
13:58KineticShampoo_http://i.imgur.com/cZj1N.png
13:58KineticShampoo_Still new to Clojure but I really like the language, it's very easy to read
13:59kzarnice, good work
14:00gfrlogKineticShampoo_: I like how it is terribly easy to resize
14:00KineticShampoo_yeah, just a simple edit
14:00KineticShampoo_:)
14:01TheMoonMasterHow good is clojure on the web development side of things?
14:01gfrlogTheMoonMaster: it is some good
14:02gfrlogTheMoonMaster: it's certainly used that way often enough
14:03kzarTheMoonMaster: Yea it's looking pretty good, Enlive is pretty good and you can run on the google app engine too. I guess one bad side is the footprint ram wise of the java vm if you're running on a VPS
14:04TheMoonMasterAwesome, I do mostly web development and was wondering if Clojure would be practical in that aspect
14:06kzarTheMoonMaster: It's what I'm just toying around with and learning myself, so far I'm really impressed heh
14:07kzarOh I got it, the equivalent turned out to be simply CalendarEventFeed itself
14:08TheMoonMasterkzar: I'm really impressed with Clojure so far, it's the first functional language I've gotten deep into.
14:12kzarYea, same here. If I'm honest I'm a little slow-minded for it but I enjoy tinkering heh
14:13TheMoonMasterHaha, solving problems with clojure is much harder than with the other languages I use, but I'll get used to it.
15:15gfrlog,('not= 7 8)
15:15clojurebot8
15:29dnolen,(bases (class 'foo))
15:29clojurebot(clojure.lang.AFn clojure.lang.IObj java.lang.Comparable clojure.lang.Named java.io.Serializable)
15:38kzarI'm trying to convert this line `Link batchLink = feed.getLink(Link.Rel.FEED_BATCH, Link.Type.ATOM);` to clojure, I've got Link in my namespace but there doesn't seem to be a Rel method for it. I ran javadoc on Link and the page http://code.google.com/apis/gdata/javadoc/com/google/gdata/data/Link.html seems to say the class does has a Rel method and that was inherited from a different class, think I'm missing somethi
15:38kzarng here.
15:39gfrlogkzar: what is your clojure code?
15:40kzargfrlog: Well at the moment I'm just toying around trying to get the Link.Rel.FEED_BATCH to work interactively
15:40dnolen(let [batch-link (.getLink feed Link.Rel/FEED_BATCH Link.Type/ATOM)] ...)
15:40dnolenkzar: something like ^, untested.
15:41dnolenthere is no Rel method, it's a nested class
15:41gfrlogso in java I think Link.Rel.FEED_BATCH is nested properties
15:41gfrlogoh nested class
15:41gfrloghmm
15:41gfrlogstatic class?
15:42gfrlogmaybe try Link$Rel/FEED_BATCH
15:43kzarHmm neither Link.Rel or Link$Rel work, am I right in just specifying Link when importing the class?
15:44dnolenkzar: it's telling you that it can't find the class?
15:45kzardnolen: Yea exactly, Link.Rel gives me a class not found exception
15:48dnolenkzar, yet Link by itself works?
15:49kzardnolen: Yep, it's a puzzler eh?
15:49TheMoonMasterWhat is the best way to remove all elements from a sequence that don't have duplicates?
15:50dnolenkzar: what happens you do just Link$Rel
15:50kzardnolen: It gives me a unable to resolve symbol exception
15:51kzarTheMoonMaster: I'm thinking you could use the frequencies function on your sequence and then use filter on the result?
15:53gfrlog,(let [coll [1 2 3 3 4 5 4 6 7 8 9 6 6], singles (->> coll frequencies (filter #(= (last %) 1)) (map first))] (remove (set singles) coll))
15:53clojurebot(3 3 4 4 6 6 6)
15:54gfrlogTheMoonMaster: ^
15:54kzar,(filter #(> (val %) 1) (frequencies "dsfdjsfjsfiejwaadas"))
15:54clojurebot([\d 3] [\s 4] [\f 3] [\j 3] [\a 3])
15:56gfrlog,(val [4 5])
15:56clojurebotjava.lang.ClassCastException: clojure.lang.PersistentVector cannot be cast to java.util.Map$Entry
15:56kzardnolen: My only thought is I've somehow got the wrong Link class but I don't see how
15:57kzar,(map val {:a 2 :b 3})
15:57clojurebot(2 3)
15:57kzar,(map key {:a 2 :b 3})
15:57clojurebot(:a :b)
15:57gfrlog,(seq {:a 2 :b 3})
15:57clojurebot([:a 2] [:b 3])
15:57TheMoonMasterThanks
15:57gfrlog,(map key [[:a 2] [:b 3]])
15:57clojurebotjava.lang.ClassCastException: clojure.lang.PersistentVector cannot be cast to java.util.Map$Entry
15:58gfrlogso map has special behavior for maps?
15:58gfrlog,(map prn {:a 2, :b 3})
15:58clojurebot[:a 2]
15:58clojurebot[:b 3]
15:58clojurebot(nil nil)
15:59gfrlog,(map class {:a 2, :b 3})
15:59clojurebot(clojure.lang.MapEntry clojure.lang.MapEntry)
15:59gfrloghuh.
15:59gfrlog(class (first (seq {:a 2, :b 3})))
15:59gfrlog,(class (first (seq {:a 2, : b 3})))
15:59clojurebotInvalid token: :
16:00gfrlog,(-> {:a 2, :b 3} seq first class)
16:00clojurebotclojure.lang.MapEntry
16:00gfrlogyou learn something new every so often
16:03gfrlogcome to think of it I wasn't even aware that the key and val functions existed
16:04kzardnolen: Ah maybe this is it, the doc is for 1.41.1 but I'm using 1.41.5
16:04dnolenkzar: yes I was just about to suggest that.
16:04gfrloggood thing they used major version incrementation to indicate the breaking changes
16:06kzardnolen: I can't see updated documentation online either :(
16:13kzardnolen: although I grabbed gdata-samples.java.1.41.5.zip and they are using the same class as me and they do use Link.Rel.FEED_BATCH
16:17dnolenkzar: (import '[com.google.gdata.data Link ILink ILink$Rel])
16:17dnolenILink$Rel/FEED_BATCH -> "http://schemas.google.com/g/2005#batch&quot;
16:18kzardnolen: Ah it works! thanks
16:19kzarHow come the Java guys could just do Link.Rel without knowing about ILink though?
16:19dnolenjava magic
16:20dnolengotta go
16:21kzarheh
16:28mrjeebushello. i'm getting started with clojure and lisp in general: is (a b c) the same thing as (a (b c)) - i get that all lists are implemented as chains of cons, as in a linked list, so why aren't these two equivalent?
16:30kzar,(second '(a b c))
16:30clojurebotb
16:30kzar,(second '(a (b c)))
16:30clojurebot(b c)
16:31fliebelmrjeebus: (cons a (cons b (cons c nil))) = '(a b c)
16:31mrjeebusah, i see what i'm doing
16:32mrjeebus(a b c) is really syntactical sugar isn't it
16:32fliebelwell, sortof, yea…
16:33raektraditionally in lisps, you write conses as (a . d), and (a b c) is just a short form for (a . (b . (c . nil)))
16:33raekbut clojure does not have the "dotter pair" syntax
16:33raek*dotted
16:33mrjeebusbut in memory it's (cons a (cons b (cons c nil))) isn't it
16:33raekmrjeebus: yes
16:33mrjeebusah, all clear, thanks very much
16:41pdkclojure won't let you make non-proper lists period
16:43mrjeebussorry? not sure what you mean there
16:44kzarYou can't make a pair with cons in clojure like you can in other lisps
16:45mrjeebusso in other lisps you can (cons 1 2) but not clojure?
16:45zippy314,(cons 1 2)
16:45clojurebotjava.lang.IllegalArgumentException: Don't know how to create ISeq from: java.lang.Integer
16:46zippy314,(cons 1 '(1 2))
16:46clojurebot(1 1 2)
16:46zippy314,(cons 1 [2])
16:46clojurebot(1 2)
16:47mrjeebusare there any legimitate uses of non-proper lists or is it an implementation artifact of other lisps that it's allowed at all?
16:50kzarmrjeebus: Well if you want a pair, maybe coordinates or something it's handy I guess. But then you could just provide a vector or a list with two items instead so it's not really a big deal, for me anyway
16:51zippy314mrjeebus: I couldn't tell you definitively as I'm pretty new to clojure, but it looks to me like cons is expecting a seq as the second argument. I think I read that because clojure handles vectors and sets so nicely some of the other stuff, like dotted pairs, was left out on purpose.
16:57pdk[16:45] <mrjeebus> sorry? not sure what you mean there
16:57pdkthinking of lists in terms of car/cdr isn't really the best way to do things in clojure but
16:57pdkpicture if you had to make the cdr always a cons cell or nil
16:58pdkso you can't have (x . y) but (x y) would be fine
17:09mrjeebusin other lisps, are lists always normalised so that the last pair is (y (z nil)), or is the end of the list (y z)?
17:12dnolenmrjeebus: some lisps allow lists w/o a proper tail, that is a tail that is not a list or nil. Clojure doesn't allow that.
17:28dnolenmrjeebus: Clojure has a rich set of data structures, I have yet to see a use case for supporting lists w/ improper tails beyond the logic programming library I'm working on. If you want pairs, define a real pair datatype w/ deftype.
17:47tomoj#overtone die off? :(
17:49kzarBe the change tomoj
17:57kzarIs there a way to add metadata to a Java object?
18:05dnolenkzar: not really, metadata requires a field ... maybe you could write a macro that automatically wraps a Java object in deftype that adds the metadata field and exports the original methods to the wrapper type (which you could discover via reflection). this would be easier if Java was an efficient late bound language like Objective-C, oh well.
18:09kzarshucks, nevermind eh?
18:11dnolenkzar: not worth it IMO, but perhaps someone sees a better way to do it, I don't ...
18:41sid3kany ideas about this problem; https://gist.github.com/960920
18:44dnolenkzar: hmm, would be much easier if IObj or IMeta were protocols and not Java interfaces ... so maybe one day.
18:46tomojwhere would you stick the metadata?
18:47dnolentomoj: in some external mutable store.
18:47tomojand then how does it GC properly?
18:47dnolentomoj: WeakMaps?
18:48tomojI wondered if weak things were relevant but never have understood any of them
18:48tomoja WeakMap is just a map where the keys fall out by GC?
18:49dnolenhttp://download.oracle.com/javase/1.4.2/docs/api/java/util/WeakHashMap.html
18:49tomojaha
18:49tomojthanks
23:01andrewvcIf anyone has a minute, I have some proprietary jars I'd like to include in a leiningen project. I don't have a mvn repo for them though, and I would just like to include them. What's the best way?
23:01andrewvcIncluding them in "lib" works, but they get regularly deleted by lein
23:02andrewvcextra-classpath-dirs doesn't seem to work as far as making lein compile work
23:14tomojhttp://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html
23:16tomojthat will put them where leiningen will see them
23:16tomojpackaging=jar, the rest just needs to match whatever you put in your deps
23:16tomojbest way? dunno. it works though
23:16tomoj..until you try to build the project somewhere where you haven't done this manual step :)