#clojure logs

2009-09-27

02:58ngocIt seems a variable must be of one of the 4 reference types: Var, Atom, Agent and Ref. Is there a type other than these types?
03:02jwhitlarkI'm trying to compile and run a jar via ant using instructions from: http://www.lithinos.com/Compiling-Clojure-applications-using-Ant.html
03:03jwhitlarkI keep getting "Could not find the main class"
03:04jwhitlarkAre there any other recommended resources? My google-fu seems to be failing me tonight.
03:13ngocjwhitlark: Don't you want to use Maven? I use Maven to compile Clojure programs, it is very easy, just follow instructions on the Google group of Clojure.
03:14jwhitlarkhmmm. is that the preferred way?
03:14jwhitlarkngoc: I'll take a look at maven then.
03:15jwhitlarkThe interesting thing is the class file is compiled properly, and I can run it that way, but it can't find it from the manifest file in the jar.
03:16jwhitlarkI'm just trying to jar up the example on the clojure site, nothing fancy.
03:18ngocSorry I don't use Ant. But in my experience compiling Clojure with Maven is very easy because there is a convention, you can't be wrong.
03:21fulletsIs there an easier way to distinguish a valid hash map from e.g. the result of (read-string "{:a 1 :b}") than trying to print it and seeing if an exception is thrown?
03:21jwhitlarkngoc: thanks for your help. I'll go read up on maven
03:27_mstjwhitlark: Just a tiny example of doing it manually if it helps: http://dishevelled.net/compile.txt
03:27_mstnice to know what ant/maven are doing behind the scenes I think :)
03:27jwhitlarkthanks!
03:28jwhitlarkI'll give it a spin.
03:33jwhitlark_mst: Thanks so much! I got it working with you instructions, now I can compare the two jars and see where it's going wrong.
03:34_mstexcellent :)
03:50hoeck1fullets: you could just read the hashmap elements into a list and see if they are even
05:26LauJensenNotice #45 :) http://botd.wordpress.com/2009/09/26/top-posts-1247/
05:27criosjwhitlark: regarding maven, check stuartsierra's blog: http://stuartsierra.com/
05:28konrGuys, what could be wrong with my macro? It seems that the if in the anonymous function is always returning true: http://clojure.pastebin.com/m3bfea741
05:28konr*false
05:29LauJensenkonr: No backquote
05:30LauJensenkonr: Untested, by have a look at how I control the evaluation and use gensym http://clojure.pastebin.com/m75cb5358
05:42spuzHow do I create a function that returns a sequence?
05:43spuzall the functions I've seen seem to rely on existing sequence funtions to do that
05:48hoeck1spuz: thats what lazy-seq and rest for
05:50hoeck1spuz: you may want to look at the definitions of repeat, drop-while etc. of core.clj
05:52spuzactually, for returns a sequence, so I don't think I need to create one myself
05:53hoeck1sorry, typo, I meant 'lazy-seq' and 'rest' are used to build lazy sequences
05:54hoeck1and yes, often you use only the helper functions like repeat, iterate or map to create lazy sequences
05:56spuzhoeck1: yeah, I understood what you meant. I'm just trying to figure out how to filter the sequence returned by 'for'. Is it possible to add a filter within the for expression, or do I need to wrap it around a call to 'filter'?
05:58hoeck1for has a :when clause
05:58hoeck1,(for [x (range 1 5) :when (even? x)] x)
05:58clojurebot(2 4)
06:09spuzhoeck1: is there any benefit in using the :when clause over a filter apart from concision?
06:10spuzit would seem to me to be potentially less efficient as you are evaluating x twice
06:12spuzfor example: (for [x (range 1 5) :when (> 2 (Math/sqrt x))] (Math/sqrt x))
06:12spuzIs the square root not be calculated twice?
06:13hoeck1spuz: yes, but then a surrounding filter would be better
06:13spuzok
06:15hoeck1spuz: or just a chain of map and filter: (filter #(> 2 %) (map #(Math/sqrt x) (range 1 5)))
06:16spuzhoeck1: yeah map makes more sense in this case. In my case I have two variables, x and y and two ranges.
06:16hoeck1spuz: :when in filter is like filtering the sequence before mapping a function over it
06:16spuz(for [x (range n m) y (range x m)] [x y])
06:27vyWhat is the alternative to "map" ignoring the results, just doing the job with side effects.
06:30hoeck1vy: look at doseq
06:30hoeck1vy: or use (dorun (map ...))
06:32hoeck1vy: dotimes and while are also useful sometimes
09:04abbehi everyone
09:51rhickeyabbe: hi
09:53lisppaste8rhickey pasted "more functional Ikeda" at http://paste.lisp.org/display/87799
09:54abberhickey: checking out your presentation :)
09:54abberhickey: i liked when you said: love jvm, not java :)
09:55rhickeyabbe: in which talk?
09:55abberhickey: Part 1 of a presentation by Rich Hickey at the Boston Lisp meeting.
09:56rhickeyah
11:03LauJensenrhickey: Great contribution on my blog, thank you very much for showing the way :)
11:06rhickeyLauJensen: np
11:13hamzahey guys, i have the following situation, i start at x=0 y=1 suplly these coordinates to a (point x y) function i get a new point. each call takes its prev. generated point as its argument. is it possible to get a sequence of it so that i can use (take 10 (repeate call)) like structure?
11:29LauJensenhamza: did you read my last blog post? that gives you the solution in 4 different flavors :)
11:31ChousukeChouser: I have the sq-macro at http://github.com/Chousuke/clojure/tree/sq-macro in core.clj
11:31Chousukethough I think it doesn't handle namespace alias resolution yet
11:32LauJensenhamza: short version, see (iterate ...)
11:33hamzalaujensen can give url to blog post?
11:34LauJensenhamza: http://bestinclass.wordpress.com/2009/09/24/chaos-theory-vs-clojure/
11:34LauJensenthat's the one you want
11:37hamzathank you,
11:38LauJensennp
11:38raekquestion: do vars used inside agents live inside the agents or the in executing thread?
11:42serp_zomg :o
11:42raektwo serps?
11:47raekanyway, serp_ and I was discussing whether one could hide java gui objects from other threads (since they're not thread safe) by keeping them in var
11:47raekyou have any ideas, #clojure?
13:33drhodesfound this neat introspection function @ http://travis-whitton.blogspot.com/2009/06/method-introspection.html#comment-form
14:04hiredmanclojurebot: ping?
14:04clojurebotPONG!
14:15Chouserdrhodes: that looks about like how repl-utils/show started
14:44drhodesChouser: oh, thanks for the heads up, I'll check it out.
14:46emacsenwhen should I use (in-ns) and when should I make a new namespace and import the sub-namespaces?
14:59hamzahey guys, i have a function that returns a file from disk, i call (memoize serve-file) in order not to hit the disk each time, serve-file is called from compojure but output is not cached. if i change the file to check i get changes reflected on the browser output?
15:05lisppaste8hamza pasted "memoize" at http://paste.lisp.org/display/87806
15:05hamzai also wrote a simple test case it always executes the function.
15:06Chousukehamza: memoize doesn't change the function, it returns a new one
15:06Chousukehamza: so you need (def mem-atest (memoize atest))
15:07hamzakk now i get it :P.
15:09hamzaif i want to reset the cache, is there a better way to do it besides calling def.
15:11hamzaagain
15:11hiredmanif you want control over the cache, I would take the source to memoize, paste it into your app, and add the ability to clear the catch
15:11hamzakk
15:21hamzawasn't there a set! function for re deffing a var or am i mistaken?
15:24hiredmanyou might have my-memoize return a proxy of AFn, and keep the cache in under the :cache key in the metadata, so you could flush the cache by mucking with the metadata
15:25emacsenChousuke: any opinion on in-ns vs importing? I am just looking for general guidelines
15:26hiredmanin-ns has nothing to do with importing
15:26hiredmanit does no importing or namespace loading
15:26emacsenhiredman: erm, I meant use
15:27emacsenhiredman: right the guideline is when to make a new sub-namespace
15:28hamzahiredman: can you explain it a little further?
15:31hiredmanhmmm
15:33hiredman,(alter-meta! (proxy [clojure.lang.AFn] []) assoc :cache {})
15:33clojurebotjava.lang.RuntimeException: java.lang.IllegalStateException: Var null/null is unbound.
15:33hiredman~def alter-meta!
15:35hamzaok thanks,
15:39emmaHi.
15:39emmaI am forming a study group which will meet here on Freenode to work through SICP (the canonical text on CS)
15:39emmaIf anyone is interested our first meeting is beginning now. It's a text available online.
15:43emacsenSICP redone with clj or just SICP?
15:43emmaemacsen: it's SICP.
15:44kwertiiI thought Knuth was the canonical text ;)
15:46metvop#j /sicp
15:49emmaWe are having our first meeting in ##club-classroom
16:37kmurph79i'm going through this http://bestinclass.wordpress.com/2009/09/24/chaos-theory-vs-clojure/ can someone explain exactly what (iterate #(* 2 %) 1)) does?
16:42arbschtkmurph79: it returns a lazy sequence of the powers of 2
16:42arbscht,(take 10 (iterate #(* 2 %) 1))
16:42clojurebot(1 2 4 8 16 32 64 128 256 512)
16:43kmurph79arbscht: thanks. what does the # and % do ?
16:44arbscht#(* 2 %) is effectively identical to (fn [x] (* 2 x))
16:45arbschtit's shorthand for anonymous functions
16:45Chousukeyou can also have more parameters with %n where n can be anything from 1 to 20, or %& for the "rest" arg
16:46Chousukejust % is equal to %1
16:47kmurph79interesting. thank you.
16:49arbscht,(take 10 (iterate (partial * 2) 1))
16:49clojurebot(1 2 4 8 16 32 64 128 256 512)
16:58somnium``how would you write a macro to create a number of seperate function calls, like (mymac fun & args) -> (fun arg0) ... (fun argn)
16:58somnium``trying to do it recursively but not getting it
16:59LauJensen~@(for [a# ~args] (~fun a#)) - something like that I believe
16:59clojurebotfor is a loop...in Java
16:59Chousukehmm
16:59arbschtsomnium``: what are you really trying to do?
17:00Chousuke(doseq [a args] (f a))
17:00Chousuke:P
17:00somnium``in an xml builder, I have helper functions that return vectors, but splicing sequences adds complications
17:01somnium``they work as expected as individual calls, but kind of repetitive to write (fun a) (fun b) (fun c) ...
17:05somnium``with side effects?
17:05somnium``hadn't considered that
17:05Chousukewell, hm
17:06somnium``its wrapped around html lib in compojure, so in something like [:tag1 [:tag2 (myhelper "foo")]] -> [:tag1 [:tag2 [:sometag "foo"]]]
17:07Chousuke(defmacro foo [f argv] `(do ~@(for [a argv] (list f a))) or something?
17:07somnium``want to be able to do [:tag1 [:tag2 (myhelpers "foo" "bar" "baz")]] -> [:tag1 [:tag2 (myhelper "foo") (myhelper "bar") etc...
17:08somnium``will try that
17:10Chousukeremember though that you can only return one expression from a macro
17:10somnium``yeah...
17:10Chousukeperhaps you could do `[:tag2 ~@(myhelpers whatever)]?
17:11somnium``may have to wrap the whole builder in a macro
17:12somnium``why only one expression form a macro? seems like a non-first class special form
17:13Chousukeyou can only return one thing from ANY function :)
17:14somnium``maybe I should just teach the builder to auto-splice sequences...
17:14Chouseryou're sure it doesn't do that already?
17:14ChousukeI mean, sure you can return multiple things wrapped in a (do ...) but then the (do ...) makes it a single expression :P
17:14somnium``not in my tests
17:15Chouserthis is compojure?
17:15somnium``yeah
17:15somnium``Im wrapping it with some stuff that operates on the vectors before html gets called
17:19somnium``I was working out a way to do layouts and partials with one context, so I came up (defview [& args] [some content]) -> (fn [context] (let [arg1 (context :arg1) ... argn (context :argn)]), so now they compose with (render {:initial bindings} :views.foo :views.bar views.zonk)
17:19somnium``but my helpers broke :(
17:20Chousersomnium``: use a seq instead of a vector. it works
17:20Chouser(html-tree [:html 1 (list 2 3 4) 5]) ==> "<html>12345</html>"
17:21somnium``ah
17:21clojurebotPaul Graham is the creator of the other new lisp
17:21somnium``strings are ok
17:21somnium``that may make things much easier
17:21somnium``thanks
17:21somnium``seqs of strings
17:21ChouserI think seqs of anything should work
17:22somnium``hmm
17:22Chouseruser=> (html-tree [:html [:p 1] (list [:p 2] 3 4) [:p 5]])
17:22Chouser"<html><p>1</p><p>2</p>34<p>5</p></html>"
17:23Chouserthat's the most I've ever used Compojure. :-D
17:27somnium``.. I found a simple solution, just have the helpers evaluate the tag and return a string .. thanks all
17:48somnium``is there a pred like string? for functions? or an idiomatic way to test?
17:54LauJensen,(string? "is there?")
17:54clojurebottrue
17:55LauJensen,(ifn? #(println "foo"))
17:55clojurebottrue
17:55LauJensen,(ifn? (println "foo"))
17:55clojurebotfoo
18:06LauJensensomnium``: You got that? :)
18:07rafsoaken,(ifn? ifn?)
18:07clojurebottrue
18:17somnium``got it
18:17somnium``thanks
18:18somnium``still finding the names of some core functions to be rather obscure
18:35Makoryu,(ifn? defn)
18:35clojurebotjava.lang.Exception: Can't take value of a macro: #'clojure.core/defn
18:44Chouser,(fn? fn?)
18:44clojurebottrue
18:45Chouser,(fn? fn*)
18:45clojurebotjava.lang.Exception: Unable to resolve symbol: fn* in this context
18:50Chouser,(fn? (fn* []))
18:50clojurebottrue
18:50Makoryu,(bound? 'foo)
18:50clojurebotjava.lang.Exception: Unable to resolve symbol: bound? in this context
18:51MakoryuWhoops
19:04hamzahey guys, i have two sets such as the following #{{:tag "key" , :url "test"}} #{{:tag "key" , :url "test"}} how can i create a set that has the same item twice?
19:05Makoryu"how can i create a set that has the same item twice?" <- Think about this for a moment.
19:06MakoryuI don't think what you want is a set.
19:06Makoryu, #{"pizza" "pizza"}
19:06clojurebot#{"pizza"}
19:07Makoryu, ["pizza" "pizza"]
19:07clojurebot["pizza" "pizza"]
19:08hamzawell my plan was to create a set of :tag :url values then select url's based on tags..
19:10Makoryu, #{{:tag 'foo :url "slashdot"} {:tag 'foo :url "reddit"}}
19:10clojurebot#{{:tag foo, :url "slashdot"} {:tag foo, :url "reddit"}}
19:11Makoryuhamza: As long as the URLs are different, you're all set
19:11Makoryuhamza: I'm really curious why you're using a set if you actually want them to be identical, though
19:11Makoryuhamza: If you need duplicate elements, use another container! Like, say, a vector....
19:11hamzamy bad, i should get some sleep. i thouth about it wrong url's are different so there should not be any problems.
19:16hamzaquestion, is it possible to get a list of distinct tags?
19:18licoresse(reduce ...) = inject:into: in Smalltalk?
19:42jwhitlarkI have a swing application where I want a pop up menu to update according to the value of a ref (or atom, not sure which to use). Any suggestions? Perhaps someway to setup a callback for when a value changes? Or do I need to go further and implement some sort of hooks/advice system?
19:47jwhitlarkhmmm. doseq with fill-queue looks like it might have potential..
19:49Chouserhm, that doesn't sound quite right.
19:49licoresse,(doc proxy)
19:49clojurebot"([class-and-interfaces args & fs]); class-and-interfaces - a vector of class names args - a (possibly empty) vector of arguments to the superclass constructor. f => (name [params*] body) or (name ([params*] body) ([params+] body) ...) Expands to code which creates a instance of a proxy class that implements the named class/interface(s) by calling the supplied fns. A single class, if provided, must be first. If not provid
19:51jwhitlarkChouser: no?
19:51jwhitlarkI was looking at http://infolace.blogspot.com/2009/08/simple-webhooks-with-clojure-and-ring.html, but it was just off the top of my head.
19:58jwhitlarkDo I need to go read up on java events? Would that be a reasonable way to do it?
20:05jwhitlarkI guess what I'm really asking is if the java event model extends (is extendable?) beyond GUIs.
20:15ambientit's a bit troubling to me that i have to have such an intimate knowledge with java also if i want to use clojure :\
20:15hamzawhy is this not working {:t 'v {:u 'u :m 't}}
20:15hamza,{:t 'v {:u 'u :m 't}}
20:15clojurebotjava.lang.ArrayIndexOutOfBoundsException: 3
20:16hiredmanhamza: maps need pairs of elements
20:17hiredmanyou have three things there
20:17hamzawhat i am trying to do is a map of map's
20:17hiredmanentirely possible
20:17hamza{:t 'v :y {:u 'u :m 't}}
20:18licoresseyou still need a key
20:18hiredmanthat will work fine
20:18hamza,{:t 'v :y {:u 'u :m 't}}
20:18clojurebot{:t v, :y {:u u, :m t}}
20:28MakoryuThat should really throw a more useful error than ArrayIndexOutOfBoundsException
20:30iceySo... for you guys on osx- how are you managing your classpath / dependencies? just putting everything in a jar folder? something else
20:30icey?
20:31Makoryuicey: Well, on OS X, the default classpath is something like .:/Library/Java/Extensions
20:31MakoryuI keep all my libraries in the latter location
20:31iceyhmmm, thanks Makoryu!
20:42lisppaste8hiredman annotated #87611 "infinite seq of swing events" at http://paste.lisp.org/display/87611#2
21:26licoressehow can I pretty-print automatically the output of lists in the repl?
21:26licoresseI am using slime
21:27licoresse,pretty print
21:27clojurebotjava.lang.Exception: Unable to resolve symbol: pretty in this context
21:27licoresse,prettyprint
21:27clojurebotjava.lang.Exception: Unable to resolve symbol: prettyprint in this context
21:27licoresseclojurebot: pretty print
21:27clojurebotHuh?
21:28licoresseright...
21:33Chouserlicoresse: there's a pretty printer in contrib, but I don't know how to hook it into slime
21:34kylesmithis there any equivalent to update-in but with functions? something like (update-with m [fn & fns] f & args)
21:36Chouseryes, I just can't think of the name.
21:36licoresseChouser: ok
21:37kylesmithI could replace fns with (apply comp fns) of course.
21:37Chouseroh, wait.
21:38Chousersorry, I misread
21:38Chouseryou want to provide a list of fns?
21:39kylesmithyes. I'm trying to incrementally build up an arbitrarily nested structure. When I recur, I can either keep a list of fns or compose them.
21:40Chouserok, you'll have to do (apply comp fns) or equiv.
21:40kylesmithI could probably restrict myself to nested vectors, then I could just use update-in with a list of ints, but fns would be more convenient.
21:44kylesmithI'm basically composing first's and last's, which won't have a fixed index on each iteration, hence the problem.
21:56licoressepprint was the pretty printer I was looking for
22:06kylesmithI can't access paste. is it down?
22:29Makoryukylesmith: There's always another paste.
22:29Makoryuhttp://gist.github.com/
22:31kylesmithhttp://gist.github.com/195087
22:36Raynessnipt.org is a pretty neat pastebin.
22:37hiredmankylesmith: saying update-with works on an associative structure seems like a misnomer
22:38kylesmithahh, I didn't change the docstring
22:38hiredman,(update-in [1 2 [[3 4 5]]] [2] (comp #(conj % 6) first))
22:38clojurebot[1 2 [3 4 5 6]]
22:38hiredman,(update-in [1 2 [[3 4 5]]] [2 1] conj 6)
22:38clojurebot[1 2 [[3 4 5] (6)]]
22:39hiredmananyway
22:39kylesmithhmm
22:39hiredmanit seems like you want to apply a function to the nth item in something
22:40hiredmanwhat happens if a collection contains multiple copies of [[3 4 5]]
22:41kylesmithprobably bad things. I'm still thinking through this.
23:53hamzais there any documantation on how to use the complex numbers lib in contrib?