#clojure log - Jan 04 2009

The Joy of Clojure
Main Clojure site
Google Group
IRC
List of all logged dates

0:00 chrisn: Where can I post a quote like lisppaste?

0:00 I have an awesome one from the one of the devs working on CUDA compilers.

0:01 danlarkin: chrisn: http://paste.lisp.org/new?

0:02 chrisn: A quote by a human. Not lisp code.

0:03 hiredman: bash.org? qdb.us?

0:03 danlarkin: nothing's stopping you from pasting a human quote on lisppaste

0:03 chrisn: http://paste.lisp.org/display/73041

0:03 I did

0:03 Chouser: http://paste.lisp.org/display/73041

0:03 sorry

0:03 chrisn: heh

0:04 Chouser: wrong globally-bound keystroke. :-)

0:05 chrisn: That, btw, in no way reflects NVIDIA's position on the subject.

0:05 the functional language guys number in the very few.

0:05 CUDA will be imperative for the forseeable future.

0:05 danlarkin: that quote reminds me a lot of a TA I had in college

0:06 hiredman: that quote sounds like a haskell guy to me

0:06 chrisn: yeah, it is definitely more haskell than lisp

0:07 Believe me, I would take anything but C and C++ after doing it for as long as I have.

0:07 but graphics are *always* C/C++

0:07 I actually program in C sometimes

0:07 real C

0:08 TDSmith: It's hard toget around C for some things

0:09 hiredman: "I write in C because using pointer arithmetic lets people know that you're virile" -- Matthew Garrett

0:09 TDSmith: Well- I'm pretty damned virile, you know.

0:10 Chouser: A bunch of my friends have been working on OS's since college. They're aware high-level languages may be useful to some people, but they don't really trust anything higher than C.

0:10 TDSmith: I put fertilizer on my balls every night before I go to sleep.

0:10 chrisn: wtf does trust have to do with anything?

0:11 you understand what the compiler is doing, read the assembly if you have to.

0:11 I have a few friends the same way and I just don't understand them.

0:11 Chouser: chrisn: right, that's why they trust C. Garbage collectors scare them, for example.

0:12 chrisn: I see "trust" as an excuse for not learning anything new.

0:12 People use that same argument to not use c++

0:12 not just gc's languages.

0:12 TDSmith: meh- it's not that simp[le

0:12 Chouser: I think it's mostly a matter of the problems you've had to solve. It only takes a couple of web-apps to realize you want your language to be helping out *a lot*.

0:12 chrisn: Or a couple cases of RSI

0:12 hiredman: chrisn: trust and STL

0:13 karmazilla: MS Singularity is mostly written in a dialect of C#, managed and all, because it is easier to trust -- reliability and security wise :)

0:13 chrisn: trust and std::vector

0:13 I don't know the entire STL

0:13 karmazilla: ... than C and asm

0:13 Chouser: but if you spend your time trying to track down why one particular load profile causes a network connection to take 2 milliseconds instead of 1 (or whatever), you really want to get down close to the metal.

0:13 hiredman: I think llvm could really be the foot in the door for higher level languages in the lower levels of the OS

0:13 chrisn: Singularity was a damn cool project.

0:13 TDSmith: I'm not very familiar with MS singularity but...

0:14 chrisn: I read their paper

0:14 TDSmith: Are we talking about the singularity here?

0:14 karmazilla: a research OS Microsoft did

0:14 TDSmith: Ah, I see...

0:14 hiredman: if people start using an llvm based c compiler, so llvm is installed anyway

0:14 might as well use it

0:15 TDSmith: So they dno't mean an intelligence hat replicates so fast that it quickly saturates the potential for compuytation avaliable in it's environs?

0:15 karmazilla: does that even make sense?

0:16 chrisn: llvm is interesting, I haven't quite got my head around it yet.

0:16 TDSmith: IT does, actually...

0:16 Sort of...

0:16 I'm skeptical, but...

0:16 chrisn: In some sense, you could give C an eval statement.

0:16 which is a hardcore concept

0:17 TDSmith: It is really odd that people would reference the "singularity" if they didn't mean it...

0:18 karmazilla: just reread your question and I think you might be confusing it with Vista :p

0:19 TDSmith: But, tha said, I've always thought that Singularitarianism was religion for atheists.

0:19 hmm..

0:20 Vista is not the singularity. I am almost sure of that.

0:25 Hmm.. clojure changes fast..

0:25 ericlavigne: TDSmith: Vista rapidly saturates the available computational power in whatever computer it is installed on.

0:25 though not in a particularly productive manner

0:26 apparently it is constantly making backups

0:26 TDSmith: eric: hmm

0:26 You're right...

0:26 Wow, what a letdown.. Vista was the singularity, I guess...

0:28 I have to admit..

0:29 I'm a bit suprised that the answer to life the universe and everything is a Micorosoft API...

0:34 karmazilla: it is for cases like that, that reality distortion fields exist

2:03 nibbs: is it possible to have regexp that refer back ?

2:03 hiredman: ah

2:04 a back reference?

2:04 like with \1 ?

2:04 java regexs use $1 instead of \1

2:05 nibbs: http://hpaste.org/13597

2:05 yes

2:06 whats up with lissppaste? it submits but then it is just blank...

2:06 Raynes: paste.pocoo.org

2:06 They have clojure highlighting.

2:06 hiredman: so does gist

2:07 Chouser: it's useful to have a single place to find pastes discussed here. Rich has requested we use lisppaste

2:08 hiredman: (.replaceAll "123rd" "(\\d+)rd" "$1RD")

2:08 arbscht_: how long until clj-paste.net? :)

2:13 gnuvince: I'd rather we submit a Clojure syntax file for lisppaste than move to another place

2:14 Especially considering that we got a bot for that.

2:15 nibbs: can i destructure-bind in a fn ?

2:15 (fn [[a b c] xs] b)

2:15 doesnt work like that but smehow?

2:16 hiredman: destructuring almost anywhere binding is done

2:16 er

2:16 works

2:16 the fn you pasted will work

2:17 nibbs: nope

2:17 hiredman: user=> ((fn [[a b c] xs] b) [:a :b :c] :d)

2:17 :b

2:17 Yep.

2:17 nibbs: http://paste.pocoo.org/show/97863/

2:17 duh

2:17 hiredman: You are doing it work then

2:18 nibbs: noh

2:18 hiredman: read the exception

2:18 nibbs: java.lang.IllegalArgumentException: Wrong number of args passed to: user$a (NO_SOURCE_FILE:0)

2:18 hiredman: so you are doing it wrong

2:18 and that is exactly what you are doing wrong

2:19 nibbs: why do you pass the :d outisde?

2:19 ah wait

2:19 hiredman: (fn [[a b c] xs] b) is a function that takes 2 args

2:19 nibbs: i see lol

2:24 herdrick: question: is there already something like member defined in clojure?

2:24 I used 'some' to make one: http://paste.pocoo.org/show/97864/

2:25 is that in canonical style?

2:25 hiredman: ugh

2:25 I wish clojurebot was up

2:25 gnuvince: herdrick: the "usual" way people do it is with a one-element set: (defn member? [e coll] (some #{e} coll))

2:27 herdrick: ah, so sets are executable like hash-maps cool, thanks

2:28 that is, thanks @gnuvince ;)

2:28 gnuvince: I wonder if this function should be included in core.clj, because it's asked weekly.

2:28 nibbs: (.replaceAll "hohejoj" "(\\d+)o\\d" "$1d") -> "hohejoj" but should be "hej"

2:28 gnuvince: I think I actually answered it here a couple nights ago.

2:28 nibbs: I mad emy own member? as a multimethod

2:29 http://paste.pocoo.org/show/97866/

2:29 obv using some seems easier :)

2:30 is some lazy?

2:30 gnuvince: nibbs: for maps, you can use contains?

2:30 user=> (contains? {:a 1, :b 2} :a)

2:30 true

2:30 user=> (contains? {:a 1, :b 2} :c)

2:30 false

2:31 hiredman: nibbs: fix your regex

2:31 nibbs: ah

2:32 gnuvince: nibbs: contains? also has the advantage of being O(1)

2:34 nibbs: ok

2:34 yeah my contains for maps is very dumb

2:35 hiredman: contains works on sets

2:41 nibbs: does nil and false always evaluate to the same?

2:42 hiredman: user=> (nil? false)

2:42 false

2:42 lambda: nil is just null, and false is a Boolean

2:43 hiredman: true and false are just there for java interop

2:44 nibbs: k

2:44 hiredman: actually false is a boolean

2:44 nibbs: (.replaceAll "hohejoj"

2:44 "(\\[bcdfghjklmnpqrstvwxz])o\\$1"

2:44 "$1d")

2:44 i still dont get it

2:45 it should match bob hoh but not hoj or lob etc

2:45 hiredman: ...

2:45 I suggest you read up on java regexs

2:46 nibbs: (.replaceAll "123rd" "([bcdfghjklmnpqrstvwxz])" "$1o$1")

2:47 works hello -> "hohelollolo"

2:47 user=>

2:50 but the other wat hohelollolo -> hello i cant get right

2:50 in python

2:50 "([%s])o\1" % "bcdfghjklmnpqrstvwxzBCDFGHJKLMNPQRSTVWXYZ")

3:00 (.replaceAll "hohejoj" "[bcdfghjklmnpqrstvwxz]o$1" "$1")

3:00 why doesnt that work`?

3:01 or actually im a little surprised it does work in python�

3:03 ok i need parens

3:03 now I see how

3:03 (.replaceAll "hohejoj" "([bcdfghjklmnpqrstvwxz])o$1" "$1")

3:03 but it still doesnt work

3:18 (re-find #"([bcdfghjklmnpqrstvwxz])o$1" "bob")

3:18 nil

3:18 why`?

3:18 that SHOULD work

3:18 it refers back to the paren

3:19 karmazilla: (.replaceAll "hohejoj" "([bcdfghjklmnpqrstvwxz])o\\1" "$1")

3:22 nibbs: thanks

3:58 when using namespace my user.clj is not available. should I require it? but it doesnt have a namespace. should it have a namespace?

3:58 or I should use load-file?

4:10 destructuring seems tio slow down a simple function by almost doubling the execution time

4:10 http://paste.pocoo.org/show/97872/

4:47 karmazilla: nibbs: destructering binding expands into invocations of nth and nthrest, which are O(n) for things that do not support index lookup

4:52 nibbs: what is the name of a html-tag that outputs text but not in a textarea and not as a link

4:52 just as plain text

5:15 who created compojure?

5:16 it would be nice to know who to ask about things?

5:16 isnt there a function to supply a vector of html-tags?

5:19 kotarak: nibbs: there is a compojure google group, IIRC

5:20 then there is Google. Searching a bit might help.

5:51 nibbs: how do I write a string to a file?

6:23 when using namespace my user.clj is not available. should I require it? but it doesnt have a namespace. should it have a namespace? or should I use load-file then?

6:25 if I want the eq of method X throws IOException {...} how do I do?

6:25 do I have to rethrow the error or just doing nothing has the same effect?

6:46 anyone familiar with the sql/insert-rows?

6:47 it takes a vectors as inserts but if I have a vector of vectors, how do I do?

6:52 StartsWithK: nibbs: docs say that insert-row takes & rows, so it should be ok to send vector of vectors

7:35 nibbs: (defn insert-rows-reviews [colls]

7:35 (dorun

7:35 (for [row colls]

7:35 (sql/insert-rows :reviews row))))

7:35 i had to do that

7:35 (defn insert-rows-reviews3 [colls]

7:35 (sql/insert-rows :reviews colls))

7:35 fails

7:36 kotarak: Use doseq instead of dorun + for

7:36 (doseq [row colls] (sql/insert-rows :reviews row))

7:38 nibbs: you should use apply: (apply sql/insert-rows :reviews colls)

7:44 nibbs: I have to say "big thank you" to whoever created contrib.sql, i dont think database stuff have ever been that simple

8:09 can I not pass :2 a s a name to a table?

8:09 but it can be named "2"?

8:10 kotarak: :2 is not a valid keyword, I suppose.

8:10 I must start with a alphabetic character, eg. :x2

8:11 nibbs: you can pass a string (create-table "2" ...)

8:13 nibbs: i try but it doesnt work

8:13 kotarak: what did you try, and what doesn't work

8:15 nibbs: i fixed it now

8:28 what a weirdo error

8:28 "movie 1" is a valid table-name right?

8:30 doesnt work

8:30 "hello" works "hello 12" doesnt work as table-name, that sucks

8:30 is it the parsing in contrib/sql perhaps?

8:31 kotarak: I personally would avoid Whitespace in table names. I suppose you have to to quote it in the SQL statement, which contrib.sql doesn't do.

8:32 nibbs: ah yeah i jsut skip the whitspace duh

8:42 should a 300kB file with one statement per row take a looooong time to insert into derby?

8:56 I have filename on the form "mv_0000001" and it is always 7 digits so 12 would be "mv_0000012" not "mv_00000012"

8:56 is there some nice trick for this?

8:56 kotarak: format maybe

8:56 (doc format)

8:56 hmmm... no clojurebot

8:57 nibbs: like in python filename = 'C:/users/saftarn/desktop/NetFlixDataSet/training_set/mv_%07d'

8:57 return filename % filmnbr + '.txt'

8:57 kotarak: as I said: format

8:57 nibbs: ah

9:10 drewr: kotarak: user> (class :23)

9:10 clojure.lang.Keyword

9:11 kotarak: Oh. Ok.

11:46 mmcgrana: i saw the recent change adding metadata support to namespaces: http://code.google.com/p/clojure/source/detail?r=1193 - could this be used to add a docstring to a namespace?

11:46 * Chouser tries it

11:48 Chouser: (alter-meta! (find-ns 'user) assoc :doc "The default namespace")

11:49 but print-doc doesn't know how to deal with it.

11:50 mmcgrana: interesting. i really like how doc strings for vars are structured in the metadata and was thinking it would be nice to do something similar for namespace-level docs instead of putting such documentation in comments at the top of files.

11:51 docs-in-meta for namespaces would also make programatically generated docs more viable

11:52 Chouser: ah, here it is (kinda) working: http://paste.lisp.org/display/73059

11:58 It'd be trivial to wrap that in a function that used *ns* and call it at the top of a file.

11:59 mmcgrana: yeah, i'm trying to paste an example of that now, but the paster is hanging...

11:59 Chouser: or even patch clojure.core slightly to allow (ns foo-ns (:doc "blah blah"))

11:59 mmcgrana: http://pastie.org/352274

11:59 Chouser: mmcgrana: sometimes the bot acts up and you have to choose None instead of #clojure, and then paste the link here yourself.

12:00 mmcgrana: o ok, ill do that

12:00 http://paste.lisp.org/display/73064

12:01 Chouser: yep, I'd have no argument with that.

12:01 of course the (doc clojure.zip) bit wouldn't work unless clojure.zip had already been loaded such as via require

12:01 nibbs: I LOVE CLOJURE, IT HAS EVEN MADE ME ABANDON PYTHON AS MY FIRST CHOICE OF LANGUAGE

12:02 Chouser: nibbs: welcome. :-)

12:02 mmcgrana: right, like it doesn't work on vars from unloaded namespaces

12:05 So a patch might look like: 1) add support for :doc in ns macro, perhaps via lower-level, seperate function to add adocstring to an arbitrary namespace, 2) update doc/print-doc to handle namespace case

12:07 i'd be happy to give that a shot

12:09 though Rich mentioned that he isn't interested in unsolicited patches - should I post the idea to the list first?

12:18 Chouser: mmcgrana: yeah, that's generally wise

12:19 let people help refine the idea a bit before posting a patch.

12:19 though I do think the process needs some refinement.

12:19 mmcgrana: which process is that?

12:19 Chouser: or I should say "would benefit from" more than "needs"

12:20 mmcgrana: i.e. the RFC/patch process or the namespace doc process?

12:20 Chouser: the process of producing incorporating (or not) patches.

12:21 mmcgrana: i agree

12:22 Chouser: the community can say "no" to an idea or a patch (unless of course overridden by Rich), but only Rich can say "yes". This is as it should be, but there are several patches that have gotten a general thumbs-up from the community but no ruling at all from the BDFL

12:23 they are in a sort of patch limbo until he rules. Maybe these should be posted to the google code issues page so that they're not lost in the avalanche of google group postings.

12:23 ...but I'm not sure that's exactly how rhickey_ means the issues page to be used.

12:30 danlarkin: guess who's been added? http://www.angelfire.com/tx4/cus/people/

12:31 nibbs: would it be possible to write some sort of decorator-macro that would add a println-statement of a variable for each time inside a loop?

12:31 so I didnt have to clutter the function with an option or something...

12:33 parsing and inserting an 8MB file is eating up my computers processor and memory

12:33 is that normal?

12:34 mmcgrana: Chouser: thanks for your thoughts, I'll post on the ns doc idea later today

13:38 nibbs: is it not possible to insert nil into a integer-field in sql?

13:38 what do you do if you dont have a value to pass?

13:38 (like a NULL field when parsing a file)

13:40 pd: NULLs are fine in integer columns

13:43 nibbs: hmm but nil?

13:43 and the NULL symol doesnt exist in clojure?

13:48 Chousuke: what?

13:49 whatever you're using to put the data into the database *should* map nil to the SQL NULL

13:49 but there's no way to have an actual clojure nil in there :/

13:53 nibbs: there are 2 things I really want from clojure

13:53 1. always show on what row the error happened in the CLOJURE-file, not what javafile.

13:54 2. a way to break a computation without killing the REPL completely

14:00 dreish: 1. I think there's a REPL that does that. I saw some messages about it on the Google group, but I don't remember where.

14:00 2. I don't know whether that exists, but I'd like it too.

14:20 nibbs: {:movieid 17770, :releaseyear 2003, :name Alien Hunter}

14:20 (str "select movieid from titles WHERE name = " moviename) <- works

14:20 btw [:name "VARCHAR(32)" "NOT NULL"]

14:21 (str "select movieid from titles WHERE name = " moviename) <- doesnt work

14:21 why?

14:21 isnt string = varchar as far as contrib.sql is concerned?

14:28 Chouser: nibbs: it's not doing any object translation for you. You'll need to quote it yourself or even better use a prepared statement.

14:39 dreish: Does anyone understand how to use PersistentQueue?

14:40 Chouser: sure, what's the problem?

14:40 dreish: I guess the interface looks simple enough, but I'm having a hard time figuring out whether the old items will get GCd.

14:41 My first idea was to use a vector and keep calling subvec as I consumed items, but then I saw in the implementation subvec keeps the original vector, so my queue would grow to infinity.

14:41 Then I saw PersistentQueue, but I can't figure out how it avoids the problem.

14:42 Chouser: once you use 'pop', the item you've popped off is no longer referenced by the PQ, so it's free to be GC'ed as long as nothing else has it.

14:44 dreish: It looks to me like r, the PersistentVector in PQ, only gets truncated (to null) when it becomes empty.

14:44 So if, by policy, my queue always had at least one item in it, the vector would keep growing forever.

14:45 Chouser: PQ.pop() always does a 'rest' which frees up the head of the seq

14:45 dreish: Sure, for the seq f, but what about the vector, r?

14:47 Chouser: ah, I think I see your concern. If you conj a lot onto the PQ, it will hold a large vector.

14:47 if you pop all but the last item of that vector, it will stil (via the seq f) hold the whole vector.

14:47 dreish: Right, which never appears to get trimmed in any way.

14:47 (Except when empty.) Right.

14:48 My program might actually not have the problem of never emptying the queue, though. I probably need to think that through a little more. :)

14:49 It could be a matter of, by the time the program has run long enough that I'd care about the size of the vector, it has almost surely run long enough to be empty at least once.

14:49 But dealing with finite computers and long-running programs, "almost surely" always leaves me a little uncomfortable.

14:49 Chouser: ok, I had thought that f and r never refered to the same vector, but now I'm not sure.

14:51 no, I think that's right.

14:51 dreish: If it could just say something like, if we only care about 5% of the vector, and the vector has more than 640 items, pop should make a copy of the remainder, not keep the whole thing.

14:51 Chouser: f and r never point to the same vector, so I think this is not a problem.

14:52 dreish: Okay, in that case I don't understand the relationship between f and r.

14:52 Chouser: starting from empyt, pushing a, b, c, d will give you a PQ of (a)[b c d]

14:52 this is seq f = (a) and vector r = [b c d]

14:52 dreish: ok

14:53 Chouser: pop once, f1 is null so you get (b c d)null

14:53 now push e f g: (b c d)[e f g]

14:54 dreish: Ah!

14:54 That's brilliant.

14:54 Thanks.

14:54 Chouser: :-) np

14:54 it's this kind of thing that (for me at least) builds trust in the whole of Clojure

14:57 dreish: Yes.

15:00 Chouser: so the worst it can get is if you push a lot into the vector and then pop all but the last

15:00 it's still carrying the whole of the large vector at that point.

15:00 dreish: Right, and then just sit there. Not exactly the worst-case I was thinking of.

15:01 As long as the queue keeps moving, it won't be much bigger than length*2.

15:01 nibbs: "select name from titles WHERE movieid = \"Fighter\"", doesnt work, how should I do?

15:02 dreish: nibbs: I think you're at roughly the same point I was yesterday when I decided not to use contrib.sql.

15:04 nibbs: but I like it

15:04 it makes sql so easy

15:05 except for that :)

15:05 dreish: It's got some nice ideas. It could probably be very good, with some work.

15:06 nibbs: wait ok that doesnt work because it shouldnt

15:06 Chouser: there's working being done on sql api

15:06 nibbs: isee the error

15:06 yeah Lau_of_DK has soem cool stuff going

15:06 on

15:12 Nafai: nibbs: What's he working on?

15:13 nibbs: higher-order-functions for sql-statements

15:13 check it on github

15:13 clojurebot: sql?

15:14 http://github.com/Lau-of-DK/clojureql/tree/master

15:14 * Nafai looks

15:16 Chouser: dreish: you're not Jason Wolfe, are you?

15:16 nibbs: dreish: you use jdbc directly?

15:16 dreish: Last time I checked, I was Dan Reish.

15:17 Chouser: dreish: ok. Someone named Jason Wolfe has been talking on the group about subvec's and queues.

15:18 dreish: nibbs: Yeah, that's what I'm doing. I'm writing a special-purpose persistence framework, and I'll target my app to that, so if contrib.sql gets irresistibly good, I can swap it in with hopefully not too much rewriting.

15:18 nibbs: thumbs up for Lau_of_DK for humour:

15:18 http://hpaste.org/13613

15:19 http://github.com/Lau-of-DK/clojureql/tree/master/src/dk/bestinclass/clojureql/demo.clj

15:19 dreish: Chouser: Same guy that found an interesting hashCode contract violation. I wasn't able to figure out what it was about, but I didn't dig too deeply. I did note that a Java array's hashCode is based on its identity, not its contents.

15:23 nibbs: (str "select movieid from titles WHERE name = " "'" moviename "'")

15:23 works ^^

15:24 Chousuke: but is vulnerable to SQL injection :p

15:25 dreish: Reminds me of my favorite movie about a character named Robert'); DROP TABLES movies; --.

15:25 pd: I've just run (add-classpath "file://path/to/clojureql/src") in a slime repl, but can't require dk.bestinclass.clojureql

15:26 Is that not how to modify the classpath in slime?

15:26 Chousuke: you forgot the trailing slash?

15:27 pd: Thank you =)

15:51 nibbs: how can I get a list of all tables in a db?

15:53 ivan: \dt

15:56 hoeck: nibbs: thats database dependend :(

15:56 nibbs: but you could try java.sql.DatabaseMetadata/getTables

15:57 nibbs: but not all jdbc drivers support metadata

16:05 nibbs: ok

16:05 http://java.sun.com/j2se/1.4.2/docs/api/java/sql/DatabaseMetaData.html

16:05 no constructor

16:06 hoeck: the java.sql.Connection has a getMetaData method

16:07 nibbs: ok but when using

16:07 sql

16:07 contrib.sql

16:08 how can I refer to it?

16:10 hoeck: contrib.sql has a connection function, so (with-connection db (resultset-seq (.getTables (.getMetaData (connection))))) should work

16:11 if you have an older contrib revision, connection may be in the internal namespace, so internal/connection

16:38 nibbs: (str "select count(grade) from " movieid "where grade = " val)

16:38 whats wrong with thayt?

16:40 dudleyf: nibbs: movieid "where

16:40 You probably want a space after that quote

16:42 nibbs: yes thanks

16:44 (defn get-tables []

16:44 (sql/with-connection db

16:44 (resultset-seq (.getTables (.getMetaData (connection))))))

16:44 ;

16:44 java.lang.Exception: Unable to resolve symbol: connection in this context (db.clj:194)

16:53 Lau_of_DK: nibbs: Which lib are you using ?

16:57 nibbs: contrib.sql

16:57 but what is connection?

16:57 some variable i can refer to?

16:58 Lau_of_DK: nibbs: Dunno, but consider using ClojureQL instead

16:58 :)

16:58 Then you could do (sql/run (query grade moviedb (= grade ~val))) to get that query

17:01 nibbs: will rich add sum to core? i know it is just (reduce + coll) but still...

17:01 Lau_of_DK: You probably answered your own question :) I dont think he will do that to save one character

17:04 nibbs: 5

17:04 it is used so often...

17:05 Lau_of_DK: You can argue before Rich - I'd hate to see Clojure become bloated with a gazillion little helpers

17:05 Chousuke: I wonder if (apply + coll) is better than reduce

17:05 less calls to +

17:05 er, fewer

17:05 dreish: + uses reduce internally, so apply is better because it requires less typing.

17:06 Chousuke: ah.

17:06 nibbs: sum is trivial to define yourself if you need it a lot

17:06 nibbs: yes ofc

17:06 just sayan yo

17:07 do you have your user.clj ina namespace?

17:07 do i have t import it then?

17:07 to use it from the repl i mean

17:07 Lau_of_DK: nibbs: You can always fork Clojure, call it Nibjure, and include that func :)

17:08 Chousuke: or send it to contrib

17:08 nibbs: lol

17:08 Lau_of_DK: Anyway nibbs, for your SQL needs, check out ClojureQL, its phenominal, and the guys who made it really did a good job :)

17:12 nibbs: yes I checked it out before

17:12 you have anice sense of humour, i liked the best in class example

17:13 Lau_of_DK: bestinclass example? You mean the demos ?

17:13 nibbs: yes

17:13 Lau_of_DK: Good, Im glad you liked it :)

17:47 nibbs: if passing NULL to sql should it be a string "NULL" or nil?

17:53 Chousuke: what are you using to communicate with SQL?

17:55 if you're using (str "select from foo bar where " whatever ...) and just sending those to the database, your NULLs will be strings :/

17:55 but that approach is flawed anyway. Did you take a look at contrib.sql?

17:55 or clojureql

18:03 emacsen: quote of the day goes to someone on the dc clojure study group list who wrote a little java gui app and someone else converted it into clj:

18:03 "Your code was 184 lines, and my Java code was 420 lines, and my JRuby

18:03 code was 402 lines!"

18:06 duck1123: it's really too bad that =~ isn't a valid symbol. It would be great if it could be a shorthand for re-find

18:07 Chousuke: ooh, excellent.

18:08 got the latest slime and clojure-swank working

18:08 apparently it's now necessarily to manually enable the fancy slime repl.

18:09 duck1123: yeah, it was kinda annoying getting it to work, but there is a thread that explains what to do.

18:09 emacsen: duck1123, yeah- you could add a reader macro at the source level and see if it'd be accepted into the language...

18:22 pjb3: Here's the swing app that emacsen was referring to: http://github.com/pjb3/converter/tree/master/converter.clj

18:22 The converter function needs to be broken down into smaller parts

18:23 But I was just doing this as a straight port of the Java version

18:23 and I need to set up a lot of objects in the let statement to be able use them as closure in the various functions

18:24 To mimic the instance variables from the Java version

18:24 Chousuke: something's wrong with the indentation of the to-f function :/

18:25 pjb3: yeah, there is, doesn't look that way in emacs though

18:26 nibbs: is it possible to run several JVMs in emacs?

18:28 Chousuke: pjb3: all the actions look really similar :/

18:29 pjb3: Yeah, I could create make-action function to clean that up a little

18:30 They are all slightly different

18:31 Chousuke: maybe even a macro

18:41 aperotte: I just found a very nice new numerical java library. In case anyone else is interested, it's here http://www.ujmp.org/

18:58 nibbs: aperotte: thanks, it leads to some good other libs too!

19:02 ehird: What's the defacto clojure tutorial

19:02 ?

19:02 Chousuke: is there such a thing :/

19:03 the wikibooks are pretty bad.

19:03 aperotte: nibbs: no problem ... I've been looking for something exactly like this, it seems to be pretty fantastic

19:07 ehird: I think the best right now are the screencasts at http://clojure.blip.tv/

19:08 ehird: ew :\

19:08 durka: i recommend watching the screencasts with a repl open

19:09 aperotte: ehird: there are also a few blogs that are essentially tutorials

19:09 Chousuke: the videos are really good though.

19:10 aperotte: ehird: for example, http://writingcoding.blogspot.com/ has a series of articles that are interesting (though some of the code might be broken now because of the more recent changes in clojure)

19:10 ehird: ah

19:27 holmak: .msg NickServ identify inaktive/00

19:37 duck1123: looks like holmak gets to change his password

19:37 holmak: haha, already done

19:37 i feel terribly dumb

19:38 duck1123: that's why, if I ever do type it manually, I always switch to the server window

19:38 just in case

19:38 holmak: i usually do - as you can see, this time i messed up

19:41 ehird: holmak: i tried ghosting you :D

19:42 holmak: I think I successfully resecured my identity. I seriously doubt my nick carries any weight anywhere anyway ;D

19:43 duck1123: I wish OAuth/OpenID worked with IRC

19:50 doublefree: yow... for the record :-) I spent more than a few hours determining why (. gl glVertexPointer 3 GL/GL_FLOAT 0 0) fails ("No matching method found") ... one valid signature is [int int int long] and later I discover (by stepping through Reflector.java (invokeMatchingMethod)) that my invocation supplied [int int int int]. my fix was: (. gl glVertexPointer 3 GL/GL_FLOAT 0 (long 0)). this mixup was frustrating, but being able to

19:56 Chouser: you were cut off at "but being able to"

19:56 doublefree: oh... but being able to step through Clojure with a debugger was key! I bet if I had realized that 'no matching method' could mean 'no matching arguments' I could have saved some time.

19:57 dreish: It was a good story up to that point, though. Why spoil it?

19:57 doublefree: dreish: I aim to please ;p

20:07 duck1123: so what do you guys think? Is it worth including a new jar just to get the dateTime formatting I want, or should I try to do it myself?

20:07 Chouser: bleh. You really can't get the Java format stuff to do what you want?

20:08 duck1123: all I want is a date formatted according to the xsd:dateTime spec

20:09 I'm close, but not quite right. I can always take the string and run it through a replacement fn to fix it, but that seems wrong

20:09 I've found other libraries that do what I'm looking for, but it seems a waste of a dependency

20:10 sohail: duck1123, in Java, there is no such thing as too many dependencies

20:11 Chouser: duck1123: looks like others have done it: http://www.objectdefinitions.com/odblog/2007/converting-java-dates-to-xml-schema-datetime-with-timezone/

20:20 nibbs: aperotte: if you are into machine learning dont forget libsvm, it is veyr easy to isntall and use

20:29 xelapond: Hi everyone

20:30 I'm a hard-core python and c++ programmer, and I have dabbled in a little scheme, but 'ive never done java

20:30 Do I have to know Java to learn Clojure?

20:32 durka: no, but it will help with the java interop

20:32 xelapond: yeah, thats the part I was really excited about

20:33 durka: i mean, you're going to need to read a lot of javadocs

20:33 xelapond: ok

20:33 durka: and they expect a superficial knowledge of java at least

20:33 but if you know c++ that's almost enough

20:33 xelapond: ok

20:33 I assume there is a java tutorial?

20:34 durka: tons of them

20:34 xelapond: ok, Ill do that first:)

20:34 thanks

20:34 I assume I could probably learn both at the same time, right?

20:34 if I don't need to know one to learn the other

20:34 ericlavigne: xelapond: you can learn either of them first, or learn both at once

20:35 xelapond: ericlavigne: ok, thanks:)

20:37 Chouser: I'd start with clojure. it's more fun. when you're dealing with some java lib and realize you need to know what a final method is, or can't understand the example (because its written in Java), then go learn a little java.

20:39 xelapond: hm

20:39 is the syntax of clojure any different from Scheme(aside from different names?)

20:39 ericlavigne: xelapond: It's very close.

20:40 xelapond: ok

20:40 I guess ill learn Clojure first, it should be pretty quick

20:40 ericlavigne: xelapond: http://clojure.org/getting_started

20:40 xelapond: yep, I'm already there:)

20:41 * drewr is 4568 list msgs behind

20:42 * ericlavigne usually just scans the subject lines as they fly by

21:12 durka: how does contrib.seq-utils/group-by work?

21:12 (group-by class [1 2 "three" :four])

21:12 java.lang.ClassCastException: java.lang.Class (repl-1:154)

21:14 i guess it expects strings?

21:14 (group-by (comp #(.toString %) class) [1 2 "three" :four])

21:14 {"class clojure.lang.Keyword" [:four], "class java.lang.Integer" [1 2], "class java.lang.String" ["three"]}

21:17 kotarak: durka: the keys must be comparable since it is a sorted-map. How do you sort classes? I suppose group-by could also return a hash-map? That would solve this.

21:17 drewr: Good heavens, Volkmann is like half the msgs.

21:17 durka: oh, that makes sense

21:55 duck1123: does anyone know of a good example of sorting a seq of maps based on certain values

21:57 gnuvince: "certain" values?

21:57 Like a few of them?

21:58 Cause you can do it pretty easily:

21:58 user=> (sort #(compare (:a %1) (:a %2)) [{:a 2}, {:a 1}])

21:58 ({:a 1} {:a 2})

21:58 duck1123: like a particular value, perhaps using another if they match

21:58 hiredman: ,(sort-by :a '({:a "foo"}{:a "bar"}))

21:58 clojurebot: ({:a "bar"} {:a "foo"})

21:59 hiredman: (doc sort-by)

21:59 clojurebot: Returns a sorted sequence of the items in coll, where the sort order is determined by comparing (keyfn item). If no comparator is supplied, uses compare. comparator must implement java.util.Comparator.; arglists ([keyfn coll] [keyfn comp coll])

21:59 duck1123: thanks hiredman I didn't realize keywords would work in that case

22:00 hiredman: clojurebot: I missed you

22:00 gnuvince: Oops, I forgot about sort-by

22:00 Good call hiredman

22:00 duck1123: and sort-by didn't work with syntax similar to what gnuvince posted

22:01 chessguy: so...what's up with clojure? i've heard the name a couple times lately, but never looked into it

22:02 suntax looks like a cross between lisp and perl or something

22:02 hiredman: clojurebot: clojure?

22:02 clojurebot: clojure is the bestest programming language available.

22:03 hiredman: the comparison to perl hurts

22:03 chessguy: wow, that's clever

22:03 hiredman, don't take it personally, it's a very ignorance-based comment

22:03 duck1123: clojure is about as compact as perl, yet still readable

22:04 chessguy: impure, though, right? (as opposed to haskell)

22:05 durka: more or less

22:05 the ability to call arbitrary Java is a pretty big impurity

22:06 duck1123: chessguy, clojure is fully compatible with java libraries, which ruins any purity. But it turns out to not that big of a problem

22:07 chessguy: err, how is it any less of a "problem" than, say, java, or c#?

22:07 hiredman: because you can just use it when you need it and avoid it the rest of the time

22:08 duck1123: well, you can get a lot done without dropping into java interop

22:08 chessguy: oh, by "it" you mean java-compatibility, not impurity

22:08 duck1123: I don't have enough experience with other functional languages to really say on this issue

22:09 chessguy: ok, so more like a cross between java and lisp then

22:10 duck1123: exactly. It's a lisp based on the jvm

22:11 chessguy: interesting...

22:11 hiredman: there are videos online with rhickey giving an intro to clojure

22:11 clojurebot: blip.tv?

22:11 duck1123: and since it was designed from the start to have that compatability, it's a really nice fit

22:12 hiredman: hmmm

22:12 chessguy: i take it though that it's still pretty much a toy, not much real-world testing

22:12 duck1123: if only more java library designers had kept clojure in mind when they designed their api's

22:13 there are a few companies that are using it full time

22:13 still a very young language, but there's nothing stopping people from using it in production

22:13 chessguy: i don't even see any serious examples on the site, though i could be missing something

22:13 duck1123: except for maybe the difficulty in finding lisp programmers

22:15 chessguy: haha, all the dice.com searches for "clojure" return results with the word "closure" in it

22:16 hiredman: ugh

22:16 * duck1123 would love to have a job doing clojure

22:16 hiredman: something broke fact look ups in clojurebot

22:16 but at least oc and the sandbox still works

22:16 doc

22:20 chessguy: i'd prefer a haskell job any day :)

22:20 * chessguy loves his static typing

22:20 durka: clojurebot: latest?

22:20 clojurebot: latest is 1195

22:21 durka: clojurebot: clojure?

22:21 clojurebot: clojure > scheme

22:21 duck1123: I used to very much prefer static typing. Ruby started to bring me around, clojure brought me the rest of the way

22:21 durka: clojurebot: blip.tv?

22:21 chessguy: duck1123, oh? how so?

22:21 durka: maybe it's something about facts with dots in them?

22:22 clojurebot: blip.tv is http://clojure.blip.tv/

22:22 clojurebot: Ack. Ack.

22:22 duck1123: it's fun to take some java code, erase all the type declarations, move some parens, and watch the line count just drop

22:22 durka: clojurebot: blip.tv?

22:22 clojurebot: blip.tv is http://clojure.blip.tv/

22:22 hiredman: grr

22:22 durka: woof

22:22 duck1123: so long as the compiler knows what type it is, I don't feel the need to type it out

22:23 durka: clojurebot: doesnotexist?

22:23 chessguy: well that's more about type inference than static typing

22:23 hiredman: hmmm

22:23 durka: are the "i don't know" messages broken?

22:23 hiredman: that must be it

22:23 chessguy: clojurebot, foobar?

22:24 durka: can i ask an agent whether it's done without awaiting it?

22:26 cmvkk: hmm i have a similar question. what if i want to run a series of n functions concurrently, but wait until they are all done before continuing?

22:27 durka: cmvkk: start them all in separate agents and call await

22:27 cmvkk: or better, what if i want to run a series of n functions for each i in (range 50000), but they all need to be done with i before going on to i+1?

22:27 durka: await takes any agents as you awnt

22:27 cmvkk: hmm

22:28 i didn't know that existed.

22:28 durka: want*

22:28 that second one is harder...

22:28 cmvkk: the second one is the same problem anyway. just send all the agents, then await before looping.

22:28 durka: unless it isn't

22:28 yeah

22:28 also, i think the answer to my question is await-for

22:29 cmvkk: i see both now. thanks a lot.

22:29 i still kind of wonder if it's worth the overhead if the functions in question are very fast

22:30 given this scenario, is there a significant overhead vs. just calling them sequentially?

22:30 hmm, maybe that question is difficult to answer in general...

22:31 durka: i think you would just need to benchmark a specific circumstance

22:32 cmvkk: i think so too. which means to me the answer is 'flip a coin and get on with it'.

22:36 chessguy: wow, this blip.tv thing has been going for like 15 minutes, and he still hasn't moved from "why" to "what"?

22:37 durka: well, it's a long video

22:37 but worth iut

22:37 it

22:47 how do agent validators work?

22:51 chessguy: are clojure vectors random-access, or o(n)?

22:51 Chouser: chessguy: constant-time lookups by index

22:51 chessguy: cool

22:51 Chouser: chessguy: roughly contant-time append

22:52 chessguy: by which you mean log n ? :)

22:52 Chouser: well, the lookup by index is O(log-base-32)

22:52 durka: i think "roughly" refers to the structure-sharing Magic

22:53 chessguy: ok

22:54 Chouser: I shouldn't have said roughly. the constant factor on append probably flustuates a bit.

22:55 durka: what don't you understand about validators?

22:56 durka: just that i can't seem to make them work

22:56 for one thing, the set-validator function is gone?

22:56 dhaya: (doc set-validator!)

22:56 clojurebot: excusez-moi

22:57 Chouser: clojurebot's a bit behind the times, but dhaya's right.

22:57 durka: that gives me the same trouble as .setValidator

22:57 (set-validator! test-agent #(true))

22:57 java.lang.RuntimeException: java.lang.IllegalArgumentException: Wrong number of args passed to: user$eval--3848$fn (repl-217:121)

23:01 Chouser: (def a (ref 2 :validator even?))

23:01 (dosync (alter a inc)) ==> error

23:02 (dosync (alter a + 2)) ==> 4

23:02 durka: oh

23:02 well ok

23:02 i was trying to give an agent a validator

23:03 Chouser: (def a (agent 2 :validator even?))

23:03 hiredman: ggrrrr

23:03 Chouser: (send a inc), @a ==> Agent has errors

23:04 (clear-agent-errors a), (send a + 2), @a ==> 4

23:05 durka: interesting

23:06 not entirely sure what i was doing wrong

23:06 i guess it was a problem with the #() syntax

23:08 Chouser: Could be. #() functions take as many args as you mention. by not including %, your #() took zero args and it should have taken 1

23:09 cmvkk: it's too bad that's the case.

23:09 i keep thinking if i want to set a particular value to an agent, i have to do like (send agent (fn [x] 0))

23:10 durka: i wrote a useful function

23:10 (defn ignore [f] (fn [& args] (f)))

23:11 Chouser: (send agt (constantly 0))

23:12 cmvkk: ahaaa

23:12 thanks

23:18 * durka is abusing the concept of a validator to have my agent beep when it finishes

23:19 Chouser: durka: you want add-watcher

23:20 durka: yeah

23:21 i only decided to try validators because i had the same trouble as i did before with validators, which turned out to be a problem with #()

23:21 also, clojure.org is out of date, lists add-watch instead of add-watcher

23:22 Chouser: clojure.org attempts to document the latest release

23:22 it's still a bit out of date with that, but not as much.

23:24 durka: oh right

23:24 nobody care about the return value of a watcher, right?

23:25 Chouser: hm, I believe that's correct.

23:34 durka: that's impressive

23:34 i think clojure used seven hours of cpu time in twenty minutes

23:37 hiredman: clojurebot: nonexistant?

23:37 clojurebot: excusez-moi

23:38 durka: clojurebot: blip.tv?

23:38 clojurebot: blip.tv is http://clojure.blip.tv/

Logging service provided by n01se.net