#clojure logs

2011-06-26

05:30shanmuHi, what is the best way to get xml back from a zipped parsed xml seq, in clojure 1.3?
05:31shanmuI find that xml/emit and prxml both donot emit proper xml when passed a zipped parsed xml....
05:57fliebelWhat would you use for a mail server, where I need to send email from Clojure and store emails in a fancy noSQL db for a sweet web app?
05:58fliebelI'm thinking some UNIX workhorse where I just mess around with the maildir. But I also found Apache James.
06:25shanmu Hi, what is the best way to get xml back from a zipped parsed xml seq, in clojure 1.3?
06:44matthias__(doc constantly)
06:44clojurebot"([x]); Returns a function that takes any number of arguments and returns x."
06:45matthias__,(doc constantly)
06:45clojurebot"([x]); Returns a function that takes any number of arguments and returns x."
10:48matthias__,(- 1)
10:48clojurebot-1
12:32daakui'm using hiccup to write a few reuseable "widget" type things (drop-down menus, nav-bars etc). i want to allow for a "family" to be specified, which adds a class to all the html elements created by the widget, and i'm wondering what would be good design for this
12:33daakuthe idea is that for say a drop-down menu, there'd be a <ol> containing <li> containing <a>, and i'd want the "family" to be applied to all three (with some added prefix/suffix)
13:15Ian_Corne,(dotimes [i 10] (println i))
13:15clojurebot0
13:15clojurebot1
13:15clojurebot2
13:15clojurebot3
13:15Ian_Corneoho
13:15clojurebot4
13:15clojurebot5
13:15clojurebot6
13:15clojurebot7
13:15clojurebot8
13:15clojurebot9
13:15Ian_Cornesorry :)
13:18semperosfor config files that don't get kept under version control (e.g. for db credentials), do folks normally just use Clojure datastructures for the config file?
13:25chousersemperos: sure is an easy place to start
13:27semperosworks for me
13:28chousersemperos: do remember to 'read' it, not 'load' it
13:30semperosthat was part of my uncertainty, how to actually structure it
13:30semperosand then "read" it in
13:30semperosvs. just using a normal Clojure file with var's and providing an example file with blank files
13:30semperos*blank values
13:34semperosI see macourtney used a normal namespaced file with default values, and documented instructions for changing them: https://github.com/macourtney/Conjure/blob/master/conjure_core/test/config/db_config.clj
13:40Ian_Corneis there a way to get back the time value from a (time exp) ?
13:48fliebelIan_Corne: time is a really simple macro, so I think your best bet would be to write one that returns the time, instead of prints it.
13:48fliebel$source time
13:48sexpbottime is http://is.gd/1COGB7
13:49Ian_Corneah thnx
14:17fliebel&(map #(cond (= (rem % 15) 0) 'fizzbuzz' (= (rem % 5) 0) 'buzz' (= (rem % 3) 0) 'fizz' :else %) [1 3 5 15 16]) ; to tired to get even this right
14:17sexpbot⟹ (buzz buzz buzz fizzbuzz buzz)
14:18fliebel&(= (rem 1 5) 0) ; so where does the buzz come from?
14:18sexpbot⟹ false
14:21AWizzArdAnybody in for a type-hint challenge?
14:24fliebelsomeone em-brace me, I just used single-quotes...
14:25AWizzArdWho is expert for removing reflection warnings by setting the right type-hints? :-)
14:26fliebelAWizzArd: Not me, but you could show me some code :)
14:27fliebel&(map class ['aap' 1]) ; weird... to much Python
14:27sexpbot⟹ (clojure.lang.Symbol java.lang.Integer)
14:28AWizzArdI have a HBox h and two Labels l1 and l2. I want to add the Labels to the HBox, and this is how it is done: (.addAll (.getChildren h) (to-array [l1 l2]))
14:29fliebelAWizzArd: What does the warning say?
14:29AWizzArdThis is the HBox: http://download.oracle.com/javafx/2.0/api/javafx/scene/layout/HBox.html and when you follow getChildren you see it returns an ObservableList: http://download.oracle.com/javafx/2.0/api/javafx/collections/ObservableList.html
14:30AWizzArdNo warning so far, but ithe ObservableList also has a setAll method. One can replace the .addAll by .setAll in my code and it still works fine.
14:30fliebelAWizzArd: You said you had reflection warnings?
14:30AWizzArdBut, and now my challenge comes: .setAll has two implementations where one has the signature boolean setAll(java.util.Collection<? extends E> col)
14:31AWizzArdSo, I tried (.setAll (.getChildren h) [l1 l2]) <-- but this produces a reflection warning.
14:31AWizzArdcall to setAll can't be resolved
14:32fliebelMaybe (.setAll (.getChildren h) ^java.util.Collection [l1 l2]) ?
14:33AWizzArdTried that.
14:33AWizzArdAlso I am using all literal types, so the compiler should know that a vector is a Collection.
14:34AWizzArdI just can’t remove that reflection warning.
14:34fliebelI suppose that because getChildren does not give a warning, h, and the return value of that can be resolved.
14:34AWizzArdh is bound in a let, so Clojure knows its type. The type of .getChildren is also clear. This is why (.setAll (.getChildren h) (to-array [l1 l2])) works fine, without a reflection warning.
14:35fliebelAWizzArd: So, why can't you use that?
14:36AWizzArdI can. I am just curious how I can solve such a challenge in principle.
14:37AWizzArdI would assume that a correct type hint exists. So, this is more a general approach to understand problemsolving in Clojure better, instead of solving the concrete problem at hand.
14:38fliebelRight... Could you try vector-of?
14:38amalloyAWizzArd: maybe you can gist a snippet?
14:38amalloyfliebel: that's only good for primitives
14:39fliebelamalloy: Right, I just figured that out :(
14:39fliebelamalloy: I was thinking it was because arrays have actual types, and vectors are just objects. But these <E> things are just casts anyway...
14:40amalloyyeah. my issue is i'm not even sure what the two type signatures *are* that AWizzArd is trying to distinguish between, nor what types his actual objects are
14:41AWizzArdamalloy: in the repl I set *warn-on-reflections* to true and then did (let [h (HBox.), l1 (Label.), l2 (Label.)] (.setAll (.getChildren h) (to-array [l1 l2]))) which works. But when I remove the to-array call it gives me the reflection warning.
14:42AWizzArdamalloy: http://download.oracle.com/javafx/2.0/api/javafx/collections/ObservableList.html
14:42AWizzArdThat interface lists two .setAll methods.
14:43fliebel*my* problem is that I can't see how the vararg one wouldn;t work for a list.
14:43AWizzArdThe first one takes a Collection, and (isa? clojure.lang.PersistentVector java.util.Collection) ==> true
14:43AWizzArdfliebel: the vararg one gets auto-translated into an array from Java
14:43amalloyfliebel: varargs are a fiction
14:44fliebelI mean, the difference between adding one list to the other or add ing the *elements* of said lis to the other is kind of ambiguous I think.
14:44AWizzArdSo, in Java one would say: h.setAll(l1, l2); <== the second .setAll, with the vararg
14:44amalloyAWizzArd: IPersistentVector doesn't extend java.util.Collection, but PersistentVector does extend it. it may be the compiler is only hinting with the appropriate interface
14:45fliebelAWizzArd: Now do h.setAll(l1), what am I trying to do here?
14:45AWizzArdfliebel: this is the vararg call, because l1 is not a Collection.
14:46AWizzArd(instance? Collection [l1 l2]) ==> true
14:46amalloyAWizzArd: doesn't address my point
14:46fliebelAWizzArd: Okay, h.setAll([l1]) then. It could be both, right?
14:46fliebelamalloy: He tried hinting with java.util.Collection
14:47AWizzArdThat also didn’t help.
14:48fliebelAWizzArd: What I'm trying to say is... maybe when you used the array, it used the fake-vararg one, but when you used the vector, it could be both.
14:48fliebelmaybe not...
14:49amalloyfliebel: that's only a concern in java, not in clojure
14:49amalloybecause the clojure compiler doesn't provide javac's sugar for accessing varargs without coercing to array
14:49fliebelamalloy: So are there 2 functions, one with a collection and one with an aray, or is there just one and some syntax for Java?
14:50amalloythere are two
14:50AWizzArdamalloy: so your guess right now is that it could be in the Clojure compiler itself, that stops me from being able to hint the type here.
14:51amalloyi think that's pretty unlikely
14:51amalloyi bet dnolen would know how to do it, for example
14:52AWizzArdYes, or rhickey might also have an idea ;)
14:52gfrlogis there a way to unchunk a chunked seq?
14:52fliebelgfrlog: Yea, it's in JoC, and on the blog of fogus.
14:53gfrlogI think I just found the latter, thanks
14:54fliebelHm, what about (fn [s] (lazy-seq (cons (first s) (recur (next s)))))))))) or whatever...
14:55gfrlogfliebel: do you mean that in a recursive way?
14:55fliebelyea
14:55gfrloglike passing (next) to the outer function maybe?
14:55amalloyfliebel: can't recur across a lazy-seq
14:56fliebelamalloy: Oh, well, give it a name and use that then...
14:56gfrlogfliebel: ah I didn't even see (recur) somehow
14:56gfrlogthought you had left it out
14:56amalloyfliebel: or use https://github.com/amalloy/amalloy-utils/blob/master/src/amalloy/utils/seq.clj#L32 -- amirite?
14:57gfrlogI use amalloy-utils as a drop-in replacement for clojure.contrib
14:57amalloyo/
14:57gfrlog\o
14:57fliebelgfrlog: As in, just change the import?
14:58gfrlogfliebel: yep, works every time.
14:58fliebelamalloy: amirite?
14:59amalloyam i right
14:59gfrlog$google amirite
14:59sexpbotFirst out of 90300 results is: amirite? Share your thoughts, ideas and jokes and see if people agree.
14:59sexpbothttp://www.amirite.net/
14:59gfrlogI dunno about that
14:59amalloybut said quickly, usually to imply "of course i'm right"
14:59gfrlog$google amirite urban dictionary
14:59sexpbotFirst out of 700 results is: Urban Dictionary: amirite
14:59sexpbothttp://www.urbandictionary.com/define.php?term=amirite
15:00gfrlogoh it's on wiktionary too
15:48fliebel"I would have included Clojure, as I find the language itself not without its merits, but the current implementation is 4 times slower than plain Java and skewed the graph badly" http://lists.nongnu.org/archive/html/chicken-users/2011-03/msg00070.html
15:49fliebelLooks like a job for dnolen :)
15:49gfrlogit's hello world?
15:49gfrlogdoesn't that mean it's measuring language startup time?
15:49fliebelgfrlog: Yea
15:49gfrlogokay, so not a serious issue then?
15:49fliebelgfrlog: Still silly that Clojure apparently loads 4 times as much as java.
15:50gfrlogit's okay that clojure has slow startup, because the JVM starts up so fast that it evens out
15:51amalloysrsly? "I wrote hello world and it was so slow in clojure that it's a bad language"?
15:51gfrlogamalloy: no, he just didn't want the graph to be unreadable
15:51gfrlogmaybe if he used a log scale he could have fit everything better
15:52gfrlogC and Bash are already like 4 pixels long as it is
15:52amalloyi see. at least he was measuring for cli scripting
16:01derphow does one convert a character to an int?
16:01gfrlog,(int \x)
16:01clojurebot120
16:01gfrlogthat's probably it
16:02fliebelderp: But note that ##(int \4) might not do what you expect.
16:02sexpbot⟹ 52
16:02gfrloghmm
16:02derp,(int \4)
16:02clojurebot52
16:02gfrlogit didn't occur to me he might think of it that way
16:02rpglover64what's ## do?
16:03gfrlogrpglover64: triggers sexpbot mid-line
16:03fliebelrpglover64: Invoke sexpbot
16:03rpglover64got it
16:03rpglover64thanks
16:03gfrlog,(map #(- (int %) 48) [\1 \2 \3 \8 \9])
16:03clojurebot(1 2 3 8 9)
16:03Raynes&(Integer/parseInt \3)
16:03sexpbotjava.lang.ClassCastException: java.lang.Character cannot be cast to java.lang.String
16:03RaynesShame.
16:03gfrlog,(map #(- (int %) 48) [\1 \2 \3 \8 \9 \0])
16:03clojurebot(1 2 3 8 9 0)
16:03gfrlogI didn't expect \0 to work
16:04fliebel&(Integer/parseInt (str \3 \3))
16:04sexpbot⟹ 33
16:04gfrlogcuz I'm dum
16:05gfrlog,(let [sexpbot-trigger "##(+ 7 8)"] (first sexpbot-trigger))
16:05sexpbot⟹ 15
16:05clojurebot\#
16:05gfrlog\o/
16:05gfrlogwhat do I win?
16:05gfrlogoh wait....
16:06gfrlog&(let [sexpbot-trigger "##(+ 7 8)"] (first sexpbot-trigger))
16:06sexpbot⟹ 15
16:06gfrlogaah
16:06gfrlogfascinating
16:06rpglover64huh?
16:06gfrlogI woulda put a bunch of money on it going the other way
16:06fliebelgfrlog: I've been thinking about creating a loop with these bots...
16:06gfrlogrpglover64: I'm experimenting with triggering two things at the same time
16:07gfrlogfliebel: I wanted to do that a while back, but sexpbot's damn arrow character messes the whole thing up
16:07rpglover64,5
16:07clojurebot5
16:07derpcan one access a string like a vector?
16:07rpglover64##5
16:07rpglover64 ##5
16:07rpglover64...
16:07gfrlogderp: strings are seqable...
16:07rpglover64 ##(5)
16:07sexpbotjava.lang.ClassCastException: java.lang.Integer cannot be cast to clojure.lang.IFn
16:07gfrlogderp: so I guess it depends on what you mean
16:07Raynesfliebel: Good luck with that.
16:07gfrlogRaynes: remove that blasted arrow!
16:08gfrloghow else can #clojure be made a fun-house?
16:08fliebelRaynes: Or change the arre into a comma :D
16:08gfrloglol
16:08RaynesMaybe you just need to make him throw a comma exception. ;)
16:08amalloygfrlog: i think it would have made more sense for & to apply first, but when i added ## i was really excited and made it a priority
16:08gfrlogamalloy: I think you just wanted me to lose a bet
16:08gfrlogamalloy: it'd be really cool if it did both
16:09derpgfrlog: I am not explaining this well, but I guess I want to be able to get a specific member of a string
16:09amalloynot my fault you don't read the sexpbot commits logs from last october
16:09amalloy&(doc subs)
16:09sexpbot⟹ "([s start] [s start end]); Returns the substring of s beginning at start inclusive, and ending at end (defaults to length of string), exclusive."
16:10fliebelWhat's the name of these codes that eval to themselves?
16:10amalloyquine
16:10rpglover64quines
16:10derpsomething like "take", but doesn't return earlier members
16:10amalloyderp: see above: subs
16:10fliebelderp: nth
16:11amalloyfliebel: nth might convert to a seq for strings
16:11gfrlogfliebel: if the bots could talk to each other, we'd need a kind of two-step quine
16:11fliebelamalloy: Yea, subs is right, but nth is like take without the earlier stuff.
16:12amalloyi see nth treats strings as CharSequence
16:12fliebelgfrlog: you could fork sexpbot and configure it to have & as a prefix and tigger on the arrow.
16:12derpwhy do certain seq commands follow different orders for arguments?
16:13gfrlogfliebel: I tried forking both bots back in the day, but couldn't get either of them set up
16:13derplike take wants the num first and collection 2nd, but nth is the reverse
16:13gfrlogderp: it is the ineffable will of Bob
16:13amalloyderp: nth drives me nuts
16:14amalloymost sequence things take [arg arg coll], not [coll arg]
16:15fliebelamalloy: Hm, I swear I had some config file for sexpbot. where to look?
16:15amalloyfliebel: ~/.sexpbot/info.clj
16:15derphmm, okay
16:15gfrloghaha! sex!
16:16fliebelamalloy: uhoh, since when does it throw log4j exceptions?
16:17derp,(subs "Hello" 2)
16:17clojurebot"llo"
16:17gfrlogman how I never done heard of subs before?
16:17derpokay, so what function does the reverse of subs?
16:17gfrlogalso why clojure.org/api doesn't have any chunked-seq functions listed?
16:17amalloyderp: also subs
16:17derpif I wanted "He" instead?
16:18gfrlog,(subs "Hello" 0 2)
16:18clojurebot"He"
16:18derpah
16:18derpI don't know why, I just assumed the default behavior would be that one
16:19gfrlogderp: I think that's how substring functions work in a lot of languages
16:19amalloyderp: then you'd need to know the length of the string to get the opposite behavior
16:20fliebelamalloy: all my plugins seem to be missing. what happened?
16:20derpah, I hadn't thought of that, I guess that is pretty sensible
16:21amalloyfliebel: i'd guess they're either gone, or in a different place than you're looking :P. not much information there to solve the problem with
16:21fliebelamalloy: I just kep removing untill it ran :)
16:25fliebelamalloy: Where do I get a current set of plugins?
16:25derpif I run (count *string*) on some big string, but this string does not change, and call it often, does that poorly affect performance?
16:26amalloyfliebel: sexpbot.plugins.*, each should be a plugin. or you can copy the info.clj from the git repo
16:27amalloyderp: no
16:27amalloystrings are counted at construction time
16:28derpokay, but what about in the general case? does clojure do some sort of fancy auto memoization for repeated calls to functions with the same args?
16:28amalloyno
16:29derpreally?
16:29gfrlogamalloy: it oughta, eh?
16:29gfrlogat least for the immutables?
16:29amalloythat would be terrible
16:29gfrlogamalloy: why? unpredictable performance?
16:29amalloyclojure should presume you care more about speed than space?
16:29fliebel&1
16:29derpwell
16:29sexpbot⟹ 1
16:30amalloyand who wants to write the type system that makes it clear what's referentially transparent and what isn't?
16:30gfrlogeh...I guess
16:30derpwell
16:30derpI mean you could have a lru cache or something
16:30amalloyderp: don't put it in the language, though. that's nuts
16:30gfrlogI would just have the immutable collections know their own sizes
16:30amalloylots of people have written lru-cache memoization functions already; you can just use them
16:31amalloygfrlog: mostly they do
16:31gfrloglazy seqs apparently don't
16:31derpokay
16:31amalloygfrlog: surprise?
16:31gfrlogamalloy: nope
16:32gfrlogamalloy: I mean of course they don't know them automatically
16:32gfrlogI mean even after repeated calls
16:32amalloygfrlog: again, space/speed tradeoff. plus, it would be awkward
16:33gfrlogI don't think it can be that awkward. But I agree that it's cleaner to let the user decide what's important.
16:33gfrlogs/can/has to be
16:33sexpbot<gfrlog> I don't think it has to be be that awkward. But I agree that it's cleaner to let the user decide what's important.
16:33amalloythey'd have to implement Counted in order to have their .count method called, so (counted? (map inc [])) would return true even though it's clearly not counted
16:33gfrlogI've never heard of counted
16:33amalloyclojure.lang.Counted
16:34amalloy&(supers (class {}))
16:34sexpbot⟹ #{clojure.lang.MapEquivalence clojure.lang.IPersistentMap java.util.Map clojure.lang.ILookup java.io.Serializable java.util.concurrent.Callable clojure.lang.Counted clojure.lang.Associative clojure.lang.IPersistentCollection java.lang.Runnable clojure.lang.IEditable... http://gist.github.com/1047945
16:34gfrloghmm
16:34fliebelyay! did it, in #tempchan
16:34gfrlogamalloy: I guess I wouldn't have done it that way
16:34amalloyfliebel: bring him into #sexpbot, he can hang out
16:34gfrlogamalloy: I would've made count part of ISeq and let the seq itself choose whether to optimize
16:35gfrlogfliebel: whatdjado?
16:35fliebelamalloy, gfrlog: added the harpoon as a prefix and launched 2 boys.
16:35amalloyhaha
16:35gfrlogalright, well get to quine writing I guess
16:35fliebel&((fn [x] (list x (list (quote quote) x))) (quote (fn [x] (list x (list (quote quote) x)))))
16:35sexpbot⟹ ((fn [x] (list x (list (quote quote) x))) (quote (fn [x] (list x (list (quote quote) x)))))
16:35gfrlogfliebel: http://blog.sigfpe.com/2008/02/third-order-quine-in-three-languages.html
16:36fliebelgfrlog: sexpbot can do haskell and a couple more, so maybe...
16:36derpum, is there a way to easily rename a function/variable and all occurrences of it in emacs?
16:36gfrlogfliebel: it looks like he sorta found a way to build them automatically
16:36gfrlogmaybe not, I didn't quite understand it
16:37derpI guess something like the eclipse refactor/rename?
16:40technomancyderp: there's slime-who-calls, which will show you all usages. no automated rename though.
16:41amalloytechnomancy: that works?
16:41technomancyohh.... there might be in tcrayford's mode.
16:41technomancyamalloy: I'm not sure how accurate is. it's slow enough that I never use it
16:43derptechnomancy: thank you
16:43technomancyderp: probably wouldn't be too hard to implement
16:43technomancyjust have bigger fish to fry myself
16:44technomancyfor moving between namespaces without renaming you can use slamhound: http://github.com/technomancy/slamhound
16:44derpI'd try it myself if emacs didn't scare the bejesus out of me
16:44technomancyit's a pretty crappy dialect
16:45technomancyI mean, for a lisp
16:49AWizzArdgfrlog: this is what the compiler should do :-)
16:49gfrlogAWizzArd: totally agreed :( :(
16:49gfrlogAWizzArd: it makes it that much more painful that this is being compiled to run on the JVM
16:51lnostdal-laptop(try ... (catch ... (loop ... (recur ...)))) ;; isn't possible? .. i can kind of understand why recuring to the "outside" of a try/catch block is tricky; but within the catch "sub-block"?
16:51gfrloglnostdal-laptop: that looks messy if nothing else
16:51lnostdal-laptop(..i'm getting "Cannot recur from catch/finally" .. but i'm recuring within it..)
16:51amalloylnostdal-laptop: i think i've seen a bug report with a fix attached. what version of clojure?
16:52lnostdal-laptop1.3-something (from git), amalloy
16:52lnostdal-laptopi can try upgrading to latest master .. lessee
16:52technomancyclojurebot: CLJ-31
16:53clojurebotIt's greek to me.
16:53technomancy,botsmack
16:53clojurebotjava.lang.Exception: Unable to resolve symbol: botsmack in this context
16:53technomancy~botsmack
16:53clojurebotclojurebot evades successfully!
16:53technomancyhttp://dev.clojure.org/jira/browse/CLJ-31
16:53amalloyhttp://dev.clojure.org/jira/browse/CLJ-667
16:53technomancyoh snap
16:54amalloytechnomancy: attached patch claims it will fix 31 too
16:54lnostdal-laptopah, yeah, that looks like what i'm doing
16:54lnostdal-laptopi can apply it and try
16:55technomancycools
16:55technomancyclojurebot: #31
16:55clojurebot31. Simplicity does not precede complexity, but follows it.
16:56gfrlogclojurebot: 42
16:56clojurebotPardon?
16:56gfrlogclojurebot: #42
16:56clojurebot42. You can measure a programmer's perspective by noting his attitude on the continuing vitality of FORTRAN.
17:10occlojurebot: #1
17:10clojurebot1. One man's constant is another man's variable.
17:17lnostdal-laptopwith some adjustments the patch seems to work fine
17:17lnostdal-laptop:)
17:29kirasif anyone would take the time to critique my code and offer some advice on how to improve it, i'd appreciate it: https://gist.github.com/1047989
17:31amalloykiras: generate-random-points doesn't need to exist
17:31amalloyor could be implemented more easily, anyway
17:31amalloyjust (repeatedly n #(generate-random-point x-n y-n z-n))
17:32kirasamalloy: ah... that's cool, i didn't know about that function
17:32amalloyc.c.math/floor can generally be replaced by int, and it looks like that's true here
17:32gfrlogkiras: using lazy-seq and recursion can usually be avoided...
17:34gfrlogso for example the sierpinski-points function...
17:34kirasamalloy: will creating an int from a floating point number will always result in it being rounded down?
17:34gfrlog,(int 3.9)
17:34clojurebot3
17:34gfrlog,(int -3.9)
17:34clojurebot-3
17:35gfrlogdown-towards-zero I guess
17:35amalloykiras: see https://gist.github.com/1047993
17:35kirasgfrlog: ah... yeah, guess i should have just tried that. didn't see a note of it when i did (doc int). guess that behavior shouldn't ever change, i hope
17:35amalloyi don't know anything about what your code is actually doing, but these are ways that jump out at me to make it simpler
17:36kirashttp://en.wikipedia.org/wiki/Sierpinski_triangle in case you haven't seen it before
17:36gfrlogkiras: I mean more algorithmically
17:37gfrlogso you're just creating n points, where each one is based on the last one?
17:37kirasgfrlog: basically
17:37gfrlogokay
17:37gfrlogwe can use iterate for that
17:38gfrlog(iterate #(sierpinskisize % tri) initial-point)
17:38kirasgfrlog: i have a triangle, i choose an initial point inside it at random. then i choose a vertex at random and draw the point halfway between the initial point and the vertex
17:38gfrlogso that ^ there will be an infinite lazy seq, starting with the initial-point
17:39gfrlogif you want to exclude the initial point, which I think your function does, then you'll want to call (rest) on it
17:39kirasgfrlog: i do
17:39gfrlogand then you can use (take) to limit the size
17:39gfrlogso (take n (rest ...))
17:39gfrlogwhere ... is the code above
17:40gfrlogI guess that's the only use of lazy-seq/recur other than the one amalloy already addressed
17:41amalloygfrlog: i get tired of writing (take-while (complement nil?) (rest (iterate f coll))): defined that as (iterations f voll)
17:41amalloy*coll
17:41gfrlogin amalloy-utils?
17:41amalloyyeah
17:42gfrlogamalloy: assuming (f nil) crashes, do you know if that expression is guaranteed to never call (f nil)?
17:42gfrlogit makes me nervous
17:42amalloyyeah i remember you having this bizarre fear a while ago
17:42gfrlogI remember bringing it up
17:43gfrlogI'm pretty sure you said it can't
17:43gfrlogmaybe I just have this traumatic childhood experience where I thought that's what was happening :/
17:44amalloygfrlog: seriously if you're worried about that happening you should never use iterate
17:45gfrlogamalloy: you mean with fragile functions, or ever at all?
17:45kirasusing slime, what's the best way to restart the repl, so to speak? say i just deleted a function and i compile the file it used to be in, the old definition is still available in the repl.
17:45amalloyever at all is what i meant
17:45gfrlogamalloy: why do you say such things?
17:45amalloyto mock your fragile sensibilities
17:46gfrlogbecause using my actual fragile sensibilities would make your tests more complicated?
17:47gfrlog(with-redefs [gfrlog/fragile-sensibilities (constantly nil)] (is ...))
17:47amalloytests are for people who know fear
17:47gfrlogoh golly are you one of those rich-hickey followers?
17:47amalloyor write imperative for loops. man do those things need tests
17:48gfrlogI do not understand the test-haters at all
17:48gfrlogespecially in a dynamic language
17:49amalloyare there really test-haters, or just people who don't enjoy writing tests?
17:49gfrlogI don't enjoy writing them, I enjoy having them
17:49gfrlogparticularly after I leave a project sitting for three months and have to come back and fix a bug
17:52gfrlogbeing able to sit in your hammock and design a bug-free program before you start typing is fine and good, but when somebody else inherits it they haven't had the same hammock time
17:56amalloyhm. my new apartment's balcony has two hooks hanging from the ceiling. i wonder if i could install a hammock. they seem too close together
17:57derpI finally did it
17:57derpI think I've written the worst clojure program ever: https://gist.github.com/1048023
17:58derpI know I am really overusing let, but I don't get how to avoid it
17:58gfrlogderp: doesn't partition do that?
17:58amalloywell it's...wrong
17:58gfrlog,(doc partition)
17:58clojurebot"([n coll] [n step coll] [n step pad coll]); Returns a lazy sequence of lists of n items each, at offsets step apart. If step is not supplied, defaults to n, i.e. the partitions do not overlap. If a pad collection is supplied, use its elements as necessary to complete last partition upto n items. In case there are not enough padding elements, return a partition with less than n items."
17:58gfrlog(partition 5 1 (range 10))
17:58amalloyyour if statement is a no-op
17:58gfrlog,(partition 5 1 (range 10))
17:58clojurebot((0 1 2 3 4) (1 2 3 4 5) (2 3 4 5 6) (3 4 5 6 7) (4 5 6 7 8) (5 6 7 8 9))
17:59derpwow
17:59amalloythe first one, that is
17:59derpthat would have made life easy
17:59technomancykiras: depends how you launched it. M-x clojure-jack-in again works
17:59derpamalloy: what do you mean?
17:59amalloyyou wrote (if test then) else
18:00derpwell I was assuming that the if statement would return to the parent function
18:00gfrlog,(->> "9834258722394" (map #(new Integer (str %))) (partition 5 1) (map #(apply * %1)) (apply max))
18:00clojurebot2240
18:00derpdoes it have to have an else statement; can't I assume that the next function will execute?
18:00gfrlogI think that's the whole euler problem in one line
18:01kirastechnomancy: i don't seem to have clojure-jack-in available to me
18:01amalloy&(let [x 1] (if true x) 2)
18:01sexpbot⟹ 2
18:01amalloyhttp://www.ibm.com/developerworks/opensource/library/os-eclipse-clojure/ is a great article i read when i was learning clojure, solving just this problem
18:03derpamalloy: thanks, that looks very informative
18:08amalloygfrlog: there's this cool site, 4clojure.org - you should try it :)
18:08gfrlog:-P
18:10gfrlog,(hash :-P)
18:10clojurebot1013999587
18:12gfrlogoh dang euler's got a lot of new problems from a couple years ago
18:15amalloygfrlog: turns out the answer to all of them is pi, though. dang math
18:15gfrlogsome of these seem to have almost nothing to do with programming
18:15gfrlogexcept that you need something to crunch big numbers for you once you've solved the problem on paper
18:15agnaldo4jHello all
18:15gfrlogagnaldo4j: hello
18:15agnaldo4ji'm from Brasil
18:16agnaldo4ji want to learn more about clojure language
18:16agnaldo4ji develop about 10 years with java
18:17agnaldo4jsorry my english
18:17gfrlogagnaldo4j: how do you want to learn?
18:18agnaldo4ji don't know, i guess contributing with project
18:18gfrlogagnaldo4j: you haven't used clojure at all yet?
18:18agnaldo4jsolving bugs, implementing features
18:18amalloyagnaldo4j: you might like www.4clojure.org - it's a good teaching site for many skill levels
18:18gfrlogamalloy: dangit that's what I was about to do :|
18:19amalloyderp: you too, even though gfrlog will tease me for suggesting my site
18:19agnaldo4jI bought a book, and i have training about it
18:20agnaldo4jcool, amolloy, thank you
18:20amalloygfrlog: try OVER9THOUSANDclojure.org
18:21gfrlogOops! Google Chrome could not find over9thousandclojure.org
18:21amalloyyeah you're registering it
18:22agnaldo4jyah, OVER9THOUSANDclojure.org not encontred
18:22gfrlogagnaldo4j: it was a joke
18:22agnaldo4jops not found
18:23agnaldo4jhahaha, ok
18:24agnaldo4ji think develop my unit tests on clujure, this is correct?
18:24gfrlogagnaldo4j: you can use clojure.test for testing, if that's what you're asking
18:24agnaldo4jor clojure is only for concurrent service, not for this?
18:25gfrlogagnaldo4j: http://clojure.github.com/clojure/clojure.test-api.html
18:25agnaldo4ji have a java application with tests on junit, but i want reduce my cust with that
18:26agnaldo4ji think with clojure i will write less code
18:26agnaldo4jthis is a correct way to start to use a clojure in a project?
18:27gfrlogagnaldo4j: you're going to use clojure within a java project?
18:28agnaldo4jinitially testing this application with java clojure
18:28agnaldo4jinitially testing this java application with clojure
18:29gfrlogagnaldo4j: I've never heard of anybody doing that, but I suppose it's possible
18:29amalloygfrlog: wut. people do it all the time. it's the stealthy way to get clojure included at work
18:29gfrlogamalloy: now I've heard of anybody doing that
18:31gfrlogI guess I can't see what sort of advantage it would be. I just imagine having a bunch of (is (= 10 (Foo/bar)))
18:31gfrlogactually I don't think I've ever seen a java project that was really testable
18:31gfrlogso I just don't know what good java is :(
18:46agnaldo4jtoday i use a java application with hibernate, but i dint undertand how use it with clojure and STM
18:46agnaldo4j*dint == don't
18:46agnaldo4j*undertan == understand
18:47rpglover64http://hpaste.org/48382
18:47rpglover64I don't understand why the two forms are different
18:48rpglover64does "recur" have unintuitive behavior with nested "fn"s?
18:48rpglover64or am I just doing something stupid?
18:51amalloyrpglover64: #(foo) is the same as (fn [] (foo)), not (fn [] foo)
18:51amalloyif you wrapped the inner fn with () in the second version they would be identical
18:52amalloywell. i'm not sure about identical, because it's not clear what you're trying to do with % and nil. are they supposed to get passed in or what
18:52rpglover64yes
18:53rpglover64this is supposed to find the second to last element in a list
18:53rpglover64derp
18:53rpglover64I hate it when something stupid confuses me
18:53rpglover64thanks amalloy
18:54amalloyrpglover64: you should come in sometime when brehaut's around. he can probably ease the haskell transition, though you seem to be doing well anyway
18:55rpglover64I played with scheme before I played with haskell, and the clojure docs are _really_ good
18:56amalloyspeaking of which, have you looked at www.clojuredocs.org? it's more in-depth than the repl docs
18:57agnaldo4jsorry my questions related about java. but my transition will be slow
18:58lnostdal-laptophmm, am i being stupid or is this java jdbc quite horrible? i.e. it doesn't actually seem to work much at all :} ..
18:58lnostdal-laptopstuff quite*
18:58agnaldo4jand i have to evangelize my coworks do that too
18:59amalloylnostdal-laptop: if jdbc didn't work the internet would probably collaps
18:59amalloye
18:59amalloyrpglover64: i wish we had hoogle though
18:59lnostdal-laptopamalloy, perhaps java.jdbc is still very much work in progress then ...(?)
18:59amalloylnostdal-laptop: oh, the clojure wrapper around it is, for sure
19:00rpglover64yeah, but once you get function overloading and lose static types, hoogle becomes less powerful
19:00lnostdal-laptopok, cool .. so what do people use as of now?
19:00amalloybug seancorfield if you have issues
19:00amalloyrpglover64: sure. it's not clear how we could *get* hoogle or i'd write it
19:00lnostdal-laptop..i'm trying to communicate with postgresql
19:00amalloy$findfn 1 5 6 ;; this is nice though
19:00sexpbot[clojure.core/+ clojure.core/unchecked-add]
19:01rpglover64you'd probably have to write a type inferencer for clojure (at least for simple types) first
19:02amalloyrpglover64: dnolen has been spending a lot of time on a logic engine. he expects one use of it will eventually be an optional type system
19:03rpglover64mmmmm, static types :)
19:06amalloystatic types? you keep your filthy mouth shut
19:07rpglover64:(
19:07amalloyi kid. i think it'd be a good addition. haskell is pretty neat, and i've barely scratched the surface
19:07rpglover64:)
19:07lnostdal-laptopno one is using clojure + postgresql ? .. or perhaps mysql?
19:07rpglover64yeah, static types are sometimes a pain in the ass, but I
19:08rpglover64've gotten to the point where they help me catch more bugs than they cause frustration
19:11agnaldo4jthanks, i will return with more questions, hehehe
19:18seancorfield__amalloy: just saw you respond on the mailing list about clojure.java.io - i was just reading the source (to learn) and couldn't see an obvious way to read bytes from a binary file
19:18seancorfield__i'm not very familiar with the underlying java streams stuff tho'
19:19amalloyread into what
19:20seancorfield__if you wanted to read a stream of raw bytes, for example
19:20seancorfield__i see how to read lines of chars from a (reader "somefile")
19:21seancorfield__but not how to read bytes... i'm sure i'm just missing something obvious?
19:21amalloyreaders are for characters
19:21amalloystreams are for bytes
19:21seancorfield__ah, ok
19:23seancorfield__so i'd do (with-open [s (input-stream "somefile")] ...) ?
19:24seancorfield__and what function would turns s into a seq of bytes?
19:26amalloyseancorfield: dunno. the function must exist somewhere, but i don't actually use that stuff much
19:26seancorfield__hmm, the atlas didn't help much in this case
19:30seancorfield__(.read s) apparently... just need to figure out EOF now :) guess i need to read the java docs... ugh! makes me feel dirty...
19:31amalloyseancorfield__: (.read s) will be super-slow, if you care
19:33amalloythe method-call overhead will be big, even if you layer a BufferedInputStream in there. you have to call (.read s ary offset len) or whatever it is
19:33seancorfield__true... the JavaDocs say -1 is returned for EOF
19:33seancorfield__yup, just seen that in the JavaDocs...
19:38rpglover64I'm confused between "future" and "delay"
19:38rpglover64they seem very similar to me
19:39amalloyrpglover64: a future immediately starts a new thread to compute the value
19:39rpglover64ah
19:39amalloya delay only does anything if you force it
19:39rpglover64right
19:39rpglover64delays make sense to me (haskell-land !)
19:40rpglover64and with that one-line summary, so do futures now
19:40amalloy*chuckle*
19:41seancorfield__and then there's promise/deliver which i think is pretty cool :)
19:44rpglover64seancorfield__: that's kinda like haskell's Par monad and the IVars associated with it
21:25gfrlog,@(delay :wut)
21:25clojurebot:wut
21:29rpglover64,(future (do (Thread/sleep 1000) :ohai)
21:29clojurebotEOF while reading
21:29rpglover64,(future (do (Thread/sleep 1000) :ohai))
21:29clojurebot#<core$future_call$reify__5500@147545b: :pending>
21:30gfrlog,(future (do (Thread/sleep 1000) (prn :ohai)))
21:30clojurebot#<core$future_call$reify__5500@123ef32: :pending>
21:30rpglover64,(let [f (future (do (Thread/sleep 1000) :ohai))] (@f)
21:30clojurebotEOF while reading
21:30rpglover64,(let [f (future (do (Thread/sleep 1000) :ohai))] (@f))
21:30clojurebotjava.lang.IllegalArgumentException: Wrong number of args passed to keyword: :ohai
21:30gfrlogclojurebot may not like futures
21:30rpglover64i give up
21:31gfrlog,(let [f (future (do (Thread/sleep 1000) :ohai))] @f)
21:31clojurebot:ohai
21:31gfrlogno need to call the result of @f
21:33rpglover64ah
21:34rpglover64that bit of difference is going to take some getting used to
21:34gfrlogdifference from haskell?
21:34gfrlogyou can use (deref f) if you like that better
21:38rpglover64yeah; there are no nullary functions in haskell
21:38gfrlogwhat's nullary about it?
21:39rpglover64"(@f)" vs "@f"
21:39rpglover64the former is a function call
21:39rpglover64the latter is a value
21:39gfrlogno, the latter is a call to deref
21:39gfrlog@f := (deref f)
21:39rpglover64and the former is ((deref f))
21:39gfrlogright
21:40rpglover64the @ isn't what's messing me up
21:40gfrlogI'm confused then, since (@f) was wrong in that context
21:40pdk`what is the issue then
21:41rpglover64pdk`: I'm just commenting how from a haskell background, "(a)" and "a" are indistinguishable
21:41gfrlogah
21:41rpglover64and how I need to readjust
22:07Raynes&(let [f (future (do (Thread/sleep 1000) :ohai))] (@f))
22:07sexpbotjava.lang.IllegalArgumentException: Wrong number of args passed to keyword: :ohai
22:08RaynesOh, I see, you were calling a future.
22:08RaynesI can't be bothered to read entire backlogs.
22:08amalloyRaynes is really earning his Reading merit badge this weekend
22:09Rayneskeyword*