#clojure log - Jul 19 2009

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

0:33 hamza: I have an array of integers i would like to find the biggest integer in the array using max but it does not work. is there a way to do it or do i have to roll my own function to iterate and find it?

0:35 durka42: hamza: what have you tried?

0:36 hamza: i was using (max array) but just found the answer (reduce max array) worked thx.

0:36 should have RTFM

0:40 hiredman: (apply max array)

0:40 I wonder if that works

0:41 ,(apply max (into-array [1 2 3 4]))

0:41 clojurebot: 4

0:49 hamza: is it possible to do this to a 2d array?

0:51 hiredman: a. there is no such thing, java arrays are 1d b. yes

0:53 ,(apply max (reduce #(apply max 5) (into-array (map into-array [[1 2] [3 4] [5 6]])))))

0:53 clojurebot: java.lang.IllegalArgumentException: Wrong number of args passed to: sandbox$eval--2791$fn

0:53 hiredman: ,(apply max (reduce #(apply max %) (into-array (map into-array [[1 2] [3 4] [5 6]])))))

0:53 clojurebot: java.lang.IllegalArgumentException: Wrong number of args passed to: sandbox$eval--2798$fn

0:53 hamza: i created an array in repl like (def atest (make-array Integer 5 5)) now if do (reduce max atest) i get class cast exception

0:53 hiredman: bah

0:54 ,(apply max (into-array (map into-array [[1 2] [3 4] [5 6]])))

0:54 clojurebot: java.lang.ClassCastException: [Ljava.lang.Integer; cannot be cast to java.lang.Number

0:54 hiredman: ,(map #(apply max %) (into-array (map into-array [[1 2] [3 4] [5 6]])))

0:54 clojurebot: (2 4 6)

0:54 hiredman: ,(apply max (map #(apply max %) (into-array (map into-array [[1 2] [3 4] [5 6]]))))

0:54 clojurebot: 6

0:56 hamza: thx alot ill try using this

1:37 fsm: Hi, I have a question about efficiency - I am writing 3d code, which makes heavy use of vectors e.g. [x y z]

1:37 right now I am using arrays to represent them and 'nth' to access the values

1:38 is there a more efficient way of reading doubles from a small, fixed-size array like this?

1:42 Jomyoot: There should be emacs built on Clojure

1:44 IS there IDE with syntax completion yet?

2:02 durka42: does slime do tab completion?

2:02 vimclojure does some

2:03 replaca: durka42: I've heard that you can get slime to do tab completion, but I haven't succeeded at it myself

2:03 I think technomancy knows how

3:19 Jomyoot: how to just grab unique entry from a seq?

3:20 duncanm: (first my-seq) ?

3:20 Jomyoot: hmm?

3:20 that would just get the first one?

3:20 duncanm: the first one is not unique?

3:20 Jomyoot: unique entries

3:21 duncanm: turn it into a set?

3:21 ,(set '(1 1 1 2 3 4 5 5))

3:21 clojurebot: #{1 2 3 4 5}

3:21 Jomyoot: then it becomes a hash

3:21 Then how would I make it back into a seq again?

3:21 duncanm: err

3:21 Jomyoot: seq() ?

3:22 duncanm: ,(seq (set '(1 1 1 2 3 4 5 5)))

3:22 clojurebot: (1 2 3 4 5)

3:22 Jomyoot: cool

3:22 kotarak: Jomyoot: all the seq functions take also maps, vectors, sets....

3:23 ,(map inc (set [1 1 1 2 3 4 5 5]))

3:23 clojurebot: (2 3 4 5 6)

3:24 duncanm: la la la

3:24 erohtar: jomyoot: distinct

3:25 ,(distinct [1 1 2 2 3 3 4 5])

3:25 clojurebot: (1 2 3 4 5)

3:25 duncanm: oh cool

3:25 erohtar: good job!

3:25 that's neat

3:48 mariorz: how can i tell how much of the heap a collection is taking?

5:21 Jomyoot: what is elegant way to do infinite loop?

5:26 kotarak: (while true ...)

5:26 There is no break, though.

5:27 If you want to leave the loop at some time do: (def *running* (atom true)) (while @*running* .... (when condition (reset! *running* false)))

5:46 berk: Hi, I am reading Okasaki's book, implementing examples as I go along. I want to create a seq interface (at least conj, first, rest) for the datastructures, in clojure (ie. not ISeq and java). What is the correct way of doing that?

5:51 kotarak: berk: use proxy: (defn seq-from-your-coll [coll] (proxy [clojure.lang.ASeq] (first [] ...) (more [] ...)))

5:55 berk: thanks kotorak, I didn't know about proxy.

5:55 kotarak: berk: it's useful to implement eg interfaces.

5:55 some kind of anonymous class.

5:55 If it's more involved you can also use gen-class.

5:56 Jomyoot: Lisp is cool

5:56 I wish I could use Lisp for everything

6:00 cp2: use lisp for your toaster

9:58 rhickey: chunks now in master

9:58 but not the mutable vector stuff

11:49 Jomyoot: I want a Classifier in Clojure

11:49 Naive Bayes or SVM

12:11 Chouser: the commit history in git confuses me

12:13 the only thing that appears to be new today is an empty commit

12:16 Jomyoot: Is there Naive Bayes in Clojure already?

12:23 Chousuke: Chouser: it's a merge commit :)

12:23 Chouser: the actual commits are ordered by creation date, so whatever was added is further down in the log.

12:24 Chouser: it helps to use gitk or something to look at it, I guess.

12:25 The merge commit message could have been a bit more informative though :P

12:26 But git autocommits merges by default

12:33 rhickey: Chouser: yeah, I don't get the the forks view either, but the commit was a merge of chunks prior to mutable vector work, so now chunks work is in master

12:46 Jomyoot: Philosophically, is Clojure tied to JVM?

12:46 Will Clojure eventually support other platform?

12:46 even native platform?

12:47 Chousuke: hmmh

12:47 to port clojure to "native" code you would have to implement an entire runtime providing GC etc. for it. :/

12:47 Jomyoot: Does RIch Hickey view JVM as "THE" platform?

12:48 or just one of the platforms

12:49 Chousuke: That I don't know. There are already attempts for "ports" to other platforms, but because clojure tries to tightly integrate with the host system, I don't think the ports can ever be 100% compatible with implementations on other hosts.

12:50 of course, if your clojure code never uses host interop and only core.clj, then it could be compatible with any clojure implementation, providing they supply a working version of core.clj

12:59 pronik: hi, is clojure-contrib supposed to be compilible with clojure 1.0 release (as opposed to current HEAD)?

13:01 Chousuke: the master branch is not.

13:01 there's a clojure-1.0-compatible branch

13:07 pronik: ok, thanks

13:12 Chousuke: No, no, no. Nothing of the sort. Idea is different and it's somewhat simpler:

13:12 1. Behavior is undefined so program can do anything it wants. It can destroy the world for god's sake!

13:12 2. Program which can destroy the world is pretty useless so obviously people will not write such program.

13:12 oops.

13:12 drag&drop fail :P

13:43 Drakeson: how would you recursively search (e.g., with a pred) on zips? (e.g. zip/xml-zip)

17:26 maacl: Is anybody else having problems with clojure-update from clojure-mode?

17:31 ah - the repo has been changed

17:54 Using emacs/slime what would cause (ns test (:use [clojure-contrib server-socket])) not to work while (use 'clojure.contrib.server-socket) works?

18:07 Chousuke: maacl: because you need a list, like (clojure-contrib server-socket), not a vector

18:08 maacl: Chousuke: oh, has this been changed at some point?

18:08 Chousuke: It has always been like that as far as I know.

18:08 it's a prefix list. a vector is used for libspecs

18:09 eg. (:use (prefix lib [lib2 :as somealias] lib3))

18:13 maacl: that is odd - the code for the clojure peepcode screencast - the mire mud uses a vector

18:23 Chousuke: changing it to a lost doesn't fix it - this is really weird

18:26 Chousuke: wait, hm

18:26 it's clojure.contrib, not clojure-contrib .P

18:27 :use etc. need to be redone anyway. :/

18:27 there was some discussion here earlier but I don't think anyone did anything. hmm

18:28 oh well, I'll get some sleep for now.

Logging service provided by n01se.net