#clojure log - May 07 2011

The Joy of Clojure
Main Clojure site
Google Group
IRC
List of all logged dates

0:01 seancorfield: pr, prn, print, println, print-dup, pr-str, prn-str, print-str, println-str, print-simple, printf...

0:01 * technomancy has started using prn for debugging instead of println

0:01 technomancy: makes it easier to spot stuff that only got checked in by accident

0:04 anyone use native-deps and want to test something for me?

0:09 trptcolin: i use prn almost exclusively too

0:10 technomancy: well if you do, please try the latest leiningen from git, it should handle them transparently

0:10 trptcolin: oh you meant the printing fn - i was talking about something else ;)

0:10 *rimshot*

0:15 technomancy: I'm confused... the native-deps task seems to be doing the exact same thing as the deps task.

0:16 https://github.com/swannodette/native-deps/blob/master/src/leiningen/native_deps.clj where exactly is the "native" magic?

0:17 oh, it's the unjar part; I see.

0:54 that looks like it did the trick.

0:54 miwillhite: Is the asterisk a convention for something?: (defn get-object*

0:56 technomancy: miwillhite: 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."

0:56 miwillhite: ha okay thx

0:58 TheMoonMaster: Might 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])?

0:59 tomoj: is the last one supposed to have 7

0:59 TheMoonMaster: Erm, yeah that was an accident, sorry, it's late.

0:59 tomoj: ,(doc partition)

0:59 clojurebot: "([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."

1:00 TheMoonMaster: Thanks!

1:00 tomoj: or perhaps partition-all

1:00 TheMoonMaster: I'll check it out, I appreciate the help.

1:02 tomoj: or do you always want to split it in half?

1:02 TheMoonMaster: That did exactly what I wanted it to do.

1:31 semperos: dlh: it actually put the repo inside the .git folder

1:31 so <project name>/.git/src, README, .git, etc.

7:08 Matt324: Newbie 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

7:09 e.g. (vijual/draw-graph [[:a :b]]) gives "java.lang.Exception: No such namespace: vijual (NO_SOURCE_FILE:1)"

7:09 raek: Matt324: have you required the namespace? in clojure, namespaces are not loaded until needed.

7:11 Matt324: raek, Ah, right, thanks, that works now.

7:28 kzar: Has anyone used the google calendar api from clojure?

7:40 (nevermind I figured it out)

8:25 If 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?

8:33 raek: kzar: yes, but with ( ) instead of [ ]

9:37 gfrlog: is it true that all the classic macro-hate doesn't apply to private macros?

9:39 mduerksen: gfrlog: what is the "classic macro-hate?" :)

9:39 gfrlog: the first rule of macro club is don't use macros

9:40 raek: it's not like some people simply hates macros, it's more like "The main reason for beginners is: you don't need it."

9:40 this is a very interesting thread re. eval, which has a very similar reputation: http://stackoverflow.com/questions/2571401/why-exactly-is-eval-evil

9:40 gfrlog: well there was also some talk at the last conj about how it makes composability hard

9:41 which 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

9:42 raek: couldn't those cases be the same?

9:42 gfrlog: raek: not if one is inherently public and the other is inherently private

9:43 well maybe I wasn't specific enough about the private case

9:43 more specifically..

9:43 I'm thinking of macros that are essentially def-helpers

9:43 they make your defs more succinct, so in some sense they're only used at compile time.

9:44 (please note that I don't have a good idea of what "compile time" means)

9:46 (I used to think I did but every time I say anything about it hiredman starts contradicting me)

9:47 raek: if you need to generate defs, then you need macros

9:48 mduerksen: gfrlog: 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 :)

9:48 gfrlog: well there's not necessarily a 'need' -- it just keeps the code dry

9:48 raek: since you cannot 'apply' special forms programmatically

9:49 gfrlog: for 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'

9:50 he 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:04 g4bor: hi, which is the "more official" planet clojure? http://planet-clojure.org/ or http://planet.clojure.in/ ?

12:23 Frozenlock: Is there a way to send ethernet packet with clojure?

12:25 gfrlog: Frozenlock: is there a way to send ethernet packet with java?

12:28 Frozenlock: gfrlog: I honestly don't know. My Java's knowledge is a huge void.

12:32 TheMoonMaster: Frozenlock: I am really new to Java and Clojure, but try PCAP for JAva

12:33 Frozenlock: themoonmaster: Will do, thanks!

12:44 mduerksen: can "doseq" or "for" be iterated indexed similar to map-indexed?

12:48 Bob__: hello, anyone out there?

12:50 Frozenlock: Yes

12:58 Raynes: mduerksen: 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:58 sexpbot: ⟹ (["a" 0] ["b" 1] ["c" 2] ["d" 3])

12:59 Raynes: The magic of laziness makes that less costly than you might expect.

13:28 gfrlog: ,#=(inc 12)

13:28 clojurebot: EvalReader not allowed when *read-eval* is false.

13:28 gfrlog: ,(binding [*read-eval* true] #=(inc 12))

13:28 clojurebot: EvalReader not allowed when *read-eval* is false.

13:29 gfrlog: ,(binding [*read-eval* true] *read-eval*)

13:29 clojurebot: true

13:29 gfrlog: ah right

13:30 does clojure 1.2 not have the ^:private syntax?

13:56 KineticShampoo_: Hi guys

13:57 kzar: I'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:57 KineticShampoo_: Hi

13:58 KineticShampoo_: Check out this wallpaper I made :3

13:58 http://i.imgur.com/cZj1N.png

13:58 Still new to Clojure but I really like the language, it's very easy to read

13:59 kzar: nice, good work

14:00 gfrlog: KineticShampoo_: I like how it is terribly easy to resize

14:00 KineticShampoo_: yeah, just a simple edit

14:00 :)

14:01 TheMoonMaster: How good is clojure on the web development side of things?

14:01 gfrlog: TheMoonMaster: it is some good

14:02 TheMoonMaster: it's certainly used that way often enough

14:03 kzar: TheMoonMaster: 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:04 TheMoonMaster: Awesome, I do mostly web development and was wondering if Clojure would be practical in that aspect

14:06 kzar: TheMoonMaster: It's what I'm just toying around with and learning myself, so far I'm really impressed heh

14:07 Oh I got it, the equivalent turned out to be simply CalendarEventFeed itself

14:08 TheMoonMaster: kzar: I'm really impressed with Clojure so far, it's the first functional language I've gotten deep into.

14:12 kzar: Yea, same here. If I'm honest I'm a little slow-minded for it but I enjoy tinkering heh

14:13 TheMoonMaster: Haha, solving problems with clojure is much harder than with the other languages I use, but I'll get used to it.

15:15 gfrlog: ,('not= 7 8)

15:15 clojurebot: 8

15:29 dnolen: ,(bases (class 'foo))

15:29 clojurebot: (clojure.lang.AFn clojure.lang.IObj java.lang.Comparable clojure.lang.Named java.io.Serializable)

15:38 kzar: I'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:38 ng here.

15:39 gfrlog: kzar: what is your clojure code?

15:40 kzar: gfrlog: Well at the moment I'm just toying around trying to get the Link.Rel.FEED_BATCH to work interactively

15:40 dnolen: (let [batch-link (.getLink feed Link.Rel/FEED_BATCH Link.Type/ATOM)] ...)

15:40 kzar: something like ^, untested.

15:41 there is no Rel method, it's a nested class

15:41 gfrlog: so in java I think Link.Rel.FEED_BATCH is nested properties

15:41 oh nested class

15:41 hmm

15:41 static class?

15:42 maybe try Link$Rel/FEED_BATCH

15:43 kzar: Hmm neither Link.Rel or Link$Rel work, am I right in just specifying Link when importing the class?

15:44 dnolen: kzar: it's telling you that it can't find the class?

15:45 kzar: dnolen: Yea exactly, Link.Rel gives me a class not found exception

15:48 dnolen: kzar, yet Link by itself works?

15:49 kzar: dnolen: Yep, it's a puzzler eh?

15:49 TheMoonMaster: What is the best way to remove all elements from a sequence that don't have duplicates?

15:50 dnolen: kzar: what happens you do just Link$Rel

15:50 kzar: dnolen: It gives me a unable to resolve symbol exception

15:51 TheMoonMaster: I'm thinking you could use the frequencies function on your sequence and then use filter on the result?

15:53 gfrlog: ,(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:53 clojurebot: (3 3 4 4 6 6 6)

15:54 gfrlog: TheMoonMaster: ^

15:54 kzar: ,(filter #(> (val %) 1) (frequencies "dsfdjsfjsfiejwaadas"))

15:54 clojurebot: ([\d 3] [\s 4] [\f 3] [\j 3] [\a 3])

15:56 gfrlog: ,(val [4 5])

15:56 clojurebot: java.lang.ClassCastException: clojure.lang.PersistentVector cannot be cast to java.util.Map$Entry

15:56 kzar: dnolen: My only thought is I've somehow got the wrong Link class but I don't see how

15:57 ,(map val {:a 2 :b 3})

15:57 clojurebot: (2 3)

15:57 kzar: ,(map key {:a 2 :b 3})

15:57 clojurebot: (:a :b)

15:57 gfrlog: ,(seq {:a 2 :b 3})

15:57 clojurebot: ([:a 2] [:b 3])

15:57 TheMoonMaster: Thanks

15:57 gfrlog: ,(map key [[:a 2] [:b 3]])

15:57 clojurebot: java.lang.ClassCastException: clojure.lang.PersistentVector cannot be cast to java.util.Map$Entry

15:58 gfrlog: so map has special behavior for maps?

15:58 ,(map prn {:a 2, :b 3})

15:58 clojurebot: [:a 2]

15:58 [:b 3]

15:58 (nil nil)

15:58 * gfrlog is still confused

15:59 gfrlog: ,(map class {:a 2, :b 3})

15:59 clojurebot: (clojure.lang.MapEntry clojure.lang.MapEntry)

15:59 gfrlog: huh.

15:59 (class (first (seq {:a 2, :b 3})))

15:59 ,(class (first (seq {:a 2, : b 3})))

15:59 clojurebot: Invalid token: :

15:59 * gfrlog shakes his fist at clojurebot

16:00 gfrlog: ,(-> {:a 2, :b 3} seq first class)

16:00 clojurebot: clojure.lang.MapEntry

16:00 gfrlog: you learn something new every so often

16:03 come to think of it I wasn't even aware that the key and val functions existed

16:04 kzar: dnolen: Ah maybe this is it, the doc is for 1.41.1 but I'm using 1.41.5

16:04 dnolen: kzar: yes I was just about to suggest that.

16:04 gfrlog: good thing they used major version incrementation to indicate the breaking changes

16:06 kzar: dnolen: I can't see updated documentation online either :(

16:13 dnolen: 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:17 dnolen: kzar: (import '[com.google.gdata.data Link ILink ILink$Rel])

16:17 ILink$Rel/FEED_BATCH -> "http://schemas.google.com/g/2005#batch"

16:18 kzar: dnolen: Ah it works! thanks

16:19 How come the Java guys could just do Link.Rel without knowing about ILink though?

16:19 dnolen: java magic

16:20 gotta go

16:21 kzar: heh

16:28 mrjeebus: hello. 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:30 kzar: ,(second '(a b c))

16:30 clojurebot: b

16:30 kzar: ,(second '(a (b c)))

16:30 clojurebot: (b c)

16:31 fliebel: mrjeebus: (cons a (cons b (cons c nil))) = '(a b c)

16:31 mrjeebus: ah, i see what i'm doing

16:32 (a b c) is really syntactical sugar isn't it

16:32 fliebel: well, sortof, yea…

16:33 raek: traditionally in lisps, you write conses as (a . d), and (a b c) is just a short form for (a . (b . (c . nil)))

16:33 but clojure does not have the "dotter pair" syntax

16:33 *dotted

16:33 mrjeebus: but in memory it's (cons a (cons b (cons c nil))) isn't it

16:33 raek: mrjeebus: yes

16:33 mrjeebus: ah, all clear, thanks very much

16:41 pdk: clojure won't let you make non-proper lists period

16:43 mrjeebus: sorry? not sure what you mean there

16:44 kzar: You can't make a pair with cons in clojure like you can in other lisps

16:45 mrjeebus: so in other lisps you can (cons 1 2) but not clojure?

16:45 zippy314: ,(cons 1 2)

16:45 clojurebot: java.lang.IllegalArgumentException: Don't know how to create ISeq from: java.lang.Integer

16:46 zippy314: ,(cons 1 '(1 2))

16:46 clojurebot: (1 1 2)

16:46 zippy314: ,(cons 1 [2])

16:46 clojurebot: (1 2)

16:47 mrjeebus: are there any legimitate uses of non-proper lists or is it an implementation artifact of other lisps that it's allowed at all?

16:50 kzar: mrjeebus: 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:51 zippy314: mrjeebus: 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:57 pdk: [16:45] <mrjeebus> sorry? not sure what you mean there

16:57 thinking of lists in terms of car/cdr isn't really the best way to do things in clojure but

16:57 picture if you had to make the cdr always a cons cell or nil

16:58 so you can't have (x . y) but (x y) would be fine

17:09 mrjeebus: in 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:12 dnolen: mrjeebus: 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:28 mrjeebus: 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:47 tomoj: #overtone die off? :(

17:49 kzar: Be the change tomoj

17:57 Is there a way to add metadata to a Java object?

18:05 dnolen: kzar: 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:09 kzar: shucks, nevermind eh?

18:11 dnolen: kzar: not worth it IMO, but perhaps someone sees a better way to do it, I don't ...

18:41 sid3k: any ideas about this problem; https://gist.github.com/960920

18:44 dnolen: kzar: hmm, would be much easier if IObj or IMeta were protocols and not Java interfaces ... so maybe one day.

18:46 tomoj: where would you stick the metadata?

18:47 dnolen: tomoj: in some external mutable store.

18:47 tomoj: and then how does it GC properly?

18:47 dnolen: tomoj: WeakMaps?

18:48 tomoj: I wondered if weak things were relevant but never have understood any of them

18:48 a WeakMap is just a map where the keys fall out by GC?

18:49 dnolen: http://download.oracle.com/javase/1.4.2/docs/api/java/util/WeakHashMap.html

18:49 tomoj: aha

18:49 thanks

23:01 andrewvc: If 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:01 Including them in "lib" works, but they get regularly deleted by lein

23:02 extra-classpath-dirs doesn't seem to work as far as making lein compile work

23:14 tomoj: http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html

23:16 that will put them where leiningen will see them

23:16 packaging=jar, the rest just needs to match whatever you put in your deps

23:16 best way? dunno. it works though

23:16 ..until you try to build the project somewhere where you haven't done this manual step :)

Logging service provided by n01se.net