#clojure logs

2008-10-11

06:28Lau_of_DKIn emacs, the default binding for Clojure-eval-defun is (C-M-x) but this does not work for some reason, simply no reaction. How do I bind this function (that I dont even know whats called) to something like C-c c ?
06:30tWipDoes C-h k C-M-x describe the command?
06:31tWipI think it should be lisp-eval-defun
06:31Lau_of_DKtWip, it does not, no reaction
06:32Lau_of_DKbut yes, the command is lisp-eval-defun
06:32tWipyou could try M-x local-set-key
06:32tWipto bind it
06:33Lau_of_DKWhat is the shortcut for ending the key-sequence, if I press enter it does includes that in the mapping
06:35tWipIt should work without enter
06:35tWipI'm not really an emacs master myself.
06:35Lau_of_DKOk, I'll fiddle with it. Thanks alot tWip
06:35Hunare you sure the major-mode is proper? it might just eval it as a emacs-lisp-defun
06:36Hunhere C-M-x is bound to slime-eval-defun which sends stuff through swank
06:37Lau_of_DKIf you mean wether or not I'm on Clojure-mode, then yes I am
06:37Hunoh, clojure-mode. don't know that, i use slime with clojure here
06:39Lau_of_DKSame here, Clojure-mode only handles formatting I think
06:40Lau_of_DKAnyway, we can drop the subject, because when I bound it to C-x C-x it actually works, so I'm up and running
06:40Lau_of_DKThanks alot for your input, both of you
07:04leafwis there any reason why (map println (range 0 10)) prints numbers mixed up with the sequence full of nils ?
07:05leafwI would expect the sequence to print at the end, not at every iteration
07:25fyuryuleafw: you should avoid side effects in map
07:25fyuryuleafw: (doseq i (range 0 10) (println i))
07:26leafwit was just a test
07:32leafwI can't find how to say: do this N times.
07:33leafwwithout (doseq i (range 10) (....)) , where I don't need the i at all
07:33leafwsame for looping. And for map, it creates and returns a seq that I don't need
07:34kotarakleafw: then you use side-effects. I would try to eliminate the side-effects if possible.
07:35kotarakside-effects are not the way clojure encourages..
07:35leafwI need the side effects.
07:35leafwI know. Thanks anyway. this is an exisiting library, can't override its behaviour, just script it nicely.
07:35kotarakthen what changes between the loops?
07:35kotarakIterate over that instead of "i"
07:36leafwI am processing lines of an image with multiple threads. Each thread grabs the next available line for processing.
07:36leafwthe side effect is the editing of that image. And no I can't afford to duplicate it, not enough RAM.
07:40fyuryufor i in range(N): do_something() is a a common idiom in python
07:40fyuryuit translates nicely to Clojure with doseq or dotimes
07:41leafwdotimes, that's it
07:42leafwgot erased from my mind for some reason
07:46leafwstill, dotimes also uses an iterator ... never mind
08:17leafwI am puzzled by an error message: java.lang.IllegalArgumentException: Unable to resolve classname: int (macro_multithread.clj:72)
08:17leafwthe code: (let [#^int offset (* width row)]
08:17leafw...)
08:18leafwwhere width and row are also declared as #^int
08:18kotarakHmmm... int is no class. Try #^Integer maybe.
08:19kotarakI don't whether one can declare basic types like this.
08:19kotarakI don't know ..
08:19leafw(let [#^int i 0] (println i))
08:19leafwthis works.
08:20leafwbut I am not sure if it does what I intend
08:21leafwdebugging clojure remains ... hard. Very hard.
08:23leafwand with macros, java stack traces are wrong.
08:23leafwi.e. they don't point to the right line on the code
08:27leafwand it would be great if macroexpand would print the statements with indentation and in separate lines ...
10:14Chouserleafw: I think primitive locals are declared thus: (let [offset (int (* width row))] ... )
10:15leafwthat is casting, which sets the value, but does not add type declaration to the offset (I think)
10:15Chouseryeah, I know one woudl think that, but I'm pretty sure that's how you get a primitive local.
10:15ChouserLet me see if I can find an example.
10:16leafwok, let's see
10:16leafwindeed #^int is not accepted
10:17rhickey_leafw: this is pretty well documented at: http://clojure.org/java_interop, under Support for Java Primitives - did you read that?
10:18leafwI read indeed, rhickey_
10:19leafwbasically it means it's automatic. i.e. (let [offset 512] would have offset as primitive directly
10:19leafwis that right?
10:20rhickey_No, 512 is an Integer without the (int ..) coercion
10:20rhickey_else math would be bad by default
10:20leafwby the way I created a macro to multithread the processing, in place, of lines in an image ... if there's something grating about it that I should know, I would appreciate very much. It's named "multithreader" and it's here: http://pacific.mpi-cbg.de/cgi-bin/gitweb.cgi?p=fiji.git;a=blob;f=plugins/Examples/Multithreaded_Image_Processing.clj;hb=HEAD
10:21leafwrhickey_: ok, then I need to add a couple of casts. Someday ...
10:21leafwthanks for your infinite patience -- if anything reasures me of the outcome of a project, is the patience of its developer(s)
10:28Chouserprintln will print the number and then return nil
10:29Chousergah, sorry, I was scrolled way back.
10:41alecIs there a clean way to create a map with keys as strings and do case-insensitive lookups, like a Common Lisp equalp hash? I can always hack up an indirect lookup.
10:44ChouserI don't think so. I'd just use a transformed string as the key, and keep the original key and value in the map value.
10:45Chouser{"foobar" ["FooBar" "value"]}
10:47Lau_of_DKIs there someone in this group, who has superior RegEx skills?
10:48ChouserLau_of_DK: Try asking your question, maybe someone will know something.
10:50Lau_of_DKOkay, I just figured that it wasn't too polite to have the actual RegEx discussion in a Clojure group. But since you ask :) I need a Regex that can identify the longest recurring cycle of digits in a string. For instance "1111111" is seen as a 1-digit cycle, and "123456123456" is seen as a 6-digit cycle
10:50Chouserhm, that's a good point -- wouldn't want to be OT
10:50Lau_of_DKOkay - Feel free to MSG me if anybody has a take on this
10:55alecLau_of_DK: regular expressions are probably inappropriate, but I bet you could write some cool Clojure code taking a dynamic programming approach, and then it'd be on topic
11:02Chouser(second (re-find #"^(.*?)(?:\1)*$" "123123123123"))
11:03Chouserhm, I think that's the shortest recurring cycle.
11:04Chouseroh, and that requires my regex patch to clojure
11:05rhickey_Chouser: sorry I haven't pulled the trigger on that - not for lack of support for it - just working on extensible print/read
11:06Lau_of_DKChouser, how to I apply the patch, and how does this patch extend Clojures way of doing it ?
11:06Chouserrhickey_: np -- I don't see it as urgent, as long as it's inevitable. ;-)
11:06rhickey_Chouser: yes, inevitable
11:06ChouserLau_of_DK: skip it. Without my patch, use #"^(.*?)(?:\\1)*$"
11:06Chouserrhickey_: you're changing how read/print work?
11:07Lau_of_DKk
11:08rhickey_Chouser: extending - #=(java.util.HashMap. {:a 1 :b 2 :c 3}) will read a literal HashMap
11:08rhickey_#=(java.util.Date. "Sat Oct 11 11:05:23 EDT 2008") reads a Date
11:08Chouserrhickey_: ah, right. forgot you were working on that. Does the syntax keep chaning?
11:09rhickey_as does #=(java.util.Date. 2008 10 11)
11:09rhickey_#<...> doesn't work because > is not a terminating macro character, i.e. it is a constituent character - can be part of a symbol
11:10rhickey_I don't want to repeat the C++ space before > travesty
11:10Chouserindeed!
11:12rhickey_but I've refined the semantics over the last couple of days - I had ##(expr) which evaluated the expr, but that ends up being too big a hammer for read, so #= constructs values with the unevaluated (i.e. as-read) args
11:13rhickey_ends up being very nice, essentially you can read it as - the value you would get from this expression, give literal args
11:14rhickey_it means people can extend print/read by just making prints that target #=
11:14ChouserAh! nice
11:14rhickey_you can call ctors, static methods and instantiated vars
11:16rhickey_plus class literal: #=java.util.ArrayList, and vars: #=(var clojure/rest)
11:17rhickey_makes print/read a powerful and easy serialization tool
11:17tWipso you could embed java serialized objects in sexp
11:17rhickey_always on the todo list but I need it for AOT compilation
11:17rhickey_tWip: yup
11:18tWipvery nice, clojure seems to be going forward in leaps and bounds
11:28rhickey_A Clojure-derived Lisp for the AVM2: http://github.com/aemoncannon/las3r/wikis
11:33rhickey_Chouser: you and he should talk
11:33Chouseryeah, looks like he's done more work than I
11:34rhickey_He's transliterated the compiler and dropped a bunch of stuff, I think the ClojureScript approach (just a different backed + support libs) has definite advantages
11:34rhickey_back-end
11:34rhickey_ClojureScript is still Clojure
11:36Chouserare you in touch with him? I see only one post that might be his on the group.
11:40rhickey_Chouser: not too much, he contacted me once or twice when starting out, then last night to let me know it was up
11:42rhickey_fun - this is the default print behavior:
11:42rhickey_user=> (java.util.Date.)
11:42rhickey_#=(java.util.Date. "Sat Oct 11 11:36:40 EDT 2008")
11:42rhickey_That's with no special print for Date!
11:43ChouserI'm way too lazy to solve the problem the he'd done. He's going to have work to do to keep his boot up to date.
11:43rhickey_Chouser: right, it's not Clojure anymore
11:43Chousernice. And Date will probably even read that, right?
11:43rhickey_exactly
11:44tWiphow do you know that Date does not have some secret state?
11:44rhickey_many types have ctors that can read their toString output
11:44rhickey_if they do, this works by default, if not define custom print
11:45Chouserbut now that print is a multimethod, that's easy to provide without a Clojure patch.
11:45rhickey_tWip: if they have a public string ctor, it'd better produce a valid object
11:45rhickey_Chouser: right again
11:45ChouserAnd read is sufficiently generic already that new patches there shouldn't be necessary.
11:46Chouser...with the exception of things like my #"" which want to screw around with quoting rules.
11:46tWipyes, but If I have a class that has a public string ctor, but still has some other state that is not printed in toString)
11:46rhickey_It solves a fundamental problem, that the reconstitutor might not have the corresponding libs loaded yet, or ever
11:47rhickey_tWip: then you define a print-method for that class, this is just a useful default
11:47tWipok, so it is optimistic in trying a public string ctor, if available
11:47tWipI agree, that it will be very useful in many cases
11:48rhickey_the only other possible default is error
11:56Chouseraemon's containers can't be called.
11:56ChouserI don't really like how that works in ClojureScript right now.
11:56ChouserBut the other solutions I've thought of are all rather clumsy too.
11:57rhickey_Chouser: how so?
11:58ChouserAFAICT, the only thing that can be called directly in js is a Function.
11:59ChouserA Function can either be made using the constructor and passing in a string (ew!) or literally saying function(){}
12:00ChouserI could possibly make container instances using function(){}, but they'd essentially be closures (which I've now learned is slow) and they wouldn't participate in js inheritence.
12:01ChouserSo for now, anytime I generate code to call something that might be a container, I emit foo.apply(this,[...])
12:02Chouserapply works on real functions, and is also a method I've written for AFn.
12:02rhickey_sounds ok to me
12:07ChouserIt's a bit slower than a regular function call. I don't know if it's just the new array being made, or if the call itself has more overhead.
12:07Chouserplus it's ugly :-/
12:08rhickey_I missed the array, yeah.
12:10ChouserAnother option is foo.call(this,arg1,arg2,...), but that's also slower than normal.
12:10ChouserI guess I need to do some more complete profiling and see how fast I can make either of those.
12:11rhickey_Chouser: profiling JS is dangerous, as there is so much platform variance, plus there's a perf war going on (can only help in the long run)
12:11Chouseryeah
12:12Chouser"complete" includes each test on at least 4 browsers. bleh
12:12rhickey_No point in optimizing for anything other than the top-of-the-line engines - V8, WebKit, as they or similar tech will soon win
12:13rhickey_and likely be the most viable platforms for ClojureScript
12:13Chouserwell there's Chrome, WebKit, and Firefox -- plus you still can't afford to ignore IE
12:14rhickey_you want to make sure it works there, sure
12:14ChouserOpera's not shabby either, and has a good chunk of the mobile market still
12:15rhickey_sorry I meant to say et al before, not to limit to V8/WebKit
12:15rhickey_just that _optimizing_ for older JS implementation tech is a waste of time, they'll all be doing what V8/WebKit do soon enough
12:17Chouserperhaps you have more confidence in IE than I :-)
12:19rhickey_people who use IE get what they deserve
12:20rhickey_Chrome exists for a reason
12:25arohnerlisppaste8: url
12:25lisppaste8To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.
12:26lisppaste8arohner pasted "repl no exception" at http://paste.lisp.org/display/68317
12:26arohnerif you manage to throw an exception that is caught on that line, the repl does not print a stack trace
12:26arohnerthe paste fixes that
12:30arohnerstill trying to figure out what I did, but the original error was not helpful
12:30arohnerjava.lang.RuntimeException: java.lang.IllegalArgumentException: Too many arguments to struct constructor (NO_SOURCE_FILE:0)
12:32rhickey_new print/read support is up, rev 1061 - tire-kickers encouraged
12:35kotarakrhickey_: Exception in thread "main" java.lang.IllegalArgumentException: Multiple methods match dispatch value: class clojure.lang.APersistentVector$Seq -> interface java.util.Collection and interface clojure.lang.ISeq, and neither is preferred
12:40kotarakAlso (doc var) works, but (print-doc var) says "unable to resolve symbol: var in this context".
12:43kotarakOk. Forget the last one.
12:54aleckotarak: I get that one, too, but only when starting via slime
12:54alec(the first one, IllegalArgumentException)
12:55kotarakthe second one is stupidity of mine. Just ignore...
12:56kotarakI get the first one by starting a new REPL and do a (doc doc).
13:00arohnerfound it. resultset-seq explodes if your query has duplicate column names
13:00arohnerrhickey: what would you like resultset-seq to do in that case?
13:03Chouserkotarak: you got that exception by doing something like (seq [1 2 3]) ?
13:04kotarakChouser: I did actually (doc doc), but (seq [1 2 3]) also throws the exception.
13:58achim_pmmh, there seems to be something wrong with the latest rev - sequences won't print
13:58achim_p(prefer-method print-method clojure.lang.ISeq java.util.Collection)
13:59achim_pthat's probably missing in boot.clj
14:18qawsxanyone own a lisp-machine?
14:30Lau_of_DKCould somebody point me in the right direction of how I make an optimal Decimal expansion in clojure?
15:19arohnerdoes anyone else get frustrated by slime's default behavior with exceptions?
15:20arohnerI don't really understand how to use it, and it just gets in my way
15:33alecit's not so nice in Clojure because it only gives you the option to abort or move up the stack trace (which is also pretty useless)
15:33arohneris the moving up the stack trace supposed to show you the exception cause?
15:34arohnerbecause that doesn't seem to work
15:34alecit does in other lisps; I don't know if there's enough machinery to support it in Clojure yet
15:36arohnerI'd also like if there were an option to disable the exception thing popping up in emacs, so it would just print the exception in the repl
15:36alecthat would be a useful improvement
15:36rhickey_acj, sorry about print in 1061 - I'd made half a change I didn't intend to check in
15:37rhickey_all should be well now, I've made an enhancement so that prefer-method handles entire trees - it was too tedious to make each specific preference
15:38rhickey_so, e.g. (prefer-method print-method clojure.lang.IPersistentCollection java.util.Collection) says prefer all IPersistentCollections to all java.util.Collections
15:48pointerfuncan anyone see me or i need to register?
15:48Lau_of_DKWe see you :)
15:49pointerfunok so must just be that the c-people are ignoring me
15:50Lau_of_DK:(
15:52pointerfunANYONE KNOW C? if i have a function that takes a string should ibe of the type char or char[]?
15:54arohnerpointerfun: you know this is a channel for a lisp on the jvm. Not really the place for C questions
15:57danlarkinchar *
15:57danlarkin:-D
15:58pointerfun*? that menas pointer no?
15:59danlarkinpointerfun: you're in the wrong channel, try #c
17:53H4nsXlisppaste8: url
17:53lisppaste8To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.
17:55lisppaste8H4nsX pasted "Proper? Slow?" at http://paste.lisp.org/display/68331
18:08Chouserlooks fine to me. This is to allow replacing individual methods without replacing the whole object?
18:09H4nsXno, it is just some syntactic sugar. i'm still thinking of ways to make working with java apis more pleasant, and one of the things that disturbed me was the syntax for proxy, as it allows for object as well as interface instantiation, where i only need interfaces.
18:10H4nsXalso, i do not like writing the handlers in-line, thus the apply/partial thing. that way, i'll have very short implements clauses when calling the java framework
18:11H4nsXi am not sure whether the apply will incur a (notable) performance penalty. i guess not, but as i am new to clojure, i rather ask :)
18:38Chouseryou don't need the apply if there are not pre-applied-args
18:41Chouseractually, in neither case.
18:46lisppaste8Chouser annotated #68331 with "implement without apply" at http://paste.lisp.org/display/68331#1
18:46Chouserthen you're always incurring a single extra function call, which is the sort of thing HotSpot is supposed to be able to inline away.
21:10pjb3So now that maps are Maps, we have another problem
21:10pjb3clojure maps typically are keyed by keywords
21:10pjb3java Maps are typically keyed by Strings
21:11pjb3so passing {:foo "bar"} into a Java method that calls whatever.get("foo") isn't going to work
21:12pjb3So we could write function to convert all the keyword objects in a map to string
21:12pjb3but I'm wondering if there is a way to avoid that
21:44danlarkinproxy is confusing me, anyone have an example to point me towards? there's only two uses in clojure-contrib
21:51Chouserdanlarkin: there's one on the wiki as well
21:52ChouserAlso: http://groups.google.com/group/clojure/browse_thread/thread/3c3a2ef16d2b0467/d9aed18eb65abdff?pli=1
21:55danlarkinAh ha, I see what I was missing... proxy "Expands to code which creates a instance of a proxy class that implements the named class/interface(s)"
21:55danlarkinso it doesn't create a class, but an instance of a class
21:55danlarkind'oh
21:56Chouserright. Actually, it creates a class behind the scenes the first time, and reuses it next time you call proxy on the same class/interace
21:56Chouserbut it returns the instance, not the class.
21:56Chouserif you actually need a class, you have to use gen-class
21:58danlarkinmmhmm, so when the code in mmap.clj calls (proxy [InputStream] ...) as a function, that's because InputStream implements runnable, or callable?
21:59Chouserthat seems unlikely.
22:00Chouserhey, I wrote this. hmm...
22:00Chouserok, calling buffer-stream creates a new InputStream and returns it.
22:00danlarkinnot knowing java definitely makes it harder to understand how to do some things in clojure :-[
22:01Chouserload-file passes that new InputStream to a new instance of InputStreamReader
22:01Chouserheh, someone was just complaining to me today how not knowing lisp makes Clojure docs hard to understand.
22:01danlarkinhaha
22:01danlarkincan't win!
22:03danlarkinok so InputStreamReader takes an instance of InputStream in its constructor. And that's what buffer-stream returns
22:03danlarkin(an instance of InputStream)
22:03Chouserthere you go.
22:05danlarkinso (. (buffer-stream (mmap f)) available) would be valid, for instance?
22:23Chouserdanlarkin: right
22:29danlarkinChouser: great! thanks