#clojure logs

2011-02-16

00:00ihodesand you make sure all arithmetic is mod N
00:00simardcool
00:01simardI might try that tomorrow... after sleeping a lot
00:01ihodeshaha it's pretty fun in clojure. i'm going to push to github a simple rsa-clj libe soon, i think.
00:02simardnice
00:02simardfun and efficient ?
00:02ihodesyep, else it wouln't work for RSA using large enough primes. you're looking at numbers with 200 digits or more
00:03ihodesthought we'll see if i get to all the necessary speed-ups.
00:03simardhow do you enforce modulo N for all your arithmetic ?
00:03simardmanually ?
00:04amalloysimard: mod n after every iteration
00:04simardright, manually
00:05brehautshould be easy enough to define a macro that takes a list of math operators and defs a bunch of inline functions that do that
00:06amalloybrehaut: it occurs to me: suppose we had some number of operations we wanted to perform in mod-N arithmetic. this seems like the sort of thing you could do with a monad
00:06amalloychain together a bunch of operations with a reduce-to-base-N thingy
00:08brehautyeah you could
00:08brehautbut you wouldnt do it that way if you want it fast ;)
00:12pdk(doc println)
00:12clojurebot"([& more]); Same as print followed by (newline)"
00:12pdk(doc print)
00:12clojurebot"([& more]); Prints the object(s) to the output stream that is the current value of *out*. print and println produce output for human consumption."
00:12pdk,(println 1 2 3)
00:12clojurebot1 2 3
00:12pdknever knew it padded with spaces before
00:12amalloy&(prn 1 2 3)
00:12sexpbot⟹ 1 2 3 nil
00:13amalloy&(pr-str 1 2 3)
00:13sexpbot⟹ "1 2 3"
00:13amalloyhm. i thought it didn't always
00:16brehautamalloy: (defn mod-n-m [n] (monad [m-result (fn [x] (mod x n)) m-bind (fn [v f] (mod (f v) n))]))
00:16brehautthen you can do (def mod-2-m (mod-n-m 2))
00:17brehaut(domonad mod-2-m [a (m-result 1) b (inc a)] b)
00:17brehautand it does what you want
00:18brehautthe haskell nerd in me suggests that you would be better off with an applicative functor though
00:18amalloybrehaut: mrrrg. bind and result always confuse me. i don't see why you need two mod operators - can't m-result just be identity?
00:18amalloysince bind is doing the mod, that is
00:18brehautamalloy: im not sharp enough on the math to say for sure
00:19cdddrWhy does ({} key default) work, whereas ([] index default) doesn't? Especially since once can pass a default to nth?
00:20brehautis (mod (some-op? (mod x n)) n) always equivalent to (mod (some-op?) n) ?
00:20brehautoops
00:20brehautthat last one should be (some-op x)
00:20ihodesnot always
00:20brehautihodes: thanks. in that case you cannot get away with m-result being identity
00:21ihodese.g. a mod a / 2 is not the same as a/2 mod a.
00:21brehautm-result has the responsibilty of introducing a value into the monadic context such that any following operation defined in that context will acceptit
00:22brehautwhereas m-bind passes some previous known-safe context into a new function that in tern must return something in that context
00:22brehauthowever i have screwed up
00:22amalloyihodes: i don't think that's an example of what he asked
00:23ihodesi may have misunderstood his question. i also left of parens in my example
00:24ihodesoff* should have been (a mod a)/2 != (a/2 mod a).
00:24brehautcorrected monad (defn mod-n-m [n] (monad [m-result (fn [x] (mod x n)) m-bind (fn [v f] (f v))]))
00:24brehautexample of use
00:24brehaut(domonad mod-2-m [a (m-result 2) b ((m-lift 1 inc) a)] b)
00:24ihodesbut i'm not familiar with category theory, so i'm not following the monad discussion. i'm more of a set and number guy ;)
00:24amalloyah. brehaut, that correction makes me much happier
00:25brehautamalloy: yeah, it also makes the use of the monad basicly pointless ;) you have to m-lift everything
00:25brehautthe only advantage you get is that the base is now determined by the monad, not by the code
00:25brehauti dunno if you think thats an advantage, i consider it a lot of overhead for not much gain
00:27amalloybrehaut: no, not much. but it's really a special case of restricting the operand in some way, by calling (f val) before passing it along
00:27brehautyup for sure
00:34brehauttrying to write the applicative version of this is horrible.
00:35amalloybrehaut: i think you can avoid the lifting by causing the monad to operate on functions instead of values, and eventually return a function that does all the operations including mod
00:36brehautamalloy: that would be an approximation of the state monad
00:36amalloyi'll take your word for it. it sounds pretty bizarre to me
00:36brehautit gets a bit squiffy without a type system to help keep you sane
00:37amalloy*laugh*
00:38brehautheh :)
00:39brehautwe'll its quite important that every function that is bound takes 1 argument from the non-monadic context, and returns one value in the monadic context
00:40brehautie the haskell type sig is Monad m => a -> m b
00:40tomojhow could cake automatically pull native deps for jiraph?
00:40tomojdoes it peek into the jar for project.clj?
00:41tomojnothing in the pom about jtokyocabinet
00:41brehautin clojure, that constraint isnt enforced, this you could actually bind a function of type a -> b into the monad and it will run, but you could create an error
00:41tomojhuh, nothing in jiraph's project.clj either..
00:41brehautamalloy: fair enough :) it still wigs me out that haskell's types are curried
00:42amalloytomoj: transitive dependency?
00:43brehautamalloy: by which i mean if you have a type :: T a b c
00:43tomojamalloy: hmm
00:43brehautwhich means a type T that is generalised over parametric types a b and c
00:43tomojhttp://clojars.org/repo/tokyocabinet/tokyocabinet/1.23-SNAPSHOT/tokyocabinet-1.23-20101217.045604-14.pom
00:43brehautyou can define something as :: T int int
00:43tomojjiraph has that directly in :dependencies
00:44tomojodd
00:44brehautwhic returns a new anonymous type that needs to be parameterised over one more type
00:44brehautaaand thats enough of that
00:45amalloysummary: haskell -> confusing
00:45brehaut(defn haskell [brain] (squish brain))
00:46brehaut(defn haskell-types [brain] (scatter (haskell brain)))
00:49tomojdo "OOP corresponds to a modeling paradigm" and "prolog corresponds to a modeling: logic" (correspondences being loose of course) make sense?
00:49tomojif so, what corresponds to clojure?
00:50amalloyi think you mean prolog corresponds to a logic paradigm, but it's all rather vague and fluffy
00:51tomojI meant "a modeling paradigm: logic"
00:51brehautim confused
00:54jimbostrudellisp corresponds to algebra. rules and operations for for transformation of data
00:54jimbostrudelfeel free to remove one of those "for"s. I don't care which
00:55amalloyrules and operations for for transmation of data? jimbostrudel, that makes no sense :)
00:55jimbostrudel;)
00:56jimbostrudeltransmation, definitely
00:57tomojcertainly the modeling paradigm has got to have a little more to say about what those rules are and operations do?
00:57tomojof course it does
00:57tomojalgebra has plenty to say
00:59jimbostrudelsure. any specific language is going to have a lot of rules and the operations are the functions you define and the standard library
01:00tomojI'm not sure it can be that specific
01:01tomojnevermind, I see you're right again
01:11tomojit is bothersome that cake-suitable native dep jars aren't necessarily lein-suitable
01:14tomojjiraph's cake dev-dep on clojure-protobuf also requires leiners to add clojure-protobuf to :dependencies
01:15amalloytomoj: lein has dev-dependencies, doesn't it?
01:15tomoj.. didn't try that
01:16amalloytechnomancy: come quick, someone is badmouthing leiningen :)
01:17tomojto dev-deps works too
01:17tomojI don't understand why
01:17tomojI thought dev-deps were for lein's VM
01:19tomojI see they're on the classpath though
01:20amalloytomoj: i think they're supposed to be for "stuff you only need when hacking on the project"
01:21tomojsounds about like what I thought
01:21tomojI wasn't hacking, merely useing jiraph.graph
01:22tomojso if dev-deps are left out of jars, my project will break?
01:22tomoj(.. are dev-deps left out of jars? I should know that..)
01:23tomojs/jars/uberjars/
01:24amalloy*shrug* i don't deal with this stuff really
01:29ossarehtomoj: dev-deps are left out of Jars.
01:29ossarehmore specifically uberjars
01:30tomojso I bet I do have to add it to :dependencies
01:31tomojbut not due to cake incompatibility
01:31ossarehsorry, I've dropped in midway through this - best I can advise is if you're uberjaring and need a library that isn't defined upstream as a dependency then yes, you need to include it in your dependencies.
05:24xkbhi, I want to do something like this: (repeat 10 (rand-int dim))
05:24xkbonly with rand-int each time :)
05:24xkbhow do I do that?
05:25fliebelxkb: repeatedly
05:25xkbahh
05:25xkbthat was it
05:38xkbthanks
05:40clgv&(doc repeatedly)
05:40sexpbot⟹ "([f] [n f]); Takes a function of no args, presumably with side effects, and returns an infinite (or length n if supplied) lazy sequence of calls to it"
05:40clgv&(doc repeat)
05:40sexpbot⟹ "([x] [n x]); Returns a lazy (infinite!, or length n if supplied) sequence of xs."
05:41clgv&(repeat 10 (rand-int 100))
05:41sexpbot⟹ (86 86 86 86 86 86 86 86 86 86)
05:41clgvlol k. I get it ^^
05:42fliebelclgv: Did you solve the table problem yet? (or am I confusing people again?)
05:42fliebel$source range
05:42sexpbotrange is http://is.gd/OEN10A
05:43__name__is there any mvc web framework for clojure?
05:43fliebel__name__: You mean actual mvc, or just a good separation of concerns?
05:44__name__fliebel: i meant former but latter is fine with me as well
05:44ejackson__name__: enlive + compojure
05:45fliebel__name__: There is Compojure, which seems to be the most like Django, and there are a couple of others that take the Pyramid approach, eg, throw some libs together yourself and have it work.
05:46__name__does clojure webdev expect you to write your templates in lisp rather than embed code in html as others do?
05:47__name__ah, okay, enlive somewhat injects content into a html file
05:47fliebel__name__: Only Hiccup does that. Enlive does not, really. There are a couple of others, that work more like classic PHP-style templating.
05:47fliebelMustache comes to mind. https://github.com/fhd/clostache
05:48__name__thanks
06:23iwillighi guys, i want to extend a Java class to implement clojures Iseq... is proxy the best (or only) thing to use?
06:23opqdonutreify is ok too
06:24iwilligwith reify you can only extend interfaces right?
06:24opqdonutoh you want to actually subclass it and not wrap? then proxy yeah
06:25iwilligthanks opqdonut
06:26clgvfliebel: tableproblem?
06:27fliebelclgv: Hmmm, yea, 25 students on tables of 5, lots of valid positions.
06:27clgvfliebel: that wasnt me. but I dont remember the name of the guy asking
06:28fliebelah, it was jcromartie
06:29clgvI did something on the logic puzzle. but didnt manage to complete it yet
06:30fliebelclgv: I've been doing logic programming for the last few days… I'm thinking that should be useful, though there aren't any numbers involved :(
06:31clgvfliebel: I did implement the first two criteria. but on the third my table has more columns than the one shown in the solution
06:31fliebelclgv: Did you look at the JS source?
06:32clgvfliebel: not thouroughly
06:33khaliGis everyone using (setq lisp-indent-offset 2) for slime? i just discovered it
06:34clgvkhaliG: I am not using emacs at all ;)
06:34khaliGwhich are you using?
06:34clgveclipse CCW ;)
06:46raekkhaliG: what does it do?
06:47khaliGraek, as far as i can tell, indents forms in lets/fns better
06:47khaliGso they dont end up all the way across the right of the page
06:48raekall I use is clojure-mode-use-backtracking-indent, which makes proxy and defrecord indent properly
06:49raeklet, fn and defn use 2 spaces of indentation for me...
06:52raekah, you said slime. I was thinking of clojure-mode, clojure source files rather than the repl
06:52khaliGyep :)
06:53khaliGit almost does the right thing but not quite, off by one space in the var defns in (let [...] form) but at last form lines up correctly
06:53khaliGs/last/least
06:53sexpbot<khaliG> it almost does the right thing but not quite, off by one space in the var defns in (let [...] form) but at least form lines up correctly
06:55raekhrm. I recall having read that someone managed to get clojure-mode working in the repl.
07:13ejacksonraek: My emacsfu is weak, but I just leached this: https://github.com/spicycode/the-greatest-and-best-emacs-configuration-ever-devised-by-man which gives me clojure-mode in the repl etc etc
07:24thorwili really need a way to diagnose why slime likes to hang here. if only it would produce error messages
07:25raekthorwil: how did you install slime? from elpa?
07:27thorwilraek: no, ubuntu package.
07:27thorwilalso cl-swank
07:28thorwilguess i try removing those packages, then
07:29raekyou could try installing slime from elpa instread. I have no idea if that will change anything, but I think it's more common to use this variant
07:29raekcl-swank sounds like swank for Common Lisp...
07:30raekthorwil: I would recommend these instructions: https://github.com/technomancy/swank-clojure
07:31raeksection Connecting with SLIME
07:31thorwilyes. i had a brief look into cl after reading land of lisp
07:31raekI should really buy that book...
07:33thorwilit's quite entertaining and to me rather eye-opening, not knowing much that much about lisp beforehand
07:34thorwilbut reading through the examples, i always had the impression that CL is a bit much on grown side
07:55iwilligdo methods on a proxy take "this" as an argument ?
07:57khaliGthey can, if that's what you're asking
07:58iwillig"Each method fn takes an additional implicit first arg, which is bound to 'this."
07:58iwilligmmm
07:58iwilligk
07:59iwilligi don't understand... i am getting an invalid argument error.... but its not clear to me why
08:02raekiwillig: iirc, you don't write the 'this' parameter in the parameter list explicitly. 'this' will automatically be bound to the instance
08:03iwilligyeah thats what the docs say thanks
08:03iwilligokay really dumb question... with proxy are you allow to add new methods to your object ? or just override existing methods ?
08:06raekI suspect the latter, but I'm not sure
08:08raekproxy is a java interop feature, and for java code to use a method of a class, it has to know about that class at compile time
08:08khaliGyou can add a new method if its part of an additional interface
08:08khaliGat least that's how i've been doing it but i should probably check out protocols
08:09raekso it doesn't seem like it would be easy to call such a method, if you coould define it
08:09raekif you don't use this for java interop, then you should use protocols
08:11iwilligokay thanks guys
08:13raekregardless whether you use proxy or reify, you can extract code that methods have in common to an ordinary clojure function (if that was the concern)
08:21khaliGit's scary that i've almost got a working program in less than 350 lines of clojure...
08:23ejacksonkhaliG: keep coding and it'll get smaller, and smaller. I'm always afraid of working on any piece of clojure too long in case I create a singularity.
08:23khaliGhaha i have that feeling ejackson :)
09:01abedratechnomancy, should lein uberjar swallow compilation errors?
09:06rhebushello
09:07rhebusI'm trying to get started with clojure and Midje.sweet
09:07rhebusbut I really don't understand things
09:08rhebusI've got as far as a system where I can do (require 'midje.sweet) and (midje.sweet/fact (+ 1 1) => 2) but if I try (:use midje.sweet) I get a ClassNotFoundException
09:08rhebusI have clojure, clojure-contrib, midje and unifycle jars in ~/.clojure
09:08rhebusand $HOME/.clojure/* on the classpath in my clj bash script
09:08rhebuswhy am I getting a ClassNotFoundException when I try (:use midje.sweet)?
09:10rhebushttp://pastebin.com/7L6iDd6t shows my clojure session
09:10fliebelrhebus: Have you tried cake or lein? Manually managing the classpath is not ideal.
09:10clgvtry (use midje.sweet) instead
09:11clgvthe keyword syntax is only used within an ns-statement
09:11rhebus(use midje.sweet) gives the same error
09:11rhebusfliebel: maybe i should try that
09:11clgvoh sorry forgot one thing
09:11fliebelclgv: Your code needs a quote. (use 'midje.sweet)
09:11clgvnow its correct (use 'midje.sweet)
09:11rhebuswooo that works perfectly thanks
09:12rhebusok so let me get this straight
09:12clgvprobably you should get one of those introductory books for clojure ;)
09:12rhebuswhen do I use (:use foo.bar) and when (use 'foo.bar)?
09:13rhebusif those books tell you how to set up your system
09:13clgvfirst one within an ns-statement. last one if you type it on repl
09:13rhebusand those are the only use cases?
09:13rhebusthat I am likely to come across in my first month of clojure, that is...
09:14clgvwell you could use the last one on every position where you can write statements, but that would be bad style in general I guess
09:14rhebusok
09:14clgvtry using it within an ns-statement when you code files
09:17clgvrhebus: I started with one of the books and that speeded up learning a lot ;)
09:17rhebusi'll be ok once I'm bootstrapped
09:17clgvjust an advice ;)
09:18rhebusgetting a usable environment is a necessary requirement
09:18rhebusi do have a pragprog clojure book but it's in the office
09:18clgvahkk
09:18cdddrclgv: Are any of them good for people who know their share of FP, but are just new to Clojure?
09:19clgvcdddr: humm I guess so. "Programming Clojure" was my start
09:20clgvcdddr: I dont think it is explaining too much general theory on FP.
09:20cdddrOoh, somewhat affiliated with the Pragmatic guys. Works for me.
09:21cdddrAnd they ship PDFs, too. Excellent.
09:21fliebelI thin the world could use a "7 functional languages in 7 weeks/hours/years"
09:22clgvI didnt have to buy it since our department already owned a hardcopy :)
09:22cdddrIf it's years, I'd be inclined to +1.
09:22cdddrI've come to hate those "24h" bullshit books.
09:22cdddrclgv: Hahaha, that's always preferable. :>
09:23clgvyes indeed :)
09:23clgvuhh now I have a serious performance issue
09:23cdddrKept a head to something obnoxiously huge? ;)
09:25clgvI am using filter like follows: (filter #(criterion? param1 param2 % param4 param 5) (filter #(contains? unused-set (:bla %)) coll))
09:27clgvand it tells me that it needs 6s in total (~30.000 calls to that function) but the criterion? only takes 1s in total
09:27clgvdoes filter has this big perfomance overhead internally?
09:27clgvor what might be the problem?
09:27cdddrShouldn't. You could combine the two tests, though.
09:28clgvthe criterion? test is more expansive
09:28clgvs/expansive/expensive
09:28sexpbot<clgv> the criterion? test is more expensive
09:29cdddrclgv: I meant using comp to combine them, but erh, yeah, I see.
09:30clgvcdddr: maybe an and-statement would be shorter if it already returns false after first parameter evaluation
09:30clgvbut why is there a gab of almost 5s?
09:30clgv*gap
09:31clgvI have a doall statement around it to be able to measure the time
09:32cdddrWait, well if 1s is spent in the oter filter, then logicall the other 5s is spent in the inner one, no?
09:32arturophello, I'm a newbie looking for a bit of help
09:32clgvthe inner one is a simple contains? on a set
09:33clgvthe set contains at most 150 elements
09:33cdddrUh, wait, I need to indent. :>
09:33clgvthe collection also contains at most 150 elements
09:34clgvjust doing a lein compile to look at the java classes
09:34cdddrclgv: Humor me here, try to measure just the inner filter.
09:34arturopI'm trying to install the clojure koans but can't figure out how to do it
09:34cdddrBecause ~5s for filter overhead definitely sounds wrong.
09:35clgvcdddr: ok I'll do
09:35clgvyes I definitely think the is something wrong
09:35clgvwith my code - not clojure ;)
09:37cdddrHeheheh, blaming the language is *almost* never right. :)
09:37cdddrI did find a gcc bug once, though. :D
09:37clgvespecially if you just got started some months ago ;)
09:37rhebusfliebel: ooh, playing with lein and it's very nice indeed
09:37clgvI did find several borland c++ 4.0 compiler bugs ;)
09:38cdddrC++ is almost cheating. ;)
09:39clgvcdddr: inner filter criterion takes around 6ms in total
09:39clgvso there is something wrong with my expression in terms of performance
09:43cdddrclgv: Could try with that and, it does short-circuit on false.
09:44clgvcdddr: humm ok I did an error when measuring time. it takes indeed 2s
09:44clgvso 1s+2s = 6s? :(
09:46cdddrWell, if the functions are crazy fast, half overhead isn't all that unrealistic.
09:47cdddrSo anding them together might work out better.
09:47clgvI'll try now^^
09:50cdddrAnd in other news, I was kind of braindead, trying to look for a first value in coll for which fn returns something non-false.
09:50clgvdoes the definition via #(dosomething %) maybe cause performance overhead?
09:50cdddrclgv: It shoudn't, it's only defined once.
09:51cdddrWhat I tried - some ungodly mess of drop-while, complement and some stuff I'd rather not remember.
09:51clgvis it really? even if it's a closure?
09:53cdddrclgv: I'm inclined to do some hand-waving and argumentum and JITium when all else fails, but, well, you could just try and see. ;)
09:53cdddrWhat I should have done - (first (filter identity (map f coll))).
09:55clgvthat looks odd - why filter identity? what about "some"?
09:55Chousukeclojure is not lazy, sequences are lazy :)
09:55cdddrclgv: Yeah, that's even better.
09:56cdddrclgv: If it wasn't clear, I'm only doing this for like two days. ;)
09:56clgvkk
09:56cdddrclgv: but... but... I feel cheated!
09:57cdddrI do remember doing ctrl+f "first" on that page. :(
09:57cdddrI blame my broswer. ;)
09:59cdddrChousuke: Ah, right. :>
10:30clgvok, the #(criterion? %) approach for filter is ok
10:30clgvchanging that to a defn and a partial only makes it worse
10:52TimMcI'm looking for a macro that is like `and` but returns the last true value it received.
10:52fliebel&(and 1 2 3)
10:52sexpbot⟹ 3
10:52TimMc&(and 1 2 3 false)
10:52sexpbot⟹ false
10:52TimMc^ doesn't return 3
10:53fliebelah, like that.
10:54TimMcI'm trying to write a macro, but I'm still new to this.
10:54fliebel&(last (take-while identity [1 2 3 false]))
10:54sexpbot⟹ 3
10:54fliebelTimMc: No need to use macroes for everything.
10:55TimMcfliebel: I want to delay evaluation of the arguments.
10:55fliebel&(source and)
10:55sexpbotjava.lang.Exception: Unable to resolve symbol: source in this context
10:56TimMcI should explain my intent -- I have a GUI program with a number of updater functions. There's a cascade of state changes, and I want to avoid recomputing all the dependent state info if the source state info hasn't changed.
10:56edoloughlinTimMc: How do you know what your last true value is if you're not evaluating?
10:56TimMcedoloughlin: Evaluate each item as I come to it, and then decide whether to keep evaluating or not.
10:57clgvhow about ##(some identity (reverse [1 2 3 false]))
10:57sexpbot⟹ 3
10:57clgv&(doc reverse)
10:57sexpbot⟹ "([coll]); Returns a seq of the items in coll in reverse order. Not lazy."
10:57clgvoh its not lazy...
10:58clgvcould have been on an array but not on a seq.. ;)
10:58TimMcLazy isn't what I need -- all the "arguments" will be function calls.
10:58TimMc(changes (update-foo!) (update-bar!) (update-qux!))
10:59TimMcHuh. I suppose if none of my updaters take arguments, I can just pass the functions in...
10:59fliebelSo you want to keep updating untill you get false?
10:59TimMcYeah, and then return true if any of them did.
10:59TimMc(changes update-foo! update-bar! update-qux!) <- Look ma, no macros!
11:00fliebel&(last (take-while #(%) [+ * :a]))
11:00sexpbotjava.lang.IllegalArgumentException: Wrong number of args passed to keyword: :a
11:00TimMcI won't even need an accumulator -- no need for tail recursion here.
11:00TimMc(I won't be using long lists of functions.)
11:09TimMcfliebel: This works: https://gist.github.com/829621
11:14clgvTimMc: you might get problems with your recursion if you have a bigger number of elements in that list. and you are returning the result of the first call and not the last one
11:19abedraand you are returning the result of the first call and not the last one
11:19abedraand you are returning the result of the first call and not the last one
11:19abedraand you are returning the result of the first call and not the last one
11:22clgvthere seems to be an echo ;)
11:30TimMcclgv: This is for hardcoded lists, not lists that are passed in.
11:30TimMcI could add an accumulator helper if it became a problem.
11:32clgvok. but you are returning the wrong result
11:39TimMcclgv: Wrong result? I did switch to returning the value instead of literally true or false.
11:39TimMcOh, I see -- yes.
11:40TimMcI'll return (if fv true false) instead.
11:43cdddrIs there any (de-facto?) standard for naming functions in Clojure?
11:52fliebelcdddr: lower-case-hymphenized seems to be the norm.
11:53fliebelcdddr: Unless you wanted to know about earmuffs and star functions.
11:55rhebusquestion marks on predicates seem to be the done thing too
11:56cdddrSo all in all, rather lax? :)
11:56rhebusdon't ask me, i'm new here :
11:56rhebus:)
11:56fliebelcdddr: Oh, yea, question marks for predicates.
11:57cdddrrhebus: That makes the two of us. :)
11:57rhebusdoes anyone use midje? I'm having trouble using (unfinished) on a function which I want to use in a src file and (provided) results in a test file
11:58rhebusif I put (unfinished foo) in the test file, the src file complains that foo isn't defined
11:58rhebusi can provide an example if this isn't clear
12:01bortrebnormally you just have a function called "thing" instead of "get-thing"
12:03cdddrSo if I have a function that goobles a coll of widgets and produces a whatchamacallit, I'd probably just call it whatchamacallit? ;)
12:06rhebusah, i found my midje problem; you have to remove the (unfinished foo) when you start doing (provided (foo x) => bar)
12:19rhebus&(* 1 (repeat 5 2))
12:19sexpbotjava.lang.ClassCastException: clojure.lang.LazySeq cannot be cast to java.lang.Number
12:19rhebuswhat am I doing wrong? how do i "flatten" the list to allow * to see the elements of the repeat?
12:19rhebus&(* (repeat 5 2))
12:19sexpbotjava.lang.ClassCastException: Cannot cast clojure.lang.LazySeq to java.lang.Number
12:20rhebushmm, I should apply reduce shouldn't i
12:20amalloyrhebus: or just apply *
12:20rhebus&(reduce * (repeat 5 2)
12:20sexpbotjava.lang.Exception: EOF while reading
12:20amalloy&(apply * (repeat 5 2))
12:20sexpbot⟹ 32
12:20rhebus&(reduce * (repeat 5 2))
12:20sexpbot⟹ 32
12:21amalloyrhebus: mine is "like" (* 2 2 2 2 2), yours is ##(reduce list '* (repeat 5 2))
12:21sexpbot⟹ (((((* 2) 2) 2) 2) 2)
12:21rhebuswhat about with the extra element? ##(apply (cons 1 (repeat 5 2)))
12:21sexpbotjava.lang.IllegalArgumentException: Wrong number of args (1) passed to: core$apply
12:21rhebus&(apply * (cons 1 (repeat 5 2)))
12:21sexpbot⟹ 32
12:22amalloy&(reduce (partial list '*) (repeat 5 2))
12:22sexpbot⟹ (* (* (* (* 2 2) 2) 2) 2)
12:22arturophello
12:22arturopI'm having classpath problems
12:22amalloyarturop: are you using lein or cake? if not, i suggest you do so
12:22arturopI am using lein
12:23arturopI am trying to run the clojure koans project
12:23arturopand I'm using eclipse and ccw
12:23arturopI've been all day with it but it's beating me
12:23khaliGis there a stylistic guide to writing clojure code?
12:24arturopin the eclipse project it seems to be right the folder is there
12:24rhebuswhich is less ugly, ##(apply * (cons 1 (repeat 5 2))) or #(* 1 (apply * (repeat 5 2))) ?
12:24sexpbot⟹ 32
12:24arturopbut nothing
12:25rhebus&(apply * 1 (repeat 5 2))
12:25sexpbot⟹ 32
12:25rhebushuh, that's the best way then :)
12:26arturopany ideas before I jump off a bridge
12:27amalloycdddr: (filter identity (map f coll)) is (keep f coll)
12:30amalloywell. except that keep will include false elements, removing only nil
12:30cdddramalloy: Yeah, I suck and I really wanted (some f coll).
12:31technomancykhaliG: there are coding guidelines on the assembla wiki
12:32khaliGthe library coding standards page?
12:33khaliGok just scanned through that and it didnt answer my question
12:33khaliGi'm wondering whether it's good practice to use the doto form even just for one thing?
12:33amalloykhaliG: sure
12:34khaliGamalloy, to make it clear to the reader that you're doing some sort of mutation?
12:35amalloythat's one reason. the alternative, (let [x (f)] (hack-up x) x)), is rather more verbose and less clear
12:36amalloytechnically, the fact that there are two exprs inside a let implies side effects, but doto is more explicit
12:36amalloy(and means you don't have to type "x" three times :P)
12:37arturopeven if no one can help me
12:37arturopcan anyone suggest any investigation route
12:37cdddramalloy: Wouldn't one normally want to bind x in the [] section every time? I know I do.
12:38khaliGhm amalloy well what if you dont even care about x after evaluation?
12:39khaliGeg, (.setText month-label (get-month month)) vs (doto month-label (.setText (get-month month))
12:39amalloycdddr: (defn make-me-a-window [name] (doto (JFrame.) (.setTitle name)))
12:39amalloykhaliG: ah. in that case...probably not
12:39khaliGamalloy, i'm easy either way, just trying to learn best practice
12:39cdddramalloy: Yeah, but I meant the hack-up alternative with let.
12:40ogonzalezarturop, is your problem with ccw only? you should be able to run the clojure koans without it
12:40amalloycdddr: you were saying that you always want to bind x, and i demonstrated that you don't. i guess i don't understand what you're getting at
12:40arturopI've tried from the command line
12:40arturopand I get something else
12:41arturopException in thread "main" java.lang.NoClassDefFoundError: and
12:41arturop...
12:41arturopCould not find the main class: and. Program will exit.
12:42cdddramalloy: What I meant was that if I wanted to hack up x with let, I'd do it in the [] section both times.
12:42amalloycdddr: you mean like (let [x (f), x (hack-up x)] ...)?
12:43cdddrYup.
12:43ogonzalezarturop, does it fail without having modified any koan?
12:43cdddrSeems more explicit.
12:43amalloycdddr: but it's wrong
12:43amalloy(.setTitle x "hello") doesn't return x, it returns void. that's why the doto macro is so useful
12:44cdddrAhh, I see. Thanks.
12:45amalloy&(let [x (java.util.ArrayList.) x (.add x 10)] x)
12:45sexpbot⟹ true
12:45amalloy&(let [x (java.util.ArrayList.) _ (.add x 10)] x)
12:45sexpbot⟹ #<ArrayList [10]>
12:45amalloy&(doto (java.util.ArrayList.) (.add 10))
12:45sexpbotjava.lang.IllegalArgumentException: Malformed member expression
12:45amalloywhoa what?
12:46arturopogonzalez: yes
12:46arturopI haven't been able to run it even once
12:48ogonzalezarturop, are these ones http://github.com/relevance/functional-koans.git? They work fine for me; just script/run and first error appears
12:49arturopwell
12:49arturopbreakthrough
12:49arturopI did this
12:49arturop(load-file "script\\run.clj")
12:49arturopand now it works...
12:50arturopand to be precise it's https://github.com/functional-koans/clojure-koans.git
12:50arturopin any case
12:51arturopthx a lot indeed
12:54x6763hi everyone. I'm considering using Clojure for developing on the Android platform. Anyone know of any issues I should be aware of?
12:55lucianx6763: clojure's bootstrap is very gc-intensive, but android's gc is optimised for very low memory usage and memory sharing, not high peformance
12:56technomancyx6763: it's got a pretty lousy boot time and bloats up the application size by many mega-bytes.
12:56lucianthe net result is that clojure takes a very, very long time to start up on andrid
12:58x6763ah, i see...that probably won't be very acceptable for a lot of our users
12:58x6763thanks lucian and technomancy
13:06khaliGlucian_, are those obstacles solvable or it's likely to persist?
13:10dnolenkhaliG: the obstacle is solvable with faster mobile hardware, at the rate things are moving this won't much of a wait.
13:11khaliGthats good to hear dnolen
13:12khaliGi'm actually looking forward to running my clojure app on different machiens to see how it performs, i have a netbook and access to an ipad
13:16fliebelhey dnolen :)
13:17fliebelI came across cond-i, and noticed there is none in Logos. Why?
13:18dnolenfliebel: cond-i is interleaves goals, in the latest version of miniKanren that is the default.
13:19dnolenfliebel: cond-e *is* cond-i
13:20fliebeldnolen: That is cool… I guess, but also somewhat confusing :)
13:22dnolenfliebel: cond-e in TRS preserves Prolog depth-first search. They introduce cond-i to show the benefits of interleaving search. Later they decided they preferred interleaving search and made it the default, which simplifies the implementation (since they only support one kind of search instead of two).
13:22fliebelAh, I see
13:23fliebeldnolen: Meanwhile I'm still thinking about the finite domain thing. It would be nice to be able to do (run* [q] (add-o 2 q 5)) => 3
13:26dnolenfliebel: I'm not even sure it's possible to do that efficiently. TRS shows you how to build relational arithmetic operators. Beautiful code, but too slow to be even remotely useful.
13:27fliebelWhoa, it's actually in the book? nice :) Why is it so slow?
13:28dnolenfliebel: it uses a binary numerical representation and relational operators based on hardware adders.
13:31fliebeldnolen: I will get there, I hope :) I was thinking you could limit the possibilities a lot with a range-like cond-e. (cond-r start end step number)
13:32jweisslooking for a little advice - trying to put together a tree datastructure, each node contains a keyword for a particular page in the web app i'm testing, and a function that will navigate there. and then a list of "child" pages that you can navigate to from that page. i want to be able to walk the tree, and 'comp' all those functions together to navigate from root to leaf.
13:33jweissnot sure if each node should be a map and have a :children key with a list in it, or what
13:34dnolenfliebel: you probably could I haven't thought about it enough, Art of the Propagator and Chapter 9 and 12 of this http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.102.7366&amp;rep=rep1&amp;type=pdf, get into that.
13:35fliebeldnolen: I'll add it to the list. TRS is first :)
13:36fliebel#### < marker for my chat history ;)
13:49amalloyjweiss: maybe ##(doc tree-seq)?
13:49sexpbot⟹ "([branch? children root]); Returns a lazy sequence of the nodes in a tree, via a depth-first walk. branch? must be a fn of one arg that returns true if passed a node that can have children (but may not). children must be a fn of one arg that returns a sequence of th... http://gist.github.com/829892
13:49jweissamalloy: will take a look, thanks
13:52lucian_khaliG: i doubt android's gc will get much faster any time soon, really
13:53luciankhaliG: clojure's bootstrap could be improved, however
13:53lucianand there isn't really any chance of getting it on an ipad
13:55cinchjweiss: for walking a tree, clojure.zip is great. i have a similar web app with a tree structure for pages and folders, the code is here: https://github.com/cinch/sicnarf-blog
14:07odyssomayHi, how can I call the superclass of a gen-class?
14:15rmarianskiodyssomay: i think you can use exposes-methods to do that
14:15rmarianskihttp://clojure.github.com/clojure/clojure.core-api.html#clojure.core/gen-class
14:20odyssomayrmarianski, thx, got it
14:20jweissis it possible to retrieve the names of the arguments that an anonymous fn takes?
14:20jweisssay if i want to automatically roll a series of functions up into one
14:22jweisseg, i have 3 functions f1, f2, f3 that take [x] [] and [y z], and i want to create one function (fn [x y z] (f1 x) (f2) (f3 y z))
14:24rmarianskii'm not sure if you can do that generally
14:24jweissi suppose i could add meta to them
14:25jweissbut that seems redundant
14:26amalloyjweiss: this sounds like a bad idea. for example, a function can take more than one set of args, even an anonymous function
14:26amalloyif you really want to, then adding :how-to-roll-me-up meta seems like the way to go
14:27jweissamalloy: that's true - i suppose i could have callers pass a map to the rolled-up fn and each piece could pull its args from the map
14:28jweissno way to tell in advance whether the caller supplied all the necessary args though, for that i guess i'd need meta.
14:28amalloyjweiss: consider also (fn [[x y] count])
14:29amalloyin general if you want to mess with "names" you're in for a world of pain; dealing with "number of args" is somewhat less awful
16:31octeis there a way to define a java-compatible interface in clojure, that extends an existing java interface?
16:31brehaut(doc definterface)
16:31clojurebot"([name & sigs]); "
16:31fliebelocte: deftype, and all the others are java compatible, as far as I know.
16:31octebrehaut, yeah, i found that, seems very undocumented.. doesn't seem you can extend an existing interface with it
16:31brehautthats a remarkably empty doc
16:32fliebelbrehaut: It;s used by defprotcol, which generates both a protocol and an interface.
16:32brehautfliebel: ah right cheers
16:33fliebel"defprotocol will automatically generate a corresponding interface" ##(doc defprotocol)
16:33sexpbot⟹ "Macro ([name & opts+sigs]); A protocol is a named set of named methods and their signatures: (defprotocol AProtocolName ;optional doc string \"A doc string for AProtocol abstraction\" ;method signatures (bar [this a b] \"bar docs\") (baz [this a] [this a b] [this a ... http://gist.github.com/830255
16:34octestill doesn't extend and existing interface?
16:34fliebelocte: it does, you can extend protocols and interfaces.
16:36raekbut a protocol interface cannot extend another interface in the ordinary java sense, right?
16:37raekI mean, you can create a protocol implementation for objects that implement a certain interface, but that's outside the jvm type system
16:37fliebelraek: rly? Well, I trust you on that.
16:37raekocte: also, why do you need it?
16:38fliebelraek: Oh yea, you're right.
16:39raeksince the extention would be performed after the interface was defined, that would imply that you could change a detail of a type
16:39octeraek, playing around with jna
16:50raekocte: you should be able to generate an interface that extends another with gen-interface, but that requires compilation
16:51mattreplwhatever happened to streams?
17:10jweissi'm a little stumped here. i have a macro that outputs ~(map keyword args) but in the output the args aren't turned into keywords at all, they're still symbols. change it to a (for [arg args] (keyword arg)) somehow fixes it.
17:11raekjweiss: paste?
17:12raekthat sounds weird
17:12jweissraek: https://gist.github.com/830354
17:12jweissthat's the for version
17:12jweiss(see line 5)
17:15jweissraek: erm, now changing it back to map, seems to still work. i... don't get it
17:16jweissoh wait, no didn't work
17:16raekjweiss: you also have to reevaluate any code that uses the macro
17:16jweissraek: it's really just a data structure that uses the macro
17:17raekwhat would a typical call look like?
17:17jweissraek - (page :mypage (fn [arg] (browser click arg)))
17:18jweissraek - edited the gist to the version that doesn't work
17:18markskilbeckMorning, all.
17:18jweissexpands to {:req-args [arg], :page :mypage, :fn (fn [arg] (browser click arg))}
17:18jweisswhy isn't it :req-args [:arg] ?
17:19raekjweiss: you are using the name map in your let
17:19jweissdoohhhhhh
17:19markskilbeckSay I have a vector of vectors (the vector type isn't important, I guess) and each element is something like: [1 2]. How do I map a function to the second element of each vector?
17:19octeis there a way to cast/coerce an int into a byte i clojure? (cast Byte 0xFF) throws a class cast exception.
17:20markskilbeckOh, I guess I'd use an anonymous function for map.
17:20raekand you don't have to syntaxquote hashmaps
17:20raek,(let [x 1] [`{:foo ~x} {:foo x}])
17:20clojurebot[{:foo 1} {:foo 1}]
17:20jweissthanks raek, i probably would have caught that map thing if it hadn't broken in such a small way
17:22jweissmuch appreciated raek, looks better without the extra quoting and unquoting, and map actually works.
17:23raekmarkskilbeck: anonymous function + map => for
17:23raekusually indents prettier too
17:23markskilbeckAh. Thanks raek
17:24ndimidukis there an example of using ring's warp-cookies middleware in an application someplace handy?
17:25raekmarkskilbeck: update-in can be used if you only want to update one element
17:41jweissif i have a macro and i call it with arguments that contain another call to the same macro, is there any guarantee that the argument will be expanded first?
17:41amalloyjweiss: it is guaranteed not to happen, if i understand what you're saying
17:42jweissamalloy: ok then, will it happen *after* my top-level expansion?
17:43amalloythat is, (mymac (mymac 10)) will be called first with argument '(mymac 10), and then whatever that results in (which may or may not include (mymac 10)) will be expanded
17:43shachafjweiss: A macro gets its arguments completely unexpanded, no?
17:43shachafjweiss: Then whatever it returns is evaluated.
17:43jweissshachaf: i guess that makes sense, so i guess my macro has to treat it's self-call as "pre-expanded"
17:44amalloymarkskilbeck: ##(for [[a b] (partition 2 (range 10))] [a (inc b)])?
17:44sexpbot⟹ ([0 2] [2 4] [4 6] [6 8] [8 10])
17:45markskilbeckCool amalloy :)
17:47amalloyalternatively, ##(for [pair (partition 2 range)] (update-in pair [1] inc))
17:47sexpbotjava.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.core$range
17:47amalloyexcept that partition is giving seqs, not vecs :P
17:47amalloy&(for [pair (partition 2 range)] (update-in (vec pair) [1] inc))
17:47sexpbotjava.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.core$range
17:48amalloyoh. haha whoops. anyway you get the idea, i hope
18:09TimMcAny idea why I'd suddenly start getting a NoSuchMethodError when calling a record's constructor that was working when I last checked it into source control?
18:09TimMcException in thread "AWT-EventQueue-0" java.lang.NoSuchMethodError: timmcHW3.core.GUI.<init>(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V at timmcHW3.core$init_gui$fn__43.invoke(core.clj:35)
18:10TimMcThis is from calling (GUI. nil nil nil nil nil nil nil)
18:17TimMcGRah, nasty evil transient errors...
18:49bmhCan incanter find inverse matrices?
18:50simardwhat's the most efficient way to test if a number is a palindrome ? I thought about using Integer/toString, then .split, and then (nth) and then =
18:50bmhsimard: In what base?
18:50simardb
18:50simardwell.. 10
18:50simard;)
18:50simardbut I know Integer/ supports converting to a string of base b if required
18:51amalloyTimMc: are you AOT compiling? sounds like a class file versioning issue
18:51amalloysimard: i have a tiny little github repo that converts a number into and out of base N
18:52amalloygiving you a seq of its digits
18:52amalloyit's pretty trivial, but http://github.com/amalloy/bit-packer
18:52simardwell I'm here to learn you know, so trivial will do
18:52simardthanks
18:55bmhah-ha. Incanter can find matrix inverses, it's just called "solve"
19:10amalloysimard: so palindrome-checking in base 10 probably looks like (apply = ((juxt identity reverse) (pack x 10)))
19:40TimMcamalloy: A lein clean did the trick.
19:40amalloyso that's a yes, re aot?
19:41TimMcWell, I had been using lein run exclusively.
19:41TimMcSo, I suppose no AOT.
19:42amalloyhm. i don't really know how lein run works
19:42TimMcInterestingly, lein uberjar may be what actually cleared up the issue... weird.
19:42TimMcNo wait, I had been doing some lein compile.
19:42TimMcSo yes, probably a class versioning issue.
19:43technomancyif you have :main set, it will assume you need AOT and will compile for you automatically.
19:44technomancyof course, if the .clj has a newer mod time than the .class file, it should force a recompile
19:49TimMctechnomancy: Aha! I did a git reset --hard HEAD^ to try something out -- must have rolled back the .clj file mtime as well.
20:11amalloydoes the compiler do any clever caching of constant values for me? eg, if i write ((juxt identity reverse) my-seq) inside a function, does it rewrite that to (let [fn1 (juxt identity reverse)] (fn [my-seq] (fn1 my-seq))), or reconstruct the juxt function every time i call my function?
20:11amalloyalso, simard, ##(doc floor)
20:11sexpbotjava.lang.Exception: Unable to resolve var: floor in this context
20:11amalloyhm
20:17TimMcfloor?
20:17TimMcIsn't that a Math/ function?
20:18amalloyTimMc: Math works exclusively with doubles, and gives doubles back
20:18amalloyclojure.contrib.math has a version that gives you sensible types
20:18TimMcnice
20:18amalloy&(Math/floor (/ 5 2))
20:18sexpbot⟹ 2.0
20:19amalloy&(do (use 'clojure.contrib.math) (floor (/ 5 2)))
20:19sexpbotjava.io.FileNotFoundException: Could not locate clojure/contrib/math__init.class or clojure/contrib/math.clj on classpath:
20:21octeis there anyway to create an alias for a symbol?
20:22ihodesi know this is off-topic, but i'm new to irssi. does anyone know how to search back through the chat with it? i had little luck with the online docs
20:22hiredmanresolution is symbol -> var, there is no symbol -> symbol resolution
20:22octeihodes, you can use /lastlog text-to-search-for max-number-of-hits-to-show
20:22octeoh, parameters are other way around
20:26ihodesocte: sweet-thanks! is there anyway to pipe that output to another irssi window?
20:26octeno idea
20:26ihodesfair enough. i'll search around. that's quite helpful already, though. thanks :)
20:42TimMcocte: Just run /lastlog from window 1, after selecting the correct network.
21:31krumholtHi. I don't have a better solution but it's kind of confusing that (+ Integer/MAX_VALUE Integer/MAX_VALUE) produces an exception while (+ Integer/MAX_VALUE 4294967294) does not.
21:48TimMc,Integer/MAX_VALUE
21:48clojurebot2147483647
21:49TimMc,(+ Integer/MAX_VALUE 2147483647)
21:49clojurebot4294967294
21:49DespiteItAll,(+ Integer/MAX_VALUE (int 2147483647))
21:49clojurebotjava.lang.ArithmeticException: integer overflow
21:50DespiteItAllSeems to me, you're forcing it to be an int
21:50dnolen,*clojure-version*
21:50clojurebot{:major 1, :minor 2, :incremental 0, :qualifier ""}
21:50TimMcAnd Clojure 1.3 will behave differently for this, yeah?
21:56dnolen(+ Integer/MAX_VALUE Integer/MAX_VALUE) does not produce an exception in 1.3.0.
22:28krumholtnice i like it. if this changes in 1.3.0
22:37pdkyknow what i realized
22:37pdkit's probably disturbing how much i look to use -> and ->> in places now
22:37pdkbackwards unnested nested code!
22:42krumholt+ really changed for the better in 1.3.0
22:49Null-AI want to define a type which is java serializable. Can I define it with deftype?
22:49_na_ka_na_Null-A, yes
22:49Null-A_na_ka_na_: not defprotocol though?
22:50Null-Adefrecord* _na_ka_na_
22:51_na_ka_na_Null-A, no don't think you can extend protocols like you can extend interfaces in Java, if that's what you mean
22:51pdkok here's something to chew on
22:51Null-A_na_ka_na_: sorry I meant defrecord, which autogenerates the hash function, et al
22:51pdki'm trying to hit on some form that'd work like adding the forms arguments to a doto call programmatically without being totally ugly and inscrutable
22:51_na_ka_na_I think can you make a defrecord also serializable
22:52pdkand i was wondering if the use of ` and doto here might be considered ugly http://pastebin.com/5dZkFCue
22:52Null-Ak
22:52Null-Athanks _na_ka_na_
22:52pdklet alone be sure to work :p
22:52pdkmaybe an atom + doseq would fit the bill more cleanly
22:52pdkoh welp
22:53pdkguess that settles it since (apply doto ... is already an error being a macro
22:54pdkthat and i assume doto expects the object to be mutable
22:55_na_ka_na_pdk, yes I think doto is for mutable java objects
22:55pdkatom + doseq it is
22:55amalloypdk: doto doesn't care about the underlying object at all, and indeed doesn't know about it
22:56amalloy,(doto (inc 10) println)
22:56clojurebot11
22:56clojurebot11
22:56_na_ka_na_,(doto (atom 10) (swap! inc) (swap! inc))
22:56clojurebot#<Atom@91cceb: 12>
22:56pdkwell doto is basically accumulating state with that object before returning it
22:56_na_ka_na_,(macroexpand-1 '(doto (inc 10) println))
22:56clojurebot(clojure.core/let [G__1263 (inc 10)] (println G__1263) G__1263)
22:56pdkso you probably end up with only the last change applied being seen if you pass it something immutable i'd imagine :p
22:56amalloypdk: no, that is one way to use doto. doto just reorganizes the forms
22:57pdk,(doto {} (assoc 1 2) (assoc 3 4) (println))
22:57clojurebot{}
22:57clojurebot{}
22:57pdk,(doto {} (assoc 1 2) (assoc 3 4))
22:57amalloydoseq and an atom is disgusting. you probably want reduce or iterate
22:57clojurebot{}
22:57_na_ka_na_so its just like -> I guess
22:57pdk-> nests em
22:57_na_ka_na_expect that it doesn't pass the previous form to the next etc.
22:57pdkdoto just seems to run each form sequentially
22:57_na_ka_na_ya
22:58pdk(doc iterate)
22:58clojurebot"([f x]); Returns a lazy sequence of x, (f x), (f (f x)) etc. f must be free of side-effects"
22:59amalloyyour problem looks like it wants to be solved with reduce, but it's hard to see what you're trying to do
23:01pdkcool beans
23:02pdkpopped in reduce and it did the trick though i wasn't holding up hope since the function insert-pair was going to be inserting/updating various values in a map of maps depending on whether new insertions were already present
23:02pdkthough since it worked immutably already i guess there was no cause for concern about that
23:03amalloyindeed
23:09simardI'm trying to solve the collatz problem (from euler project) with clojure.. right now I know exactly how I'd do it in C or any language that would allow for mutable data (ie, have an 1 by N array and fill cases when necessary)
23:09simardI'd like to do it in a clojury way though, but efficiently
23:10simardany suggestions ?
23:11amalloysimard: i suggest you stop worrying about efficiency so much when you're learning a language
23:11simardlol
23:11simardmy engineering background programming microcontrollers perhaps
23:12amalloy*shrug* and your vague belief that infinite sequences will be slow
23:12amalloyi have a collatz implementation in a gist somewhere if you want to use it for inspiration
23:12simardsure
23:13amalloyhttps://gist.github.com/607446
23:13pdksituations with potentially infinite seqs = time to fall back on lazy seq idioms
23:14bortreb?
23:14pdk!
23:15amalloysimard: you can memoize the collatz function if you want to trade memory for time, but it's not really worth it
23:15simardreally I'd rather not trade anything
23:15simardI'm pretty sure I can do that quick and with not much memory.. with an array :P
23:16simardhttp://clojure.roboloco.net/?tag=collatz-sequence
23:16bortreblol the hailstone numbers --- this problem me very sad, as even the best clojure solution I could make that was backed with an array took 13 secs, while my c and FORTRAN versions took only 3 milliseconds :(
23:16simardyeah
23:16simardmore like I would expect
23:19dnolensimard: you should be able to get that to Java speeds, but if you're on 1.2.0 you're going to need a lot more type-hinting.
23:21dnolensimard: nothing dirty about Java arrays in Clojure. Those methods are there for a reason.
23:26dnolensimard: there's a number of things that are slow in your int-array solution.
23:28simarddnolen: what ?
23:29dnolensimard: aset-int is ridiculously slow, you need to type-hint all arithmetic operations in 1.2.0, you need to type-hint primitive array.
23:30simardoh
23:30simardyeah, I'll be doing it in C
23:30simard:)
23:30simardjust this time
23:31dnolensimard: stack-into-array, banging on a mutable array from within the realization lazy-sequence adds needless overhead.
23:41pdk1.3.0 is making changes with how it handles primitives and boxing
23:42pdkideally boxing a lot less internally
23:43Scriptorhad a good discussion about that earlier