#clojure logs

2008-11-23

00:59albinoDoes the plus sign in the docs for aset represent varargs?
01:01hiredman(doc aset)
01:01clojurebotSets the value at the index/indices. Works on Java arrays of reference types. Returns val.
01:03hiredmanit must
01:09gnuvince_albino: it's like with regexes; ? is when there's none or one, * when there's none or many and + when there's at least one.
01:12albinouser=> (aset a 0 1 10)
01:12albinojava.lang.IllegalArgumentException: Argument is not an array (NO_SOURCE_FILE:0)
01:12albinoI can't get it to work with more than one index
01:15ChouserI think the multiple indexes is for multi-dimentional arrays.
01:15Chouser(aset a 1 2 10) is like a[1][2] = 10
01:20albinoahhh
01:20albinowe need that in the docs
01:22albinoI thought it was a[1] = 10; a[2] = 10;
01:23Chouseryeah, that's a reasonable guess. And it does appear the actual behavior isn't even hinted at in the docs.
01:24Chouserthat I can find, anyway.
01:26notallamahow can i tell how a sorted set will be sorted?
01:26notallamais there any way to give it a comparator?
02:45albinoDo I need to import things from clojure.core? I figured it would all be imported by default.
02:50danleiFrom (doc ns) If :refer-clojure is not used, a default (refer 'clojure) is used.
04:06Lau_of_DKTop of the morning gents! =)
04:06kotarakHi Lau!
04:20hiredmanclojurebot: Lau_of_DK is <reply>Top of the morning #who!
04:20clojurebotYou don't have to tell me twice.
04:20hiredmanclojurebot: Lau_of_DK?
04:20clojurebotTop of the morning hiredman!
04:21Lau_of_DK:)
04:35tWipwebjure now supports regex patterns on the path... and binding groups
04:40Lau_of_DKwebjure != compojure ?
04:40Lau_of_DK@ tWip
04:40tWipno, they are two different projects
04:40tWipI don't know about compojure
04:40Lau_of_DKYou mean, "Yes, they are two different projects"
04:41Lau_of_DKWhat makes webjure special ?
04:41tWipI think webjure came first
04:41Lau_of_DKoh :)
04:43tWipcompojure seems to have more of a community
04:44Lau_of_DKWhy the fork then. Wouldnt you get more done by merging the two projects?
04:44tWipI don't think they forked
04:51tWipand no, I think exploring different ways to make a web framework for Clojure is useful
04:51tWipmaybe one de-facto will emerge in time, but it's good to have choice
04:53Lau_of_DKtWip: alright
06:19Lau_of_DKSo - Anyone doing anything interesting in Clojure?
06:20kotarakNot in, but for actually. Working on VimClojure improvement. Hmmm.. So interesting maybe depends on the point of view. ;)
06:20Lau_of_DKYes - Im not really into the revival of discarded editors though, but others might find it interesting, so thanks for sharing =)
06:21Lau_of_DKDid you check out Chousers online Repl, kota ?
06:21kotarakThe Browser Repl?
06:21Lau_of_DKyea
06:22kotarakI had a look, but cannot claim, that I understood everything. I'm not that deep in javascript and browser stuff.
06:22Lau_of_DKHe wrote part of it in C, I think you can find the whole thing in contrib
06:23blackdog_awayi wonder why chouser doesn't use an applet with clojure
06:24Lau_of_DKHmm...
06:24Lau_of_DKThats actually a very good question.
06:24Lau_of_DKblackdog, did you ever find a way to wrap JQuery nicely in Clojure?
06:25blackdog_awayi suppose his method is likely to woork 100% with no requierment for jdk installation
06:25blackdog_awayyes, clojurescript works
06:25blackdog_awayi did a one line test, but it can be done
06:25Lau_of_DKChousers own words were that it was not ready for production yet
06:26blackdog_awayi think its a technology in search of an application
06:27Lau_of_DKAs it is, JQuery is so simple to write out in plain javascript, that I'd prefer to have the thing operational beore using it
06:27Lau_of_DKBut maybe thats just me
06:27blackdog_awayagreed, it needs the killer app
06:28blackdog_awayas js is a tad entrenched to beat up on
06:29Lau_of_DKHow do you mean blackdog_away ?
06:30blackdog_awaywell there are too many plus points with js for clojurescript to really be an option
06:30blackdog_awayunless there was a killer app
06:30blackdog_awayanother negative is it needs compiled
06:33Lau_of_DKI agree with the first part. But I dont see how the compilation is any different from anything else that goes out of Clojure
06:33Lau_of_DK@ Big Black Dawg
06:33blackdog_awaywell, compared to js on the client it's a problem
06:33Lau_of_DKSo you mean, that it takes away from the performance we would normally free from the server?
06:35blackdog_no, simply an extra compilation step is not so good for the client i think
06:36blackdog_if you're used to working with gwt etc or java web frameworks it's a no brainer,
06:36blackdog_but for your average web designer type, they don't want another step
06:37blackdog_well i suppose you can argue that flash etc all require extra steps too
06:37blackdog_i guess that's why i don't like any of them :)
06:38Lau_of_DKWeird attitude :)
06:38Lau_of_DKI mean, I agree that we should plan ahead with resources in mind. But this step that youre worrying about is not likely to cause any problems, anywhere?
06:38Lau_of_DKOr am I being short sighted now?
06:39blackdog_well, for example, i was using haxe a lot last year, and it's excellent, great for the web,
06:39blackdog_but really with the advances in js and great debugging
06:39blackdog_it's hard to beat straight js/dom
06:40blackdog_that's really all I'm sayin
06:40blackdog_the point of haxe being it's an extra compilation step too
06:40blackdog_and it just becomes old
06:40Lau_of_DKk
06:40Lau_of_DKYou want the comet?
06:41blackdog_?
06:41Lau_of_DKComet? You work with Comet now right?
06:41blackdog_i wrote a wrapper for the jetty comet chat server in clojure
06:42Lau_of_DKk
06:42blackdog_but that's all, i need to know more about
06:42blackdog_it
06:43Lau_of_DKbtw, BlackDingDawg - Do you know how to set up a standard apache2 server to handle the static pages, and then have it proxy all dynamic pages to a jetty or something like that?
06:44blackdog_not really i use nginx these days to do exactly the same thing
06:45blackdog_but it won't take yo long to goog for mod_proxy
06:45Lau_of_DKIm sure it wont, but I have zero experience, so if you knew how, I'd prefer to hear it from you
06:47blackdog_can't remember of the top of my head
06:59FibIs there any significant difference between ((fn a [seq] (foo seq)) seq) and (fn b [& args] (apply foo args))? Would there ever be a limit on the number of args to a function?
07:01jaanuuu. snowstorm. lights are blinking. i'll better go offline..
07:02timothypratleyb is easier to call?
07:02timothypratleyopps that doesn't answer your question /hides
07:05Fibhehe
07:11FibIt's true (apply b seq) and (b z y x) are very easy while (a `(~z ~y ~x)) is a bit uglier
07:11FibBut if you want to chain serveral operations on a sequence then calling apply each time would be awkward...
07:11kotarakI hope that his is a joke: (a (list x y z))
07:11kotaraks/his/this/
07:12FibAh I see
07:12FibSorry, I am a complete newbie :)
07:12kotarakno problem. I was scared by the quotation usage. :)
07:13kotarakFib: it depends on what you want to do. eg. map gets a collection. (map transform-element some-seq)
07:14kotarak(apply map transform-element some-coll) seems odd.
07:15FibYeah, that's what I was thinking
07:15kotarak(it has an application though: (apply map transform-pair [first-coll second-coll])
07:15FibI was defining a function "average" and wondering if that should take varargs or a sequence
07:17kotarakProbably a seq. Rationale: (defn average "Returns the average of the elements of coll." [coll] (/ (reduce + coll) (count coll)))
07:19kotarakEqually well not a seq: Rationale: + and friends also take variable numbers of arguments...
07:19kotarakHmmm... Don't know. Personal preference maybe�
07:20Fib:)
07:20FibI'm still trying to understand the (apply map transform-pair [col1 col2]) example you gave though
07:21FibIs that any different from (map transform-pair [col1 col2])?
07:21kotarak(map (fn [x] (transform x)) xs) vs. (map (fn [x y] (transform x y)) xs ys)
07:21mehrheitFib: it's the same as (map transform-pair coll1 coll2)
07:21Fibah ok
07:22kotarakFib: it was bad example from my side. Since map actually accepts multiple arguments.
07:23timothypratleyGood question really, I'd be interested in when to use a vs b. At a guess I'd imagine b is good for cases where you generally only have a few arguments, whereas a is good when you want to use larger sequences eg (range 100)?
07:23timothypratleyaverage is a tricky example
07:24timothypratleyI would say it is more likely you want to use it for large sets
07:24timothypratleyso a is more convenient
07:24kotaraktimothypratley: I think it depends on whether you want to work in the collection as an argument or whether the collections the arguments.
07:25kotarakGeez, I'm confused today. Sorry. I don't even understand what I'm trying to say myself...
07:25timothypratleyhahahaa, I agree I'm just trying to figure out how to tell the difference :)
07:25kotarakreduce expects a collection which it transforms into something else.
07:26kotarak+ adds two or more numbers.
07:27kotarakOk. I'm confused. Sorry.
07:27timothypratleyyes... one could quite easily define + as opperating on a collection of 1 or more elements
07:27timothypratleyand vice versa
07:28kotarakI'm looking for a good example.
07:28timothypratleyI think the rational would be that usually people use + with only 1 or two args
07:28kotarakSay struct: (struct foo :a :b :c) creates a new foo map with the given values.
07:28kotarakNow you get [:a :b :c] from somewhere else.
07:29kotarakThen you use apply: (apply struct foo the-vector)
07:30kotarakProviding the values always in a collections, doesn't make sense, because the number is well-defined.
07:31kotarakSomething like that maybe? Would go along your argument about the "usual" call.
07:33tWipshould an empty list be a seq?
07:33tWip(seq? ()) => false
07:33timothypratleySounds reasonable :) Average is tricky because well you do want to take the average of 2 numbers sometimes... othertimes maybe you want to average a large set of data, its hard to say which is more likely... wouldn't it be great if both forms were supported??? but surely that is impossible (and confusing).
07:34kotaraktWip: I think the empty list is Collection not a Seq.
07:35tWipyes, but what is the reasoning behind that?
07:36ChousuketWip: it's an empty list, so as a sequence, it's "nothing". I guess that's why it's not automatically a seq
07:36Chousukeyou can do (seq ()) and get nil
07:36kotaraktWip: a collection is something specific, while a seq is an abstract view on a specific collection
07:38tWipeasy to work around, I still feel it should be a seq
07:39danleihow to do this? (in a non-ugly way) have not looked at multimethods so far
07:39danlei(defn avg ([s] (/ (reduce + s) (count s))) ([x & args] (/ (+ x (reduce + args)) (inc (count args)))))
07:42kotarak(defn avg [x & args] (/ (reduce + x args) (inc (count args))))
07:42kotarakups
07:42kotaraksorry. Forget it. Misread your function.
07:43danleiin cl, i'd specialize on list in the first case (first method of a generic function), a number in the second case. i guess, that could be done with multimethods. i'll have a look at them later.
07:44ChousuketWip: you just need to remember (seq coll) whenever you work with sequences :)
07:46FibIsn't it because () doesn't support (first) and (rest) and thus doesn't match the abstract interface of a sequence?
07:48tWipok, I changed my usage to coll? and calling seq... it's no big deal, just seemed weird at first
07:53timothypratleydanlei: that seems to work great :) thanks. why do you call it ugly?
07:54danleibecause it is so ugly, that only a mother could love it =)
07:54timothypratleyhahahah
07:54danleibut yes, it works
07:54danlei*chuckles
07:58Lau_of_DKdanlei: I must say, you havent convinced me that a mother could actually love it :(
07:59danleiwell, maybe a very benevolent one ;)
08:00danleiyou know how to do it with multimethods? still hadn't the time to check them out
08:00Lau_of_DKoh youre right.. or maybe a blind one, who used to code a little Python way back when :)
08:00danlei=)
08:10timothypratleydanlei: well if you think yours is ugly... wait till you get a load of this:
08:10timothypratley(defn avg [s & nots]
08:10timothypratley (if (seq? s)
08:10timothypratley (apply avg s)
08:10timothypratley (/ (reduce + s nots) (inc (count nots))))
08:10timothypratleythen...
08:10danleiit's alive!
08:11timothypratley(defnaa avg [s] .....) => above
08:11bottleneckanyone know of a guide to a simple webserver
08:11Lau_of_DKbottleneck: To write one, or to use one?
08:11bottleneckwrite
08:11MarkVolkmannWhat is the function that expands a list so that each value can be used as a separated argument to a function?
08:12bottleneckjsut want to do a simple one to see hown they work
08:12Lau_of_DKbottleneck: I think I have a guide for a Jetty/clojure server in about 100 lines or so, want me to dig it up ?
08:12bottleneckyes please, would be awesome
08:12tWipadded basic json support to webjure
08:12blackdog_bottleneck, http://robert.zubek.net/blog/2008/04/26/clojure-web-server/
08:13Lau_of_DKbottleneck: thats the one that blackdog_ posted
08:14danleiMarkVolkmann: you mean apply?
08:14Lau_of_DKtWip: I think somewhere along the way I got JQuery and Json mixed up. What does JSon specifically enable me to do ? I know its serilization, but when will I need it ?
08:14blackdog_your browser reads json natively
08:14tWipmost likely when you call your servlets from javascript code using AJAX
08:14blackdog_it's a subset of javascript
08:15blackdog_jquery is a nice library that helps you select then appy actions to dom elements
08:15tWipand much much more
08:15tWipjquery has some very nice UI plugins
08:15Lau_of_DKJQuery is my weapon of choice, when I want to move formatting operations and such, away from the server and onto the client, as I see it
08:15blackdog_still a bit limited in the UI package
08:16Lau_of_DKAm I to take it, that JSon is the format in which I pass my data to JQuery ?
08:16blackdog_no official grid yet
08:16blackdog_yes
08:16Lau_of_DKk, thanks
08:16blackdog_there's a $.getJSON method
08:18Lau_of_DKIt confused me a bit blackdog_ when you were explaining your servlet approach to me. You said "This way, I dont need Jetty", and then you sent me an example using Jetty =)
08:18blackdog_i don't need to, but i do, could be any server, jetty is very convenient
08:18blackdog_the point is the client is not tied to a jsp/asp or php
08:19blackdog_why tie yourself to a server framework when you can tempalte on the client?
08:20Lau_of_DKTo get cool t-shirts from Microsoft?
08:21bottleneckLau_of_DK: thanks!
08:24Lau_of_DKno probs
08:42MarkVolkmannSuppose foo is the list (1 2 3) and I want to pass the items in it as individual arguments to a function. What expands a list like that? (my-function (??? my-list))
08:43rhickeyMarkVolkmann: (apply + foo)
08:43danlei(apply my-function my-list)
08:43MarkVolkmannThanks!
08:44danleiwtf
08:44danleiwhy does cond return nil?
08:45rhickeydanlei: tradition, a la one-branch if
08:45danleihm
08:46danleiwhat should i use instead? nested ifs?
08:47Chousukewhat kind of code?
08:47rhickeydanlei: for what purpose? cond only returns nil if no condition matches
08:47danleithe cond kind of code
08:47danleiwait a sec
08:48danlei(cond [true 1]) -> nil
08:48danleii'm used to cl: (cond (t 1)) 1
08:49danleinot a problem, just /very/ surprising to me
08:50danleior do i miss something?
08:50Chousukecond doesn't take a vector.
08:50Chousuke(cond true 1) -> 1
08:51danleioh my
08:51danleinow, that's embarassing =)
08:51danleithank you
08:56MarkVolkmannTo get the metadata for a function, say str, I enter (meta #'str). What do the # and single-quote do in this context?
08:58Chousukethat returns var named by str
08:58rhickeyMarkVolkmann: #' is a reader macro. When read, #'x reads as the form (var x)
09:00MarkVolkmannThanks! I need to go read more about vars.
09:06danleiok, now that i know about cond ... ;) how would i dispatch on type, i.e. if something is/are a number/numbers, or a collection?
09:06danleii tried like this:
09:06lisppaste8danlei pasted "avg" at http://paste.lisp.org/display/70915
09:06danleiworks. is that the way to do it?
09:07danlei(first multimethod so far)
09:08danlei... at least, it's not as ugly, as the other one ;)
09:10fandahello!
09:10fandaquestion about fn?
09:10Lau_of_DKHey fanda
09:10Lau_of_DKshoot
09:10fanda(def x 5) => #'user/x
09:10fanda(var x) => #'user/x
09:10fanda(fn? (var x)) => true
09:10fandatrue or false?
09:11duck1123should be
09:11fandawhy is var a function?
09:13rhickeyfanda: why are all vars functions?
09:13rhickeyvar is a special form
09:14rhickeyvars are functions because it is useful for them to be so - they all implement the IFn interface in terms of a call to their value, which must in turn be a fn
09:14Lau_of_DKGuys, simple question (I hope)
09:14Lau_of_DK(defmacro onClick [obj & body] `(. ~obj addMouseListener (proxy [MouseListener] [] (~'mouseClicked [evt#] ~@body))))
09:15Lau_of_DKWhy does this not work in a JPanel which implements addMouseListener?
09:15Lau_of_DKs/in/on
09:15fandathanks rhickey! that makes sense. just double checking tests for Clojure predicates
09:17rhickeyfanda: Imagine you had some global fn foo, if you passed foo to (hang-onto-this foo), you would be passing the current value of foo. If you later fixed foo, hang-onto-this wouldn't see the change. If instead you passed (hang-onto-this #'foo) then it would. In either case it could 'call' what it was passed
09:18rhickeyLau_of_DK: I'm on a mission - no one should ask a macro question by posting only the source of the macro - please post an invocation and actual and/or expected expansions
09:19rhickeyand please paste
09:19Lau_of_DKAlright Rich Norris, I'll get right on it
09:22rhickeyChuck Norris doesn't say please
09:22ChouserI was thinking the other day of a "macro help request" form with separate sections for each.
09:23rhickeyChouser: great idea!
09:23duck1123is there an easy way to add metadata to a file? It's looking like we might need a way to store things about files (ie. filename, author, license) as clojure data
09:23Lau_of_DKChouser: does Rich actually sponsor you ? :)
09:23rhickeyduck1123: files are not first-class constructs in Clojure, but namespace metadata has been requested
09:24lisppaste8Lau_of_DK pasted "mouseListener" at http://paste.lisp.org/display/70916
09:25mmcgranaHey Rich, very sorry about the clj-doc license issue, I'm working on it right now.
09:25rhickeymmcgrana: np
09:25duck1123that was why I bring it up
09:26rhickeymmcgrana: I'm sorry I didn't get to look at it sooner - very neat
09:26duck1123what if clj-doc indexes non-clojure core code, it'd have a different license
09:27mmcgranarhickey: thanks
09:27mmcgranahopefully I'll have it set up on a proper server at a permanent URL for 1.0
09:28mmcgranaduck1123: perhaps if i do the license notice per-function, like under the source code.
09:29rhickeyLau_of_DK: please try macroexpand-1 on your macro before pasting
09:29Lau_of_DKrhickey: macroexpand-1 is basically what you see in the bottom of the paste
09:29duck1123mmcgrana: have you thought any about using iframes? As much as I hate them, they make it easy to see code and function list seperately
09:30rhickeyi.e. paste real code you have tried, rather than having others try for the first time
09:30lisppaste8Lau_of_DK annotated #70916 with "macroexpand-1" at http://paste.lisp.org/display/70916#1
09:30rhickeyuser=> (macroexpand-1 '(onclick panel (javax.swing.JOptionPane/showMessageDialog nil "Clicked")))
09:30rhickey(onclick panel (javax.swing.JOptionPane/showMessageDialog nil "Clicked"))
09:31Lau_of_DKrhickey: Ive tried this code, and variations on it for quite some time
09:31Lau_of_DKYour error is just because C is lowercase in on_C_lick
09:31Lau_of_DKIt was just meant as an example to understand what I was aiming for
09:32mmcgranaI was thinking something like this http://skitch.com/mmcgrana/hqgn/clj-doc-clojure-library-documentation.
09:33mmcgranaAny ideas on how to disambiguate the text: i.e. what software its referring to exactly, which files, etc.
09:33philHey all. How do I create a new var without interning it?
09:34Chouser(doc with-local-vars)
09:34clojurebotvarbinding=> symbol init-expr Executes the exprs in a context in which the symbols are bound to vars with per-thread bindings to the init-exprs. The symbols refer to the var objects themselves, and must be accessed with var-get and var-set
09:34philGreat, cheers.
09:35rhickeyLau_of_DK: and I wasted my time trying to get it to work, it's simple courtesy to make a decent try yourself first and paste only code you have run
09:36Lau_of_DKrhickey: Im sorry about the typo, but like I said, I've tried this code several times in several variations.
09:37rhickeymmcgrana: looks fine. I think you could 'attach' the notice to the corresponding code by putting it in the same box
09:38mmcgranaok good idea
09:38rhickeymmcgrana: but in this case, the notice applies to the doc as well
09:39rhickeymmcgrana: so what you have is fine
09:41danleiok, another cl/clojure question: in cl, if a symbol is read, it gets interned in the package you're in. then it may e.g. be bound to a special (symbol-value slot). i have read that clojure differs here, and symbols don't get interned, but vars do, and that symbols are only names, or somehting. could someone just quickly name the main differences between symbols/vars in cl and clojure and the consequences?
09:42phildanlei: Symbols are interned in a namespace which is a mapping from those symbols to vars. Vars in turn are bound to other values.
09:42danleiso symbols /are/ interned, when they're read, like in cl?
09:42danleibut don't have a value-slot, but are ... "names"(?) for vars?
09:48rhickeyphil: not quite, symbols are not interned in namespaces inherently
09:48danleirhickey: does it boil down to "symbols are just names"?
09:48rhickey(identical? (symbol "foo") (symbol "foo"))
09:48rhickeyfalse
09:49rhickeysymbols are just names, but with faster equality than strings
09:49danleiah, ok
09:50rhickeybecause symbols' names are interned strings
09:50rhickeybut the symbols themselves aren't interned, so they can support metadata
09:51rhickeyvars are much more like CL's symbols, but still not identical
09:52danleiif i do (resolve 'x), for example
09:52rhickeyvars are (normally) interned in a namespace, are named by a symbol in that namespace, have root value bindings and can be thread-locally bound
09:52danleii get a var back, if it's def'ed
09:53rhickeydanlei: right, and that resolution happens at compile time, not read time - the reader reads symbols
09:54danleirhickey: ok. i think it's clearer now
09:54rhickeybut symbols can name other things, like classes, too
09:54rhickeyuser=> (resolve 'String)
09:54rhickeyjava.lang.String
09:55danleiok
09:56danleiand i can't resolve that symbol, because resolve works on vars, and the argument to resolve would be the symbol which names it, right?
09:56danlei(which names the var)
10:02danleiah, ok. i actually /can/ resolve it, since returns the var /or/ class.
10:09mmcgrananew docs w/ license notice are uploaded: http://clj-doc.s3.amazonaws.com/tmp/doc-1116/index.html
10:09MarkVolkmannI recently ran across function definitions like this. (defn- -foo ...) I understand that defines a non-public function. Is the fact that the name of the function starts with a dash a convention for private functions or a requirement?
10:10kotarak-foo is a method for the class defined by the namespace.
10:10kotarakdefn- says it's private.
10:10kotarakas a clojure function, I mean.
10:11MarkVolkmannIt looks like I don't have to start the number of the function with a dash though. It must be a convention to do so.
10:12kotarak?? "number of the function"?
10:15Lau_of_DKkotarak: I think he means "name of the function"
10:15Lau_of_DKWe just have to hope Rich doesnt catch him makings typos like that, you know how he gets :)
10:16kotarakOh. If I remember correctly, for the new AOT gen-class one has to start the method names with a dash. For private function this is not necessary.
10:17rhickeymmcgrana: sorry, I missed the lack of copyright notice - text should start with: Copyright (c) Rich Hickey. All rights reserved.
10:17MarkVolkmannRight, I meant name, not number.
10:18mmcgranaok np
10:18rhickeyMarkVolkmann: right -name is the name to which an AOT generated class method will be bound
10:19MarkVolkmannIf I change the default namespace using (ns my-ns), is there an easier way to pop back to the previous default namespace than something like (ns user)?
10:20Lau_of_DKrhickey: Are you the one who updates ants.clj when something new happend to Clojure?
10:20rhickeyMarkVolkmann: you should only use ns for namespace definition, use in-ns to change namespaces, and no, there isn't 'back' function for namespaces
10:20rhickeyLau_of_DK: yes
10:21Lau_of_DKrhickey: I didnt really understand the latest change where (send-off *agent* self) becomes (send-off *agent* #'self). Can you explain that for me?
10:22MarkVolkmannI tried defining a private function with a name that didn't start with a dash and it worked as expected. I couldn't use the function from another namespace. That's why it seems to me that starting the function name with a dash is just a convention.
10:22kotarakMarkVolkmann: a name with a dash has nothing to do with private functions.
10:22rhickeyMarkVolkmann: name starting with dash is completely unrelated to defn- and private
10:23kotarakdefn- defines a private function.
10:23kotarakdefn -foo defines the method foo for some class
10:23kotarak(.foo x) translates to the function -foo
10:24MarkVolkmannIs (defn -foo) a way to add a method to an existing Java class?
10:24MarkVolkmannHow does it know which class I want to add to?
10:25kotarakMarkVolkmann: no monkey patching here, you have to derive (ns my.fancy.Class (:gen-class :extends this.other.Class) (defn -methodToOverride ....))
10:25rhickeyMarkVolkmann: With AOT compilation, each namespace becomes a class. You can declare with a :gen-class clause in ns the superclass and interfaces that class extends/implements
10:26rhickeythen define the overidden or declared methods by defn-ing -methodName functions
10:26mmcgranarhickey: like this? http://skitch.com/mmcgrana/hqe8/clj-doc-clojure-library-documentation
10:26rhickeyas kotarak said, no monkeypatching
10:27rhickeymmcgrana: great, thanks
10:29MarkVolkmannIt's tough to tell from the documentation why I should prefer (in-ns my-ns) over (ns my-ns) when I just want to change the default namespace. The both say they create it if it doesn't exist.
10:30mmcgranarhickey: np, thanks for your help
10:30danleiMarkVolkmann: i think, ns is more to create a namespace, e.g. at the top of your file, while in-ns is more for changing the current ns, creating it being just a convenience
10:31rhickeydanlei: right, I think the point is it's not clear
10:31rhickeyI'm thinking of renaming ns to defnamespace
10:32danleimaybe defns? but that would probably be to close to defn
10:32MarkVolkmannI'd suggest defns to keep it similar in length to other functions and using "ns" like other functions.
10:32rhickeydanlei: we've discussed defns before, looks like plural defn
10:33rhickeyI'd be fine with it, but that's the objection
10:33kotarakOh please. Not the defns/defnamespace whatever disscusion. rhickey, please use simply defnamespace it's clear and one doesn't type it too often...
10:33mmcgranais it bad style to use ns multiple times for the same namespace? For example, if the ns is defined over several files and there are java imports for each of the different files?
10:34rhickeykotarak: right, the other advantage is it is long, so less likely a target for use in repl
10:34MarkVolkmannMaybe def-ns.
10:34danleiwell, i think, whatever it'll be named like, a "def" in front of it would be a good idea
10:34rhickeymmcgrana: yes, that's bad, use ns once in the file named for the namespace and in-ns in the others
10:35rhickeymmcgrana: because you don't actually get per-file imports anyway
10:35mmcgranaok
10:35rhickeyimport imports into namespace
10:35mmcgranaright, i just meant to declare the import close to where they are used, so that its easier to know when I need to add/remove imports.
10:36mmcgranabut all the imports should just actually be declared at the one spot (ns is used for a namespace?
10:37rhickeymmcgrana: yes, so it documents the sources of names in the namespace, else one file will presume it can use a name another introduces in an import
10:38danleibtw. is there a way to un- use/refer a package?
10:38danleiaehm
10:38danleinamespace ;)
10:39mmcgranaok
10:39Lau_of_DKrhickey: Did you catch my last question?
10:39rhickeyuse/refer isn't a link, it pulls current vars in. There is ns-unmap
10:39rhickeyLau_of_DK: you can ignore the #', it doesn't matter anymore
10:40Lau_of_DKk, thx
10:40danleirhickey: yes, i meant something like ns-unap for everything i refer'ed from another ns
10:40danlei*unmap
10:40rhickeydanlei: not yet
10:40danleirhickey: ok, thanks
10:44Lau_of_DKuser> tst
10:44Lau_of_DK[{:b 4, :a 1} {:b 5, :a 2} {:b 6, :a 3}]
10:45Lau_of_DKIf I want to grab the entry where b = 5. How do I do that idiomatically? (word?)
10:45bottlenecki have 2 maps with {word: count} pairs, i want to merge them. some words occur in both and then i want to do word: count1 / (count1 + count2)
10:46rhickey(doc merge-with)
10:46clojurebotReturns a map that consists of the rest of the maps conj-ed onto the first. If a key occurs in more than one map, the mapping(s) from the latter (left-to-right) will be combined with the mapping in the result by calling (f val-in-result val-in-latter).
10:46bottleneckso 4 / (4+0) or 7 / (7+12)
10:47rhickeyhmmm, clojurebot should do the arglists as well
10:48rhickeybottleneck: merge-with takes a function that will be used to combine entries
10:48bottleneckah nice
10:48bottleneckhow do i force float-division?
10:49rhickeybottleneck: use floats
10:49rhickeyor cast with (float ...)
10:49rhickeyor (double ...)
10:50Lau_of_DKAnybody got a take on that?
10:50bottleneck(defn assoc-inc [m k v]
10:50bottleneck (if (contains? m k)
10:50bottleneck (assoc m k (+ v (get m k)))
10:50bottleneck (assoc m k v)))
10:50rhickeyLau_of_DK: filter
10:51bottleneckis there a built-in way fo doing that?
10:51bottleneck(assoc-inc {1 2 3 4} 1 3) -> {1 5 3 4}
10:51Lau_of_DKthanks rhickey
10:52rhickey(assoc m k (+ (m k 0) v))
10:52rhickeygets rid of the if
10:54rhickeymore generally, you'd want assoc-with a la merge-with
10:54bottlenecki dont get it
10:54rhickeybottleneck: (m k 0) == (get m k 0), that extra arg at end is default return if not found
10:56bottleneckok
10:57danleiis there a way (without use of regexes) to get the namespace of a symbol out of the return value of resolve? like: (symbol-ns (resolve 'sym)) -> my-ns
10:58mmcgranaits in the metadata
10:58mmcgrana(:ns ^#'filter)
10:59danleiah, ok
10:59danleimmcgrana: thanks
10:59mmcgranaor: (:ns (meta (resolve 'filter)))
10:59mmcgrananp
11:02notallamathis is weird. i made a prime number function, and it gets up to 46337 and then says "java.lang.RuntimeException: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long (NO_SOURCE_FILE:0)"
11:03notallama< and > don't work with longs?
11:03notallamaor =?
11:05bottleneckrhickey: can i merge-with with default?
11:05bottleneck(merge-with #(/ (float %1) (+ %1 %2)) {"you" 10 "are" 5 "sick" 1} {"you" 2 "no" 12})
11:05bottleneck{"no" 12, "are" 5, "sick" 1, "you" 0.8333333}
11:06bottlenecki want then for sick to be 1 / (1+0) -> 1
11:06bottleneckwhich it ebcome sby luck
11:06bottleneckwait
11:06bottleneck"are" should be 1 instead if 5 in the emrged map
11:30danleiok, first try for unrefer. not really tested, but seems to work:
11:30lisppaste8danlei pasted "unrefer" at http://paste.lisp.org/display/70917
11:32danleimaybe i should take the ns as an argument too, but then, its more for interactive use
11:56AWizzArdHow can one compile .clj files? Something like (compile-file ...)
11:59bottleneckif i want to map over a hash-map, is (for [x Map]...) the onyl way, ic ant use map?
11:59Chousuke(map fn (vals yourmap))
12:00rhickeybottleneck: you can use map, the mapping function will be passed map entries, which you can destructure with [k v] or use (key e) (val e)
12:00AWizzArd(map #(println %) {:a 10 :b 20})
12:01rhickeyAWizzArd: map with side effects is not a good example
12:01AWizzArdit just produces a very strange result for me
12:01Chousukeworks for me, in the repl
12:01AWizzArdit produces ([:b 20]\nnil [:a 10]\n nil) where \n is a newline
12:02ChousukeAWizzArd: that's just the repl not being quite synchronised
12:02rhickeymap is a function, it returns a sequence of the return values, which for println are nil
12:02AWizzArdI am using the newest clojure.jar and also just checked out a fresh swank-cloujre
12:02Chousukethe return value is (nil nil) but it prints the vectors too
12:02rhickeyif you care about the returns fine, if you just want side effects use doseq
12:02AWizzArdrhickey: sure.. but it should produce a different result
12:03ChousukeAWizzArd: it produces the correct result
12:03ChousukeAWizzArd: it just prints weird.
12:03ChousukeAWizzArd: if you want to foce it to print correctly, you need to use doall
12:03AWizzArdI will post a screenshot, one sec
12:03Chousukeforce*
12:04rhickeyit doesn't print weird, you've mapped a function with side effects, it returns a lazy seq and those effects are delayed
12:04rhickeyAWizzArd: we know what you are seeing
12:05ChousukeAWizzArd: whenever you use a 'map with side-effects, you must remember to use 'doall or 'dorun. otherwise the results may be not what you want
12:05lisppaste8danlei annotated #70917 with "takes ns as argument, too" at http://paste.lisp.org/display/70917#1
12:05rhickeymap is lazy, so the values aren't produced until needed, they are needed to print the result in the repl, thus the interleave of print result val, side-effect, print result, side-effect
12:06AWizzArdso this problem is maybe in emacs, displaying it in a wrong color?
12:07rhickeybottleneck: (map (fn [[k v]] [v k]) {:a 1 :b 2 :c 3})
12:07rhickey([2 :b] [3 :c] [1 :a])
12:08AWizzArdHow can one compile .clj files? Something like (compile-file ...)
12:08rhickeyuser=> (map val {:a 1 :b 2 :c 3}) ;same as vals
12:08rhickey(2 3 1)
12:08rhickeyAWizzArd: you can compile namespaces with (compile 'my.ns.lib)
12:09rhickeythe class files will be put in *compile-path*, and both the source root and *compile-path* must be in the classpath
12:09AWizzArdoki thx
12:11danleidoes anybody see anything suspicious in unrefer? if not, i'll add it to my toolbox
12:15rhickeydanlei: a few things, first, you are getting map entries which you should treat as such - first and frest are suspect, use key/val etc. Second, you should do find-ns once in a let
12:17danleirhickey: ok, thanks. i understand the key/val issue, but why should i do find-ns in a let, if it's called only once?
12:19rhickeydanlei: it's not called only once, but every step of the filter
12:19danleirhickey: ah, stupid me. sure
12:20notallamai posted about my prime number sieve problem. i found the issue, but it turns out that sorted-set doesn't make a nice priority queue due to lack of custom comparator. any ideas for a way around this?
12:25lisppaste8danlei annotated #70917 with "destupidized version" at http://paste.lisp.org/display/70917#2
12:25lisppaste8bottleneck pasted "merge-maps problem" at http://paste.lisp.org/display/70919
12:25bottleneck^^ why does it return {}, i suppose im not handling let correctly
12:27bottleneck(defstruct word :ham :spam)
12:28rhickeybottleneck: how about a doc string? - would help us know what the function is trying to do
12:29rhickeydanlei: you need to lift find-ns, not ns-map/mappings, which only happens once
12:30danleirhickey: wtf ... i think i need some sleep. thanks
12:33lisppaste8bottleneck annotated #70919 with "example" at http://paste.lisp.org/display/70919#1
12:33AWizzArdhttp://clojure.googlegroups.com/web/http-client.clj makes use of gen-and-load-class. I think this exists no longer. Is genclass the new replacement?
12:34AWizzArdgen-class
12:34rhickeybottleneck: did you look at merge-with?
12:34lisppaste8bottle annotated #70919 with "asa" at http://paste.lisp.org/display/70919#2
12:34bottleneckmerge-with: yes but i didnt get how to handle the caes where one isnt in the other
12:36lisppaste8bottle annotated #70919 with "dsdsd" at http://paste.lisp.org/display/70919#3
12:36rhickeybottleneck: you have to remember that the data structures are immutable, and that map/assoc etc return new values that you have to keep track of, they don't work by side effects
12:37lisppaste8danlei annotated #70917 with "schwere geburt" at http://paste.lisp.org/display/70917#3
12:37danleii think i'll get some coffee ... start feeling stupid :) thanks for the tips
12:38bottleneckso reduce instead of map
12:41hiredmanAWizzArd: it uses gen and load for ssl stuff
12:42hiredmanI would recommend grabbing xlightweb and driving that with clojure
12:42AWizzArdoh oki, never heard of that before. Let me see...
12:43AWizzArdBtw, is there a java tool that allows me to operate firefox? I would like to do some automatic testing of a website, and it would cool to have something as close to a real browser as it can get.
12:43hiredmansomeone else here recommended it to me
12:44AWizzArdWith running JavaScript and such
12:47lisppaste8asasa annotated #70919 with "dsfd" at http://paste.lisp.org/display/70919#4
12:47bottleneckrhickey ^^
12:55Chouserah, shoot. paste.lisp.org actually does do a little something with its captcha.
12:57Aisling9
12:58dthomasChouser: Thanks for printStackTrace last night, BTW. Didn't really solve my most hated problem, which is stack traces when working in SLIME being light on details, but it got me past the exception I was working on at the time.
13:00danleiomg ... another creation, only a mother could love. any ideas why my donut is so ugly?
13:00lisppaste8danlei pasted "ugly donut" at http://paste.lisp.org/display/70920
13:02dthomasSide SLIME/swank-clojure question: is slime-eval-defun supposed to eval in the NS appropriate NS for that point in the buffer? If my REPL is in "user" but the buffer starts with (ns some.package), eval-defun fails because (I'm guessing) it tries the defun in "user" (the REPL's NS).
13:04Chousukedthomas: I think that's intended behaviour.
13:05Chousukethere is only one instance of clojure after all.
13:05dthomasYeah, I seem to recall it worked this way when using SLIME with, say, SBCL.
13:05dthomasDoes slime-eval-defun (C-M-x) eval in the correct Clojure namespace for others?
13:06dthomasActually, I just realized that if I change the slime-repl's namespace to my.namespace first, it doesn't help: it still can't find some of the Java classes I've imported.
13:07Chousukethe repl namespace should be the same as in your other buffers, as long as you've evaled the ns setup expressions :/
13:07Lau_of_DKGood evening gents!
13:08danleihere is the page, i transcribed it from, no idea why mine looks so ugly: http://www.zetcode.com/tutorials/javagamestutorial/basics/
13:09Chousukedthomas: at least for me, evaling import statements in a buffer also makes them available in the repl.
13:10dthomasChousuke: I can eval the whole buffer, (ns) form included, and it works fine. I can see the NS in the REPL, just as it should be.
13:11dthomasChousuke: But trying to evaluate with slime-eval-defun then fails to find classes that are imported in that NS, which makes me think it's evaluating in a different namespace than the one in the (ns) form at the top of the buffer.
13:12bottleneckhttp://paste.lisp.org/display/70919#4
13:12bottlenecknoone can help
13:13bottleneckiff reduceing over a map cant i use when?
13:13bottlenecki have to use if-else
13:13bottleneckif i have a cond
13:13bottleneck?
13:13Lau_of_DKrhickey: I was wondering about the STM. As I recall you once made the argument, that locking gives terrible performance. What the difference between user locks, and the STM locks, dont they drag down performance as well ?
13:15bottleneckyes now it works
13:17bottleneckso this ia annoying
13:17rhickeyLau_of_DK: I never said locking gives poor performance, I may have said coarse-grained locks do
13:17bottleneckthen i have to filter out afterwards
13:17Lau_of_DKrhickey: right, that might actually have been it
13:27danleii'm googling for a java lib that lets me display notes, nothing fancy, i only just one system which i can put notes on. any tips?
13:28danlei*only need
13:29danlei(by notes, i mean musical notation)
13:30Lau_of_DKhttp://www.softsynth.com/links/java_music.html
13:31danleiLau_of_DK: thanks, already plowing through ;)
13:34danleiLau_of_DK: they all look kinda overkill to me ...
13:35lisppaste8Lau_of_DK pasted "Refs vs. Agents!" at http://paste.lisp.org/display/70921
13:36Lau_of_DKCould somebody please lend a hand with this. I think I might be misunderstand send-off. Youre supposed to identify a single pixel in the swarm my its id, so (get-pixel 1) returns the first with :id 1.
13:36Lau_of_DKSo my idea was, that the agents state, would simply be this id.
13:36Lau_of_DKBut something is not working, since they get corrupted after the first cycle
13:37Chouserevery action you send to the agent needs to return their new state
13:37Chouserif you don't want the state to change, you need to return the old state
13:37dthomasOK, nevermind my SLIME problems, it seems that CVS SLIME within the past couple weeks must have fixed my problem.
13:38Lau_of_DKWhich I believe the last 'a' in (behave) accomplishes, right Chouser?
13:40danleiah, abc4j looks interesting
13:41ChouserLau_of_DK: oh, sorry, didn't notice the paste. Did you try to list the errors the agent has?
13:42Lau_of_DKThe error is "Agent has errors NO SOURCE"
13:42Lau_of_DKCan I get more than that?
13:44Lau_of_DKGot it working Chouser
13:45Lau_of_DKI couldnt get a more precise error, but I could strip the body, and rebuild it bit by bit
13:45Lau_of_DKthe @ can be a bit confusing when nested
13:57powr-tochey
13:57Lau_of_DKyo
13:57powr-tocIs there a reason why (+) returns 0 but (*) returns 1?
13:57notallamathey return the identity.
13:58kotarakbecause 0 is the neutral element for +, and 1 for *
13:58powr-tocahh, makes sense
14:00thearthurcan i get a functions name?
14:00thearthurif somone passes a fun can i print its name?
14:01kotarakthearthur: functions don't have names.
14:01kotarak(fn [] :xxx)
14:01kotarakNo name.
14:02thearthursome of them do
14:02thearthurif they where defined with defn no?
14:02kotarakNo. There are names refering to functions. But the functions itself doesn't have a name.
14:05powr-tocWhere is the doc function defined?
14:06kotarakpowr-toc: in clojure.core namespace
14:06kotarakpowr-toc: src/clj/clojure/core.clj
14:06powr-tocI have it in boot.clj
14:06kotarakOk. That's all possible for pre rev1094 version.
14:07kotarakWith revision 1094, the file was renamed.
14:09powr-tocahh
14:09powr-tocIs there any idea on how long until 1.0 is expected?
14:13Lau_of_DKIs there anyway of testing the effectiveness of the STM in a given program of mine? Can the Javaprofilers help et?
14:13Lau_of_DKetc?
14:24AWizzArdHow can one load/make use of downloaded .jar files?
14:25lisppaste8bottleneck pasted "bayesian spamfilter" at http://paste.lisp.org/display/70929
14:26kotarakAWizzArd: download .jar; export CLASSPATH=$CLASSPATH:file.jar; have fun :)
14:26bottleneck^^ 4 functions to make a spamfilter, nice! however im sure i can make it more elegant, merge-maps should be a lot shorter and clearer
14:27danleiAWizzArd: you can check your classpath from the repl with: (System/getProperty "java.class.path")
14:27AWizzArdah gut
14:27danleikeine ursache
14:31bottleneckja bitte und guten tag
14:32bottleneckno opinions ony my spamfilter?
14:33AWizzArdI can add anything to the environment variable CLASSPATH under Windows Vista, this (System/getProperty "java.class.path") always returns "clojure.jar". That does not sound right, right?
14:35danleiAWizzArd: for me it's: "/home/danlei/build/clojure/trunk/target/clojure-lang-1.0-SNAPSHOT.jar:/home/danlei..."
14:36Lau_of_DKCan somebody tell me how this is done in these terrible AOT times: http://rpdillon.googlepages.com/creatingexecutablejarswithclojure
14:36danleiAWizzArd: i've heard, that the classpath environ variable is not used, when a classpath is given via -cp, but i'm not sure about it. try adding it with (add-classpath "file:///C:/path/to/file.jar")
14:37danleiAWizzArd: if you're running slime, add the path to swank-clojure-extra-classpaths
14:41lisppaste8kotarak pasted "rescue for Lau" at http://paste.lisp.org/display/70930
14:42Lau_of_DKuuuuh
14:42Lau_of_DKThanks alot Mr. Kota - You saved the day
14:42kotarakLau_of_DK: np :)
14:48Lau_of_DKbut Mr. Kota..
14:48Lau_of_DKThis effectively means, that I must rename ALL my functions to my namespace :|
14:50kotarak?? Do you mean the new -form?
14:50Lau_of_DKoh...
14:50Lau_of_DKI started with (ns 'lbj.core.Langdon)
14:51kotarakwithout ': (ns lbj.core.Langdon)
14:51Lau_of_DKso I figured everything must be (defn lbj.core.Langdon-func)
14:51Lau_of_DKyea
14:51Lau_of_DKmistake
14:51kotarakNo. In this namespace simply (defn -foo ..) (defn -bar ...)
14:51Lau_of_DKk
14:51kotarakThe Classname is not needed anymore.
14:56Lau_of_DKSo basically, every single variable, function, constant, whatever, in every single problem I write, must be prefixed with -, for the reader to understand that its in the same ns ?
14:56kotarakNo.
14:57kotarak-foo in namespace foo.bar.Baz is the method foo of class foo.bar.Baz as in (.foo (new foo.bar.Baz))
14:58bottleneck1. is there some database stuff shipping with Clojure or what is the easiest way to set up and use a database? 2. is there a lib that lets me start mp3s ?
15:01Lau_of_DKkotarak: thats basically the same thing
15:02Lau_of_DKeverything in that namespace must be prefixed with -
15:02kotarakIf everything is a method then yes. "Normal" functions, don't have to be prefixed.
15:02albinobottleneck: use JDBC and do the java thing as far as databases are concerned
15:03kotarak(ns foo.bar.Baz (:gen-class ...)) (defn bar [x] (+ x 2)) (defn -foo [a-number] (bar a-number))
15:03Lau_of_DKkotarak: Explain the difference between method and function please
15:04kotarakA method is part of the class as in (.methodName clase-instance). A function is a "normal" Clojure function.
15:04kotaraks/clase/class/
15:04Lau_of_DKk
15:07notallamaare methods java mathods? like, if i compile with a fn called -bar, can i go into java, import it, and say "foo.bar()"?
15:08kotaraknotallama: you have to declare a class with :gen-class. There you can specify, that your class has a method bar and then you can basically do that. Yes.
15:11notallamaawesome. i'm going to have to figure out how this works.
15:11kotarak(doc require)
15:11clojurebotLoads libs, skipping any that are already loaded. Each argument is either a libspec that identifies a lib, a prefix list that identifies multiple libs whose names share a common prefix, or a flag that modifies how all the identified libs are loaded. Use :require in the ns macro in preference to calling this directly. Libs A 'lib' is a named set of resources in classpath whose contents define a library of
15:12kotarakupsala.
15:12kotaraknotallama: you might be interested in [doc gen-class] with (). (Don't what clojurebot does. It's a bit long...)
15:15lisppaste8Chouser pasted "my test macro" at http://paste.lisp.org/display/70931
15:16Chouserclojurebot: macro help is http://clojure-log.n01se.net/macro.html
15:16clojurebotAck. Ack.
15:16Chouserclojurebot: macro help?
15:16clojurebotmacro help is http://clojure-log.n01se.net/macro.html
15:18kotarakChouser: *thumbs up*
15:19rhickeyChouser: awesome!
15:20Chousercheap hack, actually, but anyway...
15:20Chouseryou have to fill out the captcha *after* you submit the form -- an extra step.
15:21kotarakChouser: the right way: poka-yoke
15:23Chouser:-)
15:29bottleneck1. is there some database stuff shipping with Clojure or what is the easiest way to set up and use a database? 2. is there a lib that lets me start mp3s ?
15:30Chouser1. Java comes with JDBC. There is also clojure.contrib.sql
15:30Chouser2. I think Java comes with audio playback libs.
15:35bottleneckjdbc? i want something that abstracts away all the annoying sql syntax
15:35bottlenecklike: insert stuff table row col
15:35bottleneckand not allt hat extra shite
15:37Chouserbottleneck: ah, yes, that would be nice. The idea has come up, but I'm not aware of any implementation.
15:39kotarakThere is schemeql, but I don't know, whether it's easy to port and whether it is worth the trouble..
15:42ChouserI'd love to see something like (select my-col from my-table where id-col = ~id) -> [{:my-col "foo1"} {:my-col "foo2"}]
15:42bottleneckhmm link?i might cuz it looks like im going with clojure
15:42Chouserbut I haven't thought it through much.
15:42kotarakChouser: schemeql is something in this way.
15:43kotarakBut I never used it and don't know it state.
15:48ChouserSchemeQL link: http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.11.4048
15:52Chouserlooks about right to me
15:58jgracinI never found any sources of SchemeQL
15:58jgracinsource code, I mean
15:59Lau_of_DKChouser: how do I test the effeciency of the STM in any program of mine?
16:02Chousereffeciency? If you mean overall performance, I suppose you would create something that puts your program under realistic or extreme load, and measure how it performs.
16:06Lau_of_DKI mean, how many transaction had to be retried, average re-try rate. That type of thing.
16:10Chouseroh! There's no "standard" way yet, as far as I know.
16:10ChouserPerhaps you could add a logging call to the dosync macro and collect stats that way.
16:12bottleneckwhy does both succeeding imports and failing ones return nil?
16:13powr-tocLau_of_DK: There's a nice low ceremony java ORM for JDBC, called ActiveObjects... It's OO, so it's not the functional wrapper you're looking for, and I have no idea how it'd translate into clojure; but it might be worth a look as a last resort
16:13powr-toc
16:13dthomasbottleneck: What is a failing import?
16:14dthomasbottleneck: When I try to (import) something that doesn't exist I get a ClassNotFoundException.
16:15bottleneck(import '(java.jdbc))
16:15bottlenecknil
16:15bottleneck(import '(java.jdbcsdcscc))
16:15bottlenecknil
16:16dthomasbottleneck: Ah, OK.
16:16cooldude127bottleneck: you can't just import a whole package in clojure i think
16:17dthomasI suspect you don't need to import a package when you use a fully-qualified name.
16:17cooldude127correct
16:19dthomasI wonder if Java even offers a way to introspect a "namespace" (or "package" or whatever they'd like to call java.sql).
16:19bottleneckso hiw do i do?
16:20dthomasI guess that's java.lang.Package. I see Package/getPackage itself returns null instead of raising an exception when given a bogus package name.
16:21dthomasbottleneck: What are you trying to accomplish? If you want to use things in java.sql by their fully qualified name you can just use them. E.g. java.sql.DriverManager.
16:22AWizzArdWhen I do (System/getProperty "java.class.path") I get back "c:/Users/ath/clojure/clojure.jar" under Windows Vista. Now I say (add-classpath "file:///Users/ath/clojure/libs/xLightweb/xlightweb-2.2.1-jar-with-dependencies.jar") and it returns nil. But when I check the classpath again via (System/getProperty "java.class.path") nothing has changed. Is that normal? Doesn't this get updated?
16:25dthomasAWizzArd: I observe the same behavior here. My guess is that java.class.path is set at JVM bootstrap time and from then on it's just the ClassLoader using that path.
16:26dthomasEr, that is, I'm betting the ClassLoader reads that property when it's constructed, and further modifications to it are ignored.
16:26dthomasI note that when I (add-classpath) something, I can't (import) it but I can refer to classes from that JAR.
16:26AWizzArdhow do you refer to them?
16:28dthomasAWizzArd: Fully qualified name. Like I just loaded a JAR and then tried just "org.w3c.util.URLUtils" in the REPL
16:32Lau_of_DKSo Im reading through the ClojureGroup, and suddenly there are entire posts in French... w00t?
16:33kotarakYeah, instead of discussing in english whether the language matters, they do it in french, excluding external opinions.
16:34Lau_of_DKCant we add a filter for french? My mind has one built in :)
16:53danleiis there a way to make the prompt show only the last part of the ns? foo.bar.baaz.quux> -> quux>
16:53danleis/./-/g
16:55AWizzArddanlei: you would have to supply your own repl
16:55AWizzArdthe p part prints the full ns thing (default)
16:55AWizzArdyour print would not
16:56danleiAWizzArd: ok, thanks, AWizzArd
16:56arohnerIf you look at Repl.java, the prompt is hard coded
16:56arohnerit would be pretty simple to replace that with a var that points at a fun
16:56danleiyes, that shouldn't be hard. just wanted to know, if there's a standard way to tweak it
16:59AWizzArdin Common Lisp you "program" your own Lisp interpreter by saying: (loop (print (eval (read))))
17:00AWizzArdthat will not give any output prompt.. but into this structure you could put your own prompt
17:00arohnerthe musings on the google group about rewriting the repl in clojure look interesting
17:01danleii should start reading the group more regularly
17:01Lau_of_DKI second that
17:01AWizzArdyou can simply build your own repl on top of the existing one
17:01AWizzArdin this meta repl you can do whatever you want
17:02danleii understand
17:12flaskandthomas:ok, im new to databases, how do i create database? is their one coming with java or i have to download postgresql or mysql separately and install?
17:12ChouserSo far I've written a Clojure REPL in Clojure for the browser and for Swing. Someone else wrote one in Clojure for Qt.
17:13dthomasflaskan: AFAIK J2SE JDK doesn't come with any databases, so you'll probably need to have a database and then the JDBC driver for it.
17:13kotarakI use a Clojure Repl for Gorilla. But heavily modified in many ugly ways to sync with Vim.
17:16Chousukeflaskan: if you want an easy way to make a simple database, you could try sqlite
17:17Chousukeit doesn't require any complex server setups so it should be good for experimentation :)
17:17tWipI think JDK6 comes with derby
17:19tWiphttp://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/beta2.html
17:19dthomasflaskan: I second Chousuke's recommendation pretty much. I just compiled http://www.xerial.org/trac/Xerial/wiki/SQLiteJDBC the other day.
17:19tWipunder database... but don't use it for production :)
17:20dthomasI'm actually kind of scared by the number of pure Java SQL databases available with a quick web search.
17:22dthomasNever really looked at Derby, looks kind of nice. It seems to support foreign keys, which I sometimes miss in SQLite. Also supports multiple connections to the DB from within the same JVM, which I was having problems with in conjunction with the above SQLite JDBC driver.
17:22tWipyeah, I think bundling derby pretty much solved the testing of jdbc apps
17:23tWipno need for sqlite
17:52flaskanChousuke: how do i connect it to my program?
17:57Chousukeflaskan: that shouldn't be too difficult with JDBC. I'm sure you'll find examples if you do some googling.
17:58flaskantWip: how do i access derby from clojure? is the database itself there too so i dont need to install anything?
17:58flaskani cant even understand how do they made java so complicated.
17:58blackdog_flaskan, have a look in contrib.sql
17:58blackdog_in tests there is an example
18:07flaskani see
18:07flaskani have contrib in C:/clojure_20080916/clojure-contrib
18:07flaskanbut i never got how to install it so i cant use it
18:08arohnerflaskan: source or jar?
18:27flaskansource
18:33flaskanwhere is that link to setup slime?
18:33flaskanhttp://github.com/jochu/swank-clojure/tree/master/swank-clojure.el
18:33flaskanis that enough?
18:37hiredmanclojurebot: (* 34 23)
18:37clojurebotI don't understand.
18:37hiredmandamn you
18:37hiredman(* 34 23)
18:37clojurebot782
18:41danlei(+ 1 2)
18:41clojurebot3
18:41danlei(prn 'hello)
18:41danleinice
18:42flaskan(pr "clojurebot is a donkey")
18:43flaskan(eval '(+ 1 2))
18:43arohneris there a way to make swank pretty print a macroexpand?
18:43danleiclojurebot: clojurebot?
18:43clojurebotclojurebot is self referential
18:44hiredmanjust math right now
18:46hiredmanand only simply stuff, no nested expr
18:47danleiis there a function that: (?? [a b c d]) -> [b c d a] -> [c d a b]
18:47danlei"rotates"
18:48flaskan(+ 3 4)
18:48clojurebot7
18:48Chouserclojure.contrib.lazy-seqs/rotations
18:48flaskan(- clojurebot life)
18:49danleiChouser: great thanks
18:49flaskanchouser: cool
18:49flaskani want to setup SLIME for windows, can someone post a link?
18:49Chouser(apply + 1 2 3)
18:49flaskani think remember seeing one
18:49Chouser(+ 1 2 3)
18:49clojurebot6
18:49flaskanor how do i do it?
18:50danleiflaskan: i remember some podcast, but maybe that was for os x
18:50flaskanbut slime is just a bunch of el-files right?
18:50flaskanso i need to what, run it with clojure as inferior-lisp?
18:51danleiwell, you'd need swank-clorure and stuff, it's described on the wiki
19:00danleihm, i think i'm a little confused ... what does (require 'foo.bar) (refer 'foo-bar) become in ns?
19:00dthomasI'm a bit surprised that 0 is apparently true. Is this right?
19:01rhickeydanlei: use
19:02rhickeydthomas: 0 is not nothing (nil), nor false
19:02flaskanrhickey: on homepage, Slow/no innovation post standardization, slow as in slow execution speed? sbcl is superfast...
19:02powr-tocdoes anyone know in which java files the built-ins are defined (e.g. if, let etc...)
19:02rhickeyflaskan: slow innovation, not execution :)
19:03flaskanah yes i read like a donkey
19:03rhickeypowr-toc: clojure.lang.Compiler
19:03danleirhickey: ok, (:use (foo.bar) (baz.quux)) seems to work. is that correct (the parens)
19:04powr-tocrhickey: thanks... was looking in there, but somehow skipped past them.
19:05danleinice, works
19:07dthomasrhickey: OK, I guess I see where that's documented both in the section on the reader and the "Differences with Lisps" page. Thanks.
19:08rhickeydthomas: 0 is true in Common Lisp too
19:09dthomasrhickey: Huh, so I just tested. That's kind of embarassing that I didn't know that.
19:09dthomas(And now immortalized in IRC logs.)
19:11dthomasToo bad in this case, since I wanted to do (or (compare a b) (compare c d)).
19:16flaskanclojure-lang-1.0-SNAPSHOT.jar
19:16flaskanwhat is that?
19:18flaskanpath tot e clojure.jar?
19:18flaskanwhy snapshot?
19:20flaskani got wokring a bit, both clojure and slime in the menu
19:20flaskanbut i cant run inferior lisp
19:22notallamapoint it to your clojure.jar. (whatever yours is called)
19:22flaskanin did
19:22flaskani did
19:22arohner_flaskan: what do you mean "can't run?" what happens when you do M-x inferior-lisp?
19:22flaskanno such filem or directory, lisp
19:23flaskan(setq swank-clojure-jar-path "C:/clojure_20080916/clojure.jar")
19:23arohner_if you are trying to run slime, you should use M-x slime rather than M-x inferior-lisp
19:24powr-tocIs there a reason why the special-forms like if, let etc... don't have meta-data associated with them? I'm thinking doc strings etc...
19:25powr-tocas a newbie, it occaisionally seems frustrating to do (doc new) and get an error
19:26arohner_powr-toc: SVN clojure supports (doc <special form>)
19:26powr-tocahh cool
19:26powr-tocI'll upgrade
19:26arohner_it only tells you to go read clojure.org though
19:26flaskanok i got it running wioth M-x slime but it doenst sem to fucntion poerfectly. for some reason I cant do C-c C-e(its grey in the menu)
19:26powr-toclol
19:27arohner_flaskan: you have a repl?
19:27flaskanwhy are the keybindings for clojure-mode no in the menu? why are the keybindings for slime grey, ie not working?
19:28arohner_flaskan: did you install clojure-mode?
19:28arohner_go to a .clj file and type M-x clojure-mode
19:28notallamaflaskan: have you looked at http://riddell.us/clojure/ ? that helped me get it working.
19:29arohner_or http://en.wikibooks.org/wiki/Clojure_Programming#Emacs_.2F_Slime_Integration
19:29flaskanaroherr: yes repl
19:29flaskan^^ im doing that
19:30flaskani have clojure and slimem in the emacs-menu, the clojure-repl is running with M-x slime
19:30flaskanbut the keybindings are not working
19:30danleiok, something must be wrong. is this correct use: (ns ... (:use (foo.bar) (baaz.quux)) ... ?
19:31flaskanin normal clojure-mode i can do C-c C-e to eval last s-expr, now i ahveto choose with the mouse in the clojrue-menu. the binding is in the slime-menu but it is grey, ie not activ eor something
19:31flaskanusing windows btw
19:32arohner_try C-x C-e
19:34danleii don't get it; (require 'foo.bar) (refer 'foo-bar) works perfectly fine ...
19:34notallamai have that same issue on my windows box. i'm thinking it's because i screwed up the setup. i'll try fixing it afte i' done my homework, and let you know how it goes if you don't get it working by then.
19:36flaskanuser=> java.lang.Exception: No such namespace: swank
19:36flaskanthe repl starts but i get that ^^
19:36arohner_flaskan: I've seen that when the clojure and swank versions don't match up. If you have a pre-AOT clojure, you'll need a pre-AOT swank, and vice versa
19:37arohner_you are using the downloaded clojure.jar?
19:37flaskanahead of time compilatioN?
19:37arohner_flaskan: yes
19:37flaskandont know i have the september 16 version
19:37arohner_and you git clone'd swank?
19:39flaskanyes
19:39flaskanboth swank and clojure-mode i git-cloned
19:39arohner_run this:
19:39arohner_git reset --hard 73625153203649bb9bac1a32774e1100a60c6f5c
19:39arohner_inside your swank-clojure directory
19:39arohner_then restart emacs
19:40arohner_that will point your swank to an older version which should work with the sept clojure
19:42flaskanuser=> java.lang.Exception: No such var: swank/start-server
19:42flaskanetc
19:42flaskanstill the same problem
19:42arohner_hrm. That's the exact version I'm using on an older clojure version
19:43danleiok, one more time. can someone give me a sample invocation of "use"? neither (use 'foo.bar), (use 'foo-bar) (use '(foo.bar)) (use '(foo-bar)), nor 20 other possible combinations i tried seem to do the trick. can't be that hard
19:44arohner_danlei: (use 'clojure.contrib.test-is)
19:44arohner_if that doesn't work, it probably means the library you want is not in the classpath
19:45flaskananyway f*** slime. couldnt someone put up a guid eon how to do java classpath stuff on windows, how to make it work with clojure?
19:45danleiwell, it works, if i do (require 'foo.bar) (refer 'foo-bar)
19:45danleibut not with (use 'foo.bar)
19:45arohner_danlei: how does it not work?
19:45Chousukearen't you supposed to use the ns macro instead of those anyway?
19:45danleinamespace foo.bar not found
19:46danleiwell, i wanted, but that won't work either
19:46danleii'm sure it's just a small glitch, but i don't get what's wrong
19:46Chouserdanlei: it may be your file structure
19:47danleiok
19:47danleilook:
19:47arohner_flaskan: use -cp when starting java
19:47Chouserdanlei: what's the full name of your namespace?
19:47arohner_java -cp /path/to/clojure-contrib.jar clojure.lang.Repl
19:48danleidhl-utils
19:48Chousukethat's missing clojure.jar though :p
19:48arohner_oops, need a clojure.jar in there
19:48danleithey live in .../clojure/dhl/utils.clj
19:48danleiand ... is in the classpath
19:48arohner_java -cp path/to/clojure.jar:/path/to/clojure-contrib.jar clojure.lang.Repl
19:48danleisorry .../clojure/ is in the claspath
19:48Chousukedanlei: that's misnamed then, isn't it?
19:48Chouserok, with that file structure your namespace should be clojure.dhl.utils
19:49Chouserok, then dhl.utils
19:49rhickeyflaskan: maybe you want to try this: http://groups.google.com/group/clojure/msg/5f4d2779717e6b26
19:49danleieven if .../clojure/ is in the classpath?
19:49danleiyes, ok
19:49cooldude127is anybody else reasonably familiar with On Lisp's non-determinism macros? (choose, fail)
19:49danleii just double-checked it's definitely in the classpath, and i spelled everything correct
19:50danleiif i do (require 'dhl.utils) (refer 'dhl-utils) everything works as expected
19:50Chouserso with your
19:50Chouserno
19:50danleithen: use 'dhl.utils ->
19:50danleinamespace dhl.utils not found
19:51Chouserif (refer 'dhl-utils) works, then your namespace is named dhl-utils when it should be dhl.utils
19:51danleiaha
19:51danleijust a sec, i'll check
19:51cooldude127CLOJURE WHY CAN'T YOU JUST HAVE CONTINUATIONS
19:52cooldude127I KNOW IT'S NOT YOUR FAULT
19:52cooldude127sorry guys :)
19:53danleiChouser: Thou art a saint. Thank thee!
19:53danleii almost went mad
19:53Chouserdanlei: np. subtle one there. :-)
19:53danleioh boy
19:55powr-toccooldude127: vaguely... they implement failure driven search right?
19:55bradbevdoes anybody know where the best place to post patches for clojure/swank?
19:56powr-toclike prolog style backtracking etc...
19:57arohner_bradbev: fork it off github, and then commit to your fork
19:58bradbevarohner_: true. I guess that's easier than posting patches to the main tree then?
19:59arohner_are you asking about clojure proper, or swank-clojure, or both?
19:59bradbevswank-clojure
20:01arohner_ok, yeah. what I said above. the process is different for clojure proper and for a second I thought you were asking about htat
20:02cooldude127powr-toc: exactly
20:03cooldude127i'm trying to port those to clojure
20:03cooldude127it's only going somewhat well
20:03bradbevarohner_: thanks
20:03arohner_np
20:05cooldude127powr-toc: it works, but the problem with it is that if you reach a solution before you've tried them all, the possibilities are still left around, they don't get removed
20:06cooldude127it makes me sad
20:07flaskanrhickey: thanks for the link, seems awesome
20:07flaskanreally very good initiative
20:07Chousercooldude127: doesn't 'on lisp' include macros for making continuations out of closures?
20:09cooldude127yeah it does, i need to look at them, still haven't wrapped my head around how that can work
20:10Chouserdoes anyone think there's a niche for very small standalone text editor + clojure repl written in pure clojure? It'd be very small and require essentially no installation, but it's getting to be a crouded space with slime, clojurebox, enclojure, gorilla, jedit plugin, eclipse plugin, etc.
20:11danleiChouser: if it would be a one-click installer, everything included that one needs to get a repl, without classpaths and all that stuff, there would surely be a niche
20:12danleii mean ... about 8-10 /long/ discussions just about such stuff in the last few days
20:13Chouserdanlei: yeah, I think it could be a single .jar which, if I understand correctly, could be double-clicked in Windows and MacOS. Launching in any Linux would be a one-liner at worst.
20:13danleiChouser: i'm sure that peope would use it
20:13danlei+l
20:13flaskana
20:13MarkVolkmannDarn! I asked this question this morning and I already forgot the answer! ...
20:14lisppaste8flaskan pasted "bayesian spamfilter" at http://paste.lisp.org/display/70940
20:14MarkVolkmannI have a list and I want to use the values and arguments to a function. What expands a list in place so the items in it can be treated as individual arguments?
20:14ChouserMarkVolkmann: apply
20:14flaskandoes anyone know how to make the merge-and-compute... function smaller?
20:14MarkVolkmannThanks!
20:15flaskanChouser: id be interested in the code but not really using it
20:15Chouserflaskan: heh, ok.
20:17cooldude127Chouser: might be nice for those new to the language or those unattached to their editor
20:17cooldude127but for me, emacs is it
20:18MarkVolkmannWhy doesn't this print all the arguments on separate lines?
20:18MarkVolkmann(defn prn-all [& args] (apply prn args))
20:18danleithat's what i thought, too. imagine being a total newbie, never used emacs or stuff. then you've got to get java, clojure, contrib(?), set classpaths up, install slime, make that work with swank-clojure, ... it's quite something a starter has got to get working
20:19MarkVolkmannWhen I run (prn-all 1 2 3), all the values are output on the same line, but prn is supposed to include a newline after each call.
20:19arohner_MarkVolkmann: because you call prn once with [args]
20:19danlei(and emacs alone may be fairly intimidating to some)
20:19flaskananyone using clojure-box? it works perfectly, i just dont get which .emacs file it uses. i want to take away the toolbar, how?
20:19MarkVolkmannHow can I make my prn-all function call it once for each argument?
20:19arohner_try (defn prn-all [& args] (doseq [x args] (prn x))
20:20cooldude127well here does, now i'm giving clojure continuations
20:20MarkVolkmannI'm confused why apply didn't do that. Isn't it supposed to call the function prn once for each item in the args list?
20:20danleiflaskan: you're talking about the emacs toolbar?
20:21arohner_flaskan: i don't know where the .emacs file is, but you can get rid of the toolbar by eval'ing (if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
20:21cooldude127MarkVolkmann: you're thinking of map
20:21arohner_prn by itself takes any number of arguments, prints them, and then prints one newline
20:22arohner_try (prn 1 2 3)
20:22cooldude127apply basically the list you pass as the last argument and makes each element an argument
20:22arohner_apply calls the function you supply, once
20:22MarkVolkmannAh, okay. I guess I need to use doseq to call a function once for each item in a sequence.
20:23arohner_right
20:26cooldude127wow the doc macro makes me super happy
20:31flaskanwhen using clojure-box, is it then possible to do sql stuff without installing anything else?
20:32danleiany musicians here?
20:32flaskanim trying to write a genetic programming music program in clojure
20:32flaskanbut no i suck at music unfortuenwately
20:32danleihm
20:33cooldude127Chouser: you seem to know what's going on when it comes to idiomatic clojure. so when it comes to these continuation and non-determinism macros, we have some global state. is this a situation for refs or vars?
20:33danleihow would you model generation of scales/arpeggios and stuff
20:33danleii did it like this:
20:33danleikeep chromatic scale in a vector
20:33danleiand the scales, for example are the number of half-steps (relative to each oher)
20:33danleithen, i map those over the chromatic scale from the tonic
20:34danleiso that i can create scales/arpeggios and that stuff without having a large database of such stuff
20:36danleiat least it works, kinda :)
20:38cooldude127you gotta love clojure's approach to mutable state until it makes your life a pain in the ass
20:38lisppaste8Chouser annotated #70940 with "shorter merge-and-compute... for flaskan" at http://paste.lisp.org/display/70940#1
20:41Chousercooldude127: vars are fine if all the mutation is going to happen within a single thread -- changes will be invisible to other threads and thrown away when the thread completes.
20:41Chousercooldude127: chances are you want a ref
20:43cooldude127Chouser: ok, well now i have new challenges, as i'm not sure how to implement these continuation macros with refs
20:44Chousercooldude127: you're sure the state mutates, right? Sorry, it's been ages since I looked at 'on lisp'
20:44cooldude127well, the paths variable gets stuff added to it whenever you do a choose
20:45cooldude127i'm not really sure about the continuation variable, looks like all it does is get rebound
20:45cooldude127but the way it does is weird, he uses it as the name of the first argument to functions
20:45Chousersorry, gotta go -- back in a few...
20:45cooldude127NOOOOO
20:45cooldude127k
20:52bradbevwhat's the best way to see if an argument is a function? I feel like I want (function? x) or (callable? x)
20:52bradbevfn?
20:52bradbevdoh
20:53cooldude127yay
20:53cooldude127lol
20:54Chouserbradbev: note that (fn? {}) -> true
20:54cooldude127yeah anything that can be called like a function gets to return true
20:54bradbevyeah, same for vectors etc
20:55cooldude127and keywords even
20:58powr-tocIs that why vectors etc... implement java.lang.Runnable?
20:58cooldude127probably
20:58powr-tocIs it just a side effect of them being functions?
20:58cooldude127everything in clojure implements everything even remotely possible
20:58bradbevcoming from CL, I am starting to like how easy it is to call functions is a Lisp-1
20:58bradbevin a Lisp-1
20:58cooldude127yeah it's so nice and clean
20:59Chousercooldude127: ok, so he's capturing *cont* all over the place
20:59danleii often name my vars as functions ...
20:59cooldude127yes
20:59cooldude127Chouser: i'm not sure how to translate the lambda captures to refs
21:00danleitook me almost 10 minutes to find a bug (let [seq ...
21:00cooldude127do i even need refs for it?
21:00Chouserdanlei: yeah, don't do that.
21:00cooldude127danlei: that's the only problem
21:00powr-toccooldude127: I guess it makes sense, just wondering what it means to run a vector...
21:00danleiChouser: yes, i know. it's just habits
21:01Chousertempting names for locals that should be avoided: seq, list, vector, vec, fn
21:01Chouserstr
21:01Chouserpowr-toc: it takes an int, and returns the value at that index
21:02cooldude127powr-toc: all functions are runnable
21:02Chouserpowr-toc: ([:a :b :c] 1) -> :b
21:02MarkVolkmannquestion about function documentation syntax ... look at (doc concat) as an example ...
21:02cooldude127powr-toc: they just do their thing
21:02danleithose things bite me quite often, a few hours ago, cond confused me to death, because of the removed parens =)
21:02cooldude127lol
21:02MarkVolkmannIt says ([] [x] [x y] [x y & zs]).
21:02cooldude127MarkVolkmann: those are the 4 possible signatures
21:02MarkVolkmannWhy not just & x.
21:02cooldude127optimization
21:02MarkVolkmannDoesn't that encompass all the possibilities?
21:03MarkVolkmannSo the common cases are handled more efficiently?
21:03cooldude127yes
21:03MarkVolkmannThat seems to be an implementation detail and not really part of the documentation of the function.
21:03cooldude127and it might use reduce to turn the multiple one into a bunch of calls to the two-arg variety
21:03cooldude127MarkVolkmann: could be true
21:04cooldude127are the docs autogenerated?
21:04powr-tocChouser: yeah, I understand that... but Vectors are a function of their indexes... java.lang.Runnable#run() takes no params (though they could be instantiated via a constructor)... so I guess it's just a function of being a function...
21:04cooldude127i had not considered that
21:05cooldude127is rhickey here?
21:05Chouserpowr-toc: ah, good point. yeah, IFn implements Runnable, but in any case where a function can't be run with zero args, that fact's not useful.
21:05powr-tocSo I guess there's no use in it
21:05cooldude127apparently not
21:06cooldude127we could just try (.run [1 2 3])
21:06cooldude127could we not?
21:06Chousercooldude127: the arg list doc is generated from the actual function signatures in most cases
21:06cooldude127yeah that's what i thought
21:06powr-tocChouser: still... it's all elegant, right through to the java... I like it :-)
21:07cooldude127yeah (.run [1 2 3]) throws an exception
21:07cooldude127i don't think vectors specifically implement run by choice
21:07cooldude127it appears to delegate to function behavior
21:07Chousercooldude127: I don't think you need a ref
21:07cooldude127Chouser: i was starting to think so
21:08cooldude127i still think i do for choose
21:08cooldude127but not for continuations
21:08Chouseroh, ok.
21:08cooldude127still not sure what the hell i'm doing
21:08cooldude127lol
21:08Chouser:-)
21:08Chouserwell, good luck with it anyway.
21:08cooldude127thanks
21:09cooldude127it was so much easier in arc lol, of course graham would make it easy in his own language
21:09rhickeyfns implement Runnable, but not all IFns do
21:09cooldude127rhickey: why do vectors?
21:09MarkVolkmannYes, documentation of the arguments a function takes IS autogenerated. That explains why (doc concat) outputs what it does. It picks up on the optimizations.
21:10rhickeycooldude127: because their abstract superclass does
21:11cooldude127rhickey: sounds right
21:11cooldude127the exception calling run() on it throws indicates that
21:11ChouserIFn extends Runnable
21:13flaskanChouser: cool, learned some new tricks from that
21:13Chouserflaskan: great!
21:13Chouserflaskan: I did that without actually understanding your algorithm or having a complete test case, so there may be other reductions available.
21:13powr-tocLooks like it should throw an IllegalArg...Exception due to the arity
21:14cooldude127powr-toc: run() should? cuz it does :)
21:14flaskanIf you only have 1 core, is STM useful then? like i cant hvae more execeutionsppeed right? but i can still have better concurreny
21:15powr-toccooldude127: hehe... was reading the code, not running it :-)
21:15cooldude127words cannot express how happy i am having ERC for IRC right next to a clojure slime buffer
21:15cooldude127emacs FTW
21:15julian_morrisonflaskan: threads still contend on a preemptive multitasking OS, even on one core
21:16danleigod, making music is hard
21:17julian_morrisonquestion for anybody who knows Clojure concurrency well: how would you code reactive behavior?
21:17julian_morrisonboth STM and agents seem to be purely applicative - the best I've come up with is spin-and-poll
21:18Chouserjulian_morrison: you want a thread to block until some kind of signal?
21:19rhickeyyou can add watchers to agents
21:19julian_morrisonChouser: I'm thinking something like a comms protocol that has states and reacts to inputs, errors, etc
21:20julian_morrisonrhickey: you can?
21:20rhickeyjulian_morrison: add-watch/remove-watch
21:21cooldude127woah
21:21cooldude127didn't know that was there lol
21:21rhickeybut for what you are describing, agents are the same as actors, just not switch statements
21:21rhickeythe functions you run can implement a state machine with the state
21:21julian_morrisonah, that must be new, it hasn't made it to the web site
21:22cooldude127how up-to-date is the web site?
21:22Chousermight refs one day support watchers as well?
21:22danleicooldude127: it's still experimental
21:22julian_morrisonrhickey: I've been thinking about the agent, actor thing. People keep saying they're similar but they look like duals to me.
21:23rhickeyjulian_morrison: agents are an open protocol and actors are closed
21:23rhickeyan actor is waiting for a fixed set of inputs
21:23rhickeyan new function for an agent can be defined and sent at any time
21:24julian_morrisonone moves data to code, the other moves code to data
21:24julian_morrisonactors are implicits stateful, even if the state is in tail call parameters
21:25rhickeyboth are stateful
21:25julian_morrisonand actors can give security gurantees - agents obviously can't
21:25rhickeythat's right, Clojure doesn't protect against internal malice, but few systems really do or can
21:26cooldude127rhickey: that kind of protection is usually restrictive
21:26julian_morrisonagents are stateful in a strange way. the only state is the reference. they're the most purely FP concurrent system i've ever seen
21:26rhickeyactors bifurcate the control model into messages and functions, agents use a single control model
21:26julian_morrisonactors can give strong guarantees, cf the "object capability model"
21:27rhickeyits the standard dynamic/control tradeoff - Clojure favors dynamic models
21:27cooldude127dynamic = yummy :)
21:27julian_morrisonalso, actors don't make assumptions that everyone can see all the RAM
21:28rhickeybut have the serious limitation of requiring messages to read, which introduces the possibility for deadlock or the necessity of timeouts
21:29rhickeya->b tell me something, while b->a tell me something, a waits for b, b for a, deadlock
21:29rhickeyso actors impose the overhead of a distributed model even in the local case
21:29rhickeyI decided against that
21:30rhickeybut yes, agents are a shared memory system
21:30julian_morrisonI think you could work around that deadlock but it would involve a very strong asynchrony assumption and an effort to never block
21:30powr-tocrhickey: are there any good papers on pros/cons of actors which influenced your decision?
21:30rhickeypowr-toc: just read about Erlang
21:31rhickeyjulian_morrison: timeouts are the norm with actors
21:31powr-tocrhickey: hehe, that'd all be pro actor literature then ;-)
21:31cooldude127erlang is all actor-ed up
21:31rhickeypowr-toc: not at all, there ar epapers about deadlocks, lost messages, etc
21:32powr-toccool... I'll have to go and dig em out..
21:32rhickeyErlang is a great way to do comm apps, but comm apps are hard
21:32rhickeyall apps shouldn't be that hard
21:32powr-toctrue
21:33julian_morrisonwhat apps nowadays aren't comm apps
21:34julian_morrisoneven my desktop widgets are often comm apps
21:34rhickeyparts of apps are comm, but not simple object interactions
21:35julian_morrisonno, that's true, apps are usually comm on their outside
21:35rhickeythe vast majority of an app shouldn't work that way, IMO
21:35julian_morrisonalthough big apps often are comm on their inside
21:35powr-tocrhickey: Have you any plans to better support distributed apps in clojure?
21:35rhickeyincredibly cumbersome
21:35rhickeypowr-toc: there will be support for message queues, probably on top of JMS
21:36powr-toccool
21:36rhickeyjulian_morrison: inside, many things are solved by queues
21:37julian_morrisonrhickey: are there FP queues in Clojure? I know there are non-FP ones in Java
21:38rhickeyjulian_morrison: I don't think queues should be FP - I like j.u.concurrent for workflow
21:39julian_morrisonrhickey: aside, a request: pretty please, could we have the API doc in PDF?
21:39rhickeythere is a PersistentQueue in the Clojure lib but not exposed in the API yet
21:39julian_morrisonno FP in queues? Interesting. Why?
21:40rhickeyjulian_morrison: because you need to pace work, i.e. block
21:41rhickeyjulian_morrison: http://clojure.googlegroups.com/web/manual.pdf
21:42julian_morrisonrhickey: thanks :-D
21:43julian_morrisonhmm. I wonder if "functional reactive programming", Haskell style, applies
21:47julian_morrisonthat is, describing blocking semantics as a function of lazily streaming input
21:56rhickeyjulian_morrison: I don't know enough about FRP, but the little I've read about seemed inordinately complex
21:57rhickeywhy simulate time when you have real time?
21:57blackdog_are there any examples (apart from rhickey's lisppast) on the new gen-class stuff
21:57powr-tocrhickey: one thing erlang supports is safe hot code-swapping, as fn's are def'd is there a safe way to update a function definition in a running system?
21:58blackdog_do i need to use import or use to get at it from clojure
21:58hiredmanI do it all the time with clojurebot, just dump updated functions into the repl
21:58rhickeyblackdog_: you can just use :gen-class in your ns declaration
21:59powr-tochiredman: yeah, but what would happen if that function was running at the moment you updated?
22:00rhickeypowr-toc: it doesn't mutate running code, just swaps the fn in the var
22:00blackdog_ok, and if i want to generate a new instance in clojure is that (my.ns.) ?
22:01rhickeynext call sees new code
22:01julian_morrisonpowr-toc: the Erlang way is that you can have two versions, and when the old version tail calls with a package name prefixed, the call goes to the new version and the old version gets unloaded
22:01rhickeyjulian_morrison: yes, Erlang is more sophisticated in this area
22:02julian_morrisonrhickey: blame the JVM not yet supporting tail calls ;-)
22:02powr-tocjulian_morrison: yeah, OTP's quite nice in that regard
22:02rhickeynot the tail calls, the multiversion update
22:03julian_morrisonas to the simulated time thing earlier, I think that's a Haskellism.
22:03rhickeyplus it is module granularity, Clojure's is per var
22:03powr-tocrhickey: true
22:03julian_morrisonrhickey: if you had tail calls, you could do it the Erlang way, just tail calling the var
22:05blackdog_ah hang on, is the ns version specifically for AOT? I see a gen-class function now too, which is really what I want in this case i think
22:06Chouserblackdog_: I don't think you're meant to call gen-class directly.
22:06rhickeyjulian_morrison: a long running agent often works that way, sending the same action to itself, will see updated code
22:07blackdog_ah, ok, how do i get hold of a new instance of my class then - feeling dense
22:08rhickeyjulian_morrison: but most Clojure code isn't wait/do/loop as in Erlang. Agents are idle, new actions use new code
22:09hiredmanclojurebot: new Class(x) is (Class. x)
22:09clojurebotYou don't have to tell me twice.
22:09hiredmanhmmm
22:09hiredmanclojurebot: new is <reply>new Class(x) is (Class. x)
22:09clojurebotYou don't have to tell me twice.
22:09rhickeyjulian_morrison: I've read Haskell School of Expression, Hudak's book on FRP
22:10rhickeyAs someone who's worked on professional broadcast multimedia systems, I found it pretty irrelevant
22:10julian_morrisonfair enough
22:11rhickeytime is the hole in the functional model, as functions don't have time, but real programs do
22:11julian_morrisonHaskell is often trying to push the envelope of "just how far can we get with one hand tied behind our backs" anyhow
22:12rhickeyagents and refs model time
22:12julian_morrisonactors model physics and were designed from it ;-)
22:12rhickeyI think Haskell is absolutely right to push that agenda and see where it goes, I've learned a lot from it
22:13rhickeyjulian_morrison: I quite disagree about actors - Armstrong is always saying that's the way the world works but it simply isn't
22:13julian_morrisonrhickey: how so?
22:13rhickeywe can observe things without their cooperation - not everything is messaging
22:13julian_morrisonrhickey: you observe something by bouncing a particle off it. particle interactions are local.
22:14rhickeyI don't bounce a particle off it - a particle bounced off it and hit me
22:14julian_morrisoneven quantum stuff is local if you use the Everett model
22:14rhickeyno cooperation
22:15julian_morrisondoesn't matter, same difference. the particle's interaction with you is also local
22:15rhickeyI think there's all kinds of intention in the actor model not present in physics, but am no physicist
22:16skritare refs the idiomatic way to do something like paul graham's accumulator generator?
22:16skrit(defn acc-gen [n] (let [x (ref n)] (fn [y] (dosync (alter x + y)))))
22:16rhickeyskrit: pgs accumulator generator is a real waste of time
22:17skriteven as an exercise?
22:18rhickeyIf I try to bounce a message off an actor that it doesn't understand, it controls what happens
22:19rhickeyskrit: yeah, think of something cool you'd like your computer to do and make it do that, much better exercise
22:19julian_morrisonrhickey: true
22:19skrityeah, just coming from a lisp background rather than java, starting off in what I know
22:20rhickeyskrit: unfortunately some of those exercises don't encourage good habits
22:21skritso you won't recommend things like project euler, etc
22:21Chouserskrit: oh, I like project euler
22:21rhickeyskrit: no, project euler is neat, and lot of Clojure people are doing that
22:22rhickeyaccumulator generator is silly
22:22Chouserit doesn't dictate how you solve the problem -- functional solutoins are generally very natural.
22:22skritoh, I agree
22:23ChouserI mean functional solutions for PE problems. :-)
22:23julian_morrisong'night all
22:37notallamayeah. i'm doing pe right now. it's the first time i have tried it. i looked at it before, but when i only knew java, the programming part was rather unpleasant.
22:40Chousernotallama: and now?
22:40blackdog_Chouser, you have any full example of gen-class usage
22:41blackdog_i understand the definition just don't know how to instance one
22:42notallamaclojure is quite fun to program in. i end up wanting to implement several solutions.
22:47notallamascheme is nice to program in too. and i thought it would be painful, but i also kinda like c. (not for project euler type stuff, though. i like the repl too much there)
22:48Chouserblackdog_: no, I haven't worked one up yet.
22:48Chouserblackdog_: all I've got are rhickey's example and a simple AOT class with just 'main'.
22:49notallamai end up using gdb as a repl in c, but it's not really the same.
22:49blackdog_yea, i have that
22:49blackdog_and understand it, but i don't know how to use it :)
22:49blackdog_do i import or use? neither is working for me
22:51Chouserblackdog_: I don't know if you can instantiate the class without AOT.
22:51Chouseras in, without compiling it first.
22:51blackdog_yea, so use compile first
22:52blackdog_ok, I'll give that a shot, i guess i was thinking it was a bit like gen-and-load
22:57Chouseryeah, I just confirmed --
22:57Chouser'require' doesn't create a class from a namespace
22:57blackdog_ok
22:57Chouserthat is, not one named for the namespace
22:58Chouseryou have to do a separate compile first, though you can then immediately start using it.
22:58blackdog_okdok, thanks
23:04arohner_Chouser: to clarify, that means that require will load source or .class, but will not compile source?
23:14ChouserIt looks like 'require' loads and of course compiles in-memory and evaluates the lib, but does not save it to disk and does not appear to create a class named for the namespace.
23:15arohner_that sounds like rhickey's standard orthogonal-ness
23:15Chouseror, right, if it finds a .class file that's newer, loads and evals that.
23:32timothypratleyException in thread "main" java.lang.NullPointerException (server.clj:0)
23:32timothypratleywhat might be hiding the line number?
23:32timothypratleyhmmm I'll try to make an example
23:45notallamaso i was showering, and those accumulator generators crossed my mind. wouldn't that just be a special case of iterate? (not the same thing, but you'd use it for the same thing)
23:48hiredmansome thing like http://paste.lisp.org/display/70873
23:49hiredman(Except diffferent of course)
23:50hiredman(f n) -> g, (g e) -> h, (h :nan) = n+e
23:52hiredmanhah
23:53hiredmanuser=> ((partial (partial (partial + 1) 2) 3))
23:53hiredman6
23:57notallamaah. i was thinking it was a function that returned a counter. i see what it's supposed to be now, though.
23:57hiredmanc is a counter
23:58hiredmanwhich is the different part, the same part is returning a function whose result is the current state of the calculation