#clojure logs

2011-08-28

00:19semperosstill trying to get my read function to work with clojure.main/repl; when I add a "\n\r" newline to the end of my LineNumberingPushbackReader, I only have to press enter once to get the results at the REPL, but I still don't understand why I have to press enter an additional time at all
00:20amalloysemperos: \n\r? nobody uses that. unless you mean \r\n, i suspect that \n<anything> would work as well as \n\r
00:26semperosyeah, I keep mixing the order up
00:27semperosit just feels like I'm so close, and based on a bit of informal debugging, the default read function gets called (the LispReader code), but then it just hangs before printing the value, as if it's waiting for more input
00:37klutometisdgreensp: That's a perfect example of something ungoogleable, I think.
00:37klutometisI take that back, actually: http://www.google.com/codesearch#search/&amp;q=defmacro-%5CW&amp;type=cs
00:37klutometisBut nothing is Clojure-specific.
00:38amalloyclojuredocs.org
00:38klutometisI take that back, too: http://www.google.com/codesearch#F-ttn8kjUJ4/modes/clojure/clojure-contrib/src/clojure/contrib/def.clj&amp;ct=rc&amp;cd=26&amp;q=defmacro-%5CW&amp;sq=
00:38klutometisamalloy: Thanks.
00:41amalloy&(doc get-method)
00:41lazybot⇒ "([multifn dispatch-val]); Given a multimethod and a dispatch value, returns the dispatch fn that would apply to that value, or nil if none apply and no default"
00:42amalloyneat. thanks, clojuredocs
01:27tufflaxare there any macro problems on 4clojure?
01:27tufflaxguess it wouldnt work that well now that i think about it
01:28tufflaxthe way most problems work
01:41amalloytufflax: no, there aren't. we spent some time trying to imagine how we could write one
01:44amalloymight be interesting to use macrolet
01:45tufflaxcouldnt you just use defmacro? "write a macro m that does this" and then u show like "(= (m bla bla) (something))"
01:45amalloywe don't allow any defs
01:45tufflaxhm
01:46amalloyand i like it that way; even if we could allow defs just for macros, i like reminding people that you can do everything with closures, without the need for any defs
01:47tufflaxbut that is not common for macros, is it?
01:47amalloyno
02:27klangCan clj-http.client (one of the 9 masters there are) do the same as clojure.contrib.http.agent? .. or what is the prefered method for making http requests from clojure?
03:50BBHossHello all, what's the best place for an existing developer to try out Clojure? I have clj/contrib installed, I just need something to do with it now, something to show me the power.
03:52khaliGwhat kind of power do you have in mind?
03:53BBHosskhaliG: dunno, I guess I'm looking for the killer application of Clojure
03:54scottj"if william wallace were here..."
03:54BBHossor even just a good tutorial that does a good job of introducing the language
03:54scottjBBHoss: what kind of apps are you into?
03:55khaliGBBHoss, personally I was drawn to being able to write swing apps in a lisp language coming from a java/lisp background
03:55BBHossscottj: I do rails apps right now, but I don't want to limit myself to that necessarily
03:55thorwilBBHoss: have a look at http://java.ociweb.com/mark/clojure/article.html
03:55khaliGBBHoss, so a one liner putting a swing gui on the screen impresses me - but you may have different ideas of what's cool
03:56scottjBBHoss: so for web stuff noir has a nice page http://webnoir.org/ clojurescript is very cool, pacman is cool http://mjg123.github.com/pacman/pacman.html
03:57BBHosskhaliG: JRuby can do that too :), I just see Clojure blowing up in the Ruby community, and I want to understand why
03:57BBHossJust got back from a Ruby conference where I saw a TON of people with Clojure t-shirts on, so something is up :)
03:58BBHossthorwil: that looks quite in depth, I will be sure to read through that tomorrow
04:02BBHossnight/morning all
04:07khaliGscode, damn that pacman is addictive
04:07khaliGscottj, rather
04:08scottjkhaliG: it was actually the first time I've ever actually played pacman :) after I eat all the things how do I finish the level?
04:09khaliGscottj, same! ive eaten them all - i guess it has somethign to do with that bright line in the middle? dunno
04:10khaliGoh cool you can zoom in
04:11amalloyhaha in real pacman, once you eat them all you go on to the next level
04:11khaliGoh its a tarp! :P
04:12scottjso maybe this only has a single level
04:13scottjsource has data for 21 levels
04:13amalloydunno, then
04:15amalloyman, i thought i was young. haven't played pacman? suddenly i'm telling kids to get off my lawn
04:19scottjoh I just leveled up when I won without dying at all
04:21amalloybug report, then? "can't go to next level after dying"?
04:24scottjyeah
04:25khaliGhmm. one thing i dont like about using proxy is that a change to any of the methods requires recreating a new instance of the object :/
04:26khaliGis there a workaround?
04:28amalloy&(doc update-proxy)
04:28lazybot⇒ "([proxy mappings]); Takes a proxy instance and a map of strings (which must correspond to methods of the proxy superclass/superinterfaces) to fns (which must take arguments matching the corresponding method, plus an additional (explicit) first arg corresponding to ... http://gist.github.com/1176420
04:29amalloythere are lots of reasons to not like using proxy, but that is not one of them
04:33khaliGamalloy, update-proxy is interesting but I don't think it helps in the use case i had in mind - modifying a running app while developing it
04:34amalloyi don't understand. you want to change a proxy, so you call update-proxy
04:34amalloyhow does that not help?
04:35khaliGamalloy, say i don't have easy access to the proxy at the repl
04:35amalloythen there's nothing proxy-related you could do to change it
04:35khaliGright
04:35amalloyinstead, have your proxy call a var
04:36amalloythen when you redef the var, the new value will be seen
04:36khaliGits tricky because my methods close over some objects
04:38amalloy(defn f [] 1) ... (let [p (proxy [java.util.ArrayList] [] (size [] (#'f)))] (.size p))
04:38amalloyor do whatever you want. whatever functionality you want to be able to modify, put somewhere mutable
04:39amalloyif you don't know what you'll want to change, *and* won't have a handle to the proxy instance, you are pretty much SOL as far as i know
04:42amalloy(and IMO would deserve any pain you get)
04:43khaliGfor example, i use (proxy [javax.swing.table.AbstractTableModel TableDataModel] ..) which implements some of my own methods from TableDataModel, and each time i make a change to those, i have to compile the function and restart the app to see the changes. I would like to make changes to a method while the app is running
04:44khaliGif that's possible, perhaps with something other than proxy
04:44hiredmankhaliG: or have you proxy methods call a fn and just update the fn
04:45hiredmanproxy does actually let you update the fns, but yetch
04:47khaliGhiredman, yeah that might be a bit obscuring though :/ i'd have to add new parameters to those fns
04:48hiredmankhaliG: huh?
04:49khaliGfor example (getValueAt [row column] (my-get-value-at closed-over-foo row column))
04:49hiredmanwhat is obscuring about it?
04:50amalloyless obscuring than mutating a dang object's behavior
04:50hiredman(value-at thing row column)
05:01fliebelamalloy: Ah, finally a Geni employee around :) Fuck timezones...
05:02amalloyfliebel: yeah, i keep a pretty late cycle, though not as much as lancepantz does
05:02amalloyor Raynes :P
05:03amalloyanyway, what's up? i see you were looking for us earlier
05:03fliebelYou remember I was trying to run Jiraph? Protobuf still refuses to work.
05:04amalloyi don't think anyone but ninjudd really knows how that stuff happens. Raynes might, i suppose
05:04fliebelI talked to Raynes, and he was going to talk to ninjudd, but I havn;t heard anything from them. I wrote down my problem here: https://github.com/flatland/clojure-protobuf/issues/8
05:04fliebelYea, Raynes said ninjudd is the only one who dares to touch Protobuf.
05:05amalloyfliebel: have you considered using lazybot's $mail to at least get asynchronous messages instead of waiting to run into someone?
05:07fliebelamalloy: I've considered it... If you restart Lazybot, does it persist?
05:07amalloyit's supposed to. i haven't tested it recently
05:07fliebelOk, I'll try.
05:08amalloyor you could email him, or github message, or...
05:08fliebeltelepathy...
05:09amalloyyeah. ninjudd's pretty busy, and doesn't spend a lot of time in irc. i imagine he'd appreciate a medium where he could respond whenever it's convenient
05:11amalloyfwiw, he and lancepantz both use macos, so it's not like it doesn't work on macs
05:12fliebelamalloy: But you only install protoc once, so if it started to break, they would not notice, I guess.
05:12amalloysure, that's possible. it worked as recently as a couple months ago
05:13fliebelI'll send hi a github message, as I trust it more than $mail, and I don't have his email.
05:13fliebelHm, weird.
05:14fliebelMy Mac is prey much a "clean" environment, as I just installed Lion, which might as well be the problem itself.
05:15amalloyi wouldn't be astonished, because i'm a mac cynic
05:17fliebelamalloy: What do you use?
05:17amalloyubuntu
05:18amalloyi guess my self-contradictory attitude could be summed up as: macos is nice, but that doens't mean i have to like it
05:27fliebelamalloy: That thing of you, it was called cognitive dissonance, right? ;)
05:27amalloyhah
05:28amalloyyes, i suppose so
05:31MasseRWhat does invalid token exception mean?
05:33amalloy&foo:
05:33lazybotjava.lang.Exception: Invalid token: foo:
05:35ChousukeMasseR: you're trying to use an illegal identifier somewhere
05:36MasseRThanks. That's it
05:36MasseRI tried to create a map with a colon as a separator
05:38MasseRUhm. (use 'clojure.contrib.pprint) should work, right?
05:39MasseRAh it's moved to clojure.pprint
05:47amalloyhmmmmm. usually i hate depending on maps to be ordered, but does anyone know if literal maps supplied in source code retain their order regardless of size? like {:a 1 :b 2}, does that always seq as a before b?
05:48fliebelamalloy: Only if it's an array-map
05:48fliebelSo, not regardless of size
05:49fliebelBut I think if you make an (array-map k v k v) direclty, it should work.
05:52amalloysure. i was just fiddling around with a map-based DSL when i realized i care about order
06:30NorritHello, where can I find the old contrib.io in the new contrib layout?
06:31hiredmanclojure.java.io
06:32Norritah, thx
06:39Clintegerthey weren't kidding about this being messy..
06:47scodeHow do I idiomatically test whethr an object is a byte array?
06:47scode(I.e., equivalent of string? for example.)
07:03fliebelscode: Uhm, I don't think arrays are real objects in java, but I guess instance? works.
07:03fliebelOr you can compare the-array/TYPE with the TYPE of a bute array.
07:10fliebel&(class (byte-array 0))
07:10lazybot⇒ [B
07:16scodeThe thing is that [B is not a suitable literable in source code :)
07:16scodeI.e., (instance? [B) obviously doens't work.
07:16scodeAnd I don't want to do (Class/forName "[B").
07:29fliebelscode: Why not? Well, of you want, you can define a convenient symbol to it, and use that.
07:30fliebel(def ba (Class/forName "[B"))
07:53fliebelIs there still any movement in async in Clojure? http://dev.clojure.org/display/design/Asynchronous+Events http://groups.google.com/group/ring-clojure/browse_thread/thread/243f452c915356c8/
08:12scodefliebel: Mostly just because it feels verbose :)
08:37NorritHi, can someone spot the error? (.start (Thread. (fn [] (println "Test")))) ==> nil
08:38NorritShouldn't it print "Testnil"?
08:39tomojyou in some kind of fancy repl?
08:40Norritemacs + swank
08:40tomoje.g. `lein swank`
08:40tomojyeah, check the terminal you started swank in
08:40tomojproblem is just that the bindings to print to the repl aren't set up outside the repl thread
08:41Norritok, I expected something like that .. thx
08:41tomojI remember you can hack around that, dunno if there is a proper way
08:44NorritI found the stackoverflow question: http://stackoverflow.com/questions/4532862/understanding-output-in-clojure-using-swank-slime
08:58bsteubertomoj, Norrit: another way is (alter-var-root #'*out* (constantly *out*))
08:59bsteuberafter that all threads' *out* is like in the one executing the line
08:59bsteuberso all threads will print to the swank buffer
09:00Norritbsteuber: thx I will try that out, too
09:01bsteuberNorrit: the backside is that if you do a lot of debug prints, the repls becomes quite full and it might even become hard to enter new commands
09:32ambrosebshow can I get marginalia to recognize a comment nested in a form?
09:33ambrosebsseems to only render comments on the top level
10:22SomelauwHi, I am trying to write a local recursive list in clojure. In scheme I would have used let-rec, but clojure doesn't seem to have it, so I am wondering what the best alternative would be.
10:23NetpilgrimI’ve written a DFS searching for a path from one vertex to another. (https://gist.github.com/1176716) It kind of works but I can’t figure out how to stop the search once the (first) path is found. I’m probably still thinking too much in imperative terms where I would just call return. Any pointers?
10:26SomelauwFor example (letrec [exponential2 (lazy-cons 1 (map #(* 2 %) exponential2)] (nth exponential2 5))))
10:26SomelauwI want a local recursive list.
10:26tomojNetpilgrim: how does that deal with cycles?
10:27Netpilgrimtomoj: Cycles are avoided by the definition of children, which excludes vertices already on the current path.
10:28NetpilgrimSomelauw: I'll have to take time to understand this. Where does letrec come from? It's not in clojure.lang.
10:28tomojSomelauw: ##(take 10 (iterate (partial * 2) 1)) ?
10:28lazybot⇒ (1 2 4 8 16 32 64 128 256 512)
10:28tomojor do I misunderstand?
10:28SomelauwOr even (letrec [ones (lay-cons 1 ones)] ones)
10:29NetpilgrimSomelauw: Or clojure.core or where the usual stuff comes from.
10:29tomojoh, that was just a silly example?
10:29SomelauwNetpilgrim: It works with def.
10:29SomelauwNetpilgrim: But I don't want to spoil the global scope.
10:30Somelauwtomoj: That works, but I am looking for a more generic approach.
10:31tomoj&(nth ((fn ones [] (lazy-seq (cons 1 (ones))))) 10000)
10:31lazybot⇒ 1
10:31tomoj:/
10:31SomelauwIn sicp there is a whole chapter about streams. That is the kind of thing I am looking for.
10:32NetpilgrimSomelauw: I hadn't thought about making anything lazy in my search. But I guess if I'm really only interested in the first path found, there should be an easier solution?
10:33SomelauwNetpilgrim: That seems like the right approach. Return a lazy list and only ask for the first element.
10:34NetpilgrimSomelauw: Thats looks like a clean, general solution in any case. I’ll try to implement it. Lazy sequences are still new to me.
10:35Somelauwtomoj: I think that would be the best alternative so far.
10:37tomojNetpilgrim: stick around a bit longer
10:39NetpilgrimMy first experiment with lazy seqs was to get one of primes. Could someone take a look and see if I'm doing it right? (https://gist.github.com/1176126) There is probably a better way to calculate primes but I'm just asking about the code structure.
10:41tomojone problem is that you probably don't want to def primes to the seq itself
10:41tomojwell, I guess it doesn't really matter in this case
10:42Netpilgrimtomoj: Why not?
10:42Netpilgrimtomoj: Or in what cases not?
10:42tomojif you def primes to the seq, you will hold the head
10:42tomojwhich means none of the seq can ever be garbage collected
10:42tomojbut you carry the whole seq around anyway to generate it, so..
10:43Netpilgrimtomoj: Yeah, I thought about that and came to the same conclusion.
10:43Netpilgrimtomoj: BTW: Is there a way to reference all the elements in a seq before the one being constructed?
10:44Netpilgrimtomoj: Basically what I hold in known-primes?
10:44tomojI think you did that the most elegant way I can think of right now
10:45tomojwait
10:46tomojwhat if you instead wrote a function that takes the seq of known primes and returns the next prime, and combined that with iterate?
10:46SomelauwI think I don't really like wrapping a lazy list in a function. It doesn't feel right.
10:46tomojor the function conses the next prime
10:46tomojSomelauw: lazy-seqs are just functions inside seqs, seems appropriate to me
10:47tomojbut I don't have scheme brainwashing :)
10:47NetpilgrimSomelauw: What do you mean? Isn't there always a function to generate the seq?
10:48SomelauwAlso, I am not sure if the list gets properly memoized in your approach.
10:48tomojthe letrec version would notice that you only need one seq, and have that seq's more() return itself?
10:49SomelauwI am testing it right now on a lazy fibonacci sequence.
10:49Bronsahow can i share a Var between two namespaces?
10:49SomelauwAnd it doesn't seem to memoize properly.
10:50tomojI think if you want it 'properly memoized' you will have to do it yourself
10:51Somelauwtomoj: I am going to read a chapter about clojure macros in a minute.
10:52NetpilgrimI'm still very fuzzy on the whole subject of lazy seqs. I’ll still have to read that chapter in The Joy of Clojure. Hopefully that will make things clearer.
10:53SomelauwAlthough I am first going to google a bit more, because I can't believe there is no alternative.
10:55tomojNetpilgrim: I think I solved your problem
10:55tomojcheck out tree-seq
10:56tomojcan gist you my code if you want
10:56Netpilgrimtomoj: I would appreciate it.
10:56tomojlet me make sure it works first :)
10:58tomojhttps://gist.github.com/b6baf208f18d21c2d88e
10:58Netpilgrimtomoj: Looking at the documentation of tree-seq, I don't think it can deal with cycles. But it will be interesting to look at the code.
10:59tomojthat's why it took me so long :)
10:59tomojbut I already had an attempt written when I realized the cycle problem, so just kept going
11:02tomojhttps://gist.github.com/1d43fb74aaf2d16b0ecf might be less confusing
11:02tomojdunno if you're used to ->> :)
11:02tomojoh, except that doesn't work
11:03Netpilgrimtomoj: I haven't used --> yet but I know how it works (I think).
11:03tomojfixed
11:05Netpilgrimtomoj: Than you very much for the effort. I'll have to leave soon for a few hours but I will go over the code and probably learn a lot.
11:06tomojNetpilgrim: I suppose the first arg to tree-seq should really be (constantly true)
11:06tomojI think passing my children function there may actually do weird things.. not sure
11:07tomojor at least (comp seq children)
11:14Netpilgrimtomoj: Wow, I really need more time to understand what's going on there. Clojure syntax and functional thinking is both new to me. It's a bit frustrating but also really cool, like the first time I learned how to code, which was awesome. :)
11:15Netpilgrimtomoj: I've got to go now. See you later, and thanks again.
11:55mudgei can start a clojure web application with lein run
11:55mudgeand my project says which namespace my -main is in
11:55mudgebut how do i stop or restart my web application?
11:56justicefrieswhat are people using as far as web frameworks go
11:57mudgecompojure
11:57mudgeand some use noir which is build on top of compojure
11:57justicefriesnice okay
11:57mudge*built
11:57justicefriesi'm making the leap from ruby/rails. :D
11:58coopernursejusticefries: yes, noir is good. I put a site up on github if you want to look at an example
11:58mudgenice job
11:58mudgei want to look at an example too
11:58justicefriesyeah!
11:58coopernursehttps://github.com/coopernurse/votenoir
11:58coopernursedeployed to appengine at: http://votenoir.appspot.com/
11:59coopernursenot claiming it's amazing code, but it may give you some ideas
11:59justicefrieswhoa defpartial
11:59coopernurseyeah, that's a macro noir provides
11:59justicefriesnice.
11:59coopernursenoir docs here: http://webnoir.org/
12:00justicefriesthe biggest thing I'm trying to wrap my head around is code organization with larger projects. reason I say that with any importance is with an OO language, separation of things out into classes is...just what you do.
12:00justicefriesso now I have to consider it differently. ;)
12:01justicefriesso with noir I don't actually write any html.
12:01justicefriesaccurate?
12:03coopernurseyep, by default noir encourages you to use hiccup - which is like haml in ruby
12:03justicefriesah ha.
12:03justicefriesvery cool.
12:03coopernursewhich I personally like - I like having everything in one place
12:03st3fancoopernurse: happy with GAE?
12:03justicefriesyeah
12:03coopernursest3fan: the price is right :-)
12:03st3fanyou mean free?
12:03st3fanwell, for small sites
12:03coopernursest3fan: but it's flaky.. stuff randomly fails
12:04coopernursest3fan: yes, free quota is very generous
12:04st3fanwell that is the google way .. distribute app over many servers so that it does not matter when things fai
12:04coopernursest3fan: so I like to use it for toy apps.. and most of what you write is portable. the datastore is the most unique layer
12:04st3fanl
12:05st3fanyeah very cool
12:05coopernursest3fan: yes, but I'm talking about some of their tools breaking.. for example, on friday you couldn't deploy any index changes. 500 error from their servers using their scripts
12:05st3fanaha
12:05mudgewhat advantage does defpartial give over just defining your hiccup code with defn?
12:05coopernurseI posted to their google group. no answer from google. but one other person on the group said "yeah, I'm getting those errors too"
12:05coopernursemudge: judging from the source, it just prevents you from having to wrap it in (html ..)
12:06coopernurselooks like a pretty thin macro
12:06mudgecoopernurse: how fun, yay
12:07mudgeand defpage replaces using the compojure GET macro?
12:07coopernursejusticefries: regarding code organization, it is different than rails, but it's similar to other microframeworks like express in node.js or flask for python (and probably sinatra)
12:07coopernursemudge: yes, exactly
12:07jnb16Quick ClojureScript question is someone wouldn't mind helping. Trying to get a clojure macro to run. I have a src folder with a clj and a cljs dir. Inside each of those dirs is a toplevel dir with the same name and then my code. I am getting java.io.FileNotFoundException: Could not locate recipeapp/rmacros__init.class or recipeapp/rmacros.clj. Do I need to pass something special to cljsc? sorry for the wall of text
12:08justicefriesah ha.
12:08mudgecoopernurse: i see, anything else that noir gives that might be good that you know of?
12:09jnb16oh, also..I am using :require-macros in my cljs namespace (I think that is right) for requiring the macro
12:09coopernursemudge: the "flash" message feature seems useful. wrapper functions for cookies. simplified middleware bindings. pre/post request filters (good for auth)
12:10coopernursemudge: compojure is good, but very low level. noir provides many of the things you sort of expect to find in a web framework.
12:10mudgecoopernurse: i see
12:17thorwilcoopernurse. mudge: afaics defpartial duplicates hiccup's defhtml. though defpartial might well predate the hiccup solution
12:18mudgethorwil: thanks, i didn't realize hiccup had defhtml
12:18thorwiljust saying, as using defhtml makes more sense regarding code organization
12:19coopernursethorwil: as opposed to defpartial? how so?
12:19thorwilcoopernurse: because it wraps hiccup's html
12:20mudgethorwil: where is defhtml? in hiccup? i can't find it
12:20mudgethorwil: nevermind, i found it
12:21coopernursethorwil: oh, defhtml makes more sense than using (html ) directly? or makes more sense than using defpartial?
12:22thorwilcoopernurse: second
12:22mudgewhat's the difference between defhtml and defpartial?
12:22jnb16no clojurescript gurus I guess..I'll try again later, but if anyone has an idea, feel free to PM me...thanks!
12:22coopernursejnb16: yeah, sorry, haven't tried clojurescript yet
12:23coopernursethorwil: I'd like to hear more. seems they are equivalent
12:23jnb16no worries :D
12:23thorwilcoopernurse: there is not more to it :)
12:23coopernurseheh, ok
12:23mudgethorwil: why is defhtml better than defpartial?
12:24mudgethorwil: because the name defhtml is better?
12:24thorwilmudge: code organization. having all the html business in/from hiccup
12:25mudgebut defpartial is also uses hiccup, how is it better organization?
12:25coopernursemudge: right, that was what I was wondering
12:26mudgethorwil: is it just nicer to use all hiccup rather than use somethinge else too?
12:26upwardindexwell since hiccup is coupled to html generation, it makes more sense to use html generations facilities of hiccup
12:26mudgeI might use defhtml because I like the name better than defpartial
12:27upwardindexnoir is decoupled from html generation as you can use enliven with it for example
12:27mudgeupwardindex: yes
12:27coopernursewell, if you include noir as your project dependency, hiccup is included transitively, and you can use hiccup directly if you like
12:27thorwilthis is such a minor detail, not worth this many words. its just a need that follows from hiccup, where hiccup has a solution, so having it all in one place makes sense
12:27mudgethorwil: yea, makes sense
12:28coopernursethorwil: agreed, seems more like a matter of aesthetics than anything else
12:28mudgeor code organization
12:29mudgein a way
12:30coopernurseit seems lots of ruby folks are finding their way to clojure
12:30thorwilseeing how i want to update parts of a page asynchronously, i wonder what it would take to write a function that takes a defhtml and returns a javascript function that acts like a template
12:31coopernursethorwil: when you say "acts like a template" - you want to take the server generated html and do further transformation on the client? like token substitution
12:32coopernurseor do you want to just use that html fragment to replace innerHTML of a containing element?
12:32thorwili guess as long as all args are strings and there are no conditionals or loops, all needed is some escaping on what hiccup generates
12:32thorwilcoopernurse: the js function would take the same args as the defhtml
12:34coopernursethorwil: I suppose an example use case would help - I'm not sure I get it
12:34thorwilexample: a comments section. i have a defhtml for a single comment
12:35thorwilthe js/client side should be able to add a comment locally, with the same html structure
12:36thorwilso i figure a defhtml->js-template-function would be pretty neat
12:36coopernurseI see
12:39coopernurseseems like that's what clojuresript would be useful for
12:40coopernurseobviously that's a bigger undertaking.. regarding tooling
12:47scottjyou guys have seen pinot right? it has defpartial
12:48mudgescottj: bite me a donut, I hadn't seen it before
12:48mudgescottj: looking at it now, looks good
12:56coopernursescottj: wow, yeah that looks pretty sweet. chris granger is writing some good stuff
12:59thorwillooking forward to the day there is a 1.3 release and an updated appengine-magic, so i might take advantage of clojurescript and things like that :)
12:59sridapparently some host tutorials on github, https://github.com/swannodette/enlive-tutorial#readme -- IMO, this is better than blogging them, as readers can 'fork and edit' the content.
12:59coopernurseah, does clojurescript require clojure 1.3?
13:01jblomocoopernurse: yes
13:05coopernursejblomo: ah, interesting..
13:06scottjI think you can have clojurescript in a 1.2 project fine since the cljs compiler and it's 1.3 is separate
13:13griosHello. Why: (class (def m-symb 'a)) => clojure.lang.Var but (def m-symb 'a) (class m-symb) => clojure.lang.Symbol ?
13:13jblomodef returns Vars
13:13jblomotypically you don't notice because you're not using the return value of def
13:16griosjblomo: okay thanks
13:18mudgeis there a defonce for functions?
13:18griosI'm having some headache trying to disjoin Java-like's "identifiers" concept from Clojure's "symbols
13:21griosbecause I was reading The Joy of Clojure: << symbol’s qualification is a characteristic of evaluation and not inherent in the symbol at all >>. So Vars live in a namespace, but symbols itself do not?
13:24mudgehow do i check if a var exists?
13:24mudgelike i want to check if the var 'server' exists or not
13:24dnolen,(doc resolve)
13:24clojurebot"([sym] [env sym]); same as (ns-resolve *ns* symbol) or (ns-resolve *ns* &env symbol)"
13:24dnolen,(doc ns-resolve)
13:24clojurebot"([ns sym] [ns env sym]); Returns the var or Class to which a symbol will be resolved in the namespace (unless found in the environement), else nil. Note that if the symbol is fully qualified, the var/Class to which it resolves need not be present in the namespace."
13:26mudgednolen, cool, thanks
13:42cemericksrid: My favorite one, actually :-)
13:49manutter,(doc pmap)
13:49clojurebot"([f coll] [f coll & colls]); Like map, except f is applied in parallel. Semi-lazy in that the parallel computation stays ahead of the consumption, but doesn't realize the entire result unless required. Only useful for computationally intensive functions where the time of f dominates the coordination overhead."
13:49manutter##(doc pmap)
13:49lazybot⇒ "([f coll] [f coll & colls]); Like map, except f is applied in parallel. Semi-lazy in that the parallel computation stays ahead of the consumption, but doesn't realize the entire result unless required. Only useful for computationally intensive functions where the t... http://gist.github.com/1176980
13:51manutter##(doc ->)
13:51lazybot⇒ "Macro ([x] [x form] [x form & more]); Threads the expr through the forms. Inserts x as the second item in the first form, making a list of it if it is not a list already. If there are more forms, inserts the first form as the second item in second form, etc."
13:53manutter##(doc read)
13:53lazybot⇒ "([] [stream] [stream eof-error? eof-value] [stream eof-error? eof-value recursive?]); Reads the next object from stream, which must be an instance of java.io.PushbackReader or some derivee. stream defaults to the current value of *in* ."
13:54manutter##*ns*
13:55manutter##(pr-str *ns*)
13:55lazybot⇒ "#<Namespace sandbox16249>"
14:06mudgein my compojure app i have: (route/resources "/") but it is not finding my stuff in resources/public
14:08mudgewhere should my resources directory be located in my compojure application?
14:11semperosfairly sure that, by default, resources should be in the root of your project
14:11semperosthe "resources" folder, that is
14:11mudgesemperos: yes, i think so too, buy my clojure app isn't finding my stuff in project root/resources/public/
14:12mudgei have this in my routes: (route/resources "/")
14:12mudgebut things are not found in resources/public/
14:13semperosthe URL is formatted "/public/foo.css" for example?
14:13mudgesemperos: yes, ahhh, i think figured it out!
14:14jblomoyea, you don't need the /public in the URL
14:14mudgesemperos: i had my urls like that, public/foo.css, my urls actually need to be just: foo.css and it looks in the public directory for it
14:14mudgeyea
14:14mudgeworking now
14:14semperos:)
14:14semperosglad to hear it
14:23jnb16any clojure*script* gurus around?
14:25jblomoi've used it before, not a guru, though
14:25jnb16Any experience with getting clojure macros to work?
14:26jblomowell, like 'doto'?
14:26jnb16Sorry, I meant like writing clojure macros that then work on cljs files during the compilation step
14:27jnb16writing your own defmacro's
14:28dnolenholy moly, red-black tree balance checking with object arrays fast - https://gist.github.com/1177009
14:28jblomosorry, no. i thought they worked just like clojure macros?
14:29jblomodnolen: nice :) I enjoyed your talk on match
14:29jnb16ah, yeah. It seems like you need to put the macros in a separate normal clojure file (.clj)...but now cljsc seems unable to find it boo...Thanks tho!
14:29dnolenjblomo: thanks!
14:47hanDerPederwhy do I get nil here? https://gist.github.com/1177035
14:55thorwilhanDerPeder: because (str a) can't result in an Integer or Double
14:55hanDerPederthorwil: I dont understand what you mean
14:55hanDerPederthis works though: https://gist.github.com/1177048
14:56thorwilhanDerPeder: java.lang.Integer (str a)
14:56thorwilhanDerPeder: you surely meant "java.lang.Integer a"?
14:57hanDerPederI meant, if 'a' is of class integer then return 'a' as a string
14:58thorwilright, i was confused
14:59Somelauwtomoj: I think I found what I was looking for.
15:00SomelauwClojure has rec-cons and rec-cat.
15:13thorwilhanDerPeder: with cond it seems to work: (defn emit-bash-form [a] (let [c (class a)] (cond (= c java.lang.Integer) "int" :else nil)))
15:13thorwilstrange
15:17Somelauwalthough it doesn't seem to work in my ancient version of clojure
15:19hanDerPederyea, especially since it works fine when using multimethods
15:35raekhanDerPeder: the java.lang.String form is unevaluated, so you actually check for a symbol
15:35raekeven though a class and a symbol prints the same, they are not the same
15:36raekyou need to work around this by having class objects instead of symbol objects in the code. this is possible with a macro: https://gist.github.com/997652
15:38theignoratihow do I properly deploy a compojure app? there's 9000 blogs and they all do it in a different way
15:41jblomotheignorati: i think it depends on your infrastructure.
15:41theignorati1 dedi
15:46floatbothhi
15:50chouserfloatboth: hello.
15:50semperoshowdy
15:50floatbothanyone knows why a macro like (defmacro test [& a] `(fn [d#] (-> d# ~@(map eval a)))) results in a java.lang.ExceptionInInitializerError?
15:51chouserfloatboth: did you try (pst) ?
15:52floatbothchouser: what's this?
15:52chouserprints the stack trace
15:52chouserperhaps I should first ask which version of Clojure you're using.
15:53floatboth1.2.1
15:56floatbothwhen I make it a function and try, the output seems fine: (clojure.core/fn [d__9393__auto__] (clojure.core/-> d__9393__auto__ #<my fn> #<another fn>)) but I can't eval that
15:57amalloy$javadoc java.util.Map
15:57lazybothttp://download.oracle.com/javase/6/docs/api/java/util/Map.html
15:58amalloyfloatboth: you're probably trying to embed objects into the code that aren't code objects. in any case using eval in a macro is wrong basically 100% of the time
15:58bumber,(var (def a 'a))
15:59clojurebot#<Exception java.lang.Exception: SANBOX DENIED>
16:00amalloybumber: def already returns the var. (var (anything)) is always invalid code
16:01floatbothsame w/o eval
16:02raekfloatboth: you probably want (-> d name-of-my-fn name-of-another-fn), i.e. symbols instead of function objects
16:03raekfloatboth: also, can you describe what 'test' is supposed to do?
16:04floatbothraek: I don't have symbols… I want something like apply-macro from contrib to work, impossible?
16:04raekhow would you use apply-macro?
16:04raekthe idea of applying a macro doesn't make sense to me
16:05floatbothI just want my macro to make a function which will receive an arg and -> it through functions given to the macro
16:06raekyou don't need a macro for that
16:06amalloyfloatboth: this is really hard for you because you should just be using ##(doc comp)
16:06lazybot⇒ "([f] [f g] [f g h] [f1 f2 f3 & fs]); Takes a set of functions and returns a fn that is the composition of those fns. The returned fn takes a variable number of args, applies the rightmost of fns to the args, the next fn (right-to-left) to the result, etc."
16:07floatbothhmm, nice
16:07floatboththanks, I'll try it
16:07amalloyand no matter how hard you try with a macro, it can *never* work, not even with something like apply-macro
16:08amalloyi mean, you can make a macro expand to a use of comp, or splice in the symbols. but you can't do it with eval, because eval doesn't have access to lexical bindings
16:08bumberamalloy: thanks for the clarification :)
16:08floatbothyeah, got it. thanks everyone!
16:08amalloy(let [the-function (if some-test inc dec)] ((test the-function) 1))
16:09amalloywill fail because the macro can't know what the-function's value is
16:11floatbothmy brain will fail, no, already failed. I wanted something to compose functions and forgot to find-doc this :D
16:13hanDerPederraek: thank you very much for the clarification
16:15mudgedoes it make sense to deploy clojure apps using git?
16:15hanDerPederraek: can you tell me why it works when using multimethods?
16:15floatbothmudge: sometimes it's even the only option (heroku)
16:17mudgefloatboth: i am trying to use git to deploy my clojure web app, but when I push to the repository on my server I am getting an error because I think pushing to the repository doesn't
16:17mudgeupdate the working directory of the repository
16:18raekhanDerPeder: it is because case is a special form that does not evaluate some of the arguments. cond and multimethods always evaluate their corresponding thing
16:19hanDerPederi see, thanks
16:19raekhere, case is the odd one
16:19floatbothmudge: it makes sense to deploy apps in any language using git, actually. for web, try this workflow: http://joemaller.com/990/a-web-focused-git-workflow/ btw you better ask on #git I guess
16:20mudgethanks floatboth
16:21MasseRHow come "(reduce (fn [acc x] (merge-with + {x 1} acc)) {} (lower-case (slurp "/usr/share/dict/words")))" takes 22 seconds? In haskell a similar function returns a lot faster (IIRC)
16:22coopernurseanyone successfully written an oauth client with clojure?
16:22amalloy~source frequencies
16:22amalloy$google clj-oauth
16:22lazybot[mattrepl/clj-oauth - GitHub] https://github.com/mattrepl/clj-oauth
16:22coopernurseamalloy: sorry, I should have added "with app engine"
16:23coopernurselooks like clj-oauth uses HTTPClient, which won't fly
16:23amalloyMasseR: frequencies will be a lot faster than your by-hand reduce
16:23coopernurselooks like a fork of signpost (java) supports appengine..
16:23coopernursebut I don't see any clj wrappers
16:23MasseRamalloy: :D of course there's already a function
16:24amalloybut just slurping the whole thing into memory into a single string will be a bit slow already, i suspect
16:24MasseRSo slurp reads to memory?
16:24amalloyit returns a string. how could it not?
16:25MasseRamalloy: I was going to say lazy seq, but .. string, of course
16:28upwardindexIs try-clojure.org 502 for anybody else?
16:29Netpilgrimupwardindex: Yepp.
16:29amalloy$google downforeveryoneorjustme
16:29lazybot[Down For Everyone Or Just Me -> Check if your website is down or ...] http://downforeveryoneorjustme.com/
16:29coopernurseupwardindex: yeah, it seems busted
16:30upwardindexNetpilgrim, coopernurse: thanks I was thinking I might have caught a virus or something
16:30amalloyi'll see what i can do
16:31amalloyi'm not sure how Raynes generally launches the thing
16:35amalloyupwardindex: back up for now
16:36amalloy$mail Raynes i restarted try-clojure, but it's running in a cake repl right now so you'll probably want to fix it to whatever clever way you usually run it
16:36lazybotMessage saved.
16:36upwardindexamalloy: yay!
16:38rata_hi
16:38upwardindexrata_: hello
16:42rata_how can I specify the file encoding when I open a URL with (java.net.URL. url)?
16:49dnolenvector patterns have landed, pretty syntax for matching primitive arrays are in, https://gist.github.com/1177009
16:51drewryour tweet mentioned bits too
16:52drewrpretty sweet
16:53dnolendrewr: yeah the bit stuff needs more work. Need to look deeper into the feature set that Erlang supports and replicate that.
16:55coopernurseis there a #clojure meetup planned for strange loop?
16:57drewrdnolen: that's exactly why I'm interested.. I'm always jealous of erlang there
17:08dnolendrewr: I don't think it'll be very hard. thinking about the syntax: https://github.com/swannodette/match/blob/master/src/match/bits.clj#L34
17:12drewrdnolen: quite nice actually
17:13Somelauwstrange loop
17:16coopernursehttps://thestrangeloop.com/
17:18michaelr525heya!
17:20michaelr525Suppose that you were asked to design a scalable architecture that will start very small and later will grow to the size of facebook or amazon store or whatever huge site, where would you start?
17:20michaelr525Would you try to sell Clojure as the main platforms for development?
17:21michaelr525platform
17:24michaelr525Take your time, you don't have to answer right away.. :)
17:25coopernursemichaelr525: seems like facebook has proven you can grow almost any language. they use php extensively (although they did end up writing a compiler for it)
17:26michaelr525Sure, but I like clojure :)
17:27jblomoyes, clojure is mature enough to scale
17:27michaelr525And if you are given the chance to start from zero..
17:27michaelr525What would you choose?
17:27upwardindexmichaelr525: One of the major problems for scaling to such a big size is finding people to hire
17:27jblomothen i would pick whatever language the team was comfortable with
17:28michaelr525jblomo: And if you are the one building the team?
17:30jblomoyou mean if i had to start building before hiring a team?
17:33michaelr525yep
17:33michaelr525You start building and as the company grows you hire/grow your team
17:35jblomoyea, i'd start in clojure
17:36upwardindexcould be an interesting idea to lobby the closest school to start teaching clojure for your future expansion :)
17:36michaelr525haha
17:36michaelr525I think it's a bad idea though :)
17:37michaelr525I would only hire people which want to learn it or have already learned
17:38michaelr525okay, back to my first question. Anyone has some usefull links on designing scalable web architectures?
17:39michaelr525I think the question of DB is even bigger than the question of programming language...
17:40coopernursemichaelr525: you might like: http://highscalability.com/
17:41mrh0057infoq.com has a lot of presentation from twitter, facebook, and other organizations engineers about their architecture
17:41michaelr525thanks
17:50akhudekhi, is anyone familiar with clojureql around?
17:50akhudekI'd like to be able to insert a record into a table and have the auto-generated id returned
17:50akhudekthis works: https://gist.github.com/1177273
17:50akhudekbut is rather crude I would think
18:11chouserI thought strangeloop *was* a Clojure meetup this year.
18:18sridstrangeloop seems like an interesting conference; i hope they will upload the talk videos.
18:19coopernurseyeah, I hope to meet some of the folks from this channel there
18:25dnolenhmm anybody get :refer-macros working (and is it actually :requires-macros ?) ?
18:26sridlearning enlive templating seems daunting, but i'll persist
18:26amalloydnolen: looks like :requite-macros
18:27amalloy*require-macros
18:29dnolenamalloy: that was it thanks.
18:29dnolencljs-watch rules
18:30manutter1srid: sorry, I'm late to the party, but I just saw you mention enlive -- have you seen Brian Marick's enlive tutorials?
18:31manutter1I thought they were pretty good, so I thought I'd throw in a plug.
18:31manutter1https://github.com/marick/enlive-tutorial
18:32sridmanutter1: thanks, I'll take a look
18:32manutter1Oops, that's the code, but you can follow the link to the tutorial itself.
18:39dnolenamazing, match.core almost just works with ClojureScript!
18:41dnolenJS.Next indeed
18:47mudgehow does leiningen setup the classpath when running lein run? or how can i find this out?
18:54mudgehow do I call java on the command line to run my java program?
18:58raekmudge: run "lein classpath"
19:13scottjsrid: btw strangeloop talks have shown up on infoq during the following year, I suspect that will happen again
19:15coopernursemudge: if you're trying to package your clojure app as a standalone jar you can run on another machine
19:15coopernursethen you can run: lein uberjar
19:15coopernurseand that will create a single jar with all the dependencies rolled up into a single big jar file
19:17coopernursethis article has some good info on packaging up hello world that you can run
19:17coopernursehttp://zef.me/2470/building-clojure-projects-with-leiningen
19:20dnolenpattern matching for JavaScript, er I mean ClojureScript, http://dosync.posterous.com/advanced-pattern-matching-for-javascript
19:22hugoddnolen: I was wondering just today if that might be possible… :)
19:23dnolenhugod: amazing simple. The main problem is difference between types in Clojure and ClojureScript. Need some way to communicate that to the macro that it's being called by the ClojureScript compiler.
19:23amalloyall things are possible, if you just mention to dnolen that "wouldn't it be cool if..."
19:52mudgef
19:53mudgeanyone ever stopped an embedded jetty from the command line?
19:55mudgecoppernurse, i am using git to deploy my webapp, and I want to use the command line to start web app remotely
19:57scottjcan you kill the process and restart it using ssh?
19:57scottjor you want everything but jetty to remain up?
19:58mudgescottj: i want to kill the process
19:59mudgescottj, but i'm not sure if it is always safe to just kill the process, i wonder if there is a gracefull way to do it
20:02dnolenwowzers, https://gist.github.com/1177425, Google Closure optimizing the output of match
20:04mrh0057mudge: if you use kill <processid> it will send a stop signal to the program and try to kill it gracefully. There is flag you pass in kill to force quite.
20:06mudgemr0057, ah thanks, so I guess i would just write a shell script that finds the webapp/jetty process and then kills it gracefully
20:06mrh0057yes you call just a the kill command to stop jetty
20:07st3fanwhat is the easiest way to start a clojure repl in emacs?
20:08st3fani just want to play with some code .. not have a project with lein
20:08mudgest3fan, clojure-jack-in is really easy
20:08st3fanof what package is that part?
20:08scottjst3fan: recent clojure-mode+swank I think
20:08amalloygoodness, dnolen, that is pretty unintelligible
20:09st3fanswank-clojure?
20:09clojurebotsee swank
20:09bioinformaticszeCould anyone offer me a suggestion on converting a loop to a lazy sequence?
20:09mudgest3fan: https://github.com/technomancy/swank-clojure
20:09amalloybioinformaticsze: sure, that's always fun
20:10amalloy(that said, everyone's life is easier if you just gist some code and ask if anyone can help with ___, rather than asking permission and then making folks wait for the code)
20:10st3fanoh th version emacs shows me is super old .. 1.1.0
20:11scottjamalloy: sounds like clojurebot needs an asking response ala #emacs
20:11amalloyanyone?
20:11clojurebotPlease do not ask if anyone uses, knows, is good with, can help you with <some program or library>. Instead, ask your real question and someone will answer if they can help.
20:11scottjer anyone instead of asking I think
20:11bioinformaticszeSorry. Here is a gist: https://gist.github.com/1177434
20:11dnolenamalloy: you think that's crazy, this is the output of the redblack tree balance pattern https://gist.github.com/1177437
20:12amalloyscottj: i'm aware of "anyone?", but if someone looks like they're trying to be polite i aim for something a little less rude-looking
20:12scottjclojurebot: sales pitch?
20:12clojurebotTitim gan éirí ort.
20:12amalloyhah. no, we don't have that one
20:12amalloybioinformaticsze: and what do you want a lazy sequence of? that bytes in the input stream
20:12amalloy?
20:13bioinformaticszeI guess so. I'm trying to download the file and write it to another file.
20:13amalloybioinformaticsze: well, then (a) you don't really want a lazy sequence, and (b) clojure.java.io/copy already does this
20:14bioinformaticszeThis is the original version I used. But it ran out of memory (HEAP?).
20:14amalloyoh and (c) (if-not test (do forms)) is equivalent to (when-not test forms)
20:14bioinformaticszehttps://gist.github.com/1177441
20:15amalloyyes, for a large file that will blow the heap. go look at clojure.java.io/copy
20:15bioinformaticszeOK. Thank you.
20:15bioinformaticszeI will use that.
20:16bioinformaticszeI wish I had asked three hours ago. :(
20:16TimMcBut then you would have learned less!
20:17TimMcNow you know *why* to use clojure.java.io/copy, not just that you should in this instance.
20:17bioinformaticszeCould you tell me what is wrong in this version that is causing the heap to blow? https://gist.github.com/1177441
20:17bioinformaticszeTimMc: That's true. Thank you.
20:18TimMcbioinformaticsze: I would guess that to-byte-array reads in the entire input stream and tries to represent it as a single byte array.
20:18TimMcIf the file is really big, that might not fit in memory.
20:18bioinformaticszeI see.
20:18TimMcIn short, you need to take a streaming approach.
20:19TimMcCurrently, you're trying to swallow a wedge of watermelon all at once. You need to bite off smaller pieces!
20:20bioinformaticszeHow would I convert that into a stream? Adding lay-seq beforehand didn't seem to work.
20:21TimMcI presume clojure.java.io/copy uses a loop to read a chunk, write a chunk, repeat.
20:21st3fanmmm water melon
20:21TimMcYou could do the same, or just call the library function.
20:21coopernursebioinformaticsze: do you need a stream, or do you just want it written to a file
20:21coopernurseI haven't used copy, but I'm reading the docs here: http://clojuredocs.org/clojure_contrib/clojure.contrib.io/copy
20:22coopernurseand it looks like you can pass it a File
20:22coopernursewhich might make your task a one liner
20:22bioinformaticszeI think I know how to write to the file using copy. I was asking so to understand how to use lazystreams better.
20:23coopernurseoh, I see.
20:23TimMcLazy streams?
20:23bioinformaticszeSorry. Lazy sequences.
20:24TimMcI don't think you want laziness here.
20:24TimMcThat's for delaying computation, and it doesn't work well when you are holding open resources, such as file handes and network connections.
20:24bioinformaticszeOK.
20:24TimMcAnyway, here's how clojure.java.io/copy is actually implemented: https://github.com/richhickey/clojure/blob/8c9b0574a83f6c77576325b724c837cf4143eb33/src/clj/clojure/java/io.clj#L316
20:26bioinformaticszeHere is a refactored version using copy: https://gist.github.com/1177434
20:27TimMcand above that are some variants for other streams
20:27TimMcbioinformaticsze: Is `to` a File?
20:28bioinformaticszeYes. I think I don't need to make a stream for it do I?
20:28TimMcDoesn't look like it.
20:28bioinformaticszeWell spotted!
20:28TimMcio/copy can take a File for output
20:32bioinformaticszeI can use *file* instead?
20:35amalloyTimMc: i think programming needs more watermelon metaphors
20:36ent0does (for [x [1 2 3] y [4 5 6]] [x y]) have a special name in set theory?
20:37TimMcamalloy: I was trying to figure out if the rind could be a header, but I don't consume watermelon slices from that direction.
20:38TimMcent0: Cartesian join?
20:38bioinformaticszeUpdated version: https://gist.github.com/1177434
20:38TimMcLookin' sharp.
20:39TimMcJust toss a docstring in there.
20:39bioinformaticszeI there a clojure alternative to File. ?
20:39bioinformaticszes/I /Is /
20:39lazybot<bioinformaticsze> Is there a clojure alternative to File. ?
20:39ent0TimMc: that's it. thanks.
20:40amalloyit would be called the cartesian product (maybe join is a synonym?) if you wrapped a (set) around the (for); i think ordering probably makes it a little different
20:41amalloybioinformaticsze: clojure is a hosted language, in a pretty fundamental way. the clojure way to get file handles is "just use the java built-ins"
20:41bioinformaticszeOK. That's good to know
20:41bioinformaticszeThank you.
20:42bioinformaticszeThank you both for your help.
20:44akhudekLauJensen: any insight on this? https://gist.github.com/1177273
20:45akhudekI noticed in the clojureql code there is :last-index that seems intended to be put in metadata
20:45akhudekhowever, the metadata of the result of a conj! is empty
20:47klutometisDoes anyone know the relative complexities of `cons' and `conj'? In some lisps, for instance, `cons' is O(1) but `append' is O(n). Does anyone know if `conj' is O(n)?
20:47klutometisThe following seems to contradict that:
20:47klutometis&(count (time (reduce #(cons %2 %1) '() (range 10000))))
20:47lazybot⇒ "Elapsed time: 12.149319 msecs" 10000
20:48klutometis&(count (time (reduce #(conj %1 %2) '() (range 10000))))
20:48lazybot⇒ "Elapsed time: 10.636916 msecs" 10000
20:48akhudekklutometis: at least with conj, it depends on what data structure you are conjing
20:48klutometisakhudek: I noticed a note to that effect in the docs.
20:52akhudekmy guess is that for vectors conj would have average time log32n
20:52akhudekfor sorted collections log2n
20:52TimMc So, constant. :-P
20:54symbole`Those two examples should perform similarly. It does on my machine.
20:55TimMcklutometis: cons and conj on a list do the same thing.
20:55TimMcTry it with vectors instead.
20:56akhudeknot to mention that count on a list is O(n)
20:57symbole`akhudek: Does a vector know its length?
20:57TimMcThat's OK, O(n) is a lower bound for concatenation anyway.
20:57akhudekyes
20:57TimMcOh right, but it would make that step faster for vector.
20:57TimMc&(find-doc #"count")
20:57lazybot⇒ ------------------------- clojure.contrib.macro-utils/mexpand ([form]) Like clojure.core/macroexpand, but takes into account symbol macros. ------------------------- clojure.contrib.macro-utils/mexpand-1 ([form]) Like clojure.core/macroexpand-1, but takes into a... http://gist.github.com/1177493
20:57TimMcmeh
20:58TimMc,(doc counted?)
20:58clojurebot"([coll]); Returns true if coll implements count in constant time"
20:59klutometisakhudek: I just threw count in there to avoid printing the entire list.
20:59TimMcah
20:59klutometisTimMc: You're saying `concat' is O(n)?
21:00akhudekI think he meant that it takes at least O(n) to build a list of size n
21:00akhudekno matter the complexities
21:00TimMcIterative concatenation, yes.
21:00akhudekof conj
21:00TimMc(I.e., you're doing it one element at a time.)
21:00TimMc&(#() (time (reduce #(conj %1 %2) '() (range 10000))))
21:00lazybotjava.lang.IllegalArgumentException: Wrong number of args (1) passed to: sandbox16249$eval18562$fn
21:01TimMchrm
21:01TimMc&(fn([_]) (time (reduce #(conj %1 %2) '() (range 10000))))
21:01lazybotjava.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Symbol
21:01TimMcUgh, too much Java.
21:01amalloyTimMc: you can use = there, instead of #(), and it will actually work :P
21:01TimMcOh, cute.
21:01TimMc&(= (time (reduce #(conj %1 %2) '() (range 10000))))
21:01lazybot⇒ "Elapsed time: 12.829725 msecs" true
21:02SomelauwSomething that keeps confusing me with all sequence functions is the order of the arguments. Sometimes the sequence seems to go first and sometimes the count.
21:02TimMc&(= (time (reduce #(conj %1 %2) '[] (range 10000))))
21:02lazybot⇒ "Elapsed time: 11.886005 msecs" true
21:04st3fani'm getting a "loop requires a vector for its binding" error on http://pastebin.com/WJ5pVqnJ .. does anyone see why?
21:04amalloyyour second loop doesn't supply a vector for its binding :P
21:04st3fanoh argh
21:04st3fans/loop/recur
21:04amalloyi assume you meant recur
21:05TimMcst3fan: do that to line 5
21:06symbole`TCO where art thou?
21:06amalloymeh
21:06amalloyi'd like TCO for mutually-recursive functions, but for self-recusion i think explicitly saying recur is nice
21:06TimMcsymbole`: Surprisingly rarely needed.
21:07amalloyTimMc: i wanted it last week for http://stackoverflow.com/questions/7134733/tree-search-saving-execution-state/7134870#7134870
21:07amalloybut, agreed, i rarely care
21:09st3fantco is overrated
21:09st3fani think recur is much nicer / more explicit
21:10amalloyst3fan: except for mutually-recursive functions
21:10TimMcamalloy: I haven't fully grokked your SO solution, but all this returning and executing of thunks puts me in mind of trampoline.
21:10amalloy*nod*
21:11TimMcI guess you basically are writing a variant on that?
21:11amalloythe solution is a customized trampoline
21:13amalloyTimMc: just finished rereading Stranger in a Strange Land last night. good book, and it's always nice to be reminded of the origin of the word "grok"
21:25TimMcHmm. Maybe write a parameterized trampoline that takes a custom predicate.
21:26amalloyTimMc: sure. but then you have to jump back up to the top level every time; you can't do a bunch of work on a single stack frame
21:28SomelauwBut you can't make a trampoline of mutually recursive functions that output a function.
21:29TimMcSomelauw: You could, with more wrapping.
21:29amalloywhich i think the docstring of trampoline even mentions? ##(doc trampoline)
21:29lazybot⇒ "([f] [f & args]); trampoline can be used to convert algorithms requiring mutual recursion without stack consumption. Calls f with supplied args, if any. If f returns a fn, calls that fn with no arguments, and continues to repeat, until the return value is not a fn,... http://gist.github.com/1177551
21:34mudgeis running a clojure program like this: java -cp "lib/*:src/" clojure.main src/jobboard/core.clj less efficient than running the clojure program from the compiled files?
21:34mudgebecause when I run java -cp "lib/*:src/" clojure.main src/jobboard/core.clj i notice that no class files are generated
21:35mudgedoes that mean that the class files are compiled every time on the fly?
21:37TimMcI don't know, but it probably doesn't contribute much to the startup time.
21:39mudgeTimMc: yes, which might not matter because my clojure program is a web application, so it doesn't matter if it is a little slower starting up, it is a long running process
21:39amalloyTimMc: it's probably a non-negligible part of the startup time
21:40amalloybut the jvm is gonna start up slow no matter what you do with it
21:41mudgeamalloy: non-negligible, as in taking up a lot of startup time?
21:41amalloythere's a big gap between "non-negligible" and "huge"
21:43mudgeso it is more than a litte but not a lot
21:43amalloy*shrug*
21:43amalloyit's not zero
21:43amalloymore than that, try it and see
21:46klutometisIs anyone aware of a mechanism to express infinity in Clojure besides Double/POSITIVE_INFINITY and the like?
21:47amalloyis there a way to write infinity other than infinity?
21:47symboleklutometis: I suspect Clojure would use what Java offers.
21:49TimMcklutometis: Not in an interoperable way.
21:49klutometissymbole: Indeed; it's just too bad I can't test against Double/POSITIVE_INFINITY with an integer index without incurring implicit casts.
21:49devnhm, neat -- didn't notice until a moment ago that in clojurescript you can use doubles all over the place, like (range 0.1 1.2 0.3)
21:49klutometisTimMc: Is there anything non-interoperable, so to speak, on the Clojure side?
21:50TimMcI think protocols are pretty much inaccessible from Java.
21:50TimMcbut not using Double/POSITIVE_INFINITY would make your stuff unusable from pretty mcuh the rest of Cloure as well
21:50TimMc(don't quote me on protocols)
21:51devnTimMc: What about a protocol on an interface?
21:53devn(I showed up late to this conversation, 1 buffer with oversized text of context)
21:58TimMcdevn: Something about Double/POSITIVE_INFINITY and interop.
21:58TimMcklutometis: Can you expand on what's wrong with infinity here?
22:04klutometisTimMc: I'm running a tree algorithm, for instance, to discover the number of leaves with an optional `max' parameter; if it encounters more than max, the computation bails out.
22:05klutometisBy default, I'd like it to be infinite.
22:05klutometisSure, we can do something like max: nil, etc.; but I'd rather not special-case it.
22:06amalloyso use Long/MIN_VALUE or something
22:06klutometisThere's also Integer/MAX_VALUE, etc.; but it feels dirty. Also: doesn't Clojure automatically transition to BigInt at some point?
22:06amalloys/min/max
22:06lazybot<amalloy> so use Long/max_VALUE or something
22:08TimMclazybot: Not case-sensitive? For shame.
22:08rata_hi
22:09TimMcklutometis: I think nil is not dirty for this -- you are decaring the absence of a limit value.
22:10klutometis&(expt 2 128)
22:10lazybotjava.lang.Exception: Unable to resolve symbol: expt in this context
22:10klutometisIs there a way to make lazybot import clojure.contrib.math?
22:10klutometisAnyway, my REPL gives something like 340282366920938463463374607431768211456; which implies that we've implicitly gone into BigInteger territory, doesn't it?
22:11klutometisTimMc: That may not be conceptually rigorous, but maybe it's the best solution.
22:13rata_how can I specify the file encoding when I open a URL with (java.net.URL. url)?
22:15TimMcYou mean the character encoding?
22:19TimMcAnyway, I suspect what you mean is, you want to send an HTTP GET request to a URL and specify the character encoding of the resulting reader.
22:28devnklutometis: I think you want MAX_VALUE
22:29devn&(range 0 1 1/3)
22:29lazybot⇒ (0 1/3 2/3)
22:29devn&(range 0 1 0.1)
22:29lazybot⇒ (0 0.1 0.2 0.30000000000000004 0.4 0.5 0.6 0.7 0.7999999999999999 0.8999999999999999 0.9999999999999999)
22:30devnnot sure why I haven't used those more often.
22:32TimMcdevn: But with MAX_VALUE, you lose out on auto-promotion.
22:32devnTimMc: what's the problem again? heh
22:32devnwe're talking about POSITIVE_INFINITY and interop
22:32TimMcYou could end up with a BigInt count greater than Long/MAX_VALUE
22:32devnwe're talking about MAX_VALUE and promotion
22:32devnwhat's the actual problem?
22:33TimMc22:05 < klutometis> TimMc: I'm running a tree algorithm, for instance, to discover the number of leaves with an optional `max' parameter; if it encounters more than max, the computation bails out.
22:33devnah!
22:34TimMcThe question is how to appropriately encode "no maximum".
22:35TimMc+Inf means you are dealing with floats, which is inappropriate
22:35TimMcnil means you can't use < directly, so have an additional clause in the guard
22:36TimMcLong/MAX_VALUE means that you don't have infinity anymore, even if the count would normally promote to a bigint
22:38devnseems like there ought to be some middle ground where -- could you switch between MAX and +Inf at some reasonable point in the computation?
22:38devnCould you promote yourself or something?
22:38TimMcew
22:39devnIt's a start...
22:39TimMcAnyway, I think nil is the most meaningful and correct approach.
22:39devnTimMc: Sorry again for the weird buffer, but could you explain why?
22:40TimMc(and max (> current max)) is not much worse than (> current max)
22:40TimMcnil is also appropriate to denote the lack of a value
22:40amalloyare we really worried that your tree is going to contain more than ##(Long/MAX_VALUE) nodes? that's absurd
22:40lazybot⇒ 9223372036854775807
22:40TimMcamalloy: ssh!
22:41TimMcit could be a streaming tree! >_>
22:41amalloynext time i have ten quintillion things to count, i'll use Double/POSITIVE_INFINITY
22:41TimMcOK, so accept "nil" as a limit and convert it to Long/MAX_VALUE.
22:42klutometisamalloy: Heh; practicality rears its ugly head.
22:43klutometisTimMc: Is there +Inf? Scheme has one, to be sure. Is max: `nil' really conceptually accurate, or is it some indirect consequence of infinity?
22:43klutometisIt's true, I guess, that `infinity' means boundless; so maybe there's something to be said for a negative interpretation.
22:44TimMc+Inf was just a shorthand
22:45TimMcI don't know of a short way of writing it in Clojure.
22:46TimMc(I don't see anything on clojure.org/reader)
22:46amalloythere isn't anything
22:49klutometisI'm a little nostalgic for Scheme, where (>= +inf +inf) => true; even though I'm not sure that's mathematically correct.
22:55klutometis&(time (let [max nil] (map #(and max (> % max)) (range 1000000))))
22:55lazybot⇒ "Elapsed time: 0.737597 msecs" (nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil n... failed to gist: Broken pipe
22:55klutometis&(time (let [max Double/POSITIVE_INFINITY] (map #(> % max) (range 10000))))
22:55lazybot⇒ "Elapsed time: 1.307385 msecs" (false false false false false false false false false false false false false false false false false false false false false false false false false false false false false false false false false false false false false false false fal... failed to gist: Broken pipe
22:55klutometis&(count (time (let [max Double/POSITIVE_INFINITY] (map #(> % max) (range 10000)))))
22:55lazybot⇒ "Elapsed time: 0.687695 msecs" 10000
22:55klutometis&(count (time (let [max nil] (map #(and max (> % max)) (range 10000)))))
22:55lazybot⇒ "Elapsed time: 0.667645 msecs" 10000
22:56klutometisIt looks like it's just as efficient to check for the existence of max than compare against our best approximation of infinity.
22:56klutometisMaybe that settles it, then.
22:56amalloyklutometis: you weren't timing anything
22:57TimMcheh
22:57klutometisamalloy: Doh! Lazy maps.
22:59klutometis&(time (let [max Double/POSITIVE_INFINITY] (doseq [x (range 10000)] #(> % max))))
22:59lazybot⇒ "Elapsed time: 2546.715829 msecs" nil
23:00klutometis&(time (let [max nil] (doseq [x (range 10000)] #(and max (> % max)))))
23:00lazybot⇒ "Elapsed time: 2495.457683 msecs" nil
23:00klutometisThat's actually doing some work, isn't it?
23:01amalloyyes
23:01klutometis(I should have used x instead of the lambda-shorthand.)
23:01amalloyi mean, it's doing some work, but not the work you want to compare times
23:02klutometisamalloy: How should I set up this experiment?
23:02TimMcklutometis: With real data. :-)
23:02rata_TimMc: yes, that's what I mean
23:02rata_do you know how to do it?
23:02amalloyor at least, as you said, use x instead of a lambda. returning a lambda takes constant time, regardless of the code
23:03TimMcrata_: You'll get an inputstream from URL's API, and you can tell the Reader you pass it to what encoding to use.
23:03klutometis&(time (let [max Double/POSITIVE_INFINITY] (doseq [x (range 10000)] (> x max))))
23:03lazybot⇒ "Elapsed time: 2201.290519 msecs" nil
23:03klutometis&(time (let [max nil] (doseq [x (range 10000)] (and max (> x max)))))
23:03lazybot⇒ "Elapsed time: 2504.918599 msecs" nil
23:03rata_TimMc: but I'm using enlive-html/html-resource
23:04klutometisTimMc: For the time being, I think you have the best solution; I'll run it on real data and let you know.
23:04TimMcrata_: Not familiar with it, but I suspect there's a shorthand for what you want.
23:04TimMcBedtime, in any case.
23:04amalloyklutometis: that last versino actually timed something, at least
23:04klutometisamalloy: Exactly; the difference is probably nominal.
23:05amalloyof course
23:19ibdknoxfor those who were asking about my nodeknockout project: http://nodeknockout.com/teams/wrench-labs
23:19ibdknoxsadly no clojurescript :(
23:22amalloyibdknox: i think you could use a few more sponsors in the right column :P
23:23ibdknoxlol
23:23ibdknoxthat's for the nko itself
23:23ibdknoxnothing to do with me :-p
23:32amalloyibdknox: did the purple ovals get explained at the beginning? they seem to jump around kinda randomly
23:33sridthis channel is being logged publicly ... shouldn't that be put in /topic? http://clojure-log.n01se.net/
23:35ibdknoxamalloy: yeah it was, they're teleporting ones
23:35ibdknoxamalloy: or with the theme, they ASLR's :)
23:35ibdknoxerr
23:35ibdknoxaslr hacks
23:35devnsrid: i think it used to be
23:37mudgeis there any solution for using clojure for shell scripting? because bash sucks
23:39amalloyhah, the kilobyte currency reminds me of something, ibdknox. last night amazon was trying to sell me a kindle preorder (they succeeded, which is not relevant). what made me laugh was the "5KB filesize" and "1064 page print length"
23:39ibdknoxhahaha
23:42devnjust have to throw this phrase out into the ether:
23:42devnmadison square clabango
23:44amalloyibdknox: so is the coding period over?
23:46ibdknoxamalloy: yep, ended at 5pm pst
23:47ibdknoxwhat's sad is I stopped about midday today to come up with a design and then we didn't implement most of that design :(
23:48amalloywell, maybe i'll leave it running for a couple hours and see if my defenses ever become inadequate
23:48ibdknoxamalloy: I was going to have turrets that had lasting effects :D
23:48ibdknoxyeah
23:48ibdknoxit ended up being too easy :(
23:49amalloythe first few levels were tricky
23:49ibdknoxyeah
23:49ibdknoxthere are a bunch of other maps too
23:49ibdknoxbut we didn't hook them up
23:49amalloyouch
23:49amalloytimed coding is tough
23:49ibdknoxhaha, the fragmenter towers are wicked over powered
23:50ibdknoxyeah
23:50ibdknoxI think we did well
23:50ibdknoxour is functional
23:50ibdknoxand at least moderately entertaining :)
23:58amalloyibdknox: does it scale up to MB if you have enough points? that would be a selling point
23:58amalloyroundabout when you get to wave 150, it looks like
23:59amalloyincidentally, i don't think the orange ones are overpowered. the green guys give more bang for your buck