#clojure logs

2010-07-04

00:01polypushello bahman
00:02polypusis there a built in function for getting the index of the first value in a sequence for which some predicate is true?
00:02unlinkIs this not supposed to work? (defprotocol P (f [x]) (f [x y]))
00:03unlinkNot saying it's a good idea, I am just trying to reify an interface that looks something like that.
00:12mudgenhello
00:12mudgendoes anybody know how to get clojure classloaders to work with java webstart?
00:13mudgenI wrote a clojure program that is launched with java webstart, but the clojure classloaders doen't seem to be working
00:16mudgenis this not a good time to ask questions?
00:16Blackfootusually people are pretty helpful, but perhaps no one else is around.
00:17Blackfootand i haven't used webstart, sorry
00:24mudgencan someone tell me what clojure.lang.RT is?
00:26unlinkmudgen: The Clojure runtime.
00:26mudgenthanks
00:27mudgeni am getting this error from a java webstart program that tries to load my clojure classes: java.io.FileNotFoundException: Could not locate clojure/core__init.class or clojure/core.clj on classpath:
00:27unlinkMan, the Java library I am using is just so stateful, I'm not sure even makes sense to attempt to use Clojure here.
00:27mudgenanybody know what is causing that error?
00:29mikemmudgen: looks like the classpath :)
00:29mikemmudgen: did you aot compile your clojure code?
00:30mudgenmikem, yes, it is AOT
00:31rhudsonunlink: syntax for that is (defprotocol P (f [x] [x y]))
00:32mudgenmkiem: it isn't a problem with the classpath, because the program finds clojure.jar just finds and starts to run my clojure program, it's that the clojure itself cannot find its own classes
00:32mudgenjust fine*
00:32mudgenthe clojure classloaders aren't working or something
00:32mikemmudgen: hm, not sure :S
00:38Bahmanmudge: http://groups.google.com.sg/group/clojure/browse_thread/thread/f0c69735c5a9bd03/1e0dced366af9077?lnk=gst&q=webstart&fwc=1
00:38Bahmanmudgen: http://groups.google.com.sg/group/clojure/browse_thread/thread/f0c69735c5a9bd03/1e0dced366af9077?lnk=gst&q=webstart&fwc=1
00:39Bahmanmudge: Sorry...typing mistake.
00:39mudgenchecking it out
00:48bortrebpolypus: swank.util/position does exactly what you want
00:50bortrebpolypus: if you don't like swank you can just take the first value of clojure.contrib.seq-utils/positions
00:53bortrebI'm having a lot of trouble integrating clojure with my team's java project -- I want to rewrite a few .java source files with better clojure versions, but I can't figure out how to compile the whole thing, s
00:54bortrebsince some java files depend on the newly written clj file, but the clj files depends on other (different) java files
00:54bortrebright now I'm just using a script to compile them in the right order
00:54bortrebbut is there a better , standard way?
00:55polypusbortreb: ty
01:30mudgeadd-classpath is depreciated, what's the way to do it in clojure.1.1 ?
01:31hiredmandon't
01:31mudgedon't add to the classpath?
01:33mudgewhat if you can't set your classpath before hand and need to do it dynamically in your code?
01:35tomojwhy would that be the case
02:02bortrebmudge: the classpath can't be changed after the jvm is initilized.
02:02bortrebmudge: it's an annoying limitation of the jvm
02:03bortrebmudge: http://stackoverflow.com/questions/252893/how-do-you-change-the-classpath-within-java
02:04Bahmanbortreb: IIRC one can change classpath using the classloader.
02:04BahmanSystem.class.getClassLoader.setClassPath()
02:05BahmanSomething "like" that.
02:05hiredmanBahman: no
02:05BahmanOr it was Runtime.getClassLoader()...can't remember well.
02:05hiredmanno
02:06Bahmanhiredman: I've done so in past.
02:06bortrebYou can change the classpath IF you know what the main system classloader is but it's not gauranteed to always work across all jvms
02:06hiredmanBahman: no, you haven't
02:07bortrebas the stackoverflow answer sugests
02:07hiredmanclassloader has no such method
02:07bortrebyou can get it with reflection but there's no "official" way to do it
02:07hiredmanif you, you know, provide your own system classloader you can give it such a method
02:07Bahmanhiredman: You are making me doubt it...but I've done so...just a moment I check if I still have the source code.
02:07hiredmanBahman: you've not
02:08hiredmanjava provides no mechanisms for dynamicaly adding to the system classpath
02:09tomojhow do you provide your own system classloader?
02:09hiredmanit's a -D
02:09tomojaha
02:10hiredmanhttp://gist.github.com/255766
02:10tomojjava.system.class.loader
02:11hiredmanor http://gist.github.com/251980
02:11hiredmanif you don't like generating from asm
02:12hiredman(no warranty on any of that, btw)
02:16Blackfootanyone else having an issue loading clojure.contrib.json from 1.2.0-SNAPSHOT: ClassNotFoundException: clojure.contrib.pprint.PrettyWriter
02:22tomojno
02:23Blackfoothuh maybe the jar is old clojure-contrib-1.2.0-20100615.150419-128.jar
02:23tomojthat's the same jar I have
02:24tomojand clojure.contrib.json does not mention PrettyWriter at all
02:26Blackfootlooks like it (:use [clojure.contrib.pprint :only (write formatter-out)]
02:26tomojwhich causes no problems here
02:28Blackfoottomoj: well i guess that means i should be able to fix it :)
02:28Blackfoothiredman: ah good to know, though contrib is being used second hand in my case
02:48Blackfoottomoj: thanks, found the issue: old jar file in my java classpath
02:54Bahmanhiredman: Couldn't find the source for the classpath stuff...but IIRC I used an approach similar to what bortreb pointed out to connect to a PG instance.
02:56BahmanIs there any way to remove the first item of a vector?
02:58mikemBahman: next
03:00bortrebBahman: rest
03:01BahmanThe difference is only the return value?
03:01bortrebno difference
03:02bortreb, (= (class (next [1 2 3]))(class (rest [1 2 3])))
03:02clojurebottrue
03:03Bahmanbortreb: I mean in case there is no "rest" or "next".
03:03bortreb, (= (class (next []))(class (rest [])))
03:03clojurebotfalse
03:03bortrebinteresting
03:03BahmanAlright...thanks.
03:04Bahmannext returns nil...rest returns [].
03:38BahmanI'm writing a simple search function for a map with two arguments: key and value.
03:38Bahman(defn product-find [key value)
03:38Bahman (filter (fn [p] (= value (@p key))) @products))
03:39BahmanIt evaluates well in REPL but when I use it like (product-find [id 10001])
03:39BahmanI get: Unable to resolve symbol: id in this context
03:40mikemBahman: shouldn't id be a :id or "id" or something?
03:41Bahmanmikem: (product-find [id 10001]) --> Unable to resolve symbol: id in this context
03:42mikemand what is 'id' ? is it bound to a value earlier somehow, in a let perhaps?
03:42Bahmanid is a key in a structmap.
03:42Bahman(defstruct product :id :name :code :note :weight :volume)
03:43mikemBahman: then why are you calling (product-find) with 'id'? shouldn't you be calling with ':id' instead?
03:44Bahmanmikem: If I use ':id' it throws Wrong number of args passed to: core$product-find
03:46mikemBahman: hm, on a limb here, what if you pass (keyword "id") instead of :id?
03:48mikemBahman: btw, looks like you don't have properly balanced brackets/parens in your definition of product-find, at least from the paste on IRC
03:49Bahmanmikem: Let me try keyword version.
03:53mikemBahman: this works for me: http://paste.lisp.org/display/112133
03:54BahmanThank you mikem...I have to figure out why mine doesn't work.
03:54mikemlook at your definition of product-find, the brackets/parentheses in your paste above were wrong
03:55BahmanDoh! Found the problem!
03:56Bahman(product-find [id 10001]) I was passing the args as a vector :-)
03:56mikemBahman: :)
03:56Bahmanmikem: Thanks.
04:06LauJensenMorning all
04:07BahmanMorning LauJensen!
04:27mudge<bortreb>: maybe you can't change the classpath after the jvm initializes, but can you still load in new classes?
04:27mudgeinto java
04:34hiredmanit's not that you cannot change the classpath, it's you cannot change the classpath of the system classloader
04:35Bahmanhiredman: I agree :-)
04:36mudgei see
04:36mudgeso you could make your own classloader with its own classpath?
05:14bortrebok
05:14bortrebhere's how you can dynamically add stuff to the classpath
05:14bortrebthis works for me at least
05:15bortreb(defn add-to-classpath [file-name] (wall-hack-method java.net.URLClassLoad\
05:15bortreber 'addURL [java.net.URL] (ClassLoader/getSystemClassLoader) (.toURL (file-str \
05:15bortrebfile-name))))
05:17bortrebI made a random clojure project after initializing a jvm then called this with the path to the src directory of that project and was successfully able to load clojure files from that path. Beyond that I don't know if it will work for you.
05:33mudgebortreb, thank you, i'll try it out
05:34bortrebyou'll need java-utils and duck-streams btw
05:43mudgedoes clojure make its own class loaders for its compiled code?
05:45bortrebmudge: I don't believe so - it seems to use the System ClassLoader
05:46bortrebdid add-to-classpath do anything for you?
05:48mudgebortreb: i haven't tried it yet, do don't have the code with me right now
05:50bortrebsupposedly different "vendors" are free to implement even their own System Class-loader, which means that the hardcoded "addURL" method might not work universally
05:50mudgeI just read that java webstart does not use the system loader, but uses a user-level classloader
05:51mudgeso i guess i need to load my clojure code with the user classloader or change clojure to use the user classloader
05:52LauJensenCan the google groups be browsed via nntp ?
06:04mudgehow does clojure know which classloader to use?
06:09BahmanLauJensen: I've searched for that a while ago and it seems it's not possible...GoogleGroups is just web UI.
06:17mudgedoes clojure use the system classloader by default? is there way to change the classloader that it uses?
06:21mudgeanybody ever used *use-context-classloader* ?
08:13Rayneschouser: ping
08:13mudgepong
08:13mudgei love ping pong
08:13Raynes;o
08:34mikemis there a function which appends one vector to another? ie [1 2] [3 4] -> [1 2 3 4]
08:34LauJensen,(into [1 2 3] [4 5 6])
08:34clojurebot[1 2 3 4 5 6]
08:35mikemLauJensen: thanks. how does (concat) compare to this? (I just found concat)
08:35the-kenny,(concat [1 2 3] [4 5 6])
08:35clojurebot(1 2 3 4 5 6)
08:35the-kennyconcat returns a seq, not a vector
08:36the-kenny,(doc concat)
08:36clojurebot"([] [x] [x y] [x y & zs]); Returns a lazy seq representing the concatenation of the elements in the supplied colls."
08:36LauJensenmikem: concat returns a lazyseq, into calls conj on each item, more effecient
08:36LauJensensometimes concat might be what you want
08:36LauJensen,(reduce conj [1 2 3] [4 5 6])
08:36clojurebot[1 2 3 4 5 6]
08:36mikemthe-kenny: right, thanks :)
08:36mikemok, got it
10:58raekshould the body of a lazy-seq always return an ISeq object, or will any seqable object do?
11:08LauJensenraek: All sequable items implement ISeq
11:48raek,(instance? clojure.lang.ISeq [1 2 3])
11:48clojurebotfalse
11:48raek,(instance? clojure.lang.ISeq (seq [1 2 3]))
11:48clojurebottrue
11:49rhickey,(doc lazy-seq)
11:49clojurebot"([& body]); Takes a body of expressions that returns an ISeq or nil, and yields a Seqable object that will invoke the body only the first time seq is called, and will cache the result and return it on all subsequent seq calls."
11:50raekso if I want a lazy-seq to return [1 2 3], I should wrap it in a seq call?
11:52LauJensenraek: I think so, yea
11:52rhickeyraek: no lazy-seq will call seq, specifically so you can return [1 2 3] etc
11:52rhickeyapparently not documented
11:53raekcan I assume that this will always work?
11:53rhickeyraek: yes
11:54rhickey,(lazy-seq "fred")
11:54clojurebot(\f \r \e \d)
11:54rhickey(lazy-seq [1 2 3])
11:54rhickey,(lazy-seq [1 2 3])
11:54clojurebot(1 2 3)
12:10Blackfootis there a way to System/setProperty in the resources path of a lein project?
12:16arohnerBlackfoot: I believe you can put them in the :jvm-opts
12:16arohnerBlackfoot: you might need lein 1.2 though
12:17Blackfootluckily i upgraded just yesterday, i will check it out thanks
13:19mudgehow long does it usually take for something to be approved that you posted to the clojure google group?
13:26NikelandjeloIs there any macro, which takes map, keys. And creates local bindings for according keys? I only know how to do it with function arguments like this: (fn [ {:keys [a b c]} ] )
13:45Blackfootarohner: :jvm-opts worked great, thanks
13:55mudgedoes anybody know how to tell clojure to use a custom classloader instead of the system classloader?
14:46mudgemrSpec/noobek can you make up your mind?
14:48mrSpecI've already made ;)
14:49mrSpecmudge: ^
14:49mudgeokay mrSpec
15:28Blackfootcan protocols specify constructors
15:30qbgBlackfoot: What exactly do you want?
15:31Blackfootqbg: i'd like to enforce classes implementing a protocol have a certain constructor signature
15:32qbgNo.
15:32qbgAt least not directly
15:32Blackfooti guess the alternative is to have a method called "construct" or something that returns an instance
15:32qbgYou could have a method in the protocol return a new object
15:33qbgBut the issue there is what would you dispatch on?
15:35Blackfootah i see that problem
15:36qbgWhy the need for a certain constructor signature?
15:36Blackfootwell the over all plan is to have a plugin type system
15:37Blackfootwhere the use select the type of "music player" they want to use
15:37Blackfoots/user selects/
15:38Blackfootso if all the music player plugins took the same constructor, it would make the plugin system more consistent
15:39qbgIf the plugins are going to be written in Clojure, why not just specify a construct function that must exist in the plugin's namespace?
15:39Blackfootyea, that should work
15:41Blackfooti'll try that out thanks
15:42Blackfootbetween defrecord and deftype, one would choose defrecord if the object that they're creating should implement IPersistentMap. otherwise just use deftype?
15:42qbgdefrecord gives you a lot for free
15:43qbgI'd use defrecord unless you need you need to implement an interface differently than what defrecord gives you
15:44Blackfootok
15:45qbgdeftype seems more suited for Clojure-in-Clojure usage
17:59nardoniWhat's the best way to require all files in a directory?
18:01Blackfootnardoni: similar to java, i don't think there is an easy way
18:04nardoniBlackfoot:
18:04nardoniwoops
18:04Blackfootyou might be able to iterate over files with find-namespaces
18:04Blackfoothttp://richhickey.github.com/clojure-contrib/find-namespaces-api.html
18:05nardonii'll check it out :)
18:05Blackfootsomething like this http://learnclojure.blogspot.com/2010/02/requiring-all-possible-namespaces.html
18:07nardoniI'm trying to create a templating library, with templates being in plain clojure
18:08nardoniI can get half way there with (load-string (slurp file)) and namespace pollution; but it's hardly ideal
18:08nardoni(bare in mind, I'm new to clojure )
18:33redalastorI noticed nothing was pushed to the clojure repo for more than a week. Does it means we are close to a new release?
18:46Blackfoothow do i refer to a protocol defined in another namespace?
18:46Chousukejust like everything else.
18:46Chousukethe.namespace/Protocol
18:46Blackfoot(defrecord Foo [] other.namespace/Myprototype ...) throws a No such var:
18:47Chousukeat least, it worked for me last time I tried :P
18:47Blackfootdo i need to capture the result of defprotocol?
18:48Chousukeno
18:50Blackfoothrm, maybe there is a circular dependency. play.clj both defines the protocol and :uses the defrecords based on the protocol
22:22cais2002what's typical strategy to resolve this: Reflection warning, twitter.clj:363 - call to java.io.File ctor can't be resolved.
22:23danlarkinphew! 363 lines!
22:23danlarkinsplit that bad boy up
22:24danlarkinyou're calling the java.io.File constructor with args it doesn't take
22:29cais2002let me see, not my code
22:38cais2002ok, it seems that two of File's constructor take 1 parameter, and clojure is not able to auto-derive which one to resolve to. adding type hint seems to address it
23:29itistodaywhy not= and not != ?
23:43BahmanHi all!