#clojure log - Jul 05 2009

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

0:00 jackdempsey: :-)

0:14 duncanm: Chouser: oh?

0:15 Chouser: repl-utils/javadoc

4:41 hiredman: clojurebot: lisp machine?

4:41 clojurebot: lisp is the red pill

4:42 hiredman: clojurebot: lisp machine is <reply>my lisp machine is the jvm

4:42 clojurebot: 'Sea, mhuise.

5:11 ChrisPS: join /#emacs

5:38 This statement in emacs: (require 'clojure-auto)

5:38 in my clojure-mode.el there is no such thing

5:38 what does it referr to?

5:39 it should be a (defun clojure-auto) right?

5:43 hoeck: ChrisPS: this is an artifact from earlier versions of clojure-mode

5:44 ChrisPS: hoeck: Oh, thanks -

5:44 So where to find current info?

5:44 hoeck: for setting up swank-clojure?

5:44 ChrisPS: yes

5:44 hoeck: which guide are you following?

5:45 ChrisPS: I tried Bill Celementson

5:45 hoeck: I haven't changed my config for a year or so, except removing (require 'clojure-auto) :)

5:48 ChrisPS: clojure-mode has M-x clojure-install

5:49 ChrisPS: I know

5:49 hoeck: and it worked?

5:49 ChrisPS: nope

5:49 investigating it now

5:50 lenst: don't like clojure-install, makes to many assumptions

5:51 ChrisPS: when I (setq load-path "...") do I just set it to the containing folder, or do I point at the .el file directly

5:52 lenst: load-path should be a list of folders

5:52 ChrisPS: ok

5:56 what is the command in the .emacs file that actually loads clojure?

5:57 what is the paste?

5:57 listpaste

5:59 hoeck: lisppaste8: URL

5:59 lisppaste8: To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.

5:59 hoeck: ChrisPS: ^^

5:59 ChrisPS: thanks :-/

6:01 lisppaste8: ChrisPS pasted "My current .emacs" at http://paste.lisp.org/display/83042

6:01 ChrisPS: the paths are a-ok

6:02 hoeck: ChrisPS: do you want to use slime or only inferior-lisp?

6:02 ChrisPS: slime please

6:02 lenst: lol, scrap that and start over

6:03 ChrisPS: I have Aquaemacs and Carbonemacs installed, in addition to that emacs-22.3.1

6:04 lenst: (add-to-list 'load-path "/Users/chris/lisp/clj/clojure-mode") not setq

6:05 ChrisPS: lenst: ok

6:07 when I look in my modes, there is no clojure

6:07 M-x

6:07 clo..

6:07 so now, I guess, I need to actually start that fun

6:07 function

6:07 lenst: read the comments in the beginning of clojure-mode.el

6:08 ChrisPS: ok

6:09 lenst: the README for swank-clojure wasn't very helpful for me

6:10 maybe adding (require 'swank-clojure-autoload) to .emacs is enough

6:11 ChrisPS: but since swank-clojure-autoload is a different file than swank-clojure

6:11 I need to (add-to-list ... ) as well?

6:11 (just need to understand the basics)

6:11 lisppaste8: hoeck annotated #83042 "swank-clojure" at http://paste.lisp.org/display/83042#1

6:12 ChrisPS: right

6:12 hoeck: just add the paths containing the *.el files

6:15 ChrisPS: oh man, progress

6:15 :-)

6:17 at least the major and minor modes are ok

6:17 (Clojure Slime)

6:17 lenst: I wish emacs package writers wouldn't require you to put require or load in .emacs. It adds to the startup time of emacs.

6:17 ChrisPS: if I C-x e (list 1 2 3 4) I get a Not Connected

6:19 Hun: lenst: that's what autoload is for

6:19 ChrisPS: ah, M-x slime

6:19 hoeck: ChrisPS: if you start slime with M-x slime, you should see a *inferior-lisp* buffer with a starting clojure

6:19 ChrisPS: yes

6:19 trye

6:19 true

6:20 And now, after I started slime, the magic appears

6:21 thanks a lot!!!

6:27 lenst: hoeck: do you use slime-repl?

6:31 hoeck: lenst: yes, but in case of setting up swank-clojure, the inferior-lisp prints messages in case of not finding clojure.jar

7:16 mauritslamers: question: when I use map, how can I use the same parameter twice? I have a list with lists and want to map the first list onto the rest

7:16 but in some way it doesn't work as I expected

7:18 lisppaste8: mauritslamers pasted "route-detection" at http://paste.lisp.org/display/83046

7:18 hiredman: mauritslamers: sounds like you want first and rest

7:19 (map (first some-list) (rest some-list))

7:19 mauritslamers: that is what I do, but it does not work as I expect

7:19 the source material is a list of lists of maps

7:19 hiredman: what do you expect it to do?

7:19 and what is the first item in the list?

7:20 mauritslamers: a list of maps

7:20 hiredman: a list is not a fn and it does not implement IFn

7:20 so you cannot map a list over anything

7:21 mauritslamers: did you look at the paste above?

7:21 hiredman: yeah

7:21 seems like a lot to read at 4am

7:21 mauritslamers: in Europe here, 1.22 pm :)

7:22 I'll add the source and expected outcome to the paste

7:22 hiredman: :(

7:23 ChrisPS: hehe

7:23 hiredman: that is just more to read

7:25 Lau_of_DK: hiredman: Whats been going on with clojurebot ?

7:26 hiredman: Lau_of_DK: I was camping on the wrong side of a group of mountains from my internet connection

7:26 whoops

7:26 lisppaste8: mauritslamers annotated #83046 "route-detection" at http://paste.lisp.org/display/83046#1

7:27 mauritslamers: hiredman: sorry about that, but it explains much better what my problem is than I can in the channel

7:29 hiredman: mauritslamers: it is important to keep in mind that a seq of a map is a seq of key,value pairs

7:29 ,(seq {:a 1 :b 2})

7:29 clojurebot: ([:a 1] [:b 2])

7:30 hiredman: and map calls seq

7:30 well, MapEntry

7:30 ChrisPS: it is really cool to have the test as part of the metadata for a function

7:31 mauritslamers: That explains a lot ...

7:31 hiredman: and clojure's MapEntrys display as two element vectors

7:31 ,(class (first (seq {:a 1 :b 2})))

7:31 clojurebot: clojure.lang.MapEntry

7:32 mauritslamers: any idea how to concat the mapped item to the result of every map call?

7:33 hiredman: concat into what?

7:33 well

7:33 opqdonut: something like (map #(vector (f x) x) seq) ?

7:33 hiredman: what do you mean

7:33 mapped item is what?

7:34 a list? a list cannot be mapped

7:34 mauritslamers: map calls the func with every item in the list

7:34 clojurebot: map is *LAZY*

7:34 hiredman: if you want to merge maps

7:34 use merge-with

7:34 mauritslamers: thanks, I'll look into that

7:34 hiredman: mauritslamers: that is like the very definition of map

7:35 if you want something different, you either need to use something different, or alter your algorithm

7:35 mauritslamers: map itself cannot map a list, but the function I call can

7:36 hiredman: so you have (map #(some-logic % (first some-list)) (rest some-list))

7:36 mauritslamers: It is a route detection algorithm, creating a route using the :from and :to map keys in the map

7:38 it seems merge-with is what I want, thanks!

12:17 Chouser: maps can be called with key and not-found args, just like the 'get' fn. But sets only take a single arg.

12:49 krumholt_: hi i have a vector and i need to create pairs like: [1 2 3 4] => [1 2] [2 3][3 4][4 1]

12:49 Chousuke: partition

12:49 and possibly cycle

12:53 krumholt_: partition looks good thanks

13:49 krumholt__: how can i swap to values of a vector (??? [1 2 3 4] 1 2) => [1 3 2 4]

13:54 Chouser: (defn swap-key [coll a b] (let [av (coll a), bv (coll b)] (-> coll (assoc a bv) (assoc b av))))

13:55 works on maps too: (swap-key {:a 1, :b 2, :c 3, :d 4} :a :d) ==> {:a 4, :b 2, :c 3, :d 1}

13:56 I guess you probably only need to store off one of the values, not both. *shrug*

13:59 krumholt__: ok thanks again

14:00 durka42: clojurebot: welcome back!

14:00 clojurebot: It's greek to me.

14:00 durka42: anyone know if ztellman hangs out here?

14:36 is there an easy way to convert a garden-variety map into a sorted-map?

14:36 ,(reduce conj (sorted-map) {:a 1, :b 2})

14:36 clojurebot: {:a 1, :b 2}

14:36 Chouser: that's it

14:36 or 'into'

14:38 durka42: i suppose into is reduce-conj written without using reduce

14:38 Chouser: yup

14:39 makes what you're intending to do more explicit for human readers

14:52 Chousuke: into could also potentially get its own interface someday and become more efficient than "reduce conj" :)

14:52 but whether that will actually happen remains to be seen.

16:24 AWizzArd: Is there some kind of unification and pattern matching system available for Clojure or Java? I have some collection of data and want to get some elements of it, and I can describe a pattern of properties of those elements.

16:29 kencausey: AWizzArd: Do you mean like regular expressions? There is syntax for that based on Java support.

16:30 Or something more general perhaps?

16:30 I suspect the second on further reading

16:30 replaca_2: AWizzArd: the closest I know of is datalog, which doesn't sound like exactly what you're looking for

16:32 AWizzArd: Not regexps, but something more like datalog.

16:34 For example I could say: all elements in the vector V are hashmaps with the key :type and the value :person. And if there is a person Jim followed by one or more persons who are not Tania and then one person Tania follows, in that case I want to have the persons between them.

16:34 Something like that.

16:38 replaca: AWizzArd: yeah, I've been thinking about the clojure flavor of that too, but I don't think anyone's written that yet

16:38 AWizzArd: Maybe Jessrules can do it?

16:38 replaca: AWizzArd: who's that?

16:39 AWizzArd: http://www.jessrules.com/

16:39 it even comes with a Lisp syntax

16:39 I discovered it several months ago, but the homepage was down in the last weeks for some reason

16:39 today it seems to be up again

16:39 replaca: oh, yeah. news to me!

16:40 brb

16:40 AWizzArd: may be something like Common Lisps „Lisa”

16:43 hiredman: you might be able to do something like that with fnparse

16:44 AWizzArd: hiredman: is that in contrib?

16:45 danlarkin: fnparse is for parsing strings

16:45 hiredman: ~fnparse

16:45 clojurebot: I don't understand.

16:45 hiredman: danlarkin: you can define your own combinators

16:45 Chousuke: actually, I think fnparse can parse pretty much anything :P

16:45 hiredman: ^-

16:45 Chousuke: strings are just what you usually need to parse.

16:46 hiredman: so if you approach the problem as a string of tokens

16:46 AWizzArd: I will have a look. Maybe it is in core but new or it sits somewhere in contrib.

16:46 Chousuke: but I guess it'd work for data structures too

16:46 hiredman: AWizzArd: nah, its on github

16:46 clojurebot: parse?

16:46 clojurebot: parser is http://github.com/joshua-choi/fnparse/tree/master

16:46 AWizzArd: thx

16:46 danlarkin: Hm... interesting, yeah I guess you're right

16:46 wow! that's like 1000x more useful now

16:46 hiredman: :)

16:48 AWizzArd: I will have a look and see if I can provide my own combinators to search through vectors of tokens

16:55 danlarkin: I haven't looked at fnparse recently, but would you just write a lexer to help your combinators?

16:57 hiredman: help?

17:20 meredydd: Hey - how is one supposed to combine routes in Compojure?

17:20 The source is confusing - the comments suggest a Ring function should return :next if it can't match anything

17:20 but in practice, it seems they return empty 200 responses

17:21 and the (routes) function appears to be expecting that they return nil if they don't match

17:55 drewr: Apparently there's a practical difference between (take 20 (iterate inc 1)) and (range 1 21).

17:56 Wait, I think I just realized why.

18:11 lisppaste8: drewr pasted "take/iterate vs range" at http://paste.lisp.org/display/83073

18:12 drewr: What's the difference between the two?

18:12 Even if new LazySeqs are created by each take, wouldn't they be GCed?

18:14 ChrisPS: Question: Do I need to add the locations clojure and clojure-contrib to my classpath?

18:15 AWizzArd: ChrisPS: yes

18:15 you don't *need* contrib

18:15 hiredman: ~def iterate

18:15 ChrisPS: great

18:15 AWizzArd: but you also don't *need* to program ;-)

18:15 hiredman: :(

18:19 ChrisPS: I don't need contrib? why not?

18:20 how can I read the classpath from within clojure

18:20 from the repl

18:34 eevar: ChrisPS: (System/getProperties)

18:35 ChrisPS: hmm

18:38 hiredman: ~def iterate

18:39 ChrisPS: I don't understand why a (ns whatever (:require clojure.contrib.str-utils)) give an error message

18:39 Could not locate clojure/contrib/str_utils__init.class or clojure/contrib/str_utils.clj on classpath:

18:40 hiredman: is contrib in you classpath?

18:41 ChrisPS: my classpath say: /Users/wave/lisp/clj/clojure:/Users/wave/lisp/clj/clojure-contrib

18:41 so the clojure-contrib is, but what about contrib??

18:43 hiredman: by contrib I mean clojure-contrib

18:43 what is in /Users/wave/lisp/clj/clojure-contrib

18:43 ChrisPS: then yes it is

18:43 hiredman: how are you starting clojure?

18:44 ChrisPS: via slime

18:44 emacs

18:44 hiredman: how are you setting the classpath?

18:44 ChrisPS: in .bash_profile

18:44 hiredman: ok

18:44 that will not work

18:44 ChrisPS: good

18:44 hiredman: you need to set it some how via slime

18:44 ChrisPS: ok

18:45 hiredman: but I don't use slime or emacs for that matter

18:45 basically java ignores CLASSPATH if you use the -cp flag

18:45 ChrisPS: so if just add it to the string in .emacs

18:45 it would work

18:48 still, when I do a

18:48 (doc clojure.contrib.str-utils/str-join)

18:48 clojurebot: "/;nil; "

18:48 hiredman: clojurebot: stop being so broken

18:48 clojurebot: we can't stop here! this is bat country!

18:48 ChrisPS: hehe

18:49 I get an exception

18:49 hiredman: so does (require 'clojure.contrib.str-utils) work?

18:50 ChrisPS: no

18:50 same msg

18:50 hiredman: (System/getProperty "java.class.path")

18:50 ChrisPS: java.io.FileNotFoundException

18:51 "/Users/wave/lisp/clj/clojure/clojure.jar:/Users/wave/lisp/clj/swank-clojure/:/Users/wave/lisp/clj\

18:51 ah fuck, lispaste!

18:51 where are thou

18:51 @

18:51 hiredman: lisppaste8: url?

18:51 lisppaste8: To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.

18:51 ChrisPS: hehe, thanks

18:51 I am getting old

18:52 lisppaste8: chrisPS pasted "classpath issue" at http://paste.lisp.org/display/83075

18:52 hiredman: do you not have a contrib jar?

18:53 ChrisPS: I do

18:53 hiredman: some pieces of contrib rely on being AOT compiled (which happens during the jar building process)

18:53 ChrisPS: the jarfile needs to be on the classpath

18:53 ChrisPS: I just ant'ed the contrib root

18:53 hiredman: not the path to the jar file

18:54 ChrisPS: the jarfile needs to be included the path-statement?

18:54 hiredman: so it should be /something/something/clojure-contrib.jar

18:54 ChrisPS: ah

18:54 will try now

18:54 hiredman: there are ways to do it like you are trying to do

18:54 clojurebot: jar dir

18:54 clojurebot: with java6(jdk1.6) CLASSPATH can contain a "*" so /jar/dir/* will suck in all the jars in the /jar/dir directory, this also works with swank-clojure-extra-classpaths in emacs, alternatively you can use this shell snippet: find .jars/ -type f -name \*.jar -print0|xargs -0|sed "s/ /:/g"

18:55 ChrisPS: but it will only suck in the dirs immediately below, so it's not recursive?

18:55 hiredman: eh? which?

18:56 the java classpath does not suck jars out of directories

18:56 ChrisPS: say /lisp/clj/*

18:56 ok ok

18:56 hiredman: that I dunno

18:56 ChrisPS: nevermind

18:56 hiredman: it is kind of weird, because it doesn't use the shell expension

18:56 expansion

18:59 ChrisPS: it works!!

19:00 I am a happy man, thanks hiredman for your assistance!!

22:49 duncanm: is this a common question: why couldn't clojure automatically convert Fns into some interface if that interface has only one method?

22:50 i'm watching this video on JRuby, and it looks like JRuby can allow Ruby blocks to be used as Swing ActionListeners

22:50 clojurebot: this is not a bug

22:52 slashus2: duncanm: Looks like clojurebot knows what you are talking about.

22:52 duncanm: heh

22:52 hiredman: dunno

22:52 I have also fetl pangs of jealousy when watching jruby do that

22:53 duncanm: hiredman: right?

22:54 hiredman: (defmacro fn->al [fun] (proxy [ActionListener] [] (actionPerformed [event] (fun event))))

22:54 duncanm: why write it as a macro?

22:55 hiredman: I guess it should be a function

22:55 I wrote it a while ago, but I can't seem to find it

22:57 I started on a macro to generate single method proxies a couple of times

22:58 gstamp: Towards the bottom of this page: http://www.dearm.co.uk/cgan/ there is a function based one

23:01 hiredman: something like (adapt ActionListener some-function)

23:01 duncanm: clojure-contrib has some swing-utils

23:03 gstamp: Here's a minor nit thing that's been annoying me. When I work with vectors in clojure I often need to run them through functions like map and reduce but the problem there is that they convert the vector to a seq. Is there another way to handle this other than just rewrapping using a (vec ...) call?

23:04 duncanm: gstamp: are you saying that it turns into a seq because it's printed using ()s ?

23:05 hiredman: duncanm: it is turned into a seq

23:05 duncanm: oh

23:05 hiredman: map, filter, et al call seq on their arguments

23:06 (def vector-map (comp vec map))

23:06 ~def vec

23:09 gstamp: Interesting that there is an array-map but not a vector-map

23:10 Love that you can compose together functions so easy though. :-)

23:29 duncanm: hiredman: so i asked in the #JRuby channel

23:29 hiredman: ruby blocks can turn into any Java interface

23:30 if the interface has 2 methods, the same block gets used for both (kinda surprising)

23:30 hiredman: yeah

23:31 I wish I had deleted this

23:31 er

23:31 hadn't

23:31 duncanm: you hacked clojure to support that?

23:40 hiredman?

23:40 oh, a macro

23:41 it'd be more interesting if the language supported it, no?

23:42 arbscht_: duncanm: not very much. this is why being a lisp is nice :)

23:43 duncanm: arbscht_: you prefer to explicitly write out a proxy form than having the compiler do it for you?

23:44 arbscht_: no, but extending the language with a macro is almost as good

23:44 grrrt: hey, I couldn't help overhear your conversation :)

23:44 I like clojure / lisp because there's no magic

23:45 any magic you want you add yourself (like a fn or macro that wraps around a proxy)

23:45 duncanm: even if there were a macro like (adapt #(...) someJavaInterface), you'd still have to remember the name of the interface, that's why i think it's more interesting that the language supports it

23:45 grrrt: well, it's already 'magically' supporting Runnable and Callable

23:45 grrrt: well that's fairly straightforward, you know what your're getting

Logging service provided by n01se.net