2009-07-19
| 00: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? |
| 00:35 | durka42 | hamza: what have you tried? |
| 00:36 | hamza | i was using (max array) but just found the answer (reduce max array) worked thx. |
| 00:36 | hamza | should have RTFM |
| 00:40 | hiredman | (apply max array) |
| 00:40 | hiredman | I wonder if that works |
| 00:41 | hiredman | ,(apply max (into-array [1 2 3 4])) |
| 00:41 | clojurebot | 4 |
| 00:49 | hamza | is it possible to do this to a 2d array? |
| 00:51 | hiredman | a. there is no such thing, java arrays are 1d b. yes |
| 00:53 | hiredman | ,(apply max (reduce #(apply max 5) (into-array (map into-array [[1 2] [3 4] [5 6]]))))) |
| 00:53 | clojurebot | java.lang.IllegalArgumentException: Wrong number of args passed to: sandbox$eval--2791$fn |
| 00:53 | hiredman | ,(apply max (reduce #(apply max %) (into-array (map into-array [[1 2] [3 4] [5 6]]))))) |
| 00:53 | clojurebot | java.lang.IllegalArgumentException: Wrong number of args passed to: sandbox$eval--2798$fn |
| 00: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 |
| 00:53 | hiredman | bah |
| 00:54 | hiredman | ,(apply max (into-array (map into-array [[1 2] [3 4] [5 6]]))) |
| 00:54 | clojurebot | java.lang.ClassCastException: [Ljava.lang.Integer; cannot be cast to java.lang.Number |
| 00:54 | hiredman | ,(map #(apply max %) (into-array (map into-array [[1 2] [3 4] [5 6]]))) |
| 00:54 | clojurebot | (2 4 6) |
| 00:54 | hiredman | ,(apply max (map #(apply max %) (into-array (map into-array [[1 2] [3 4] [5 6]])))) |
| 00:54 | clojurebot | 6 |
| 00:56 | hamza | thx alot ill try using this |
| 01: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] |
| 01:37 | fsm | right now I am using arrays to represent them and 'nth' to access the values |
| 01:38 | fsm | is there a more efficient way of reading doubles from a small, fixed-size array like this? |
| 01:42 | Jomyoot | There should be emacs built on Clojure |
| 01:44 | Jomyoot | IS there IDE with syntax completion yet? |
| 02:02 | durka42 | does slime do tab completion? |
| 02:02 | durka42 | vimclojure does some |
| 02:03 | replaca | durka42: I've heard that you can get slime to do tab completion, but I haven't succeeded at it myself |
| 02:03 | replaca | I think technomancy knows how |
| 03:19 | Jomyoot | how to just grab unique entry from a seq? |
| 03:20 | duncanm | (first my-seq) ? |
| 03:20 | Jomyoot | hmm? |
| 03:20 | Jomyoot | that would just get the first one? |
| 03:20 | duncanm | the first one is not unique? |
| 03:20 | Jomyoot | unique entries |
| 03:21 | duncanm | turn it into a set? |
| 03:21 | duncanm | ,(set '(1 1 1 2 3 4 5 5)) |
| 03:21 | clojurebot | #{1 2 3 4 5} |
| 03:21 | Jomyoot | then it becomes a hash |
| 03:21 | Jomyoot | Then how would I make it back into a seq again? |
| 03:21 | duncanm | err |
| 03:21 | Jomyoot | seq() ? |
| 03:22 | duncanm | ,(seq (set '(1 1 1 2 3 4 5 5))) |
| 03:22 | clojurebot | (1 2 3 4 5) |
| 03:22 | Jomyoot | cool |
| 03:22 | kotarak | Jomyoot: all the seq functions take also maps, vectors, sets.... |
| 03:23 | kotarak | ,(map inc (set [1 1 1 2 3 4 5 5])) |
| 03:23 | clojurebot | (2 3 4 5 6) |
| 03:24 | duncanm | la la la |
| 03:24 | erohtar | jomyoot: distinct |
| 03:25 | erohtar | ,(distinct [1 1 2 2 3 3 4 5]) |
| 03:25 | clojurebot | (1 2 3 4 5) |
| 03:25 | duncanm | oh cool |
| 03:25 | duncanm | erohtar: good job! |
| 03:25 | duncanm | that's neat |
| 03:48 | mariorz | how can i tell how much of the heap a collection is taking? |
| 05:21 | Jomyoot | what is elegant way to do infinite loop? |
| 05:26 | kotarak | (while true ...) |
| 05:26 | kotarak | There is no break, though. |
| 05:27 | kotarak | If you want to leave the loop at some time do: (def *running* (atom true)) (while @*running* .... (when condition (reset! *running* false))) |
| 05: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? |
| 05:51 | kotarak | berk: use proxy: (defn seq-from-your-coll [coll] (proxy [clojure.lang.ASeq] (first [] ...) (more [] ...))) |
| 05:55 | berk | thanks kotorak, I didn't know about proxy. |
| 05:55 | kotarak | berk: it's useful to implement eg interfaces. |
| 05:55 | kotarak | some kind of anonymous class. |
| 05:55 | kotarak | If it's more involved you can also use gen-class. |
| 05:56 | Jomyoot | Lisp is cool |
| 05:56 | Jomyoot | I wish I could use Lisp for everything |
| 06:00 | cp2 | use lisp for your toaster |
| 09:58 | rhickey | chunks now in master |
| 09:58 | rhickey | but not the mutable vector stuff |
| 11:49 | Jomyoot | I want a Classifier in Clojure |
| 11:49 | Jomyoot | Naive Bayes or SVM |
| 12:11 | Chouser | the commit history in git confuses me |
| 12:13 | Chouser | 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 | Chousuke | Chouser: the actual commits are ordered by creation date, so whatever was added is further down in the log. |
| 12:24 | Chousuke | Chouser: it helps to use gitk or something to look at it, I guess. |
| 12:25 | Chousuke | The merge commit message could have been a bit more informative though :P |
| 12:26 | Chousuke | 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 | Jomyoot | Will Clojure eventually support other platform? |
| 12:46 | Jomyoot | even native platform? |
| 12:47 | Chousuke | hmmh |
| 12:47 | Chousuke | 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 | Jomyoot | 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 | Chousuke | 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 | Chousuke | 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 | Chousuke | 1. Behavior is undefined so program can do anything it wants. It can destroy the world for god's sake! |
| 13:12 | Chousuke | 2. Program which can destroy the world is pretty useless so obviously people will not write such program. |
| 13:12 | Chousuke | oops. |
| 13:12 | Chousuke | 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 | maacl | ah - the repo has been changed |
| 17:54 | maacl | 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 | Chousuke | it's a prefix list. a vector is used for libspecs |
| 18:09 | Chousuke | 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 | maacl | Chousuke: changing it to a lost doesn't fix it - this is really weird |
| 18:26 | Chousuke | wait, hm |
| 18:26 | Chousuke | it's clojure.contrib, not clojure-contrib .P |
| 18:27 | Chousuke | :use etc. need to be redone anyway. :/ |
| 18:27 | Chousuke | there was some discussion here earlier but I don't think anyone did anything. hmm |
| 18:28 | Chousuke | oh well, I'll get some sleep for now. |