#clojure logs

2012-11-16

00:34SgeoIs it safe to say that a + b - b might not = a when using floats?
00:52pyrtsaSgeo: Yes.
00:57amalloySgeo: a = 1e-20, b=1e20 is an easy case
00:58SgeoI wonder if there cases that might come up in a 3d world that uses floats for locations
00:59SgeoBeyond the fun shakiness further out in the world
00:59amalloyor b∈{NaN, ∞, -∞}
01:00SgeoCan I have two namespaces each of which uses a var defined in the other?
01:00ivanprobably with resolve
01:00SgeoWithout resolve, I mean
01:01cshellcircular deps?
01:01amalloywell, yes and no. you can't use the vars directly, but they can be passed in from some third namespace that depends on both of those
01:01Sgeo:/
01:02SgeoEh, my usecase is literally just one def that I could easily rewrite
01:02Sgeoin the other namespace
01:10rattboibbloom: I'm having issues w/ the code you posted. The inner let defines grid, but then it is attempted to be used outside the let.
01:16mindbender1,(set? {1 1})
01:18ivan&(set? {1 1})
01:18lazybot⇒ false
01:18ivan&(set? #{1 1})
01:18lazybotjava.lang.IllegalArgumentException: Duplicate key: 1
01:19mindbender1(set {1 2})
01:19mindbender1&(set {1 2})
01:19lazybot⇒ #{[1 2]}
01:19mindbender1i think this is inconsistent
01:20ivanyou're passing a map to set
01:20mindbender1yes
01:20ivan&(set {1 2 3 4})
01:20lazybot⇒ #{[3 4] [1 2]}
01:20metellus&(vec {1 2 3 4})
01:20lazybot⇒ [[1 2] [3 4]]
01:22mindbender1#{{1 2}} => #{{1 2}} but (set {1 2}) => #{[1 2]}
01:23mindbender1&(type (first (set {1 2})))
01:23lazybot⇒ clojure.lang.MapEntry
01:23mindbender1ok
01:23bbloomrattboi: d'oh sorry
01:25bbloomrattboi: but it's an easy fix, move the vector into the comprehension https://www.refheap.com/paste/6767
01:25amalloymindbender1: you're making it unnecessarily complicated. (set x) doesn't create a new set containing the element x, it creates a set containing each element of x
01:25mindbender1amalloy: example?
01:25amalloy&(set 1)
01:25lazybotjava.lang.IllegalArgumentException: Don't know how to create ISeq from: java.lang.Long
01:26amalloy&(set [1])
01:26lazybot⇒ #{1}
01:26mindbender1I passed a map
01:26mindbender1not a list
01:26metellusmaps are key,val pairs
01:26mindbender1ok, a list of pair
01:27mindbender1thanks
01:28Sgeo,`foobar/baz
01:28rattboibbloom: awesome. I'm finally getting somewhere :)
01:28Sgeo&`foobar
01:28lazybot⇒ clojure.core/foobar
01:28Sgeo&`foobar/baz
01:28lazybot⇒ foobar/baz
02:13amalloydoes anyone know what IRC channels ztellman hangs out in? i thought he had #lamina or something, but that's empty
02:52alex_baranoskyare sorted-maps quicker to do lookups in?
02:53amalloyslower, usually
02:58bbloomalex_baranosky: the advantage of sorted-maps is the ability to use subseq on them and walk a key range -- it's an index
02:58bbloomalex_baranosky: similarly for sorted sets
02:59bbloomamalloy: also, aren't tree maps generally more space efficient?
02:59alex_baranoskygenerally indexed things are quicker to do lookups from, is that also true of sorted-map?
03:00amalloythey might be smaller, i suppose. i doubt it's a noticeable fraction of the total size
03:00bbloomalex_baranosky: hash-maps have unsorted keys and O(1) complexity lookups. tree-maps have sorted keys and logarithmic complexity
03:00alex_baranoskybbloom: thanks for the info
03:01bbloomalthough i may be wrong about O(1) for the immutable hash maps in clojure
03:01bbloommy data structures are a little rusty :-)
03:01bbloomalex_baranosky: but yeah, if you need to do a prefix match or something, you can use a sorted map
03:02bbloomalex_baranosky: or if you want to walk the keys started from a particular entry
03:02bbloom&(doc subseq)
03:02lazybot⇒ ------------------------- clojure.core/subseq ([sc test key] [sc start-test start-key end-test end-key]) sc must be a sorted collection, test(s) one of <, <=, > or >=. Returns a seq of those entries with keys ek for which (test (.. sc comparator (compare ek key)) 0) is true nil
03:03alex_baranoskybbloom: I plan to create a lookup table where the key is [start-timestamp end-timestamp] and the value is the result of a calculation.
03:03amalloybbloom: clojure's hash maps are O(log32(n)), which for any value of n that can fit in a computer is a small integer
03:04bbloomamalloy: i figured: i knew they were red black trees, which means logs of course
03:04bbloomtree screams log :-)
03:04bbloomalex_baranosky: do you plan to look up by an exact key match?
03:05amalloyhuh? you asked about hash maps, and i answered hash maps, which are not red/black
03:05bbloomamalloy: gah, sorry
03:05alex_baranoskybbloom: yeah, exact match, so sounds like hash-maps will be good for me here, right?
03:05bbloomright, that's the default type of map
03:06bbloomamalloy: the hash maps are trie's right?
03:07amalloyyes, although the difference between a trie and a tree has never made sense to me
03:07alex_baranoskybbloom: yep, I'm not that noon :)
03:08bbloomheh, trie just means a prefix tree
03:08bbloomafaict
03:08amalloyoh, does it? that's simple enough then
03:08bbloomamalloy: http://en.wikipedia.org/wiki/Trie
03:08alex_baranoskyare you two at the COnj this yeaR?
03:08bbloomi won't be
03:09alex_baranoskyI almost decided to come, but chickened out of paying for it :)
03:09amalloyno
03:10alex_baranoskyI should plan harder for next year
03:10amalloyif i were at the conj i definitely would not be on irc at this hour
03:10alex_baranoskyamalloy: good point
03:11bbloomsince we're talking data structures, i'm gonna out the results of my wikipedia-ing for the sake of my own memory
03:11bbloomtypical mutable unsorted maps are hash tables, which do have O(1) lookups
03:12bbloomtrees, by their nature, provide log lookups
03:12bbloomclojure's hash-map is a trie, since it is assumed that hash codes will be uniformly distributed, the tree should be well balanced
03:12bbloomtries are just prefix trees, which is fundamentally the same thing as a sorted tree
03:12bbloombut clojure's sorted-map is a red black tree
03:12bbloomwhich is a special kind of sorted binary tree that is self balancing
03:13bbloomthat's the interesting bit: since the keys can be anything (ie non uniform) then you need to pay some extra cost for balancing the tree
03:13bbloomso RE: the memory usage amalloy, i doubt the sorted maps are more memory efficient
03:14bbloomit would likely be true that a mutable TreeMap would be more memory efficient than a mutable HashMap
03:14bbloombut i have to assume that red black trees have the same complexity, but larger constants in both time and space when compared to tries
03:14bbloomhopefully that makes sense / is correct :-)
06:04ChironHi guys, would you please have a look at https://groups.google.com/forum/?fromgroups=#!topic/clojure/3XkAhC7gUP8 ?
06:07clgvChiron: is that your question?
06:08Chironyes
06:08clgvhave a look at the doc of `tree-seq`
06:09Chironi did, but i don't really understand how to use it in my case
06:10Chironi didn't get why the guy who answered, used map? function
06:12clgv,(doc tree-seq)
06:12clgv&(doc tree-seq)
06:12lazybot⇒ ------------------------- clojure.core/tree-seq ([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). ch... https://www.refheap.com/paste/6773
06:12clgvas you see there, he uses `map?` as the function that decides when to branch.
06:13clgvso that function will call the children function on every map of that tree structure
06:14Chironyes but in my snippet, i didn't mention any thing about maps .
06:15clgvyou did. you had the following keyword access: (:children input)
06:15Chironhmmm
06:15Chirontrue
06:17clgvso if you had a tree of maps you could use laurents suggestion. if you have something similar but not build of maps then you can adapt that sugggestion
06:17Chironmy original snippet is ok ?
06:17Chironthe very first post
06:19clgvwithout context yes.
06:20Chironcan i change (tree-seq map? :children input) to something like (tree-seq is-instance-of-class2 :children input) ?
06:21Chironso if it is instance of class 2 , call :children , if not , do nothing , just pass it to the result seq
06:21clgvwhy don't you try? ;)
06:22Chironwell true, just chatting :)
06:23Chironjust one more thing please, my original snippet . it is not going to consume the stack and throw stack overflow in some cases ?
06:24clgvyes it will
06:25clgvit consumes stack, but if your tree is not too deep you probably wont get a stack overflow
06:25Chironi see
06:27clgvjust try it with representative worst case data
06:29Chironoki
06:29Chironthanks!
07:26mpenetibdknox: in jayq.util/clj->js is there a specific reason for using coll? instead of sequential? (even tho there is a check for maps before, the later would seem more appropriate)?
08:01jweissi'm trying to figure out why i can change the print-method for a function object using ^{:type ::foo} metadata, and this also changes the dispatch for pprint. but if i do the same thing for a vector, it only affects prn, not pprint.
08:08tgoossensis it idiomatic to use java enums in clojure. Or do you just give a keyword (which i think is allright)
08:08tgoossensconcrete example. In clojure i'm making some kind of game. A "robot" can have an orientation (north, west, etc)
08:09tgoossensin java i would use an ENUM for that orientation
08:09tgoossensbut in clojure
08:09ucbtgoossens: keywords or symbols are most idiomatic I'd say
08:09tgoossensi just used :north, :south, etc
08:09ucbtgoossens: especially keywords
08:09tgoossenswhich i think is fine
08:09tgoossensjust wanted a 2nd opinion
08:09ucbI'd +1 keywords
08:09ucbtgoossens: I've also seen people use symbols directly, which is also fine
08:11tgoossenshmm
08:11tgoossenskeywoards are clearer i think
08:12tgoossensyou can see that it is not a function
08:12ucboh, I understand that, I'm only saying what I've seen done
08:12tgoossensoh yeah
08:12tgoossensone thing
08:12tgoossensturning clockwise
08:12tgoossens:north -> :east , :east -> :south etc
08:12tgoossenscounter clockwise
08:13tgoossensis the inverse mapping
08:13tgoossenscurrently i have
08:13tgoossens(inverse-orientation :north) -> :south
08:13tgoossens(anticlockwise : north ) == (inversre-orientation (clockwise :north))
08:14tgoossensis that ok. Or should I use some kind of bimap (not sure if that exists)
08:15ucbtgoossens: the inverse orientation and rotation are two different things; I wouldn't conflate them together
08:15ucbmaybe I'd have (inverse :nort) ; :south
08:15ucband (rotate-right :nort) ; :east
08:15tgoossenshmm
08:16ucbunless you want (inverse ...) to be (rotate 180 ...)
08:17tgoossensgot to go : ( (college)
08:17tgoossensthanks already
08:18ucbno worries
08:44borkdudeI had an idea, but realized this idea must have come up before. Some people like LaTeX because what comes out of it looks beautiful. The LaTeX code itself isn't really beautiful, but the end results justifies it. What about applying the same approach to Clojure? So typing it in one half of the instarepl results in nicely looking code (without lots of parens) on the right?
08:45borkdudeNot that I hate parens, but Clojure code could maybe be formatted into something more beautiful looking
08:47borkdudeibdknox maybe this is a cool idea for lighttable?
08:50Scriptorborkdude: it's a matter of just getting used to it :)
08:51Scriptorthe parens are nowhere near as jarring as they used to be for me
08:51borkdudeScriptor don't get me wrong, I am used to it. Common Lisp since 2004, Clojure from 2009 on
08:51Scriptorah
08:52Scriptorcould it be done just by modifying the syntax highlighting?
08:52luciani've pondered whether something more like yaml for data structure could work for a homoiconic language without redundant separators
08:52Scriptoror would it rearrange the code as well (for better whitespace and whatnot)
08:52borkdudeScriptor but being able to view the code in multiple ways, like in a LaTeX-ish pseudocode mathematics book kind of style could be nice
08:53lucianthere's sweet-expressions for schemes, but it does too much i feel
08:53Scriptorhmm
08:55borkdudeemacs does this already (in some modes?) by replacing fn with the lambda sign
08:56lucianfor me, the redundancy between parens and indentation is the annoying bit
08:56luciani have the same feeling when i write in a { } language
08:56Scriptorwhitespace-aware lisp has been done before
09:06borkdudegtg
09:11ivenkysgents - (defmulti encounter (fn [x y] [(:Species x) (:Species y)])) - what is :Species in this ?
09:14ivenkysi understand encounter is a multi-method and takes a function with 2 args as params - but i dont get what :Species does here
09:47andrewmcveigh|woivenkys: :Species is just a keyword there.
09:48Bronsabut it's being used as a function
09:48Bronsaso (:a x) is just like (get x :a)
09:48andrewmcveigh|woBronsa: indeed, keywords can act as functions
09:48ivenkysandrewmcveigh|wo: Bronsa : does this mean the "assumption" here is that fn takes two maps as params ?
09:49Bronsayes
09:49andrewmcveigh|woyep.
09:49Bronsawell, more generally, a clojure.lang.ILookup i think
09:49ivenkysBronsa: andrewmcveigh|wo : that was the missing link - thanks gents
10:11TimMc,(- Double/POSITIVE_INFINITY Double/POSITIVE_INFINITY)
10:12Iceland_jack&(- Double/POSITIVE_INFINITY Double/POSITIVE_INFINITY)
10:12lazybot⇒ NaN
10:44TimMcivenkys: Don't assume gender.
10:48duck1123Bmt^MOBv
10:48duck1123at least that wasn't all the password
11:07scottjhas anyone seen any summaries/notes on rich's keynote?
11:25clgv&(+ Double/POSITIVE_INFINITY Double/POSITIVE_INFINITY)
11:25lazybot⇒ Infinity
11:32seangroveAny word on whether Domina elements can be passed to the google closure library?
11:35seangroveIt seems that Domina elements are a special object in Javascript, and the Google Closure libraries are expecting standard html elements
11:37seangroveAh, need to use domina/single-node
11:43Stoogehello :)
11:43mjwhittgreetings :)
11:44Stoogedo you have any good tutorials/books/video clips/exercises for beginners?
11:45joroStooge: I'll recommend http://www.clojurebook.com/, and then experimenting with repl using (doc and (source
11:46Stoogethanks :)
11:53TimMcStooge: http://clojure-doc.org/ is also coming along
11:54TimMcMost pages aren't complete yet, but there's already some really good stuff.
11:55Stoogeyou mean there are lots of undocumented functions? :p
11:56AdmiralBumbleBeeStooge: are you willing to buy a book?
11:56Stoogeofc not :)
11:56Stoogei need money :)
11:57AdmiralBumbleBeehttp://java.ociweb.com/mark/clojure/article.html
11:57AdmiralBumbleBeethat's where I started
11:57seangroveGoodness me, the google closure library does not lend itself well to clojure idioms
11:57seangroveMore and more impressed with the approach of Domina
11:58Stoogek
12:00joroDo you use Clojure in your daily work?
12:03duck1123I tried using Domina, but I had issues with one of the goog.dom namespaces or something. (this was a while ago) I've been using Jayq/jquery. Is there anything that domina offers that might make it worth switching?
12:04Stoogeduck1123 ? :P is this related to closure at all? :p
12:06duck1123Domina and Jayq are Clojurescript libraries.
12:06Stoogek sorry :P
12:06Stoogenever heard about them :P
12:06ivenkysTimMc: hmm good point - my default assumption might be incorrect - i stand corrected (at least on this channel)
12:06duck1123jayq is a wrapper around jquery, domina (IIRC) is a wrapper around the Google Closure dom stuff
12:18seangroveduck1123: It does seem to lend itself much more towards clojure idioms, it's tiny, and extendable to lots of other libraries
12:18seangroveI've certainly come around to the micro-library approach, domina fits well
12:19seangroveBut I was using jayq beforehand, which is certainly great as well
12:21UrthwhyteHaving a StreamClosed error when trying to write out to a file with the following code: https://gist.github.com/5490934e9720abc5b131
12:21Urthwhyteam I meant to have a doseq or something?
12:22hiredman~map
12:23hiredmanclojurebot: ping
12:24alexnixonUrthwhyte: map returns a lazy sequence, which is evaluated *after* your with-open scope has closed. So you need to force evaluation before the with-open closes. So yes, doseq would be good here.
12:25hiredmanclojurebot: ping
12:25clojurebotPONG!
12:26hiredmansometimes you can just hear the jit spinning
12:26Urthwhytehaha
12:26UrthwhyteOf course >< - thank you alexnixon
12:39zodiakwhy does compojure destructure a request in a defroute ? is it jst for clarity when defn a route ?
12:40zodiakI mean, I understand the functionality, jst wondering the rationale
12:40mpenetzodiak: you are free not to do it in the route definition
12:41zodiaksurely.. I guess I was wondering, why is it even "there" ?
12:41mpenetzodiak: it is handly for extremely simple "controller", but gets hairy imho when you need to use a large number of arguments from it
12:41zodiakjst so it's not passing a whole hash-map/dict around ?
12:41zodiakmpenet, aaahh
12:42zodiakso, it's part of keeping the function definition 'concise' or 'clear' to other people ?
12:42clojurebotis there a function that is somewhat similar to partition, except that it creates a max number of groups based on a number
12:42zodiakas then you know it's using (say) params etc instead of 'large hash-map'
12:42mpenetzodiak: yep
12:42zodiakmpenet, gotcha :D
12:43zodiak(this maybe starting to make sense. vunderbar ;)
12:45zodiakclojurebot, I am guessing you would have to write on using partition-by
12:45clojurebotPardon?
12:45zodiakbah.. someone talking via bot.. awesome :P
12:49antoineBhello, how to use the keyword this in clojurescript?
12:50sahadevhello, is this the right place ask clojure newbie questions?
12:50antoineByes
12:52sahadevantoineB: thanks. when I run, (take-while #(< % 100) (fib 1 1)), I get all fib numbers less than 100, as expected. However, when add another condition, (take-while #(and (< % 100) (even? %)) (fib 1 1)), I get an empty list as the result. why?
12:53sahadevif I rewrite it as (filter even? (take-while #(< % 100) (fib 1 1))), it works as expected.
12:53metellus,(fib 1 1)
12:53clojurebot#<CompilerException java.lang.RuntimeException: Unable to resolve symbol: fib in this context, compiling:(NO_SOURCE_PATH:0)>
12:53sahadevmetellus: fib is another function already defined. (defn fib [a b] (cons a (lazy-seq (fib b (+ a b)))))
12:54metellusok, then the first element of the list is 1
12:54metelluswhich is odd, so take-while stops immediately
12:54antoineBshachaf: take-while ends when it encouter a false
12:55mpenetantoineB: in cljs you can reach this with the this-as macro
12:55antoineBshachaf: (filter #(even? %) (take 100 (fib 1 1))
12:56sahadevantoineB: the filter solution works. (filter even? (take-while #(< % 100) (fib 1 1)))
12:57sahadevbut, i would like to understand what's wrong with the take-while solution.
12:57AndRsahadev: that's because filter does not stop on false, it takes *all* members from the collection for which the predicate is true
12:57AndRtake-while only takes members until it finds one for which the predicate is true
12:57metellus,(doc take-while)
12:57clojurebot"([pred coll]); Returns a lazy sequence of successive items from coll while (pred item) returns true. pred must be free of side-effects."
12:57metellusAndR: you mean until it finds one for which the predicate is false
12:57AndRcompare: (take-while odd [1 2 3 4 5]) and (filter odd [1 2 3 4 5])
12:57AndRyes, sorry :P
12:58sahadevI see.
12:58mpenetantoineB: (this-as that (jq/val (jq/$ that) ))
12:59antoineBmpenet: ok thanks
13:00mpenetit's also possible with (js* "this"), but not advised, as js* is an internal thing and could change/disapear
13:01sjlIs there a way to make drip work with Leiningen yet?
13:01sjlI set the LEIN_JAVA_... thing but drip creates a new JVM every time I run a lein command
13:02sahadevthanks all.
13:06sahadevI am currently running emacs + nREPL. Using this setup, I can write small snippets in emacs, and execute them using C-c C-e. How do I run the script from the command line?
13:06sahadevlooking the process list, it looks like the repl is being run by leiningen.
13:07sahadevall I want to run is some form of: clojure script.clj
13:09sahadevah, i managed to find the right incantation :)
13:09babilensahadev: You can use "lein run" (cf. https://github.com/technomancy/leiningen/blob/master/doc/TUTORIAL.md) or create an überjar and execute that. Both approaches are discussed in the TUTORIAL
13:11babilensahadev: There are also hacks/tools such as https://github.com/Raynes/lein-bin and other ways... I am sure that other have some suggestions as well.
13:11sahadevbabilen: thanks.
13:12babilensahadev: All that being said: I haven't yet found a *single* approach to create well-behaved executables easily
13:13sahadeva lot of the docs assume familiarity with java environments. not being a java guy, sometimes I have trouble following things that might be very obvious to a java programmer.
13:13sahadevis there a tutorial/doc for "getting started with clojure for non-java programmers"?
13:16zodiaksahadev, not really.. but.. to be fair.. clojure is pretty far removed from java in the first place
13:17babilenWasn't there a nice/good "Java for Clojurists" article somewhere?
13:17sahadevzodiak: I am not looking for help with the clojure language per se. but, with the environment/toolsets to help me get started quickly.
13:17babilenAnd why is it not possible to query the bots in a /query (they don't answer)
13:18zodiaksahadev, I actually found the clojure book by oreilly to be helpful .. but it depends on what you want to do with clojure
13:19mycelloandisahadev: most people use emacs and nrepl or swank for their toolset
13:19babilensahadev: I wouldn't concern myself *too* much with it for now. You don't need to know much about the Java ecosystem if you use leiningen ... It *does* help to know the Java standard library though.
13:19zodiakif you want web programming, look at compojure and ring. you will bump into leiningen at somepoint (go for lein2)
13:19babilensahadev: I second the recommendation for "Clojure Programming" (http://www.clojurebook.com/) btw
13:19zodiakgui I would say seesaw and ignore swing ;)
13:20sahadevfor example, I have a very simple, short clojure script. and i want to run it from command line. but most of the docs I found talk about tools (like lein) that assume certain things. for example, presence of project.clj, which I am sure is very convenient, if I am working on a real project.
13:20babilenSo: Is anybody aware of a good way to write command line applications in Clojure?
13:20zodiakand I use vim (good old vim ;) for editing .. although some people use eclipse or emacs (same thing! *zing*)
13:20babilenI also use vim (vim vimclojure + lein tarsier) and am very happy with it
13:21AndRsahadev: you probably want to make a project for anything you don't do directly from a repl
13:21mycelloandisahadev: "lein run" is the easy way
13:21zodiakbabilen, I am afraid all I can think of is lein2 uberjar and then the usual java -jar song and dance
13:21sahadevzodiak: babilen: I just got the O'Reilley book. looks promising.
13:22zodiaksahadev, you will have a learning curve if this is your first lisp
13:22AndRsahadev: for a single script, assuming you have clojure.jar somewhere on global classpath, you can say java -cp `path_to_clojre.jar` clojure.main /path/to/script.clj
13:23zodiakbut, like anything worth doing, it's going to take a while to get into the groove
13:23babilenzodiak: I've just stumbled over https://github.com/kumarshantanu/lein-exec but have no idea if it is any good
13:23sahadevzodiak: I dabbled a little with emacs-lisp and scheme in the past, but I am very much a newbie when it comes to lisps. but, I am looking forward to learning it.
13:23babilenzodiak: I am thinking of something like that combined with a tool such as drip that minimises the pain of starting the program over an over again
13:24zodiakbabilen, not sure. never used it. sorry.
13:24sahadevAndR: that's exactly what I ended up (after pruning most of the options in the lein command line that is running the repl in my emacs session)
13:24babilensahadev: I would recomend to start by reading the leiningen tutorial and to take a look at interesting plugins on https://github.com/technomancy/leiningen/wiki/Plugins
13:25babilengtg, good luck!
13:25zodiaksahadev, well.. grab lein (lein2 preferrably since it really is the future), lein2 repl (bring up repl/command line) and then .. read for the most part and play around
13:26zodiakremember, inside the repl you can lookup docs (doc str) or search (find-doc "str")
13:26AndRsahadev: I recommend making a lein project, doing work with lein repl, then to make the executable do `lein uberjar`, for which you can then do 'drip my.jar' and it should run your main class
13:26sahadevzodiak: my "lein --version" says 2.0.0-preview7. that's what you mean by lein2, right?
13:26AndRyes
13:26zodiaksahadev, yes sir/madam
13:28zodiakgood show :) any questions, feel free to ask. I don't think there are too many ego's/prima donna's around this channel ;)
13:28AndRit seems lein is not integrating cleanly with drip (there are a number of bugs in drip saying so), so `lein run` will not take advantage of drip I'm afraid
13:28zodiakjark is another thought, or cake
13:28zodiaknot that I have ever used either, right enough
13:28sahadevzodiak: thanks :) that's encouraging.
13:29sahadevwhat's drip?
13:29zodiaksahadev, it's an 'always on' jvm, so when you start your clojure or java program, there isn't a huge wait time in the jvm starting up
13:29zodiakbasically ;)
13:30mycelloandiis drip like nail gun?
13:30sahadevah, i see.
13:30zodiakmycelloandi, mostly, yes.
13:31sahadevthanks a lot, all. i think i'll be dropping by often.
13:31zodiaksahadev, surely.. I would suggest jst idling in here.. never know what you may learn
13:32sahadevzodiak: yep. i agree.
13:45jonasenI created a lein plugin for codeq: https://github.com/jonase/quantize
13:46jonasenIf someone would try it and see if it works I'd be thankful
13:54mudgeHello, I am trying to use Clojure with a Java Web Start application. By default Clojure uses the context classloader but clojure-1.4.0.jar isn't in there, so I am getting this error: Caused by: java.io.FileNotFoundException: Could not locate clojure/core__init.class or clojure/core.clj on classpath
13:55mudgeclojure-1.4.0.jar exists in the current classloader not the context classloader. I would set the context classloader to the current classloader, but I don't have control of the Java code to do that.
13:56mudgeSo I'm thinking that I should go into the source of Clojure and change *use-context-classloader* to false and rebuild Clojure and use that. I'm wondering if that is the best thing to do and if that might cause any problems.
13:57zodiakmudge, having been down the clojure webapp and jetty path very recently, have you tried using an uberwar ? it sounds like you are only using a war
13:58zodiak(if you get my meaning)
13:58jodaroits amazing what rm -rf'ing your ~/.m2 can fix
13:59mudgezodiak: I'm building a module for an existing system which has it's own unique installation/deployment scheme. I create jar files and zip them together with a configuration file and then httpPost them to the application.
14:00zodiakO_o
14:01zodiakmercy.. that's.. urm.. yeah
14:01mudgeThe problem that I have is that my clojure-1.4.0 is in my current classloader and not in my context classloader, but by default Clojure only looks in the context classloader
14:02zodiakchanging clojure source to fix a (pardon my french) "weird deployment mechanism" is not the ~best~ idea
14:02mudgeI would set the context classloader to the current classloader by I dont' have access to the Java to do that. So I'm thinking that the only way to do this is to tweak the Clojure source so it doesn't look in the context classloader by default. But not sure if that is the best thing to do or not.
14:02zodiakbut, that's jst me
14:02mudgezodiak: I agree, but I don't know of any other way which is why I'm writing here.
14:07zodiakmudge, yeah.. sadly.. I don't know of anyway to do what you want to do :\
14:08TimMczodiak: clojurebot responds to something like 1 in 1000 messages as if it were the target.
14:09TimMcwith strange results
14:09zodiakTimMc, no joke :D
14:12TimMczodiak: And if your message contains " is " or " are " it stores it as a factoid, which then may get triggered by other messages.
14:12zodiakO_o
14:12zodiakhah!
14:12zodiakkinda cool but.. kinda weird :)
14:12TimMcNot my idea. :-P
14:13mudgeAny idea why *use-context-classloader* is set to true by default?
14:28mudgejust asked a Clojure question on stackoverflow: http://stackoverflow.com/questions/13423048/why-does-clojure-use-the-context-classloader-by-default
14:33znDuffmudge: uhh, the context classloader _is_ the default classloader.
14:33znDuffmudge: ...now, why it doesn't always use _that_ is an interesting question. You might find http://stackoverflow.com/questions/10941330/class-forname-in-clojure-not-respecting-contextclassloader (and its answer) worth reading.
14:34znDuffmudge: short form: the DynamicClassLoader wrapper Clojure provides is necessary to have a per-namespace bytecode cache, and it has to be stored somewhere.
14:35znDuff(provisio: This is from memory, and it was quite a while back that I was actually banging my head on this stuff; memory may have failed a bit since then)
14:36mudgeznDuff: thanks. What would happen if I changed *use-context-classloader* to false?
14:38znDuffmudge: then you get the classloader that Clojure itself was loaded with
14:38mudgeznDuff: I'm compiling (with gen-class) a Clojure application and putting it into an existing Java Web Start application and Clojure-1.4.0.jar is not in the context classloader, it is in the current classloader, so having a problem loading any clojure code
14:38mudgeznDuff: anything bad about that?
14:39znDuffmudge: you might want to look at the answer on the SO question I posted a link to. And maybe the question, too.
14:40mudgeznDuff: I'm thinking of changing *use-context-classloader* to false in the Clojure source, rebuilding it and using that.
14:41mudgeThanks znDuff, that SO post is about what classloader eval uses. It is good to know that eval uses a DynamicClassLoader
14:41znDuffmudge: it's not just about eval, that's just what I used to demonstrate.
14:42mudgeznDuff: I will reread more thoroughly now.
14:47alex_baranoskywhat does ^:constant metadata do ? Anyone got a link to its explanation?
14:48mudgeznDuff: i don't get what you are trying to say in this comment: but the DynamicClassLoader instance bound to clojure.lang.Compiler/LOADER when clojure.lang.Compiler/eval is called matters.
14:56znDuffmudge: Effectively, that comment is duplicative of the answer. Related note: The work that went into that question came out as a patch to clojure.osgi adding support for Apache Felix; if you want to see it in action, that would be https://github.com/charles-dyfis-net/clojure.osgi/blob/master/clojure.osgi/src/main/clojure/clojure/osgi/core.clj
14:56mudgels
14:56lazybotboot dev etc lib media mnt root sbin selinux srv usr
14:59mudgeznDuff: thanks
15:03mudgehow do I get clojure source for 1.4.0?
15:03mudgeI go here https://github.com/clojure/clojure but that is for Clojure 1.5.0
15:03hiredmangit
15:04raekmudge: use the 1.4.0 tag
15:04raek(instead of the master branch)
15:05mudgeraek: I see clojure-4.4.0-beta7.zip, would I download that? It's the latest beta version.
15:05Apage43https://github.com/clojure/clojure/tree/clojure-1.4.0
15:05Apage43https://github.com/clojure/clojure/archive/clojure-1.4.0.zip
15:05Apage43if you want a zip
15:05raekmudge: if you have clones the repo you already have that tag in your clone
15:06raekjust do a "git checkout clojure-1.4.0"
15:07mudgeraek: Apage43: got it, thank you!
15:08mudgeraek: the tags without alpha and beta in them mean that they are production ready?
15:08raekmudge: yes, that's the release version
15:08mudgeraek: thanks
15:09raekusually it's foo-alpha1, fo--alpha2, ..., foo-beta1, foo-beta2, ..., foo-RC1, ..., foo
15:11FoxboronAnyone got any great books on learning Clojure which also contains tasks?
15:11raekweird that there isn't any obvious browse link for the tags at github...
15:11znDuffFoxboron: meaning exercises? Hmm -- the more exercise-focused books are mostly not as good for conceptual learning.
15:12FoxboronznDuff, yes exercises, forgot the word there when i typed it ^^
15:12FoxboronznDuff, i find it better to read and learn by.
15:12raekFoxboron: btw, have you looked at http://www.4clojure.com/ ?
15:12Foxboronraek: havent seen it actually
15:13UrthwhyteI did about 60 4clojure problems and then switched to reading Programming Clojure
15:14UrthwhyteIt's really helpful if you follow some of the people topping the leaderboards - some very beautiful (and hideously terse) solutions will give you insight into the language
15:15Netfeedis it possible to redifine a function in a module?
15:15Netfeedredefine
15:15Mr_BondNetfeed: yes, you can just defun it again
15:15TimMcNetfeed: By modfule you mean namespace?
15:16Netfeedyes
15:16Netfeedeven if it's private?
15:16TimMcPrivate only affects what users of that namespace see.
15:17Netfeedso it's possible to redefine it from another namespace?
15:17TimMcNo, you can't do something like (def other.namespace/foo 5).
15:17Netfeedtoo bad
15:17raekbut you can use 'intern'
15:17TimMcYou would have to switch over to the other namespace first.
15:18TimMcOh yeah, you could use ns interning.
15:18TimMcSounds like trouble though.
15:18amalloyyeah, don't do that. only sadness and spaghetti lies that way
15:18raekNetfeed: the real question is why you want to do this, though...
15:19TimMcamalloy: That's a good mental image.
15:19Netfeedi want to just add some prints to a function in the tower-lib to understand why i get an assert error in it
15:20TimMcI think with-redefs might help.
15:20raekNetfeed: how are you interacting with clojure? a text-based repl? nrepl/slime?
15:20amalloyTimMc: weeping willows with cold pasta draped over their limbs, marinara sauce dripping forlornly to the ground, silent splats nobody can hear
15:21amalloyhm. soft splats scans better
15:21TimMcD: D: D:
15:22Netfeedraek: lein repl i guess
15:23TimMcclojurebot: sadness and spaghetti?
15:23clojurebot<amalloy> weeping willows with cold pasta draped over their limbs, marinara sauce dripping forlornly to the ground, silent splats nobody can hear
15:23TimMcOops, that doesn't include your edit.
15:24raekNetfeed: one way is to modify the defn in an editor, enter the namespace via (in-ns 'foo), paste the new definition in the repl, and then (in-ns 'user) to get back
15:24raekthis gets much simpler with editor integration
15:26Netfeedi'm fairly new to clojure so i'm not really there yet :)
15:26raekanother way is to download the source to the library, add it as a "checkout" in lein, edit the library source code in your working copy and (require 'the-lib :reload) whenever you have made changes
15:26Netfeedwith-redefs helped a bit tbh, cool function
15:29krakoophey all... I wrote my first macro (which serves no purpose besides trying macros) and it kinda works as I expected: (defmacro noob [x] `(prewalk-replace {2 :changed} ~x)
15:30krakoopwhen I run this on, say, : (noob '[(print 1 2 3) (((print 2)))]) (once again, this serves no purpose besides trying to understand) I get what I expect: [(print 1 :changed 3) (((print :changed)))]
15:31TimMckrakoop: It's not really serving as a macro.
15:31TimMcTake off the ` and the ~ and the ' in the input.
15:31krakoophowever I'd now like to replace not '2' with ':changed' (which works fine) but 'print' with something else. For example I'd like to replace 'print' with 'tst'.
15:31raekkrakoop: that definition is essentially the same as (defn noob [x] (prewalk-replace {2 :changed} x))
15:32krakoopI know, I know. That's not my question. My question is how can I replace not '2' with ':changed' but 'print' with another function name.
15:32krakoop; )
15:32bbloomkrakoop: at the time the macro is evaluated, x is a list
15:32raek(prewalk-replace {'print :changed} ...)?
15:33bbloom&(let [x '(print :changed)] (cons 'not-print (next x)))
15:33lazybot⇒ (not-print :changed)
15:34bbloomkrakoop: or, with the syntax quote:
15:34bbloom&(let [x '(print :changed)] `(not-print ~@(next x)))
15:34lazybot⇒ (clojure.core/not-print :changed)
15:34amalloy(defmacro noob [x] (prewalk-replace {'print :changed} x)
15:34krakoop@raek: {'print :changed 2 :changedtoo} won't work for 'print (but still works for '2')
15:34amalloykrakoop: that's because of what TimMc said. your syntax-quote shouldn't be there
15:35krakoopok but what when I want to do the same in case I need the syntax quote too?
15:35TimMcI think it should still work...
15:35raekkrakoop: the ` is interfering... it adds namespace parts to all the symbols
15:35TimMcaha
15:35amalloyTimMc: no, because `'print is 'clojure.core/print
15:35amalloyand also because he's not postwalk-replacing the form itself, but the result of evaluating the form
15:35TimMcsyntax-quote strikes again!
15:36raekkrakoop: if you want to experiment with postwalk-replace, start with ordinary functions and pass them quoted code
15:36krakoopwell the point of my question is kinda precisely to understand syntax quoting etc. ; )
15:37raekah
15:37raekwell, we can take a look at syntax quote in isolation (you don't have to be in a macro to use it)
15:37krakoop@raek: postwalk-replace is not what I'm interested in... a simple 'replace' example would work too: I mean, I'd be just as confused ; )
15:37raek,`[(print 1 2 3) (((print 2)))]
15:37clojurebot[(clojure.core/print 1 2 3) (((clojure.core/print 2)))]
15:38raekthis is the value that postwalk-replace received in your example
15:38krakoopso how would I modify my map so that it replace print (which is received as clojure.core/print) with something else ?
15:39amalloy!!!! no it's not, raek
15:39raekamalloy: you are right.
15:39amalloyit received [(print 1 2 3) (((print 2)))], but its replace-map was {clojure.core/print :changed}
15:39amalloykrakoop: don't syntax-quote it :P
15:39raekthat makes more sense
15:40krakoopamalloy: oooooh gotcha
15:42estebannso clojure.java.shell/sh seems to hang if the command run prints too much to stdout... has anyone else seen this or is it just me?
15:43mudgezdNuff: I set *use-context-classloader* to false in RT.java, but now I am getting this error: aused by: java.lang.ClassNotFoundException: clojure.lang.PersistentList
15:44mudgeseems like Clojure is still looking in the context classloader even though I set *use-context-classloader* to false
15:47ebaxtI'm trying to understand a lazy fibs example: https://gist.github.com/4090592, I
15:47znDuffmudge: if you're following the OSGi example, I don't think I ever set *use-context-classloader* to false there.
15:48ebaxtI've tried to break down the state of the execution, and I'm wondering if either A or B is correct=
15:48ebaxt?
15:49mudgeznDuff: I'm not following the OSGi example
15:49mudgeznDuff: I have a gen-classed class file that I want a Java application to use -- the source of which java I don't have access to.
15:51Mr_Bondestebann: how long does it have to be?
15:52Mr_Bond,(clojure.java.shell/sh "cat" "/etc/resolv.conf")
15:52clojurebot#<ExecutionException java.util.concurrent.ExecutionException: java.lang.RuntimeException: java.lang.ClassNotFoundException: clojure.java.shell>
15:52estebannlooks like an out of memory exception is failing to bubble up... so bigger than you have heap space
15:52Mr_Bondah, I see
15:53estebannyou can test it with (clojure.java.shell/sh "cat" "/dev/urandom") pretty easily at least on linux
15:53Mr_Bondyeah, good idea
15:55Mr_BondI guess it would be nice to have an alternate interface to sh, which gave a sequence, instead of it having to first fill up "stdout" variable
15:55estebannI definitely would appreciate it at the moment
15:58Mr_BondI seems supported by http://docs.oracle.com/javase/7/docs/api/java/lang/Process.html#getInputStream(), so you could write your own "sh" using https://github.com/richhickey/clojure/blob/4bea7a529bb14b99d48758cfaf0d71af0997f0ff/src/clj/clojure/java/shell.clj#L63 but I guess there is probably something in clojure.contrib or in the repos for it
16:00estebanncool... should I report this somewhere?
16:00amalloyMr_Bond: see Raynes's conch library. or maybe it's fs? i don't remember which one it's in
16:01Mr_Bondestebann: I think it's expected, but otoh it would be nice to have such a tool in core
16:02Mr_Bondamalloy: nice
16:02Mr_Bondthanks
16:02estebannhuh.. I would have expected to get the Out Of Memory Error
16:03estebannrather than a hung thread
16:03Mr_Bondoh, right. Yeah, that's not good
16:04Mr_Bondmm, it looks like Raynes.fs/exec could be an option
16:04amalloyit's an OOME on a different thread
16:04Mr_Bondah, no it just wraps clojure.java.shell/sh
16:05amalloythere's no real way to catch that given the rubbish implementation of sh, as far as i know
16:05amalloyMr_Bond: yeah, you want conch, not fs
16:06Mr_Bondcool, yeah thats more like it
16:07estebannamalloy: cool, loooks good
16:08Mr_Bondthere was a link pasted the other day, about a functional programming book (clojure) on PDF, for a couple of bucks
16:08Mr_Bondanyone happen to remember the link?
16:27alex_baranoskydoes anyone know what ^:constant metadata does?
16:31zodiakalex_baranosky, I ~assume~ the opposite of ^:dynamic
16:31zodiakmarks it as a var but NOT dynamically rebindable
16:31zodiak(guessing here ;)
16:31alex_baranoskyhttp://stackoverflow.com/questions/9162558/how-does-clojure-const-work
16:31TimMcI think the opposite of ^:dynamic is simply the lack of it.
16:32alex_baranoskyit changes the way the code gets compiled
16:32zodiakTimMc, following the python mantra though, explicit is better than implicit so, having a ^:constant would tell me "whoa, this isn't changeable no way no how"
16:33zodiakand anywhere I see ^:constant is with things like pi or tau so .. as I said, guessing :)
16:33TimMcTHis is a question of reality, not desire.
16:33TimMcOh, I see why you said that.
16:34zodiakdynamic would have to be constantly looked up, right ? to check the value, constant should be looked up once (hopefully ;)
16:35alex_baranoskyits actually ^:const not ^:constant
16:35alex_baranoskyI got that one wrong
16:36zodiakwell, shut my mouth then :)
16:37alex_baranoskyso const attempts to embed the var in the code at compile time
16:37alex_baranoskyI just attempted to use ^:const on a simple date format, and found out that detail (since the reader/printer don't know how to handle SimpleDateFormats)
16:39bobryFolks, how should I debug "Uberjar aborting because jar/compilation failed: java.lang.String cannot be cast to clojure.lang.IFn"?
16:39bobryAll I have is a file with an empty -main function, which does nothing.
16:40bobrySo I guess it's not my code which is causing the exception.
16:41zodiakbobry, have you tried calling your main from lein repl ?
16:41bobryI've tried 'lein run' and it seems to work fine.
16:44zodiaktime to pastebin.com I reckon
16:45Foxborondoing some problems on the clojure4 site. Came to problem 22 where i am suppose to count a list without using count.
16:45zodiakfwiw, I almost always use lein repl and then use lib, (main) the sucker
16:45Foxboron#(for [x %] :let [y (+ y 1)] [y])
16:45FoxboronWhy wont this work :3?
16:45Foxboron<- total LISP noob
16:47bobryokay, this is nice, the problem was in the :license field of the 'project.clj' file, which was "MIT", instead of a hash-map
16:47znDuffFoxboron: first, y has no initial binding; second, for loops are like Python list comprehensions, so they aren't really a fit to what you're trying to do here.
16:47bobrytime for a bug report :)
16:47AimHereFoxboron, I think there's about 4 reasons
16:49znDuffFoxboron: ...a for loop just creates a lazy sequence -- it doesn't actually force it to be evaluated -- and it doesn't retain state between steps in that loop
16:49znDuffFoxboron: as a hint, you might look at loop/recur.
16:49Foxboronwas going to ask for hints ^^
16:50FoxboronStarted clojure today and only know Python from before, so its a rather radical change
16:50zodiakFoxboron, also the bracketing in the for loop is wrong ;)
16:50Foxboronbut its actually rather fun
16:50Foxboronzodiak i did notice on the second look
16:50Foxboronspent 4 hours fixing the leining repl....
16:50znDuffFoxboron: ...actually, I said "like Python list comprehensions", but they're actually closer to genexps, in terms of being lazy.
16:51Foxboronsomething bugged with the path and the 2nd version on windows FYI
16:51raekFoxboron: when you're using loop and recur, imagine that you are only allowed to update your variables at one point (at the end of the loop)
16:51FoxboronznDuff, i havent actually read up what it means by being "lazy", so will look into that aswell :)
16:51znDuffFoxboron: Have you tried Light Table for Windows, by the way?
16:51FoxboronznDuff, oh damn right.
16:51FoxboronI was going to, totally forgot
16:52Foxboronanother reason why i actually started looking at Clojure, i found the syntax rather pleasant looking at when i watched the demo.
16:52purpleguy it is
16:52purpleguythe guy who writes it gave a talk just day before yesterday
16:52purpleguyhere at my uni
16:53Foxboronthere is a...
16:53znDuffpurpleguy: I've seen the new version, and I still don't think it's there yet.
16:53purpleguybasically, he's got so many features he's implementing
16:53FoxboronJavaScript conf going on where they will be presenting some stuff using LightTable
16:53Foxboronwill be livestreamed
16:53FoxboronznDuff, i won't really judge it before its out.
16:53Foxboronanyone seen the talk which the concept was based on?
16:54znDuffFoxboron: With the interactive game? A great many of us have.
16:54Foxboronsaw it first time yesterday actually.
16:55Foxboronalso, what is considered the best site for clojure documentations? i use clojuredocs.org but i find it rather messy and all over the place
16:55dakroneFoxboron: there are multiple sites, perhaps try clojure-doc.org or doc.clojure.org
16:55AimHereI find that clojure cheat sheet to be the most useful document out there
16:56AimHereAt least as a reference
16:56Foxboronlooked at it, but its not really fit when you dont know what you are looking for
16:57AimHereWell perhaps, though I do recall clicking on likely looking functions to see what's out there at times
17:24jodaroi wish i was conjing
17:26Foxboron(#(loop [x 0 lis %] (when (= (peek lis) nil) (x))(recur (pop lis) (inc x))) '(1 2 3 3 3 4))
17:26Foxboronam i on the right track now <.<?
17:26FoxboronFor those who didnt see the chat above: Trying to count items in a list without using count.
17:28znDuffFoxboron: that's quite a lot more involved than what you need.
17:29Foxboroni honestly don't doubt that.
17:29znDuffbut that said, it's very much on the right track.
17:29Foxboronany hints on whats wrong?
17:29Foxboroni find it rather hard figureing out the error messages in Clojure. Kinda anoying
17:30TimMcFoxboron: (x) calls x as a function with no args.
17:30Foxboroni want x as a variable, trying to search around examples doing that
17:30TimMcso you should gets some "expected an IFn" msg.
17:30TimMcFoxboron: You want the value x?
17:30Foxboronjava.lang.ClassCastException: java.lang.Integer cannot be cast to clojure.lang.IPersistentStack (NO_SOURCE_FILE:0)
17:30TimMcJust write x.
17:31TimMcFoxboron: You have your recur in the wrong order, then.
17:31FoxboronTimMc, i want x as a variable for counting. Basically x = 0
17:32Foxboronits funny, its like trying to learn programming all over again :P
17:32raekFoxboron: the predicate for checking whether a seq is empty is 'empty?'. peek looks at an element in the list.
17:32Foxboronoh, i didnt know that actually
17:33raekFoxboron: the general method you are using is right. but as TimMc said you have the arguments reversed in the recur form
17:33raekloop has x and list, but recur has list and x
17:33TimMcFoxboron: I don't think you read what I wrote: (x) calls x as a fn. Note the parens.
17:33raek,(empty? [])
17:33clojurebottrue
17:33raek,(empty? [1 2 3])
17:33clojurebotfalse
17:33Foxboronhah, even a repl bot here.
17:33raek,(rest [1 2 3])
17:33clojurebot(2 3)
17:34Foxboronraek, i got a repl setup here too :)
17:34FoxboronTimMc, then i asked how i can define x as a variable inside the loop. But i never really got a hint in the right direction :P
17:34raekso, there's some examples of the sequence api
17:34Foxboronthanks raek ^^
17:35raekyou have been using the stack api which is related
17:36raekfor sequences peek=first and pop=rest
17:36hiredman,(pop ())
17:36clojurebot#<IllegalStateException java.lang.IllegalStateException: Can't pop empty list>
17:37raekyou can think of sequences as "iteration" in the form of data
17:37Foxboroni see, does make sense
17:46DaReaper5Hi, what is the best/proper way to support long polling/push from a client (front end javascript) on a clojure web server backend
17:47DaReaper5I am having trouble finding a library or approach that will support this
17:47DaReaper5This is the closest I have found: https://github.com/shenfeng/async-ring-adapter
18:05Foxboronwohoo, did it
18:06Netfeedis it possible to split a keyword?
18:06raekNetfeed: into namespace and name parts?
18:07DaReaper5Does anyone know the best way to facilitate long polling on a clojure web server?
18:07DaReaper5Should I use threads and listeners
18:07SgeoWhat's the best way to store a chunk of binary data?
18:07Netfeedjust the parts, (name :foo/bar) returns "bar", and i'd like the :foo too
18:07SgeoA vector of bytes?
18:07mattmoss,(namespace :foo/bar)
18:07clojurebot"foo"
18:08Netfeedthanks
18:08SgeoUh.
18:09SgeoI'm playing with byte on Try Clojure
18:09Apage43Sgeo: depends where it comes from and where you're gonna put it
18:09SgeoWhy are they signed?
18:09Apage43all java primitive number types except char are signed
18:09SgeoThat's... uh... brillant
18:09raekSgeo: that's the way they are printed by default
18:10SgeoAnd read too, apparently
18:10Sgeo,(byte 0xFF)
18:10clojurebot#<IllegalArgumentException java.lang.IllegalArgumentException: Value out of range for byte: 255>
18:10Sgeo,(byte 0x7F)
18:10clojurebot127
18:10Sgeo,(byte -0x7F)
18:10Apage43yep, can't do that.
18:10clojurebot-127
18:11Sgeo,(char 0xFF)
18:11clojurebot\ÿ
18:11Sgeo,(char 0x100)
18:11clojurebot
18:11flying_rhinohello folks
18:11raekthe JVM does not have separate types for signed and unsigned primitives
18:11SgeoAre chars unicode codepoints, at least? A little bit of sanity in the Java prims?
18:11raekyes, char != byte
18:11flying_rhinodoes anyone have a list of all immutable types available to me in clojure?
18:11raekbyte is int8_t and char uint16_t
18:11flying_rhinoall data types i mean
18:12Apage43Sgeo: not.. really. char is really a unsigned 16 bit number, which can't cover all of unicode
18:12Sgeoraek, uh, 16 bits is not enough to represent all unicode codepoints.
18:12flying_rhinothere's vector, hash table, linked list, what else is there?
18:12raekSgeo: the JVM uses UCS2
18:12SgeoCan Java strings handle codepoints outside the BMP?
18:12Apage43java's internal string representation is UCS-2
18:12SgeoI... uh
18:13raekso code points in the astral planes are represented using two JVM chars
18:13Apage43Sgeo: yep, they're just more than one "char" long, awkwardly
18:13SgeoWouldn't that be UTF-16 not UCS-2?
18:13Apage43JVM predates UTF-16. It's "close enough" most of the time though.
18:13DaReaper5oh man still having an issue here with finding a solution to facilitating long polling on clojure
18:14DaReaper5should i use "add-watch" in conjuction with a thread?
18:14amalloyDaReaper5: i suspect you would get better answers if you told someone what "long polling" is
18:14raekSgeo: sorry. yes I got that wrong. it uses UTF-16
18:14flying_rhinowhat are immutable types (besides vector hash table and linked list) that are available to me in clojure?
18:14raeksurrogate pairs and all that kind of jazz
18:15DaReaper5amalloy long polling is way of facilitating a PUSH to a client from a server
18:15raekflying_rhino: sets and queues
18:15raekand records
18:15amalloyand numbers!
18:15amalloyand strings!
18:15DaReaper5basically (from what i understand) it is just a request that does not respond until the event
18:15raekmutable numbers - now that's a terrible idea!
18:15flying_rhinowhat do queues and records do?
18:15DaReaper5i want to know a good way of waiting for an event and then responding
18:16mattmoss(def 3 4)
18:16mattmossadd-watch
18:16mattmoss?
18:16DaReaper5so this "could" be summed up (if there is no lib for it) as: "How to I do listeners in clojure"
18:16raekflying_rhino: you add elements to one end of the queue and take elements away at the other end
18:16DaReaper5mattmoss but i can't find any good examples of it
18:16DaReaper5:s
18:16flying_rhinoI see
18:16raekrecords could be seen as "optimized" hash maps
18:17raekthat can also implement protocols
18:17mattmossDaReaper5: Sorry... I don't know the mechanics of long polling to be ableto suggest how to set something up.
18:17DaReaper5mattmoss: basically this: i need to wait until something is triggered or happens
18:18DaReaper5i know how to do the whole response part
18:18DaReaper5but how to actually wait for the event in the same thread?!
18:18mattmossWhy same thread?
18:18raekSgeo: since you are entering encoding problem territory, beware of the java methods that convert between bytes and chars without an explicit encoding (and remember to always provide one explicitly)
18:18flying_rhinoraek: thanks. Is it possible to build your own datatypes in clojure (say quad trees) or do you have to do it from java?
18:19flying_rhinoraek: I know how to do it in Java, but have no idea how to do it in immutable language
18:19raekflying_rhino: I think you should be able to do that using defprotocol and deftype (and possibly defrecord)
18:19DaReaper5Its what i need for long polling, basically clojure will reseave the message then wait until something happens to send a responds
18:19mattmossIf same thread... then maybe a future... then block on it with deref and a timeout?
18:19DaReaper5response*
18:19DaReaper5http://stackoverflow.com/questions/6954347/how-to-implement-the-observer-design-pattern-in-a-pure-functional-way
18:20DaReaper5^ has the best example i have found on add-watch
18:20DaReaper5but (possible because of my lack of knowledge of clojure) how would i get the response to be in the same thread. Would i do this:
18:20raekflying_rhino: you'll probably find the datastructure implementations of ClojureScript more interesting than those of Clojure. cljs relies much more on protocols
18:21DaReaper5I think i should do this:
18:21DaReaper5(Thread/sleep 100) then check for event then (Thread/sleep 100) etc
18:21DaReaper5however that is horrible
18:21flying_rhinoraek: clojurescript is that something like scripting lang fro clojure or what?
18:21flying_rhino*for
18:21raekflying_rhino: maybe this is a good example: https://github.com/clojure/data.finger-tree
18:22raekflying_rhino: it's a variant of clojure that compiles to javascript
18:22flying_rhinoraek: nah I like execution speed and js isn't very fast
18:22DaReaper5I should just listen for an event then respond in the same thread
18:23raekflying_rhino: it's interesting in that it relies more heavily on protocols than on host interop (clojure has lots of stuff written in java)
18:23flying_rhinoraek: obviously
18:24mattmossDaReaper5: Why same thread? And same as what... the thread kicking things off, the thread sending the event... ?
18:24raekso in Clojure you have java interfaces for most datatype abstractions but in ClojureScript these are "pure" clojure abstractions
18:24DaReaper5thread initiating the listener
18:25flying_rhinoraek: I see
18:25DaReaper5mattmoss i cant think of any other way where i would respond to a long polling event
18:25raekso, the clojuresctipt data structures may be a little more ideomatic since they are more recent
18:25DaReaper5again long polling is when i do a request to a server and just wait and wait for the event
18:25raekwell, the overall structuring of them
18:25flying_rhinoraek: I see
18:25DaReaper5as the response
18:26mattmossDaReaper5: So put it in a future, then deref it. It will block... or add a timeout so you can periodically do some other task and deref again.
18:26DaReaper5hmm i guess this is where my lack of clojure knowledge shows
18:27flying_rhinoraek: tbh biggest problem I have with clojure is it's singular insistence on fuctional programming. Focus on it is okay, but somethimes you need/want some mutable types.
18:28TimMcflying_rhino: Feel free to use transients, or even arrays.
18:28flying_rhinoarrays? You mean like java array?
18:28raeksure
18:29flying_rhinoI didn't expect clojure to have those
18:29raekwell, you can use java arrays directly from clojure
18:30TimMcThis ain't Haskell.
18:30raekbut you lose the benefits of functional programming, etc
18:30TimMcWell...
18:30raekequational reasoning, thread safety, structural sharing...
18:30flying_rhinocan I also use all other mutable types from java? (not saying that's a good thing, just asking if it is possible)
18:30TimMcone could certainly make an argument about whether functional programming is really about immutable data types.
18:31raek(if you start using uncontrolled mutation in your code)
18:31TimMcflying_rhino: ##(java.util.ArrayList [1 2 3])
18:31lazybotjava.lang.ClassCastException: java.lang.Class cannot be cast to clojure.lang.IFn
18:31TimMc&(java.util.ArrayList. [1 2 3])
18:31lazybot⇒ #<ArrayList [1, 2, 3]>
18:31TimMcGo nuts.
18:32raekto me referential transparancy is one of the most important characteristics of FP
18:32TimMcThat is certainly a pretty nice one.
18:32DaReaper5mattmoss thanks man, promise and future seem to be the way to go
18:32flying_rhinocan I also use all other mutable types, like numbers and stuff?
18:32flying_rhinonot saying ti is a good idea
18:32TimMcnumbers aren't mutable!
18:33mattmossDaReaper5: Enjoy.
18:33TimMcwell, AtomicInteger is, I guess
18:33raekbut what "FP" really means is disputed, of course...
18:33flying_rhinoI mean from java
18:33metellusIntegers are mutable, I think
18:33TimMcNo way.
18:33raekflying_rhino: the variable is mutable, not the number in it
18:33flying_rhinoI mean can I use plain java datatypes which are mostly mutable, if I am not mistaken?
18:34flying_rhinoyou mentioned array
18:34TimMcflying_rhino: Nothing is stopping you.
18:34flying_rhinogood to hear
18:34flying_rhinolook I am going to try functional way first, ofcourse but I want to know that there is ejection seat
18:35flying_rhinoin case functional doesn't cut it.
18:35raekClojure certainly has its ejection seat... :)
18:35mattmossIs it a functional ejection seat?
18:35TimMc&(let [q (java.util.concurrent.LinkedBlockingQueue. '[a b c])] (.poll q) (.size q))
18:35lazybotjava.lang.SecurityException: You tripped the alarm! clojail.testers.ClojailWrapper@68b653 is bad!
18:35TimMclazybot: ?
18:36brainproxymattmoss: yes, it will give you happy functional ejection time
18:36DaReaper5mattmoss: i just want to summarize promise and future... so i can be sure i understand them: Promise-> def creates a promise which is an object that can be passed to any thread. If a thread treis to deref the promise object it blocks until it is ready. When you deliver a promise it becomes available to the other threads.
18:37TimMc&(let [l (java.util.concurrent.atomic.AtomicLong. 5)] (.incrementAndGet l))
18:37lazybot⇒ 6
18:37mattmossDaReaper5: That... sounds right. Also note that you can only deliver once to a particular promise.
18:37DaReaper5Future: like promise but you define the function that calculates the object which pritty much does a deliver at the end of the calculation.
18:38DaReaper5mattmoss makes sence concurrance wise
18:38DaReaper5This is what I am learning it from (thank god for stackoverflow) http://stackoverflow.com/questions/4623536/how-do-clojure-futures-and-promises-differ
18:39TimMcpromise/deliver is far more powerful and flexible
18:39DaReaper5timmc seems like it because you get to decide when the object is available
18:39TimMcand where
18:39TimMcor even whether
18:40DaReaper5now i get the super complicated task of how to assign and delegate these promises
18:40DaReaper5basically i want a certain method call to deliver a promise to a user session.
18:41mattmossDaReaper5: MAke sure to read the answer by dimagog right below the first large answer.
18:41raekI think you could describe 'future' as a function that returns a promise-like thing and starts a thread that evaluates an expression and deliver its value
18:42DaReaper5raek ya i think thats what i was trying to say
18:43TimMcI guess you could easily implement future using promise/deliver... but it's a actually a thing from Java-land.
18:44alexykwhat's #_(…) as a way to comment out things?
18:44amalloya way to comment out things, man. there's no other way to say it
18:44alexykwhat's #_ ? in relation to lambdas etc
18:44raekalexyk: unrelated
18:44mattmossIt's a reader thing?
18:44raek#_ means "ignore the next form"
18:44alexykso random syntax?
18:45TimMcBasically java.util.concurrent.Future + some interfaces.
18:45raekyes, it's done by the reader
18:45alexykok
18:45raekmost often the first character after the # determines the "special meaning"
18:45TimMc,[1 #_ #_ 2 3 4 5 6]
18:45clojurebot[1 4 5 6]
18:46raekhuh, they stack? :)
18:46TimMcand interact badly with fn literal args
18:47TimMc,(#(#_ %1) 'hello)
18:47clojurebot()
18:47mattmoss,#'#_
18:47clojurebot#<ExecutionException java.util.concurrent.ExecutionException: java.lang.RuntimeException: EOF while reading>
18:47mattmoss,#_#'
18:47clojurebot#<ExecutionException java.util.concurrent.ExecutionException: java.lang.RuntimeException: EOF while reading>
18:47TimMcmattmoss: It's not a var.
18:47Sgeo,#_#' (do)
18:47clojurebot#<ExecutionException java.util.concurrent.ExecutionException: java.lang.RuntimeException: EOF while reading>
18:47mattmoss,#_#'_
18:47clojurebot#<ExecutionException java.util.concurrent.ExecutionException: java.lang.RuntimeException: EOF while reading>
18:48SgeoAww
18:48raekalexyk: the "#" as no meaning by itself is what I was trying to say...
18:48Sgeo,
18:48clojurebot#<ExecutionException java.util.concurrent.ExecutionException: java.lang.RuntimeException: EOF while reading>
18:48Sgeo,#'do ; do is not a var
18:48clojurebot#<CompilerException java.lang.RuntimeException: Unable to resolve var: do in this context, compiling:(NO_SOURCE_PATH:0)>
18:48ivantoo many #_ will overflow your stack
18:48mattmoss,#_o--o
18:48clojurebot#<ExecutionException java.util.concurrent.ExecutionException: java.lang.RuntimeException: EOF while reading>
18:48alexykso #(+ % 1) is also a reader thing, with spec. meaning provided by ( ?
18:48Sgeo,[#'-> #'+ ; but macros and functions are]
18:48clojurebot#<ExecutionException java.util.concurrent.ExecutionException: java.lang.RuntimeException: EOF while reading>
18:48Sgeo,#_o--o (do)
18:48clojurebotnil
18:49TimMcThis look slike a good time to head home.
18:49Sgeo,[#'-> #'+] ; but macros and functions are
18:49clojurebot[#'clojure.core/-> #'clojure.core/+]
18:49mattmosslol
18:49alexykTimMc: you must be on the wrong coast
18:49raekalexyk: yes, #(foo %) is just a reader shorthand that means the same thing as:
18:49TimMcNo, I'm on the right(-most) coast.
18:49raek,'#(foo %)
18:49clojurebot(fn* [p1__325#] (foo p1__325#))
18:50mattmoss,`'
18:50clojurebot#<ExecutionException java.util.concurrent.ExecutionException: java.lang.RuntimeException: EOF while reading>
18:50alexykTimMc: which is the wrong one, w.r.t. startups
18:50raekso "#(" means "start of anonymous function shorthand"
18:50Sgeo,(#(inc (#(inc %))) 5)
18:50clojurebot#<ExecutionException java.util.concurrent.ExecutionException: java.lang.IllegalStateException: Nested #()s are not allowed>
18:51raekyou could also think of # as switching some kind of "mode" in the reader
18:51mattmoss,`':'
18:51clojurebot(quote :')
18:51amalloySgeo: 'do is not a var, but i had a good laugh when i saw one of the monad libraries had (:refer-clojure :exclude [do])
18:52mattmoss,'':-
18:52clojurebot(quote :-)
18:52mattmossquote smiley
18:53amalloy,'(tophat :-)
18:53clojurebot(tophat :-)
18:57DaReaper5How would I go about having a reusable/assignable promise. Here is the issue: i want to call upon the promise to retrieve the most recent event which will be stored in the promise.
18:57DaReaper5Actually, could i just use a blocking queue
18:57DaReaper5that would return the top item or block until there is one?
18:58raekyes, BlockingQueues can do that
18:58DaReaper5http://clojuredocs.org/clojure_core/1.2.0/clojure.core/seque ?
18:59raekhttp://docs.oracle.com/javase/6/docs/api/java/util/concurrent/BlockingQueue.html
18:59raekand
18:59raekhttp://docs.oracle.com/javase/6/docs/api/java/util/concurrent/LinkedBlockingQueue.html
19:00DaReaper5hmmm so use the java blocking queue eh
19:00raekblocking queues and persistent queues of promises feels like two ways of thinking about the same thing
19:00flying_rhinodo I have threads in clojure?
19:01flying_rhino(I know there are better ways, I just want to know if it is available)
19:01raekhttp://clj-me.cgrand.net/2010/04/02/pipe-dreams-are-not-necessarily-made-of-promises/
19:01raekflying_rhino: of course!
19:01raekhttp://clj-me.cgrand.net/2009/11/18/are-pipe-dreams-made-of-promises/
19:01flying_rhinocoz there are places where I might want to use some mutability and threads for some stuff (not a lot of stuff ofcourse)
19:02raek(let [t (Thread. (fn [] ...some code...))] (.start t))
19:02raekflying_rhino: you could also use Clojure's thread safe mutation primitives (refs, atoms, etc)... :)
19:03flying_rhinogood to know
19:03raek(future ...some code...)
19:04DaReaper5ok ill fiure out the usage late but i think i can do a hash map of blocking queue which the long polling method request/take from.
19:04DaReaper5later*
19:04DaReaper5queues*
19:04raekflying_rhino: some Clojure features assume that certain expression don't have side-effects, though. this is usually clear from the documentation.
19:04flying_rhinoI know
19:05flying_rhinobasically strict functional programming is a little too hardcore for me.
19:38ChongLiflying_rhino: you ought to watch SICP
19:38ChongLiit'll change your perspective
19:38flying_rhinowhy?
19:38clojurebotwhy is the ram gone is <reply>I blame UTF-16. http://www.tumblr.com/tagged/but-why-is-the-ram-gone
19:39ChongLithen you'll start looking at imperative programming as this scary, weird thing
19:39amalloywatch it? read it
19:39flying_rhinolinks?
19:39ChongLiamalloy: the lectures are essential IMO
19:39amalloyi mean, i haven't watched it, so maybe the recording is really great. but i imagine you want the book as well
19:39amalloy$google sicp
19:39lazybot[Welcome to the SICP Web Site] http://mitpress.mit.edu/sicp/
19:40amalloy$google sicp lectures
19:40lazybot[Structure and Interpretation of Computer Programs, Video Lectures] http://groups.csail.mit.edu/mac/classes/6.001/abelson-sussman-lectures/
19:40ChongLihttp://www.youtube.com/course?list=ECE18841CABEA24090\
19:40ChongLierr
19:40flying_rhinothanks
19:40ChongLihttp://www.youtube.com/course?list=ECE18841CABEA24090
19:42ChongLiI especially enjoy the lecture where Gerald Sussman dresses up and writes the evaluator on the black boards
19:42ChongLiit has a very sentimental quality to it
19:43flying_rhinoalthought, ChongLi , I am not sure that my ambivalence is entirely due to paranoia. I am planning (for now just planning) to develop RTS game in clojure. Still not sure that it is a good idea. Basicaly games have a lot of changing state so immutability scares me somewhat.
19:43ChongLithe two of them are brilliant lecturers
19:43ChongLijust package your state in one of clojure's reference types
19:44ChongLiand then write a bunch of pure functions on different parts of the game logic
19:45flying_rhinoalthought real time strategies appear real time they are in fact turn based but turn expires quickly. I plan to have turn last 0.25 .
19:45flying_rhinoSo I generate new state every 0.25 seconds.
19:45ChongLiyou might even consider using streams (lazy seqs in clojure) to represent the game as a series of instants in time
19:46flying_rhinobasically different subsistems in game have to assemble new state every 0.25 seconds
19:46ChongLievery real-time game works like that AFAIK
19:46ChongLiI'm not aware of any continuous time games
19:46ChongLiSICP will teach you a different way of looking at a problem
19:47ChongLinot as decomposing something into a tree of specialized parts
19:47ChongLibut as a stack of successive layers of abstraction
19:47flying_rhinoI dunno but what I want is easier to do than say shotter that has new state every 0.03 sec or some such.
19:52ChongLiflying_rhino: may I ask why you chose clojure for writing a game?
19:54flying_rhinoI like lisp because I like macros as abstraction tools and code as data thingy is intriguing (and makes sense to me). I like Java as a platform (althought I havent done any Java programming in ages). Lisp + JVM seems like nice combo.
19:55flying_rhinoI also want to see if it is acheivable (I mean game in lisp)
19:55ChongLiI see no reason why not
19:55ChongLiit all depends on what sort of performance demands you have
19:55flying_rhinoperformance IS concern
19:56ChongLiif you use lwjgl you can shift most of the burden onto the GPU
19:58flying_rhinoI'll go with client server architecture with clojure as server (if I pick clojure). There is panda3d graphic engine at client side.
19:59flying_rhinopanda3d is engine written in c++ and has nice python interface. I'll probably make very thin client in python. Almost all calculations will happen on server.
19:59flying_rhinoso I don't have to worry about graphic card and stuff.
20:00flying_rhinoI hope clojure has decent performance with multicore (that's kind of a point of immutability, right?)
20:01flying_rhinowell at least that's a plan
20:01flying_rhino*the plan
20:02flying_rhinoany objections to the plan?
20:04flying_rhinoI'll take look at SICP, by the way
20:04flying_rhinothanks
20:06ChongLihey
20:06ChongLiwhy python?
20:07ChongLiI think you're likely to get better performance out of clojure than python (unless you're calling only C libs from python)
20:08flying_rhinobecause panda3d only has python interface. And it won't do anything other than read stuff server send and tell panda3d to draw it. Server will do almost all the work.
20:08flying_rhinoI might choose different 3d engine but panda3d is very easy to use.
20:08ChongLiah
20:09flying_rhinoI doubt python will turn out to be a bottleneck here
20:09flying_rhinobut you never know
20:10flying_rhinobut if you know engine with java bindings, let me know.
20:11ChongLiwell there's lwjgl (which is what minecraft was written for)
20:11flying_rhinowill take a look
20:11flying_rhinoultimately graphic is lesser concern
20:11ChongLibut it's mostly a raw library for doing opengl and input
20:11flying_rhinoat first it will be 2d anyway
20:12flying_rhino3d isn't integral to anything
20:12ChongLiopengl is still good for 2D drawing
20:14flying_rhinowell I first I'll proabably stick to java native drawing tools, provided those don't completely suck.
20:14flying_rhino*at first
20:16SgeoJNA's Pointer docs has this
20:16Sgeo"Create from native pointer. Don't use this unless you know what you're doing."
20:16SgeoFor the Pointer constructor
20:17SgeoBut then in that case, if a JNAerated function takes a pointer, how do I pass one to it?
20:17flying_rhinoChongLi: anyway thanks for your advice
20:18ChongLiflying_rhino: no problem
20:18ChongLiI think a lot of people are rediscovering SICP these days
20:18ChongLisince a few articles about it have been posted on reddit/HN
20:38yediso i'm still tryna wrap my mind around functional programming
20:39ChongLineed some help?
20:39yedihow would I print every other element in a list if I was looping through it with doseq?
20:39yedii could use let to bind a variable and just increment it
20:39yedibut it seems like the imperative way to go about it
20:39ChongLiyeah
20:39amalloy&(take-nth 2 (range 10))
20:39lazybot⇒ (0 2 4 6 8)
20:40ChongLiamalloy has the right idea
20:40ChongLiseqs are meant for stream processing
20:40Sgeo,(doc take-nth)
20:40clojurebot"([n coll]); Returns a lazy seq of every nth item in coll."
20:40yeditake-nth seems like itll be handy
20:40amalloythe idea, as usual, is not to think about doing it "in doseq", but instead think of a way to transform the data non-mutably and then as a last step throw that into a doseq if for some reason you need to
20:40SgeoThat's a weird name for that idea.
20:41ChongLiSgeo: what is?
20:41Sgeotake-nth. It's ... hmm
20:42yedithanks guys
20:42yediamalloy: that's a good way to think about it
20:42ChongLiyedi: stream processing is all about composing producers (such as range) with maps, filters and accumulators
20:42wingy_FP is so sweet
20:43ChongLithe topic is covered quite well in SICP
20:45yediif only I realized how interesting/seemingly intelligent FP was when I was doing my first programming class which used scheme
20:46ChongLiit can be a lot to take in
20:47yedifor mac users: nrepl in emacs uses ctrl-up and ctrl-down to go through the repl history, but mac uses that key combination to do os related stuff
20:47yedihow do you get around that
20:48ChongLiI use M-p M-n
20:49ChongLiit is really nice in that you can type a bit and use those keys to search history
20:49ivanI use up/down
21:00yedii'm getting this error when i try to count the lines in a file: https://gist.github.com/4092610
21:02ChongLisounds like the lazy IO bugaboo
21:04SgeoCan we just take line-seq out into a shed and burn it?
21:04SgeoOr at least slap a large warning label on it?
21:05yediSgeo: what would a better alternative be for reading lines in from a file?
21:05Sgeoyedi, something that isn't lazy
21:05SgeoErm, I mean, hi.
21:06ivansomething that closes the file when you reach the end and otherwise leaks
21:06ivanjust set your fd limit really high ;)
21:06yedifd limit?
21:06ChongLifile descriptors
21:07Sgeoyedi, what's going on is that line-seq isn't reading lines until they're requested
21:07ivanunlimit -n The maximum number of open file descriptors (most systems do not allow this value to be set)
21:07yediright, aka lazy
21:07SgeoThey're not requested until count
21:07ChongLiand if the file is closed
21:07ChongLithey won't be able to be read
21:07ChongLiand an exception is thrown
21:09yediso after parse-lines returns, the file closes?
21:09ChongLisame problem occurs in haskell (or any language where you're doing lazy stream processing with IO)
21:09ChongLiyeah
21:09yediso I can't actually access any of those lines
21:09yedii'd have to load them into memory?
21:09SgeoAfter the with-open returns
21:09ChongLior print your count inside with-open
21:10SgeoPut a doall inside the with-open somewhere, that will load them into memory
21:10yediis there a non lazy version of line-seq?
21:10yediah
21:10Sgeo(comp doall line-seq) should be non lazy
21:10yedi*checking with doall does*
21:11Sgeo(doc doall)
21:11clojurebot"([coll] [n coll]); When lazy sequences are produced via functions that have side effects, any effects other than those needed to produce the first element in the seq do not occur until the seq is consumed. doall can be used to force any effects. Walks through the successive nexts of the seq, retains the head and returns it, thus causing the entire seq to reside in memory at one time."
21:11ChongLikeep in mind though
21:11SgeoOr you could do count inside with-open
21:11ChongLithat if your file is really big
21:11ivanmaybe someone should write a lazy-line-slurper that works with file paths and closes/reopens fds as needed
21:11ChongLiyou may not want it all in memory
21:12yediright ChongLi
21:12SgeoSomeone should port the ResourceT stuff from Haskell into Clojure.
21:12SgeoWell, not an exact port, that uses monads.
21:12ChongLianother solution might be iteratees
21:14SgeoClojure can kind of sort of fake some common monads.
21:14Sgeo(Idiomatically in everyday code not deliberately using monads, I mean)
21:17gfredericksis the IO monad impossible? does that require pervasive laziness?
21:18gfredericksor maybe it is just thunks that do IO...
21:19ChongLiI thought the real barrier to monads in clojure was the lack of return type polymorphism
21:20ChongLithe inability to write a function whose type is a -> m a
21:20SgeoIO monad is not related to laziness
21:20SgeoIn Haskell or Clojure
21:23gfredericksSgeo: I had the idea when I tried to think about implementing an IO monad with the motivating thought being that an IO a is a description of how to obtain an a. If I tried to imagine that as a data structure then I started thinking the data structure had to be lazy
21:23gfredericksbut now I can't reconvince myself of it
21:24SgeoHint: There exists a data structure in both Haskell and Clojure, but one of the differences of the two is that Haskell's version of that structure is more restrictive.
21:25Sgeo^^being slightly obtuse
21:25gfredericks"a data structure"? is there a mystery data structure that you're trying to get me to identify?
21:26SgeoYes. Although I guess you might not call it a data structure.
21:26SgeoBut it's an item you can pass around and return from stuff.
21:26gfredericksundefined?
21:27SgeoIt exists in Clojure but not in Java. In Java there are annoying workarounds for it not existing.
21:27gfredericksa function? :)
21:27SgeoYes.
21:27Sgeo:)
21:27gfredericksand an IO a is essentially an () -> a?
21:28gfrederickser
21:28gfredericksI'm not sure that communicated by thought :/
21:28gfrederickss/by/my/
21:28SgeoAn IO a can be represented in a non-functionally-pure language with a zero argument function.
21:29gfredericksyeah that's what I was going for
21:29SgeoThat trick doesn't work in Haskell, since functions themselves aren't supposed to do impure stuff like I/O
21:29gfredericksand that's why I was having trouble communicating it :)
21:31ChongLiunsafePerformIO
21:32SgeoI did say "supposed"
21:32ChongLiit's actually used in a bunch of libraries
21:32SgeoBut ideally those libraries expose a purely functional interface
21:32gfrederickswhat sorts?
21:33ChongLiit's often used as a hack
21:33gfredericksrandomized algorithms?
21:34ChongLithat'd violate referential transparency
21:34gfrederickse.g. quicksort
21:35ChongLithey're more commonly used in doing some mutable stuff before freezing an immutable data structure
21:35ChongLisimilar to clojure's transients
21:37gfredericksI guess the only legitimate use should be for performance?
21:37ChongLinah, there's other uses
21:38ChongLimemoization for one
21:38Sgeounamb
21:38Sgeo?
21:38ChongLiI guess that's performance related too
21:40gfredericksthis is weird stuff.
21:40ChongLiconal elliott is way above my head
21:58ForSparePartsIs there a good way to prevent my nrepl from dying when I kill a window I created from it with Java interop stuff? Do I need to start a new thread, or...?
22:13amalloydon't set EXIT_ON_CLOSE on your window :P
22:13ForSparePartsamalloy, Ah. That would do it.
22:41TimMcclojurebot: hello
22:41clojurebotBUENOS DING DONG DIDDLY DIOS, fRaUline TimMc
22:41TimMc:-)
22:57LesZedCBhello!
23:24mholmqvisthi, I'm having some issues with the reader literals for records, anyone who can try to help a bit?
23:25shachafI don't know anything about Clojure, but I bet you could get more people who can help you by asking your question.
23:25shachaf(As opposed to not asking it.)
23:27Raynes~anyone
23:27clojurebotJust a heads up, you're more likely to get some help if you ask the question you really want the answer to, instead of "does anyone ..."
23:27mholmqvisttrying to serialize a record with a jodatime DateTime instance as one of the fields. I cannot get the reader to read the record after serializing it...
23:28mholmqvistthe field looks like :timestamp #<DateTime 2012-11-17T04:17:43.675Z>
23:28mholmqvistand if I try with a map instead of a record it works fine and the value in the map is then :timestamp #=(org.joda.time.DateTime. 1353125863675)
23:29mholmqvistwith #= instead of #<
23:30mholmqvistthis causes an "Unreadable form" error in the record case
23:31TimMcYeah, #<...> is never readable.
23:31mholmqvistthat's what I thought...
23:31TimMc#=(...) is reader-eval syntax, which is enabled iff *read-eval* is bound to true.
23:32TimMc,(read-string "#=(the bot says nice try)")
23:32clojurebot#<RuntimeException java.lang.RuntimeException: EvalReader not allowed when *read-eval* is false.>
23:33TimMcNone of this deals with reader literals, by the way.
23:34mholmqvistyeah right, sorry about the bad question. :)
23:35mholmqvistok, so how can I serialize a record and read it on the other end? including the fields?
23:35TimMcHmm, that sounds like a bug to me.
23:36TimMc(read-string "#clj.core.MyRecord{:a #=(+ 1 2), :b 2}") does what I'd expect, so it's not that the printer is avoiding doing something the reader can't handle...
23:40mholmqvistwell, if I do (pr-str (into {} my-record-instance)) I get "#=(clojure.lang.PersistentArrayMap/create {:timestamp #=(org.joda.time.DateTime. 1353126954623)}"
23:41mholmqvistand if I just do (pr-str my-record-instance) I get " #MyRecord[#<DateTime 2012-11-17T04:38:24.877Z>]"
23:42mholmqvistso putting everything in a map works better, but I guess I'm doing something fundamentally wrong?
23:43amalloysounds like you're on some nutso version of clojure, perhaps? records don't print like that on 1.4.0
23:43mholmqvisthm…only included 1.4.0
23:44amalloyhttps://www.refheap.com/paste/6782
23:44TimMcamalloy: They do with *print-dup* true on 1.3.0.
23:44amalloyugh print-dup
23:44amalloydon't use it
23:45amalloybut you're right, it looks like print-dup is true for him
23:45TimMchttps://www.refheap.com/paste/6783
23:45mholmqvistis print-dup deprecated?
23:46TimMcI was using print-dup to get a #= in my output.
23:47TimMc(Array-map, since I don't have Joda Time in that project.)
23:47amalloymholmqvist: not as far as i know, but it's rubbish
23:47mholmqvistTimMc: right.
23:48mholmqvistamalloy: how can I do it any other way?
23:48mholmqvistget something like joda DateTime in the record?
23:48amalloyjust use pr-str, without print-dup
23:48TimMcamalloy: You object to the use of #=, or something else about print-dup?
23:49SgeoWhat's *print-dup*?
23:49Sgeo(doc *print-dup*)
23:49clojurebot"; When set to logical true, objects will be printed in a way that preserves their type when read in later. Defaults to false."
23:50amalloy#= is not my actual objection, but is inextricably bound up in it. the objection is that each java object (or deftype) that wants to be printable with print-dup has a totally isolated part of its code responsible for printing it, which outputs a non-compiler-checkable string that has implicit dependencies on the rest of the file
23:51amalloywhat will happen (and *does* happen in clojure.lang) is that data structures evolve, and their print-dup implementations don't change, so that calling print-dup on an object produces a string that is basically rubbish
23:51mholmqvistamalloy: just noticed I was using print-dup
23:52mholmqvistusing pr-str gives "MyRecord{:timestamp #<DateTime 2012-11-17T04:47:14.25}"
23:52Sgeoamalloy, write about it on clojuredocs?
23:52mholmqvistwith the #
23:52mholmqvist"#MyRecord{:timestamp #<DateTime 2012-11-17T04:47:14.25}"
23:52amalloyfeel free, bro. i don't use clojuredocs
23:52mholmqvistbut still "Unreadable form" on the reader side...
23:54mholmqvistamalloy: now working!
23:56mholmqvistmissing binding of print-dup. thanks TimMc for the refheaps!
23:56mholmqvistamalloy:
23:56mholmqvistamalloy: is it possible to do in any other way?
23:57amalloyof course. clojure is turing-complete; you can write your own version of printing based purely on the lambda calculus. but that's not very interesting, and why would you when you already have a six-character function (pr-str) that does exactly what you want?
23:59SgeoTuring-complete does not imply being able to do anything. If you take Brainf*** and remove . you can't write to the screen.
23:59TimMcamalloy: It sounds like the problem is that pr-str by itself produces a #<...> form, which is unreadable.
23:59Sgeo(And BF would still be TC)
23:59mholmqvistyeah I have no problem using that function. I was just curious since you said it was rubbish. :)
23:59amalloyno, print-dup is rubbish
23:59TimMcMaybe the solution actually is reader literals and print-method.
23:59mholmqvistTimMc: that's my impression also
23:59TimMcamalloy: ...
23:59amalloyTimMc: no, he solved it by not binding *print-dup*