#clojure logs

2011-07-02

01:11hiredmanamalloy: `(quote ~x)
01:21amalloyhiredman: good point. the compromise is more readable than either extreme
02:00replacatechnomancy: are you hanging around late on a friday night?
03:09replacaare re-split and re-partition gone in the new contrib layout?
03:09replacaI could really use a function index of this new stuff
03:09replacaoh wait, I'm writing that code now... :)
05:27fliebelI remember seeing some talk about simplicity by someone of clojure/core. Anyone knows what that was?
05:32teromPerhaps this one? http://blip.tv/clojure/stuart-halloway-simplicity-ain-t-easy-4842694
05:33fliebelterom: Probably, I only remember it being long.
05:35fliebelterom: No, it wasn't that.
06:12stamphi
06:12stampwhat framework do you recomend for simple blog?
06:13stampI now little of clojure and didn't play with any frameworks
06:14fliebelstamp: Why do you want a framework for a blog?
06:18stampsimplest project to learn
06:19fliebelstamp: What I mean is, what do you want to get out of it? Get a blog? Use Wordpress or Jekyll. Learn X? use Y.
06:19stamplearn clojure and make blog with more than one contributor
06:27fliebelstamp: I'd go for the module bits on top of ring. I have the feeling that using things like Sandbar and Compojure teach you Clojure like Rails does ;)
06:27fliebel*modular
06:32stampfliebel: so i should build my own microframework on top of ring?
06:34fliebelstamp: Well, I'd say you have different options. If you write directly on top of Ring, you'll probably learn more clojure than using the RoR of Clojure. If you want to get going quickly with a simple CRUD app, Sandbar is probably faster.
06:35stampok, i'll check both options
06:36fliebelstamp: Another nice options is writing a static site generator, and use git for the multiple author aspect.
07:26DranikI'm trying to insert an entity to DB using SQL. How to get the id of the inserted entity?
09:00schasiCan I see the stepwise execution of something like reduce?
09:04fliebelschasi: reductions does that
09:04fliebel&(reductions + [1 2 3 4 5])
09:04sexpbot⟹ (1 3 6 10 15)
09:09schasifliebel: I meant one step in the execution of reduce :) like (reduce + [1 2 4]) -> (reduce + (+ 1 2) [3]). Or something. Don't really get the sourcecode of reduce :D
09:10fliebel$source reduce
09:10sexpbotreduce is http://is.gd/SRobxr
09:11schasiWith "don't get" i meant "don't understand on reading". But I might just have gotten it. But thank you :)
09:12fliebelschasi: You could copy the code and replace calls to reduce/recur with println to see one step of the execution.
09:14schasiThanks
09:26mneedhamHey all - beginner question for ya. I'm trying to use one of the functions listed on clojure.java.io - http://richhickey.github.com/clojure/clojure.java.io-api.html#clojure.java.io/output-stream - but I'm not sure how to do that. I have the REPL running with 1.3.0 but when I try to require the namespace I end up with an error
09:26mneedhamuser=> (:require clojure.java.io)
09:26mneedhamCompilerException java.lang.RuntimeException: java.lang.ClassNotFoundException: clojure.java.io, compiling:(NO_SOURCE_PATH:1)
09:27mneedhamany ideas?
09:42fliebelmneedham: If you use a standalone require, don;t use the keyword ;)
09:42fliebel&[:require require]
09:42sexpbot⟹ [:require #<core$require clojure.core$require@10dbc37>]
09:43mneedhamnot sure I understand, sorry. What should I be doing instead?
09:44Chousukemneedham: :require is part of ns's syntax, "require" is what you want
09:44Chousuke(doc require)
09:44clojurebot"([& args]); Loads libs, skipping any that are already loaded. Each argument is either a libspec that identifies a lib, a prefix list that identifies multiple libs whose names share a common prefix, or a flag that modifies how all the identified libs are loaded. Use :require in the ns macro in preference to calling this directly. Libs A 'lib' is a named set of resources in classpath whose contents define a library of Cloju
09:46mneedhamok. So should I expect (require clojure.java.io) to be ok if I'm just running a 1.3.0 based repl?
09:47Chousukemneedham: you might need to quote the symbol, I don't remember whether require is a macro or a function.
09:50mneedhamahhh cool - thanks for your help
09:50mneedhamI was trying to understand what's happened with clojure contrib - I last played with clojure about 18 months ago
09:50mneedhamhas some of the contrib stuff been pushed into the main libraries?
10:11pcavswhy is this room so empty? Usually at least 100+ people in here...
11:06mneedhamis there anyway from the repl to see which methods are available to call on an object? google hath failed me so far
11:13ahritaurhello, is there any way to print something to web-page? I have clojure+compojure+hiccup and i want something like (dotimes [i 4] (printToWebPage someDynamicContent)
11:55mudgehello
11:56mudgeI want to convert clojure source code files into java source code automatically, any recommendations on how to do that? if it is even possible?
11:56pcavsYou could do something really awful like compile clojure, then use a decompiler to decompile it into ugly java...
11:57pcavsmudge: but I don't think that would be a good idea. What's the use case here?
11:57mudgepcavs: yes, i was thinking of trying to use a decompiler
11:58mudgepcavs: to be honest, my boss will absolutely not except any programming language except Java but I want to write in Clojure, so I thought if there was a way to generate exceptable Java from clojure source ...
11:59pcavsmudge: ouch, doesn't sound good. I don't really see that working...You'd lose out on the entire purpose of Clojure I think.
11:59mudgepcavs: why?
11:59mudgepcavs: if i could just write clojure in the normal way and if it could be converted to Java source and it was good enough, what's the downside?
12:00pcavsmudge: because the decompiled java bytecode will be impossible to understand and extremely ugly java code. It would be unmaintainable as java code, so in order to change it you'd really be changing your clojure code and then compiling it and decompiling it again.
12:00pcavsSo the decompiled java source code isn't really the source code
12:00pcavsit's some sort of fake intermediary
12:01mudgepcavs: i see, so perhaps it isn't really possible then
12:01pcavsat least that's my 2 cents
12:01mudgepcavs: have you played with a decompiler and seen its output?
12:02mudgeit would be cool if Clojure had a function that converted clojure source to java source
12:02pcavsmudge: I have not, but I've decompiled straight java code before, and it's quite ugly from what I remember, but this was back in Java 1.3-4 days so maybe the decompilers have gotten ebtter.
12:02clojurebothmm… sounds like your out of heap space
12:03mudgepcavs: okay, i'll check it
12:48mudgepcavs: i used a java decompiler, i think decompiling clojure bytecode into java source is too unreadable
12:48pcavsyeah, I kind of thought that would be the case
12:49mudgepcavs: I wonder if it is possible to write a clojure program that takes clojure source as input and outputs readable java code
12:50mudgepcavs: that sounds like an interesting project
12:50mudgethe readable java source could depend on clojure libraries
13:13roblallyWhat are people's thoughts on Matchure? It looks nice, but I'm nervous about building a dependency on it. With the imminent arrival of 1.3 and the lack of recent project activity....
13:34fliebelroblally: Dunno, I din;t like it very much, so I wrote this: http://pepijndevos.nl/clojure-micro-pattern-matcher/index.html
13:35roblallyInteresting, fliebel, I'll take a look.
13:41fliebelIs there any sane way of implementing IFn? ... Without implementing all ±30 methods. I think dnolen had a huge macro for it somewhere.
13:42fliebelIMO, varargs is one point where Java interop fucked up.
13:46cemerickfliebel: extend AFn, and override the arities you want
13:46fliebelcemerick: I want varargs ;)
13:49midswhat is the name again of that convenience wrapper around compojure / hiccup? it sounded like webiv
13:50gfrlogwhat do you get by wrapping compojure and hiccup?
13:51midsI could tell you if I remembered the name/site :)
13:52gfrlogwell you must know what it does if you know that you want to use it :P
13:52cemerickfliebel: then extend RestFn :-)
13:52fliebelcemerick: RestFN? awesome, going to look it up :)
13:53cemerickfliebel: https://gist.github.com/1061456
13:53midsgfrlog: iirc it wrapped a couple rest/compojure/hiccup/sandbar things in a single dsl
13:54gfrlogah ha
13:55fliebelwhoa. that is a lot of java code...
13:58fliebel$mail dnolen cemerick showed me RestFn, which could solve your IFn implementation problem as well, I think.
13:58sexpbotMessage saved.
13:58cemerickfliebel: exactly; best to make use of it if it solves the problem.
13:59cemerickIt being a concrete base class is likely a difficulty in certain circumstances, tho.
13:59fliebelcemerick: yea, I guess. maybe dnolen just avoided it for performance reasons :D
14:00cemerickThere is no penalty for calls to subclasses of concrete bases. The problem is e.g. you can't make a deftype a RestFn.
14:05hiredmancemerick: does it need to be? can't you just provide doInvoke from IFn?
14:07cemerickhiredman: doInvoke isn't anything special; it's the massive pile of boring args -> args + rest conversions in RestFn's invoke impls that you need
14:07hiredmanroblally: matchure and a few other libraries I looked at struck me as digusting, so I also wrote my own too
14:07cemerickThat could get macro'ed in easy enough, but that's a lot of class-size overhead in every single variadic fn for not a lot of benefit.
14:08hiredmancemerick: are you sure about that?
14:08cemerick(again, the concrete base class limitations still being relevant)
14:08cemerickwhat, the class-size overhead?
14:08fliebelhiredman: Where does yours live? Which other?
14:09hiredmanhttps://github.com/hiredman/match
14:09hiredmanfliebel: I forget exactly, I looked at two at least, and one of them was matchure
14:10hiredmanhah
14:10hiredmanand I have my own cond-let too
14:10fliebelhiredman: Hah, you use core.logic :)
14:11hiredmanyeah, but it's not like I know how it works or anything
14:12fliebelhiredman: So how is yours different from Matchure? It too is 90% macro and has the silly a? syntax.
14:13hiredmanmatchure may have been the one that wasn't updated since pre clojure 1
14:13hiredmanone of them did eval'ing + fn creation which broke recur
14:16hiredmanneeded it for https://github.com/hiredman/moravec/blob/master/src/moravec/four.clj
14:21fliebelhiredman: What's that?
14:22hiredmanit may some day be a compiler
14:22hiredmanwell, I guess it is already, it can generate byte code for the λ calculus
14:22hiredman(I got closures working last night)
14:22dnolenfliebel: yeah I looked at RestFn, don't think I need it since I can sit in front of IFn w/ a macro.
14:25fliebeldnolen: Can I see your macro?
14:25dnolenfliebel: I could be wrong look at prelude.clj in core.logic.
14:38admiralbumblebe3Im new to clojure and I'm having a bit of an issue.. when I try: (byte-array (map byte [0xF0 0x41 0x32 0x00 0x05 0x00 0xF7])), I get the error "java.lang.IllegalArgumentException: Value out of range for byte: 240"
14:38admiralbumblebe3what am I misunderstanding here?
14:39hiredmanon the jvm bytes are *signed* values, crazy
14:39morphlingadmiralbumblebe3: java bytes are signed, -128 to 127
14:39admiralbumblebe3oh.. damn
14:40admiralbumblebe3thats what I get for not knowing java
15:46fliebelDoes Daniel Renfer com in here sometimes? He's working on OStatus in Clojure it seems.
16:40mattmitchelli'd like to create a macro that "captures" the & body arg in a hash, and returns the hash. I can't seem to figure out how to capture the syntax quoted & body arg. Would someone mind giving me a clue on to how to do something like: https://gist.github.com/1061620
16:44gfrlog mattmitchell: I'm a bit confused about the backquote there
16:45gfrlog(defmacro def-field [a b] {:fields a, :builder `(quote ~b)})
16:46gfrlogcan you try that and say what's wrong with it?
16:46mattmitchellgfrlog: well, I'll tell you what I'm trying to do. I want to "capture" the body, so I can call it later. So I assumed I'd need the syntax quoted value?
16:46mattmitchellgfrlog: oh sure, let me try
16:47gfrlogapparently it returns {:fields [:data], :builder (str "hello!")}
16:47gfrlogmattmitchell: creating a function to call later would be insufficient? you need the actual form?
16:48mattmitchellgfrlog: I guess I didn't want to have to call fn everytime I setup one of these "fields"
16:48gfrlogmattmitchell: you can do it in the macro
16:48gfrlogI'd bet half of all macros exist mostly for doing that
16:48gfrlogso let's change the macro definition to...
16:48mattmitchellgfrlog: oh, you mean create a function that wraps the body, the returns the function?
16:49mattmitchellok :)
16:49gfrlog(defmacro def-field [a & b] {:fields a, :builder `(fn [] ~@b)})
16:49gfrlogworks for me
16:50gfrlogI changed the args so that you can give several forms for the function, for side effects
16:50mattmitchellwow, that's awsome
16:51mattmitchellgfrlog: thank you for that. Very helpful. I'm going to pull that apart and see if I can get my tiny brain to understand :)
16:51gfrlogmost of the macros I write assemble a fn for some reason or another
16:51mattmitchellgfrlog: ok, so that's a typical way to "capture" the body and eval later?
16:51gfrlogany macro called (with-<something>) usually doest hat
16:51gfrlogmattmitchell: yep
16:51mattmitchelli see
16:57mattmitchellgfrlog: if I wanted to pass an arg to that function, how would I do that? I get a "Can't use qualified name as parameter"
16:58gfrlogmattmitchell: um
16:58gfrlogis that gonna be like a magic thing? like you'll call (def-field [:a] (+ x 12))
16:58gfrlogand the macro will set it up to have an arg called x?
16:58mattmitchellgfrlog: exactly, although... is that a bad thing?
16:59gfrlogI think it makes the code confusing. I've done such a thing only once, and tried to avoid it otherwise. If you explain the use case a little more I might be able to recommend something else. But yes, this is possible.
16:59gfrlogThe reason what you tried didn't work is because the symbol is being processed by backquote; so rather than:
17:00gfrlog%`(fn [x] (+ x 12))
17:00Chousukemattmitchell: in general, it's best to just let the user decide what to bind things to, even if there's just one that's almost always bound to the same name.
17:00gfrlog&`(fn [x] (+ x 12))
17:00sexpbot⟹ (clojure.core/fn [clojure.core/x] (clojure.core/+ clojure.core/x 12))
17:00gfrlogyou'd want &`(fn [~'x] (+ x 12))
17:00mattmitchelli see ok
17:00gfrlogdamn I'm bad at triggering sexpbot today
17:00gfrlog&`(fn [~'x] (+ x 12))
17:00sexpbot⟹ (clojure.core/fn [x] (clojure.core/+ clojure.core/x 12))
17:01gfrlogignoring the body of the fn there, since that wouldn't be given explicitely in your macro
17:01gfrlogbut anyhow I was asking what you're trying to do with all this
17:04mattmitchellgfrlog: well, i have a hash-map, where each key is an output key for a new document. The value defines a list of db fields to use when performing a select. I then want to use the function (builder) to transform data from the row, for the field. Does that make sense?
17:04mattmitchellgfrlog: there are about 10-20 fields per table, and about 10 different tables. So my goal was to create a macro, that would eliminate a lot of (fn [x]) code
17:05gfrlogmattmitchell: is it all within one namespace? I think magic names like that is a lot more acceptable if you keep it all in one file
17:05mattmitchellgfrlog: it is yes, all in one file.
17:06gfrlogokay. you know about the #() syntax though right?
17:06mattmitchellThe the map without magic looks like: {:address [:line1 :line2 :city :state :country] (fn [row] )
17:06mattmitchellgfrlog: yes that's true, i could just use that
17:07gfrlogmattmitchell: and a lot of simpler functions can be built up compositionally without #() at all
17:07gfrloge.g., if you're just going to do (fn [row] (:country row)), that's just :country
17:07gfrlog(fn [row] [(:country row) (:state row)]) is (juxt :country :state)
17:08mattmitchelli see, so maybe are you suggesting stay away from macros for this?
17:08gfrlogthat's good default advice :)
17:09Chousukeheh, yeah
17:09Chousukefirst rule of macro writing: make sure you actually need a macro
17:09Chousukethen don't write it
17:10gfrlog:)
17:10Chousukethen if you get annoyed enough, start thinking about writing it :P
17:11mattmitchellok good, makes sense. But one of these days I need to come to grips with macros. I get so confused with all the quotes :(
17:12gfrlogmattmitchell: that's pretty normal. but I think you get a lot more mileage out of learning to use HOFs well than macros.
17:12mattmitchellgfrlog: and much more simpler to understand yes. OK, I'll back out a bit and try this again :)
17:13gfrloggood luck
17:13mattmitchellgfrlog: thanks! and thanks for your help.
17:13gfrlognp
17:35currentBWhat's the best way to test if a value is a clojure boolean
17:36gfrlog(map boolean? [true false nil 8 "wut"])
17:36currentB(isa? true java.lang.Boolean) doesn't work, for example
17:36currentBoh
17:36currentBdidn't see that in the docs
17:36gfrlogisa? is between two classes I think
17:36gfrlogso ##(instance? true java.lang.Boolean) should work
17:36sexpbotjava.lang.ClassCastException: java.lang.Boolean cannot be cast to java.lang.Class
17:36gfrlog&(instance? java.lang.Boolean true)
17:36sexpbot⟹ true
17:36gfrlogthere it is
17:36currentBawesome thanks
17:37gfrlogbut of course ##(boolean? false) is nicer and shorter
17:37sexpbotjava.lang.Exception: Unable to resolve symbol: boolean? in this context
17:37gfrlogbut it doesn't exist
17:37gfrlogso I'm dumb
17:37currentBhaha
17:37gfrlogbut the other way works :)
17:38gfrlog&(isa? java.lang.Boolean java.lang.Object)
17:38sexpbot⟹ true
17:38terom,(map boolean [true false nil 8 "wut"])
17:38clojurebot(true false false true true)
17:38gfrlogterom: thanks :)
17:38gfrlogI'm forgetting all of my bot-triggers today
17:39gfrlogoh that's different anyhow
17:39gfrlogdoubt it would have helped currentB
17:39teromTrue. (No pun intented...;)
17:40gfrlog(def boolean? (partial instance? java.lang.Boolean))
17:52hiredmangfrlog: not inlinable :/
17:52gfrloghiredman: isn't it strange that boolean? doesn't exist?
17:53hiredmanmeh, booleans are just kind of odd anyway
17:53gfrlogyeah who needs them
17:53hiredmanwhy not just call boolean on the value
17:53gfrlogcould just use :true and nil
17:53gfrlogit's a good point
17:57terom,(Boolean. "true") ; something to watch for...
17:57clojurebottrue
17:57terom,(true? (Boolean. "true"))
17:57clojurebotfalse
17:58gfrlogwut it does
17:59pdk,(identical? true (Boolean. true))
17:59clojurebotfalse
17:59pdk,(.class true)
17:59clojurebotjava.lang.IllegalArgumentException: No matching field found: class for class java.lang.Boolean
17:59pdk,(map type [true (Boolean. true)])
17:59clojurebot(java.lang.Boolean java.lang.Boolean)
17:59teromBoxed boolean, I guess, but not boolean primitive.
17:59pdkstay fresh clojure
18:00gfrlog,(map #(System/identityHashCode %) [true (Boolean. "true")])
18:00clojurebot(14929221 28937278)
18:00gfrlog,(map #(System/identityHashCode %) [true (Boolean. true) (Boolean. "true")])
18:00clojurebot(14929221 2760940 30908546)
18:01terom,(.booleanValue (Boolean. "true"))
18:01clojurebottrue
18:20hiredmanthe clojure mailing list should make everyone who sends an email over X characters provide a useful clojure library to the community before allowing the email through
18:23hiredman"oh, it looks like you want to send 500 words that boil down to 'I think clojure is awsome and aren't we all so cool for using it!' to the mailing list, please take over one of the new contrib libraries and I will be happy to send it for you"
19:24mjg123Hello guys - how can I turn (:a 1 :b 2) into a map {:a 1 :b 2} :)
19:26dnolen,(apply hash-map '(:a 1 :b 2))
19:26clojurebot{:a 1, :b 2}
19:26dnolenmjg123: ^
19:26mjg123oh that's cool
19:26mjg123thanks dnolen
20:12davekongIs there a function like print that also takes a stream to print to as an argument?
20:32amalloydavekong: java interop. just call .write on the stream
20:32davekongamalloy: k, thanks
20:32amalloy(or, really, on the reader)
20:34amalloy&(let [out-str (java.io.StringWriter.) out (java.io.PrintWriter. out-str)] (.print out "test") (str out-str))
20:34sexpbot⟹ "test"
20:34amalloydavekong: 6
20:34amalloyer, ^
20:34amalloystill getting used to having my numbers and symbols swapped :P
20:35davekongfor typing faster?
20:35amalloybut a lot of these cases can be solved with just ##(doc with-out-str)
20:35sexpbot⟹ "Macro ([& body]); Evaluates exprs in a context in which *out* is bound to a fresh StringWriter. Returns the string created by any nested printing calls."
20:35amalloydavekong: mostly just so i don't have to hold shift so often. i don't think it will improve speed that much, but it should help with comfort
20:36amalloy&(with-out-str (dotimes [n 10] (prn n)))
20:36sexpbot⟹ "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n"
22:28hugodswank-clj is now ritz, to try and avoid confusion with swank-clojure
22:38tmciverhugod: I spoke to you the other night about debugging clojure code and you informed me that you could open the .clj files from the jar in emacs, edit and then C-c C-k to compile. When I do this, I get a FileNotFoundException for the jar file. Any ideas?
22:45tmciverhugod: Even with this error it seemed to work just saving the file. But tonight I think I'm getting some strange behavior that may be classpath related. Do you know how the slime classpath is set up?
22:46hiredmantmciver: use C-c C-c
22:46hiredman(will re-evak the current top level form)
22:46hugodtmciver: not sure what the problem is compiling - works fine here - all the file's namespace dependencies have to be on the classpath
22:47tmciverhiredman: Ah yes, that seemed to work! Thanks.
22:47tmciverI'll have to add that one to my list of slime commands.
22:52tmciverhiredman: does 'top level form' mean that it compiles the whole file?
22:52tmciverhugod: how can I determine what my 'slime' classpath is?
22:53hugod(.getURLs (.getClassLoader clojure.lang.RT))
22:54hugodthe slime classpath is determined by the project you started the swank server in
22:55tmciverhugod: so it will be lib/*:lib/dev/* in that project?
23:02hiredmantmciver: the top level expression
23:07hugodtmciver: if you're using lein, then yes, plus source, classes and resource paths
23:07tmciverGreat. Thanks again!