#clojure logs

2009-07-05

00:00jackdempsey:-)
00:14duncanmChouser: oh?
00:15Chouserrepl-utils/javadoc
04:41hiredmanclojurebot: lisp machine?
04:41clojurebotlisp is the red pill
04:42hiredmanclojurebot: lisp machine is <reply>my lisp machine is the jvm
04:42clojurebot'Sea, mhuise.
05:11ChrisPSjoin /#emacs
05:38ChrisPSThis statement in emacs: (require 'clojure-auto)
05:38ChrisPSin my clojure-mode.el there is no such thing
05:38ChrisPSwhat does it referr to?
05:39ChrisPSit should be a (defun clojure-auto) right?
05:43hoeckChrisPS: this is an artifact from earlier versions of clojure-mode
05:44ChrisPShoeck: Oh, thanks -
05:44ChrisPSSo where to find current info?
05:44hoeckfor setting up swank-clojure?
05:44ChrisPSyes
05:44hoeckwhich guide are you following?
05:45ChrisPSI tried Bill Celementson
05:45hoeckI haven't changed my config for a year or so, except removing (require 'clojure-auto) :)
05:48hoeckChrisPS: clojure-mode has M-x clojure-install
05:49ChrisPSI know
05:49hoeckand it worked?
05:49ChrisPSnope
05:49ChrisPSinvestigating it now
05:50lenstdon't like clojure-install, makes to many assumptions
05:51ChrisPSwhen I (setq load-path "...") do I just set it to the containing folder, or do I point at the .el file directly
05:52lenstload-path should be a list of folders
05:52ChrisPSok
05:56ChrisPSwhat is the command in the .emacs file that actually loads clojure?
05:57ChrisPSwhat is the paste?
05:57ChrisPSlistpaste
05:59hoecklisppaste8: URL
05:59lisppaste8To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.
05:59hoeckChrisPS: ^^
05:59ChrisPSthanks :-/
06:01lisppaste8ChrisPS pasted "My current .emacs" at http://paste.lisp.org/display/83042
06:01ChrisPSthe paths are a-ok
06:02hoeckChrisPS: do you want to use slime or only inferior-lisp?
06:02ChrisPSslime please
06:02lenstlol, scrap that and start over
06:03ChrisPSI have Aquaemacs and Carbonemacs installed, in addition to that emacs-22.3.1
06:04lenst(add-to-list 'load-path "/Users/chris/lisp/clj/clojure-mode") not setq
06:05ChrisPSlenst: ok
06:07ChrisPSwhen I look in my modes, there is no clojure
06:07ChrisPSM-x
06:07ChrisPSclo..
06:07ChrisPSso now, I guess, I need to actually start that fun
06:07ChrisPSfunction
06:07lenstread the comments in the beginning of clojure-mode.el
06:08ChrisPSok
06:09lenstthe README for swank-clojure wasn't very helpful for me
06:10lenstmaybe adding (require 'swank-clojure-autoload) to .emacs is enough
06:11ChrisPSbut since swank-clojure-autoload is a different file than swank-clojure
06:11ChrisPSI need to (add-to-list ... ) as well?
06:11ChrisPS(just need to understand the basics)
06:11lisppaste8hoeck annotated #83042 "swank-clojure" at http://paste.lisp.org/display/83042#1
06:12ChrisPSright
06:12hoeckjust add the paths containing the *.el files
06:15ChrisPSoh man, progress
06:15ChrisPS:-)
06:17ChrisPSat least the major and minor modes are ok
06:17ChrisPS(Clojure Slime)
06:17lenstI wish emacs package writers wouldn't require you to put require or load in .emacs. It adds to the startup time of emacs.
06:17ChrisPSif I C-x e (list 1 2 3 4) I get a Not Connected
06:19Hunlenst: that's what autoload is for
06:19ChrisPSah, M-x slime
06:19hoeckChrisPS: if you start slime with M-x slime, you should see a *inferior-lisp* buffer with a starting clojure
06:19ChrisPSyes
06:19ChrisPStrye
06:19ChrisPStrue
06:20ChrisPSAnd now, after I started slime, the magic appears
06:21ChrisPSthanks a lot!!!
06:27lensthoeck: do you use slime-repl?
06:31hoecklenst: yes, but in case of setting up swank-clojure, the inferior-lisp prints messages in case of not finding clojure.jar
07:16mauritslamersquestion: 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
07:16mauritslamersbut in some way it doesn't work as I expected
07:18lisppaste8mauritslamers pasted "route-detection" at http://paste.lisp.org/display/83046
07:18hiredmanmauritslamers: sounds like you want first and rest
07:19hiredman(map (first some-list) (rest some-list))
07:19mauritslamersthat is what I do, but it does not work as I expect
07:19mauritslamersthe source material is a list of lists of maps
07:19hiredmanwhat do you expect it to do?
07:19hiredmanand what is the first item in the list?
07:20mauritslamersa list of maps
07:20hiredmana list is not a fn and it does not implement IFn
07:20hiredmanso you cannot map a list over anything
07:21mauritslamersdid you look at the paste above?
07:21hiredmanyeah
07:21hiredmanseems like a lot to read at 4am
07:21mauritslamersin Europe here, 1.22 pm :)
07:22mauritslamersI'll add the source and expected outcome to the paste
07:22hiredman:(
07:23ChrisPShehe
07:23hiredmanthat is just more to read
07:25Lau_of_DKhiredman: Whats been going on with clojurebot ?
07:26hiredmanLau_of_DK: I was camping on the wrong side of a group of mountains from my internet connection
07:26hiredmanwhoops
07:26lisppaste8mauritslamers annotated #83046 "route-detection" at http://paste.lisp.org/display/83046#1
07:27mauritslamershiredman: sorry about that, but it explains much better what my problem is than I can in the channel
07:29hiredmanmauritslamers: it is important to keep in mind that a seq of a map is a seq of key,value pairs
07:29hiredman,(seq {:a 1 :b 2})
07:29clojurebot([:a 1] [:b 2])
07:30hiredmanand map calls seq
07:30hiredmanwell, MapEntry
07:30ChrisPSit is really cool to have the test as part of the metadata for a function
07:31mauritslamersThat explains a lot ...
07:31hiredmanand clojure's MapEntrys display as two element vectors
07:31hiredman,(class (first (seq {:a 1 :b 2})))
07:31clojurebotclojure.lang.MapEntry
07:32mauritslamersany idea how to concat the mapped item to the result of every map call?
07:33hiredmanconcat into what?
07:33hiredmanwell
07:33opqdonutsomething like (map #(vector (f x) x) seq) ?
07:33hiredmanwhat do you mean
07:33hiredmanmapped item is what?
07:34hiredmana list? a list cannot be mapped
07:34mauritslamersmap calls the func with every item in the list
07:34clojurebotmap is *LAZY*
07:34hiredmanif you want to merge maps
07:34hiredmanuse merge-with
07:34mauritslamersthanks, I'll look into that
07:34hiredmanmauritslamers: that is like the very definition of map
07:35hiredmanif you want something different, you either need to use something different, or alter your algorithm
07:35mauritslamersmap itself cannot map a list, but the function I call can
07:36hiredmanso you have (map #(some-logic % (first some-list)) (rest some-list))
07:36mauritslamersIt is a route detection algorithm, creating a route using the :from and :to map keys in the map
07:38mauritslamersit seems merge-with is what I want, thanks!
12:17Chousermaps can be called with key and not-found args, just like the 'get' fn. But sets only take a single arg.
12:49krumholt_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:49Chousukepartition
12:49Chousukeand possibly cycle
12:53krumholt_partition looks good thanks
13:49krumholt__how can i swap to values of a vector (??? [1 2 3 4] 1 2) => [1 3 2 4]
13:54Chouser(defn swap-key [coll a b] (let [av (coll a), bv (coll b)] (-> coll (assoc a bv) (assoc b av))))
13:55Chouserworks on maps too: (swap-key {:a 1, :b 2, :c 3, :d 4} :a :d) ==> {:a 4, :b 2, :c 3, :d 1}
13:56ChouserI guess you probably only need to store off one of the values, not both. *shrug*
13:59krumholt__ok thanks again
14:00durka42clojurebot: welcome back!
14:00clojurebotIt's greek to me.
14:00durka42anyone know if ztellman hangs out here?
14:36durka42is there an easy way to convert a garden-variety map into a sorted-map?
14:36durka42,(reduce conj (sorted-map) {:a 1, :b 2})
14:36clojurebot{:a 1, :b 2}
14:36Chouserthat's it
14:36Chouseror 'into'
14:38durka42i suppose into is reduce-conj written without using reduce
14:38Chouseryup
14:39Chousermakes what you're intending to do more explicit for human readers
14:52Chousukeinto could also potentially get its own interface someday and become more efficient than "reduce conj" :)
14:52Chousukebut whether that will actually happen remains to be seen.
16:24AWizzArdIs 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:29kencauseyAWizzArd: Do you mean like regular expressions? There is syntax for that based on Java support.
16:30kencauseyOr something more general perhaps?
16:30kencauseyI suspect the second on further reading
16:30replaca_2AWizzArd: the closest I know of is datalog, which doesn't sound like exactly what you're looking for
16:32AWizzArdNot regexps, but something more like datalog.
16:34AWizzArdFor 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:34AWizzArdSomething like that.
16:38replacaAWizzArd: yeah, I've been thinking about the clojure flavor of that too, but I don't think anyone's written that yet
16:38AWizzArdMaybe Jessrules can do it?
16:38replacaAWizzArd: who's that?
16:39AWizzArdhttp://www.jessrules.com/
16:39AWizzArdit even comes with a Lisp syntax
16:39AWizzArdI discovered it several months ago, but the homepage was down in the last weeks for some reason
16:39AWizzArdtoday it seems to be up again
16:39replacaoh, yeah. news to me!
16:40replacabrb
16:40AWizzArdmay be something like Common Lisps „Lisa”
16:43hiredmanyou might be able to do something like that with fnparse
16:44AWizzArdhiredman: is that in contrib?
16:45danlarkinfnparse is for parsing strings
16:45hiredman~fnparse
16:45clojurebotI don't understand.
16:45hiredmandanlarkin: you can define your own combinators
16:45Chousukeactually, I think fnparse can parse pretty much anything :P
16:45hiredman^-
16:45Chousukestrings are just what you usually need to parse.
16:46hiredmanso if you approach the problem as a string of tokens
16:46AWizzArdI will have a look. Maybe it is in core but new or it sits somewhere in contrib.
16:46Chousukebut I guess it'd work for data structures too
16:46hiredmanAWizzArd: nah, its on github
16:46hiredmanclojurebot: parse?
16:46clojurebotparser is http://github.com/joshua-choi/fnparse/tree/master
16:46AWizzArdthx
16:46danlarkinHm... interesting, yeah I guess you're right
16:46danlarkinwow! that's like 1000x more useful now
16:46hiredman:)
16:48AWizzArdI will have a look and see if I can provide my own combinators to search through vectors of tokens
16:55danlarkinI haven't looked at fnparse recently, but would you just write a lexer to help your combinators?
16:57hiredmanhelp?
17:20meredyddHey - how is one supposed to combine routes in Compojure?
17:20meredyddThe source is confusing - the comments suggest a Ring function should return :next if it can't match anything
17:20meredyddbut in practice, it seems they return empty 200 responses
17:21meredyddand the (routes) function appears to be expecting that they return nil if they don't match
17:55drewrApparently there's a practical difference between (take 20 (iterate inc 1)) and (range 1 21).
17:56drewrWait, I think I just realized why.
18:11lisppaste8drewr pasted "take/iterate vs range" at http://paste.lisp.org/display/83073
18:12drewrWhat's the difference between the two?
18:12drewrEven if new LazySeqs are created by each take, wouldn't they be GCed?
18:14ChrisPSQuestion: Do I need to add the locations clojure and clojure-contrib to my classpath?
18:15AWizzArdChrisPS: yes
18:15AWizzArdyou don't *need* contrib
18:15hiredman~def iterate
18:15ChrisPSgreat
18:15AWizzArdbut you also don't *need* to program ;-)
18:15hiredman:(
18:19ChrisPSI don't need contrib? why not?
18:20ChrisPShow can I read the classpath from within clojure
18:20ChrisPSfrom the repl
18:34eevarChrisPS: (System/getProperties)
18:35ChrisPShmm
18:38hiredman~def iterate
18:39ChrisPSI don't understand why a (ns whatever (:require clojure.contrib.str-utils)) give an error message
18:39ChrisPSCould not locate clojure/contrib/str_utils__init.class or clojure/contrib/str_utils.clj on classpath:
18:40hiredmanis contrib in you classpath?
18:41ChrisPSmy classpath say: /Users/wave/lisp/clj/clojure:/Users/wave/lisp/clj/clojure-contrib
18:41ChrisPSso the clojure-contrib is, but what about contrib??
18:43hiredmanby contrib I mean clojure-contrib
18:43hiredmanwhat is in /Users/wave/lisp/clj/clojure-contrib
18:43ChrisPSthen yes it is
18:43hiredmanhow are you starting clojure?
18:44ChrisPSvia slime
18:44ChrisPSemacs
18:44hiredmanhow are you setting the classpath?
18:44ChrisPSin .bash_profile
18:44hiredmanok
18:44hiredmanthat will not work
18:44ChrisPSgood
18:44hiredmanyou need to set it some how via slime
18:44ChrisPSok
18:45hiredmanbut I don't use slime or emacs for that matter
18:45hiredmanbasically java ignores CLASSPATH if you use the -cp flag
18:45ChrisPSso if just add it to the string in .emacs
18:45ChrisPSit would work
18:48ChrisPSstill, when I do a
18:48ChrisPS(doc clojure.contrib.str-utils/str-join)
18:48clojurebot"/;nil; "
18:48hiredmanclojurebot: stop being so broken
18:48clojurebotwe can't stop here! this is bat country!
18:48ChrisPShehe
18:49ChrisPSI get an exception
18:49hiredmanso does (require 'clojure.contrib.str-utils) work?
18:50ChrisPSno
18:50ChrisPSsame msg
18:50hiredman(System/getProperty "java.class.path")
18:50ChrisPSjava.io.FileNotFoundException
18:51ChrisPS"/Users/wave/lisp/clj/clojure/clojure.jar:/Users/wave/lisp/clj/swank-clojure/:/Users/wave/lisp/clj\
18:51ChrisPSah fuck, lispaste!
18:51ChrisPSwhere are thou
18:51ChrisPS@
18:51hiredmanlisppaste8: url?
18:51lisppaste8To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.
18:51ChrisPShehe, thanks
18:51ChrisPSI am getting old
18:52lisppaste8chrisPS pasted "classpath issue" at http://paste.lisp.org/display/83075
18:52hiredmando you not have a contrib jar?
18:53ChrisPSI do
18:53hiredmansome pieces of contrib rely on being AOT compiled (which happens during the jar building process)
18:53hiredmanChrisPS: the jarfile needs to be on the classpath
18:53ChrisPSI just ant'ed the contrib root
18:53hiredmannot the path to the jar file
18:54ChrisPSthe jarfile needs to be included the path-statement?
18:54hiredmanso it should be /something/something/clojure-contrib.jar
18:54ChrisPSah
18:54ChrisPSwill try now
18:54hiredmanthere are ways to do it like you are trying to do
18:54hiredmanclojurebot: jar dir
18:54clojurebotwith 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:55ChrisPSbut it will only suck in the dirs immediately below, so it's not recursive?
18:55hiredmaneh? which?
18:56hiredmanthe java classpath does not suck jars out of directories
18:56ChrisPSsay /lisp/clj/*
18:56ChrisPSok ok
18:56hiredmanthat I dunno
18:56ChrisPSnevermind
18:56hiredmanit is kind of weird, because it doesn't use the shell expension
18:56hiredmanexpansion
18:59ChrisPSit works!!
19:00ChrisPSI am a happy man, thanks hiredman for your assistance!!
22:49duncanmis this a common question: why couldn't clojure automatically convert Fns into some interface if that interface has only one method?
22:50duncanmi'm watching this video on JRuby, and it looks like JRuby can allow Ruby blocks to be used as Swing ActionListeners
22:50clojurebotthis is not a bug
22:52slashus2duncanm: Looks like clojurebot knows what you are talking about.
22:52duncanmheh
22:52hiredmandunno
22:52hiredmanI have also fetl pangs of jealousy when watching jruby do that
22:53duncanmhiredman: right?
22:54hiredman(defmacro fn->al [fun] (proxy [ActionListener] [] (actionPerformed [event] (fun event))))
22:54duncanmwhy write it as a macro?
22:55hiredmanI guess it should be a function
22:55hiredmanI wrote it a while ago, but I can't seem to find it
22:57hiredmanI started on a macro to generate single method proxies a couple of times
22:58gstampTowards the bottom of this page: http://www.dearm.co.uk/cgan/ there is a function based one
23:01hiredmansomething like (adapt ActionListener some-function)
23:01duncanmclojure-contrib has some swing-utils
23:03gstampHere'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:04duncanmgstamp: are you saying that it turns into a seq because it's printed using ()s ?
23:05hiredmanduncanm: it is turned into a seq
23:05duncanmoh
23:05hiredmanmap, filter, et al call seq on their arguments
23:06hiredman(def vector-map (comp vec map))
23:06hiredman~def vec
23:09gstampInteresting that there is an array-map but not a vector-map
23:10gstampLove that you can compose together functions so easy though. :-)
23:29duncanmhiredman: so i asked in the #JRuby channel
23:29duncanmhiredman: ruby blocks can turn into any Java interface
23:30duncanmif the interface has 2 methods, the same block gets used for both (kinda surprising)
23:30hiredmanyeah
23:31hiredmanI wish I had deleted this
23:31hiredmaner
23:31hiredmanhadn't
23:31duncanmyou hacked clojure to support that?
23:40duncanmhiredman?
23:40duncanmoh, a macro
23:41duncanmit'd be more interesting if the language supported it, no?
23:42arbscht_duncanm: not very much. this is why being a lisp is nice :)
23:43duncanmarbscht_: you prefer to explicitly write out a proxy form than having the compiler do it for you?
23:44arbscht_no, but extending the language with a macro is almost as good
23:44grrrthey, I couldn't help overhear your conversation :)
23:44grrrtI like clojure / lisp because there's no magic
23:45grrrtany magic you want you add yourself (like a fn or macro that wraps around a proxy)
23:45duncanmeven 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:45duncanmgrrrt: well, it's already 'magically' supporting Runnable and Callable
23:45grrrtwell that's fairly straightforward, you know what your're getting