#clojure logs

2009-11-11

00:01timothypratleywhat's a usage for (ints ...)?
00:03timothypratley,(ints (make-array Object 1))
00:03clojurebotjava.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [I
00:03timothypratleyIs that intended? I can't think of a scenario where "ints" would do anything useful, but it must exit for a reason :)
00:05technomancyit's not useful for pure-clojure; it's intended for java interop
00:05timothypratleyI just need something for a test I'm writing, any ideas?
00:06timothypratley(otherwise I'll just leave it out)
00:07_atotimothypratley: ints is usually used for type-hinting
00:09timothypratley_ato: ints type hint is different from ints function
00:10timothypratley,(doc ints)
00:10clojurebot"([xs]); Casts to int[]"
00:10_atoala (defn foo [int-array] (let [local-array (ints int-array)] ...))
00:11_atosimilar to how you'd do the same thing with int, to perevent boxing
00:11_atoat least that's what I always assumed it was for
00:13_atodon't think you can test that, as there's no way to know whether it got unboxed ;)
00:14timothypratleyhmmm ok good :)
00:14timothypratleythanks
00:15timothypratley,(ints (int-array 1))
00:15clojurebot#<int[] [I@9f017d>
00:15timothypratleyI wonder if that's a false sense of security
00:45codyKanyone using maven together with swank-clojure-project?
00:46codyKI'm a little confused about how swank-clojure-binary should be getting set, since maven seems to keep jars in a single repo rather than in the individual project directories
00:52codyKhrrm, looks like perhaps doing mvn clojure:swank on commandline and then connecting to it from emacs is the way to go
01:44twbrayWatching thousands of lines of +PrintGCDetails output... what fun
04:07michaeljaakaHi!
04:16michaeljaakaIs there any live?
04:17michaeljaakaJust curious
04:19ChousukeI guess it's silent time right now :P
04:30somniumquestion for silent time: why is eval frowned upon?
04:31somnium~eval
04:31clojureboteval is evil
04:31michaeljaakaeval
04:31michaeljaaka~do
04:31clojurebotTitim gan éirí ort.
04:31michaeljaakahmmm bot could be an intteractvie help
04:32somniumhe speaks irish when you confuse him
04:32michaeljaakainstead of looking into doc I would type here a function name and get an answer
04:32somniumhe does that already
04:32michaeljaakahow?
04:32somnium,(doc eval)
04:32clojurebotDENIED
04:32somniumhe really doesn't like eval I guess
04:32michaeljaaka.(doc do)
04:33michaeljaaka.(doc ->)
04:33michaeljaakahmmm
04:33michaeljaakadoc ->
04:33somniumI have a list of expressions like '(+ foo bar baz), and foo bar baz gets looked up in the database and replaced, and I call map eval
04:33michaeljaakadoc do
04:33somniumit works like a charm but eval makes me feel dirty
04:33somnium(doc do)
04:33clojurebotTitim gan éirí ort.
04:33somnium,(doc do)
04:33clojurebotI don't understand.
04:33somnium,(doc ->)
04:33clojurebot"([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."
04:34michaeljaakadoc let
04:39raekwhy use eval when one have macros?
04:40raekanyway, I haven't used eval this far...
04:40raekbut it *is* there, which means you are free to use it
04:41somniumits in a layout like: {:title "foo" 1 id-1 2 id 2 :func '(+ (- foo bar baz))}
04:41raekwhy not #(+ (- foo bar bax)) ?
04:41raekwhere is the code created?
04:41somniumbecause foo bar baz don't exist
04:42somniumthey have to be resolved at runtime
04:42somniumits similar to a macro, but the information isn't available at compile time
04:42raekah, then perhaps eval is best the way
04:42somniumits quite convenient in any case
04:43raekmy personal opinion is that you should use it
04:43raekas long as you control the code generation
04:47raekbut this is just my opinion, more experienced people might have different ones
05:13piccolinoAny feedback on my little CSV library would be helpful. http://github.com/davidsantiago/clojure-csv
05:14Maddasraek: Why would macros change anything about the need for eval?
05:14MaddasOh, sorry, this was addressed just afterwards.
05:23raekpiccolino: sounds like a useful lib
05:24piccolinomy first real clojure code.
05:27raeklooks good :)
05:27piccolinoThanks.
05:28raekhowever, it's good to have doc and author metadata in (ns ...)
05:28piccolinoFor all the functions?
05:28raeklike the various clojure.contrib libs have
05:29raekno, a general description of the whole file
05:29raeklike:
05:29hiredmanclojurebot: web dev?
05:29clojurebotweb dev is the worst dev
05:29piccolinoOh yeah, OK.
05:29piccolinoI'll look at how to do that.
05:29raekotherwise, it's well documented
05:31raek(ns
05:31raek #^{:author "Stephen C. Gilardi",
05:31raek :doc "def.clj provides variants of def that make including doc strings and
05:31raekmaking private definitions more succinct."}
05:31raek clojure.contrib.def)
05:31raeklike that ^
05:32raekclojure.contrib uses that alot
05:32raekmaybe you should add the csv code there...
05:33piccolinoTo clojure-contrib?
05:33raeksimple data formats are good candidates for clojure-contrib. imho
05:33raekyes
05:33piccolinoHm, well, glad to do that, if they'll have it.
05:34raekone of the things I love about clojure is how easy it is to parse data in a lazy way
05:35piccolinoYeah, I originally wrote it not lazy, without even thinking about it.
05:35piccolinoAnd then changing it to be lazy was pretty easy, very little change.
05:37raekhow does the output look like? seqs of seqs of strings?
05:37piccolinoThe output of a CSV parse is a sequence of vectors of strings.
05:38piccolinoEach vector of strings is a row.
05:45raekI really like that clojure libs tend to be build to emmit data in *simple* data structures
05:46piccolinoYeah, you should see somnium's MongoDB library.
05:46piccolinoIt's fantastic. Just turns clojure data structures in MongoDB documents and vice versa.
05:48piccolinoGoodnight.
05:48somniumglad you like it, but that's more thanks to mongodb's data format than my efforts
05:48piccolinoAnd thanks for your help.
05:48piccolinosomnium, that's true, but we were praising clojure here.
05:48piccolinoYou couldn't do the same thing with Scala or Java.
05:49somniumtrue, the scala mongo code I've seen doesn't look pleasant
05:49somniumbut that might be scala's fault
05:49somniumclojurebot: tell me about scala
05:49clojurebotScala often gets in the way when trying to write neat code -- seen in #scala
05:50piccolinoI thought it was just the static typing. You can't really take some data struture you made and use in your code, and have it automatically be turned into mongo stuff. Very easily.
05:52somniumI started on scala once or twice, but it always gave me a headache. (I just wanted to try out Lift, really)
05:52piccolinoYeah, I found Scala just before Clojure.
05:52piccolinoDidn't really feel like it was saving me much time and effort over Java after a while.
05:53somniumclojurebot: tell me about scala
05:53clojurebot{((x: Any, y: Any) => (f: Function2[Any, Any, Any]) => f(x, y))(1, 2)((x: Any, y: Any) => x)}
05:53somnium^ my head hurts
05:53piccolinoLove that type inference.
05:53piccolinoThat was what killed me. I sure had to type out a lot of types for a language that had type inference.
07:28AWizzArd~max people
07:28clojurebotmax people is 197
08:09raek(into {} (map fn-making-pairs coll))
08:09raekis this ideomatic?
08:11somniumfn-making-pairs is returning vectors?
08:12raekyes
08:13raeka sequence of vectors of size 2
08:15somniumthen it works fine with fn-making-pairs
08:16somniumas I'm sure you're aware
08:16raekthere's also: (merge (map fn-making-maps coll))
08:16somniumthat would create a vector though
08:16raekif fn-making-maps returns {<key> <value>}
08:17somniumah, yes, didn't notice you changed the name
08:17raeksomnium: which?
08:17raekok
08:18raekso, are both equally good?
08:18somniumI think it depends more on the function
08:18somniumI mean, if you have this function, and you want to make it into a vector or a map, what you showed was fine
08:19chouserraek: I think into is preferred
08:19raekalso, the function would only return a signle key-value pair
08:19somniumraek: I would go with chouser on this one
08:20chouserat least right now on HEAD, into uses transients and so is likely faster
08:20raekok, thanks!
08:20raekmaybe merge is better when merging maps with more associations
08:21raekthen I'll continue to use into...
08:23chouserright, if you already have fn-making-maps and esp. if it can return larger maps then clearly you need to use merge
08:23chouserwell, (apply merge (map ...)) right? But without those constraints I think 'into' is more common.
08:34raekchouser: ah, yes. forgot apply
08:36chouser'merge' could use transients
08:42somnium(reduce conj {} ...) seems to be very slightly faster than (reduce into {} ...)
08:43somnium(2/10s of a second per 1,000,000 on my old laptop), I guess into is firing up a new loop on every iteration?
08:52chousersomnium: for a large number of small maps, conj appears to be faster. For a small number of large maps, into seems faster.
08:53chousereither could overtake the other as the functions mature.
08:56somniumchouser: good to know, thanks
08:56chouser*sigh* http://golang.org/
08:56somniumI saw that
08:57somniumI thought, that could make a great platform for clojure :)
08:57somniumif only it could link to C libs
08:57somnium(I'm not sure that it can't, but it wasn't mentioned anywhere)
08:58blackdog`why the sigh chouser? another missed opportunity, or ...
08:59chouserit comes bundled with libs. like a "simple regex lib" that understands . but not (?>X)
09:00blackdog`it's still experimental i guess,
09:00blackdog`they do mention regex needs more advanced functioality
09:00cemerickI don't quite grok its raison d'être
09:01chouserwell, that's more a datapoint suggesting the state of the useful libraries.
09:02somniumit seems kind of like D with message passing (though D can link to C AFAIK)
09:02chouserlanguages already demand so much of their users: leran the primitives, learn the semantics, learn the data types, learn the APIs, learn the configuration and deployment environments, and so on.
09:02cemerickyeah, I was going to say, they're a little nuts when they say that "No major systems language has emerged in over a decade". D is quite a big leap forward, and has some degree of momentum.
09:03cemerickplus the C linkage, as somnium said
09:03chouserit seems to me that new languages should strive to reduce that set while making their differences as clear and beneficial as positive.
09:05chouserinstead we get this kind of thing -- learn all the above, plus our own new syntax, plus you'll have to re-write regex and xml parsers and parser generators and just everything from scratch.
09:05fogus_The approach to language design is typically, look at the big pile of paradigms, pick a few, tweak a few things here and there. Tada... ne language
09:06fogus_rhickey: yep
09:06chousergood guess!
09:06chouserthey asked me why I sighed.
09:06rhickeyGoogle is sure squatting on some terms with Closure and Go
09:07cemerickthe FAQ makes it sound like they'd like to stop writing C at google. I'll bet they have far different requirements in that context than any of us do.
09:07chouseryeah, you'd think they'd know more about SEO
09:07AWizzArdwhat is it about this Go thing?
09:07cemerickchouser: don't worry, they'll make sure the results are How They Should Be.
09:07chousercemerick: heh
09:07fogus_They know all about SEO... my guess is that golang will be the #1 hit for "Go" any day now
09:08chouseroh, how nice! the standard lib inluces a PNG image decoder
09:08fogus_cemerick: beat me to it ;)
09:08cemerickchouser: is that a big deal?
09:09chousercemerick: it's goofy. I guess if you have to build all your libraries from scratch, you have to start somewhere. Maybe png image decoders (but apparently not jpeg?) is where you start. *shrug*
09:11chouser"goroutines"
09:11cemerickall those billions in advertising funny-money will pay for a lot of go coding monkeys in some random google playground. I'll bet libraries won't be a problem soon enough.
09:12chousercemerick: could be, and would still be unfortunate.
09:12cemerickI agree.
09:12cemerickThis is the sort of thing that happens when an organization simply has too much money.
09:12chousercemerick: if that happens, I'll probably have to learn it eventually, though I've managed to avoid learning PHP so far.
09:12Chousuke_Go actually didn't seem too bad.
09:13chouserthat won't last though -- the shop I work for has a lot of PHP. ...it's just a matter of time now...
09:13cemerickchouser: well, you're a PL masochist, AFAICT :-)
09:14gbtat least you're not being pushed onto cobol *sob*
09:14chousergbt: good point
09:16chousersuddenly a day of writing unit tests in clojure doesn't look so bad. Thanks, Google!
09:16gbtwell at least my misfortune wasn't met with snickers ;)
09:17ChousukeAt least Go has the right idea about interfaces.
09:17ChousukeIt'll be interesting to see if anyone actually starts using it.
09:20fogus_The best part so far appears to be the .go file extension. That looks pretty cool.
09:20chouserthe fact that "why does go not have macros" isn't even on the list is telling.
09:21somniumI wonder if this is that language yegge was blogging about
09:21chousernah, yegge was talking about his own version of javascript
09:28ordnungs`hi all
09:28chouserordnungs`: hello
09:34ordnungswidrigjust another day, just another programming language is born
09:37rhickeynew language, new backend for cinc
09:43ordnungswidrigcinc?
09:44chouserordnungswidrig: http://blog.n01se.net/?p=41
09:47adityohello folks
09:47jableyordnungswidrig: turtles
09:47chouserheh
09:47adityo,(import '(java.util UUID))
09:47clojurebotjava.util.UUID
09:47adityo,(. UUID randomUUID)
09:47clojurebot#<UUID ab96c396-0685-4cc5-9a2c-161b42cb2f29>
09:48adityobut when i do the same thing inside a ns and file, i am getting an error
09:48chouserthat format sure is tenacious
09:49chouseradityo: what error?
09:51adityochouser: java.lang.IllegalArgumentException: Don't know how to create ISeq from: Symbol
09:51chouseradityo: from the 'import' line, right? are you doing it inside an 'ns' block?
09:53adityochouser: sorry my bad, got the issue, my function didnt have the args []
09:53chousernp.
09:53gbtI'm waiting for the day when I don't feel stupid :)
09:53chouser,(UUID/randomUUID)
09:53clojurebot#<UUID 1e245222-746c-4ae1-889a-8ea118f68c86>
09:54chouserbtw, that ^^^ is the preferred form for static method calls these days.
09:55adityoyes i changed it to that form
09:56chouseroh dear http://en.wikipedia.org/wiki/Go!_(programming_language)
10:00ordnungswidrigAs long as they dont call is gojure....
10:00chouserheh
10:01ordnungswidrigis cinc a current project or will is be addressed "later", say after clojure 2.0 or like that?
10:02chouserordnungswidrig: much of the work rhickey has been doing lately (reify, deftype, protocols) will directly support cinc
10:02chouserhe's also mentioned though that he wants at least more release before those go into the master branch.
10:03ordnungswidrigsounds reasonable
10:05AWizzArdI think when the changes of New go into Master it is maybe time for a new release, such as 1.1 or something like that?
10:06cemerickI confess I don't see an obvious use case for protocols in my work, although it's entirely possible I'm not grokking them fully.
10:06chouserAWizzArd: I think 1.1 is going to happen before the 'new' branch merge.
10:07somniumis a 1.1 rc close? (only issues I've had have been naming, c.c.test-is -> c.test, -> c.c.walk c.walk)
10:09ordnungswidrighow can I macroexpand in the repl?
10:09rhickeycemerick: do you use interfaces?
10:10chouser,(macroexpand-1 '(dosync a b))
10:10clojurebot(clojure.core/sync nil a b)
10:10somniumordnungswidrig: are you using slime?
10:10ordnungswidrigchouser: Doh! I missed the '
10:10ordnungswidrigsomnium: yes
10:11cemerickrhickey: certainly. But then, I'm happy enough to use deftype or reify as necessary. I'm rarely consuming others' libraries, so I don't often need to 'inject' interface impls for a given type.
10:12somniumordnungswidrig: C-c C-m macroexpands the expression at point into a new buffer
10:12rhickeycemerick: really? - you never wished, say, String, could play along with an API you built without putting in an if(x instanceof String) ... ?
10:12chouser'defprotocol' can't be used to *define* a host interface, right? The only time I've bothered to define interfaces, they need to be consumable by Java.
10:12chouseroh, except for finger trees. that will use protocols
10:13rhickeychouser: no, defprotocol will be completely dynamic
10:13ordnungswidrigsomnium: oh, nice. Didn't know this would work in the repl, too.
10:14rhickeyIn any OO shop I've been in, our own libraries and apps had become large enough that saying 'just derive from MyInterface' was no longer workable
10:15cemerickrhickey: I'm sure it happens occasionally, but I can't say it's frequent enough to become irritating. I might have simply internalized the pain, tho. :-)
10:15Chousukerhickey: Could there be a way to generate a Java interface from a protocol though?
10:15cemerickThe functional footprint of our Java codebase is rapidly shrinking relative to our clojure codebase. That makes things easier :-)
10:15rhickeyChousuke: quite possibly
10:16rhickeycemerick: are you using multimethods?
10:16cemerickrhickey: yes, but often not dispatching on a single arg's type :-)
10:17rhickeyhmpf
10:20cemerickI wouldn't fret about it -- if it makes it easier to build and maintain the core data structures, that well worth the price of admission for me.
10:21chouserhow many requests have been made to backport bug fixes or features to Clojure 1.0?
10:21ChousukeI suppose protocols will still break a dependency on Java. It should help porting eg. contrib to other Clojure hosts if libraries in contrib defined protocols and then used those instead of direct JVM calls.
10:21rhickeycemerick: I predict deftype+ defprotocol will be huge
10:21cemerickI'm sure. Part of my issue is that I'm so married to interfaces mentally, that I'm sure I'm not seeing the big picture.
10:22rhickeythey are just more powerful interfaces
10:22rhickeydon' t require derivation
10:22rhickeydynamic
10:22rhickeycan be applied to existing classes
10:22rhickeycan be partially inplemented
10:23rhickeycan mixin implementations mechanically
10:23cemerickThe a-ha moment is surely just around the bend for me.
10:23rhickeyreified
10:23rhickeylooks like I can do pre and post conditions at the protocol level too
10:23chouserI see one patch and recall zero other requests in the last 6 months. I guess I'm not shocked, but a bit surprised.
10:24rhickeychouser: yeah, seems like as always, some people use download, others master/trunk
10:24rhickeyof course, if there were more releases with bigger/breaking changes there might be more interest in bugfixes on a release branch
10:24ol3how do i define a 'private' value (e.g. like defn-)
10:24cemericktoo much fantastic stuff keeps going into HEAD
10:25cemerickthat's the sort of dynamic that makes the python moratorium seem like absolute lunacy to me.
10:25chouserapparently 1.0 is good enough without fixes for anyone that doesn't want HEAD
10:26chouserol3: there's stuff in clojure.contrib.def or you can just (def #^{:private true} foo)
10:26ol3chouser: thank you
10:27chouserrhickey: pre/post for any method?
10:27rhickeyso, we need names for the protocol predicate equivalents instanceof and isAssignableFrom
10:27rhickeychouser: yeah
10:28chouseroh, and in defprotocol rather than in implement? very nice.
10:28rhickeyI went with extend for (extend atype aprotocol ...)
10:28rhickeyso maybe (extends? aprotocol atype)
10:28rhickeyand (implements? aprotocol aninstance)
10:29chouserI like 'extends?' -- points to types not instance for me.
10:30rhickeysatisfies? an option instead of implements?
10:30rhickeyfor instance case
10:30AWizzArdhmm
10:30chouser'isa?' retains a moment of doubt for me, while 'instance?' is clear.
10:31defn`Am I being stupid? (defn myfunction [n] (reduce + (range 1 n)))
10:31opqdonutisa? pci? usb?
10:31opqdonut:)
10:31defn`oh god -- it's too early
10:31defn`nvm
10:33rhickeyso, for instances: satisfies?, implements? something-else?
10:34chouser"implements" in Java is about classes on both sides
10:34fogus_rhickey: typeof? ?
10:35chouserit's too bad "instance" is inaccurate
10:35esjquacks_like?
10:35chouserheh
10:35somniumhandles? ?
10:36mtm_follows? (as in follows the protocol)
10:37chouser(def a-foo (Foo)) (type a-foo) ==> ::Foo
10:37djorkhmm, my boss is on the phone with assembla for some kind of pitch
10:37defn`Hmmm, how to calculate the number of divisors...
10:37defn`The efficient way, that is..
10:38chouserthe instance case will mean the same as #(extends? %1 (type %2)) right?
10:39Chousukehow about "understands?"
10:40ordnungswidrigdefn`: efficient would be using prime factors.
10:40ordnungswidrigChousuke: adheres?
10:41chouser"provides?"
10:41rhickeychouser: it's slightly trickier than that, because sometimes a type is a Class, and thus a path to supers, and someting a keyword :my.ns/MyType, and not. extends? answers the question, "has someone said (extends MyType AProtcol ...)?", not, "does an instance of MyType satisfy the protocol?" (since they could due to class-based implementation)
10:42rhickeygetting an answer to the second question requires an instance right now
10:47chouserthat is certianly trickier.
10:49rhickeythe instance one is more important
10:50rhickeycompare instance? usage with .isAssignableFrom (never wrapped)
10:51chouser(instance? X a) implies (.x-method a) will work. (satisfies? ::X a) will imply (x-fn a) will work?
10:52rhickeychouser: where X is a protocol?, yes
10:53chouseroh, we don't use keywords for naming protocols? (skimming the Protocols page again...)
10:54rhickeysubject to dynamic redefs - I've made it tolerant so that if you originally defprotocol P with foo and bar methods, extend some types to implement it, then redef P with baz, those impls will still work for foo and ba, but fail for baz calls, until you re-extend
10:54chouserah, I see.
10:54rhickeyprotocols get top-level var names, so just Protocol
10:55rhickeydetypes get keyword names, since var name is factory fn
10:55rhickeydeftypes
10:55chouserbut the dynamic redef issue there is separate from your earlier statement about trickiness that I'm still trying to grok.
10:56rhickeygiven some keyword ::MyType, there isn't a path to the implementing class, and thus its supers
10:58chouser(satisfies? Number 5) will be false because Number is a class not a protocol?
10:58rhickeyso if you said (deftype Type [a b c] [Interface] ...) (extend Protocol Interface) then (extends? Protocol ::Type) -> false
10:59rhickeysatisfies?/extends?/implements? etc are only about protocols as first arg, not intertwined with type system
10:59chouserso my example is either false or it throws something?
11:00rhickeyoops, sorry (extend Interface Protocol ...) above
11:00rhickeychouser: throws something
11:00rhickeyor nil
11:01rhickeyI really want a separate set of predicates, and to encourage the use of protocols, it can completely isolate you from the host class system
11:02chouserthat'll be important, so I'm on board. Just have to cut these new neural pathways...
11:03rhickeyI guess satisfies? is better than implements?
11:05rhickeyfollows?, supports?, conforms?, complies?, heeds?, obeys?, observes?
11:06fogus_panders? caters? fits-the-bill?
11:06rhickeypander? hah
11:07defn`accommodates? harmonizes? integrates? suits?
11:08fogus_(head explodes)
11:08Maddastries-really-hard?
11:08chouserfogus_: Mine's already in shambles, trying to pick up the pieces.
11:09fogus_,(head explodes)
11:09clojurebotjava.lang.Exception: Unable to resolve symbol: head in this context
11:09fogus_:p
11:09the-kenny,(explode :head)
11:09clojurebotjava.lang.Exception: Unable to resolve symbol: explode in this context
11:09the-kenny:(
11:11mtmixnay on 'observes?' Sounds too much like an event watcher
11:11osaundersIs there such a thing as a lisp where code is written as a tree instead of lists?
11:11chouser,(isa? ::head ::exploded)
11:11clojurebottrue
11:12chouserosaunders: lists are used to build trees
11:12Chousukeosaunders: there's misc which uses maps
11:12ordnungswidrighmmm, can I determine the arity of a function at runtime?
11:12chouserosaunders: you can think of each list as a node, each element can be a symbol (leaf) or another list (child tree)
11:13fogus_richhickey: IMHO satisfies? is the most self-evident (so far)
11:13fogus_whoops, this is not github
11:14osaunderschouser: There's a difference though. Tree nodes may contain other tree nodes but that's not the same as child nodes.
11:15Chousukebut a tree which has a tree as a node is is in effect a bigger tree :P
11:15osaundersThe difference is nested lists are a fixed structure but a tree makes up something more akin to a graph.
11:15AWizzArdI am not a native speaker, but maybe complies? is also ok?
11:16ordnungswidrigAWizzArd: "complies to", it is?
11:16AWizzArdgenügt?
11:16AWizzArdfor example
11:17osaundersAnyway I think I got my answer: no.
11:17ChousukeAWizzArd: you conform to a protocol, but comply with standards :)
11:17ordnungswidrigChousuke: the point goes to you.
11:18ordnungswidrigcomplies-with? would by, um, long
11:21fogus_,(:arglists (meta (var +)))
11:21clojurebot([] [x] [x y] [x y & more])
11:21fogus_ordnungswidrig: ^^^
11:22ordnungswidrigfogus_: thanks, that is what I was looking for
11:23chouser,(:arglists (meta (var defmulti))) ; beware
11:23clojurebot([name docstring? attr-map? dispatch-fn & options])
11:24Chousukeordnungswidrig: you can't trust arglists :)
11:25Chousuke(alter-meta! #'+ assoc :arglists '(chousuke was here))
11:25Chousuke,(alter-meta! #'+ assoc :arglists '(chousuke was here))
11:25clojurebot{:ns #<Namespace clojure.core>, :name +, :file "clojure/core.clj", :line 654, :arglists (chousuke was here), :inline-arities #{2}, :inline #<core$fn__4440 clojure.core$fn__4440@b374f9>, :doc "Returns the sum of nums. (+) returns 0."}
11:25Chousuke(doc +)
11:25clojurebot"(chousuke was here); Returns the sum of nums. (+) returns 0."
11:26ordnungswidrigChousuke: I trust them on the repl for debugging. I don't expect them to be manipulated.
11:26ordnungswidrig:-)
11:26Chousukeordnungswidrig: some Clojure arglists are, though.
11:26Chousukelike defmulti's
11:27ordnungswidrigChousuke: I mangle with some higher order functions and I got lost on what the arity of some composition of them was.
11:27ordnungswidrigChousuke: so this helps me to check that I think correctly
11:27Chousukealso anonymous functions don't have the metadata.
11:27Chousukeanyway
11:27ordnungswidrigChousuke: hmm
11:27Chousukechouser: didn't you have some code that uses reflection to figure out the arity?
11:27ordnungswidrigChousuke: I see
11:28chouseryeah, I didn't write it, but I've posted it
11:28ordnungswidrigchouser: say, I "found" it?
11:28Chousukeis there some factoid for it?
11:30ordnungswidrigIs a (defn foo [r] ((comp a b) r)) equivalent to (def foo (comp a b)) ?
11:31chouserclojurebot: count arities?
11:31clojurebotHuh?
11:31Chousukeordnungswidrig: yes and no.
11:31ordnungswidrigChousuke: besides docs, meta information and such
11:31chouserclojurebot: count arities is<reply>To count arities see http://groups.google.com/group/clojure/msg/fb9930ba2a25d2dd
11:31Chousukeordnungswidrig: then yes
11:31chouserclojurebot: count arities?
11:32chouserdid I kill him?
11:32Chousukeexcept the latter will also accept more than one argument if the composition supports it.
11:32Chousukeclojurebot: ping
11:32Chousukehm.
11:32chouserordnungswidrig: anyway, there's a link to another approach to getting the arities of a fn.
11:33clojurebotTitim gan éirí ort.
11:33clojurebotPONG!
11:33ChousukeIt's alive!
11:33fogus_ordnungswidrig: Even with reflection you're still bound by implementation details.
11:33chouserclojurebot: count arities?
11:33clojurebotNo entiendo
11:34ChousukeI think you needed to add some spaces between the is and the <reply>
11:34Chousuke:P
11:34chouserah
11:34ordnungswidrigfogus_: I know, I just wanted to make sure a higher-order-function-result would accept the number of arguments I tought.
11:34chouserclojurebot: count arities is http://groups.google.com/group/clojure/msg/fb9930ba2a25d2dd
11:34clojurebotRoger.
11:47blackdog`chouser: where is the source of clojurebot?
11:48chouserclojurebot: where are you?
11:48clojurebothttp://github.com/hiredman/clojurebot/tree/master
11:48blackdog`ha :) fantastic
12:02maacljava.util.concurrent Executors expects a Runnable How do I pass it a Clojure function that takes a parameter? it works fine passing a function name but if I pass it a function including a param like (foo "bar") it breaks.
12:04chousertry #(foo "bar")
12:07maaclchouser: thanks :-)
13:49cemerickanyone care to share experiences with swarmiji?
13:50rhickeywhat to call the protocol implementation method map? these can be obtained explicitly, and can be used as mixins. Basically a map of :methodname -> fn
13:51cemerickIt looks like a really pleasant alternative to JMS + couch (our current setup) w.r.t. the programming model, but (unless I'm missing something) a lot of the coordination lands on you, rather than the messaging container.
13:54chouser"method map" isn't too overloaded
13:55technomancyswarmiji struck me as pretty simplistic. you could probably build your own implementation in the time it would take to adapt your app to it.
13:56technomancyit's up to you to ensure that jobs actually finish, etc.
13:56cemerickyeah, that was my point w.r.t. coordination
13:56cemerickglad I'm not totally off the mark
13:56dysingerswarmiji just like ruby nanite is fire and forget
13:57dysingerdoesn't provide for tracking work
13:57technomancyalso the coding style drove me nuts when I was reading through it, but I'm really OCD about that kind of thing.
13:57cemerickI'm not particularly looking to migrate at all -- just making sure I'm not missing opportunities. JMS works like a champ, but isn't super-friendly on the clojure side of things
13:57rhickeychouser: needs to connect to things like (find-protocol-method-map p x)
13:58dysingercemerick: I am working on this problem actively for our needs.
13:59cemerickdysinger: I'm particularly interested in hornetq, and its claims of providing a pure REST api shortly. That would make for a pretty easy way to switch between in-house deployments and something like SQS.
13:59dysingerI think we'll see more and more distributed compute tools around clojure shortly
13:59cemerickI know rhickey has thought some about abstract queue interfaces, but he's busy :-)
13:59dysingerI got managed jvms w/ erlang messaging going last night.
13:59dysingerbut that's not my focus - just playing around.
13:59rhickeyjinterface?
14:00dysingery
14:01dysingererlang starts jvm and monitors it / restarts it if needed. jvm uses erlang messaging via jinterface. jvm clients use jinterface to talk to distributed erlang managed jvms.
14:01dysingerservice is .... repl !
14:01rhickeyI always wanted to fiddle with that
14:01dysingerI love that you don't have to classify services - the service is repl.
14:07cemerickjinterface is tantalizing, but I've no interest in getting into erlang at all (hands are plenty full otherwise). It's a thought for the future though, esp. since we're using couch anyway.
14:55rhickeyprotocols are up! http://github.com/richhickey/clojure/commit/766b248f7d097c2c62e809ef6de2e6afd3850fc9
14:55rhickeyfeedback welcome
14:58chouserwhee!
15:00headiusdysinger: SuperTaz on #jruby wants to talk about your job req
15:14tomojis contains? O(log_32 n) for sets?
15:15Chousukehm.
15:15Chousuke(doc contains?)
15:15clojurebot"([coll key]); Returns true if key is present in the given collection, otherwise returns false. Note that for numerically indexed collections like vectors and Java arrays, this tests if the numeric key is within the range of indexes. 'contains?' operates constant or logarithmic time; it will not perform a linear search for a value. See also 'some'."
15:15Chousukeso, probably :P
15:16chousertomoj: log32 for hash-sets, log2 for sorted sets. I think.
15:17ordnungswidrigwhy doesnt this work: (#({:a %}) :foo) whereas ((fn [x] { :a x }) :foo) does?
15:17chouser#(x) is (fn [] (x)) not (fn [] x)
15:18ordnungswidrigchouser: uh
15:18chousernot enough? :-)
15:18ordnungswidrigchouser: ah
15:18the-kennyWhat's the purpose of defprotocol? I see all these nice commits, but there are no use-cases and such things... That's what I'm missing
15:18ordnungswidrigchouser: how would I then generate a map?
15:19Chousukethe-kenny: They're for interfaces.
15:19chouserordnungswidrig: #(hash-map :a %) or (fn [x] {:a x})
15:19Chousukethe-kenny: only, they're more powerful than java interfaces :)
15:19ordnungswidrigchouser: I see
15:20Chousukethe-kenny: but I think having a "native" construct for specifying interfaces is valuable. Reduces dependency on java.
15:20ChousukeI mean, even if defprotocol had no other use.
15:20Chousukewhich it likely does :P
15:21ordnungswidrigChousuke: does have or does not?!
15:21Chousukedoes have
15:22ordnungswidrigChousuke: for example?
15:23chouserordnungswidrig: you've seen the assembla page?
15:24ordnungswidrigchouser: nope
15:25chouserordnungswidrig: http://www.assembla.com/wiki/show/clojure/Protocols
15:26ordnungswidrigchouser: fun stuff
15:30chouserrhickey: does reify not accept a list of interfaces?
15:31chouseroh, nm, arg order changed
15:32rhickeysorry about that, yes, since no longer 'new', name can go first
15:33chouseryep, np.
15:33chouserthanks for the comment in Compiler.java. :-)
15:35hiredman"just realized that the current system I have is fatally flawed"
15:35hiredmanpoor fnparse :(
15:36rhickeyreify docs here: http://www.assembla.com/wiki/show/clojure/Datatypes
15:45chousercould reify be faster than the old newnew?
15:47chouserit appears to be.
15:49ordnungswidrigis there a idiom for (if (fn? a) (a) a)
15:50hiredmantrampoline
15:50hiredmanmaybe?
15:51ordnungswidriga is either a function or a value
15:51hiredman,(trampoline (fn [] :a))
15:51clojurebot:a
15:51hiredman,(trampoline :a)
15:51clojurebotjava.lang.IllegalArgumentException: Wrong number of args passed to keyword: :a
15:51hiredman:(
15:51hiredman,(trampoline identity (fn [] :a))
15:51clojurebot:a
15:51hiredman,(trampoline identity :a)
15:51clojurebot:a
15:51hiredman:D
15:52tomoj,(trampoline identity (fn [] (fn [] :b)))
15:52clojurebot:b
15:52hiredmanyeah, well, …
15:52ordnungswidrighiredman: now with (fn [x] :b)
15:53ordnungswidrighiredman: doesnt look more idiomatic then (if (fn? a) (a) a) to me
15:53tomoj(if (fn? a) (a) a) seems perfectly fine to me
15:53tomojcouldn't imagine a clearer way to write it
15:53ordnungswidrigtomoj: so im my case it'd be (fn [a x] (if (fn? a) (a x) a))
15:53ordnungswidrigtomoj: looks good
15:54tomojexcept, hmm
15:54tomoj,(fn? :a)
15:54clojurebotfalse
15:54tomoj,(fn? {})
15:54clojurebotfalse
15:55tomojdunno if you want those
15:55ordnungswidrig,(ifn? {})
15:55clojurebottrue
15:55ordnungswidrig,(ifn? :a)
15:55clojurebottrue
15:55tomojaha
15:55ordnungswidrigtomoj: but sure :-)
15:55tomojguess fn? is better anyway, otherwise you wont be able to pass keywords, maps, etc as values
15:57ordnungswidrigtomoj: oh. I didn't think of this. This explains a weird error I'm chasing for days... *doh*
15:58hiredmanhttp://gwolf.org/blog/piespy-modelling-irc-interactions <-- I smell a new clojurebot feature
15:58tomojif I use nailgun can I use clojure as a scripting language? like, executable .clj files? that sounds nice..
15:58ordnungswidrigtomoj: btw, you're from austin?
15:58tomojordnungswidrig: yup
15:59hiredman#! is setup as a comment just for that purpose
15:59ordnungswidrigtomoj: how is car2go going? I'm from Ulm and I worked as a contractor for Daimler/TSS in Ulm who built the *um* fine peace of software for that :)
16:00tomojordnungswidrig: never heard of it till now
16:00tomojbut hmm.. I don't have a car, and I've always wanted a smart car
16:01ordnungswidrigtomoj: oh man, they failed on marketing this one
16:01ordnungswidrigtomoj: you don't want a smart :) At last not the ones they provide in Ulm. But the concept is great!
16:02tomojtrying to discover whether there are any locations near campus, and failing
16:03ordnungswidrigtomoj: unless you are a registered driver they do not provide many information. Usability could be done better on the website.
16:04ordnungswidrigtomoj: there is no map on the website?
16:05tomojcouldn't find one, anyway
16:05tomojmaybe I'm just dumb
16:05tomojoh, now I found it :)
16:05ordnungswidrigtomoj: then you're smarter than me!
16:06chouserah, nm -- I was misreading my notes. reify is the same speed as old new new
16:06tomojlooks like they're all downtown, far enough away that I'd have to ride the bus to get to them :(
16:08ordnungswidrigtomoj: in ulm the area is ok. in fact ulm is like twin town, neu-ulm on the other side of the river. and at first neu-ulm was out of area.
16:51hiredmanclojurebot: latex \sum_{n=1}^\infty 2^{-n}
16:57cemerickhiredman: that's sick :-D
16:58mikehogyeis there a way to get clojure.main to run a script from a file that is not on the classpath?
16:58mikehogye"java -cp clojure.jar -h" indicates that "path" can be a file or resource
16:58rhickeyso, who's tried protocols?
16:59chouserrhickey: started. got distracted. :-/
16:59mikehogyebut I keep getting "Could not locate blah__init.class or blah.clj on classpath"
16:59rhickeyI'm finding their dynamic nature to be a lot of fun
17:00cemerickI'm always ~5 days behind :-P
17:01rhickeywhen backed with :on interface, speed as good as using the interface directly, so not really a tradeoff to write to protocols
17:01mikehogyehmm ... apparently I'm doing something else dumb -- a simple test case works fine
17:01rhickeyand their dynamic lookup much much faster than multimethods
17:02cemerickrhickey: I actually just thought of a use case, so maybe I'll be of some use after all.
17:02rhickeycemerick: cool
17:03cemerickrhickey: BTW, are you planning on having good and proper name support in deftype, etc., by the time new is merged into master?
17:03rhickeycemerick: good and proper?
17:03cemerickdashed-name, etc
17:04rhickeyI've been thinking about that, I'd hare for people to be marrying the munging algorithm on the Java side, but there might not be a Java side...
17:04Chousukehiredman: what's with the near-illegible colour though? :/
17:04rhickeyI'd hate for
17:04cemerickit's obviously window-dressing, but it's just odd to see camelCased keywords
17:05hiredmanChousuke: it's fixed
17:05hiredmanthat was just the color in the example I was following
17:05cemerickrhickey: I'd say, if you're using non-Java names, that a decision you need to live with the consequences of
17:05cemericknothing stopping people from using Java names if interop is a priority for them.
17:06rhickeycemerick: but then I need to document and fix the munging scheme
17:06rhickeyso far there are no human consumers of the munging, so it can be quite verbose and ugly
17:06cemerickrhickey: well, that's a cost that only you can evaluate at this point. I don't know that you need to make it pretty, though.
17:07cemericke.g. if you're putting dashed-names etc. in your deftype slots, I wouldn't expect them to be usable from Java at all anyway
17:07rhickeywhat if it was limited to dash-becomes_underscore?
17:07mikehogyenever mind; found my problem
17:08cemerickas opposed to supporting all of the naming possibilities like embedded:colons, etc?
17:08rhickeyyeah
17:09cemerickI think that's a fine compromise. Long term, though, I'd assume you'd like to keep allowable names, etc., totally independent of host restrictions. i.e. if you need to have a host-friendly name, stick to underscores, or target one host explicitly.
17:10Chousukemaybe an option somewhere to specify a "host name"? :/
17:10rhickeywhat's the url syntax for line#s in github source view?
17:10chouseryou can click on a line
17:10chouserI think it's #L012
17:10rhickeyhttp://github.com/richhickey/clojure/blob/master/src/jvm/clojure/lang/Compiler.java#L2487
17:11cemerickI'm guessing the biggest difficulty will be encountered by anyone creating macros and such on top of deftype/defclass.
17:11cemerickrhickey: oh, see, I think that's totally sane as-is
17:11ChousukeI suppose it would complicate things much if the thing has two names, one on the clojure side and another on the host side.
17:12_ato think most people are used to that munging from stack traces
17:12cemericki.e. no need to clean it up AFAIC
17:13cemerickChousuke: I think something like that will be necessary eventually. Who knows what'll happen when the objc host backend is built? :-P
17:15drewryou can click on the line number in the margin too
17:19_atohttp://kenai.com/projects/jruby/pages/CompilerNameMangling
17:19_atothye have less cases though
17:22raekso, if I want to try protocols, where should I begin?
17:22raekor rather, what kind of stuff can I use it for?
17:37headiusrhickey: it would be nice if we could start to agree on mangling conventions
17:37headiusI've brought this up with scala guys, but they apparently don't have any standard even now
17:38hoeck1raek: I would start with reading http://www.assembla.com/wiki/show/clojure/Protocols
17:39hoeck1raek: in fact, I did, but its too late here right now, so I'm going to try them out tomorrow
17:45tomojwhat is this ":on barMethod" thing?
17:45tomojseems unexplained
17:46hiredmanuh
17:46hiredmanits :on AnInterface isn't it?
17:46hiredmanyou can implement a protocol on an interface
17:46hiredmanwell
17:46hiredmandefine, not implement
17:47krumholt_ I read the article about protocols . can someone explain to me in 1 or 2 sentences what kind of problem protocols address?
17:47tomojthere is also a ":on barMethod" in the example
17:48chouserrhickey: deftype implements a interface but not a protocol, right?
17:49hiredmankrumholt_: you can name a set of opertions on some thing
17:49hiredmana protocol for dealing with something
17:49_atokrumholt_: basically it's like multimethods dispatched on type, but multiple methods can be grouped together under the one name and it's performs much faster
17:50Chousukekrumholt_: consider the Clojure Seq abstraction.
17:50krumholt_so it's a nicer way to express common multimethod usecase
17:50Chousukekrumholt_: As far as I understand this stuff, that will become a protocol
17:50_atokrumholt_: sort of like a more dynamic version of javas interfaces
17:51krumholt_ok thanks everyone. i think i get the idea
17:51hiredmanwell, a protocol is a set of ops, and a multimethod is a single op
17:52Chousukejust to add to the mix, the design document also mentions multiprotocols :P
17:53hiredmanI'm not too clear on extending protocols
17:53_atotomoj: maybe :on barMethod lets you alias a java interface method to a clojure function name or something
17:54hiredmanbut I guess you just make a new protocol with the same set of ops?
17:54chouser_ato: I think that's right
17:56_ato"By default, methods of the protocol map to methods of the same name in the interface. A different mapping can be provided on a per-method basis using :on inside the signature."
17:56_ato^ from the defprotocol docstring
17:56hiredmanhmmm
18:01drewrare there any pastes with a good protocol eg?
18:05chouserno return types on protocol methods?
18:06chouserno protocols on protocols?
18:07chouserI must not be thinking about this correctly.
18:07chouseroh -- no types on any of the args?
18:08_atochouser: what would a protocol on a protocol do?
18:09chouserwell -- maybe "on" is the wrong word. If something is a Car it will provide all the methods that a Vehicle does, plus some Car-specific ones.
18:10the-kennyhm... I think clojure-mode ignores (setq indent-tab-mode nil), strange.
18:10chouserSo am I not supposed to capture that when I defprotocol, but just hope/assume that anything extending Car will also extend Vehicle?
18:11Chousukechouser: I don't think you're supposed to have protocols for Cars and Vehicles :/
18:11ChousukeI mean, they should be split so that you could implement both with no overlap.
18:12chouserwhere does the "start" method go? One or the other? both?
18:12chouserbah. gotta go.
18:13hiredmanif there is any question, it goes on the more specific
18:13hiredmanor Vehicles->StartableVehicles->Cars
18:14ChousukeMovingthings - Motorised things - Wheely things
18:14_atoyeah, it's not inheritance
18:15_atoit's a "protocol"
18:15_atoeg you could start things that aren't vehicles
18:15technomancythe-kenny: it's not that clojure-mode ignores it; it's just that it becomes buffer-local when you set it
18:15_mstI remember looking at how Compojure implemented multiple backends for sessions (file, memory, database, ...) and thinking it could use something a bit like this
18:16technomancythe-kenny: (set-default 'indent-tabs-mode nil)
18:16_mstnot really inheritence, just a way of expressing the required interface in code and making it possible/easy to provide custom implementations
18:16the-kennytechnomancy: Oh, ok. I wasn't aware of that.
18:17_atoif I'm "getting it" right the idea is composition is better than extension
18:17hiredmanwell, you can implement protocols on interfaces which are heritable
18:17_atohiredman: right, but I think that's only to support java interop
18:18_atoyou're not supposed to use that to "get" inheritance
18:18hiredmaninterface inheritence is ok, implementation inheritence is bad
18:18the-kennytechnomancy: hm.. that doesn't work.
18:19technomancyit might only take effect for new buffers?
18:19the-kennyI just restarted emacs
18:20_atoI think the key is to think of it more like duck-typing... who cares whether something is a car or a vehicle as long as it's "startable"
18:20hiredmanif you look at the java side of clojure the tree is deep interfaces, shallow implementation sharing
18:21hiredmanso you have a long chain of interfaces, and at the end maybe one abstract class with some common code and then a single concrete class
18:22_ato"#
18:22_ato *
18:23_ato# While avoiding some of the drawbacks implementing an interface creates an instanceof type relationship and hierarchy"
18:23hiredman*shrug*
18:24_atoI dunno maybe we just wait for Rich to give a talk on it and clear up what is good and proper :p
18:24hiredmanI am not using clojure's code base as argument from authority, but as an example of what I think works well
18:25hiredman_ato: the fact remains, interfaces are heritable, and you can implement protocols :on interfaces
18:25hiredmanbah
18:25hiredmans/implement/define/
18:27_atoyeah, I'm not necessarily disagreeing with you, just that's my interpretation of why Rich has apparently made protocols themselves not heritable
18:28hiredman~latex sum \limits_{k=1}^N k^2
18:28hiredman:(
18:29hiredman~latex \sum \limits_{k=1}^N k^2
18:30the-kennyGoogle Charts can do LaTeX? Wow
18:30hiredman_ato: I think inheritence matters less in clojure because clojure is dynamic and has first class functions
18:31hiredmanso using inheritence for types is nixed, and you can mix in implementations via functions
18:32krumholt_when do i need :use and :import in the ns macro? is it correct that use is for clojure code and import for java code?
18:32hiredmanyes
18:32krumholt_ok thanks
18:33hiredmanhttp://github.com/hiredman/clojurebot/blob/master/hiredman/clojurebot/latex.clj#L1
18:34qedCould someone step me through something?
18:34qedI know that lazy-cons isn't the way to do this anymore, but:
18:34qed(def triangles (lazy-cons 0 (map + triangles (iterate inc 1))))
18:36hiredmanI, uh, well using lazy-cons there would be silly even if it still existed
18:36hiredmanyou may as well (def triangles (cons (map + triangles (iterate inc 1))))
18:36hiredmaner
18:37hiredman(def triangles (cons 0 (map + triangles (iterate inc 1))))
18:37qedthat's chouser's code
18:37hiredman:(
18:37qedhiredman: could you explain to me how you might write that with lazy-cat?
18:37qedor a completely different problem, i just dont see how it works
18:38hiredmanlazy-cat?
18:38qednod
18:38hiredman(lazy-cat [0] (map ...))
18:39hiredmanlazy-cat just concats sequences
18:39qedps your code didn't work
18:39_ato(lazy-cat xs ys zs) === (concat (lazy-seq xs) (lazy-seq ys) (lazy-seq zs))
18:39hiredmanso you give it sequences
18:39qedhiredman: but you can use it to create an infinite seq right?
18:39hiredmanno
18:39_atoqed: maybe you want lazy-seq
18:39hiredmannot lazy-cat
18:39hiredmanqed: what do you mean didn't work?
18:40qed(def triangles (cons (map + triangles (iterate inc 1)))) blows up
18:40hiredmanqed: please notice the correction I pasted right after
18:40qedoh d'oh, sorry
18:41_atohiredman: that doesn't work either as triangles is unbound in the right-hand side
18:41_atothat's probably why chouser used lazy-cons
18:41qedlazy-seq is the new lazy-cons, right?
18:41hiredmanno
18:42qedwhere did lazy-cons go?
18:42_ato(def triangles (lazy-seq (cons 0 (map + triangles (iterate inc 1)))))
18:42_atohttp://clojure.org/lazy
18:42qedthanks _ato
18:43_mstalso worth noting that that version necessarily hangs on to the head of the seq...
18:44qed(next triangles)
18:44qedoops
18:44technomancynil
18:45qedtechnomancy: :)
18:45qed_ato: could you step me through what's happening in your function?
18:46hiredman(it's not a function)
18:46qedim aware, but surely you understand what im sasking
18:46qedasking*
18:46somniumis there any need to use lazy-seq with map?
18:46_atoqed: lazy-seq is a macro that doesn't execute it's body until first/rest is called on it
18:47_atosomnium: in this case yes, because triangles (as the map argument) doesn't exist yet
18:48_ato,(do (lazy-seq (println "hi")) nil)
18:48clojurebotnil
18:48_ato,(do (first (lazy-seq (println "hi"))) nil)
18:48clojurebothi
18:49hiredmanwithout looking at the code, I think you should collapse it into a call to interate
18:49hiredmaniterate
18:49hiredman(iterate some-function 0) can surely get you the same result
18:50_mstmaybe (iterate some-function [0 1]) since you need to track two pieces of state
18:50hiredman_mst: are you sure?
18:51_mstnope :)
18:51hiredmanthere are two sequences in the map, sure
18:51_mstbut I have it in my head you need to track a running integer (from 1) and the last triangle number you saw
18:52_mstfirst attempt: (map first (iterate (fn [[t i]] [(+ t i) (inc i)]) [0 1]))
18:52_ato,(take 10 (map #(/ (* % (inc %)) 2) (iterate inc 0)))
18:52clojurebot(0 1 3 6 10 15 21 28 36 45)
18:52_msttricky :)
18:53qednice :)
18:53_atohttp://en.wikipedia.org/wiki/Triangular_number :-P
18:53hiredman(list (- (* n n) (* m m)) (* 2 m n) (+ (* n n) (* m m))
18:53hiredmanI just don't remember what m and n are supposed to be
18:54somniumthat one is pleasingly symmetrical somehow
18:54hiredmanclojurebot: latex \frac{-1\pm\sqrt{8x+1}}{2}
18:57hiredmanhttp://en.wikipedia.org/wiki/Pythagorean_triple
18:58hiredmanit occurs to me I might confused as to which euler this is
19:01qed#12
19:02qed1 + 2 + 3 + 4 = 10, 10 is div by 1 2 5 and 10
19:03qedwhich triangle number has 500 divisors
19:03qederr > 500 div
19:04qedI started with (defn gen-tri-num [n] (reduce + (range 1 (+ n 1))))
19:05qedthen i was going to calc the number of divisors for each tri-num i generated
19:05qedthat's where i got stuck -- not sure the best way to do that
19:07hiredmanhttp://gist.github.com/232449 one of the more amusing bits from my eulering
19:07hiredmanI don't recall what made me call it totally useless
19:09qedmaybe that it's incredibly useful?
19:10hiredmanreverse psychology?
19:10tomojI never got that one
19:11tomojtook way too long
19:11qedreverse psychology is even less rigorous than forward psychology
19:12hiredmanclojurebot: reverse psychology is even less rigorous than forward psychology
19:12clojurebotIn Ordnung
19:12qed:)
19:12qedclojurebot: reverse psychology
19:12clojurebotreverse psychology is even less rigorous than forward psychology
19:23tomojdamn your divisor function is SO much faster than mine
19:26qedugh i just signed an NDA
19:26qedi kick myself everytime i do that
20:36hiredmanclojurebot: hydra?
20:36clojurebotExcuse me?
20:41penthiefI've just done clojure-install from emacs, and it worked, but after restarting I get 'symbol's value as variable is void "package-activated-list"' when I type M-x slime
21:24chouserrhickey: so I'm trying to redo finger trees with protocols
21:25chouserI implement a lot of clojure interfaces
21:25chouserdoes that mean (until clojure's interfaces are themselves protocols) that I need to create one protocol per interface
21:30chouserand instead of a reify on a couple interfaces, I need to extend a huge list of uninheriting protocols.
21:32hiredmanI gtalk's sms gateway and appengine's xmpp support could get me a repl of sorts on my phone
21:33hiredmanI think
21:33tomojgood luck typing sexp's on your phone
21:33hiredman:P
21:34hiredmanI'm trying to think of something I can do with that
21:35tomojhmm.. if you take paredit and navigation operations and separate them from self-insert stuff, I wonder how many operations you wind up with
21:37rhickeychouser: can you give me an example?
21:38rhickeyI think while Clojure's abstractions are interfaces you can just implement them (in e.g. deftypes)
21:38rhickeyif you introduce your own abstractions, you can do so with protocols
21:39rhickeyno need to wrap Clojure's interfaces with protocols before Clojure does
21:39rhickeybut what do you mean by uninheriting?
21:40hiredmanprotocols don't inherit
21:40hiredmanI think, is what he means
21:45djorkwhat is ->> and why is penumbra using it ?
21:45hiredman->> is newish
21:45djorkhmm
21:45djorkok
21:45hiredmanlike -> but the other side
21:45djorklike, the last few weeks?
21:45hiredman,(doc ->>)
21:45clojurebot"([x form] [x form & more]); Threads the expr through the forms. Inserts x as the last 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 last item in second form, etc."
21:46hiredmandjork: more like months I think
22:02chouserOk, so I can use deftype to implement existing interfaces, and then extend it with my own protocols
22:02dreishIs there any good documentation for ns yet?
22:03djorkhmm, I want to believe in penumbra :)
22:03hiredman(doc ns) seems to have all the bits
22:03clojurebot"([name & references]); Sets *ns* to the namespace named by name (unevaluated), creating it if needed. references can be zero or more of: (:refer-clojure ...) (:require ...) (:use ...) (:import ...) (:load ...) (:gen-class) with the syntax of refer-clojure/require/use/import/load/gen-class respectively, except the arguments are unevaluated and need not be quoted. (:gen-class ...), when supplied, defaults to :name correspo
22:03dreishSeriously? That's not even close to complete.
22:04hiredmandreish: what do you mean?
22:04tomojhehe
22:04hiredman(doc use)
22:04tomojall the bits are there, they're just scattered about and difficult (for me) to understand
22:04clojurebot"([& args]); Like 'require, but also refers to each lib's namespace using clojure.core/refer. Use :use in the ns macro in preference to calling this directly. 'use accepts additional options in libspecs: :exclude, :only, :rename. The arguments and semantics for :exclude, :only, and :rename are the same as those documented for clojure.core/refer."
22:04djorkseems clear to me
22:04tomojwould be nice to have some examples of all the different ways to use all the subforms
22:04dreishWhat tomoj said. Which I guess isn't the same as being undocumented.
22:05tomojsomeone had suggested before setting up examples of all the core functions
22:05tomojwonder if anything came of that
22:05dreishI find myself using ns mainly by guess-and-fix because the docs are just a tangle of spaghetti.
22:05djorkI think the docs just need a bit more hyperlinking.
22:05tomojyes, guess-and-fix indeed :)
22:06djorkI actually found it pretty helpful to just sit down and read the docs from the beginning. It's better than most languages.
22:07dreishYeah, I generally don't work that way once I'm past the basics.
22:07djorkmaybe it's time for clojure.contrib.examples :)
22:07djorkor cheat
22:08dreishOr just a thorough, third-party reference to the language.
22:08djorkhttp://cheat.errtheblog.com/
22:08djorkdreish: have you tried this yet? http://jnb.ociweb.com/jnb/jnbMar2009.html
22:08djorkit's very good
22:09dreishdjork: Thanks for the reminder. I've seen that, but forgot about it.
22:09djorkhow about cheat sheets for different areas of clojure
22:09dreishI vaguely remember some inaccuracies, I think, but that could have been a long time ago, or a different document.
22:10dreishDoesn't seem to cover ns, though.
22:11dreishWhat I'm wondering, specifically, is whether there's a way to include several libs at the top dot level without saying :use over and over.
22:12dreishI.e., to replace (:use [util]) (:use [server-lib]) (:use [clojure.contrib.def]), which seems pretty gross to me.
22:12djorkwhat would you want to shorten, for example...
22:12tomoj(:use util server-lib clojure.contrib.def) doesn't work?
22:12dreishI don't think so. I thought it complained about no such thing as util.server-lib.
22:12tomojsingle-segment names are bad, I think
22:13dreishThanks, mom.
22:13dreish:-P
22:13djorksingle-segment names aren't just bad... they don't work in some cases (I believe)
22:14nforrestI've read that in clojure, list element access is O(n) and prepending to a list is O(1). I understand how that works (it's a linked list). However, I've also heard that vector element access is O(1) and appending to a vector is also O(1). What sort of data structure allows you to achieve that kind of performance?
22:14djorkdresh, consult (doc require)
22:14djorkit's big
22:14dreishI'm not into languages that tell me to sit up straight. Clojure hasn't seemed much like that to me so far.
22:14tomojI'm imagining a webapp that automatically indexes all the interns in clojure.* and clojure.contrib.* and lets people submit examples, maybe with vote up/down
22:15djorknice idea
22:15tomojwhy are single-segment names bad, again? I forget
22:16arohner_nforrest: it's not technically O(1), it's O(log sub 32)
22:16tomojman "clojure" is so difficult to make punny names with :(
22:16nforrestOh, I see.
22:16tomojlog_32 is practically constant, though
22:16nforrestThat seems much more possible.
22:16nforrestThanks.
22:16arohner_there are some blog posts somewhere about the clojure datastructures
22:17dreishtomoj: Apparently (:use util server-lib clojure.contrib.def) does work. I must have had an extra pair of something when I tried that. Thanks.
22:17djorkwhat, clojure makes for awesome puns :)
22:17tomojand then you can do like
22:17djorkmy toy mud is called "dunjeon"
22:17tomoj(:use [util :only (foo)] server-lib ...)
22:17tomojhmm, yeah, hadn't thought about that kind of pun yet
22:18tomojneed to find a phonetic dictionary to search through for zh and soft g
22:18djorkyeah just throw some j replacements in there and you're done
22:19tomoj:)
22:23qedwhat is a 'coll' in clojure?
22:23qedlike any form of a list? can a seq be a coll?
22:24qedis a seq a coll?
22:24tomojI think 'coll' means any x for which (sequential? x) is true
22:25rhickey_,(coll? (seq [1 2 3]))
22:25clojurebottrue
22:25qedthanks rich, tomoj
22:25tomojoh, hmm
22:26tomojcount's parameter is called "coll" in the docs but it works on non-persistent collections too
22:26qedrhickey_: is that the same rationale behind forcing the programmer to create (seq "abcd") before cons'ing on it?
22:26qedonto*
22:26qedlike (cons 1 (seq "abcd"))
22:26tomojoh, {} is not sequential
22:26tomojbut it is a coll
22:27tomojwhat's the interface for seqables?
22:27tomojand, is there a predicate for that?
22:27rhickey_Seqable
22:28tomojI always thought sequential? checked for seqability
22:39djorkmaybe this falls under "premature optimization" but I am wondering about the performance implications of frequently calling conj or assoc on large vectors or maps
22:40chouserdjork: it is premature. when you find you need it, look at transients
22:40djorkthose are new, aren't they?
22:41chousernewish
22:49djorkwow the JVM exhibits a really wild range of performance
22:49djork79 ms, 30 ms, 2.6 ms
22:49djorknot a cached lazy seq or anything
22:50djorkstarting from scratch with a ref of a vec of 100K strings
22:50chouserdeftype can't implement a protocol, right?
22:54rhickey_chouser: nope
22:55rhickey_I've thought about supporting extends there, since why should interfaces get preference?
22:56rhickey_but it could get confusing, the difference between Java-like methods and real fns
22:56chouserso confused already
22:56rhickey_oh no!
22:56chouserI'm starting from http://tinyurl.com/ylx4j3k/finger_tree.clj#LID18
22:56rhickey_what's confusing?
22:56chousera pile of interfaces
22:57chouserthat starting point uses interfaces in a couple different ways, and I think converting to protocol/deftype is forcing me to tease apart the reasons.
22:59chouserSome of those interfaces, like IDigit mearly aggregate other interfaces. No way to do that with protocols, right?
22:59djorkwow, clojure is a better Java :)
22:59rhickey_not so far, but doing that doesn't really save you much in the implementing
22:59chouserright
22:59chouserjust a few words.
23:00chousertake none of this as criticism -- I don't understand well enough to complain yet.
23:00rhickey_and you can put multiple protocols in a single extend
23:00chouser:-)
23:00chouserright
23:00chouserok, setting that aside.
23:02chouserIDoubleSeq does that but also adds a couple methods. So I should replace that with a defprotocol that leaves out the interfaces and just defines the two methods.
23:02rhickey_right, the real reason for aggregating protocols is to combine multiple dependent contracts, but that has some implementation issues
23:02rhickey_yes, best to think of the Clojure interfaces as interop, and your new abstractions with protocols
23:03chouserok, so I think I'm ok on through IDeepTree. That extends IPersistentCollection for interop and defines three methods that are just accessors to data fields.
23:03rhickey_it will be really nice when you can interop with the Clojure abstractions through protocols
23:04chouseryes!
23:04chouserbut I should understand this anyway.
23:04chouserI might have to explain it to someone.
23:04chouserin Chapter 10.
23:04chouserok, because there are new data items, that will call for deftype
23:06chouserI can use deftype's IPersistentMap auto-impl to access them, so I don't need hand-written accessor methods for IDeepTree
23:06rhickey_right, most of your factory fns on newnew can become deftypes with factory fns
23:07chouserBut I need to support IPersistentCollection, and since that's an interface not a protocol, those methods have to be defined inside the deftype
23:08rhickey_right, but some of your new stuff can share impls, like measureFns/More/Pop betwen empty/single
23:08rhickey_mixins are really easy with protocols
23:08rhickey_and clean, no incidental hierarchy
23:09chouserjust merge maps as needed, right?
23:09rhickey_yeah
23:09rhickey_extend is an ordinary fn
23:09rhickey_and the method maps just kw->fn
23:10chouserok, but I'll have some DeepTree methods that must be in deftype (for IPersistentCollection) and others in extend for my own protocol stuff.
23:10rhickey_you can reuse an impl wholesale, just (extend type proto map)
23:10rhickey_yes, having methods not 'in' will be commonplace with protocols
23:11rhickey_but at least will be sets, vs independent multimethods
23:12chouserit just seems odd that some methods must be in deftype while others can't be.
23:12rhickey_in a pure Clojure design the deftypes might have no methods at all
23:12chouserright, that makes sense to me.
23:12hiredmanexcellent
23:12rhickey_so, the methods there are just interop
23:12chouserI guess it's the interop nature that's forcing some of the methods into deftype.
23:13rhickey_one problem is the use of the word method, since they are methods in very different senses, and the Java ones are not first-class
23:13chouserthe methods in extend will be able to use the deftype :kw accessors, and call the deftype methods
23:13rhickey_maybe we should use another term for protocol fns
23:14rhickey_chouser: kw accessors yes, methods will need (.foo x)
23:14hiredmanoperations
23:14rhickey_although that's the case inside deftype too, no real class scope for methods
23:14rhickey_hiredman: maybe
23:15chouserthe methods in deftype will be able to call any protocol methods via the defprotocol-created functions
23:15chouserand of course access their own fields.
23:15rhickey_chouser: sure
23:15chouserok.
23:15chouserthanks for walking me through that. I think I'm back on top of it again.
23:15rhickey_but the point of making (:kw x) as fast as dot was so that protocol methods are not at a disadvantage
23:16rhickey_chouser: cool
23:16chouserit reminds me so much of math -- makes sense until you try to do the homework.
23:17rhickey_hah
23:17chouseronce you can do it on your own *then* you know you've got.
23:17chousergot it.
23:17rhickey_well, converting something is hard too, since you've already got one mental model
23:18rhickey_on a green field design deftype + protocols should be sweet
23:18chouserand the interop here is perhaps deeper than will be common
23:19chouserwill I have a problem getting the default IPersistentMap methods in my deftype that also implements custom IPersistentCollection methods?
23:19rhickey_it will be straightforward to make protocols that correspond to (and are :on) the existing interfaces
23:19rhickey_chouser: yes
23:20rhickey_there isn't a way to pick and choose bits of the impl, as it can be difficult to determine what will work together
23:20rhickey_so, either I do it or you do
23:20rhickey_but not some of each
23:21rhickey_but you've already done it
23:21rhickey_just add some dots
23:23rhickey_gotta crash - good luck!
23:23chouserso my deftype for IDeepTree needs to include accessor methods
23:23chouserlike I have now
23:24rhickey_if you don't take the IPersistentMap impl, you'll still get keyword accessors
23:24chouserwell, I
23:25chouserwell, I'll let you sleep. I probably won't get that far tonight anyway.
23:25chouserthanks again.
23:25rhickey_tomorrow then...
23:26tomojthis deftype/protocol stuff is still a total mystery to me
23:26hiredmanso :on is something of a red herring
23:28chouserwell, it allows you to bridge existing interfaces into the defprotocol/extend system
23:28chouserbut yeah, I guess it's an interop feature on an other native construct.
23:28hiredmansure, but it sounds like the idea is that for existing interfaces you will just use deftype directly
23:31chouseroh, I see what you're saying
23:32chouserinstead of putting some methods into the deftype I ought to be able to make a bridge protocol for IPersistentCollection and implement them with 'extend' like all my other methods.
23:33chouserexcept
23:33chouserno, that should be right.
23:40chouserexcept not in this case, because the whole point is to let people do (count my-finger-tree), but 'count' is not yet a protocol method -- it wants to call .count on an actual IPersistentCollection object, so having my own kind of thing that uses defprotocol/extend won't help.
23:40chouserit needs to be an actual intance of a Java class that extends IPersistentCollection, so I need to have those methods in the deftype.
23:47hiredmanI haven't looked at my reader in a few weeks, maybe I should update it
23:53tomojwhat's a good way to make your code configurable?
23:53tomojwithout making people need to wrap everything in a binding
23:54hiredmanpass an argument
23:54tomojah, yes
23:54tomojhmm
23:55tomojI guess that would mean I'd have to wrap all my tests inside a macro or something
23:55hiredmanusually the first thing I do with a binding heavy api is start wrapping stuff in (defn foo [some-resource args] (binding [*resource* some-resource] ...))
23:55tomojor pass the same parameter over and over again
23:56tomojI'm working on htmlunit tests with clojure.test and want to set a global root-url