2010-07-04
| 00:01 | polypus | hello bahman |
| 00:02 | polypus | is there a built in function for getting the index of the first value in a sequence for which some predicate is true? |
| 00:02 | unlink | Is this not supposed to work? (defprotocol P (f [x]) (f [x y])) |
| 00:03 | unlink | Not saying it's a good idea, I am just trying to reify an interface that looks something like that. |
| 00:12 | mudgen | hello |
| 00:12 | mudgen | does anybody know how to get clojure classloaders to work with java webstart? |
| 00:13 | mudgen | I wrote a clojure program that is launched with java webstart, but the clojure classloaders doen't seem to be working |
| 00:16 | mudgen | is this not a good time to ask questions? |
| 00:16 | Blackfoot | usually people are pretty helpful, but perhaps no one else is around. |
| 00:17 | Blackfoot | and i haven't used webstart, sorry |
| 00:24 | mudgen | can someone tell me what clojure.lang.RT is? |
| 00:26 | unlink | mudgen: The Clojure runtime. |
| 00:26 | mudgen | thanks |
| 00:27 | mudgen | i 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:27 | unlink | Man, the Java library I am using is just so stateful, I'm not sure even makes sense to attempt to use Clojure here. |
| 00:27 | mudgen | anybody know what is causing that error? |
| 00:29 | mikem | mudgen: looks like the classpath :) |
| 00:29 | mikem | mudgen: did you aot compile your clojure code? |
| 00:30 | mudgen | mikem, yes, it is AOT |
| 00:31 | rhudson | unlink: syntax for that is (defprotocol P (f [x] [x y])) |
| 00:32 | mudgen | mkiem: 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:32 | mudgen | just fine* |
| 00:32 | mudgen | the clojure classloaders aren't working or something |
| 00:32 | mikem | mudgen: hm, not sure :S |
| 00:38 | Bahman | mudge: http://groups.google.com.sg/group/clojure/browse_thread/thread/f0c69735c5a9bd03/1e0dced366af9077?lnk=gst&q=webstart&fwc=1 |
| 00:38 | Bahman | mudgen: http://groups.google.com.sg/group/clojure/browse_thread/thread/f0c69735c5a9bd03/1e0dced366af9077?lnk=gst&q=webstart&fwc=1 |
| 00:39 | Bahman | mudge: Sorry...typing mistake. |
| 00:39 | mudgen | checking it out |
| 00:48 | bortreb | polypus: swank.util/position does exactly what you want |
| 00:50 | bortreb | polypus: if you don't like swank you can just take the first value of clojure.contrib.seq-utils/positions |
| 00:53 | bortreb | I'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:54 | bortreb | since some java files depend on the newly written clj file, but the clj files depends on other (different) java files |
| 00:54 | bortreb | right now I'm just using a script to compile them in the right order |
| 00:54 | bortreb | but is there a better , standard way? |
| 00:55 | polypus | bortreb: ty |
| 01:30 | mudge | add-classpath is depreciated, what's the way to do it in clojure.1.1 ? |
| 01:31 | hiredman | don't |
| 01:31 | mudge | don't add to the classpath? |
| 01:33 | mudge | what if you can't set your classpath before hand and need to do it dynamically in your code? |
| 01:35 | tomoj | why would that be the case |
| 02:02 | bortreb | mudge: the classpath can't be changed after the jvm is initilized. |
| 02:02 | bortreb | mudge: it's an annoying limitation of the jvm |
| 02:03 | bortreb | mudge: http://stackoverflow.com/questions/252893/how-do-you-change-the-classpath-within-java |
| 02:04 | Bahman | bortreb: IIRC one can change classpath using the classloader. |
| 02:04 | Bahman | System.class.getClassLoader.setClassPath() |
| 02:05 | Bahman | Something "like" that. |
| 02:05 | hiredman | Bahman: no |
| 02:05 | Bahman | Or it was Runtime.getClassLoader()...can't remember well. |
| 02:05 | hiredman | no |
| 02:06 | Bahman | hiredman: I've done so in past. |
| 02:06 | bortreb | You 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:06 | hiredman | Bahman: no, you haven't |
| 02:07 | bortreb | as the stackoverflow answer sugests |
| 02:07 | hiredman | classloader has no such method |
| 02:07 | bortreb | you can get it with reflection but there's no "official" way to do it |
| 02:07 | hiredman | if you, you know, provide your own system classloader you can give it such a method |
| 02:07 | Bahman | hiredman: You are making me doubt it...but I've done so...just a moment I check if I still have the source code. |
| 02:07 | hiredman | Bahman: you've not |
| 02:08 | hiredman | java provides no mechanisms for dynamicaly adding to the system classpath |
| 02:09 | tomoj | how do you provide your own system classloader? |
| 02:09 | hiredman | it's a -D |
| 02:09 | tomoj | aha |
| 02:10 | hiredman | http://gist.github.com/255766 |
| 02:10 | tomoj | java.system.class.loader |
| 02:11 | hiredman | or http://gist.github.com/251980 |
| 02:11 | hiredman | if you don't like generating from asm |
| 02:12 | hiredman | (no warranty on any of that, btw) |
| 02:16 | Blackfoot | anyone else having an issue loading clojure.contrib.json from 1.2.0-SNAPSHOT: ClassNotFoundException: clojure.contrib.pprint.PrettyWriter |
| 02:22 | tomoj | no |
| 02:23 | Blackfoot | huh maybe the jar is old clojure-contrib-1.2.0-20100615.150419-128.jar |
| 02:23 | tomoj | that's the same jar I have |
| 02:24 | tomoj | and clojure.contrib.json does not mention PrettyWriter at all |
| 02:26 | Blackfoot | looks like it (:use [clojure.contrib.pprint :only (write formatter-out)] |
| 02:26 | tomoj | which causes no problems here |
| 02:28 | Blackfoot | tomoj: well i guess that means i should be able to fix it :) |
| 02:28 | Blackfoot | hiredman: ah good to know, though contrib is being used second hand in my case |
| 02:48 | Blackfoot | tomoj: thanks, found the issue: old jar file in my java classpath |
| 02:54 | Bahman | hiredman: 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:56 | Bahman | Is there any way to remove the first item of a vector? |
| 02:58 | mikem | Bahman: next |
| 03:00 | bortreb | Bahman: rest |
| 03:01 | Bahman | The difference is only the return value? |
| 03:01 | bortreb | no difference |
| 03:02 | bortreb | , (= (class (next [1 2 3]))(class (rest [1 2 3]))) |
| 03:02 | clojurebot | true |
| 03:03 | Bahman | bortreb: I mean in case there is no "rest" or "next". |
| 03:03 | bortreb | , (= (class (next []))(class (rest []))) |
| 03:03 | clojurebot | false |
| 03:03 | bortreb | interesting |
| 03:03 | Bahman | Alright...thanks. |
| 03:04 | Bahman | next returns nil...rest returns []. |
| 03:38 | Bahman | I'm writing a simple search function for a map with two arguments: key and value. |
| 03:38 | Bahman | (defn product-find [key value) |
| 03:38 | Bahman | (filter (fn [p] (= value (@p key))) @products)) |
| 03:39 | Bahman | It evaluates well in REPL but when I use it like (product-find [id 10001]) |
| 03:39 | Bahman | I get: Unable to resolve symbol: id in this context |
| 03:40 | mikem | Bahman: shouldn't id be a :id or "id" or something? |
| 03:41 | Bahman | mikem: (product-find [id 10001]) --> Unable to resolve symbol: id in this context |
| 03:42 | mikem | and what is 'id' ? is it bound to a value earlier somehow, in a let perhaps? |
| 03:42 | Bahman | id is a key in a structmap. |
| 03:42 | Bahman | (defstruct product :id :name :code :note :weight :volume) |
| 03:43 | mikem | Bahman: then why are you calling (product-find) with 'id'? shouldn't you be calling with ':id' instead? |
| 03:44 | Bahman | mikem: If I use ':id' it throws Wrong number of args passed to: core$product-find |
| 03:46 | mikem | Bahman: hm, on a limb here, what if you pass (keyword "id") instead of :id? |
| 03:48 | mikem | Bahman: 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:49 | Bahman | mikem: Let me try keyword version. |
| 03:53 | mikem | Bahman: this works for me: http://paste.lisp.org/display/112133 |
| 03:54 | Bahman | Thank you mikem...I have to figure out why mine doesn't work. |
| 03:54 | mikem | look at your definition of product-find, the brackets/parentheses in your paste above were wrong |
| 03:55 | Bahman | Doh! Found the problem! |
| 03:56 | Bahman | (product-find [id 10001]) I was passing the args as a vector :-) |
| 03:56 | mikem | Bahman: :) |
| 03:56 | Bahman | mikem: Thanks. |
| 04:06 | LauJensen | Morning all |
| 04:07 | Bahman | Morning LauJensen! |
| 04:27 | mudge | <bortreb>: maybe you can't change the classpath after the jvm initializes, but can you still load in new classes? |
| 04:27 | mudge | into java |
| 04:34 | hiredman | it's not that you cannot change the classpath, it's you cannot change the classpath of the system classloader |
| 04:35 | Bahman | hiredman: I agree :-) |
| 04:36 | mudge | i see |
| 04:36 | mudge | so you could make your own classloader with its own classpath? |
| 05:14 | bortreb | ok |
| 05:14 | bortreb | here's how you can dynamically add stuff to the classpath |
| 05:14 | bortreb | this works for me at least |
| 05:15 | bortreb | (defn add-to-classpath [file-name] (wall-hack-method java.net.URLClassLoad\ |
| 05:15 | bortreb | er 'addURL [java.net.URL] (ClassLoader/getSystemClassLoader) (.toURL (file-str \ |
| 05:15 | bortreb | file-name)))) |
| 05:17 | bortreb | I 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:33 | mudge | bortreb, thank you, i'll try it out |
| 05:34 | bortreb | you'll need java-utils and duck-streams btw |
| 05:43 | mudge | does clojure make its own class loaders for its compiled code? |
| 05:45 | bortreb | mudge: I don't believe so - it seems to use the System ClassLoader |
| 05:46 | bortreb | did add-to-classpath do anything for you? |
| 05:48 | mudge | bortreb: i haven't tried it yet, do don't have the code with me right now |
| 05:50 | bortreb | supposedly different "vendors" are free to implement even their own System Class-loader, which means that the hardcoded "addURL" method might not work universally |
| 05:50 | mudge | I just read that java webstart does not use the system loader, but uses a user-level classloader |
| 05:51 | mudge | so i guess i need to load my clojure code with the user classloader or change clojure to use the user classloader |
| 05:52 | LauJensen | Can the google groups be browsed via nntp ? |
| 06:04 | mudge | how does clojure know which classloader to use? |
| 06:09 | Bahman | LauJensen: I've searched for that a while ago and it seems it's not possible...GoogleGroups is just web UI. |
| 06:17 | mudge | does clojure use the system classloader by default? is there way to change the classloader that it uses? |
| 06:21 | mudge | anybody ever used *use-context-classloader* ? |
| 08:13 | Raynes | chouser: ping |
| 08:13 | mudge | pong |
| 08:13 | mudge | i love ping pong |
| 08:13 | Raynes | ;o |
| 08:34 | mikem | is there a function which appends one vector to another? ie [1 2] [3 4] -> [1 2 3 4] |
| 08:34 | LauJensen | ,(into [1 2 3] [4 5 6]) |
| 08:34 | clojurebot | [1 2 3 4 5 6] |
| 08:35 | mikem | LauJensen: thanks. how does (concat) compare to this? (I just found concat) |
| 08:35 | the-kenny | ,(concat [1 2 3] [4 5 6]) |
| 08:35 | clojurebot | (1 2 3 4 5 6) |
| 08:35 | the-kenny | concat returns a seq, not a vector |
| 08:36 | the-kenny | ,(doc concat) |
| 08:36 | clojurebot | "([] [x] [x y] [x y & zs]); Returns a lazy seq representing the concatenation of the elements in the supplied colls." |
| 08:36 | LauJensen | mikem: concat returns a lazyseq, into calls conj on each item, more effecient |
| 08:36 | LauJensen | sometimes concat might be what you want |
| 08:36 | LauJensen | ,(reduce conj [1 2 3] [4 5 6]) |
| 08:36 | clojurebot | [1 2 3 4 5 6] |
| 08:36 | mikem | the-kenny: right, thanks :) |
| 08:36 | mikem | ok, got it |
| 10:58 | raek | should the body of a lazy-seq always return an ISeq object, or will any seqable object do? |
| 11:08 | LauJensen | raek: All sequable items implement ISeq |
| 11:48 | raek | ,(instance? clojure.lang.ISeq [1 2 3]) |
| 11:48 | clojurebot | false |
| 11:48 | raek | ,(instance? clojure.lang.ISeq (seq [1 2 3])) |
| 11:48 | clojurebot | true |
| 11:49 | rhickey | ,(doc lazy-seq) |
| 11:49 | clojurebot | "([& 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:50 | raek | so if I want a lazy-seq to return [1 2 3], I should wrap it in a seq call? |
| 11:52 | LauJensen | raek: I think so, yea |
| 11:52 | rhickey | raek: no lazy-seq will call seq, specifically so you can return [1 2 3] etc |
| 11:52 | rhickey | apparently not documented |
| 11:53 | raek | can I assume that this will always work? |
| 11:53 | rhickey | raek: yes |
| 11:54 | rhickey | ,(lazy-seq "fred") |
| 11:54 | clojurebot | (\f \r \e \d) |
| 11:54 | rhickey | (lazy-seq [1 2 3]) |
| 11:54 | rhickey | ,(lazy-seq [1 2 3]) |
| 11:54 | clojurebot | (1 2 3) |
| 12:10 | Blackfoot | is there a way to System/setProperty in the resources path of a lein project? |
| 12:16 | arohner | Blackfoot: I believe you can put them in the :jvm-opts |
| 12:16 | arohner | Blackfoot: you might need lein 1.2 though |
| 12:17 | Blackfoot | luckily i upgraded just yesterday, i will check it out thanks |
| 13:19 | mudge | how long does it usually take for something to be approved that you posted to the clojure google group? |
| 13:26 | Nikelandjelo | Is 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:45 | Blackfoot | arohner: :jvm-opts worked great, thanks |
| 13:55 | mudge | does anybody know how to tell clojure to use a custom classloader instead of the system classloader? |
| 14:46 | mudge | mrSpec/noobek can you make up your mind? |
| 14:48 | mrSpec | I've already made ;) |
| 14:49 | mrSpec | mudge: ^ |
| 14:49 | mudge | okay mrSpec |
| 15:28 | Blackfoot | can protocols specify constructors |
| 15:30 | qbg | Blackfoot: What exactly do you want? |
| 15:31 | Blackfoot | qbg: i'd like to enforce classes implementing a protocol have a certain constructor signature |
| 15:32 | qbg | No. |
| 15:32 | qbg | At least not directly |
| 15:32 | Blackfoot | i guess the alternative is to have a method called "construct" or something that returns an instance |
| 15:32 | qbg | You could have a method in the protocol return a new object |
| 15:33 | qbg | But the issue there is what would you dispatch on? |
| 15:35 | Blackfoot | ah i see that problem |
| 15:36 | qbg | Why the need for a certain constructor signature? |
| 15:36 | Blackfoot | well the over all plan is to have a plugin type system |
| 15:37 | Blackfoot | where the use select the type of "music player" they want to use |
| 15:37 | Blackfoot | s/user selects/ |
| 15:38 | Blackfoot | so if all the music player plugins took the same constructor, it would make the plugin system more consistent |
| 15:39 | qbg | If 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:39 | Blackfoot | yea, that should work |
| 15:41 | Blackfoot | i'll try that out thanks |
| 15:42 | Blackfoot | between defrecord and deftype, one would choose defrecord if the object that they're creating should implement IPersistentMap. otherwise just use deftype? |
| 15:42 | qbg | defrecord gives you a lot for free |
| 15:43 | qbg | I'd use defrecord unless you need you need to implement an interface differently than what defrecord gives you |
| 15:44 | Blackfoot | ok |
| 15:45 | qbg | deftype seems more suited for Clojure-in-Clojure usage |
| 17:59 | nardoni | What's the best way to require all files in a directory? |
| 18:01 | Blackfoot | nardoni: similar to java, i don't think there is an easy way |
| 18:04 | nardoni | Blackfoot: |
| 18:04 | nardoni | woops |
| 18:04 | Blackfoot | you might be able to iterate over files with find-namespaces |
| 18:04 | Blackfoot | http://richhickey.github.com/clojure-contrib/find-namespaces-api.html |
| 18:05 | nardoni | i'll check it out :) |
| 18:05 | Blackfoot | something like this http://learnclojure.blogspot.com/2010/02/requiring-all-possible-namespaces.html |
| 18:07 | nardoni | I'm trying to create a templating library, with templates being in plain clojure |
| 18:08 | nardoni | I can get half way there with (load-string (slurp file)) and namespace pollution; but it's hardly ideal |
| 18:08 | nardoni | (bare in mind, I'm new to clojure ) |
| 18:33 | redalastor | I noticed nothing was pushed to the clojure repo for more than a week. Does it means we are close to a new release? |
| 18:46 | Blackfoot | how do i refer to a protocol defined in another namespace? |
| 18:46 | Chousuke | just like everything else. |
| 18:46 | Chousuke | the.namespace/Protocol |
| 18:46 | Blackfoot | (defrecord Foo [] other.namespace/Myprototype ...) throws a No such var: |
| 18:47 | Chousuke | at least, it worked for me last time I tried :P |
| 18:47 | Blackfoot | do i need to capture the result of defprotocol? |
| 18:48 | Chousuke | no |
| 18:50 | Blackfoot | hrm, maybe there is a circular dependency. play.clj both defines the protocol and :uses the defrecords based on the protocol |
| 22:22 | cais2002 | what's typical strategy to resolve this: Reflection warning, twitter.clj:363 - call to java.io.File ctor can't be resolved. |
| 22:23 | danlarkin | phew! 363 lines! |
| 22:23 | danlarkin | split that bad boy up |
| 22:24 | danlarkin | you're calling the java.io.File constructor with args it doesn't take |
| 22:29 | cais2002 | let me see, not my code |
| 22:38 | cais2002 | ok, 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:29 | itistoday | why not= and not != ? |
| 23:43 | Bahman | Hi all! |