#clojure logs

2009-09-26

01:37LauJensenMorning gents
01:57wavister1~def doubles
02:25LauJensen,(use 'clojure.contrib.pprint)
02:25clojurebotnil
02:29LauJensenjava.lang.ClassNotFoundException: clojure.contrib.pprint.PrettyWriter (pprint.clj:14)
02:29LauJensenI get that when calling the above use statement, using latest contrib - w00t?
02:37LauJensenCan somebody from the contrib team tell me if this is an error in your build (which Google leads me to think), or if Im missing something?
02:42leafwhow can one declare the type of an array? like #^String[] ?
02:43leafwwill that work?
02:45leafwdoesn't work
02:46arbscht,(doc into-array)
02:46clojurebot"([aseq] [type aseq]); Returns an array with components set to the values in aseq. The array's component type is type if provided, or the type of the first value in aseq if present, or Object. All values in aseq must be compatible with the component type. Class objects for the primitive types can be obtained using, e.g., Integer/TYPE."
02:48LauJensen,(doc make-array)
02:48clojurebot"([type len] [type dim & more-dims]); Creates and returns an array of instances of the specified class of the specified dimension(s). Note that a class object is required. Class objects can be obtained by using their imported or fully-qualified name. Class objects for the primitive types can be obtained using, e.g., Integer/TYPE."
02:49LauJensenarbscht: Since you're up - Can you test if you can use pprint ?
02:49arbschtI suppose I could
02:55arbschtLauJensen: got a test case?
02:55LauJensenyea, fire up a REPL having contrib in your cp, eval (use 'clojure.contrib.pprint) and see what happends
02:56LauJensenMine will bork saying it cant find PrettyWriter.clj
02:56LauJensen@ arbscht
02:56arbschtworks for me
02:56LauJensenHow old is your contrib?
02:56arbschtup to date as of 5 minutes ago
02:57LauJensenman thats weird
02:57LauJensenso it must be a local cp thing for me...
02:57LauJensenThanks for helping
04:28leafwLauJensen: about "#^String[]", I didn't explain it correctly. I want to add a type tag to a variable's metadata, just like one would add #^String to a "text", how can one do so to what is returned by make-array ?
04:29leafwor into-array, same thing?
04:29leafwfor primitives, there is #^ints, etc.
04:33LauJensenleafw: I don't think you can do that with make-array
04:33leafwno, not make-array ..
04:34leafwjust to declare the type of a variable, and that type being any array type, like String[], Potato[], ...
04:36LauJensenMake array returns a String[] array, but has nothing to do with meta data
04:36leafwLauJensen: I know tht. Never mind. You don't know the answer, or don't understand my question.
04:36LauJensenI gotta jet, sorry if I seem a bit confused, very distracted
04:36LauJensenas you just noticed :) good weekend
04:36leafw(let [#^String[] (get-some-string-array)] ... )
04:37hiredmanuh
04:37leafwthat, fails. One can't declare array types. That is all.
04:37leafwso I wonder whether it's possible at all.
04:37leafw(let [#^String[] arr (get-some-string-array)] ... )
04:37leafw--missed the actual var.
04:38hiredmanhave you profiled and found that there is a bottleneck with the array?
04:38leafwhiredman: it's about avoiding pain in the future. I want to declare types here.
04:38leafwand you didn't answer the question either :)
04:38hiredmanwhile there is a big difference between boxed integers and primitives I doubt it's huge between Objects and Strings
04:38hiredmanwhat question?
04:39leafwhow to give an array type to a var?
04:39hiredmanthere is no class named String[] so there is no way that type hint will work
04:39leafwi.e. #^String text "text" would do it. How about arrays of String?
04:39hiredmanarrays are funky
04:39leafwwell: in java, one can (String[]) cast to that.
04:39hiredman,(class (into-array ["foo"]))
04:39clojurebot[Ljava.lang.String;
04:39leafwok, so the answer is no, I can't. Ok.
04:39hiredman^-
04:40leafwhum
04:40leafwright--so that is the type
04:40hiredmanyes
04:40leafwI wonder if with semicolon or not
04:40leafwclojure would hiccup at the ;
04:40hiredmanthe arrays of primitives are just special cased with #^ints in the compiler
04:41leafw,(let [#^[java.lang.String; arr (into-array ["foo"])] (println arr))
04:41clojurebotEOF while reading
04:41hiredmanI would not bother, unless profiling has revealed it to be an issue
04:41leafwit's not about performance, hiredman. It's about type safety/integrity.
04:42leafw,(let [#^[Ljava.lang.String; arr (into-array ["foo"])] (println arr))
04:42clojurebotEOF while reading
04:42hiredmanperhaps you would be more interested in #scala
04:42leafw*sigh* no.
04:42leafwI'll make my own macros to test for what I want.
04:43hiredman~ticket #172
04:43clojurebot{:url http://tinyurl.com/ya742mz, :summary "#^objects type hint shortcut", :status :fixed, :priority :normal, :created-on "2009-08-11T09:44:36+00:00"}
04:45leafwcool -- thanks. So #^"[Ljava.lang.Object;" is possible, and soon a better way. Nice.
04:46hiredman,(let [#^"[Ljava.lang.String;" arr (into-array ["foo"])])
04:46clojurebotnil
04:47leafwhum, cgrand's patch is limited to Object[] only ..
04:47hiredmancorrect
04:48leafwmenos da una piedra -- at least it's something.
04:58cgrandleafw: I thought about allowing #^[String] but never discussed it nor implemented it
04:59leafwcgrand: sounds like a List<String> rather than a String[]. Perhaps another array representation is needed.
05:00leafwthe plural 's' would be a hint, but of course there's no guarantee that someone won't create a class whose name finishes with s (like Class)
05:00cgrandexcept List<String> doens't exist for the JVM
05:00leafwI am interested in developer's perception when reading code, not JVM
05:00hiredmanI think looking to type hints to enforce types is a bad idea
05:00hiredmanthey are there to coerce the compiler
05:01leafwor the reader.
05:01leafwthe point is, if one can type hint, one should be able to type hint any type. Arrays included.
05:01leafwthis exception is just weird.
05:01hiredmanyou can
05:02hiredman,(let [#^"[Ljava.lang.String;" arr (into-array ["foo"])])
05:02clojurebotnil
05:02leafwtrue, but it's not elegant.
05:02hiredmanideally you should not need any type hints
05:03leafwhiredman: for single-developer project, indeed no. For multiple-dev or for broad-time-single-dev (i.e. next year myself), yes.
05:04hiredmanno
05:04hiredmanyou need to specify types, but not via hints
05:04hiredmanhints are the wrong mechanism for it
05:04hiredmanthey are for bashing the compiler over the head
06:16LauJensenleafw: I appologize about that earlier, you have my full attention now :)
06:17leafwLauJensen: no problem, read back the log :) problem solved.
06:17LauJensen~logs
06:17clojurebotlogs is http://clojure-log.n01se.net/
06:17LauJensenOk, glad to hear it
06:20LauJensenHmm, still reading, you're still dragging hiredman along :)
06:22LauJensencheck, I'm up to date. I seems weird though that you want to introduce static typing into Clojure, but why just just use comments if it's purely for perception? (let [foo bar] ; String[] ...?
06:23leafwdev perception ... and enforcement.D ebugging clojure is sometimes very hard, like C with gdb: the stack trace leads to the wrong place.
06:23LauJensenThats certainly true
06:47mrsolo... Perhaps these are why pointfree style is sometimes (often?) referred to as pointless style.
06:47mrsolo :-)
06:49mrsolooops wrong channgel
09:43ngocLisp has many dialects, which Lisp is the most similar to Clojure?
09:52arbschtngoc: clojure :)
09:52hoeckngoc: IMO scheme, as it is a lisp-1 too
10:04ambienti've been wondering if clojure truly is completely homoiconic
10:05ambientif i wanted to convert clojure code to my own defined bytecode reader macros and concurrency structures might hinder that
10:07ambientto use a clojure subset to write domain specific code
10:27rhickeyambient: the reader reads data structures, whether they are defined by "reader macros" or not
10:44chouserrhickey: you are considering having ` at read time expand only to (syntax-quote ...), correct?
10:45rhickeyChouser: yes
10:47chouserok. I think that might make this make-myfoo cleaner to write: http://paste.lisp.org/display/87734
11:04rhickey(defmacro make-myfoo [] `(defmacro ~'myfoo [s#] `(~~''foo ~s#)))
11:11rhickeyChouser: no?
11:11rhickey^^
11:11emacsendon't we have any kind of time representation stuff in contrib yet??
11:18chouserrhickey: I don't think so -- that pushes the unqualified symbol all the way through to myfoo's expansion.
11:19rhickeyah
11:19Chouserso if I did (make-myfoo) in each of ns1 and ns2, hoping for them to refer to ns1/foo and ns2/foo, I'll be disappointed
11:21ChouserI want to control the timing when ` does its qualifying magic to be when (make-myfoo) is expanded.
11:30rhickeyChouser: yeah, we have to move syntax-quote out of read time for that
11:42ChouserChousuke: did you say you had syntax-quote implemented as a macro?
12:56djorkhi
12:57djorkI'm trying to run the penumbra examples, but I can't figure out how to resolve the classpath. I'm in the src directory of penumbra, running like this: java -cp /Library/Java/Extensions/*.jar:../lib/osx/*.jar:. clojure.lang.Repl examples/gears.clj
12:57djorkjava says java.io.FileNotFoundException: Could not locate penumbra/opengl__init.class or penumbra/opengl.clj on classpath: (gears.clj:0)
12:58djorkalthough penumbra/opengl.clj is clearly there and that path should resolve quite easily
13:01djorkclojure loads fine
13:18djorkOK so I figured out the (massive) classpathit needs
13:23djorkyay, finally gears
13:23djorkI don't know which imaginary world these instructions work in: http://wiki.github.com/ztellman/penumbra/getting-started
13:23djork:)
13:23djorkno mention of the clojure-contrib dependency
13:26danleihow would I give re-matches regex options (like DOTALL)?
13:31cemerickdanlei: re-matches takes a Pattern as a first arg -- you need to supply options when the Pattern is created
13:43Chouserdanlei: one way to do that is to put (?s) at the front of the pattern, like #"(?s).*"
13:45danleiok, thanks
14:31hamza`i have a bunch of functions that transform a string each one replaces a regex in the string. is there a reverse of map such that it will apply the list of functions to the string and return the result?
14:31LauJensenChouser: Wouldn't ->> do what hamza` is asking for ?
14:32hamza`(doc ->>)
14:32clojurebotNo entiendo
14:32hamza`,(doc ->>)
14:32clojurebotexcusez-moi
14:36Chouser->> is new -- clojurebot doesn't have it yet
14:37hamza`i have -> in docs but not ->> which one i should be looking for?
14:37Chouserhamza`: you want the result of each fn to be fed into the next?
14:38emacsenChouser: so, no datetime lib?
14:38hamza`yes start with a string apply each replace fcuntion and get the resulting string..
14:39hamza`each one will use the output of the the one before it..
14:39Chouserhamza`: you can use map, or perhaps -> or ->>
14:39Chouserwhat hn are you using to replace
14:39Chouser?
14:40ChouserI'll try again: what fn are you using to replace?
14:40LauJensenhamza`: you're just calling replace/replaceAll on it ?
14:40hamza`(replace-1 (replace-2 (replace-3 input))) now i have this but as the regexs grow lists grow how can i change this into map or -> ?
14:40arbschtcompose them?
14:40hamza`i am calling replace all on the string..
14:42Chouser,(-> "hello, there" (str2/replace #", " "-") (str2/replace #"ello" "i"))
14:42clojurebotjava.lang.Exception: No such namespace: str2
14:42Chouser,(require '[clojure.contrib.str-utils2 :as str2])
14:42clojurebotjava.io.FileNotFoundException: Could not locate clojure/contrib/str_utils2__init.class or clojure/contrib/str_utils2.clj on classpath:
14:42Chouserbah
14:43maravillas,(doc comp)
14:43clojurebot"([& fs]); Takes a set of functions and returns a fn that is the composition of those fns. The returned fn takes a variable number of args, applies the rightmost of fns to the args, the next fn (right-to-left) to the result, etc."
14:43Chouser(->> "hello, there" (re-sub #", " "-") (re-sub #"ello" "i"))
14:44Chouserso thats at least 2 options, -> with str-utils2/replace and ->> with str-utils/re-sub
14:45hamza`ok thanks, did not about comp too.
14:46Chouser,(reduce #(%2 %1) "hello, there" [#(re-sub #", " "-" %) #(re-sub #"ello" "i" %)])
14:46clojurebot"hi-there"
14:47Chouser,((comp #(re-sub #"ello" "i" %) #(re-sub #", " "-" %)) "hello, there")
14:47clojurebot"hi-there"
14:48LauJensen,(reduce #(.replaceAll %1 (first %2) (last %2)) "choiser is foo bar baz" [["foo" "going to the"] ["baz" "now!"]])
14:48clojurebot"choiser is going to the bar now!"
14:48LauJensen:P
14:48LauJensen(he's Chousers evil twin)
14:49Chousernote comp needs the fns in revers order of the others
14:50Chouserof those I like -> and str2 the best
14:50LauJensen,(.. "foo bar baz" (replaceAll "foo" "doo") (replaceAll "baz" "daz"))
14:50clojurebot"doo bar daz"
14:50LauJensen'..' also works
14:50Chouserbut you have to encode your regexen as strings which is unfortunate
14:52LauJensen~regex
14:52clojurebotSometimes people have a problem, and decide to solve it with regular expressions. Now they have two problems.
15:35hamza`btw, has anyone got etags to index clojure files?
15:40konrGuys, ~/src is on my classpath. Isn't ~/src/lancet the right directory to put step-1-complete.clj, which contains (ns lancet.step-1-complete) ?
15:41konrI'm getting a file not found exception (Could not locate lancet/step_1_complete__ini
15:41konrt.class or lancet/step_1_complete.clj on classpath)
15:50hiredmankonr: http://clojure.org/libs checkout "Lib Conventions"
15:59konrhiredman: thanks!
15:59clojurebothiredman is slightly retarded
16:18konrI still don't get it. If ~/src/ is on my classpath, shouldn't java be able to locate ~/src/lancet/foo.clj?
16:19LauJensendo you literally mean ~ ?
16:20konrLauJensen: no, it is just 'src' on my classpath
16:20LauJensenif it's like you describe above, you should be able to call (use 'lancet.foo)
16:23konrLauJensen: Hmmm, it turned out to be a problem with the "src", which I solved by changing it to "/home/me/src". Thanks!
16:24LauJensenah ok
16:29spuzThis sounds like a stupid question but, how do I modify a var? For example, if I want to track the number of calls made to a function, how do I increment a count var?
16:30LauJensen(def counter (atom 0))
16:30LauJensen(swap! counter inc)
16:31LauJensen@ spuz
16:32spuzLauJensen: swap! seems to apply to atoms, not vars
16:33LauJensenIt's only for atoms, thats why I defined counter as such - You specifically need a var for this? why ?
16:34spuzI guess I assumed that var meant variable
16:34spuzso it would seem there should be a way to modify a variable
16:34LauJensenClojure vars are immutable
16:35spuzmake sense
16:35LauJensenhttp://clojure.org/vars
16:41spuzit seems you can use (binding) to redefine a var, if I'm assuming this var is only accessible to a single thread, how do I decide whether to use an atom or a var?
16:42LauJensenFor those who liked the ikeda sim, it's been updated with an opengl and .net version, http://bestinclass.wordpress.com/2009/09/24/chaos-theory-vs-clojure/
16:47spuzLauJensen: The open gl version looks even simpler than the plain swing version ;)
16:47LauJensenIt should be, or he failed making 'wrappers' :)
16:49spuzIt's a very useful example by the way. I would love to see how you would make a multi threaded version of it though.
16:49LauJensenI was actually thinking about something along those lines myself
16:52lpetitvars are not immutable
16:59LauJensenspuz: I see I misled you, a Var can be rebound with 'binding'
17:00lpetitand in extreme cases, the root binding of a var can be altered with (alter-var-root
17:00LauJensenBut for a counter I'd go with the atom :)
17:01lpetitbut this is really just intended for use e.g. when writing a REPL, so 99.99999999999999% of the time one should just consider a var is used for providing dynamic binding
17:01lpetit@LauJensen : +1
17:02spuzbut even dynamic binding does not appear to be very common
17:03lpetiteven less in clojure, since it is very error prone when used (almost inevitably) in conjunction with lazy sequences and multithreading
17:03spuzthere's an example in the programming clojure book which redefines a function to be a memoized version of that function but it seems unlikely you would need to do that in practice.
17:04spuzso I guess atoms are the way to go
17:06lpetitmemoization (caching) can certainly be a way of shooting yourself in the foot, if you don't take great care (like any caching mechanisms, whatever the language)
17:21somniumusing def to redefine values is generally frowned upon but wondering if this is a special case...
17:23somniumif I have a macro (deflayout :name layout) that creates/updates 'layoutmap with {:name layout}, it uses def to alter 'layoutmap every time its called, but this all happens when the file is read in, no changes to 'layoutmap at runtime.
17:24rafsoakenwhat is wrong with (use 'clojure.parallel) ?
17:24somniumso managing state with a ref seems strange
17:25rafsoakenwhen (use 'clojure.contrib.math) works?
17:25hiredmansomnium: don't re-def
17:25hiredmanuse an atom or a ref
17:25hiredmanrafsoaken: look at the exception
17:26somniumhiredman: all the calls at runtime have the form (with-layout :name & content)
17:26hiredmanmost likely you will see a class not found exception
17:26hiredmansomnium: use a ref or an atom, do not re-def
17:26rafsoakenhiredman: ClassNotFoundException - even though it's described in the API?
17:27hiredmanrafsoaken: go read the docs for clojure.parallel
17:27technomancynice to see it in Real Life
17:27somniumhiredman: ok, I really just want to define it once, I guess I could do (deflayouts & key-val-pairs) and do it one shot
17:28hiredmanrafsoaken: http://clojure.org/other_libraries
17:28lpetit@somnium : yeah
17:28somniumjust wondering what the best way to allow separate calls and still create one central 'layouts var
17:28hiredmanan atom or a ref
17:28rafsoakenhiredman: thanks, i'm just ignorant sometimes
17:29hiredmanyou are talking about mutating something bound to a name
17:29hiredmanso use a ref or an atom
17:29somniumok ok
17:30somniumah, atoms are perfect, sorry for dumb questions
17:37LauJensensomnium: Don't appologize, it wasn't dumb
17:39lpetitsomnium: multimethods rebind the var root of the method every time you add a new method, so that may not be dumb
17:40somniumthanks for the support :)
17:40somniumit just seems odd to consider it 'state', since its really a declarative api, at least in my head
17:41hiredmanlpetit: well multimethods predated atoms
17:41hiredmanlpetit: are you sure of that?
17:41lpetithiredman : I remember reading this on one of cgrand's blog posts
17:42LauJensenthen it must be true
17:42hiredman~def c.l.MultiFn
17:42lpetithttp://clj-me.blogspot.com/2008/05/multimethods-aren-magic-nor-mutable.html
17:42lpetitor it was true (very old post)
17:43LauJensenYou give up the Gists, the watcher system, probably more, but you get fast page rendering - I considered it a good trade
17:44hiredmananyway, defmethod calls .addMethod on the multifn, and doesn't touch the Var at all
17:45lpetitso it used to be mutating the var, sorry for the outdated info
17:46hiredmanI wonder why it used to do that, seems like such an icky thing to do
17:51lpetitindeed, as expected by looking the code at http://tinyurl.com/ycm4ude , the current version does not make Christophe's example fail anymore
17:52licoresse,(doc ->>)
17:52clojurebotExcuse me?
17:55lpetitall in all, what is the added cost of using an atom ? I mean, vars are still there ...
18:11hiredmanvars can be dynamically rebound
18:18lpetithiredman : so maybe it's more appropriate for somnium to directly place the map in a var. It depends on the use case. If as he said mutating the var is just "project configuration / wiring" done in multiple places (imagine a modular GUI), then maybe it's ok. But if this modularity is not just at compile time, but also at runtime (dynamic plugins), then I think using an atom then becomes...
18:18lpetit...inevitable ...
18:44rabidsnailIs there a way to use epoll/kqueue from clojure? Is there some other way to cheaply sit on thousands of open tcp sockets?
18:45Chouserrabidsnail: there's a built in java lib for that. looking now...
18:45rabidsnailthanks
18:47Chouserhttp://java.sun.com/javase/6/docs/api/java/nio/channels/ServerSocketChannel.html
18:48ChouserThat ties in somehow, but I've not actually used it.
18:48Chouserso I'm a bit vague on the details
18:49rabidsnail_Sorry, I missed the last minute. My iphone battery died somehow.
18:51Chouserhttp://www.java2s.com/Code/JavaAPI/java.nio.channels/SelectableChannelregisterSelectorselintops.htm
18:51ChouserI think that's an example of what you want.
18:52Chouserit creates a single Selector and incoming tcp connections are registered with it
18:52Chouserit blocks on the selector and wakes up when any of the registered connections has some data to read.
18:53ChouserI believe that uses epoll or whatever's appropriate on the given OS internally.
18:54rabidsnailYes, that seems like what I want. Thanks.
19:05somniumant-question: what's the tersest way to glob everything in src for a compile target?
23:26konrIs there a particular swing book you guys recommend?