#clojure logs

2009-01-10

00:12durkawhat do y'all use in clojure for http client things?
00:13durkaXMLHTTPRequest style
00:16danlarkinwhatever framework you're using (assuming it is one) should deal with it I guess?
00:16durkawell that's what i'm asking, like in CL you might use Drakma or something
00:18Chouserduck-streams will open a URL for you.
00:21Chouser(line-seq (ds/reader "http://n01se.net/"))
00:22durkahmm, ok
00:22Chouseryou need more control?
00:24durkamaybe
00:24Chouser(line-seq (java.io.BufferedReader. (java.io.InputStreamReader. (.openStream (java.net.URL. "http://n01se.net/")))))
00:24durkai might need to issue specific HEAD/GET/POST requests
00:24mmcgranayou might want to check out Commons HttpClient
00:24durkaoh, i was wondering if you were here
00:25durkais clj-http-client ready for a user?
00:25danlarkindurka: ohh, you mean from the client side
00:25durkayeah
00:25danlarkinsorry :)
00:25mmcgranayeah, feel free to give it a shot. no promises, but i'll try to fix any problems you run into.
00:28durkai'll see what happens
00:30mmcgranaOK, thanks for trying it out. I'm actually pushing a huge changeset (truly epic) to clj-garden right now, but it doesn't touch clj-http-client. BTW there is some example usage of it in the gitcred sub-project.
00:53durkabah
00:53durkawhere the heck is the OS X classpath set
00:53mmcgranahmm i set it at the command line using a shell script
00:54mmcgranaare you having classpath problems?
00:56durkai'm just trying to find out where it comes from
00:57durkai'll just append to it in .zshrc
00:58mmcgranafwiw, try $ cat /System/Library/Java/JavaConfig.plist
01:00durkai did find that
01:00mmcgranao ok
01:00durkabut $CLASSPATH in the shell seems to not have the complete DefaultClasspath
01:00durkahmm, clojure.core/use is converting - to _ and therefore not finding clj-http-client.jar
01:01mmcgranayou want to (use 'clj-http-client.core), not the jar itself
01:01mmcgranaor (ns your.ns (:use clj-http-client.core))
01:01danlarkindurka: yes, clojure converts - and _ regarding namespaces
01:02durkabut then what would i put on the classpath
01:02durka=> (use 'clj-http-client.core)
01:02durkajava.io.FileNotFoundException: Could not locate clj_http_client/core__init.class or clj_http_client/core.clj on classpath: (repl-1:12)
01:02mmcgranao i c sorry this is my bad
01:03mmcgranaone sec
01:04durkaadd-classpath'ing the jar fixes it
01:04durkaexcept i don't have Commons HttpClient...
01:05mmcgranahmm yeah so i don't the lib is broken, i saw the same error you did because i also didn't have it in my classpath, but now its working for me, so i can help you get it working over there.
01:06mmcgranathe httpclient jar i'm using http://www.java2s.com/Code/Jar/Apache-Common/commons-httpclient-3.1.jar.htm
01:07mmcgranaalso, you'll need the commons io 1.4 jar http://commons.apache.org/downloads/download_io.cgi
01:07mmcgranathis will be a good chance for me to write a proper readme for the project. thanks for bearing with me durka
01:07durkano problem
01:07durkayou aren't using the 4.0 beta?
01:08mmcgranano, its actually a totally different library i think - pretty much a complete rewrite. i'm not sure that its fully stable yet, 3.1 seemed fine.
01:09mmcgranai'll keep my eye on it though.
01:11mmcgrananow that i look at again, 4.0 seems more mature than i previously thought. I'll have to look at that again when I get the chance.
01:12mmcgranaum that didn't make much sense: basically I'll look into 4.0 at some point in the future
01:13durkaalso need the commons logging jar
01:14durkahttp://commons.apache.org/downloads/download_logging.cgi
01:14mmcgranaok thanks
01:15mmcgranayeah I don't like that a http library depends on a logging library and then goes off creating logs behind your back when you initialize clients, if thats fixed in the supposedly more modular 4.0 it alone would be a good reason to switched
01:15mmcgrana* switch
01:17durkaalso commons codec
01:17durkaworks!
01:17mmcgranawin!
01:17durkaand with that, i believe it's past my bedtime
01:18mmcgranawell i'm glad you got that working. let me know if you have end up with any problems or suggestions. i'll try to get this readme out by tomorrow.
01:20durkaso for the readme, what i needed to get it working were the commons io, logging, codec and httpclient jars (I put them in the java ext dir) and clj-http-client.jar (explicitly, not the directory containing it) on the classpath
01:21mmcgranaok
03:57danleijoin emacs
04:20bagginsHi.
04:26bagginsCan I use clojure if I'm after code that is compiled optimally for speed?
04:27bagginsthe whole every-variable-is-final attitude seems to go against that as a priority.
05:02rottcoddbaggins: there is overhead, but you can optimize bottlenecks to match the speed of java
05:02blbrowncan I pass clojure sequences where a java array is required. e.g. an array of strings [ "a", "b" ]...
05:05blbrowninto-array I guess
05:08bagginsi guess there's the question: does the compiler really optimize thanks to this?
05:10blbrownbaggins, I just joined, but if you look at scala (another jvm language), in some cases it has better speed when matched up against pure java. Remember that some of the core java libraries are poorly designed. Some maybe clojure can end up with faster bytecode?
05:24rottcoddas Michael Abrash says, "the best optimizer is between your ears"
05:24RaynesTruefax
05:27blbrownis there a 'return', early exit function in clojure
05:28danlarkin"you're doing it wrong" if you need one
05:28blbrowncl has one, hehe
06:01bagginswait a minute�. i have to "do it [anything/everything] right" in clojure? could be in trouble
06:10blbrownbaggins, hehe, that is what I was thinking. I have been doing it wrong in common lisp for 5 years too
06:17bagginsheh
06:18blbrownbaggins, it isn't a crime, I don't worry about it
06:18bagginsit's weird though really. computers are state machines. surely an imperitive style suits them more.
06:19bagginswhen i write CL i write more in an imperetive style than i probably should i think.
06:21kotarak"stolen" from Scheme ;)
07:48bagginsok now i've been wrestling with this for like half an hour
07:48bagginshow do i specify in gen-class' :methods vector that a method is of void return type
07:49kotarakVoid/TYPE, IIRC.
07:49bagginsuy
07:49kotarakLike Integer/TYPE for ints.
07:49bagginsHm. well I don't think that works either
07:49bagginsi'm getting a weird error
07:49kotarakBut I may be wrong. So you have to test.
07:49bagginsjava.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.IllegalArgumentException: No matching field found: getSimpleName for class clojure.lang.Symbol (ClojureAppletTest2.clj:3)
07:50kotarakAt least for integer it works.
07:50kotarakMaybe I remember something wrong for the Void stuff...
07:50kotarak1:1 user=> Integer/TYPE
07:50kotarakint
07:51bagginshm
07:51bagginslet me show you what i have
07:51kotarak1:3 user=> java.lang.Void/TYPE
07:51kotarakvoid
07:51kotarakYou have to qualify Void.
07:51kotaraklisppaste8: url
07:51lisppaste8To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.
07:52bagginsstill the same
07:52kotarakPaste your code to lisppaste. Then we can have a look.
07:54lisppaste8baggins pasted "when I add :methods, this fails." at http://paste.lisp.org/display/73383
07:54bagginssome of that code i wrote ages ago
07:55bagginsi realisei can do str function instead of concat now
07:55kotarak(. obj (method)) can be written as (.method obj) now.
07:55bagginsok
07:56kotarakThe first is still ok, but the later is more convenient.
07:56bagginsbut anyway. the problem is that :methods key
07:56kotarakEg. for (-> obj .getThing modifyIt .doStuff)
07:57bagginsok. i realise it could be written a lot more prettily
07:58kotarakNo Problem. Just a remark...
07:58Chousukebaggins: also (. Color BLUE) = Color/BLUE
07:58Chousuke/ is used to access static fields
08:00bagginsbut do you know why it fails in that cascading way when i try to put that method in there?
08:02lisppaste8kotarak annotated #73383 with "works for me :(" at http://paste.lisp.org/display/73383#1
08:03ChousukeI don't get any errors either.
08:04kotarakAh. Ok.
08:04kotarakNow I have the failure.
08:11bagginshow are you compiling it?
08:11bagginsi have it saved in a file ClojureAppletTest2.clj
08:11bagginsand i am running
08:11kotarak(compile 'foo.ClojureAppletTest2)
08:11bagginscho "(compile 'ClojureAppletTest2)" | java -cp clojure.jar:`pwd` clojure.lang.Repl
08:11bagginsecho that's supposed to say
08:12kotarakI just type it at the repl with src and classes in the Classpath and the file in src/foo.
08:14bagginshm
08:14bagginsare you on the latest version?
08:15kotarakNot totally, but sufficiently bleeding edge. 1195.
08:15bagginsoh hm.
08:16bagginsthe repository has changed?
08:16kotarakClojure is now hosted on google code.
08:16kotarakhttp://code.google.com/p/clojure
08:17bagginsno wonder
08:18bagginsmaybe he should leave a note in the old repository with instructions for the new one
08:18bagginsand remove all the code
08:20bagginshm. could take a while. svn is slow.
08:20kotarakThere are also mercurial and git mirrors...
08:20kotarakMuch faster.
08:22bagginshttp://github.com/kevinoneill/clojure/tree/master this one? looks about it
08:23kotarakDon't know. I use Shawn Hoover's mercurial mirror on bitbucket.
08:23Chousukebaggins: that's the git one, yes
08:24Chousukeit's not auto-updated though :/
08:24Chousukeso sometimes it lags behind a bit
08:24bagginsoh
08:24bagginswell
08:25bagginsgreedy
08:25ChousukeI did a git svn clone :)
08:25Chousuketook about 30 minutes but that was one-time pain.
08:27bagginsyeah that's what i'm doing
08:28kotarakHmmm... The argument vector in the :methods section seems to be the problem.... At least that's the last thing printed, before the exception is thrown, when I add a (prn c) (flush) to escape-class-name...
08:29kotarakBut I can't really believe it...
08:32bagginsyeah. when i remove the line it ... works-ish... or it fails in a different place
08:34kotarakbtw, you can just specify void for void.
08:35kotarakHmmm... An empty argument vector also solves the problem.
08:44kotarakHmm.. it seems for method arg vector we get a Symbol instead of a Class.....
08:44kotarakjava.lang.Class
08:44kotarakjava.lang.Class
08:44kotarakjava.lang.Class
08:44kotarakclojure.lang.Symbol
08:48kotarakAdding this line in escape-class-name fixes the problem.
08:48kotarak (let [c (if (class? c) c (Class/forName (name c)))]
08:49kotarakAlso I still believe I miss something.
08:49kotarakAlthough...
09:06kotarakrhickey: in line 137 in gen-class.clj the argument vector of a :methods spec is fed to overload-name with converting the symbols to classes via the-class. Is this a bug?
09:06kotarakwithout converting....
09:22FibHm, svn relocate is telling me that the uuid for the new repo doesn't match - should I just do a clean checkout?
09:33knaprwhat profiler works best for clojure?
09:34kotarakbaggins: I drilled it down to this:
09:34kotarak(ns foo.Bar
09:34kotarak (:gen-class
09:34kotarak :methods [[toString [Object] String]]))
09:34kotarakCompiling this fails.
09:40bagginshm
09:41knaprwhat profiler works best for clojure?
09:41kotarakknapr: any Java profiler will do, rhickey uses eg. YourKit.
09:43rhickeykotarak: :methods is only for adding methods, your class will have toString already because it is in Object
09:44kotarakrhickey: Ok.
09:46kotarakbaggins: java.applet.Applet already has a paint method from java.awt.Container. So just drop the :method clause.
09:48bagginsoh
09:49bagginsi added it because of another problem
09:49bagginsbut ok
09:49baggins:)
09:52bagginsnow i get a filenotfound exception
09:54kotaraktry adding a baggins.ClojureAppletTest and put the file under src/baggins/ClojureAppletTest and make sure the classes directory exists and both, src and classes, are in the classpath.
09:55kotarakI mean (ns baggins.ClojureAppletTest ...) instead of (ns ClojureAppletTest ...)
09:56bagginsin the clojure src directories?
09:57kotarakNo. In your project directory. You shouldn't work in Clojure's source tree.
09:58kotarakThe file containing the namespace has to follow certain naming conventions.
09:58kotarakfoo.bar-baz => foo/bar_baz.clj
09:58bagginswell i was just trying to do it in the pwd
09:58bagginsand i put . in the classpath
09:59kotarakIt's good to put your sources in a src directory and create a classes directory, which holds the compiled class files.
09:59bagginsbut i just trashed my .bashrc file accidentally >_M
09:59baggins>_<
09:59rhickeykotarak: looks like a bug (overload-name + :methods), could you please create an issue?
09:59kotarakrhickey: ok
09:59kotarakwill do
10:00kotarakbaggins: then you have to do (binding [*compile-path* "."] (compile ...)) (out of my memory..)
10:00bagginsah. binding
10:00bagginsi was just trying let
10:12ChousukeI wonder what the exact rules for symbol/keyword names are :/
10:14StartsWithK(symbol "with spaces and . and / ")
10:15ChousukeStartsWithK: that's the problem. 'symbol does no validation
10:15Chousukeyou can create illegal symbols with it
10:16StartsWithKwhat do you mean by validate?
10:16StartsWithK(symbol? (symbol "with spaces and . and / "))
10:16StartsWithKreturns true
10:17kotarakbut "with spaces and . and /" is probably not a valid symbol.
10:18Chousukeit's unreadable
10:19ChousukeI thought about writing a validator since that's an open issue but I'm not sure I can catch all the corner cases
10:20Chousukethen there are other issues like being able to create a namespace named "foo/bar", but you can't actually access vars from that namespace
10:20Chousukefoo/bar=> foo/bar/x
10:20Chousukejava.lang.Exception: No such namespace: foo/bar (NO_SOURCE_FILE:0)
10:21Chousukeinteresting, isn't it?
10:24Chousukealso, / is a valid symbol but /a is an invalid token :(
10:28StartsWithKexcpetion made for / in clojure.core i guess
11:17asbjxrnWhat am I doing wrong? This takes 34 seconds:
11:17asbjxrn(time (let [x (make-array Float/TYPE 10)] (dotimes [n 100000] (dotimes [f 10] (aset x f (float 0.1))))))
11:18Chouseruse a number smaller than 100000, and it should go faster.
11:19asbjxrnRight. I just thought updating arrays would be faster.
11:19Chouseror insert #^floats after x
11:20Chouserthat is, between x and (make array ...
11:21rhickeyname check: I have enhanced io! to establish an io context, and have a new fn, temp name io-scope, which takes a Closeable and ties its lifetime to the nearest dynamically enclosing io! block. so, (io! ... (io-scope afile) ...) afile will be automatically closed
11:22rhickeyio-scope throws exception if not in io! context
11:22rhickeybuilding blocks of enforced closing
11:22Chouserclose-later
11:23rhickeyick
11:23Chouserhm
11:23rhickeyshould have io, was io-close, but that seems to close now
11:23rhickeywould like it to be short as well
11:23rhickeybut using scope as a verb is slightly icky too
11:25rhickeyio-register, io-bind, io-entail
11:25Chouserit does almost nothing at the moment it's called, so it's like a declaration
11:25kotarakio-closee
11:26Chouserio-closable
11:26kotarakio-to-close
11:26asbjxrnChouser: Thanks. That worked.
11:26Chouserasbjxrn: great
11:27rhickey(io-scope x) returns x
11:27rhickeyI imagine a lot of (let [foo (io-scope bar)] ..)
11:27rhickeyalso map io-scope
11:28Chouser...in a context that consumes the whole seq, of course
11:28rhickeyChouser: nope
11:29rhickeythis is part of the solution for inside out lfe
11:29rhickeythe idea is that some (mostly io) soures will only give you a stream if they can succefully io-scope their resource
11:30rhickeythen you can use as much or little of the stream, knowing the io! block will clean
11:30rhickeyup
11:31bagginsok i give up on clojure for the day
11:31bagginsthanks for the company and help.
11:32kotarakbaggins: np
11:33ChousukeI like io-scope. instead of being an action on its argument (which should be a verb) it looks more like a declaration
11:34rhickeyChouser: but, yes, it must finish with the stream/seq in scope, if it leaks it, it will throw, but I can't prevent leaking
11:37rhickeyio-closes?
11:38ChouserI meant using up the (map io-scope ...) seq so that everything gets closed, but I guess if they're being opened lazily as well, that should be ok.
11:38kotarakio-will-close
11:39rhickeykotarak: a bit long
11:40Chouserthe problem with io-scope is it doesn't even hint what it will do with the io scope.
11:40Chouserio-closes is better. I like the sound of io-closable but i suppose that sounds more like a suggestion than a demand.
11:42rhickeyChouser: the problem with closable is spelling, it's java.io.Closeable
11:49Chouserwow. why would they spell it like that? ..but ok, I can see that that nixes closable
11:49knaprYourKit is not free though, what's the best free profiler?
11:49rhickeyanother problem with close is it marries current capability, I'd like this to work if Java adds Disposable etc, in other words the scoping related cleanup might be polymorphic
11:50rhickeyfor me, scope generically implies lifetime
11:50Chouserio-kills
11:50rhickeytoo violent
11:50Chouserheh
11:51Chouserio-allows-to-pass-on
11:52rhickeyoh boy
11:52Chousukeio-bound?
11:53rhickeyChousuke: the only problem with bind/bound is the other usages, also io-bound implies a perf characteristic
12:02rhickeyio-involve, io-enclose, io-collect
12:05rhickeyio-enlist
12:06kotarakio-disposes
12:07rhickeyio-join, io-tie
12:14rhickeyio-frees
12:15StartsWithKio-attach io-relate io-fixate io-confine
12:15ChouserSomebody already said io-collect, right? I like how that suggests collecting them all into the 'io!' block, but also collecting a bit like garbage collect.
12:15kotarakio-cleaned
12:17rhickeyChouser: gc is collecting in a sense that close is not
12:17rhickeyio-limit
12:17kotarakio-closed
12:18holmakMay I ask what you are trying to name?
12:18lisppaste8asbjxrn pasted "Why does the first let benefit from type declaration, but not the second?" at http://paste.lisp.org/display/73389
12:18holmakIs it some kind of macro to close a file after you do stuff with it?
12:19rhickeykotarak: it needs to be generic, not tied to close is better
12:19asbjxrnI can't spot what the difference between the two lets are... Can anyone help me out?
12:20rhickeyit really is about the extent of the resource
12:20kotarakholmak: it registers a thing in an io! block, to be closed when the io! blocked is left. Throws when there is no enclosing io! block.
12:20Chousukeasbjxrn: give type hints to x and y too?
12:21kotarakio-resource
12:21holmakkotarak: Thanks. Reminds me of "with" in Python, though someone has probably brought that up already. "io-with"?
12:24asbjxrnChousuke: You're on to something. But where to I add the hint in a dotimes?
12:25asbjxrn(And should dotimes have added it itself, since it has to be an int.)
12:27achim_pasbjxrn: maybe try (aset diffused-grid (unchecked-add x (unchecked-multiply y 100)) (float 0.1))
12:28lisppaste8rhickey annotated #73389 with "faster" at http://paste.lisp.org/display/73389#1
12:29asbjxrnAh!
12:35akingwow.. asbjxrn paste goes 200x faster by adding a single "int" coercion.. didn't think reflection was that slow.
12:36Chouserthat's boxing, not just reflection
12:36akingso boxing and reflection? or just boxing?
12:37rhickeyaking: primitive vs boxed math
12:38rhickeyall-primitive arithmetic is very fast
12:40akingI guess the skill is to figure out where and when to add the coercion tags. Turning on the reflection warning is showing lots of warnings in my code.. time to track down those in the more math intensive bits.
12:40rhickeyio-frees and io-releases match the generic resource notion
12:40Chousukeio-autorelease?
12:41Chousuketoo long?
12:43asbjxrnAny reason (+ 2 100) shouldn't be (int (+ 2 100)) ? Overhead in the wrong places?
12:43vsthesquareshiredman: why are there some methods in clojurebot_core that do not abide by lisp convention and use camel case instead? are they java overrides?
12:44Chousukeasbjxrn: in that case the addition will be done with boxed math, and then cast to primitive
12:45asbjxrnSorry. My test was wrong.
12:45lisppaste8rhickey pasted "line-stream example of io-scope use" at http://paste.lisp.org/display/73390
12:45Chousukevsthesquares: they have been there since the beginning
12:46Chousukevsthesquares: no-one bothered to change them
12:46asbjxrn(What I actually meant was (+ (int 2) (int 100)) and (int (+ (int 2) (int 100))). But that is the case already.)
12:46vsthesquaresoh, ok
12:49ChousukeI should've named the clojurebot things clojurebot.core etc instead ;( but I didn't realise I could have the namespace clojurebot AND subnamespaces at the same time.
12:49ChousukeI guess I could just break things a bit
12:49Chousuke:P
12:50vsthesquareswell, I was just wondering, thanks for the info
13:35Lau_of_DKGood evening everyone
13:39zargon_Noob question: lisp's/clojure's development idiom is to change code/functions in your "running" environment on-the-fly and then rerun the code you're working on, right? How does this relate to the fact that a function as parameter comes in as the function itself (not its var), so that a change to the original function might not be seen if this function-reference is being cached? Is this a...
13:39zargon_...problem? How do you deal with that?
13:40Lau_of_DKIt doesnt seemed like anything is cached, so all updates apply immediately
13:40vsthesquaresit's just being evaluated every time you send it to the repl
13:42zargon_but if you do (def myfunc_handler myfunc) and then (otherfunc myfunc_handler), otherfunc will not see any changes to myfunc when called afterwards, right
13:42zargon_?
13:44danlarkinzargon_: why not test it out :)
13:45zargon_example scenario: in web-app development i would typically like to store such handlers in the session (buried in some component-graph), no consuming function will ever see changes to the underlying function
13:45zargon_this is in contrast to the above mentioned "on-the-fly" change idiom , isn't it?
13:47zargon_danlarkin: I tried, and i know that (def myfunc_handler #'myfunc) works like I want it to. The question is: should I always store the var if we want to propagate changes on-the-fly?
13:48danlarkinzargon_: no, if you redefine myfunc, any code calling myfunc will immediately use the new definition
13:48danlarkinno need to use myfunc_handler for that
13:50zargon_danlarkin: hmm, so storing handlers like in (def myfunc_handler myfunc) is not somethin you're confronted often? Is this an "anti-pattern"?
13:52zargon_what about generator functions which internally cache a function-reference (e.g. via closure), this would be a typical scenario ...
13:54danlarkinzargon_: closures act the same as any other code
13:54danlarkindynamic invocation
13:55lisppaste8achim_p pasted "on the fly" at http://paste.lisp.org/display/73394
13:56danlarkinHm
13:56achim_pdanlarkin: i think that's the problem (see paste)
13:57zargon_achim_p: thx for clarifying
13:57danlarkinbut why would that behave that way when one layer of "indirection" does use the redefed definition?
13:58danlarkinoh
13:58danlarkinwait
13:58danlarkinnevermind
13:58danlarkinI know why
13:59achim_pyou close over the value of the var, not the var itself
14:04zargon_achim_p: isn't that something that happens often in clojure programs?
14:07achim_pi'd say so, yes. the #' form seems to be rather rare. but i don't know how to best organize code for live patching, i've never really done that. i always thought it was a lisp myth ;)
14:10zargon_well, web-developing (e.g. via compojure) would qualify as "live-patching" as you call it. you have a serverside environment with "state" and between HTTP requests you change functions, so in this case if you close over values in the code you would be confrontend with that problem ...
14:11Lau_of_DKachim_p: You thought live patching was a myth? Its been done on a space shuttle by Nasa Im told :)
14:11ChousukeI think if you need to pass functions to some library and might want to live-update the function later, the right way to do that is to pass the var
14:12zargon_Chousuke: which means you change code semantics because of the way you develop your application?
14:13Chousukeassuming you have f, that takes a function as its parameter and setups a thread that calls teh parameter in some way repeatedly (on its own), then you need to give f the var as the parameter... otherwise you lose the ability to update it live.
14:13Chousukezargon_: the fortunate thing here is that vars implement IFn and just pipe the call down to the value they hold
14:14Chousukezargon_: if x holds a function, (#'x 1) and (x 1) have the same effect
14:14Chousukehm, bad wording
14:14zargon_i know that, and its a clever decision, however ...
14:15zargon_why isn't that the default?
14:15Chousukedefault?
14:15zargon_I mean propagating "vars" to functions instead of the function itself
14:15Chousukevars are not the same as their values
14:17zargon_Let it say that way, why doesn't the IFn act like a var so that on-the-fly updates are always seen ...
14:17ChousukeIFn is an interface for things that can be called.
14:17Chousukethe thing here is that data is immutable.
14:18Chousukeif you redefine a function, it results in a different function
14:18Chousukethat is, it doesn't change the old function
14:19achim_pi think the question behind this is: why are vars resolved at read time instead of eval time?
14:19achim_pwho knows the answer? ;)
14:19zargon_yes ...
14:20Chousukeum, what?
14:20achim_paren't they?
14:21ChousukeI'm not sure what you mean by read-time resolution
14:21Chousuke(def a (def x 1)) (var-get a) = 1; (def x 2) (var-get a) = 2
14:22lisppaste8danlarkin pasted "dynamic invocation?" at http://paste.lisp.org/display/73395
14:22Chousukehowever, when you do for example [x x] it results in [1 1]; that is, the value inside the var is taken instead of the var itself
14:22achim_pwhat i mean is: for (def x 3) (def y 4) (+ x y) is not (+ #'x #'y), for instance
14:23zargon_As I understand it the compiler goes from symbol => var => function-ref and stores the function-ref in the bytecode, this is the reason why live-updates can not be seen. I just wonder why this is the "default" instead of having a mechanism that works like storing a var and deferring function-ref lookup to runtime ...
14:23Chousukeachim_p: yeah, and that's makes sense.
14:23Chousukeachim_p: adding together two vars is not a sane operation :P
14:23achim_pso my guess was the symbol->var translation happens at read time
14:26zargon_but I guess it's all about Clojure's immutability promise which has been applied to function-definitions as well
14:29Chousukelisppaste8: url
14:29lisppaste8To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.
14:31lisppaste8Chousuke pasted "live updates" at http://paste.lisp.org/display/73396
14:32Chousuketry that :P
14:34Chousukewell, adding the one missing paren of course.
14:35eyerisWhat do I need to load the MySQL JDBC driver besides "(class com.mysql.jdbc.Driver)"? I'm getting "java.lang.ClassNotFoundException: com.mysql.jdbc.Driver"
14:36zargon_Chousuke: thanks for clarification, my question was: do we have the need for "cangeable" very often in Clojure programs as I understand the answer is "no", however I think in webdevelopment the answer would be "yes"
14:36triddellquestion: if I have this data structure:
14:36triddell(def data '( ([1][2]) ([3][4]) ))
14:37triddellhow can I get ([1][2][3][4]) ?
14:37triddellbasically I want to flatten all the vectors to one list
14:38Chousukezargon_: I think in webdevelopment most of your functions are used directly by others instead of indirectly like that. in those cases, you don't need to pass around vars.
14:38Chousertriddell: concat
14:39zargon_ok, thanks for listening guys ...
14:39triddellChouser: thanks! I'll check that out.
14:39lisppaste8Chousuke annotated #73396 with "another example" at http://paste.lisp.org/display/73396#1
14:39Chousukeoh, damn, he left :p
14:42achim_pcan anybody more knowledgeable than me confirm or deny the following statements?
14:42achim_p1. at read-time, symbols are resolved to the *values* of the corresponding vars
14:42achim_p2. at read-time, #'-forms are resolved to the vars
14:42achim_p3. for updateable "higher order" functions passed to a function, we need the var
14:42triddellChouser: the inner vectors are in lists though... concat doesn't seem to remove these
14:42achim_p4. for updateable..., resolution (1) must not happen
14:42achim_p5. this would mean, that the burden of var-resolving would lie with each function and must not happen automatically
14:42achim_p6. nobody would want that ;)
14:44Chousukeachim_p: I'm not sure about that. you can see how redefining foo affects bar in my annotation
14:45mmcgranaChousuke: are there any particular semantics around changing a bunch of definitions at the same time in a concurrent setting? If you have a graph of functions referring to each other and multiple using these functions, is there any sane way to change them all? I.e. is there a way to hot-swap an entire application?
14:45mmcgrana*multiple threads using
14:46Chousukemmcgrana: I think defs are atomic, but you'll have to ask rhickey for details.
14:47Chousertriddell: ah, try (apply concat my-list)
14:48mmcgranaYeah I'm pretty sure that individual defs are atomic - i think the symbol table is implemented with the same persistent data structures used in user-level code - but I'm not sure that can gaurentee safty in swapping an entire lib w.r.t to the application logic. Perhpas one would just have to lock a region while everything gets sanely swapped out.
14:51eyerisWhat does (class do? I can't find it in the docs.
14:52triddellChouser: thank you once again... I do try this stuff on my own for before asking here :-)
14:52mmcgrana(doc class)
14:52clojurebotReturns the Class of x; arglists ([x])
14:55eyerisIs there a way to get readline-style history support in the repl?
14:56vsthesquareseyeris: you can use jline
14:56Fibhttp://clojure.org/getting_started
14:56eyerisAhh. I see it now.
14:56FibMake sure to use ; rather than : in the classpath, that confused me the first time
14:58danlarkinif you're on windows, that is
15:09eyerisI am trying to load the MySQL JDBC driver. I'm a bit hopeless, having not used any other JVM language. My best attempt is: http://pastebin.com/m2fa17e42
15:10AWizzArdeyeris: have you downloaded the driver from the official mysql website?
15:11eyerisNo, I installed it from a debian pacakge.
15:12AWizzArdOkay, fair enough. Have you added it to the classpath?
15:13eyerisI think so, I've set JAVA_HOME=/usr and I can find the driver in /usr/share/java/mysql.jar
15:13AWizzArdoh, btw, import is not the right thing to do
15:14eyerisYeah? I've tried (class com.mysql.jdbc.Driver)
15:14AWizzArdeyeris: try: (Class/forName "com.mysql.jdbc.Driver") instead
15:14eyerisThat also resulted in a classnotfound
15:15eyerishttp://pastebin.com/m4413b7a5
15:15danlarkineyeris: the mysql.jar isn't on your classpath?
15:16AWizzArdyou have the mysql-connector-java-5.1.7-bin.jar in your classpath, yes?
15:16danlarkinin these snippits your're pasting, it's not on your classpath
15:16eyerisHow can I tell what my classpath is set to?
15:16danlarkinyou're setting it with the -cp argument to java
15:16eyerisI've tried adding /usr/share/java/ to my -cp switch
15:17Chousukeeyeris: you need the full path to the jar
15:17AWizzArdbut you should add /usr/share/java/mysql-connector.jar to the CP
15:17eyerisOh, I thought -cp just appended values to your std classpath
15:17eyerisI see.
15:17AWizzArdeyeris: I wished -cp would work like that.
15:17eyerisSo there is no way to make the JVM auto load classes from the jars in a dir?
15:18danlarkinif you want that you need to do java -cp $CLASSPATH:etc:etc
15:18Chousukethere's the java.ext.dir property or something
15:18ChousukeI can't remember the exact name
15:19eyerisYay! It works!
15:19AWizzArdgrats
15:19eyerisNow I just need to figure out how to add it to the classpath used by Jetty/Webjure
15:21Guest67527I am having trouble getting doc strings to show up on multimethods
15:21Guest67527(defmulti multi "some-data" identity)
15:21Guest67527doesn't do it
15:26eyerisDoes anyone here know how I can figure out what packages are available as dependencies in Maven2 pom.xml files?
15:29ChouserGuest67527: there's no special support for docstrings in defmulti
15:29ChouserGuest67527: so instead, do: (defmulti #^{:doc "my docstring"} multi identity)
15:29Guest67527ah, the meta goes before the item name
15:30Guest67527I am not always sure where to put the meta description
15:32AWizzArdclojurebot: max people
15:32clojurebotmax people is 127
15:32AWizzArdah nice
16:02AWizzArdrhickey: what for would you use java.util.Hashtable vs Clojures HashMaps {} ?
16:04danlarkinAWizzArd: within clojure?
16:05AWizzArdyes
16:05AWizzArdHashtables are much more ugly to use, but it seems that they are threadsafe and a good bit more efficient.
16:06AWizzArdThread safe, but no transaction safety.
16:07rhickeyAWizzArd: how do you move something from one ht to another thread-safely?, or do a conditional add?, look for one of n keys etc etc?
16:07rhickeyatomic individual ops isn't much mt capability
16:07AWizzArdrhickey: only with locking I guess
16:08rhickeyexactly
16:08rhickeythus, Clojure
16:08AWizzArdyes
16:33eyerisIs (let) lazy?
16:33eyerisI.e. is this correct? http://pastebin.ca/1305380
16:38danlarkineyeris: no
16:38danlarkinthe difference is in your second example you have (. rs (next))
16:38Lau_of_DKeyeris: The correct approach to SQL is: http://github.com/Lau-of-DK/clojureql/tree/master
16:39Chousukeeyeris: please don't use . that much, it hurts my eyes :(
16:39Chousukeeyeris: it's much better to use (.next rs) etc.
16:40Chousukeand instead of . you can use the more general -> operator :)
16:40Chousukeer
16:40Chousuke..
16:40Chousukeinstead of ..
16:42Chousukeeyeris: one reason for not using . is that the head of a list (where the operator goes) is an important place, and "." alone doesn't carry any information about what you're actually doing
16:43eyerisOkay
16:43Chousukeof course, there are times when . is better, but I can't think of any example right now
17:03mmcgranais there any way to memoize a function such that logic that retrieves the value is run exactly once? I'd like to cache the result of slurping an IO stream into a string.
17:04durkathere's the memoize function in core
17:04rhickey(doc delay)
17:04clojurebotTakes a body of expressions and yields a Delay object than will invoke the body only the first time it is forced (with force), and will cache the result and return it on all subsequent force calls; arglists ([& body])
17:06mmcgranaRight delay is simiilar to what I'm looking for, but I think the caller needs to have a handle on the delay to be able to prevent re-execution of the slurping. I'll make an example one sec.
17:12Lau_of_DKDoes anyone here know of a good opensource (preferably) bug tracking software? (a little of topic, sorry)
17:12ole3bugzilla (good?), code.google.com
17:13Lau_of_DKDont know if its good or not, but I'll look into it
17:21mmcgranai guess delay is the way do do it, i just have to find a way to shuttle the Deley instance around.
17:22durkaLau_of_DK: trac has issue tracking as well
17:22Lau_of_DKk thx
17:30blbrownI get this error, http://paste.lisp.org/display/73404 I can't understand why though. What would cause the nullpointer exception
17:36danlarkinblbrown: is there a "setter" for event.styles?
17:36danlarkinseems like you should be using that
17:36danlarkinset! is definitely not what you want to use
17:37blbrowndanlarkin, why not, I am converrting java code to clojure. This is the java code. event.styles = new StyleRange[styles.size()];
17:37blbrowndanlarkin, clojure version: event.styles = new StyleRange[styles.size()];
17:37blbrown (set! (. event styles) (make-array StyleRange 1))))
17:37danlarkinno
17:37danlarkinforget about set!, pretend it doesn't exist
17:38danlarkinit's a special form, it is not for general purpose assignment operations
17:40danlarkinsomething like this makes sense, (.setStyles event (make-array StyleRange 1))
17:41blbrowndanlarkin: does setStyles have to exist for that class LineStylEvent (swt api)
17:41danlarkinyes
17:42blbrowndanlarking there is no setter for 'event.styles'
17:42blbrownis a field with public access
17:43danlarkinoh...
17:44danlarkinhttp://clojure.org/java_interop#toc20
17:44blbrownhmm, is that exactly what I am doing
17:44danlarkinI apologize :-/
17:44rhickeyblbrown: you are sure event is not null?
17:44danlarkinsee this is why I should just be a lurker
17:44danlarkinand stop trying to help :)
17:45blbrownrhickey, event.styles is null ... (set! (. event styles) (make-array StyleRange 0))
17:45blbrownrhickey, this doesn't generate an error the code above
17:46blbrownrhickey, sorry, event is not null, but event.styles is null
17:47LARefugeeare archives of these chats kept somewhere?
17:47rhickeyblbrown: you are certain in the exact context where you get this error event is not null?
17:48hiredmanclojurebot: logs?
17:48clojurebotlogs is http://clojure-log.n01se.net/
17:48LARefugeeTanks!
17:50blbrownrhickey, it isn't pretty, but I am trying something like this. http://paste.lisp.org/display/73404#1
17:51rhickeythis is your real cause: at org.eclipse.swt.custom.StyledTextRenderer.getTextLayout
17:53rhickeywhat's at octane_main.clj:188
17:53rhickey?
17:54blbrownrhickey, sorry about that. I need to continue with the other required code for SWT. http://paste.lisp.org/display/73404#2
17:54blbrownworks not
17:54blbrownnow
17:55ole3Is it possible to give default initargs to a function?
17:56ole3something like keyword arguments in common lisp
17:57AWizzArdindirectly it's possible
17:57ole3?
17:58AWizzArdyou can specify multiple implementations of a function, which differ in the number of their parameters
17:58ole3ah, ok, but when i have many arguments...
17:59ole3maybe a 'arg-list' argument could help
17:59hiredmanuh, I think you can do something like it by passing a hash and doing destructuring
17:59AWizzArdyes, for non-trivial things use a hashmap
17:59AWizzArdthis is a design pattern in Clojure
18:00hiredman,((fn [& x] x) :a :b :c :d)
18:00clojurebot(:a :b :c :d)
18:00ole3i think i got it, thank you
18:00Chousukethere are no lisp style keyword args but with maps and destructuring you can have default values
18:00ChousukeCL style, even :p
18:02ole3,((fn [{foo 123}] foo) {:foo 12})
18:02clojurebotnil
18:03AWizzArdole3: for more trivial cases take a look at the implementation of drop-last for example: http://code.google.com/p/clojure/source/browse/trunk/src/clj/clojure/core.clj
18:03ole3I have to use rest arguments always
18:04AWizzArddrop-last has two implementations, where the first has only one parameter. If you call that it calls itself with two args.
18:05Chousukethe map destructuring stuff is somewhat complicated, I can never remember how it works.
18:06AWizzArdmaybe defn can be improved to have an :optional in the argument vector, which automatically falls back to use a hashmap
18:08hiredman,((fn [{:keys [a b c] :or {c 3}}] c) {:a 1 :b 2})
18:08clojurebot3
18:08hiredmancomplicated
18:11ole3hiredman: perfect, thank you!
18:11ole3((fn [{:keys [port address] :or {port 2500 address "0.0.0.0"}}]
18:11ole3 (list port address))
18:11ole3 {:port 80})
18:11ole3,((fn [{:keys [port address] :or {port 2500 address "0.0.0.0"}}]
18:11ole3 (list port address))
18:11clojurebotEval-in-box threw an exception:EOF while reading
18:11ole3 {:port 80})
18:11ole3ok, compilcated
18:12ole3,((fn [{:keys [port address] :or {port 2500 address "0.0.0.0"}}] (list port address)) {:port 80})
18:12clojurebot(80 "0.0.0.0")
18:12ole3thanks
18:13hiredmanole3: the destructuring stuff is on http://clojure.org/special_forms in the section on let
18:17ole3hiredman: I can think of this like this: every key that is not supplied is nil and the result of the arguments are :ored with the keys of the parameter map.
18:18ole3nice
18:21spooneybargerLau_of_DK: done
18:22Lau_of_DKGood to have you here :)
18:23spooneybargerWe should probably continue our clojure conversation here instead of #emacs, more on topic here
18:23spooneybargerat least until my food arrives
18:24Lau_of_DKWe've just passed midnight here, so would you be okay, if I asked to continue this tomorrow - the bed is calling for me :)
18:25Lau_of_DKBut one of the outstanding features of Clojure is the community, you can get tons of help in here and people are always willing to lend a hand. The author of Clojure rhickey also hangs out in here, so there's always a fair chance of getting some good advice
18:26spooneybargerLau_of_DK: sleep... my more clojure time isnt til a year from now. this year is all about smalltalk for me
18:26spooneybargerLau_of_DK: i pick a language every year or two years to rearrangge my brain, except haskell, i had to cu that short, that just hurt, i need to try that again when i get an intelligence transplant
18:27Lau_of_DKhehe - We're still early in January, you have an opportunity to make a smarter decision here than smalltalk :)
18:27Lau_of_DKAlthough, I like the thought of trying to dive into a new language every year, maybe I'll take that on myself
18:28spooneybargerLau_of_DK: i enjoy smalltalk and for the work I have for a while, it is the right tool for right now. I'm always pushing. always learning, always trying to use the right tool. clojure, great potential, for the stuff for right now, smalltalk is the right tool
18:29Lau_of_DKCool, what are you working on ?
18:30spooneybargerLau_of_DK: e-commerce web app stuff that seaside is just so much the obvious platform for... ok not obvious but i spent 6 months looking at what needs to be solved, what solves these issues and seaside on glass came out the winner across the board.
18:31spooneybargerLau_of_DK: being asked to develop e-commerce web apps that act like a desktop app for that, it was the winning platform
18:32Lau_of_DKCool, will there be something online in Q1 where I can see your work ?
18:33spooneybargerits a port of a ton of code so, not til Q3, need to support existing systems and do the move at the same tim
18:33spooneybargerfoods here... talk more later... you can teach me clojure that i should look at
18:38Lau_of_DKspooneybarger: Alright, Im off to bed. Your first stop should probably be the Clojure source, get comfortable with core.clj, next up is Contrib, lots of interesting code there, and then finally you graduate to ClojureQL on Github :)
18:50ole3Where have i put the comments for defmulti?
18:54ole3there is no docstring for defmulti?
18:55Chousuke(doc defmulti)
18:55clojurebotCreates a new multimethod with the associated dispatch function. If default-dispatch-val is supplied it becomes the default dispatch value of the multimethod, otherwise the default dispatch value is :default.; arglists ([name dispatch-fn] [name dispatch-fn default-val])
18:55Chousukeapparently not
18:55hoeckole3: <Chouser> Guest67527: there's no special support for docstrings in defmulti
18:55hoeck<Chouser> Guest67527: so instead, do: (defmulti #^{:doc "my docstring"} multi
18:55hoeck identity)
18:58ReplRatis anybody else having problems accessing github? what's the pastie for this channel?
19:00hoeckReplRat: yeah, "down for maintenance" and showing a two gallants video
19:00arohnergithub is down
19:01ReplRatwow that sucks.
19:01hoeck(actually my favourite 2gallants song :)
19:01arohnerreally irritating, I want to download clj-backtrace
19:01ole3hoeck: thanks
19:01ReplRatis it acceptable for a site like this to be down for 'maintenance'?
19:01hoeckthanks to chouser for knowing the answer 4hrs ago
19:03hoeckReplRat: mhh, not really, but to be fair its 1am on sunday morning and git is distributed anyway
19:05arohnergithub is headquartered in san francisco, where it's 3pm on a saturday
19:57dreishgithub appears to be up for me. And I think it's actually 4:57 p.m. over there, not 3:57.
20:00ReplRatgithub is up again now. i just cloned compojure
20:14arohnerdreish: yeah, you're right
20:25arohnerin emacs, can I create a key binding that runs a command in slime?
20:32Guest89243(define-key slime-mode-map (kbd "C-c some-key") 'your-function)
20:33Guest93269or slime-repl-mode-map for the repl
20:35arohnerGuest26309: thanks
20:35arohnernow I just need to figure out how to send an arbitrary string to the repl via slime
20:59rhickeyok, more naming fun, need a term to unify sequences and streams - leading contender: series
20:59zakwilsonI like series.
21:08danlarkinchain?
21:08danlarkinkinda lame though
21:08danlarkinseries is better than chain
21:08Chousernot as lame as my first thought. "brook"
21:09rhickeymany cases that now test for seq? will need series? instead
21:20danlarkinprogression?
21:21danlarkinseries leads
21:25Chouserthat's 3 s-words to mean very related things. surely that's bound to confuse someone.
21:28eyerisDoes anyone here use clojureql?
21:35eyerisI'm trying to determine whether or not it has a function to transform select queries to select count(*) queries similar to sql/distinct
21:35eyerisI don't think it does.
21:43eyeris*symbol* being global is simply convention, right? There isn't any syntax support that makes *symbol* global?
21:43Chouserright
21:45Chouserevery 'def' is global
21:49eyerisIs there a function index? The search engine on the website seems to ignore my (type, returning every page that matches type.
21:50danlarkinhttp://clojure.org/api
21:51mfredricksonrhickey: about an "flow"
21:51eyerisHow can I get the type of a variable as a string? Similar to python's type() function
21:52Chouser(class x) returns the Class object for x's type
21:53Chouser(str ...) returns strings for things
21:53Chouser,(str (class 5))
21:53clojurebot"class java.lang.Integer"
21:53eyerisDo all types have a Class?
21:54Chouserwell, there are primitive types
21:54Chouserint, float, double ... but if you pass those to Clojure functions they get upgraded to Integer, Float, Double
21:55eyerisOkay
22:40danlarkinI should be able to swap! an atom from different threads and have changes show up in another thread, right? I'm pretty sure that's how it works but I'm confused as to why some code I have isn't working and I'm making sure my assumptions are correct :)
22:42Chouserdanlarkin: yes, that's correct.
22:42danlarkinright, ok thanks
22:43eyerisHow can I run a .clj file from the cmd line?
22:45eyerisIf I run the repl using the shell to redirect input from the file, the repl closes without giving me a prompt
22:45Chouserjava -cp clojure.jar clojure.lang.Repl myscript.clj
22:48eyerisIs there a cmd to print the loaded namespaces?
22:48danlarkin(doc loaded-libs)
22:48clojurebotReturns a sorted set of symbols naming the currently loaded libs; arglists ([])
22:48eyerisNice
22:49eyerisI see (all-ns) now too.
22:52eyerisjava.lang.ClassCastException: java.lang.String cannot be cast to clojure.lang.IFn
22:52eyerisHow can I tell which line is throwing that exception?
22:54hiredmaneyeris: it is the line when you are try to use a string as a function
22:55eyerisAhh! I Fn not IF n :)
23:08eyerisIs there something special I have to include in my source file in order to use the try form?
23:08eyerisWhen I try I get this error: Caused by: java.lang.Exception: Unable to resolve symbol: catch in this context
23:09hiredmanerm
23:10eyerisOh, nvm
23:10eyerisI had an extra ) before (catch
23:11danlarkinso I'm swap!ing *settings*, which contains an atom... then afterwards I print @*settings* and it has been correctly updated... but then from another thread I deref it and it's empty. I'm confused :(
23:16lisppaste8Chouser pasted "2 threads, 1 atom" at http://paste.lisp.org/display/73411
23:16Chouserdanlarkin: couldn't tell ya -- works ok for me.
23:16danlarkinyeah I was just hoping you'd say, oh I totally had that problem, and it was because I forgot the magical incantation!
23:17Chouserheh
23:17Chouseryou're sure it's the same *settings*? No typo? No binding?
23:18gnuvinceChouser: *Really* bad paste title ;)
23:19ChouserOh. Let pretend it's "1 atom, 2 threads", shall we?
23:19hiredmanoooo
23:20hiredmanmarkov chains in clojure
23:20hiredmanjust what clojurebot needs
23:22LARefugeeclojurebot: book?
23:22clojurebotbook is http://www.pragprog.com/titles/shcloj/programming-clojure
23:22danlarkinChouser: yup, same *settings*, unfortunately it's gotten hard to debug because I'm doing ... WAIT! I figured it out!!!!
23:22danlarkinyessssss!
23:23eyerisI'm new to both the JVM and Lisp. Could someone explain to me why this clojureql code is throwing an exception? http://paste.lisp.org/display/73412
23:23danlarkinChouser: thanks for the inspiration
23:24Chouserdanlarkin: np. I never debug as well as when I'm explaining to someone else why it ought to be working.
23:25danlarkinI'm doing dynamic code reloading, and *settings* was getting redefed, *sigh*
23:25Chouserah. defonce?
23:25danlarkinoh perfect, heh I was just about to write my own
23:26hiredmaneyeris: is sql-stmt a string?
23:26Chousereyeris: clojureql is expecting lisp-like code describing the query.
23:27eyerisAhh! right!
23:29hiredmanclojurebot: markov chain generator is http://groups.google.com/group/clojure-study-dc/browse_frm/thread/026ccdc8acb102f9?pli=1
23:29clojurebotAck. Ack.
23:31banisterfienddanlarkin: walang kekek
23:32danlarkinbanisterfiend: huh?
23:32banisterfienddanlarkin: grasshopper