#clojure logs

2009-08-18

00:10cable_potentially dumb map/reduce question
00:10cable_are map operations automatically made concurrent?
00:11rlbcable_: no -- see pmap
00:11cable_ah thx
00:56lowlycoderi have this really difficult task; I'm not sure if I can do it in clojure -- how do I open a file & read it in?
00:57rlb?
00:57lowlycoderi'm kidding; how do I read in a file in clojure though?
00:57rlblowlycoder: text?
00:57rlb(i.e. plain text lines, or other?)
00:58lowlycoderplain text
00:58lowlycoder(doto (java.io.FileReader. filename) ... ) ?
00:58lowlycoderwhat in ...
00:58rlb(line-seq java-buffered-reader)
00:59rlbThen you have a seq of lines you can do whatever you want with.
00:59rlb(i.e. lazy seq of lines)
00:59arbscht,(doc slurp)
00:59clojurebot"([f] [f enc]); Reads the file named by f using the encoding enc into a string and returns it."
01:00rlb(line-seq (BufferedReader. (FileReader. file)))
01:00rlbor similar
01:02lowlycoderk#<CompilerException java.lang.ClassCastException: clojure.lang.PersistentList cannot be cast to clojure.lang.Symbol (test.clj:0)>
01:04lowlycoder(import '(api.java.io 'BufferedReader 'FileReader))
01:04lowlycoder(line-seq (BufferedReader. (FileReader. "test.clj")))
01:04lowlycoderresults in: #<CompilerException java.lang.ClassCastException: clojure.lang.PersistentList cannot be cast to clojure.lang.Symbol (test.clj:0)>
01:04rlblowlycoder: your import command is wrong.
01:05lowlycoderit's just java.io
01:05rlb(import '(java.io BufferedReader FileReader))
01:05lowlycoderwonderful; thanks
01:08lowlycoderhow do I convert a string to a interger?
01:09lowlycoderrather, a number, it may be either an integer or a floating point
01:10lowlycoderclojure's # ... % notation for lambdas is prettty cool
01:10arbscht,(class (read-string "99.9"))
01:10clojurebotjava.lang.Double
01:11arbschtread-string may be too general (unsafe with untrusted input)
01:12arbscht,(Integer/parseInt "9")
01:12clojurebot9
01:12lowlycoderwhy unsafe? does it execute it too?
01:13lowlycoderdoes #(... ) notation nest? i.e. the % match only the innermost #
01:14lowlycoderack, nested #() are not allowed :-(
01:18replacalowlycoder: but nested (fn [x y z] ...) lambdas are allowed
01:20lowlycoderwhy can't I (cons 1 2) but can (cons 1 '(2 3)) ?
01:20clojurebothttp://clojure.org/rationale
01:20lowlycoderdoes cons must return a list?
01:21rlbI'm not sure clojure handles cons the same way as scheme/lisp.
01:21arbschtcons returns a seq
01:23replaca,(class (cons 1 '(1 2)))
01:23clojurebotclojure.lang.Cons
01:24replacalowlycoder: a clojure cons-cell can only have a seq in the cdr, I believe
01:24tomoj,(class (cons 1 nil))
01:25clojurebotclojure.lang.PersistentList
01:25replacalowlycoder: part of the challenge for lispers coming to clojure is to let go of things we assume from our days in CL or scheme
01:26lowlycoder(class (map #(re-split #" " %) (line-seq (BufferedReader. (FileReader. "m393/m393.off")))))
01:26lowlycoderwhy is this a LazySeq, and why can't I take the car of it?
01:27tomojline-seq is lazy
01:27replacalowlycoder: map always returns a lazyseq
01:27lowlycoderhow do I take the care of a lazyseq
01:27replaca(first foo)
01:28lowlycoderso now, first & rest is the standard way to take items from a sequence, of any form, and car/cdr is just for persistent lists?
01:28arbscht,(doc car)
01:28clojurebot"/;nil; "
01:28replacalowlycoder: what do you mean car? clojure has no such function (and really doesn't have the exact same concept)
01:28lowlycoderwtf, I don't even have car?
01:29arbschtyes
01:29tomojthere are no cons cells, what do you need car for..
01:29lowlycoderi'm just used to using it
01:29replacalowlycoder: deep breath... you're leaving common lisp now... buckle your seatbelt and enjoy the ride :-)
01:29lowlycoderwell, this is why they created define-macro :-D
01:30replacalowlycoder: yeah, don't go there. you'll be paddling upstream
01:30replacalowlycoder: try to really get into the "clojure way" and then see if you like it once you've got it
01:30lowlycoderi like the java libraries :-D
01:31replacayou might or might not, but fighting it pretty much guarantees you'll end up in a place that won't make you happy
01:33replacaif it turns out that you want Lisp on the java libs there are other solutions (kawa, for instance) that could get you there in a more familiar envinronment
01:33replacaa lot of us have realized that clojure is awfully well put together, once we let go of what we're used to
01:34replaca(and I know - I wrote the CL compatible format for clojure :-))
01:34arbschtif you haven't already, watch rich's presentations on blip.tv where he explains how clojure is different from CL or Scheme and the rationale behind the changes
01:36tomojreplaca: does it have ~r?
01:38rlb...or, if you've spent much quality time with posix threads, his talk covering the ant demo...
01:38rlb"quality"
01:48lowlycoderuser=> (def x '(1 2 3 4 5))
01:48lowlycoder#'user/x
01:48lowlycoderuser=> (map print x)
01:48lowlycoder(12nil 3nil 4nil 5nil nil)
01:48lowlycoderdoesnt' map generate lazy sequences?
01:48lowlycoderwhy does it print 1 2 3 4 5?
01:48rlblowlycoder: because the repl needs to print the result?
01:48lowlycoderuser=> (def y (map print x))
01:48lowlycoder#'user/y
01:48lowlycoderuser=> y
01:48lowlycoder(12nil 3nil 4nil 5nil nil)
01:49lowlycoderthis is intresting, on future 'y' 's, it only shows the nils
01:49lowlycodermap really is lazy; that is good to know
01:49lowlycoderany other surprises I should know?
01:49rlbhard to know in advance what might surprise you ;>
01:49rlbIf you're coming from s
01:50rlbScheme, there's no TCO.
01:50rlb(tail call optimization), at least no guaranteed TCO.
01:50rlbYou have to use loop/recur explicitly.
01:50lowlycoderthat i also know
01:50lowlycoderwhat else?
01:51rlbNot sure offhand. Stuart's book might be helpful.
01:51rlbAnd I did find the ant video quite interesting.
01:56lowlycoderhow do I convert _anything_ to a string?
01:57lowlycoderstr
01:57lowlycoderwhoa, that is so easy
02:00arbschtlowlycoder: as I said, watch rich's presentations on blip.tv. that might clear up a number of potential surprises
02:01hiredmanlowlycoder: str doesn't really work on lazy sequences
02:01hiredmanyou have to use prn-str
02:02hiredman,(str (map inc (range 10)))
02:02clojurebot"clojure.lang.LazySeq@c5d38b66"
02:02hiredman,(prn-str (map inc (range 10)))
02:02clojurebot"(1 2 3 4 5 6 7 8 9 10)\n"
02:02hiredman,(pr-str (map inc (range 10)))
02:02clojurebot"(1 2 3 4 5 6 7 8 9 10)"
02:02hiredmanthis is unfortunate, and was not the case once
02:03lowlycodercan I download these blip.t episodes?
02:03hiredmanyes
02:04lowlycoderhow? on clojure.blip.tv i see the movie but can't see the link
02:04hiredmanlower right of the page there is a menu called "files" or something similar
02:04hiredmanit has links to download mp4s or flvs
02:06lowlycodereven after clicking on deatils, I see it it not
02:07hiredman~blip.tv
02:07clojurebotblip.tv is http://clojure.blip.tv/
02:07lowlycoderi'm looking at clojure.blip.tv
02:08hiredmanlowlycoder: you have to open one of the videos
02:08lowlycoderi clicked on play on one of them
02:08lowlycoderI don't see where the link is
02:08hiredmanand on the page for the video there is a menu called "files and links"
02:08hiredmanclick on it
02:10lowlycoderhmm, i actuallllly don't see files and links
02:10lowlycoderi'm using firefox 3.0
02:10lowlycoderon ubuntu
02:10hiredmanon the lower right of the page
02:11lowlycoderlet's binary search; above or below the line that syas " Subscribe to this show via iTunes, Miro, channels.com or RSS" ?
02:12hiredmanI think you don't actually have the page for the video open
02:12lowlycoderi'm an idiot
02:12lowlycoderi see it now
02:32replacatomoj: are you still here? yup, it has full ~r support.
02:36tomojnice
02:36tomojdid you do that yourself or does java know how to do that somewhere?
02:44lowlycoderwhoa, so let works like let*
02:45hiredmanyes
02:48replacatomoj: sorry, i'm jumping in and out
02:48replacawrote it all myself
02:49replacadoc is here: http://richhickey.github.com/clojure-contrib/doc/pprint/CommonLispFormat.html
02:50replacaand api overview is on the pprint page: http://richhickey.github.com/clojure-contrib/pprint-api.html#pprint/cl-format
02:52lowlycoderis there a wya to convert a string to an integer besides read-string?
02:53hiredman~jdoc Integer
02:53hiredmaner
02:54hiredmananyway, there are a few methods there
02:54hiredmanInteger also has a constructor that takes a string
02:54replaca,(Integer/parseInt "34")
02:54clojurebot34
02:57lowlycoderhow do I get the length of a sequence?
02:57lowlycoderlength does not seem to be bound
02:57hiredman,(doc count)
02:57clojurebot"([coll]); Returns the number of items in the collection. (count nil) returns 0. Also works on strings, arrays, and Java Collections and Maps"
02:58lowlycoderif I have (def x '(1 2 3 4 5 6 7))
03:00lowlycoderis there anyway I do a binding of the form [y z]
03:00lowlycoderto have z = '(2 3 4 5 6 7) ?
03:00lowlycoder[y z] gets z = 2
03:00lowlycoderand I can't do [y . z]
03:00hiredman,let [[y & z] '(1 2 3 4 5 6 7)] z)
03:00clojurebotjava.lang.Exception: Can't take value of a macro: #'clojure.core/let
03:00hiredmanbah
03:01hiredman,(let [[y & z] '(1 2 3 4 5 6 7)] z)
03:01clojurebot(2 3 4 5 6 7)
03:03lowlycodernice; thans
03:04hiredman~destructuring
03:04clojurebotdestructuring is http://clojure.org/special_forms#let
03:08lowlycoderis there a builtin for taking a list and splitting it into the first 100 elements and the rest?
03:08hiredman,(doc split)
03:08clojurebot"clojure.contrib.str-utils2/split;[[s re] [s re limit]]; Splits string on a regular expression. Optional argument limit is the maximum number of splits."
03:08hiredmanlowlycoder: there are docs on clojure.org
03:09hiredman,(doc split-with)
03:09clojurebot"([pred coll]); Returns a vector of [(take-while pred coll) (drop-while pred coll)]"
03:09hiredmanhmm
03:09lowlycoderhiredman: i didn't know what to search for :-)
03:10hiredman(fn [n s] [(take n s) (drop n s)])
03:11hiredmanah
03:11hiredman,(doc split-at)
03:11clojurebot"([n coll]); Returns a vector of [(take n coll) (drop n coll)]"
03:11hiredmanhttp://clojure.org/sequences
03:14lowlycodertake & drop, cool :-)
03:20lowlycoderwhy does (doc str) work but (doc re-split) not?
03:21hiredman,(doc re-split)
03:21clojurebot"clojure.contrib.str-utils/re-split;[[pattern string] [pattern string limit]]; Splits the string on instances of 'pattern'. Returns a sequence of strings. Optional 'limit' argument is the maximum number of splits. Like Perl's 'split'."
03:21hiredmanre-split is in contrib
03:21hiredmanso you might not have it loaded
03:21lowlycodernice; thanks
03:22hamzahey guys, i can not call the following method from clojure second argument seems to be optional. http://java.sun.com/javase/6/docs/api/javax/swing/RowFilter.html#regexFilter%28java.lang.String,%20int...%29
03:22replacalowlycoder: for contrib refs see: http://richhickey.github.com/clojure-contrib/index.html
03:22hiredmanhamza: you have to pass in an array
03:22lowlycoderweb pages is cool, but I like accessing repl instead
03:22hiredmaneven an empty one
03:23lowlycoderuser=> (doc re-split)
03:23lowlycoder-------------------------
03:23lowlycoderclojure.contrib.str-utils/re-split
03:23lowlycoder([pattern string] [pattern string limit])
03:23lowlycoder... it works
03:23hamzai am calling like so (RowFilter/regexFilter "input" 0 )
03:23replacalowlycoder: you've got to load the namespace your interested in then (as hiredman pointed out)
03:23lowlycoderI did :-)
03:23lowlycoderleading to my comment above of "nice; thanks"
03:23hiredmanhamza: (into-array Integer/TYPE [0])
03:23lowlycoderah, taht could have been interpreted as hiredman's use of clojurebot
03:23replacabut the web page tells you about things that aren't loaded
03:24replacayeah, hiredman has a "special" doc function, I think
03:24hiredmanhamza: java varargs are syntactic suger for passing an array
03:24hamzakk it worked why is the syntax different?
03:25hiredmanclojure doesn't have the syntactic sugar
03:25alinphi
03:25alinpI have an agent defined like this:
03:25alinp(def x (agent 0))
03:25alinpand want to do this:
03:26alinp(send-off x #(+ %1 %2) 3 4)
03:26alinp@x -> 7
03:26alinpwhat's wrong with it ?
03:26alinpwhat I'm doing wrong here ?
03:26hiredman,(doc send-off)
03:26clojurebot"([a f & args]); Dispatch a potentially blocking action to an agent. Returns the agent immediately. Subsequently, in a separate thread, the state of the agent will be set to the value of: (apply action-fn state-of-agent args)"
03:26hiredman
03:27hiredmanin what you described, the function send-off needs to take three arguments
03:27alinpit will use the initial state as the 1st param ?
03:28alinpwell .. I send 3 arguments
03:28alinpbut .. still, doesn't work
03:28hiredmanthe function you send-off
03:28alinp(#<IllegalArgumentException java.lang.IllegalArgumentException: Wrong number of args passed to: user$eval--335$fn>)
03:28hiredman^-
03:28hiredmanyou are send-off'ing a 2 arg function where it needs a three arg function
03:29alinpwhay is that ?
03:30hiredmanis the docstring not clear? (apply action-fn state-of-agent args)
03:30hiredmanargs is [3 4]
03:30alinpah, ok then
03:30alinpthanks
03:30alinpmissed that
03:42lowlycoderuser=> (doc do)
03:42lowlycoder Please see http://clojure.org/special_forms#do
03:42lowlycoderwtf, if you have room for an online documentation system, why give me a URL?
03:42hiredmando is a special form, so there is no var to attach a docstring to
03:43alinphiredman: and this means that all special forms are "documented" this way ?
03:44lowlycoderuser=> (doc do)
03:44lowlycoder-------------------------
03:44lowlycoderdo
03:44hiredmanall six or seven of them
03:44alinpah, ok
03:44lowlycoderif the system can look it up to print a message, why can't it put the doc there?
03:45hiredmanlowlycoder: *shrug*
03:45hiredmanit would have to be put inside the doc lookup function
03:46alinpuser=> (doc doc)
03:46alinp-------------------------
03:46alinpclojure.core/doc
03:46alinp([name])
03:46alinpMacro
03:46alinp Prints documentation for a var or special form given its name
03:46alinpnil
03:46alinp" or special form"
03:46alinp:)
03:47Fossihow about not pasting so much stuff in here? both of you. thanks.
03:47alinp,(doc doc)
03:47clojurebot"([name]); Prints documentation for a var or special form given its name"
03:47hiredmanditto
03:47hiredman~url
03:47clojurebotExcuse me?
03:47hiredmaner
03:47hiredmanlisppaste8: url
03:47lisppaste8To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.
03:48hiredman~def print-special-doc
03:49hiredmangod github is slow
03:51arbscht,(doc foo)
03:51clojurebot"/;nil; "
03:52arbschthiredman: thoughts on a patch like this so clojurebot says something sensible when the symbol isn't found? http://gist.github.com/169596
03:53hiredmanI think you reverse d that patch
03:54hiredmananyway, yes, something should be done about it
03:54arbschtso I did, yes
03:54arbschtI can fork clojurebot and do a pull request if you want
03:55hiredmanI'd have it reply with one of the befuddled responses
03:55arbschtheh
03:56hiredmanif you want, sure, I'd hate to put you through the trouble for something so small
03:57arbschtmight as well, could be handy in the future
03:59arbschter, if github co-operates, that is.
04:00hiredman,(doc foo)
04:00clojurebot"I don't understand."
04:00arbscht:-)
04:00hiredmanarbscht: abort, abort!
04:07Fossiclojurebot: is weird in speaking far too many languages
04:07clojurebotIt's greek to me.
04:08lowlycoderdoes clojure have c++ equiv of /* ... */
04:09FossiC-SPC M-C-;
04:09Fossithat is: i don't think so
04:10Fossiyou could write a macro for it
04:10hiredmanthere is commet
04:10hiredmancomment
04:10Fossiah, right
04:10hiredmanbut comment is a macro, not really a comment
04:10arbschtclojurebot: def defn
04:11Fossi(10:13:35) arbscht: clojurebot: def defn
04:11Fossi(10:13:37) clojurebot: (notice) defn: http://tinyurl.com/p7c7c4
04:11Fossi(10:13:49) defn_ [i=defn@anapnea.net] entered the room.
04:11Fossi;D
04:11arbschtha
04:12arbschtthe README says google code still
04:15AWizzArdlowlycoder: if you want to comment out a whole form just put #_ in front of it
04:15AWizzArd,(println (+ 1 2) #_(+ 3 4) #_(+ 5 6))
04:15clojurebot3
04:15AWizzArd,(println (+ 1 2) #_(+ 3 4) (+ 5 6))
04:15clojurebot3 11
04:16lowlycoderhow does #_ work?
04:16lowlycoderi suspect it's a macro for something else
04:16AWizzArdThe comment macro can also be fine, but you should be aware that it will evaluate to nil.
04:17AWizzArdlowlycoder: it is a reader macro
04:17lowlycoderand it turns out to comment something out
04:17lowlycoderthat evalutes to nil?
04:17AWizzArdthe reader reads the form and throws it away
04:17AWizzArd,(str (+ 1 2) (comment (+ 3 4)) (+ 5 6))
04:17clojurebot"311"
04:17AWizzArdokay, stupid example as str ignores the nil
04:18AWizzArd,(+ 1 (comment 2))
04:18clojurebotjava.lang.NullPointerException
04:18AWizzArdbut #_ does not get evaluated
04:18AWizzArdthe reader consumes the form, but won't eval it
04:19arbschtcomment is nice at the top level for documentary sections etc
04:19AWizzArdyes
04:25hamzahey guy's, if i use proxy to extend JButton how can i pass variables to its contructor?
04:28lowlycoderAWizzArd: thanks
04:30d2dchatis there a protected division operator?
04:30d2dchatlike % ?
04:30d2dchatI know traditionally that is used for modulus but
04:30d2dchatit can also be protected division
04:31d2dchatany function like that avail?
04:38mebaran151what do you mean by protected division: the regular clojure one's check for overflow I think
04:38mebaran151and div by zero
04:39Fossihamza: ,(doc proxy)
04:42lowlycoderso if I (print ...) something in a child thread, it doesn't pop up in the main repl stdout?
04:44Fossii don't think so
04:44Fossiwith slime you can switch that
04:45Fossinot sure for the repl
04:56Neronuslowlycoder: You could try passing *out* of the repl to the thread at its creation (it has some main function, I guess?) and then binding it in the main function or around the main function
04:59Neronuslowlycoder: (send-off (agent [*out* "foo"]) (fn [[out o]] (binding [*out* out] (println o)))) something like that
05:00hiredmanlowlycoder: use println instead of print
05:00hiredmanor if you must use print, call flush
05:03Neronushiredman appears to be right for child threads, as (.run (Thread. #^Callable (fn [] (println "foo")))) prints to the *out* of its creating thread
05:03hiredman:|
05:04hiredmanyou know no Thread constructor takes a Callable right?
05:08NeronusYou're right, I meant runnable of course. Works either way :)
05:09hiredmanI doubt a type hint there would ever give you a performance increase, so even with #^Runnable, best to omit the hint
05:22NeronusThis wan't about performance, this was about a memory associated wrong. With ThreadPoolExecutor.sumbit I had to do that declaration, or clojure didn't know which .submit I meant (I didn't care, but how should the compiler know that?)
05:25lowlycoderthis is really dumb
05:26lowlycoderhow do I load in "test.clj" from the current directory
05:26lowlycoder(use 'test) is not loading it in
05:27hiredman,(doc load)
05:27clojurebot"([& paths]); Loads Clojure code from resources in classpath. A path is interpreted as classpath-relative if it begins with a slash or relative to the root directory for the current namespace otherwise."
05:27hiredman,(doc load-file)
05:27clojurebot"([name]); Sequentially read and evaluate the set of forms contained in the file."
05:32lowlycoderI have gears.clj in current directory; I can do (use '(gears)) ; gears.clj has a function (go) defined in it ... why can't I call (gears.go) ?
05:35NeronusYou can do either (go) after use because you refer each defined symbol of the namespace gears in the namespace doing the (use ...), or you can do gears/go, which is the way to refer function go of namespace gears
05:36lowlycoder(ns gears)
05:37lowlycoderthat is the first line of gears.clj
05:37lowlycoderdo i need to export go?
05:37Neronusna, if you defined go by (def) or (defn) its exported
05:37lowlycoderhmm, user=> (use '(gears))
05:37lowlycodernil
05:37lowlycoderuser=> gears/go
05:37lowlycoderjava.lang.Exception: No such namespace: gears (NO_SOURCE_FILE:0)
05:38lowlycoder~/genesis:master*$ cat gears.clj| grep go
05:38lowlycoder(defn go []
05:38clojurebotI don't understand.
05:39Neronuslowlycoder: (use 'gears)
05:40lowlycoderuser=> (use 'gears)
05:40lowlycoderjava.io.FileNotFoundException: Could not locate gears__init.class or gears.clj on classpath: (NO_SOURCE_FILE:0)
05:41lowlycodernice, it works now
05:42lowlycoderi had incorretly set up class paths
05:42Neronusgreat :)
07:18NeronusDoes anyone here know if the loading of a string literal via ldc (bytecode instruction) causes the class java.lang.String to be loaded?
07:22NeronusAh, found it. thanks
07:30FossiNeronus: so?
07:51NeronusIf the constant pool entry to be loaded by ldc is to be loaded for the first time, a new String object will be constructed. Thus, String has to be loaded
07:52NeronusJVMS 5.1
08:55AWizzArdI have (def x {:abc "ABC"}) and defined an inline accessor for it: (definline abc [obj] `(:abc ~obj)). So (abc x) ==> "ABC".
08:56AWizzArdI set *warn-on-reflection* to true. Now (.toLowerCase (abc x)) gives me a warning as expected. But unfortunately (.toLowerCase #^String (abc x)) also does. If abc is not an inline macro but a function then the type hint works.
08:56AWizzArdAny idea why it does not work for the inline?
08:57ChouserUse macroexpand and *print-meta* to see what the compiler actually consumes.
08:58Chouserhm, except macroexpand doesn't work on :inline
08:58AWizzArdYes, it's strange, I can't macroexpand it.
08:58AWizzArdright
08:58Chousukemaybe you need to do #^String `(:abc ~obj)
08:58AWizzArdIn the inline itself? I will try that.
08:58Chousuke,(meta #^String `test)
08:59clojurebotnil
08:59Chousukehmm
08:59Chouserwell, I'm pretty sure this is what's happening:
08:59Chousuke,(meta #^String 'test)
08:59clojurebotnil
08:59Chousuke:/
08:59Chouserthe String :tag is put on the list (abc x). Then the :inline is expanded, and the results replace the old list
08:59AWizzArdChousuke: oh cool trick, it works when I do (definline abc [obj] `#^String (:abc ~obj))
09:00Chouserthose new results have no tag, thus the reflection warning
09:00Chouser,(meta '#^String test)
09:00clojurebot{:tag String}
09:00AWizzArdYes, that could be it Chouser. But good that Chousukes trick works. Thanks you two.
09:01Chouserrhi<tab> ... rhi<tab> ... *sigh*
09:02ChousukeI just added autofn support for my reader.
09:02AWizzArdChousuke: what is that?
09:02Chousuke#()
09:02Chousukethe worker function is *ugly* but at least it works :P
09:02AWizzArdChouser: yes, he takes some days off it seems :)
09:04ChouserAWizzArd: he said a week. It's now been more.
09:04Chouserhow dare he. ;-)
09:05Chouseroh, hooray.
09:06drewrrhickey: welcome back!
09:06Jenncaspothi
09:06rhickeyhi all!
09:06ChouserChousuke: as soon as it passes the test suite, I'll start using it.
09:06Jenncaspoti am new here
09:06ChouserJenncaspot: welcome.
09:07Jenncaspotthanks
09:07Jenncaspotthis is my first time to chat
09:07AWizzArdoh funny, rhickey, only 2 minutes ago we were talking about you and your holidays :-)
09:07AWizzArdwb
09:08rhickeyAWizzArd: that would be holiday (singular), first without working on Clojure since I released it
09:10AWizzArdIt's a good thing.. holiday without your child - nice to have from time to time.
09:59LauJensenrhickey: In your absence I updated http://en.wikipedia.org/wiki/Functional_programming to include Clojure under functional languages used in industry - dunno how they could have forgot :(
10:00rhickeyLauJensen: putting it first probably isn't a good idea
10:00LauJensenOh. I felt it would be wrong to put it behind any of the inferior languages in the same category.
10:01LauJensenIf you had updated the site, then I could see a potential problem :)
10:02rhickeyas the most recent entrant, Clojure should go last
10:03rhickeybeing pushy won't win Clojure any converts, and may seem fanboyish, and thus less credible
10:04rhickeylet's stay modest, as a community
10:04Fossii think the list should be alphabetically ordered
10:04Fossiwhich it also seems to be
10:05LauJensenIts your language and therefore your call. I just feel it would be wrong to put Clojure in a less visible position and thereby perhaps leading some down the wrong path first. I'd hate to be the cause of somebody wasting a year in F# because I tried to display a false sense of humility. I know it seems like I'm overthinking something as simple as the order of mention, but I would really feel bad if it happend anyway
10:06Fossithen again such lists with "... including [list goes here]" are always a discussion topic anyway
10:07Fossiand a reference would surely help
10:07LauJensenrhickey: I've updated the page now
10:07Fossiespecially since the other mentions have them
10:07LauJensenits the last mention, although in uppercase red letters size 72
10:07rhickeyLauJensen: thanks
10:07LauJensennp
10:09FossiLauJensen: also check the "R and S-Plus" part of the discussion page
10:11LauJensenI dont have the patience for those types of discussions
10:12Fossiyes, but you seem to have the time to make an edit
10:12Fossiso imho you either do neither or both
10:12Fossibut be free to be reverted
10:18Fossii want to modify the values in a map. anybody got a merge-with example or can tell me how to return a (new?) MapEntry?
10:19tomojwhat do you want a MapEntry for?
10:19AWizzArdFossi: maybe update-in can do the job
10:25FossiIs the documentation grammatically wrong or is it my brain being too stupid to parse it?
10:25Fossi,(doc update-in)
10:25clojurebot"([m [k & ks] f & args]); 'Updates' a value in a nested associative structure, where ks is a sequence of keys and f is a function that will take the old value and any supplied args and return the new value, and returns a new nested structure. If any levels do not exist, hash-maps will be created."
10:26Chouser,(assoc {:a 0, :b 1, :c 2} :b 99)
10:26clojurebot{:a 0, :b 99, :c 2}
10:26ChouserFossi: do you want more than that?
10:27Fossialso ,(update-in {:foo 'foo :bar 'bar} #(do (println %) %)) doesn't work so well
10:27Fossifor every val in the map, i want to add something to it
10:27Chouseradd as in + or as in conj?
10:27Fossior i might even replace it
10:28Chouser,(into {} (for [[k v] {:a 0, :b 1, :c 2}) [k (+ 100 v)]))
10:28clojurebotUnmatched delimiter: )
10:28Chouser,(into {} (for [[k v] {:a 0, :b 1, :c 2}] [k (+ 100 v)]))
10:28clojurebot{:c 102, :b 101, :a 100}
10:28Fossi,(update-in {:foo 'foo :bar 'bar} #(do (println %) %))
10:28clojurebotjava.lang.IllegalArgumentException: Wrong number of args passed to: core$update-in
10:28Fossi,(update-in {:foo 'foo :bar 'bar} #(do (println %) %) nil)
10:28clojurebotjava.lang.UnsupportedOperationException: nth not supported on this type: sandbox$eval__2411$fn__2413
10:29Fossiseems k &ks is not optional, but has to be a vec
10:29Chouserupdate-in is for nested maps
10:29Chouserand probably not the best choice if you're going to change every value of the map
10:30Chouserif you're going to touch every value, it's probably best to iterate over them (using 'map', 'for', etc.) and then build them back into a map using 'into', as I demonstrated.
10:32Fossiyeah, i had a map there to start with, but got confused how to make it keep the map type
10:33Fossi"map"
10:33ChouserIf you want to keep the particular variety of map you started with (sorted or whatever), you can use (into (empty my-map) ...) instead of (into {} ...)
10:47cemerickrhickey: welcome back :-)
10:55cschreinerOn the Macintosh; In Emacs 22 (Carbon Port, CVS version) you can use the variable ‘mac-control-modifier’ to remap the Control key.
10:55cschreinerWhat denotes the caps-lock key?
10:57ChousukeI think you need to remap caps-lock from the keyboard settings.
10:57cschreiner(wrong group, heh)
10:57cschreinerSo I cannot do this locally for emacs only
10:58Chousuketry M-x apropos capslock? :P
10:58clojurebotx is y
10:59ChousukeI mapped mine through the keyboard preferences to control and then in emacs I swap meta with control
10:59ChousukeI need to be careful with cmd-w now though :P
10:59cschreinerhehe
11:00Chousukein emacs it'll be ctrl-w. but in other apps it'll close the window ;(
11:03Chousukecschreiner: do you happen to know how I turn *off* eldoc-mode? ;( it's slowing down scrolling in my buffers
11:03Chousukethere's turn-on-eldoc-mode but no turn-off...
11:03tomojM-x eldoc-mode ?
11:06Chousukeah, it works as a toggle. duh
11:07NeronusFor gtk-apps, you can tell gtk to use emacs like keybindings... e.g. pidgin ignores that though and closes the window none the less
11:08Neronusagain, IIRC
11:08Fossii have [[k1 v1] ...] and [[k1 x1] ...] and like to merge them as [k1 [v1 x1] ...]. any hints?
11:09Chousukeeasiest to make those into maps first, then use (merge-with vector ...)
11:11Chousuke,(vec (merge-with vector (into {} [[:k1 1] [:k2 2]]) (into {} [[:k1 2] [:k3 3]])))
11:11clojurebot[[:k3 3] [:k2 2] [:k1 [1 2]]]
11:13Chousukehmm
11:14ChousukeI wonder if there's something wrong with the way clojure-mode (or clojure-swank) does eldoc. it doesn't cause lag with elisp :/
11:14Fossithanks
11:20ChouserHm, I'd like to use the timeout arg to promise's CountDownLatch.await()
11:24danlarkinHey LauJensen, why the move to gitorious?
11:24alrex021I have a test in attr-map of my function: (defn #^{:test (fn [] (is (= (add3 6) 9)))} add3 [n] (+ 4 n))
11:24alrex021I get a FAIL in clojure.lang.PersistentList$EmptyList@1 (NO_SOURCE_FILE:1) as expected....but I also get a :ok as a result
11:25LauJensendanlarkin: Speed and consistent use of markup all around the site.
11:25LauJensen(hey btw)
11:25alrex021expected: (= (add3 6) 9) actual: (not (= 10 9)) ....and then on last line REPL I see .... :ok ...how does tht make sense?
11:27danlarkinLauJensen: I see, good reasons
11:28Chouseralrex021: looks like a mismatch between 'is' and 'test'
11:28stuartsierraalrex021: you're mixing clojure.test with the older clojure.core/test.
11:28Chouseralrex021: 'is' returns true or false. 'test' expects an exception on failure, not just 'false'
11:28stuartsierraRun your tests with clojure.test/run-tests.
11:28alrex021oh I see
11:29rhickeyChouser: timeout on deref of promise? returning what if timed out?
11:29alrex021so when using functions from clojure.test ...use run-tests
11:30Chousukerhickey: you could require the user to specify a timeout value
11:30alrex021so run-tests will actually look at functions in namespaces :test and treat it the same way as deftest functions?
11:30alrex021just want to make sure I understand this
11:31Chousukerhickey: then it could look like (deref obj timeout ::timeoutval)
11:31Chouserrhickey: yes. nil would work in this case, though I suppose one might eventually want to specify the value to return on failure.
11:32rhickeyI'm not sure I want to overload deref for this, but both future and promise have potentially blocking derefs and timeout options
11:33Chouseryeah, it stretches deref quite a bit. maybe a new interface. :-/
11:33Chousersince I'm on 1.0 and have my own copy of 'promise' anyway, I may just add (invoke [timeout unit] ...) to the proxy.
11:34Chousukeheh
11:34alrex021What is the best practice, if any, when writing tests in clojure.....to have them closely tied to function using :test or to define them using deftest macro?
11:34cemerickadding an available?/done? fn to IDeref would make setting up timeouts on any IDeref pretty straightforward with latch
11:35Chousercemerick: those may be related.
11:35Chousercemerick: I mean, things that might want a timeout on "deref" may also be the things that you'd want to ask 'available?' of.
11:35rhickey cemerick: I'm not sure I understand use case for timeouts on non-future/promise refs
11:35clojurebotfor is not used enough
11:36cemerickChouser: yeah, I know...trying to build my use-cases :-)
11:36rhickeyIn any case it's not going in IDeref, maybe IMightDerefIfImReady?
11:37Chouserperfect
11:37stuartsierraalrex021: it's really a matter of taste.
11:37cemerickrhickey: there is none -- I'm just pitching for an available/done marker on IDeref in general, which could be leveraged by a timeout mechanism
11:37rhickeyIMightDerefIfYoureLicky
11:37rhickeycemerick: avaialble/done just invite polling, which is bad
11:38stuartsierraalrex021: In general, I would recommend only adding :test metadata directly if you're using the clojure.core/test, which expects an exception on failure.
11:38ChouserThe question you have to ask yourself is, do you feel licky. Well do you, punk?
11:38LauJensenNo.. Not real licky Chouser... :)
11:38cemerickrhickey: my use case is with regular delays, to avoid incurring computation in certain circumstances
11:38ChouserLauJensen: yeah, me either.
11:39stuartsierraalrex021: Personally, I use clojure.test/with-test to add small unit tests to isolated functions; I use deftest to write broader integration tests.
11:39cemerickright now, I carry around an atom/delay pair to track whether the latter's been accessed yet or not
11:40alrex021stuartsierra: I must admit that I am loving the concept of testing using :test .... I'd prefer to look at source of function see its test right there. like the doc string
11:40stuartsierraalrex021: That's what clojure.test/with-test is for.
11:41stuartsierra,(doc clojure.test/with-test)
11:41clojurebotTitim gan éirí ort.
11:41stuartsierrawha?
11:42rhickeycemerick: would you be satisfied with deref-with-timeout vs done?/available?
11:46cemerickprobably not -- I use the atom/delay pair to help amortize the cost of certain operations in a data structure
11:49cemerickis the temptation to poll really that strong with some?
11:49rhickeycemerick: then I don't understand the semantics of available? - you haven't asked for anything to be done, who sets the atom?
11:53m3llingday 2 of this... http://blog.thinkrelevance.com/2008/9/16/pcl-clojure-chapter-3
11:54m3llingpersonally i think there is a bug in clojure somewhere.
11:54m3llingchecked my stuff out with git and built it.
11:54m3llingthe example does work if I remove the spaces from the data and put in a -
11:55m3llingDixie-Chicks ... for example
11:55m3llingotherwise it's java.lang.ArrayIndexOutOfBoundsException: 9
11:56cemerickrhickey: The atom always starts at false, and is flipped to true when the delay is accessed.
11:56cemerickSpecifically, the delay is deref'd (and the atom reset to true) on a query, which will build out the portion of the data structure it represents. On removal and swaps, those parts of the structure that haven't yet been accessed at all are just replaced with a new atom/delay. Those that have are replaced with an updated value from the already-forced delay.
11:56duck1123are you sure "Dixie Chicks" is quoted appropriately?
11:56m3llingi copied it from the blog.
11:56m3llingdoube-quotes...?
11:57tomojthat looks like it was written almost a year ago
11:57tomojm3lling: ^
11:57m3llingactually, i believe the problem is when trying to load the data from the file.
11:57duck1123I don't see anything that looks like it wouldn't still apply though
11:57m3llingit doesn't get reparsed right.
11:59m3llingi have a simpler version on StackOverFlow... http://stackoverflow.com/questions/1291765/how-do-i-persist-and-restore-my-defstructs-to-a-file/1294018#1294018
11:59rhickeycemerick: got it. It's interesting because in the non-async case of delay the has-been-calculated question is less about waiting for something else to complete, as with future/promise
11:59m3lling(def x (struct bookmark "news.ycombinator.com" "News" "Tech News")); Doesn't handle "Things in quotes"
12:00m3lling(save-db x "url-db.txt") ... (def y (load-db "url-db.txt")) .. will fail...
12:00Chouseryou need prn instead of print
12:01Chouseror (pr-str db) instead of (with-out-str (print db))
12:02cemerickrhickey: yeah. I think the available? semantics would apply to all IDerefs, though.
12:02stuartsierram3lling: I don't think you can pr/read struct-maps right now.
12:02cemericksort of useless with refs, but still applicable
12:02m3llingso this example doesn't work?
12:02rhickeycemerick: I'm not sure I agree, but now see the utility for delay
12:02m3llingit does work if no spaces are in the values
12:03cemerickrhickey: hey, it makes sense to me! ;-)
12:03tomojI had trouble where pr'ing structmaps with *print-dup* true printed stuff that couldn't be read
12:03stuartsierram3lling: it will work if you use pr instead of print, but when you read it back in, you'll get plain maps instead of struct maps.
12:03tomoj#=(clojure.lang.PersistentStructMap/create ...)
12:04rhickeyI think delay/promise/future might support something like that, and promise/future something like deref-with-timeout. Name suggestions for functions and interfaces welcome
12:04tomoj"no matching method found: create"
12:05stuartsierratomoj: Yes, I've had the same problem.
12:06m3llingk. i changed the save-db and it works.
12:06m3llingthx.
12:06cemerickderef-before seems like a no-brainer
12:07cemerickor deref-within maybe
12:08cemerickthe terracotta guys are growing (http://blog.terracottatech.com/2009/08/terracotta_and_ehcache_a_marri.html). Glad they're doing so well.
12:10m3llingare we sure this thing isn't a struct when it's read back in? (println (= x y)) is true.
12:10m3llingx is original and y is loaded value.
12:10stuartsierratomoj: created a ticket: http://www.assembla.com/spaces/clojure/tickets/176-structs-printed-with-*print-dup*-true-cannot-be-read
12:11tomojstuartsierra: cool
12:11hamzahow can i create a java.awt.geom.RoundRectangle2D.Double?
12:11m3llingk
12:11hamza(new java.awt.geom.RoundRectangle2D.Double ...) creates error
12:11tomojI went down the road towards manually serializing/deserializing from json
12:12stuartsierrahamza: is "Double" a nested class of RoundRectangle2D?
12:13cemerickyes, it should be java.awt.geom.RoundRectangle2D$Double
12:13hamzadunno in java i can get it using g2.draw(new RoundRectangle2D.Double(0,0,(getWidth()-3),...
12:14hamzacemeric thx it worked..
12:14cemerickhamza: RoundRectangle2D$Double is the real classname -- the period in java source code is just syntactic sugar
12:16hamzaone more question if i proxy say JButton how can i override its contructor?
12:16cemerickyou can't override constructors in proxies
12:17hamzais there any other way to do it?
12:17cemerickbut you probably don't want to override its constructor, just provide it with whatever args you want in the second vector provided to the proxy fn
12:17cemerick,(proxy [javax.swing.JButton] ["some text"])
12:17clojurebotjava.lang.IllegalStateException: Var null/null is unbound.
12:18cemerickhuh, hadn't seen that before
12:18cemerickdoes clojurebot run in headless mode or something?
12:20hamzawhat about super call how can i refer it?
12:22cemerickhamza: see proxy-super
12:38cemerickoh, how I want to stop ever writing java
12:41rhickeycemerick: in Java because...?
12:41cemerickrhickey: legacy code base, java 1.4 compat required.
12:41rhickeyah, can't help you there
12:42cemerickI shouldn't complain, this is the first java I've written in at least a month.
12:42cemerickyeah, I've gone astray for 15 min
12:47cable_rhickey: fantastic job with everything, ive finally found a JVM language worth switching to
12:47rhickeycable_: thanks!
12:48technomancyso... is there any way to build the fnparse library without an IDE?
12:48technomancythe build.xml files are a bit intimidating
12:58ChousukeProgress! (eval (first (item-seq (rh-from-str "(defn foo [#^String x] (.toUpperCase x))")))) now gives me a foo function without any pesky reflection warnings.
12:59ChouserChousuke: that's your reader?
12:59stuartsierraok, I think clojure.contrib.http.agent is finally finished.
12:59Chousukeyeah.
12:59ChousukeTomorrow I'm going to try if my reader can read core.clj :P
12:59ChouserChousuke: very cool
13:00ChousukeI still don't have support for \characterescapes but that should be simple.
13:00Chousukeand it's probably more lenient on what it accepts as tokens than the java reader
13:04Chousukeclojure.lang.reader> (= (read-string test-str) (my-read-str test-str))
13:04Chousuketru
13:04Chousukee
13:04Chousukereassuring
13:05Chousuke(metadata is probably different though)
13:12technomancyhiredman: what rev of fnparse are you running clojurebot on?
13:17hiredmantechnomancy: running ant just always worked for me, but I haven't built it in a few months
13:18hiredmantechnomancy: I'm not sure
13:22technomancyI got it to compile by tearing out a bunch of crap from the build.xml and hardcoding some classpath vars in, but now I'm getting wrong number of args
13:23technomancyif you've got a sha1 rev for me to work from that'd be awesome
13:25hiredmanI don't :(
13:25technomancyOK, I'll go back a couple months
13:25technomancysee if that does it
13:27cemericktechnomancy: is this a netbeans build process?
13:28technomancycemerick: yeah, actually I think it's just copied from the enclojure build process
13:28cemerickwell, enclojure is a netbeans module suite, which is a whole lot more complicated than a regular project.
13:28cemerickFor the latter, you should be able to just set a system property to bootstrap the whole thing.
13:29cemerickwhat do you get if you just "ant jar" the thing?
13:30technomancycemerick: it was complaining about not having clojure.jar on the classpath
13:30technomancyapparently ignoring the CLASSPATH environment var
13:30cemerickhrm. what's the github url?
13:30cemerick(the CLASSPATH env var is a scourge on our society IMO, but anyway... :-) )
13:31technomancycemerick: I don't use it unless I'm desperate. =)
13:31technomancyhttp://github.com/joshua-choi/fnparse
13:32cschreinerI loathe the classpath concept
13:34cemericktechnomancy: ugh. The clojure jar is set up as a platform library, e.g. you'd have to either be in a properly-configured NB IDE or have an NB platform harness around configured just like Joshua's in order to get it to build.
13:35cemerickNot the best thing to do with a lib that's going to get built elsewhere (e.g. set up core stuff as platform libraries)
13:35ChousukeI don't think the classpath is that different from LD_LIBRARY_PATH... the main problem I guess is that classes aren't versioned so you can't have two versions of the same class at the same time. :/
13:38technomancycemerick: sounds like I just need to get the author to get his build process fixed then
13:38cemerickheh, people are touchy about their build processes :-)
13:38cemerickbut yeah, I'd say it's essentially unbuildable as-is, based on my skimming of the project files
13:38technomancywell I'm on metered 3G bandwidth right now, so there's no way I'm downloading netbeans. =)
13:39cemerickyou'd still have to set up clojure as a "platform library", which is ill-advised outside of very constrained circumstances.
13:40cemericke.g. ties you to your current IDE, unless you're building against an internally-canonical NB platform harness (which we happen to do in one case, but for very good reasons)
13:41technomancywell I can try my "disable the tests and hardcode the classpath" approach with an earlier revision
13:41technomancyhiredman: what do you use fnparse for?
13:41ChouserChousuke: LD_LIBRARY_PATH is not recommended either -- there are global config files that are preferred, but AFAIK the jvm has no such thing.
13:41technomancycould I just rip out that functionality?
13:42technomancylooks like just factoids?
13:42technomancywhat exactly are ... factoids?
13:46hiredmanclojurebot: clojure?
13:46clojurebotclojure is cheating
13:46hiredmanthat is a factoid
13:47duck1123"You can't just have concurrency without having to worry about deadlocks, that's cheating"
13:47technomancyhiredman: ah, so all the dictionary stuff?
13:47hiredmanyeah
13:47technomancywould be a shame to lose that.
13:47hiredmanit'd didn't always uses fnparse
13:52hiredmandoes fnparse need to be built? maybe just jar up the source?
13:52technomancymaybe
13:52technomancyI'll add that back in later once I have it running
13:54hiredmanugh
13:54hiredmanjava.lang.IllegalArgumentException: Wrong number of args passed to: fnparse$followed-by (factoids.clj:14)
13:55technomancyyup. =\
13:56hiredmanI think I must be using pre-monad fnparse
13:57hiredmanugh
13:57hiredmanit returns a map now
13:57hiredmantechnomancy: do you want the working fnparse.jar I have?
13:57technomancysure
13:58hiredmanhttp://www.thelastcitadel.com/lab/fnparse.jar
13:58technomancythanks
14:13technomancyhiredman: would it be a lot of hacking to get clojurebot running in multiple channels?
14:21technomancythis doesn't seem to... work. at all.
14:22technomancychangeNick and joinChannel are no-ops
14:23technomancysendMsg seems to work though
14:27konrWhat should I use as a GUI designer with swing?
14:32cemerickkonr: NetBeans matisse is pretty good
14:32cemerickapparently, the instantiations swing designer is superior, but I'm decidedly not an eclipse fellow
14:53mebaran151are there any web frameworks a little lighter than compojure out there
14:54mebaran151something that doesn't have any batteries for html etc
14:55dnolencompojure about as light as it gets it seems to me. I personally never use it's built in HTML facilities, I prefer Enlive.
14:55stuartsierramebaran151: ring
14:55mebaran151does ring have a routing layer?
14:55dnolencompojure is actually heavily based on ring's routing layer.
14:55stuartsierrahttp://github.com/mmcgrana/ring/tree/master
14:56stuartsierraDoes compojure use Ring internally, or just implement the same API?
14:56mebaran151oh nice
14:56mebaran151and can I easily make a war out of a ring app
14:56mebaran151it's http, just without any html
14:56dnolenstuartsierra: I forget how closely related their codebase is...
15:02LauJensenAnybody know of a simple quick java image processing lib that I can use for cropping and scaling ?
15:10mebaran151I think java.awt.image might have some useful classes for this sort of thing
15:11cemerickCropping is pretty straightforward just using the standard Java2D stuff.
15:11cemerickScaling is pretty complicated, and Image.getScaledInstance is often not what you want: http://today.java.net/pub/a/today/2007/04/03/perils-of-image-getscaledinstance.html
15:12cable_there's jai as well
15:12cemerickSwingX contains some utility functions that implement the recommendations of the above article, which it mentions.
15:18tomojstuartsierra: I don't think it uses ring, as I didn't have to download ring to get compojure to work
15:19stuartsierraright, makes sense
15:20LauJensenAlright - Thanks alot guys
15:21dnolenLauJensen: while it's definitely not simple, the Advanced Imaging library does have a lot of functionality, I've always hoped someone would created a simpler interface to it.
15:22hiredmantechnomancy`: I don't think it would take that much
15:22hiredmanI have clojurebot running in here and in #clojurebot
15:55mebaran151it's nice to have only one type of datastructure, the seq
15:56mebaran151a lot of my old oop code seemed to be used to repurpose various types of reducing operations over subtly different collections
15:56LauJensendnolen: A bit beyond the scope of this project - But remind me next time something like this comes up :)
16:05hiredmanhttp://twitter.com/clojure/status/3382120972 <-- ha ha
16:10Chousuke:p
16:10Chousukehmm
16:11cemerickdoes rhickey control the clojure twitter acct?
16:11hiredmanclojuredev
16:11hiredmanclojure is someone else, I assume
16:11Chousukeif I have a function that takes a seq (aseq) as a parameter and I want to do this: (let [aseq (do-some-stuff-that-consumes aseq)] ...), how do I avoid holding onto the head?
16:11cemerickah, that explains the Germany location.
16:14Chousukehmm. or does nth hold on to the head of lazy seqs? that was what I tested with :/
16:18LauJensenLooking at Swing, its not obvious to me how I would render an image, and then provide some easy way of stretching out a rectangle for cropping it. Containing the image could be done with ImageIcon, but then what ?
16:21Chousukehm
16:22Chousukelet seems to cause things to hold onto their head
16:23Chousuke((fn [aseq] (let [aseq (nth aseq 1000000)] aseq)) (iterate inc 1)) fails, but simply ((fn [aseq] (nth aseq 1000000)) (iterate inc 1)) doesn't.
16:26LauJensenFirst one doesnt fail here
16:27Chousuketry with a bigger n?
16:28ChouserI don't think much of anything about swing is obvious.
16:29cable_heh re: swing
16:30LauJensenChousuke: yea x50 blows the heap after a while
16:30ChousukeI wonder why that is.
16:31LauJensenI'm ashamed to say, that Rich actually explained it a couple of weeks ago, but I forgot
16:31Chouserof course it does -- your are returning the head, so it must be retained
16:31Chouseroh.
16:31Chouserwait.
16:31stuartsierraWhen you let-bind the head of a sequence, the compiler doesn't know that you're not going to use it latert
16:32Chousukehmm
16:32stuartsierra(let [aseq (make-big-sequence)] (consume aseq) ... what happens here?)
16:32Chouserlet is in the tail position, so it could theoretically null out the earlier aseq. Apparently it doesn't.
16:33stuartsierrayeah, I think the analysis for whether or not aseq gets consumed could get pretty complicated
16:35Chousukehmm
16:36Chousukeso how do I avoid holding on to the head of the function parameter at all?
16:36Chousukeit seems using let will cause it to be held, no matter what I do :(
16:36Chouserthey get nulled out before whatever you call in the tail position, I believe.
16:36LauJensenDidnt Rich give an example of how he rewrote filter to avoid retaining the heaed?
16:36Chousuke((fn [aseq] (let [foo (nth aseq 1000000)] foo)) (iterate inc 1)) also boom
16:37cemerickLauJensen: You'd need to handle the rendering of the lasso and such yourself. I'm not familiar with any libraries that provide a lasso "control".
16:37Chousuke ((fn [aseq] (nth aseq 1000000)) (iterate inc 1)) no boom, but no good either ;(
16:37LauJensenChousuke: How about ((fn [aseq] (let [foo (nth aseq 1000) bar 5] ...) ?
16:38ChousukeLauJensen: adding more stuff to the let makes no difference.
16:38LauJensenSure about that?
16:38Chousukeuser=> ((fn [aseq] (let [foo (nth aseq 1000000) bar 5] foo)) (iterate inc 1))
16:38stuartsierraChousuke: what exactly are you trying to do, anyway
16:38Chousukejava.lang.OutOfMemoryError: Java heap space (NO_SOURCE_FILE:0)
16:39LauJensenk
16:40Chousukestuartsierra: well, in my reader I currently do (let [[item rh] (consume rh)] ...) a lot.
16:40Chousukestuartsierra: but if that causes the old rh to be held, it causes unnecessary slowdown and memory use :(
16:46Chouseryeah, that's a bit tricky.
16:51ChousukeHi, technomancy. I have a question for you. eldoc-mode seems to cause some rather nasty lag within clojure buffers in my Cocoa emacs when scrolling lines. I suspect swank-clojure is to blame... it seems to try connecting to the clojure instance immediately when I scroll to a new line, somehow blocking rendering when I hold down the scroll key. elisp buffers don't have this
16:51Chousukebehaviour, and I noticed they have a slight delay before the arg documentation appears in the minibuffer.
16:51ChousukeBut I have no idea where, or how, to fix that :/
16:52technomancyChousuke: I believe eldoc works with an idle timer...
16:52technomancyso it shouldn't even try to activate until you've paused on a line
16:53technomancywhat's your value for eldoc-idle-delay?
16:53Chousukelooks like it's not working in my clojure buffers :/
16:53clojurebotclojure is a very attractive hammer with a nice heft to it
16:53ChousukeI'll check.
16:55ChouserChousuke: do you have a specific example of where you're running into that OOM error?
16:56ChousukeI'm not getting it with my reader yet, fortunately.
16:57Chousukebut since it appears with the (let [foo (use foo)] ...) pattern, it's quite certainly there :P
16:57Chousuketechnomancy: it was 0.5. I set it to 1.0, with no apparent effect.
16:59Chousuketechnomancy: it looks like it's ignored
17:00Chousuketechnomancy: elisp buffers honour the value, but clojure buffers don't seem to.
17:00technomancyweird; I can't repro myself. and it only occurs when eldoc-mode is on?
17:00Chousukeyeah.
17:00technomancytry ruling out platform-specific problems... do you get it when you run in terminal Emacs?
17:03LauJensenDudes and Dudettes, how do I proxy my way out of something like this
17:03Chousukehmm, clojure-mode doesn't even work in my terminal emacs :P
17:03LauJensenclass SliderListener implements ChangeListener { public void stateChanged(ChangeEvent e) {
17:03technomancywe have more than one dudette now?
17:03Chousukeprobably because it's 22.1
17:04technomancyChousuke: yeah, can you run your 23 install with -nw?
17:05Chousukehmm, it still fails to load. it seems I have some Cocoa-specific configs
17:05technomancyis this a post-1.0-ism? (import (java.util.logging Logger Level))
17:06technomancyChousuke: yeah, I try to toss those into a (when (= window-system 'ns) block
17:06technomancybut that sounds like a yak shave
17:07hiredmantechnomancy: yes
17:08technomancyChousuke: how much do you have on top of the standard clojure-slime-config?
17:08hiredmanI think sometime post 1.0 the need to quote stuff in import and require and use went away
17:08technomancyare you on the starter kit?
17:08technomancyhiredman: cool; thanks
17:08technomancyI'm thinking about backporting contrib's logging lib to 1.0-compat
17:09Chousuketechnomancy: looks like it happens only in Cocoa emacs.
17:09technomancyChousuke: not sure I can help then. =\
17:09technomancyvery strange that the idle-timer behaviour is different
17:10technomancymaybe in the mean time I can clean up the obscene amounts of trailing whitespace in this logging.clj file. =\
17:10Chousuketechnomancy: no, wait.
17:10Chousuketechnomancy: clojure-mode still ignores the delay
17:11Chousukethe terminal version is just quick enough that it doesn't mind the lag I guess.
17:14ChousukeI suspect that if I disable the delay, elisp buffers will get laggy too
17:14ChousukeI'll try.
17:14technomancyChousuke: are you using the starter kit? how much do you have on top of clojure-slime-config?
17:17Chousuketechnomancy: no. I cloned this as a base: http://github.com/purcell/emacs.d/tree/master
17:17Chousukebut I have quite many changes to it already.
17:17Chousukethough, nothing to clojure-mode that should affect this.
17:18Chousukeand I tested on elisp buffers... they work fine even with no delay it seems.
17:18technomancyChousuke: would be interested to know if you could repro with the starter kit as per http://technomancy.us/126
17:18technomancybut again: kind of a yak shave
17:19hiredman~yak
17:19clojurebotfastest sheers on IRC
17:25Chousukehmm.
17:25Chousukeclojure-install seems to have taken over emacs :P
17:25technomancyit does take a while unfortunately
17:25technomancyno concurrency =\
17:26bitbcktIt's even worse when git:// is blocked...
17:26ChousukeI wonder if it's even possible to have proper concurrency in emacs.
17:27technomancyChousuke: well lexical scope is targeted for 24
17:27technomancythat's the main thing holding it back
17:29Chousukeemacs starter kit has no problems it seems.
17:30ChousukeI guess it's something in my config.
17:30JAS415i had better luck doing a manual install
17:31JAS415was not too complicated after i figured out what the heck classpaths are
17:32technomancyJAS415: what problems were you seeing specifically?
17:32technomancycurious
17:32ChousukeMaybe I should see if I could move my config on top of emacs starter kit
17:33JAS415well it was just a matter of I have sbcl installed as well as clojure, and I had trouble finding the stuff that I needed to manipulate to add different libraries and stuff to the classpath
17:34Chousukelooks like it has most of the features I care about anyway
17:34JAS415also i wanted to build from the most recent github version
17:34JAS415so i kind of used clojure-install to get an idea of what things were supposed to look like
17:35JAS415then i uninstalled it and reinstalled it again so I had an idea of how it actually worked
17:35JAS415(reinstall by hand)
17:35technomancyoh yeah, I never bothered to figure out how to use it with CL too
17:36technomancyI figure if you know CL, you're probably capable of figuring it out on your own. =)
17:36ChousukeI'm quite impressed by paredit btw.
17:36ChousukeI couldn't quite figure it out previously, but then I realised how to use barf and slurp and that alone makes it awesome :P
17:37Chousukenext I need to learn the commands for navigating sexps I guess
17:37technomancyI'm working on a screencast.
17:37technomancyslowly...
17:37Chousukethe emacs transpose feature is weird btw.
17:38technomancyclojurebot: paredit screencast is http://p.hagelb.org/paredit-screencast.html
17:38clojurebotc'est bon!
17:38ChousukeI haven't found a single useful use for it yet, but it's interesting :P
17:40lrennChousuke: transpose sexp can be used to move an sexp down (just keep hitting it). I don't use it, but there ya go.
17:49JAS415technomancy: for me its more like i'm stubborn enough to not admit that I can't figure it out
17:55technomancyhiredman: did you say you were able to run clojurebot in slime?
17:55technomancyI'm getting a lot of java.security.AccessControlExceptions from the securitymanager -D args
17:56hiredmantechnomancy: I don't use emacs
17:56hiredmantechnomancy: do you have the policy file setup?
17:57technomancyhiredman: oops. /path/to/this.policy.
17:57hiredmaneasiest if you just copy example.policy to ~/.java.policy
17:57technomancy=)
17:58hiredmanI could not get specifying the path to the policy file to work
17:58Chousukeit needs to be an URL
17:58hiredmanoh
17:58Chousukefile:///path/to/policy.file
17:58hiredmanwell, there you go
17:59technomancyI meant that I had it set to the literal "file:///path/to..." instead of the actual path
17:59hiredmannice
18:00technomancystill getting access denied though... I'll stick with rlwrap for now.
18:00hiredmanI have code for getting clojurebot to work in a multiuserchat with jabber too, I just haven't shoehorned it in yet
18:01ChousukeI did run clojurebot in emacs... hmm
18:01ChousukeI think I have my old emacs config somewhere
18:02mebaran151are compojure and ring likely to merge: it seems like they mirror each other's functionality
18:03hiredmanring is lower level, I think compojure is built on top of ring these days
18:04LauJensenTrue
18:05Chousuketechnomancy: I had '(swank-clojure-extra-vm-args (list "-server" "-Djava.security.manager" "-Djava
18:05Chousuke.security.policy=file:///Users/oranenj/.emacs.policy"))
18:05Chousukewhere .emacs.policy is the example.policy
18:06rhickeyDan Weinreb with nice things to say about Clojure: http://www.youtube.com/watch?v=xquJvmHF3S8
18:06rhickey50 minutes in
18:07rhickeybut the rest a nice survey about the applicability of Lisp to hard problems requiring flexibility, an area Clojure should also cover well
18:13JAS415are there any plans for multiple value return in clojure?
18:14JAS415it would be really nice :-)
18:21mebaran151JAS415, what's wrong with simply packing a vector and destructuring on input
18:21rhickeyJAS415: no plans, sorry
18:22rhickeythere isn't the requisite stack manipulation in Java bytecode for it
18:22rhickeyso it would be 'faked' in any case
18:23rhickeyI had an implementation when first doing Clojure, using thread locals
18:23JAS415ah that's too bad
18:24JAS415membaran: nothing intrinsically, just a little less efficient to be creating and destroying objects all the time
18:24technomancyGC is cheap
18:25JAS415oops x'd the box when i wanted to resize
18:26JAS415well i guess its just i just have sort of a mental differentiation between a vector that i'm destructuring and returning multiple values
18:26JAS415it also seems like people get mislead into writing fairly inefficient code
18:28JAS415there was that 'uncle bob' thread in the clojure google groups and he was asking 'why is this so slow' and it was kind of obvious, as he was making like 8,000,000 2 length immutable vectors and destructuring
18:29JAS415or maybe it was 16,000,000
18:30mebaran151but for multiple return, you would have to pack it in SOMETHING
18:30mebaran151because Java has not native tuple type
18:30hiredmanMap.Entry
18:31Chousuke:P
18:31JAS415unless you can manipulate the stack like rich was talking about, which you can't
18:31Chousukeare thread locals too slow them? :/
18:31JAS415so i'll wait for it along with TCO
18:31Chousukethen*
18:31hiredman,(java.util.AbstractMap.SimpleImmutableEntry. :a :b)
18:31clojurebotjava.lang.ClassNotFoundException: java.util.AbstractMap.SimpleImmutableEntry
18:31hiredmanbah
18:31hiredman,(java.util.AbstractMap$SimpleImmutableEntry. :a :b)
18:31clojurebot#<SimpleImmutableEntry :a=:b>
18:32Chousukehiredman: that's still creating a new object though.
18:32rhickeyJAS415: multiple returns are not coming, so don't wait for them :)
18:32JAS415haha
18:32JAS415fair enough
18:34rhickeythe #1 use case (for me) of multiple return in CL was gethash, covered by optional not-found arg to get
18:34JAS415honestly most of the uses of multiple return in CL i've found have been in incomprehensible spaghetti code
18:35rhickeyOtherwise nice but not necessary. And the inefficiencies today of ephemeral tuples for returns might disappear with the escape analysis of tomorrow...
18:35ChousukeI guess if you have a function returning multiple values or tuples in a tight loop you'll just have to use some mutable thread-local slot to hold the values and unpack them immediately. :/
18:35JAS415the thing is I kind of feel like I want either to be able to return multiple values or to be able to use state
18:37technomancyhiredman: you have some defmultis in clojurebot that check for clojure.lang.PersistentHashMap that should check for IPersistentMap
18:37technomancysince small maps are usually PersistentArrayMaps... you shouldn't care about the size of the map
18:39Chousukerhickey: btw, how do you avoid holding on to the head of aseq in code like (fn [aseq] (let [aseq (consume-a-lot-of aseq)] (first aseq))). I noticed that using let for some reason doesn't "overwrite" the function argument reference and you end up consuming more memory than needed
18:39hiredmantechnomancy: good catch
18:39hiredmanthanks
18:41hiredmanlooks like just the one
18:42rhickeyChousuke: lazy seqs are not ephemeral seqs, so if you realize part/all of it and then go on to use the head you've got the whole seq there. It's not possible to get rid of it since you asked for it and still need it. Args and ocals are cleared on tail calls only (when it is known that they can't be used again). Also, the let 'aseq' and the arg 'aseq' are two completely different lexical things. Calling the let one 'foo' would make no diff
18:45technomancyhiredman: ah, you're right; just one
18:46technomancyunfortunately I'm modifying the codebase pretty significantly or I'd be inclined to send patches instead of just "hey, could you fix..." =)
18:46hiredmanshouldn't really be there anyway
18:46hiredmanI imagine it would take a significant modification to make it suitable for anyone beyond #clojure
18:47technomancymostly just ripping things out so far
18:47Chousukerhickey: in my reader I do (let [[item rh] (consume rh)] (do-something-more item rh))) a lot, and code like that ends up holding on to the old rh for longer than necessary. the thing is, I can't quite see how to avoid that without removing all the lets from my code. :/
18:47technomancyChousuke: you mentioned you were using clojurebot? what for?
18:48Chousuketechnomancy: ages ago :P
18:48Chousukewhen I hacked it from v1 to v2. :P
18:48technomancyheh; right
18:48hiredmanand an excellent job he did
18:49ChousukeI do regret the "dfn" macro though.
18:49Chousukebecause when I re-read my code a while ago I couldn't figure out what I was thinking.
18:49hiredmanhaha
18:50rhickeyChousuke: it would clarifythings a bit for you if you used different names, as I said, they are different things, and reusing the name is giving you false expectations
18:50hiredmanwhat is a code base without its peculiarities
18:51rhickey(let [[foo bar] (consume baz)] (do-something-more foo bar)))
18:51rhickeysame
18:52rhickeybaz will stick around until the tail call to do-something-more
18:55Chousukehmm, I think I will have to restructure my code a fair bit then.
18:55ChousukeNo matter. I have a feeling the end result will be more functional, in both senses of the word
18:57ChousukeMany thanks for the clarification.
19:13technomancyhiredman: also clojurebot would be a lot more repl-friendly if you used defonce for some of your initializing stuff like *bots*
19:18hiredmanyeah, I've been ignoring that part of core
19:19technomancyminor point
19:19hiredmanit hasn't been an issue for me, because I am in the habit of sending a function at a time to the repl, and not a whole file
19:21rhickeyChousuke: it is a possible future optimization to tighten arg/local lifetime to point of last use (instead of tail call), which would solve this problem for you and many others. might not happen until cinc
19:25technomancyis defvar like defonce but with docstring sugar?
19:26technomancyoh, it's not once-only like it is in elisp.
19:30konrDo you guys know of more Clojure examples with Swing, besides the Celsius/Fahrenheit one?
19:33technomancyhiredman: did you take a look at the fnparse followed-by problem?
19:36jfieldshow can I convert a char to a byte, eg \A to 65
19:37technomancy,(int \A)
19:37clojurebot65
19:37jfieldsthanks
19:55konrdo you guys know of any enclojure (preferably with matisse) tutorial?
20:02cemerickthere's a PDF tutorial in the google group, IIRC
20:30hiredmantechnomancy: I haven't
20:34hiredmanthey are some big changes between the version I am using and the latest version
20:34technomancystrange that I'm still getting that error with the fnparse jar you sent me though
20:34hiredmanoh?
20:35hiredmanuh
20:35hiredmanI hope I gave you the right one
20:35hiredmanyeah, that is the same jar I have in ~/.jars/
20:35technomancycould you give me the URL again?
20:35hiredmanSHA1 (.jars/fnparse.jar) = b281abd4b298f5cdbac876791629e2014e356867
20:36technomancythat's what I've got. weird
20:36hiredmanhttp://www.thelastcitadel.com/lab/fnparse.jar
20:36hiredmanhmmm
20:37technomancyno big deal; I don't really need factoids now
21:12tomojwhat's the deal with sync vs dosync?
21:13tomojoh, nevermind, rich explained it a few seconds later :)
21:33hiredmanhaha, "what the hell, just crash it"
21:33hiredmanclojurebot: memory leak is <reply>what the hell, just crash it
21:33clojurebotIn Ordnung
21:48JAS415clojurebot: memory leak
21:48clojurebotwhat the hell, just crash it
22:55technomancyany jruby people; I've got my clojure-gem working pretty decently: http://github.com/technomancy/clojure-gem
22:55technomancysupports dosync and the 4 major persistent collections
22:55technomancyjust no lazy seqs yet.
22:59Chousertechnomancy: nice. We're using a mix of C++, Java, Clojure, and JRuby now.
22:59ChouserI'll pass the URL along to our ruby guy.
23:00hiredman(through the bars of his dank prison cell)
23:02TheBusbyinteresting mix of languages, end up with C, Ruby, Clojure here
23:02TheBusbyseems like a combination of C/C++ for performance, Clojure for structure, and ruby/python for scripting is becoming very common
23:03hiredmanfunny, I seem to recall someone predicting clojure for scripting and scala for structure
23:04Chouserour C++ is for legacy reasons more than performance
23:04TheBusbyalthough I'm very fond of clojure, ruby's simple string handling, quick startup time, and backticks make it much easier for scripting I think
23:04RaynesIt's sad how when people see a side-by-side of Clojure and Scala they see 'OOP' tacked on Scala's side, and immediately lose interest in Clojure. :|
23:15technomancyRaynes: it's arrow-oriented!
23:22hiredman~scala
23:22clojurebotScala often gets in the way when trying to write neat code -- seen in #scala
23:24TheBusbyI'm just waiting for a language to come out that compiles to C code
23:25hiredman:(
23:25hiredmanmy facilities does C offer to entice language designers?
23:25TheBusbyit compiles on every platform
23:25hiredman
23:26TheBusbypick just about any chip/platform/system these days, and they all have support for C
23:27TheBusby(speaking mainly for the embedded world)
23:27hiredmanthey don't support C, there is a compiler that turns C into asm for the chip
23:28TheBusbycorrect, and for many platforms that is the only compiler available for that chip
23:31albinoTheBusby: Seen gambit-scheme?
23:31TheBusbyno, googling now
23:33albinoThere have been some blog entries lately on using gambit to generate C that runs on the iPhone
23:33TheBusbyalbino: much appreciated, I'll be trying this out at once