#clojure logs

2009-10-02

00:02arbschthm, rfirst and rrest were replaced with nfirst and nnext during the lazy merge
00:08adityogood morning folks
00:08arbschthi
02:34konrIs there a particular http client I should use?
02:35arbschtwhat are your requirements?
02:36konrhmmm... support for cookies... nothing much more complicated than that
02:41arbschtyou could probably build on c.c.http-agent. if you want automatic cookie management maybe apache's httpclient
03:07Fossihi
03:12konrHI, Fossi
03:40sfuenteschouser: so your scala adventures are over?
03:45hiredman~scala ((x: Int) => x + 1)(3)
03:45clojurebotInt = 4
03:57hiredmansfuentes: http://gist.github.com/199542
03:58hiredmanor something like it
04:03sfuenteshiredman: thanks for the sample :)
04:05hiredmanit maybe help to note that resources are loaded via the classpath and the classpath has little to do with filesystem locality
04:12sgtzxanyone using Enclojure here?
04:13sgtzxI am trying to learn Clojure while using Enclojure in NetBeans, but it is acting very strangely.
04:14sgtzxfor example if I have (let [frame (JFrame. "Celsius Converter" ... then later I do (doto frame (.<I apply tab completion here and it seems to not be able to infer that frame is JFrame>
04:48Fossiwouldn't it make sense to make all io methods and java calls to use an implicit io!?
04:49konrHow do I send a file using http.client? I'm using (File. "/foo/bar.jpg"), yet apparently the field is being dropped
05:04spuzLauJensen: hey
05:04LauJensenHey spuz
05:06spuzJust running your brain sim now :)
05:06LauJensenHow's it going?
05:06spuzThere's a few things I didn't quite understand in your description though..
05:07spuzfor example, you mention pmap, but where do you actually use it?
05:07spuzalso, how does it work?
05:08LauJensenSecond line in "step" is "pmap (fn [window]"
05:08LauJensen~def pmap
05:10LauJensenAs you can see it splits the computation into bits which are passed to 'futures' running in their own threads
05:14spuzinterestingly, it appears to be creating 2 more threads than there are available processors
05:17yasonspuz: it's a common idiom: two processes per processor perform better in case the processes are less than 100% cpu-bound; otherwise it's just 50/50.
05:17eevar2I think processor count * 2 might have been a better choise
05:17eevar2granted, you get more context switches, but
05:17yasonspuz: doubling, that is. Not +2, although if you have a dual-core system then it's probably *2 and not +2 :)
05:21spuzwell, if you see the code for pmap, it sets n to numprocessors + 2. I'm not exactly sure what it does with 'n' after that but I assume that's the number of threads that is created...
05:28spuzLauJensen: also, could you explain what the step function does? I'm not quite getting the third line. Could you maybe expand it with an example of the input and output that goes into each part of the function?
05:30LauJensenspuz: I doubt I could you more input than what you get from setting the board dimensions to 3x3, re-eval 'board' and then do it step by step, you'll see how it is mapping windows on windows
05:30spuzok good idea
05:35sgtzxLauJensen: brain sim is cool
05:35sgtzxLauJensen: you mentioned there is a performance hit due to that it's a functional language, how much do you think it is?
05:36LauJensensgtzx: Glad you think so :)
05:36LauJensenWith the current model, which is simple to reason about, the performance hit is huge, the way we work the board, the way the board is allocation, the massive allocation that comes with 'partition' and the strain on the GC that puts... Its a huge hit
05:37LauJensenI'm considering doing a revised version with blazing performance, but I figured I'd wait a few days and see what the commentators come up with :)
05:37sgtzxLauJensen: I would love to see that
05:41sgtzxLauJensen: out of curiosity, what IDE do you use, or do you use emacs and slime for clj dev?
05:41vyI'd expect concat to behave same as lazy-cat and there would appear no lazy-cat? Aren't they functionally identical, except laziness?
05:42LauJensensgtzx: Emacs
05:43LauJensen,(class (concat 1 2))
05:43clojurebotclojure.lang.LazySeq
05:43hiredman,(first (concat [1] (println :foo)))
05:43clojurebot1
05:44clojurebot:foo
05:44hiredman,(first (lazy-cat [1] (println :foo)))
05:44clojurebot1
05:44vySo what's the difference between lazy-cat and concat?
05:44hiredmanlazy-cat has an extra layer of laziness
05:44vyOoops! lazy-cat is just a macro over concat!
05:45vy[& colls] `(concat ~@(map #(list `lazy-seq %) colls))
05:45hiredmanconcat is a function, so it's arguments are evaluated
05:45hiredmanlazy-cat is a macro, so it controls the evaluation of its arguments
05:46hiredmanwhich it does by wrapping them in a call to lazy-seq
05:47vyI'd still expect "concat" to work as "lazy-cat". Anyway...
05:48hiredmanwell, if you read the docstrings, the difference is explained there
05:48hiredmanso I don't know why you would expect something other than what is documented
05:48vyWhy would somebody prefer concat over lazy-cat?
05:49hiredmanconcat is a function
05:49hiredmanso you can apply it
05:49hiredmanetc
05:50rsynnottalso, lazy-cat sounds like some form of lolcat
05:52ambientso does concat ;)
05:53Fossirepost (;-)): wouldn't it make sense to make all io methods and java calls to use an implicit io!?
05:55jdzFossi: what is an implicit io?
05:56hiredman,(doc io!)
05:56clojurebot"([& body]); If an io! block occurs in a transaction, throws an IllegalStateException, else runs body in an implicit do. If the first expression in body is a literal string, will use that as the exception message."
05:57vyI'm reading clojure cheat sheet... While there appears "frest", and "rrest" in the documentation, there are no such functions supplied by the core, AFAIK. Am I missing something?
05:57hiredmanthe cheat sheet is old
05:57hiredmanthe are fnext and something else now
05:58hiredmanrnext?
05:58hiredman,rnext
05:58clojurebotjava.lang.Exception: Unable to resolve symbol: rnext in this context
05:58hiredman,nnext
05:58clojurebot#<core$nnext__3833 clojure.core$nnext__3833@1daa156>
05:59vyI love languages that are getting trimmed by time.
06:03sgtzx,nnext
06:03clojurebot#<core$nnext__3833 clojure.core$nnext__3833@1daa156>
06:13jdzthere still is not any function like CL's find, is there?
06:15vyjdz: (first (filter f coll)).
06:15jdzvy: right.
06:20liwpany slime experts here?
06:21liwpif I type e.g. "(fn" into the repl and hit tab, I get a completion suggestion buffer and point has been moved in front of 'n' which I find really annoying
06:22liwpIs there a way to stop point from moving or can I somehow overwrite the 'n' when I carry on typing?
06:30jdzi don't observe the behaviour you describe...
06:31LauJensenjdz: phew - I thought something had happend to you, since I hadn't received a flamemail for my last blog post yet :)
06:32liwpjdz: urgh, I'll need to look into my slime setup then...
06:34vyliwp: Same as jdz in here.
06:35liwpvy & jdz: what do you get then? the completion buffer, but the point stays at the end of the line?
06:35liwpi seem to recall that I didn't see this behaviour sometime in the past, but I can't be sure
06:36vyliwp: Yup.
06:37liwpthanks
06:38vyCould somebody tell me more about the "with-local-vars"? I couldn't get the difference between "with-local-vars" and "binding".
06:45liwpvy: looking at the source it seems to me that with-local-vars creates new vars for the bindings, whereas binding rebinds the existing vars
06:45liwpI don't know what practical difference that makes
06:46liwpI guess if you call code in the body that uses global vars then with-local-vars will not work, i.e. it's not rebinding those global vars
06:49pixelmanI'be been thinking about this lazy stuff -- does can clojure somehow cache stuff that's explicitly lazy?
06:50yasonpixelman: what do you mean, like (memoize) ?
06:50pixelmanI'm using compojure, and I would like to cache the result of certain calls to (html [...
06:50pixelmanthe app would be snappier
06:51liwpvy: and one major difference is that, as the doc string says, you have to use (var-get) and (var-set) to access the var in with-local-vars
06:51pixelmanlooking at memoize
06:51vyliwp: I see. Thanks. (Reading the sources...)
06:52yasonpixelman: (memoize your-page-generation-fn) and store that somewhere
06:52liwpvy: with with-local-vars you can set the var value in the body with (var-set)
06:53yasonliwp: what's the point in that, i.e. what can you do that you can't with binding?
06:53pixelmanyason: pretty cool! will try that.
06:53liwpyason: dunno, I'm trying to figure it out ;)
06:54yasonliwp: IIRC in Practical Clojure there was a paragraph that usually vars and symbols can be mingled together but for certain cases it's important to recognize the difference -- ain't figured that out yet :)
06:54liwpdefinitely one major difference is the fact that with-local-vars does not rebind vars globally (as the name suggests)
06:55yasonliwp: hmmm, but (binding) isn't global either, right?
06:56liwpyason: if you call a function from the binding body that reads a var that you've rebound, you'll get the new value rather than the orig value
06:56liwpi.e. (def a 1) (defn foo [] a) (binding [a 2] (foo)) will return 2
06:58liwp,(def a 1) (defn foo [] a) (binding [a 2] (foo))
06:58clojurebotDENIED
06:59liwp,(do (def a 1) (defn foo [] a) (binding [a 2] (foo)))
06:59clojurebotDENIED
06:59liwphave it your way then
07:01LauJensenDoes anybody know who's behind disclojure.org ?
07:02yasonliwp: I know binding but an example of with-local-vars would be enlightening
07:04liwp,(with-local-vars [bb 1] (var-get bb))
07:04clojurebot1
07:04liwpare slightly useless example :)
07:05liwpthe interesting bit is that you have to use var-get and var-set to access the var
07:05LauJensennvm
07:29pixelmanI'm looking for a logging framework, should I just use log4j or is there some wrapper or such for clojure?
07:30lpetitataggart created one in clojure.contrib
07:30LauJensenpixelman: You can wrap log4j using 1 macro, and I recommend that approach :)
07:31pixelmantnx!
07:45vyLauJensen: Were you the one who was asking yesterday how to log to a file via c.c.logging?
07:48LauJensenNo, but I remember the talk @ vy
07:51vyThen do you know the answer? I couldn't figure out it too.
07:51LauJensenTo me the answer is using log4j , for you, it may be patching c.c.logging
07:52vyLauJensen: You mean directly using log4j without c.c.logging wrapper?
07:52LauJensenThat's what I did
07:52LauJensenI'm not saying it's for you though, I just try to stay out of contrib as far as possible
07:58pixelmanc.c logging worked fine when the loglevel was accepted by log4j but crashed when I tried a :notice. still pretty slick though. I just want to log some stuff. :)
07:58Fossiout of curiosity: why's that?
07:58FossiLauJensen: out of curiosity: why's that?
08:00LauJensenFossi: A lot of the code in contrib are small helpers/wrappers/utilities which help you abstract your problem - I get the best feel for the problem when I write these myself and sometimes that helps me refactor the code - if I didn't have all the code in my POV all the time, I don't think I'd refactor like I do, and I don't think I'd have as good a feel for it... and oh.. then there's the SQL thing :)
08:01Fossiunderstandable. in case you still look for new topics, i'd love a more elaborate blog post on that ;)
08:02pixelmanwhat is the SQL thing?
08:02LauJensenI'm always looking for new topics :)
08:02Fossikinda just explained the reasoning for the method of operation in the last few
08:03Fossi*to me
08:03Fossiok, maybe that wasn't even an understandable sentence
08:03LauJensenpixelman: Kotarak and myself have developed ClojureQL which is a nice way to interact with databases, in contrib there's also an SQL wrapper, which I politically view as competition :) (just kidding)
08:06pixelmanLauJensen: interesting, gotta look up your project :) I'm using the stuff in common now and finding it pleasant to use, but it's nice to see other approaches.
08:07LauJensenclojureql is radically different, because it lets you stick with your normal syntax, (query table1 [item id cost] (< cost 500)) for instance
08:07spuzLauJensen: very interesting, is that then just parsed and converted into normal SQL?
08:08LauJensenIn some ways it's a matter of taste, in other we really provide functionality that you won't normally get, like specific backends for Mysql and Derby that provide FULL JOIN functionality etc etc, but read all about it on Gitorious :)
08:08LauJensen~clojureql
08:08clojurebotclojureql is http://gitorious.org/clojureql
08:09LauJensenThen that's saved as a syntax tree, which you can do stuff with, like (group-by foo (query table ...)) and when you ask to have it executed, it's transformed to a valid SQL string and run through JDBC's .nativeSQL, and then executed
08:10pixelmancan I access data lazily from mysql?
08:11LauJensenYep, (run *con* (query table [x y z])) gives you a lazy result-sequence, instead of LIMIT you can then do (take 50 ) on it, instead of OFFSET you can use (drop) but that's costly, we're still working on that. When you've fully realized the seq, the connection closes
08:11LauJensen(drop was costly, not limit)
08:12pixelmanneat!
08:12spuzLauJensen: that's very nice
08:15LauJensenGlad you think so - My last blog post is already 8.th on Dzone.com, it's amazing the interesting functional programming/clojure is generating these days - wonder if Rich's JVM talk has something to do with it :)
08:15snowwhiteDoes clojure have classes?
08:15Chousuke_yes and no.
08:15spuzLauJensen: was that the one about OO and time?
08:16snowwhiteChousuke_, as in?
08:16LauJensenspuz: A functional Brians Brain simulator
08:16Chousuke_snowwhite: it has classes because the JVM has them; however, actually directly making classes yourself is not very idiomatic.
08:16spuzLauJensen: I mean the jvm talk, there was one called Are we there yet I think. Is that the one you mean?
08:16Chousuke_snowwhite: the ability to create classes is mainly used for interop with Java.
08:17LauJensenspuz: To my great disappointment I still haven't heard the talk(s) but I'm thinking the OO vs Time could be it
08:17snowwhiteChousuke_, Can you show an example by pasting some code somewhere?
08:18Chousuke_snowwhite: hm
08:19snowwhiteChousuke_, thanks
08:19Chousuke_I don't have a gen-class example at hand right now :/
08:19snowwhiteChousuke_, :(
08:19LauJensen~sofiaba
08:19clojurebotsofiaba is http://wiki.github.com/Lau-of-DK/sofiaba
08:19LauJensensnowwhite: I was forced to use gen-class in that :)
08:21spuzheh, I'm not sure a full blown 3d game is the kind of example snowwhite was looking for :p
08:21Chousuke_snowwhite: behind the scenes there are of course classes generated everywhere but you can accomplish quite a lot with Clojure without writing a single named class :)
08:21LauJensenI didn't implement Duke Nukem, so it's not full blown :)
08:22Chousuke_snowwhite: for example, every clojure function is its own class.
08:22Chousuke_snowwhite: but you don't need to care about that :)
08:22snowwhiteChousuke_, hmm, but a small example could clarify a bit more?
08:22spuzit's interesting to see the classes generated by clojure, I put a very simple example through a decompiler to see what the byte code was doing and there's a lot more going on behind the scenes than you might think
08:22Chousuke_,(class (fn []))
08:23clojurebotsandbox$eval__5228$fn__5230
08:23Chousuke_but of course, that's not very interesting to you.
08:23Chousuke_for interop, you can often use proxy too
08:24spuzsnowwhite: have a look at this for more info on class generation: http://clojure.org/compilation
08:26Chousuke_snowwhite: for interop without gen-class, you can have code like (.addListener someswingthing (proxy [ActionListener] [] (actionPerformed [e] ...))) ... proxy generates a class implementing ActionListener, but you don't need to care about what exactly it is called :)
08:27snowwhiteChousuke_, cool
08:27snowwhiteChousuke_, :)
08:27Chousuke_I guess gen-class enters the picture when people in Javaland need to be able to use it directly (and not through an interface)
08:28Chousuke_or if you're implementing a main method.
08:55Drakesonis completion broken with slime + swank-clojure ?
08:55Drakesonor is it just my setup that's broken?
08:56cschreinerDrakeson: at the repl?
08:56cschreinerworks fine
08:56cschreinerin the buffer, not so
08:56cschreiner(for me)
08:56Drakesonit doesn't comlete even in the repl
08:57DrakesonI updated everything couple of hours ago
08:57cschreinerdid you first M-c k the file?
08:58Drakesonwhat is M-c k ? it is unbound here.
08:58cschreinerah, C-c k, sorry
08:58cschreinerI'm sure you did
08:59Drakesonthat's unbound, too
08:59cschreinerdid you start slime?
09:00Drakesonsure
09:00liwptry C-h k TAB
09:00liwpin the repl
09:00liwpthat should say that tab is bound to slime-indent-and-complete-symbol
09:01Drakesonliwp: it is.
09:01jdzLauJensen: i have not seen your latest blog entry, sorry
09:01liwpthen I'm out of ideas :)
09:02liwpDrakeson: and it doesn't mentione any before or after advice?
09:02Drakesonwell, if I could be sure that it is my setup that is broken, not the upstream ...
09:03pixelmanwhat to use to read in config files? wrap properties? or yaml
09:05liwppixelman: Properties can be dumped into a clojure map so it's definitely an easy way to get something working fast
09:06Drakesonliwp: I am trying to edebug the completion functions ...
09:06liwp,((into {} (System/getProperties)) "path.separator")
09:06clojurebotjava.security.AccessControlException: access denied (java.util.PropertyPermission * read,write)
09:06liwpblah
09:06pixelmanliwp: yep, that's nice
09:07liwpthe downside is that the keys are strings rather than keywords
09:08ambientanyone have the problem that after running a swing app, slime disconnects and I have to restart/reload everything?
09:09liwpambient: many swing apps bind the close button to System/exit which will then kill your JVM and the slime connection
09:09liwpit's very frustrating when running stuff via slime
09:10LauJensenliwp, can't you just override it ?
09:10ambientit's ok if i just comment out the EXIT_ON_CLOSE part?
09:11ambienti don't know how to lessen the amount balls i have to juggle in air while trying to code swing/clojure with emacs/slime/clojure-mode
09:11liwpambient: I think so, I think the default behaviour is to close the window and that's exactly what you want
09:11liwpLauJensen: sure, it just annoys me when I try out someone's clojure/swing app and closing it kills my repl
09:12LauJensenok :)
09:15ambientheh, searching for 15 minutes on how to indent clojure code in emacs and a simple mark region + press tab does it :D
09:15ambientmy google-fu is seriously lacking
09:16liwpambient: also M-x indent-region would work
09:16Drakesonpress tab? use M-C-\ after marking region.
09:16FossiMeta-Q
09:17Fossiindents the current region
09:17Fossino selection needed
09:17danleiI most often use C-M-q at the start of a sexp
09:18Fossiyeah, sorry, meta-q is paredit-indent
09:19liwpDrakeson: thanks for that - I'll have to try to remember it in the future
09:20liwpM-C-q also sounds good although I usually don't have to re-indent clojure code
09:21danleiI nedd it all the time :)
09:21danlei*need
09:21liwpI'm not sure why I don't need it, maybe it's because of paredit or because my yank reindents the yanked code
09:22danleihm, I use paredit too
09:22liwpmaybe I just leave my code in a massive mess and don't notice it 8-I
09:22DrakesonI rarely need that (maybe I press TABs too often). I only do a few C-x h C-M-\ during the day.
09:22danlei:)
09:24danleiliwp: self-reindenting yank sounds nice
09:24danleishould make mine behave like that too
09:24liwpdanlei: it's very good with e.g. C++ and friends when you move stuff out of blocks
09:25danleisure is
09:25liwpI can't remember where I picked it up from, probably emacs wiki
09:25Drakesonok, what does (slime-eval '(swank:completions "ma" "user")) produce?
09:26Drakesonit doesn't give me any completion, and results in: (nil "ma")
09:26liwpDrakeson: I get a whole list of stuff, e.g. macroexpansion-1
09:27liwp(("macroexpand" "macroexpand-1" "main-page" "make-array" "make-hierarchy" "map" "map-invert" "map-str" "map?" "mapcat" "match-method" "match-uri" ...) "ma")
09:27Drakesonliwp: thanks. now I know there is something wrong with either swank-clojure or my setup.
09:28liwpthis is the main problem with emacs: things sometimes break and it's difficult to figure out what's broken simply because your emacs setup is unique in the world
09:28danleiliwp: something like (lambda () (yank) (save-excursion (exchange-point-and-mark) (indent-sexp))) should work for lisp code
09:29pixelman,(map #( list (keyword (% 0)) (% 1) ) {"foo" "FOO" "bar" "BAR"})
09:29clojurebot((:foo "FOO") (:bar "BAR"))
09:29pixelmanhow can I build a map instead?
09:29liwpdanlei: isn't your mark going to be in the wrong place when you're yanking?
09:30danleiit's untested, but I think it should work
09:30liwppixelman: with reduce
09:30pixelmanliwp: ok!
09:30liwppixelman: something like (reduce #(assoc %1 (first %2) (second %2)) {} ...)
09:31liwpdanlei: the yank-indent hack that I use adviced the existing yank, I'll see if I can find the URL for it
09:32danleiliwp: thanks. my thingie works, btw
09:32danleibut it should do everything pasted, not only a sexp (although that's what I most often paste)
09:32danleis/do/indent/
09:33liwpdanlei: http://trey-jackson.blogspot.com/2008/03/emacs-tip-15-indent-yanked-code.html
09:33danleiliwp: thanks!
09:34liwpnp
09:37danleiah, now I see what you meant, should move to the beginning of the line, too :)
09:38pixelman,(reduce #(assoc %1 (keyword (first %2)) (second %2)) {} {"foo" "FOO" "bar" "BAR"})
09:38clojurebot{:bar "BAR", :foo "FOO"}
09:38danlei(or just press tab before yanking)
09:39pixelmanliwp: thanks for the pointer :)
09:41Chousuke,(into {} (map (fn [[k v]] [(keyword k) v]) {"foo" :bar}))
09:41clojurebot{:foo :bar}
09:45liwpChousuke: what's the best way to turn a java HashMap<String, String> into a clojure map with keyword keys?
09:46liwpi.e. we talked above about using Java Properties for config and I can turn that into a clojure map with into, but I'm left with String keys
09:47liwpI could use your above code to change the keys to keywords except that the items in a Properties object are not pairs
09:47chouserwhat's wrong with string keys?
09:47liwpchouser: you can't do (:foo my-map)
09:47liwpnot a big deal, but still
09:47Chousukeliwp: you can do (my-map "foo") though :)
09:47liwpyeah, I know
09:48liwpand also, I guess some of the strings won't be legal keywords anyhow
09:48rhickeyah, finally! - http://www.infoq.com/presentations/Value-Identity-State-Rich-Hickey
09:48Chousuke(let [m {"foo" "FOO" "bar" "BAR"}] (zipmap (map keyword (keys m) (vals m))))
09:48Chousuke,(let [m {"foo" "FOO" "bar" "BAR"}] (zipmap (map keyword (keys m) (vals m))))
09:48clojurebotjava.lang.IllegalArgumentException: Wrong number of args passed to: core$zipmap
09:48Chousukehmm
09:48Chousukeah, damn
09:48Chousuke,(let [m {"foo" "FOO" "bar" "BAR"}] (zipmap (map keyword (keys m)) (vals m))))
09:48clojurebot{:bar "BAR", :foo "FOO"}
09:49ChousukeI'm too used to paredit taking care of the parentheses :(
09:49chouser"Presented by Rich Hickey on Oct 01, 2009" Oops.
09:49liwpChousuke: that'll work, thanks
09:59spuzWhat's the best way to add two vectors? I could do something like (map + [1 2] [3 4]) => (4 6) but this returns a list rather than a vector
09:59Chousukejust call vec on that :)
10:00spuzok :)
10:00spuzI wonder if there is a more efficient way but we'll see if it is a performance problem later :)
10:01ambientvectors are often just arrays so you could use an actual array
10:01Chousukearrays are mutable though.
10:01Chousukevector aren't.
10:01Chousukespuz: I don't think there's any more efficient way, besides using mutable data structures.
10:01Chousukeand you probably don't want that. :P
10:01spuzok
10:02ambientusing the GPU for numeric work
10:02ambientor dedicated math libs
10:14namorWhat is the advantage of STM over a synchronized "swap!" function?
10:14chousernamor: coordinated accees/mutation of multiple references.
10:15liwpnamor: you can change multiple things as an atomic transaction
10:15namorOk, i get it. Thanks.
10:16raekif I want to write yaml/load instead of org.ho.yaml/load (org.ho.yaml is a java package) how do I do it?
10:16liwpraek: import org.ho.yaml
10:16liwpyaml is the java class?
10:17raekno, the package
10:17liwpwhat's the clas?
10:17raekoh whait
10:17raekorg.ho.yaml.Yaml is the class
10:17raekload is a static method of that class
10:17raekthen there's no problem :)
10:17liwpok
10:19raekuser=> (Yaml/load *in*)
10:19raek- a
10:19raek- b
10:19raek- c
10:19raek#<ArrayList [a, b, c]>
10:19raekyay!
10:20liwpcool
10:21liwpis that all you have to do? Is the yaml lib easy to use from clojure?
10:21raekI have no idea... :) this is my first experience with yaml in clojure
10:22raekthe java containers can be used with clojure's sequence library
10:23raekso traversing the yaml data shouldn't be any problem
10:24konrdoes (:import (java.awt *)) work?
10:24Chousukeno.
10:24konrChousuke: hmm, is there an alternative?
10:25Chousukeno.
10:25Chousuke:)
10:25chouserkonr: you're not going to use *all* the awt classes. Just list the ones you use.
10:26somniumit seems some libraries use def and namespaces to emulate mutable objects, though this is religiously discouraged. is there a run time difference between this and doing, for example, (ns config) (def config-state (atom {})) and using swap?
10:27Chousukesomnium: people expect defs to be immutable, or at worst thread-locally bound. :P
10:27Chousukeif it's an atom, it's *explicit* that it can change.
10:28somniumcompojure defines an explicit redef that preserves metadata, for example
10:29chouserew. really?
10:29somniumI'm new enough to lisp that I don't have any 'religious beliefs' about def, but I want to adopt best practices. I was just wondering if they're absolutely equivalent but one breaks convention and one doesn't
10:29somniumyeah, in control.clj
10:30Chousukein any case, using def anywhere except top-level is wrong.
10:30somniumI'm not sure how it's used, they
10:30somniumalso an immigrate macro but that just takes all the vars from a list of namespaces and puts them into one for convenience
10:31MakoryuWould it be possible to print warnings for any non-top-level use of def?
10:32chouseroh, I see. I think compojure's just doing that during app setup. That's slightly less evil.
10:32somniumI asked about doing that but was told it was absolutely evil and to use atoms :)
10:33somniumis there a way to list all the classes in a java package?
10:33chousersomnium: no
10:33chousersomnium: you can look at all the .class files in a directory or in a jar
10:36somniumhmm, thinking of a dirty way to do import org.foo.* by using the classpath to find all the classnames
10:37somniumanyway, under the hood, is evil-redeffing and atom swapping equivalent?
10:38chousernot quite
10:38chouserdef uses a lock on the var. atoms do atomic-set-and-check
10:39somniumok, so no reason not to use atoms when configuring state before launching the main loop to be explicit?
10:41chousersure.
10:42chouseranother benefit of using atoms is that if you decide later it needs to be a ref (to coordinate with other refs) much of your code will be very similar
10:42chouserreplace swap! with alter, wrap in a dosync, done.
10:42chouserif you were redefing vars, you'd have to go find where you need to add @, fix your def calls, etc.
10:44ambienthow do i refactor this into a shorter form? (Color. (bit-xor x y) (bit-xor x y) (bit-xor x y))
10:44liwpambient: (let [c (bit-xor x y)] (Color. c c c))
10:44ambientah.. *slaps forehead*
10:45liwpheh
10:45somniumI'm thinking of the way rails plugins go in and alter whatever core classes they're changing, it should be simple to decorate atoms with a logger to go and see exactly what happens during config
10:45chouseryou wanted something trickier, perhaps. (#(Color. % % %) (bit-xor x y))
10:45liwpchouser: slightly shorter as well I think ;)
10:45ambientthat seems oddly readable :o
10:46liwp(apply Color. (replicate 3 (bit-xor x y))) ?
10:46chouserplus it generates a whole new class for you under the covers.
10:46spuzchouser: I missed ambient's question, what is x and y?
10:46ambientimage coordinates
10:47ambientxor function gives a cool image for testing purposes
10:48spuzheh, an image of what though :)
10:48Fossixor
10:48liwpand x and y
10:48Fossiit plots the function :)
10:49ambientit's kinda the simplest fractal that i know of
10:50spuzI have a question, how can I get the decimal representation of a Ratio?
10:50chouser,(double 7/3)
10:50clojurebot2.333333333333333
10:51spuzchouser: thanks
10:53rhickeyThat infoq talk is one of my favorites
10:54chouserI'm watching it now. Did you just watch it?
10:54rhickeyyep
10:54rhickeyslight slide lag in a couple of places, but I love that they sync the slides like that
10:54liwpmust be weird watching yourself give a talk
10:55chouseryeah, that's good practical tech.
10:55liwprhickey: yeah, that's a really nice feature
10:56Fossirepost (again ;-)): wouldn't it make sense to make all io methods and java calls to use an implicit io!?
10:56rhickeyFossi: no, many are functional
10:56rhickeyalso overhead
10:56Chousukerhickey: I just finished it. They cut out the question part at the end though (or were there really no questions? :/)
10:57rhickeythey don't usually include the q/a part
10:57rhickeythere were a few, Joe Armstrong was in the audience :)
10:59Fossitoo bad :(
11:00somniumwhat's the url?
11:00rysJoe is the Erlang guy?
11:00liwprys: yep
11:01liwpsomnium: http://www.infoq.com/presentations/Value-Identity-State-Rich-Hickey
11:01rysWatched a nice thing with him and SPJ recently, can't rememeber the site though. InfoQ?
11:01liwprys: this: http://www.infoq.com/interviews/armstrong-peyton-jones-erlang-haskell
11:01liwp?
11:01liwpI haven't watched it yet
11:01rysYeah, that's the one
11:01rysIt's quite funny
11:01Chousukethe thing about needing to model time hadn't quite sunk in before I watched that presentation, but I think it's clear now. good stuff, anyway
11:02rysJoe's really animated and SPJ just sits there, dead still
11:03liwpSPJ gets animated when he's launching missiles
11:04sproingienaw he's just lazy :)
11:04liwp;-)
11:27spuzrhickey: hey, just watching your qcon talk. You say you made a talk the previous day, what was that talk about?
11:27rhickeyspuz: an introduction to Clojure
11:27spuzis that available somewhere?
11:27rhickeynot yet
11:28rhickeythe one they put up is the important one, new compared to all others
11:28spuzok
11:28rhickeythe intro has a lot of overlap with other talks I've given
11:34spuzrhickey: what kind of feedback do you get from people after these talks? Do you think you're winning the battle of converting people away from OO?
11:34liwprhickey: should into be changed take multiple from collections as args? e.g. (into [] [1] [2] [3])
11:35liwpmark volkman was asking about it on the group
11:35liwpand is this an appropriate impl: (apply into (into x y) zs)))
11:38rhickeyspuz: I think that talk was one of the more popular at QCon. There's a whole other set of issues in converting people... I'm not trying to do that, just explaining the ideas behind Clojure
11:43rhickeyliwp: I'm not sure about multiple args, not that important. could use (reduce into dest [xs ys zs])
11:43Drakesonliwp: can I ask you when you last updated your swank-clojure ?
11:43liwpsure
11:44liwpDrakeson: not too long ago I don't think
11:44liwprhickey: I was looking for low hanging fruit to contribute. Is there anything urgent in assembla that no one's looking at?
11:45sproingiespeaking of converting people from oo, there a doc out there about functional ways to replace is-a relationships?
11:45sproingiei have a few tricks but it all feels pretty ad-hoc
11:46rhickey,(derive ::square ::rect)
11:46clojurebotnil
11:46rhickey,(isa? ::square ::rect)
11:46clojurebottrue
11:46ambientsquare and rect are a good example of a devious not is-a relationship iirc
11:47rhickeyliwp: anything marked for next release without patches is fair game
11:47ambient(a bit off-topic)
11:47sproingiesquare and shape then
11:47rhickeyambient: only in the face of mutation
11:47liwpDrakeson: maybe I haven't updated after all... git log gives me c1e309dfe53cb45149258404c4db5b53fb5c81b7 from april 17th
11:47sproingiethe square/rectangle problem is a classic trick question. it _has_ no "right" answer
11:47chouserwhat?
11:48rhickeyin what way is a square not a rectangle?
11:48sproingieif the contract for shapes says they have optional constraints, then there's a right answer
11:48sproingieone-arg constructor to square violates substitution principle
11:49rhickeysproingie: you don't have an object yet when you call the ctor
11:49rhickeyso no substitution
11:50sproingieconstructors usually aren't polymorphic anyway, so there's some argument that substitutability doesn't apply
11:50sproingiewonder what liskov would say to that
11:52sproingiebeen teaching myself scala for this whole week. love the syntax sugar, but soooooo much syntax.
11:52sproingiei'd probably be half-done with my project if i started it in clojure instead
11:53Fossiany language with a construct like +: 1 2 fails :D
11:53Fossipoor mans macros
11:53somniumI couldn't stand the syntax, too similar-yet-different to ruby
11:53MakoryuFossi: Eh? What language would that be?
11:54sproingieeh my day job is perl, so i'm used to crazy syntax all over
11:54FossiMakoryu: you could define +: as a prefix + operation in scala
11:54MakoryuFossi: Ah
11:55Fossithe last char in the name defines the binding
11:55Fossiexcellent idea...
11:55sproingie+: would define a right-associative infix operator
11:56sproingieyou can't really define new prefix operators, they're hardwired to +-!
11:56sproingieoh and ~
11:56Fossiah. well. same, same really
11:57Fossipretty mad
11:57vychouser: Any progress on " http://www.assembla.com/spaces/clojure/tickets/149-pop-does-not-preserve-meta-data (Actually, I'm just wondering the patch.)
11:57vy#149
11:57vypop does not preserve meta-data
11:57MakoryuI still think the APL family has the craziest syntax
11:57sproingiei thought it was kind of crazy that ending with : would make a method right-associative. sort of flies in the face of what you'd expect for an operator that looked smalltalkish
11:57Fossiand absolutely overengineered and artificial
11:58Drakesonliwp: thanks.
11:58MakoryuEvery function, regardless of the name, is either prefix or infix
11:59sproingieJ makes perl look like cobol
11:59MakoryuYep
11:59liwpDrakeson: yeah, I don't think I've upgraded since my slime-macroexpand-all work just fine. It got broken when some stuff got moved from contrib to core
11:59liwpalthough it might have been fixed now in swank-clojure head
12:01chouservy: had totally forgotten about it
12:02chouserliwp: how's that for low-hanging fruit?
12:03somniumI wonder how hard it would be to emulate ruby semantics with clojure, wrap hash-maps with method missing, convert instance vars to atoms. maybe use | as a delimiter instead of ; due to the reader.
12:03liwpchouser: I thought it would be relatively simple to implement
12:04liwpchouser: then I noticed that the current implementation special cases transients and I wasn't so sure anymore ;-)
12:04chouserahhh. :-)
12:04somniumas an example for the conversion from OO battle. I'm assuming C-syntax to lisp and OO to functional are separate battles
12:06liwpchouser: if you don't mind calling (transient) and (persist!) separately for each collection then it's easy, but calling them only once for the into call requires some more thinking
12:09liwphow do i get git to tell me where my repo was cloned from?
12:16weissjliwp: look in .git/config
12:16liwpweissj: thanks. There's nothing like 'svn info'?
12:16weissjliwp: there might be a command to show you that as well, but i don't know what it it
12:16weissjis
12:17liwpok, thanks
12:18Chousukegit remote show origin
12:20liwpChousuke: thanks. I'm sure I've seen that before.
12:20Chousukeone of my favourite features of git is the ability to have multiple remotes
12:21Chousukemakes it easy to track multiple repositories :)
12:21liwpChousuke: with clojure are you working with a direct clone of rich's github repository?
12:21Chousukewell, yes and no.
12:22liwpI had my own clone on github and I cloned my working copy from that, but I'm not sure if that's the right thing to do w.r.t. patches
12:22ChousukeI have rich's repo as origin but I have my own github fork as a remote called "public" :P
12:22liwpthis is some sort of higher git magic that I haven't seen yet
12:23Chousukeit's not too difficult
12:23liwpso if you branch locally, do you push those branches then to your gh repo?
12:23Chousukesometimes
12:23Chousukesome I keep local
12:23liwpthat was my main reason for having my own clone on gh, that I could save my branches somewhere
12:24Chousukeif I make bugfixes and such I base them on origin/master but then for example my reader branch tracks public
12:24liwpmakes sense
12:24liwpjust yesterday I nuked my gh clone and now I'm thinking I should recreate it and do something similar to what you're doing
12:25Chousukegit help remote, then :)
12:25liwpyep, I'll need to do some reading
12:25Chousuke(well, actually it's just git remote add remotename url-here)
12:26liwpso you clone a working copy from rich's repo and then add another remote to it (for example)?
12:26Chousukethat's one way
12:26Chousukethe repos actually don't even have to be related :P
12:26liwpand is there some easy way to push branches back to the remote? I managed to make it work, but it didn't seem obvious to me
12:27liwpthat makes sense, but is also slightly scary at the same time :)
12:27Chousukegit push remotename localbranch:remotebranch
12:27Chousukeyou can also make a branch "track" a remote branch so that you can just "git push" and "git pull"
12:27liwpwill that possibly give the branch a different name on the remote?
12:27Chousukeyeah
12:28Chousukeyou can omit the :remotebranch if you don't need that
12:28liwpI think that's what I did last time (tracking), which is actually what I wanted
12:28Chousukeso most of the time just git push remote branch
12:28Chousukemany scary things are possible with git ;)
12:29liwpso a 'git push' after a 'git push remote branch' will not push the branch changes to the remote?
12:29liwpsince the branch is not tracked?
12:30Chousukecorrect. but you can always configure the defaults afterwards
12:30liwpthat's nice
12:30Chousukegit config branch.<branchname>.remote and .merge or something IIRC.
12:31liwpso you would recommend keeping my own clone on gh? I tend to do stuff both at home and at work so being able to share the repo via gh is nice.
12:31Chousukewell, I won't recommend anything... but it's what I do. :P
12:31liwpI was just worried about patches in that scenario, but it seems that having rich's repo as another remote fixes that
12:31liwp:)
12:32liwpthanks, I'll think about it
12:32liwpgott go
12:32liwps/gott/gotta/
12:33Chousukeeven with just one remote patches will not be a problem... unless you let your clone get too old so that you end up fixing things that are already fixed :P
12:35liwpChousuke: I thought that might be the case, but I wasn't sure
12:36liwpI thought maybe the diff wouldn't apply in some cases if there were subtle changes so it would be safer to produce patches against the main repo
12:36liwpanyhow, now I really gotta go :)
12:38danleiabout remote brances: I find it more convenient to "push origin foo", "co master" "branch -f foo origin/foo" that way, everything tracking is setup correctly and one hasn't got to mess with git config ...
12:38Chousuke-f?
12:38danleiforce, yes
12:39Chousukeah, right.
12:39Chousukewell, that's one way
12:39danleithe other thing works as well, of course, but I find it more convenient like this
12:46steiger(contains? [[1 2] [3 4]] [1 2]) -> false . is it a bug?
12:48Chousukeno.
12:49Chousukecontains? doesn't test whether a value is in a collection
12:49Chousukeit tests whether said collection has a value for a certain key :)
12:49Makoryu, (contains? {:foo bar} :foo)
12:49clojurebotjava.lang.Exception: Unable to resolve symbol: bar in this context
12:49Makoryu, (contains? {:foo 'bar} :foo)
12:49clojurebottrue
12:50Makoryu, true
12:50clojurebottrue
12:50steigeroh
12:50steigerI see
12:50Makoryu^ Is that defined as (def true 'true)?
12:50steigerthe docs are a little bit confusing
12:50ChousukeMakoryu: no
12:50ChousukeMakoryu: it's special to the reader
12:50MakoryuRight
12:50Chousuke,(class true)
12:50clojurebotjava.lang.Boolean
12:50Chousuke,(class 'true)
12:50clojurebotjava.lang.Boolean
12:50steigerChousuke: is there a function that tests wether a VALUE is present in the given collection?
12:51Makoryu,(class 'pizza)
12:51Chousukehmm
12:51clojurebotclojure.lang.Symbol
12:51Chousukesteiger: I'm actually not sure about that.
12:51hiredman(.contains '(1 2 3) 2)
12:51hiredman,(.contains '(1 2 3) 2)
12:51clojurebottrue
12:51Chousukeoh, right, the Collection method :)
12:51hiredman,(.contains '(1 2 3) 3)
12:51clojurebottrue
12:52steigerhm, java contains
12:52steigerthank you guys
12:58ben_mAnyone have some example code for using sdljava with Clojure?
13:31scottjI often have trouble recognizing when to use map, reduce, loop, for, or lazy seqs that iterate or something. Anyone know of a tutorial (not necessarily in clojure, other functional languages would be fine) that focuses on helping imperative programmers to recognize when to use these methods?
13:31ben_mI've got a class Foo and a method bar that returns void (java interop). I'd like to create an object of Foo and call the method on it but return the created object, not the return value of bar ... is that possible?
13:32vyben_m: What's wrong with (do (.bar foo) foo)?
13:32ben_muh
13:32sproingiescottj: find out what the sources of events in your program are. now picture them as an infinite stream of events.
13:33ben_mvy: Not familiar with do, so I don't know. I'll look it up
13:33sproingiescottj: basically anything you can visualize as a timeline of state changes or events or messages or whatever you can convert to a sequence
13:36sproingiereduce is handy for consuming a stream whenever you need to keep the previous state handy. probably not as necessary with STM tho.
13:36sproingie*a stream of states
13:38ambienti wonder if asynchronous events will map 1-1 into seqs
13:39ambientit's something i've still yet to wrap my head around in fp
13:42scottjsproingie: thanks, but I guess what I'm looking for is a tutorial that breaks down common ways of using for/while loops and shows how to do them in fp
13:42sproingieyou can block on a read of the event queue. there are probably better high-level constructs for that tho
13:43sproingiei'm not entirely sure what they are myself. i'm only halfway-FP myself :)
13:49technomancyscottj: reduce is for when you want one value from a sequence; map is to transform one sequence into another.
13:49sproingiescottj: you can always break down for/while into recursion, which we have loop/recur for
13:50technomancyscottj: for is just syntax-sugar for map
13:50technomancydoseq is like for, but intended for side-effects
13:50sproingietechnomancy: reduce is also good when you never need the value back, but you want to derive the next action from the previous one
13:50sproingieyou can get a pipeline by reducing apply over functions, for example
13:50technomancysure
13:50ambientdoseq doall and dorun still confuse me
13:51technomancyor when you need something more specific (map, set) than a seq from a sequence
13:51sproingieright, like for building a tree
13:52sproingiecons an empty tree onto the list and reduce the insert func over it
13:52technomancysproingie: reduce takes an optional initial value; no need to conj it to the list
13:53sproingieyah i haven't translated all my idioms to clojure yet :)
13:54ben_mIs there something like an infinite loop in clj? (gameloop in my case)
13:54sproingiemore useful with the optional arg since you don't have to screw up a nice homogeneous collection that way
13:54sproingieben_m: a loop/recur with no base case
13:54sproingieor a for or reduce over an infinite sequence
13:54chouserben_m: (fn [] (recur)) or (while true ...)
13:54ben_mAh, didn't know while exists. Thank you :)
13:55sproingieor just plain while, yah. havent memorized the API yet :)
13:55sproingieben_m: http://clojure.org/api
13:55chouser'while' is very rarely used
13:55ben_mI think the best way would be to use loop, since i'm using let anyways
13:55sproingieactually that probably doesn't have control structures in it, since those are usually special forms
13:55chouserbut it yells "imperative" which can be useful
13:55sproingiebut that page has a link to those
13:56technomancyanyone want to fix up swank-clojure's eldoc to indicate macros differently?
13:56technomancyor am I going to have to implement that myself? =)
13:57sproingiejust don't infinitely loop by mapping over an infinite sequence. unless you like space leaks :)
13:57chousermap will just return a lazy seq and do nothing.
13:58sproingiesomething would have to consume that. which i guess can't be map.
13:59chouserright. would have to be something like (loop [xs (map ...)] (recur (next xs))) ... which wouldn't leak anything
13:59Drakesonwhat does (remove-ns 'swank.commands.completion) do at the begining of the file?
14:00chouserthough it would churn memory needlessly.
14:00chouser(doc remove-ns)
14:00clojurebot"([sym]); Removes the namespace named by the symbol. Use with caution. Cannot be used to remove the clojure namespace."
14:01Drakesonit is being used before defining (na swank.commands.completion ...), and I don't understand the intent
14:03Drakeson(not to mention that swank completion is broken here, since the revision from around Sept 15)
14:04technomancyDrakeson: can you give an example of the breakage?
14:04ben_mTrying to do SDL programming with Clojure is pretty hard if you don't know Clojure that well and sdljava is pretty ... strange.
14:05Drakesontechnomancy: I am looking at swank_c_p_c.clj, (a small file)
14:07Drakesonin the definition of `completions' there is a try..catch that aborts the completion in case of any error. I change it to actually see the error.
14:07Drakeson(well, I forget to say, the initial problem was that I was getting no completions)
14:08Drakesonthe error message was this: "java.lang.IllegalStateException: Var swank.commands.completion/potential-completions is unbound."
14:08sproingieso when i hit C-c C-k in slime and it tells me there are errors, how do i make it actually show me the error?
14:08technomancysproingie: they should be shown in the *inf-lisp* buffer
14:09hoeckben_m: you can try processing, there is rosado's clj-processing, a thin clojure wrapper around it, using it with success for a small clojure space duel game
14:10technomancyclj-processing is awesome
14:10ben_mOh, I've heard about processing.
14:10ben_mI'll take a look at it, thank you :)
14:10technomancymight not be as performant as sdl
14:10sproingieshown and then some. massive traceback obscures the actual error
14:10ben_msdljava is a pain to use ... I'm getting a link error now for some reason
14:11ambienti could be possible just to use java sound and io api, plus straight opengl
14:11ambientor jmonkeyengine
14:11DrakesonI just copied the functions from swank.commands.completion into swank_c_p_c.clj, and it works. I just don't understand the mechanism that is supposed to load the stuff in swank.commands.contrib/
14:13ben_mambient: Can't use OpenGL at the moment because my video card broke :/
14:14ben_mElse I'd probably use one of the available Java game libraries
14:15Drakesonis the line (remove-ns 'swank.commands.completion) at the begining of swank.commands.completion really necessary?
14:16technomancyDrakeson: my guess is that it's not necessary for regular usage, but it might be needed to hack on swank-clojure itself interactively
14:16technomancyI'm not too familiar with the completion mechanism though; I find that "dumb" dabbrev is enough for me
14:17Drakesonwhen I remove it, it can successfully load swank.commands.contrib.swank-c-p-c.
14:18Drakesonit is not really a matter of completion. I just don't understand what that defslimefn swank-require in swank/commands/contrib.clj was supposed to work.
14:18Drakesonit might be missing something
14:18deafmacroHi! I tried righting "member?" to get a hang of using loop/recur. I would appreciate it if someone could review it. Here's the link http://pastie.org/639697
14:20Chousukethe x loop parameter is redundant :)
14:20Chousukeotherwise that should be okay.
14:21Chousukethough, (some (partial = x) coll) does the job :P
14:21ben_mHow do I fix an UnsatisfiedLinkError?
14:22ben_mDo I miss something on the classpath, or .. ?
14:22deafmacroChousuke: ah true :)
14:22Drakesonwow! I didn't know about java completion in swank ... that's neat.
14:23technomancyDrakeson: I heard about that but haven't gotten a chance to take a look yet
14:23technomancyimho that's much more valuable than lisp-level completion. =)
14:24deafmacroChousuke: but I would still have to bind write (loop [coll coll] ... since it requires even args?
14:24ben_mI thought defn is like an implicit loop?
14:25Drakesontechnomancy: it does not complete java.lang.Inte<TAB>, yet, but it completes java.lang.Integer/<TAB>
14:25technomancycool
14:26technomancyis that using the same C-c TAB?
14:26Drakesonno, just TAB
14:26technomancyDrakeson: you must have rebound it; needs C-c TAB here
14:26technomancyTAB is for indentation. =)
14:26Drakesonwell, I am in repl now
14:27ambientI do C-c I for Java classes, which inspects them. almost as good as completion, but not quite. don't know of a better way
14:27technomancyDrakeson: oh, gotcha.
14:27technomancyC-c I is really great too
14:32deafmacroChousuke: never mind. figured it out. thanks!
14:37durka42deafmacro: you have a brilliant username. that is all.
14:53ben_mIs there a way to import everything from a namespace?
15:07weissjcan someone recommend a library or strategy for storing clojure data in a db? i am working on a defect tracking system, one feature i intend to have is user-created record types, so it's a bit more dynamic than straight db tables.
15:08weissji checked out clj-record, that might work for me, is there anything else?
15:09tmountainweissj: strategies for storing data, or data serialization?
15:09weissjstoring data
15:11weissjthe data structure isn't complex, but i want it to be dynamic - can remove fields from a record or add them during runtime
15:11tmountainweissj: AFAIK, clojure-contrib has a sql library (JDBC wrapper), there's persist (Java lib), and also Berkeley DB
15:11tmountainweissj: BDB is more of a key / value store IIRC
15:11weissjtmountain: yeah that's a bit too simple for my purposes
15:14tmountainweissj: have you seen datalog?
15:27roberto_ping
15:34chouser(.show (proxy [java.awt.Frame] [] (paint [g] (dotimes [y 256] (dotimes [x 256] (.setColor g (#(java.awt.Color. % % %) (bit-xor x y))) (.fillRect g x y 1 1))))))
15:36chouseralso nice with bit-and or bit-or instead of bit-xor
15:46crios'night
15:47ambienthow would i go about making a graphics element into a repl that i could asynchronously draw different stuff? like (start-graphics g) (draw-line g 10 10 20 20) etc...
15:50chouserambient: (def g (.getGraphics (doto (java.awt.Frame.) .show)))
15:51chouserposition that window so you can type into your repl with obscuring it
15:51chouserthen: (.drawLine g 100 100 200 200)
15:51ben_mWhen I try to compile my program (clj -cp /usr/share/java/sdljava.jar sdl.clj) I get the following error: "Exception in thread "main" java.lang.UnsatisfiedLinkError: sdljava.x.swig.SWIG_SDLEventJNI.new_SDL_Event()J (sdl.clj:1)" Code: http://sprunge.us/KJJC
15:52ambientchouser thanks :)
15:52chouserben_m: you have to have the swig-generated .so in your OS library path. I think that's the most likely cause.
15:53ambientmy previous attempt was to draw a line (10 10 20 20) which I thought didn't work because it was drawn under the window border
15:54ben_mchouser: sigh ... :/
15:54chouser(.show (proxy [java.awt.Frame] [] (paint [g] (dotimes [y 256] (dotimes [x 256] (->> (+ (* x x) (* y y)) (* 0.01) Math/sin inc (* 127) int (#(java.awt.Color. % % %)) (.setColor g)) (.drawLine g x y x y))))))
15:56ben_mWhat's that ->>?
15:56chouserIt's a macro a bit like ->
15:57chouser(->> a (foo b) (bar c)) becomes (bar c (foo b a))
15:57chouserthat is, each expression is inserted as the last arg of the next expression
15:58ben_mDid you define it, or is that in Clojure?
15:58chouserit's new, in Clojure
15:58ben_mooh :)
15:58chouser(doc ->>)
15:58clojurebotexcusez-moi
15:59chousertoo new for clojurebot
15:59ben_mtoo new for me too :)
16:12hiredmanclojurebot: ant?
16:12clojurebotis equivilant to addresing the bot by name is equivilant to addresing the bot by name
16:12hiredmanclojurebot: ant is dumb
16:12clojurebotYou don't have to tell me twice.
16:13hiredmanugh
16:14hiredmanI've started to see errors like java.lang.NoSuchMethodError: clojure.lang.RestFn: method <init>()V not found (fnparse.clj:1) everywhere
16:15chouserhiredman: clean and rebuild fnparse, probably.
16:15hiredmanthat was from starting clojurebot just now, but I have was seeing something very similar when trying to get ant to build something for appengine
16:15hiredmanand fnparse was not used there
16:16chouserI see those all the time from contrib because I keep hoping between various versions of clojure.
16:16chouserhopping
16:17hiredmanah
16:17hiredmanthe error went away when I rebuilt contrib
16:17hiredman,(doc ->>)
16:17clojurebot"([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:18hiredmandamn
16:18hiredmansorry
16:18kotarakhuh? ->>? hoorray!
16:21chouser, (->> (range 256) (filter #(or (<= 65 % 90) (<= 97 % 122))) (map char) (apply str))
16:22chouseroh, whoops
16:22chouser,(->> (range 256) (filter #(or (<= 65 % 90) (<= 97 % 122))) (map char) (apply str))
16:22clojurebot"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
16:22hiredmanhandy dandy
16:22ambient,(* 0.01745329252 180)
16:22clojurebot3.1415926536
16:23criosclojurebot: logs
16:23clojurebotlogs is http://clojure-log.n01se.net/
16:25chouser,(.show (java.awt.Frame.))
16:25clojurebotjava.awt.HeadlessException: No X11 DISPLAY variable was set, but this program performed an operation which requires it.
16:25chouseroh, right.
16:27crioshi, I already posted this question but it seems it get lost in the net: did anyone read "Structure and Interpretation of Computer Programs", by Abelson, Sussma? If yes, do you think it could be an worth introductory "clojure" concepts textbook?
16:28crios[this one: http://mitpress.mit.edu/sicp/full-text/book/book.html]
16:28ambienti've read some of it and it has helped
16:28johnmn31when doing (defn add1 [x] (+ x 1))
16:28kotaraksomeone made a blog with translations of the code. (maybe the book-Stuart?)
16:28criosI believe, for a Java programmer an introductory "Lisp" world book would help
16:29criosthanks ambient
16:29johnmn31does this "expand" at runtime to (defn add1 ([x] (+ x 1))) ?
16:29kotarakcrios: touch yourself scheme in fixnum days
16:29kotarakteach
16:29hiredmanjohnmn31: no
16:29ambientclojure doesn't just have functional style, it has immutable data structures and strong concurrency constructs
16:30crioskotarak: "fixnum days" ?
16:30johnmn31hiredman: well, defn "expands" to (def (fn [.. right?
16:30ambientcrios it's going to take a lot of work (at least it did for me) to grok it all, but i think it's worth it
16:30johnmn31I mean (def foo (fn [...
16:31crioskotarak: I got it: http://www.ccs.neu.edu/home/dorai/t-y-scheme/t-y-scheme-Z-H-1.html
16:31kotarakcrios: well, I didn't choose the title. ;) In Scheme numbers are stored in fixnums, that is in 32 (or 64) bit. When the grow larger they are saved in Bignums.
16:31hiredmanjohnmn31: yes
16:31johnmn31k thanks
16:32arohneris there a clojure.contrib fn for calling (read) on a string?
16:32kotarakcrios: it's for Scheme, but that should be sufficient for lispiness.
16:32hiredmanjohnmn31: macroexpand and macroexpand-1
16:32kotarak,(doc read-string)
16:32clojurebot"([s]); Reads one object from the string s"
16:32ambientcrios you've looked at this, right? http://java.ociweb.com/mark/clojure/article.html
16:32arohnerkotarak: thanks
16:32arohnerthat's new since the last time I needed to do this
16:33criosambient: yes, and read also "Clojure Programming". But I feel I'm missing something
16:33ambientjust write some code
16:34johnmn31hiredman: tried that, but (macroexpand add1) didn't get me what I expected.
16:34hiredmanjohnmn31: that is not how you use macroexpand
16:35kotarak,(macroexpand-1 '(defn add1 [x] (+ x 1)))
16:35clojurebotDENIED
16:35criosambient: yes, I write some code, but I feel I miss perhaps the right "conceptual" world's view - a shared vocabulary
16:35ambientsicp lectures were quite eye opening in some parts
16:35johnmn31ah, ok, I forgot the '
16:36criosambient: ok, I'll read it (keeping to check also your blogs and chat, sure :) )
16:37johnmn31ahah! it does add parens:
16:37johnmn31(def add1 (clojure.core/fn ([x] (+ x 1))))
16:38hiredmanbut not in the defn form
16:38johnmn31so one could make mulit-arity lambdas as well then...
16:39hiredmansure
16:39johnmn31sweet
16:41chouserRevenue on T-shirt sales is rolling in at a steady clip of about $2.50 per month.
17:35ambientdoes clojure in future have some more revealing ways of communicating about errors?
17:36ambientim just having a bit of a difficulty in debugging
17:36ambient(which is happily easier in functional style because i can test each piece of my program separately)
17:40arbschtambient: c.c.trace can help debugging in some cases
17:47hiredmanwheee
17:47hiredmanappengine app built (hello world page)
17:48hiredmanand it runs on the local dev server thing
17:48ambientwith clojure? grats
17:48arbschtcompojure?
17:48hiredmanyeah
17:48arbschtneat. a few people have been doing that lately
17:49hiredmanthe shellscript for launching the local dev server of course has #!/bin/bash but if you change it to #!/bin/sh it runs fine
17:49ambienthmm, i wonder how that works in windows...
17:49ambientprobably not at all
17:49hiredmanthere is a seperate .cmd script for launching it on windows
17:50ambientgot to try that someday soon
17:50ambienton my list of things to do
17:51hiredmanI followed a howto I fould googling "clojure appengine"
18:07somniumhiredman: do you have the repl setup for it?
18:07somniumhttp://www.hackers-with-attitude.com/2009/08/intertactive-programming-with-clojure.html
18:08somniumit shows how to setup the appeninge api for the thread you run the devserver in, so you do live lispy development without any recompiles locally
18:09ben_mAlright guys, this is driving me insane.
18:10ben_mI've got /usr/share/sdljava.jar and a lot of *.so files in /usr/lib/sdljava/ ... I try to run a little example like this: clj -Djava.library.path=/usr/lib/sdljava/ -cp /usr/share/java/sdljava.jar SDL.clj
18:10ben_mWhen I leave out the -D line, I get an UnsatisfiedLinkerError
18:10ben_mWhen I include it, I get Exception in thread "main" java.io.FileNotFoundException: -Djava.library.path=/usr/lib/sdljava/libsdljava.so (No such file or directory)
18:11ben_mWithout the libsdljava.so at the end, that was the wrong line I pasted, but yeah, same error
18:11ambient"/usr/share/sdljava.jar" "/usr/share/java/sdljava.jar" different directory
18:11ben_mambient: I'm using the right ones when I try it, sorry.
18:11ben_mJust typed them here incorrectly.
18:13ambientare the binaries compatible?
18:14ambientJVM & libsdljava.so etc
18:14ambienti got some weird errors using 32 bit libs in 64 bit environment
18:15ben_muhm
18:15ben_mAll the .so files are 32bit libs, and I'm on 32 bit too.
18:17ben_mErrors + Source + commands I run: http://sprunge.us/ZdTU
18:21ambienti wonder how two -cp commands work in java executalbe, do they replace or concatenate
18:21ambientit might be in the clj script, just a thought
18:22hiredmanyeah
18:22hiredmanthe clj script is trying to pash the -D stuff as a file name argument to java
18:22hiredmanpass
18:22hiredmanuse java -Dwhatever directly
18:31ben_mI'll try.
18:33ben_mI get the same UnsatisfiedLinkError :(
19:24somniumis there support for variable arity multimethods?
19:27arbschtsomnium: yes
19:28somniumcould you give a simple example? I wasn't able to improvise the syntax
19:30somnium(defmulti foo (fn (....) (....)) and then (defmethod foo ([a] ...) ([a b] ...)) ?
19:31arbschthttp://gist.github.com/200252
19:32somnium ah, thank you
19:56rsynnottanyone know is there a way to view repl history in enclojure with keyboard shortcuts?
20:01danleictrl+uparrow
20:02danlei(if you meant input hist)
20:03danleiplain pgup otherwise
20:06rsynnottah, thanks :)
20:07rsynnottCTRL-SHIFT-UP on the mac, oddly
20:07rsynnott(I'm mostly an EMACS/slime person, but giving this thing a go)
20:08danleiI have it installed, but use emacs almost exclusively (wanted to know at least one alternative)
21:16cschreinerclojure needs to be distributed together with emacs as a one-install-package targeted newcomers
21:17hiredman~google clojurebox
21:17clojurebotFirst, out of 28 results is:
21:17clojurebotClojure Box, alpha - Clojure | Google Groups
21:17clojurebothttp://groups.google.com/group/clojure/browse_thread/thread/6fd17fb97f058192
21:18cschreinerfor mac?
21:18arbschtiirc, clojure-mode has an install routine that makes it quite easy to get started
21:19cschreinerarbscht: you're missing my point
21:20cschreinerit's too easy to get lost in emacs
21:20cschreinerbut when you get use to it, it rocks the world
21:21cschreinerand when you are adding "common" components, like compojure, or this 3d thing, I don't recall; (penumbra?) you have to deal with the ugliness of classpaths, in addition!
21:22RaynesIf you want to use Emacs, you're probably better being committed to learning Emacs, rather than wanting and expecting to be spoon-fed Emacs with a dumbed down installation. If you don't want to learn Emacs, Enclojure is always an option.
21:22arbschtI'm not convinced there is any way around that -- such is emacs. even if there was, it has little to do with clojure, which is independent of any editor
21:22cschreinerfrom the perspective of a beginner, this is daunting
21:23albinoemacs is like any other piece of technology, the learning curve has a pay off
21:23arbschta beginner would do well to learn emacs first, or avoid it altogether
21:23albinoI would vote for avoidance so you're not trying to learn two big technologies at the same time, but that's just me
21:23Raynesarbscht: Exactky.
21:23cschreinermy point is to get up and running with clojure (with most of the libraries preinstalled) in as little time as possible
21:23Raynesexactly*
21:24Raynescschreiner: Then you would want to just install Enclojure.
21:24RaynesOr Clojure-dev, or whatever.
21:24cschreinerbut are they good?
21:24cschreinerand what about customization?
21:24arbschtthey're suited to your constraint :)
21:24RaynesEnclojure is fine, Clojure-dev leaves a lot to be desired, and La Clojure is pretty good.
21:25cschreiner~google enclojure
21:25clojurebotFirst, out of 248 results is:
21:25clojurebotenclojure - home
21:25clojurebothttp://enclojure.org/
21:25Raynescschreiner: You need to decide what you want. Do you want superpowers and customization, or do you want to get up and running with Clojure really fast?
21:26RaynesYou can't really have one or the other unless you're already an Emacs user. ;)
21:26cschreinerfirst up and running, then superpowers
21:26cschreinereverybody wants to have superpowers
21:26cschreinermost geeks anyway
21:29cschreinerenclojure seems to suit my needs, thx
22:25Drakesonhow can I get a lazy random sequence?
22:28chouser,(take 20 (repeatedly #(rand-int 100)))
22:28clojurebot(45 59 66 15 15 27 40 4 29 10 74 77 17 99 17 12 13 33 31 83)
22:29Drakesonthanks
23:32Drakesonhow can I apply a function to all vals of a hashmap and obtain a "transformed" hashmap?
23:33chouser,(
23:33clojurebotEOF while reading
23:34chouser,(let [m {:a 1, :b 2, :c 3}] (zipmap (keys m) (map #(* 5 %) (vals m))))
23:34clojurebot{:c 15, :b 10, :a 5}
23:35Drakesonright now I am doing (defn map-map [h f] (apply hash-map (mapcat (fn [[k v]] [k (f v)]) h))), which looks inefficient
23:35Drakesonchouser: thanks
23:35Drakesonis there a function for that?
23:39kevin__are (keys m) and (vals m) going to have a stable ordering?
23:42slashus2only in a sorted-map
23:42slashus2well..
23:44kevin__that's what i figured, so calling them seperatly to map a hash would be unsafe right?
23:46slashus2,(keys (apply hash-map [6 8 1 2 3 4 5 6]))
23:46clojurebot(1 3 5 6)
23:46slashus2I am not sure... hmm
23:46hiredman,(let [h {:a 1 :b 2} f (fn [f v] (reduce #(conj %1 [(key %2) (f (val %2))]) {} v))] (f inc h))
23:46clojurebot{:b 3, :a 2}
23:49slashus2,(keys (apply hash-map [:c 8 :a 2 :b 4 :d 6]))
23:49clojurebot(:a :c :b :d)
23:49slashus2,(keys (apply sorted-map [:c 8 :a 2 :b 4 :d 6]))
23:49clojurebot(:a :b :c :d)
23:50ngocHow to remove element from a hash? I can use "remove", but it is long way because it takes a function.
23:50kevin__,(let [h {:a 1 :b 2 :c 3 :d 4}] [(keys h) (vals h)])
23:50clojurebot[(:a :b :c :d) (1 2 3 4)]
23:50kevin__,(let [h (apply hash-map [:a 1 :b 2 :c 3 :d 4])] [(keys h) (vals h)])
23:50clojurebot[(:a :c :b :d) (1 3 2 4)]
23:51hiredmanngoc: dissoc
23:51kevin__same wrong order this time, i guess that's ok
23:51slashus2:-(
23:53ngochiredman: thanks
23:53kevin__i was concerned that since they were unordered, keys and vals might be unordered in different ways
23:54kevin__so if you zipmap'ed them back you would associate the wrong keys and vals
23:55hiredmansome future IPMap migth do that
23:59ngochiredman: I also notice that "remove" changes the class of the hash to sequence
23:59ngoc(def h {:a 1, :b 2})