#clojure log - Sep 12 2009

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

4:54 LauJensen: Top 'o da morning gents

4:59 Ok, lemme try that in #scala and see if I get some love

5:09 cgrand: come back Lau!

5:10 LauJensen: Alright alright - You know I can't leave you guys :)

6:48 angerman: how do I add additional jars to the default slime-repl clojure?

8:07 raphinou_: Hi!

8:10 arbscht: angerman: customize swank-clojure-extra-classpaths

8:10 angerman: alternately, link your jars in ~/.clojure, if that applies

9:15 * Chousuke is currently engaged in some major rewriting of history.

9:16 Chousuke: I decided it would help to have my reader development history a bit cleaner, so now I'm splitting, merging and reorganising the commits :P

10:00 angerman: arbscht: thanks

10:00 Hmm I have 44700 items and I want to draw 10000 pairs from it, how would I do that?

10:01 e.g. I have 447000 x 447000 paris. and I want to have 10000 different items from that set

10:09 le3: f

10:17 meredydd: Hi all.

10:17 Is it just me, or has HTTP header updating in Compojure never worked?

10:18 The handling method is defined with "(defmethod update-response Map", so it never triggers on Clojure persistent maps

10:18 But if I hand it an honest-to-goodness Java Map, it complains it can't cast it into an IPersistentHashMap.

10:24 duck1123_: Is it possible to actually run a repl (or a swank server) to an application on an android phone

10:44 le3: ,(doc alter)

10:44 clojurebot: "([ref fun & args]); Must be called in a transaction. Sets the in-transaction-value of ref to: (apply fun in-transaction-value-of-ref args) and returns the in-transaction-value of ref."

11:07 triyo: Anyone purchased the Alpha Program license for the new, up and coming, book "Practical Clojure"? Just wondering if it'd be worth it.

11:07 http://www.apress.com/book/view/9781430272311

11:30 manic12: now that you point it out (the book), I may get it

11:30 triyo: :)

11:31 I think I'm gonna join you in on that one.....You get the updates till final release anyway.

11:32 manic12: I disagree with Hickey's description of clojure as a lisp. I think clojure is definitely a clojure and may be influenced by lisp, but leaves that era behind

11:32 or, I guess you could say that if clojure is a lisp, it's pushing the envelope of what it means to be a lisp

11:33 Chouser: "Clojure: redefining LISP"

11:33 manic12: sequence processing

11:34 lazy sequence processing (LSP)

11:35 yesterday I had to make a file in the default package called "user.clj" and in the ns declaration I used com.akw.init namespace...

11:36 ...init.clj then had to include com.akw.user, and have an "init" defn which called a defn in com.akw.user to load my foreign libs and change the ns

11:37 it was the only way I could get the repl to start, where I could type one function (init) and have my foreign code be loaded and work

11:38 so it took three files to do one thing, and I'm wondering if I am doing something wrong

11:39 Chouser: you can provide multiple options at the clojure.main command line

11:39 manic12: enclojure definitely needs a dialog box option to pass in a custom init to the clojure.main/repl

11:40 I'm really having a hard time with this java package & clojure namespace stuff

11:40 Chouser: something like -e "(use 'com.akw.user)" -r ought to do it.

11:41 manic12: does enclojure have a place to put that?

11:41 Chouser: I don't know.

11:42 manic12: I'll ask that one on google groups and/or submit a patch

11:42 Chouser: good idea

11:42 I really do mean to try enclojure again soon...

11:43 manic12: it just seemed very "unlispy" for the "project repl" to not have any correspondence to the project main

11:43 it knows where the libs are, but it doesn't use them by default

11:44 (the project repl that is)

11:45 also, the foreign lib I use is quite large

11:46 for every namespace I use that lib from, I have to have a huge import list in the ns form

11:47 so I will probably make a macro that wraps (ns ...) that is like (smlib-ns ...) that includes the package classnames

11:49 just seems weird I can't export the classnames as a whole to any nanespace with just one *short* import

11:55 I think that my native calls will only work from the namespace I loaded the libs from, so one is forced to use that namespace, maybe it's my imagination

11:55 Chouser: have your macro just generate an appropriate call to the 'import' fn. In fact, you might be able to write a fn instead of a macro.

11:56 oh, 'import' is a macro now, so you'll have to write a macro.

11:58 however, it's quite intentional that there's no "import foo.*" -- that makes class names available without it ever being explicit where they're coming from, which can lead to confusion and unexpected conflicts.

11:58 manic12: (it was my imagination...i think)

11:58 Chouser: I like 'use' does this too (for fn names), but I wish it didn't. :-)

11:59 manic12: well in this case, all my classes are explicitly defined to java from swig

11:59 so it's not protecting me from anything real

12:00 I'll look at the sources to import and see if I can make my own import

12:01 (which would break anytime clojure changes, but that's better than putting all these class names in a file)

12:08 is there a way to get a sequence of all the classes in a java package?

12:15 Chouser: manic12: no, you have to examine the .jar itself, or the file system.

12:15 once you have a list of the classes, your macro can expand to a regular call to 'import' so that it won't break when clojure changes.

12:15 manic12: yah

13:39 ole2: h

13:43 manic12: is there a way to stack allocate instances of java classes inside a clojure function?

13:47 Chouser: I don't think you can allocate objects on the stack in the JVM at all, in any language

13:48 manic12: this is tricky

13:48 (native call stuff)

13:51 i guess it doesn't matter since swig has defined finalizations on the objects

13:52 the tricky part is that my native calls will be looking for arrays of structs

13:52 and the jvm ain't gonna line-em-up for me

13:55 i can work around.

13:56 it was just cool with double-float arrays in allegro and displaced arrays and such

14:27 so in the form (let [x 1 y 2] ... you cannot rebind x to 3 in there?

14:30 ole2: ,(let [x 1 y 2 x 3] x)

14:30 clojurebot: 3

14:31 manic12: (let [x 1 y 2] (do-something-with x) (change x) (do-something-with x))

14:32 ole2: i dont think so, but you can rebind it with a let

14:32 ,(let [x 9] (let [x 10] x))

14:32 clojurebot: 10

14:32 ole2: there is no setf or setq

14:33 i think

14:33 ,(doc set!)

14:33 clojurebot: Gabh mo leithscéal?

14:33 ole2: ,(doc set!)

14:33 clojurebot: Titim gan éirí ort.

14:33 ole2: ,(doc setf)

14:33 clojurebot: Pardon?

14:56 Chouser: names introduced by 'let' are not variables, their values cannot change

14:56 the closest you can get it to shadow the old local with a new one of the same name

14:57 ,(let [a 1] (prn a) (let [a 2] (prn 2)))

14:57 clojurebot: 1 2

17:33 ole3: n

19:11 kanzenryu: Hello all. I'm thinking of writing a clojure program for Java coders that would demo language features that are awkward to do in Java.

19:11 Probably a visual demo that can demonstrate on-the-fly logic changes, showing shapes that are processed according to various rules

19:11 - Realtime code updating via a socket REPL while running

19:11 - Macros for simple rule DSL

19:11 - Agents/STM for multithreaded behaviour.

19:11 - Multimethods, hierarchies and derive

19:11 - Maybe error-kit for flexible error handling

19:12 - Metadata for extra decision logic

19:12 - Maybe the dataflow contrib

19:12 Any more suggestions?

19:16 Chouser: sounds interesting

19:17 kanzenryu: Various groups of shapes appear on the left, and get handled by some rules and sent to various places on the right

19:17 Chouser: I like the javadoc and show functions at the REPL.

19:18 kanzenryu: The shapes will be sandwiches with various contents. I call it the Edible Sandwich Business

19:22 My plan is to showcase whatever aspects of Clojure would make the average Java guy think "man, how would I code that?"

19:28 briancarper: If I do (def x "助") with any Japanese kanji, and then view x at a REPL, it shows "???". Also (count x) gives me 3, should be 1. Any idea where I can begin to debug this?

19:30 Chouser: that's a plain terminal repl?

19:30 ,(.getEncoding *out*)

19:30 clojurebot: java.lang.IllegalArgumentException: No matching field found: getEncoding for class java.io.StringWriter

19:30 briancarper: Plain REPL, yes.

19:30 Chouser: I'd look at the encoding of the in and out streams the repl is using, make sure they match what you expect.

19:30 hiredman: briancarper: are you using jline or anything like that?

19:31 briancarper: .getEncoding returns "ASCII". Probably not right. What's a safe way to change it?

19:31 hiredman: huh

19:31 briancarper: hiredman: Nope, no jline.

19:32 hiredman: I wonder were it gets the ASCII

19:32 briancarper: No idea. On one of my systems it's "UTF8" but my server gives me "ASCII".

19:32 Chouser: briancarper: that's the encoding of *in* or *out*? Or both?

19:32 hiredman: what platform is this? which jvm, which os?

19:32 Chousuke: briancarper: works for me.

19:32 briancarper: are you using a UTF-8 locale?

19:33 though hm, the count is still 3

19:33 briancarper: hiredman: Just *out*, not sure how to inspect it on *in*, no .getEncoding method apparently.

19:33 hiredman: Chousuke: 1 here

19:34 briancarper: Chousuke: Not sure which encoding the system is using. How could I check? It's a Linux box. Checked for LC* variables but there are none set.

19:35 Chousuke: (System/getProperty "file.encoding") I guess.

19:35 mine is apparently MacRoman...

19:35 briancarper: "ANSI_X3.4-1968", bwuh

19:36 Chousuke: try launchign java with java -Dfile.encoding=UTF8

19:36 that works for me.

19:37 user=> (def foo "テスト") user=> (count foo) -> 3

19:38 briancarper: Awesome, that worked. Thanks! Thanks everyone else too.

19:39 Chousuke: generally everything should be fine unless you try to use characters beyond the basic multilingual plane in your identifiers (I think strings will still work)

19:40 briancarper: Yeah I only need it in strings. Wouldn't try it in identifiers.

19:40 Chousuke: and even if you were writing code with characters from the higher planes I would have to ask you why you're writing code that maybe a dozen people in the world can read...

19:41 hiredman: ,(let [テ1] テ)

19:41 clojurebot: java.lang.IllegalArgumentException: let requires an even number of forms in binding vector

19:41 hiredman: ,(let [テ 1] テ)

19:41 clojurebot: 1

19:42 Chousuke: テ is not beyond the BMP :)

19:44 AFAIK any character that can be represented with one UTF-16 character (as opposed to "multibyte encoding" it) is supported by Clojure in identifiers

19:44 luis: Chousuke: come on, writing code with egyptian hieroglyphs should be fun!

19:45 Chousuke: handling all of unicode is a bit of a chore in java because char is just 16-bit, but for most purposes it works fine.

20:21 cschreiner: Does this list channel have a log?

20:21 hiredman: ~logs

20:21 clojurebot: logs is http://clojure-log.n01se.net/

20:21 cschreiner: thx

20:25 there is much nice stuff in the logs

20:25 thought I spend the next week reading them

20:38 ChrisPS: testing

20:38 ok good

20:45 wtetzner: what's the reasoning for having peek and pop?

20:45 are they any different from first and rest?

20:46 licoresse: I believe they have different semantics

20:47 wtetzner: you mean the names just match what you would use with a stack?

20:47 or are there technical differences?

20:47 oh

20:47 i get it

20:48 on a vector, peek and pop happen at the end of the vector

20:49 licoresse: right

20:50 pop on vector and lists behave differently

20:50 ,(doc pop)

20:50 clojurebot: "([coll]); For a list or queue, returns a new list/queue without the first item, for a vector, returns a new vector without the last item. If the collection is empty, throws an exception. Note - not the same as next/butlast."

21:03 Chouser: peek and pop are only like first and rest for list. they are different for vectors and queues

21:29 wtetzner: how do i create a queue?

21:32 Chouser: ,(-> clojure.lang.PersistentQueue/EMPTY (conj 1) (conj 2))

21:32 clojurebot: (1 2)

21:32 Chouser: ,(-> clojure.lang.PersistentQueue/EMPTY (conj 1) (conj 2) pop class)

21:32 clojurebot: clojure.lang.PersistentQueue

21:32 Chouser: ,(-> clojure.lang.PersistentQueue/EMPTY (conj 1) (conj 2) rest class)

21:32 clojurebot: clojure.lang.PersistentQueue$Seq

21:33 wtetzner: oh, so there's not built-in function for creating them?

21:37 Chouser: right. I think rhickey is still a bit undecided on the right way to expose queue-like things in general.

21:38 wtetzner: oh, ok

21:42 Chouser: but PersistentQueue works well. More efficient than, say, a finger tree...

21:43 hiredman:

21:46 => (h (g "suddenly"))

21:47 "CLABANGO!"

21:48 so I think maybe sometime in the comming week, if I can disentangle all the factoid code from clojurebot's core, clojurebot will start using derby for storage

21:49 durka42: why a relational database?

21:50 hiredman: because it's there?

21:51 durka42: :)

21:51 hiredman: it's just a five column table

21:51 durka42: it seems to me clojurebot would have more of a fit for a key-value store, but i know much more about RDBs than key-value DBs, so clabango

21:54 hiredman: "oh look, derby! and what's that? clojureql!"

21:55 all though I think either I don't understand clojureql, or it has a wart or two

21:56 clojurebot: how much do you know?

21:56 clojurebot: I know 352 things

21:56 hiredman: => (count (query (derby "/tmp/triples.db") :y "is" :x))

21:56 423

21:57 so once this gets done, clojurebot should be able to store relations besides "is"

21:58 durka42: cool

22:07 ChrisPS: ...

23:15 miltonsilva: hey

23:16 JAS415: hi :-)

23:16 miltonsilva: I'm having a bit of troble understanding his piece of code "(fn [[a b]] [b (+ a b)])"

23:16 JAS415: ok

23:16 well

23:17 it destructures vector [b a]

23:17 and then makes a vector of

23:17 b and (a + b)

23:17 oh

23:17 and is an anonymous function

23:17 miltonsilva: wait..

23:18 JAS415: vector [a b] i mean

23:18 i made a typo

23:18 [[a b]] is a destructuring pattern

23:21 miltonsilva: the problem I'm having is that acording to the fn defenition there should be something like this (fn name? [params* ] exprs*) so why is this different?

23:21 JAS415: the name is optional

23:21 hence the ?

23:22 miltonsilva: :) yes but why two [...] [...] is the seconde an expression?

23:23 second*

23:23 JAS415: yes

23:23 second is an expression

23:23 hiredman: the first is too, btw

23:23 JAS415: is syntactic sugar

23:24 hiredman: [] is a vector

23:24 JAS415: well i guess but i feel like that is confusing the matter

23:24 hiredman: fns use a vector to specify the argument list

23:25 (fn [x] x)

23:25 JAS415: well the vector gets macroexpanded into some sort of bindy-form, so afterwards its no longer really a vector, wholly i guess

23:25 hiredman: the function you pasted is like (fn [x] [x])

23:25 JAS415: no

23:25 JAS415: hmm

23:25 are you sure?

23:26 hiredman: when the function is compiled it is turned into something else

23:26 JAS415: right...

23:26 but if you look at the destructuring bind macro

23:27 it gets used in the (fn [[a b]] ) thing

23:27 hiredman: sure

23:27 Chouser: in (fn [x] [y]) I guess [x] is an s-expression, but it doesn't get evaluated. [y] is a normal expression that gets evaluated in the normal way.

23:27 hiredman: but destucture just emits a more complicated vector

23:27 ,(destructure '[[x y] [a b]])

23:27 clojurebot: [vec__2425 [a b] x (clojure.core/nth vec__2425 0 nil) y (clojure.core/nth vec__2425 1 nil)]

23:27 hiredman: ^- vector

23:28 Chouser: ,(macroexpand '(fn [[x y]]))

23:28 clojurebot: (fn* ([p__2431] (clojure.core/let [[x y] p__2431])))

23:28 Chouser: nested list, let, and vectors.

23:29 hiredman: :(

23:29 gnarly

23:29 then let calls destrucutre

23:29 miltonsilva: ok first... I lack some fundamental knowledge what is destructing?

23:29 hiredman: my poor beautiful code

23:29 ~destructuring

23:29 clojurebot: destructuring is http://clojure.org/special_forms#let

23:30 miltonsilva: oh handy bot

23:31 hiredman: you can basically pull apart a datastructure and bind names to parts of it

23:32 JAS415: its the best for macros

23:32 hiredman: ,(let [[x y] [1 2 3]] (+ 1 2))

23:32 clojurebot: 3

23:32 hiredman: er

23:32 ,(let [[x y] [1 2 3]] (+ x y))

23:32 clojurebot: 3

23:32 hiredman: that puts 1 and 2 from the vector [1 2 3] and binds them to x and y

23:33 miltonsilva: so [[a b]] [b (+ a b)] is actually binding /a to /b and /b to (+ a b) ?

23:34 hiredman: no

23:34 (fn [[a b]] … )

23:34 JAS415: returns new vector

23:34 miltonsilva: (my... imperative guys sure are dumb :( )

23:34 hiredman: it's a function that takes 1 arg

23:34 miltonsilva: hmm

23:35 hiredman: the one arg is pulled apart and the first element of the arg is bound to a and the second is bound to b

23:35 ,((fn [[a b]] a) [1 2])

23:35 clojurebot: 1

23:35 miltonsilva: hmmmmmmmmmmmm

23:35 now I see

23:36 hiredman: so you have a binding form that mirrors the structure of the value you are binding

23:36 ,((fn [[a]] a) "hello")

23:36 clojurebot: \h

23:41 miltonsilva: ok I understand how these nested forms work... but could you explain again what the second vector does? ] [b (+ a b)] [3 5])

23:42 JAS415: it makes a new vector

23:43 wait

23:43 can you post the whole form

23:43 miltonsilva: (fn [[a b]] [b (+ a b)])[1 2] [2 3] [3 5])

23:43 ups

23:43 (fn [[a b]] [b (+ a b)])

23:44 JAS415: [b (+ a b)] is like making a new vector with those as contents

23:46 miltonsilva: oh... so the declaration of a vector is an expression... that's what confused me... thank you hiredman & JAS415

Logging service provided by n01se.net