#clojure logs

2010-05-08

00:55cap11235I'm trying to extend JPanel using gen-class, and I can't find a way to implement a constructor so I can add a KeyListener to it. From what I can tell, :init is only for setting up the :state reference for the class, and calling super's contructors. I tried having it have "this" as a parameter, but I get get an IllegalArgumentException. How can I add my KeyListener?
01:13Drakesonsometimes (maybe whenever a jar is actually downloaded) lein deps nags something like Exception in thread "main" java.lang.NoClassDefFoundError: clojure/lang/Agent
01:14Drakesondoes that happen to you, too?
01:24tomojnever seen that before
01:24tomojDrakeson: ^
01:28Drakesontomoj: thanks
01:48technomancyDrakeson: that's a known bug; shouldn't affect functionality
01:48technomancyyou can ctrl+c your way out of it
01:49technomancyperils of living on the edge
01:49technomancyDrakeson: it's not happening in a stable release, is it?
01:52Drakesontechnomancy: no, but I cannot switch back to the stable. (I need :repositories, for instance).
01:53Drakesontechnomancy: do you plan on integrating a `search' task?
01:53technomancyDrakeson: not in the next release, possibly in 1.3
01:55Drakesonhow about a cache (as in apt-cache update), for instance in order to know which repository to find [the latest of] each artifact from
01:56technomancyDrakeson: it's a possibility; I haven't really thought it all the way through
01:56technomancyweb-based search works well enough that it's not the highest priority for the next release for me
01:58Drakesonwell, that is not just for search, it is to speedup the process of finding the repository that has the latest version of an artifact. If I am not mistaken, it currently hits all the repositories everytime lein deps is issued.
01:59technomancyyes, but changing that behaviour would involve hacking maven itself
01:59Drakesonaah, I see.
01:59technomancythere are a lot of ways you could be smarter than mvn's current behaviour obviously, but I don't think any of them are really doable without at least doubling lein's LOC count
02:00technomancywould love to be proven wrong though =)
02:00DrakesonWill seting up a local maven "proxy" help?
02:01technomancyyeah, definitely
02:01technomancyI mean, probably
02:02technomancyactually I wonder if the Agent classdef not found is a Clojure bug
02:03replaca late friday night in #clojure. hi, gang
02:03technomancyreplaca: heyo
02:03technomancyreplaca: as a pprint kind of guy you might be interested in this: http://github.com/technomancy/serializable-fn
02:04replacatechnomancy: saw it. very cute!
02:04technomancywe hacked it up at last night's seattle clojure meeting
02:04replacaI've thought about doing that a bunch of times, but never actually sat down to work it all the way out
02:05technomancyit was way easier than I thought it'd be now that you have access to &form and &env
02:05technomancyI tried adapting clojure.core/fn to do it, but the weirdness of how that macro is defined stymied me
02:05replacayeah, I was looking at that a week or so ago and there's a lot going on there
02:06technomancythe first hundred lines of core.clj have changed a lot since I last looked =)
02:06technomancyit was pretty illuminating to go over it though, shows pretty well how &form and &env are done
02:07replacacore.clj is kind of like the bible, it has to be studied and you also have to take context into account (since it unfolds in order)
02:07replacaI've been messing around with declare to keep it from squashing metadata
02:07technomancythat analogy works surprisingly well
02:09replacain the beginning, Rich said "Let there be #'list and there was #'list"
02:10technomancy"and Rich divided the fns from the macros..."
02:11technomancyman, I think it's bad when I break things while hacking swank; I hate to think what it's like when you mix things up while redefining fn
02:12replacayeah, but it breaks pretty quickly at least
02:15replacait's hard to even have a conversation about git vs. perforce anymore. So much of what I do would be unimaginably annoying in perforce
04:33fnuctionDoes anyone know if ClojureCLR will work against .Net 4?
05:14Borkdudefnuction: no, I haven't got it working in my VS2008 whatsoever
05:14BorkdudeI didn't mean no, it doesn't work on .NET 4, I meant: I don't know -- sorry ;)
05:16fnuctionI had it working against 3.5 in VS 2010, then I broke it.
05:18fnuctionPost on the Google group explains why..
05:32nurvHi.
05:38Borkdudefnuction: I didn't follow the GG much, I just tried what was said on the website but I kept getting errors
05:39BorkdudeSomething about references it couldn't find, although Intellisense could find it
05:48fnuctionBorkdude: There are lots of potential problems with finding multiple version of the assemblies etc.
05:49fnuctionnurv: Hi.
05:50Borkdudeyes, hello nurv
08:11GeoffSKcan some suggest why http://pastebin.com/raw.php?i=hsqMPeru causes a java exception?
08:20hoeckGeoffSK: probably the #((echo name running))
08:20hoecktry #(echo name running) instead
08:21hoeckbecause the echo funktion returns nil and you dont want to call nil #(nil) <- throws NPE
08:24GeoffSKhoeck: thanks (again)
08:25hoeckGeoffSK: np :)
08:25GeoffSKbtw, is this an acceptable way to tell a thread to exit?
09:27tufflaxIt's great that I can do (rest [1 2 3]) on vectors like that, but how can I use that as a vector again? The class of it is clojure.lang.PersistentVector$ChunkedSeq, so underneath somehow it is still a vector, so I should be able to "cast" it back or something, yes?
09:49patrkristufflax: the answer may depend on what you're trying to do here
09:49patrkrisusually, if you're just looping through a vector to do something to each item, then it doesn't matter that you're not getting a vector back
09:50patrkrisbut for cases where you need to get a subvector the aptly named subvec function may help you
10:07patrkrisrhickey: if you are there, could you help me understand a few things about obstruction freedom?
10:12zakwilsonI'm finding several tutorials and libraries related to Google App Engine with Clojure. Is there one library that's generally preferred over others?
10:19SynrGhmm. something's wrong with my vimclojure ... doesn't look like localleader is doing its stuff ...
10:20SynrGif i press \ then s, it just performs an 's'
10:20SynrG:p
10:25patrkrisSynrG: have you started the nailgun server?
10:29SynrGyes
10:30patrkrisand does the nailgun server have the necessary .jar-files in its classpath?
10:30patrkrisyou can check the classpath by invoking `ng ng-cp`
10:49SynrGpatrkris: seems like a vim issue, not a nailgun issue
10:50SynrGpressing \ and *any* other key doesn't do anything. it's as if i hadn't pressed the key at all :p
10:52patrkrisSynrG: I had the same symptoms. It seems that vimclojure does not map keys for starting the REPL and performing evaluation unless it detects that the nailgun server is started. Even though you may have set the localleader to something, I don't think it comes into effect unless some key combination uses it.
10:53SynrGaha
10:53patrkrisSynrG: but of course, it could also be a Vim issue. Did you get syntax highlighting working? Just to get an indication whether you installed vimclojure's vim scripts correctly into ~/.vim
10:54SynrGsyntax highlighting works fine
10:54patrkrisOk. And you unzipped the vim-stuff as per the instructions?
10:55SynrGyes.
10:56patrkrisOk. Then I'm pretty sure it has something to do with your nailgun setup. Btw, are you using a *nix or Windows?
10:56SynrGwhen i ask vim what the filetype is when i'm editing a file it says 'clojure'
10:56SynrG*nix
10:56patrkrisok, that's fine then
10:56SynrGdebian, to be precise
10:56patrkrisOk. Do you have the nailgun client in your path?
10:56SynrGyes
10:57patrkrishave you tried invoking ng ng-cp?
10:57SynrGyes. it gives reasonable results
10:57SynrGit includes clojure.jar, clojure-contrib.jar, vimclojure.jar
10:57patrkrisOk... hmmm...
10:57SynrGand jline.jar
10:57patrkrisok
10:58patrkrishave you tried setting localleader to something else?
10:58SynrGyes
10:58patrkrissorry, it's called maplocalleader - but you probably know that
10:59patrkrisand you have the g:clj_want_gorilla option set to 1, I guess?
10:59SynrGyes. i tried changing it after loading a .clj file and earlier, in .vimrc
10:59SynrGno. is that essential?
10:59patrkrisyes :)
10:59patrkrisas far as I remember, I don't think it is enabled by default
11:00patrkristry setting it in your vimrc and see if it works
11:00patrkrislet g:clj_want_gorilla = 1
11:00BorkdudeWhat does this stuff from the core function + actually do? {:inline (fn [x y] `(. clojure.lang.Numbers (add ~x ~y)))
11:00Borkdude :inline-arities #{2}}
11:00Borkdude
11:01SynrGpatrkris: still doesn't help
11:01SynrGthings are suddenly much slower tho
11:01patrkrisSynrG: strange
11:02patrkrisyou might want to check back here when kotarak is online
11:02patrkrisor try the mailinglist
11:02SynrGk
11:03patrkrisBorkdude: inlines calls to +...?
11:04Borkdudepatrkris when does that happen? I mean, there is also a 'normal' definition for two parameters
11:04patrkrisi.e. wherever you use +, a call to clojure.lang.Numbers/add is inserted instead during compilation
11:05Borkdudeaha
11:05patrkrisBorkdude: maybe the normal definition is used when you don't use + directly but instead refer to it through an indrection
11:05patrkrisbut i'm just guessing :)
11:06SynrGpatrkris: hm. something changed. i stopped ng-server, exited bash, started a fresh session to ensure my environment was properly set up, edited my file again ...
11:07Borkdudepatrkris: maybe you're right, when it is compiled the function with 2 args gets inlined, I just wondered what this inlining stuff is about
11:07SynrGpatrkris: now i get a lot of error spew and syntax highlighting is not turned on
11:07patrkrisSynrG: then try :e<CR>
11:07patrkrisSynrG: hopefully you know that <CR> means the Enter key :)
11:08patrkrisBorkdude: i think it's for the sake of performance
11:08SynrGCouldn't execute Nail! java.io.FileNotFoundException: Could not locate book_list__init.class or b
11:08SynrGook_list.clj on classpath: at ...
11:08SynrGhey, where'd my classpath go? looks empty
11:08patrkrisSynrG: try editing an empty .clj file
11:09patrkrise.g. :e myfile.clj
11:09patrkrisand then try starting a REPL via <localleader>sr e.g. \sr
11:10SynrGpatrkris: nope. same symptom as before
11:11SynrG:let maplocalleader
11:11SynrGE121: Undefined variable: maplocalleader
11:11zakwilsonUsing Compojure and ring.adapter.jetty, changes I make at the REPL are not reflected when I reload a page. I'd RTFM, but there doesn't really seem to be one.
11:11patrkrisok, try :let maplocalleader=";"
11:11patrkrisSynrG: ^
11:12SynrGno effect
11:12patrkrisSynrG: I like to use semicolon, but you can try any key you'd like
11:12patrkrisok
11:13patrkrisSynrG: could you try and close vim, but keep the nailgun server running and then start vim on an emtpy clojure-file ... just to try it out
11:13patrkrisSynrG: and remember to put a let maplocalleader=";" in your .vimrc
11:15SynrGpatrkris: still no joy :/
11:15patrkrisSynrG: damn
11:16patrkrisSynrG: but it seems that the "gorilla" part of vimclojure has been activated in some sense
11:17patrkrisSynrG: btw which version of vimclojure are you using - the bleeding edge version or the last release?
11:17SynrG,, which is the localleader for vimoutliner seems to work
11:17clojurebotjava.lang.Exception: Unable to resolve symbol: which in this context
11:18SynrGshush, clojurebot
11:18patrkris:)
11:18SynrGsec ...
11:18SynrG2.1.2
11:18patrkrisyeah, i think it's the one I'm using
11:19patrkriswell ... I don't have any other suggestions right now
11:19SynrGyup. thanks for trying :)
11:29SynrGpatrkris: hm. rebuilt and reinstalled the jars. seems to be cooperating now
11:29SynrGdunno what i did :/
11:29SynrGi still get error spew at the beginning
11:30patrkrisSynrG: can you start a REPL now?
11:31SynrGapparently
11:31SynrGbut ;ef gives:
11:31SynrGCouldn't execute Nail! java.lang.ClassNotFoundException: de.kotka.vimclojure.nails.Repl at java.n
11:31SynrGet.URLClassLoader$1.run(URLClassLoader.java:217) at java.security.AccessController.doPrivileged(N
11:31SynrGative Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
11:31SynrGtest.clj contains:
11:31SynrG(+ 2 2)
11:31clojurebot4
11:32SynrGthanks, clojurebot :p
11:32SynrGwhen did clojurebot stop requiring a prefix?
11:33patrkrisdunno - I never actually used it :)
11:33patrkrisdo you know where to find instructions on using clojurebot? :)
11:33patrkrisstrange that upon invoking ;ef it says the Repl class is missing
11:34patrkrisbut are you able to enter and evaluate text inside the REPL?
11:35SynrGrestarted ng-server again. restarted editing again
11:35SynrGlooks fine now
11:35SynrGmystifying
11:36SynrGi try random things and things work ...
11:36SynrGi hate it when that happens :p
11:36tufflaxdon't we all
11:37SynrGso, my HOWTO:
11:37SynrGobtain wall
11:37SynrGbeat head against wall
11:37SynrGrepeat until unconscious, or things work
11:38patrkris:)
11:42tufflaxpatrkris: Thanks by the way, for answering my question earlier. I wasn't trying to do anything specific, I was just curious.
11:47SynrGpatrkris: things are *not* working flawlessly, however
11:48SynrGit seems very temperamental
11:51patrkrisSynrG: you could take a look at the leiningen nailgun plugin, if you use leiningen
11:51patrkrisSynrG: it sets up the classpath for you
11:52SynrGhm. always restart ng-server each time you start vim again
11:52SynrGseems to be part of my problem
11:54SynrGthe other is that sometimes my ; seems to be 'eaten' by whatever i did previously, and i don't know why
11:54SynrGah, it's timing
11:55SynrGbecause these sequences are unfamiliar, if i wait too long while i try to think of what the sequence is ...
11:55SynrGit forgets i typed localleader
11:58patrkrisSynrG: that's right - also had that problem :)
12:00patrkrisSynrG: I hope you get it to work - see you later
12:08Drakesonhow can I extend an existing interface?
12:10Drakesonis gen-interface the only option?
12:13hoeckDrakeson: deftype, proxy or genclass
12:14hoeckoh, sorry, that implements an existing iface
12:20BorkdudeWhat's with rfirst? I see it on the Clojure cheatsheet, but it doesn't work in my repl
12:23DrakesonBorkdude: nfirst
12:25Drakesonthere was a rest --> next transition. rfirst and rrest probable got renamed to nfirst and nnext
12:26DrakesonHow does one put an "Integer []" or "I[" type hint on an argument?
12:26Drakeson#^ints apparetnly does not do it
12:28tcrayfordhave you tried #^Integer[] ?
12:28Drakesonyes
12:28Drakesonfails
12:29DuneManor #^{:tag Integer[]}
12:29DuneMan?
12:31DuneMan*wonders*
12:31Drakeson,(defn foo [#^{:tag Integer[]} x] x) (foo 1)
12:31clojurebotDENIED
12:31Drakeson,(defn foo [#^{:tag Integer[]} x] x)
12:31clojurebotDENIED
12:31Drakesonlazy bot
12:32DrakesonDuneMan: anyway, doesn't work
12:36DuneManhttp://groups.google.com/group/clojure/browse_thread/thread/9a276a1709a88eeb
12:39Drakesonthanks, "ints" works for some other places, but apparently non in definterface.
12:40DuneManwell, "ints" is int[], no?
12:45DuneMancap11235: looks like :init to me
12:45DrakesonDuneMan: it seems it should be
12:46DuneManDrakeson: So that wouldn't be Integer[]
12:46DuneManso it shouldn't work.
12:47DrakesonI don't get it. why wouldn't (defn foo [#^ints xs] xs) work?
12:47DuneManIf you're giving it Integer[], int[] != Integer[]
12:48DuneManbut you could use #^objects foo, and then give a typehint to integer for all of the accesses.
12:48DrakesonI am not giving it anything yet. it fails even before that. (definterface foo-iface (#^ints bar [this]))
12:48DuneManoh, weird.
12:48DuneManI see
12:49Drakesonis definterface being depreciated?
12:52DuneMan(gen-interface :name "Foo" :methods ....)
12:52DuneMandur
12:52DuneManyeah
12:55DuneManI mean... I'm pretty new to clojure... but definterface isn't in the docs... so maybe it was a 1.0 thing?
13:06dakronewhat's the easiest way to convert (:a 1 :b 2 :c 3) into a map? I was using (apply hash-map ...), but it throws errors on duplicate keys
13:08Drakeson,(into {} (vec '(:a 1 :b 2 :c 3)))
13:08clojurebotjava.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Keyword
13:08Drakeson,(into {} (map vec (partition 2 '(:a 1 :b 2 :c 3))))
13:08clojurebot{:a 1, :b 2, :c 3}
13:09dakroneDrakeson: that's it, thank you much
13:27tufflaxIf I want to save clojure objects/datastructures to files, should I use java's stuff? Do clojure datastrctures implement serializeable?
13:27Borkdudegood question
13:28rhudsonThey implement Serializable in 1.2
13:30tufflaxok, thanks
13:31zakwilson__With compojure.html, (html (vector [:h3 "foo"] [:p "bar"] [:div "baz"])) is returning "<><p>bar</p><div>baz</div></>". Is this a bug, or user-error?
13:32zakwilson__(expected was "<h3>foo</h3><p>bar</p><div>baz</div>")
13:52_brian2_noob question> regarding reading in a serialized java object, in java you use type casting to the object to identify it, how does that work in clojure -> http://clojure.pastebin.com/ZUmyyxYx
13:55candellerhi - having a list of strings, i.e '("foo" "bar" ...) Id like to get a list of the characters '(\f \o \o \b \a \r ...) what would be the most idiomatic way?
13:56rhudson_brian2_: The object you read in already has the right class. Clojure is dynamically typed.
13:56_brian2_i get type cast exception
13:57rhudsonWhat's the expression?
13:57rhickey,(apply concat ["abc" "def"])
13:57clojurebot(\a \b \c \d \e \f)
13:58candellerthanks, wouldnt have guessed that concat can return separate chars :o
13:58rhickey,(seq "abc")
13:58clojurebot(\a \b \c)
13:59candelleroh, why i havent thought about it, thanks
14:01_brian2_rhudson: just a sec
14:04dakronehow do you refer to protocol methods outside of the namespace they're declared in? http://gist.github.com/394685
14:05_brian2_rhudson: (def classifier2 ( .readObject objIn )) , (def compiledClassifier ( AbstractExternalizable/compile classifier2))
14:10_brian2_rhudson : the problem , I think, is that this object needs to be cast into another type to be accepted by the function I'm passing it ot
14:11_brian2_this object is a subclass of the object I need to cast it into
14:13rhudsonSorry _brian2_, was away. So it's com.aliasi.util.AbstractExternalizable ?
14:13_brian2_yes
14:14_brian2_lingpipe library
14:15rhudsonAnd classifier2 implments Compilable?
14:16_brian2_just a sec
14:18_brian2_rhudson : no, however ..
14:20arkahn is the ants.clj program Rich Hickey wrote two or three years ago still a canonical example in the use of clojure concurrency or is there something newer/updated that's a better example?
14:20_brian2_rhudson : I'm putting the authors notes up
14:21arkahn... sometimes I feel clojure suffers from Perl's TMTOWTDI - I just want one good way ; )
14:22arkahna la Python
14:23_brian2_rhudson : -> http://clojure.pastebin.com/nh1aDCgY
14:26_brian2_he starts with DynamicLMClassifier , trains it, writes it out as that type, then appears to cast it into LMClassifer , which does not, I think, implement Compilable
14:26_brian2_when he reads it in
14:29rhudsonWhen the object gets serialized, the serialization includes the name (or some indicator) of the class of the object. When you read it back it, you're reconstituting the same class of object.
14:30rhudsonIn Java, a statically typed language, you have to say what the types of your variables are.
14:30rhudsonSo when you cast to LMClassifier, you're saying "through this variable I will only perform LMClassifier calls".
14:31rhudsonBut the object itself is unchanged.
14:31_brian2_But appears I cant cast it in clojure
14:35rhudsonYou shouldn't need to cast it in Clojure. There's only one "compile" method in AbstractExternalizable, which takes a Compilable, so the implementation should be looking at the object, seeing whether it implements Compilable, and making the call if so.
14:35rhudsonSo I don't understand why you're getting a class cast exception.
14:37rhudsonYou could try putting in a type hint -- (.../compile #^Compilable classifier2)
14:37_brian2_ok
14:39rhudsonor, when you've read in the object, make sure you have the right one: e.g. (assert (instance? Compilable classifier2))
14:41_brian2_ok, this #^Compilable didnt do anything
14:41rhudsonyeah, I didn't really expect it to
14:54rhudson_brian2_, another troubleshooting thing to try is printing out the class of the object after you've read it in: (println (class classifier2)).
14:54rhudsonAnd you're using the same version of the library to write and read?
14:55_brian2_ok
14:55_brian2_yes
14:56nurvHi.
14:57_brian2_(println (class classifier2)) , com.aliasi.classify.LMClassifier
14:59rhudsonwhich is not a Compilable
14:59_brian2_hmm
15:00_brian2_ok, its my stupidity
15:01_brian2_thanks!
15:01rhudsonyou're welcome
15:06BorkdudeWhat's the difference with # and #^ ?
15:06Borkdudeno sorry ^ and #^
15:13cschreiner#^ is oldschool
15:22BorkdudeIs there any more idiomatic way of getting a sequence from \a to \z? (map char (range (int \a) (inc (int \z))))
15:25rhudson,(seq "abcdefghijklmnopqrstuvwxyz")
15:25clojurebot(\a \b \c \d \e \f \g \h \i \j \k \l \m \n \o \p \q \r \s \t \u \v \w \x \y \z)
15:25ataggartlol
15:26LauJensennaah, idiomatic would be more like
15:26LauJensen$(-> (map char (take 25 (drop-while (partial < 121) (iterate dec 10e6)))) reverse)
15:26rhudsonIt's actually fewer characters...
15:26sexpbotresult: (\a \b \c \d \e \f \g \h \i \j \k \l \m \n \o \p \q \r \s \t \u \v \w \x \y)
15:26rhudsonZebra's won't like that...
15:27BorkdudeLauJensen: I thought reverse was not so idiomatic, but more for people who come from CL ;)
15:28LauJensenof ofc you're right, try making it work with apply interleave instead :)
15:32Borkdudeyes, much better than using inc, counting down is much more spacy
15:33nurv$(map char (range 97 123))
15:33sexpbotresult: clojure.lang.LazySeq@726b766e
15:35LauJensen$(doall (map char (range 97 123)))
15:35sexpbotresult: clojure.lang.LazySeq@726b766e
15:35ataggartbtw, there are more than 26 letters
15:35LauJensenhrmf
15:35Borkdudehmm, I turned on clojure-mode in my ERC buffer, that didn't work out ;)
15:36Borkdude$(take-while true (map char (range 97 123)))
15:36sexpbotjava.lang.Boolean cannot be cast to clojure.lang.IFn
15:36Borkdudeah damn ;)
15:37Borkdude$(take-while (constantly true) (map char (range 97 123)))
15:37sexpbotresult: clojure.lang.LazySeq@726b766e
15:37Borkdudenopr
15:38BorkdudeWhat happens if you use seq on it?
15:39Borkdude$(seq (map char (range 97 123)))
15:39sexpbotresult: (\a \b \c \d \e \f \g \h \i \j \k \l \m \n \o \p \q \r \s \t \u \v \w \x \y \z)
15:40nurvmmmm...
15:41nurv$```````,(+ 2 2)
15:41sexpbotCommand not found. No entiendo lo que estás diciendo.
15:41hiredmanthat is just sexpbot's broken result printin
15:41nurvSomehow it's a stack overflow here.
15:41hiredman,(take-while (constantly true) (map char (range 97 123)))
15:41clojurebot(\a \b \c \d \e \f \g \h \i \j \k \l \m \n \o \p \q \r \s \t \u \v \w \x \y \z)
15:58hiredman,(squote '(A B C# (unsquote-splice [(squote A) 2 3]) C#))
15:58clojurebot(list (quote sandbox/A) (quote sandbox/B) (quote C__15055) (quote sandbox/A) 2 3 (quote C__15055))
16:02rhudson,#'squote
16:02clojurebot#'sandbox/squote
16:03hiredmanI really need to break the (defmulti foo type) habit and start writting protocols
16:11vIkSiThmm, I'm trying to write some code that takes in a sentence like - This 'is' a test _sentence_ (quoted word and underscored word), and then performs an operation on it.
16:12vIkSiTnow imperatively, I'd have an array/string, run through each word in that sentence in a loop, do an "if quoted() or if underscored()" on the word, and then perform the relevant operation, and append the changes into the string
16:13vIkSiTbut given immutable data structures - whats a good functional way to do it without resorting to atoms and derefs?
16:14rhudsonBasically you want to produce a new sentence that's the appropriate transform of the old sentence
16:15vIkSiTexactly
16:16rhudsonso roughly (for [w words] (if (changeit? w) (changeit w) w))
16:17vIkSiThmm yes. I'd have two if conditions though
16:17vIkSiTor n, for the purposes of this question..
16:17rhudsonthen cond
16:17vIkSiTI assume that the (changeit w) returns the changed value, but i'd have to operate on this _changed_ value in the next form..
16:18vIkSiTlet me paste what i have right now..
16:18vIkSiTwhats a good clojure pastebin btw?
16:18vIkSiTlisppaste?
16:18clojurebotlisppaste8: url
16:19rhudsondunno; haven't done it myself yet
16:20rhudsonLotsa folks seem to use gist.github.org
16:20vIkSiTthats true
16:20vIkSiThttp://paste.lisp.org/display/98969
16:21vIkSiTso I have 2 issues here : a) how do i specify a "default" value to cond, and b) how do i take the return value from (myfun w) and pass it to the next statement?
16:21rhudson(a) :else w
16:22rhudson(b) using 'for usually works out well
16:22rhudson(a) -- any "true" value serves, but :else is conventional
16:23vIkSiTrhudson, ah, how dyou mean (b) there?
16:24hiredmana,b,a ?
16:24rhudsonsomething like (let [words (for [w words] (cond ....))] (use-rebound-words ...)
16:24hiredmanshoudl be ba
16:24rhudsonhiredman: re his "so I have two issues here"
16:25hiredmanoh, I assumed you had a binary alphabet
16:25vIkSiThehe
16:25rhudson01101010000101
16:25hiredmanwhy use for in this case over map?
16:25hiredmanabbababaaaabab
16:25rhudsonI just like for better
16:26vIkSiThmm, I was thinking about map as well (i use it for everything in python) - but I'm still not sure in either case how the return value of (myfun w) is going to be reused?
16:26rhudson'for reads better than 'map when the function is long
16:26vIkSiTlets say I have a vector ["a" "b" "c"]
16:27vIkSiTand a function, (defn myfn [x])
16:27hiredmanjust say F
16:27vIkSiTsure
16:27rhudsonF
16:28hiredmanyou want to transform the elements of V with F
16:28vIkSiTnow after (for [w words] (cond (F? x) (F x)
16:28vIkSiT(F x) returns the transformed value of x
16:28hiredman(transform <=> map)
16:28vIkSiTah. so map will do an in-place transform?
16:29Borkdude,(doc update-in)
16:29clojurebot"([m [k & ks] f & args]); 'Updates' a value in a nested associative structure, where ks is a sequence of keys and f is a function that will take the old value and any supplied args and return the new value, and returns a new nested structure. If any levels do not exist, hash-maps will be created."
16:29hiredmanvIkSiT: how could it?
16:29hiredmanimmutable
16:29rhudsonNo, the point is you get a new vector , and apply the next operation to that new vector
16:29vIkSiTyes exactly.
16:29hiredmanno
16:29hiredmanyou get a new seq
16:30vIkSiTI got that. My confusion is - how do I pass that new seq to the next (F? x)
16:30hiredmanjust call the next fn on it
16:30rhudsonone way is, say ( -> ["a" "b" "c"] transform1 transform2 )
16:30Borkdudethis sounds more like a map thing
16:30hiredman,(apply str (map char (map inc (range 90 100))))
16:30clojurebot"[\\]^_`abcd"
16:31vIkSiThmmm yes that does seem better
16:31vIkSiTlet me try
16:31hiredman,(-> (range 90 100) (map inc) (map char) (apply str))
16:31clojurebotjava.lang.ClassCastException: clojure.lang.LazySeq cannot be cast to clojure.lang.IFn
16:31Borkdude(map #(if this or that then ret this or that) your-seq)
16:31hiredman,(->> (range 90 100) (map inc) (map char) (apply str))
16:31clojurebot"[\\]^_`abcd"
16:31Drakesonis there a way to transform the name of a class when you import it?
16:31Drakeson(or rename)
16:32hiredmantry using for with -> or ->>
16:32hiredmangets funky fast
16:33hiredman,(->> x (for [y (range 10) :let [x (* y y)]]))
16:33clojurebot(0 1 4 9 16 25 36 49 64 81)
16:33vIkSiTah
16:33vIkSiTwhat IS ->>?
16:34hiredman->> is ->, but differnt
16:34rhudson,(doc ->>)
16:34clojurebot"([x form] [x form & more]); Threads the expr through the forms. Inserts x as the last item in the first form, making a list of it if it is not a list already. If there are more forms, inserts the first form as the last item in second form, etc."
16:34rhudson,(doc ->)
16:34clojurebot"([x] [x form] [x form & more]); Threads the expr through the forms. Inserts x as the second item in the first form, making a list of it if it is not a list already. If there are more forms, inserts the first form as the second item in second form, etc."
16:35vIkSiTha
16:35vIkSiTnever used either
16:35rhudsonThey are really useful
16:35Plouj,(+ 1 2 3)
16:35clojurebot6
16:36Borkdudeit's just a rewrite of what you would otherwise nest
16:36vIkSiTright
16:37rhudsonAnyway, my point was not so much syntactic, as that functionally what you do is produce a new sentence (not alter the old one), and feed that to the next operation
16:38vIkSiTsure
16:41rhudsonThe arrows are a convenient way to do that if the operations are short forms (like names), and has the advantage of reading the right way. (-> a f1 f2 f3) vs (f3 (f2 (f1 a)))
17:12springifyGood evening. Has anybody here ever tried cuke4duke with lein-cuke and made it work?
17:20LauJensenIs there something in contrib which makes (mkdir "x/y/z.clj") create both x, y and z.clj provided they dont exist?
17:21DrakesonLauJensen: Don't know, but (.mkdirs (java.io.File. "x/y")) should create x/y/
17:22LauJensenGood enough, thanks
17:22mmarczykKarmic -> Lucid: yet another painless upgrade :-)
17:23nickpadhi - wondering if anyone's come across this problem trying to run the labrepl project: http://paste.lisp.org/display/98972
17:23LauJensenmmarczyk: Go get that lottery ticket
17:23mmarczykLauJensen: yup, on my way already :-)
17:24mmarczykapparently there's a Clojure package in universe, but it's 1.0... got to find out who maintains it and maybe bump it to 1.1
17:29Ploujhi
17:30Ploujso, I still can't figure out why swank/slime only works right after I install it in emacs with elpa, but fails with "Lisp connection closed unexpectedly: connection broken by remote peer" on subsequent emacs restarts.
17:49Ploujactually, sometimes it works (connects to addr=0.0.0.0/0.0.0.0,port=0,localport=53077) once every 5 times I try to restart and do M-x slime
17:55Borkdudemfex: here?
17:58Ploujwhat would you guys recommend as a rest for learning clojure for someone who isn't new to LISP and programming in general
18:00Borkdudeas a rest?
18:02Ploujerm
18:02PloujI don't know what I meant to type :)
18:02PloujI guess as a "good book"
18:03PloujI'm looking for a book/tutorial to learn clojure
18:03PloujI'm not sure if reading the clojure version of sicp is that helpful for practicing concurrent programming
18:03rhudsonStuart Halloway's book Programming Clojure is good
18:04dnolenPlouj: sounds like Joy of Clojure is going to be pretty good. Programming Clojure is good too, though a lot of 1.2 stuff is missing from it.
18:05Ploujis joy of clojure more up to date, dnolen?
18:06dnolenPlouj: seems like it
18:06rhudsonJoy of Clojure looks good so far -- 7 chapters are out in early access.
18:08vIkSiTdoes anyone cover protocols (outside of the video?)
18:08rhudsonNeither book has exercise material. projecteuler.net and rosettacode.org are good places to find some interesting problems.
18:08vIkSiTThere's also codingkata.org
18:09rhudsonHaven't seen that one; I'll take a look
18:09vIkSiT(PE is most mathematical et al; I've found ck has some interesting stuff to get used to a language)
18:09vIkSiTmostly*
18:09Ploujproject euler is hard :)
18:10vIkSiTPlouj, depends :) some of the "hardness" comes from not being familiar with certain concepts for instance.
18:11vIkSiT,(doc ->)
18:11clojurebot"([x] [x form] [x form & more]); Threads the expr through the forms. Inserts x as the second item in the first form, making a list of it if it is not a list already. If there are more forms, inserts the first form as the second item in second form, etc."
18:11vIkSiTrhudson, what are the -> and ->> operators called?
18:12rhudsonNot sure they have an official name; I think of them as the arrow operators
18:12PloujvIkSiT: yeah, it requires more concentrated thinking than I can afford while learning a language at the same time
18:12The-KennyvIkSiT: Some people call -> "thread".
18:13The-Kenny(I forgot the name for the ->>)
18:13vIkSiTPlouj, agreed. I'd say PE/SPOJ/TC et al are to finetune language skills rather than learn; codingkata et al help do the latter pretty well
18:13vIkSiT(spoj - sphere online judge, tc - topcoder)
18:13vIkSiTthey're also more algorithmic in nature
18:13vIkSiTThe-Kenny, ah thanks
18:14The-Kenny,(doc ->>)
18:14clojurebot"([x form] [x form & more]); Threads the expr through the forms. Inserts x as the last item in the first form, making a list of it if it is not a list already. If there are more forms, inserts the first form as the last item in second form, etc."
18:14rhudsonRosettacode is a mixed bag. One advantage is that you see the same problem solved in a lot of different languages
18:14vIkSiTI was trying to find some example uses of -> and ->>
18:14vIkSiTbut obviously google is horrendous in finding some
18:14technomancyvIkSiT: "thrush" is one name that I think encompasses -> and ->>
18:14The-Kenny,(-> 1 (+ 5) (- 10))
18:14clojurebot-4
18:14technomancysomeone mentioned "stitch", which I think is much better than "thread"
18:15The-Kenny(- (+ 1 5) 10)
18:15ataggart-> "nest" since that's what it does
18:15technomancyhiredman: have you thought about changing the code invocation prefix for clojurebot? I get confused since clojurebot treats , like clojure treats ~
18:15vIkSiTtechnomancy, ah thanks. ironically a google of "clojure thrush" brings me to #clojure logs from 09 with the _exact_ same question being answered :)
18:16technomancyvIkSiT: http://debasishg.blogspot.com/2010/04/thrush-in-clojure.html <= a nice explanation
18:16sexpbot"Ruminations of a Programmer: Thrush in Clojure"
18:16vIkSiTah. so -> takes 1, adds it as the second item in (+ 5 1), then -> takes the result of that and puts it as the second eleemnt in (- 10)
18:17vIkSiTtechnomancy, ah thanks. let me check
18:17The-KennyvIkSiT: yes, and second element means after the function
18:18rhudson,(-> 7 (- 3))
18:18clojurebot4
18:18rhudson,(->> 7 (- 3))
18:18clojurebot-4
18:18vIkSiThmm, after the function, as in?
18:18vIkSiTah. -> implies (- 7 3), and ->> (- 3 7)
18:18rhudsonright
18:19vIkSiTgotcha
18:20rhudson-> is especially useful in Java interop, since the standard Clojure form for a method call is (.method object args)
18:20ataggart-> is useful for nested operations on a value. ->> id useful for nested operations on a collection of values.
18:25rhudsonI recently wanted to get a line sequence from a URL, so first I got an InputStream (with-open [istream (-> drafts-url URL. .openStream)]
18:25rhudsonthen
18:25rhudson (let [lnseq (-> istream InputStreamReader. BufferedReader. line-seq)]
18:37DuneManI find -> so hard to read.
18:40DuneManprobably would get used to it if I used it.
18:40DuneMan*switches some code to use it
18:45ataggartits a nice replacement for deeply nested stuff which can be harder to read, e.g., (foo (bar (baz x) y) z) (-> x baz (bar y) (foo z))
18:45ataggartbut if you don't like it, don't use it
18:46ataggarttmtowtdi
19:03vIkSiThmm is <- an operator too?
19:03vIkSiThttp://nathanmarz.com/blog/cascalog-news-feed/ uses it all over the place;
19:03sexpbot"News Feed in 38 lines of code using Cascalog — thoughts from the red planet"
19:04rhudson,(doc <-)
19:04clojurebot"clojure.contrib.datalog.rules/<-;[[hd & body]]; Build a datalog rule. Like this: (<- (:head :x ?x :y ?y) (:body-1 :x ?x :y ?y) (:body-2 :z ?z) (not! :body-3 :x ?x) (if > ?y ?z))"
19:04vIkSiTweird. why didnt that work for me?
19:05vIkSiTaah. c.c.datalog
19:05vIkSiTdamn. the doc function should allow queries for ALL modules
19:05vIkSiTnot just those used or required in the current namespace
19:05rhudsonYeah, clojurebot already has all the contrib libs
19:06vIkSiTis there a way to force doc to do that btw?
19:06vIkSiTuseful if no web connection/IRc open!
19:06rhudsonnot to my knowledge
19:06vIkSiToh well :)
19:25somnium,(apply assoc {} :a :b [1])
19:25clojurebot{1 nil, :a :b}
19:25somniumIm guessing its doing [[x y] [1]] to get the nil, would it make sense to throw there? (just took me a little bit to track down)
19:32somniumhrm, adapting it to conj instead of assoc makes it throw
20:04dnolen,(assoc {} :a :b 1)
20:04clojurebot{1 nil, :a :b}
20:07somnium,(assoc {} 1)
20:07clojurebotjava.lang.IllegalArgumentException: Wrong number of args passed to: core$assoc
20:08somniummy POLS has been violated :/
20:25tomojwat
20:25tomojassoc should error with an even number of args, no?
20:26hiredmanjust look at the implementation of assoc
20:26hiredmanit should be least surprising that it works that way
20:26tomojis it RT.assoc?
20:26hiredmanI dunno
20:26hiredmanI haven't look at it
20:26hiredmanbut I can imagine how it goes
20:26tomojhmm
20:27tomojI think I might see what you mean
20:27hiredman(defn assoc ([a b c] ...) ([a & keyvals] blahblah blah reduce or loop))
20:28tomojjust an arity thing then?
20:28hiredman(let [keyvals '(1)] (assoc {} (first keyvals) (second keyvals)))
20:29hiredman,(let [keyvals '(1)] (assoc {} (first keyvals) (second keyvals)))
20:29clojurebot{1 nil}
20:29hiredmanit's an artifact of being a little sloppy with seq processing
20:30somniumso 'sloppy artifacts' should be unsurprising?
20:32somniumanyway, being aware of it its not a problem, just was the first time I recall encountering it
20:33hiredmanno, but if you look at the function, and say "how would I implement this" and the way you would implement it could easily yield certain sloppy behaviour, why would you be surprised to see that behaviour?
20:35somniumhmm, ease of deduction = probability of existence :P
21:00vIkSiThmm. bit stuck on doing this in idiomatic clojure - i have a string to which i want to make a transformation. "this _is_a *good* string". I'd like to replace everything within ** with the match of that word in another dictionary
21:00vIkSiT(there can be multiple words with ** - I can do single words with re-gsub, for instance)
21:00vIkSiTnot sure how best to do it. Ideas?
21:07somniumvIkSiT: are all ** whitespace delimited?
21:07hiredmanfnparse
21:07vIkSiTsomnium, yes
21:08vIkSiThiredman, seems too complex for a toy program really :)
21:08vIkSiTfnparse, that s..
21:10somniumvIkSiT: for easy you could tokenize it and then (map (fn [s] (if-let [s* (dict s)] s* s)) tokens)
21:10vIkSiThmm, what is s* here?
21:11somniums* is a non-nil result from (dict "string")
21:22somnium,(require '[clojure.contrib.string :as s])
21:22clojurebotjava.io.FileNotFoundException: Could not locate clojure/contrib/string__init.class or clojure/contrib/string.clj on classpath:
21:25somnium,(require '[clojure.contrib.str-utils2 :as s])
21:25clojurebotnil
21:57vIkSiTbtw, using a clojure string, how do i get it without the first and last characters?
21:57vIkSiTI can do nth but it only returns the first char itself
21:57vIkSiTnth i mean
21:59cp2,(drop-last (rest "foo bar baz"))
21:59clojurebot(\o \o \space \b \a \r \space \b \a)
21:59cp2er
21:59cp2,(apply str (drop-last (rest "foo bar baz")))
21:59clojurebot"oo bar ba"
22:00vIkSiThmmm
22:00vIkSiTa bit complex, for something that could be done using a[0] and a[-1] in other languages?
22:00cp2sure, but there are many ways to achieve something
22:00vIkSiTtrue
22:00cp2and all it really boils down to is how you use it in your code
22:01vIkSiTwell, what i'm trying to do is - got a list of tokens. if any of them have **s as first and last, i want to strip * and call a function using it..
22:01vIkSiTi guess i could use regexps.
22:02cp2so, if a string is like *foo*, call foo?
22:02vIkSiTmore like: if string is like *foo*, call (f foo)
22:02cp2oh yeah, i missed that the first time around
22:03vIkSiT,(second (re-find #"\$(\S+)\$" "$test$")
22:03clojurebotEOF while reading
22:03vIkSiT,(second (re-find #"\$(\S+)\$" "$test$"))
22:03clojurebot"test"
22:03vIkSiTor something like that.. (for $ or *s)
22:03somniumvIkSiT: you may prefer the java String methods .contains, .startsWith, .endsWith etc
22:03vIkSiToh good point.
22:04cp2mhm
22:04cp2honestly, your solution will be clunky just because of the way you need to deal with these tokens
22:04cp2i dont think its that big of a deal though
22:05vIkSiTsigh yeah
22:17vIkSiTbbl
22:17cp2http://tinyurl.com/2dyt9z8
22:17sexpbot"Vintage Symbolics 3650 36xx LISP Machine As-Is - eBay (item 260597652691 end time Jun-04-10 09:34:15 PDT)"
22:18hiredmanhuh, very tempting
22:18hiredmanbut I think the jvm will have to do as a lisp machine for now
22:19cp2unfortunately :(
22:21cp2i would still love to get my hands on one of those symbolics keyboards, though
22:21cp2that is a lot more affordable, at least =P
22:37cemerick~max
22:37clojurebotmaxine is http://research.sun.com/projects/maxine/
22:37cemerickwha?
22:37cemerick~max
22:37clojurebotmaxine is http://research.sun.com/projects/maxine/
22:37cemerickguess he's not tracking channel population anymore
22:37cemerickclojurebot: what do you know?
22:37clojurebotPardon?
22:37cemerick~brain
22:37hiredmanclojurebot: max users?
22:37clojurebotmax people is 283
22:37clojurebotbrain dump is http://clj.thelastcitadel.com/clojurebot
22:38hiredmanthe brain dump is busted
22:38cemerickah, bummer
22:38cemerickmaxine is pretty interesting, tho :-)
22:38hiredmanright
22:38cemerickThere was a good interview with one of the researchers a while back.
22:39cemerickse radio, perhaps
23:11_brian2_noob question> regarding exception handling, I 'm using a clojure library to scrape web pages, but how do I handle error 400 http exceptions, (try ( fetch ... doesn't seem to work
23:43sids_brian2_: the HTTP 400 errors are not the same as Java exceptions (unless the lib does the mapping)
23:43sids_brian2_: which library are you using?
23:59_brian2_sids : I'm using enlive