#clojure logs

2011-01-16

00:00Gigarobyguys is there any map that take care of order of keys ?
00:00timmcA sorted map, you mean?
00:00Gigarobyno
00:00Gigarobyone that mantains the order of keys
00:00amalloyGigaroby: insertion order? then no
00:00Gigarobyamalloy, ah ok
00:00amalloythat's not a map anymore, it's a vector
00:01Gigarobyamalloy, thanks I will use metadata then
00:38amalloyGigaroby: i don't understand how metadata can solve your problem. the point of hashmaps is they have constant(ish)-time lookup of known keys
00:39Gigarobyamalloy, all right but I also need to keep track of the order of the keys I insert
00:39amalloyif you want to look up a key based on something like its metadata, you'll have to scan through all the keys in the map
00:40amalloyGigaroby: metadata isn't a terrible solution if you won't ever be looking things up based on the metadata
00:40amalloybut my style would be to have a map more like {:key [:data :time], :key2 [:data2 :time2]}
00:41Gigarobyamalloy,
00:41GigarobyI need
00:41Gigarobyto have vectors as keys and vectors of vectors as values
00:42amalloyokay....
00:42Scriptorer...
00:43Gigaroby{[0 1] [[1 2] [3 4]] [1 3] []}
00:44Gigarobyand I want to add keys at the end of this
00:44Gigarobyand also remove at the end of this
00:45amalloyi don't see what this has to do with my suggestion to use [time, data] pairs as the values in your map
00:45ScriptorGigaroby: could you explain what you need this for? We might be able to give a better suggestion
00:47Gigarobywell I want to solve the knight tour problem and I have to use the current position as key and the list of possible next moves as values
00:47Scriptorah, so you're using vectors as coordinates
00:47Gigarobyyes
02:13amalloyguys, it's so quiet in here. are all the disreputable clojurians out partying?
02:41Dranikhi all!
02:41DranikI need to generate all tuples [0-10; 0-10]. What is the most idiomatic way?
02:45pdk`can you draw up an example by hand of what the output would look like
02:46pdk`[0-10; 0-10] i'm not quite following on what the expansion would be there
02:46midsmaybe (for [x (range 11) y (range 11)] [x y])
02:47Dranik[0;0] [0;1] [0;2] ... [5;0] [5;1] [5;2] .... [9;0] [9;1] ....
02:47Dranikmids, I'll give it a try, thanks
02:49Dranikbtw, what is the most idiomatic way to read a text file and get a sequence of lines?
02:52midsclojure.contrib.duck-streams/read-lines
02:52Dranikmids, thanks!
02:53midsdont be scared to use google though ;)
02:55pdk`,(for [x (range 4) y (range 4)] [x y])
02:55clojurebot([0 0] [0 1] [0 2] [0 3] [1 0] [1 1] [1 2] [1 3] [2 0] [2 1] ...)
02:55pdk`yep
03:01Dranikwhat is the key difference between (fn[] ...) and #(...)? I can use fn in reduce but clojure doesn't want to use #() in reduce...
03:02pdk`#() is a shorthand for anonymous functions
03:02pdk`copy the line you're trying to write, keep in mind you use %x syntax instead of named arguments in #() functions
03:02ossarehDranik: they're the same for all intents and purposes - the (fn) form is probably easier for your reduce since you can be very clear with your variables
03:03pdk`so i don't state up front what arguments the #() function takes
03:03pdk`instead i refer to them as %1 %2 etc in the order they're passed
03:03Dranikoh well, I've just tested it, and it works. Tanks!
03:07pdk`you can test lines straight in the chat with ,
03:09mids,(println "ORLY?")
03:09clojurebotORLY?
03:09mids:)
03:11amalloyDranik, mids: surely line-seq is more sensible than read-lines?
03:11Dranikamalloy, thank, I'll check it out
03:12amalloyossareh, Dranik: the difference between (fn[]) an #() is that the former can be nested; if you tried to nest #(map #(+ %1 %2)) forms, the compiler couldn't know which parens belonged where
03:13amalloyer, which %s
03:57LauJensenMorning all
03:59amalloyhey LauJensen
04:12LauJensenamalloy: Do you know of a reliable cross platform way of enumerating USB devices and getting their product IDs?
04:12amalloyfraid not. way out of my jurisdiction
04:19robonobohi, i have a namespace defined like this: (ns foo.foo (:use foo.help])), and i'm trying to call it from the repl with (use 'foo.foo), but that gives the error "java.lang.IllegalArgumentException: Parameter declaration reduce should be a vector". What am I doing wrong?
04:20robonobo(use 'foo.help) does work
04:27amalloyrobonobo: do you really mean (:use foo.help]? those parens don't match
04:28robonoboyeah, i meant (:use [foo.help])
04:28amalloyrobonobo: ah. well, that's not right. you want either foo.help or [foo help]
04:29amalloyactually i think there's a difference between [] and () in :use declarations, but honestly it's poorly documented. at any rate foo.help and (foo help) should both work
04:30robonoboso (ns foo.foo (:use foo.help)) ?
04:30amalloyrighto
04:31robonoboi still get the same error with that
04:32amalloyrobonobo: maybe gist/paste your code?
04:32robonobok
04:34amalloyrobonobo: https://github.com/amalloy/clojopts/blob/master/src/clojopts/ui.clj is a snippet from one of my projects that works
04:37robonobonow of course if I try to make a simple examle it does work
04:39amalloy*chuckle*
04:44robonoboamalloy: i've found my problem, it wasn't with the namespace
04:44robonoboi was confused by the repl telling we it was on line 1
04:44robonobobut that's the repl's line 1
04:45robonoboi just put (defn func (...)) somwhere
04:45robonobowithout the []
05:49zmyrgelhi, would multimethods a good solution for repl modeling
05:50zmyrgelI would need to have 'common' commands and then two 'sub-repl' which deal in their speciality commands + the 'common' commands
05:50zmyrgelalso is there some parser already done for this I could use?
05:52zmyrgelnow I have cond structure which first processes the common commands and if it can't find matching case it checks active repl type and continues to process that repl types commands
05:54raeka multimethod can be seen as an open case expression...
05:55zmyrgelok, what about parsing
05:55raek(defmulti eval-top-level-command (fn [words] (first words))) ;; something like this?
05:56zmyrgelso that would choose the eval-top-level-command based on the commands first word?
05:56raekmultimethods are just a bunch of functions with the same name. and then you give clojure some way of choosing the right function for a specific set of arguments
05:56raekyes
05:58zmyrgelbut wouldn't it give duplicate code.
05:58raekhere I assumed that you passed the command line as a sequence of strings (or keywords or symbols). I have no idea how your code is organized
05:58zmyrgelI'm making chess engine with UCI and XBoard protocols with addition to my own 'protocol'
05:59zmyrgeluci and xboard 'repl' should also have access to my own protocol's command processing
05:59raekwould you consider (case (first words) "start" (...handle start command...) "stop" (...handle stop command...)) to contain duplicate code?
06:00raek(you can have a default case too)
06:01zmyrgelI mean to 'extend' the default repl at runtime as I would extend Java base class
06:01raekthe clojure repl?
06:01zmyrgelmy own
06:01zmyrgelchess engine repl
06:03zmyrgeland I want to keep the engine repl types separate as if the uci repl is active the xboard repl commands are then invalid and vice versa
06:04raekmaybe you could refactor the common code into its own function
06:04raekand make it return nil or something if it does not recognize the command
06:04zmyrgelyeah
06:04raekand then your specialized repls could be functions with the same signature
06:05zmyrgelI would assume some inheritence system would be a good option
06:05raekthat delegates everything to the common function first
06:05zmyrgelfor example the 'help' command should print my default repl help and then the uci / xboard repls help
06:06raekyou could perhaps represent a set of command as a map
06:06raekthen just (merge base-handlers {:foo foo-handler, :bar bar-handler})
06:07raekwhich would add/override the :foo and :bar commands
06:07raekprotocols uses ordinary maps of functions as the way to do implementation sharing
06:08zmyrgelok, gotta see how to proceed with that
06:08zmyrgelany suggestions how to proceed with command parsing?
06:08zmyrgelnow I have very fragile system in place
06:09raeksince functions are values in clojure, class inheritance is not the *only* way of sharing behaviour
06:09zmyrgelsomething like (case (first command) "move" (make-move (second command)))
06:09raekis there a common syntax, or does each protocol need to parse its commands in its own way?
06:10raekor what do you mean by parsing here?
06:10zmyrgelI get single string as input and need to parse the engine commands from there
06:10zmyrgelxboard repl is quite simple still
06:11zmyrgelbut now my repl crashes everytime if my command is incomplete
06:11raekdo the protocols need to share parts of the parser?
06:11zmyrgelfor the 'common' part
06:13zmyrgeluci is bit more painful to parse
06:13zmyrgelhttp://wbec-ridderkerk.nl/html/UCIProtocol.html
06:13raekthe approach where you use a base handler and a more specific handler that delegates to the base handler first, and does its own handling if that failed could perhaps be applied to the parser problem too
06:13zmyrgelfor example the go command is quite nasty
06:15raeki.e. define a common parser that returns nil on ivalid data. then let a specialized parser begin with (if-let [data (parse-common ...)] data (...do own parsing...))
06:15raekhrm, that could be written as (or (parse-common ...) (...do own parsing...))
06:16raekyou could reverse the order if you want the specialized parser to be able to verride
06:17zmyrgelok, I'll get back to work. Have meeting tommorrow regarding this so need to get something done first :)
06:19raekI hope this was somewhat useful. the point is: clojure does not have a single inheritence system. since functions are first-class values, you are expected to roll your own (which is not too complicated).
06:21zmyrgelyep, gave me some ideas
06:21zmyrgelSlow and somewhat ugly process as this is my first real funtional programming project
06:39zmyrgelcan I somehow interrupt function to return it's value so far?
06:39zmyrgelthe goal is to interrupt the alpha-beta search to return the best move so far
06:40zmyrgelthe algorith processes the moves in loop within so to just return the current loops best-move value when I need it
06:40midshave it return a lazy sequence maybe?
06:41mrBlisszmyrgel: maybe an agent
06:42zmyrgelmids: how would that help?
06:42zmyrgelI mean it takes like 30 secs to seek a move and xboard protocol defines command 'move now' which would make ai's move immidiately
06:42zmyrgelso when I get the
06:43zmyrgelso when I get the 'move now' command I would need to get the alphabetas best move
06:43raekzmyrgel: if you have a Future object (e.g. from a 'future' call), you can can call future-cancel on it to interrupt that thread
06:44raekif the thread is in a blocking operation (other than reading from a socket), that blokcing operation will throw an InterruptedException
06:44raekotherwise (if it's doing calculation) the interrupted status of the thread is set
06:45raekyou can design that code to regularly check that status, and abort if it finds it set
06:47raekyou can also use an atom to hold a "is interrupted?" value that you check regularly
06:50zmyrgelcan't I just wrap it in try and then catch InterruptException and return current best move in there/
06:50zmyrgel?
06:51raekonly blocking operations throw such an exception
06:52raeke.g. taking an element from a currently empty LinkedBlockingQueue
06:52raekor waiting for a lock
06:52zmyrgelok
06:53raekso for a task that is only CPU bound, you have to design interruptability into it
06:54zmyrgelwell the loop in the function holds the best-move which I need
06:54sluggois the loop in its own thread?
06:54zmyrgelso at each loop iteration I check somehow if we have been interrupted and then return the best-move
06:54zmyrgelsluggo: not at the moment
06:55raekzmyrgel: yes.
06:56pauldoo'ello
06:56zmyrgelraek: and the obvious followup, how to check if the function is interrupted?
06:56raek(let [f (future ...call best moving finding function...)] (try (.get f 30 TimeUnit/SECONDS) (catch TimeoutException _ (future-cancel f) @f)))
06:57raekzmyrgel: http://download.oracle.com/javase/6/docs/api/java/lang/Thread.html#interrupted()
06:57pauldoohow would I create a sequence which is the result of calling a zero argument function (rand say) N times..
06:57pauldoo(map (fn [_] (rand)) (repeat 10 nil)) is the best I can come up with
06:58pauldoobut it seems a bit pants..
06:58zmyrgelraek: ok, thanks
06:58raekhrm. this will not work as I though...
06:58raekcancelling the future makes the deref throw a CancellationException
06:58raekrather than return a result...
06:59raekI got the semantics for futures and threads a bit mixed up
06:59raekzmyrgel: it might be simpler to communicate when to stop with an atom instead.
07:00mrBlisspauldoo: ##(take 10 (repeatedly rand))
07:00sexpbot⟹ (0.2759028873310243 0.6624371144084372 0.340050893492865 0.3204405251057306 0.7898043499624735 0.5132701706685107 0.21342042332892108 0.13312135339576658 0.026571457408496424 0.12350743903241035)
07:00pauldooaha! :)
07:00zmyrgelok
07:00raek(let [a (atom true), f (future ...call best moving finding function with a...)] (try (.get f 30 TimeUnit/SECONDS) (catch TimeoutException _ (reset! a false) @f)))
07:01pauldoomrBliss: thanks - repeatedly is the awesome :)
07:01raekin the loop: (loop [best-move ...] (if @running ... best-move))
07:01raekwhere running is the atom called 'a' before
07:01zmyrgelyep
07:40fbru02hey guys, i'm having a weird problem, i'm doing a map inside a macro and i don't know why after the macro resolves it tries to call the resulting list ? anyone ever had this problem ??
07:55pauldoohow do I remove a value from a map? (ie unassoc?)
07:57arbscht_,(doc dissoc)
07:57clojurebot"([map] [map key] [map key & ks]); dissoc[iate]. Returns a new map of the same (hashed/sorted) type, that does not contain a mapping for key(s)."
07:58pauldooaha.. :)
07:58pauldooI can see me adding lots of "see also" to clojuredocs.org
07:59arbscht_isn't that already there?
08:23pauldooit wasn't linked from assoc
08:45rrc7czcan somebody explain to me exactly how a method is invoked by (. o foo)? I've traced the source down to an ObjExpr fexpr, line 5421 of Compiler.java. The next line is simple a cast to IFn, then a call to invoke. Somehow it's taking the method in fexpr and calling invoke on that, but that's the part I'm missing
08:50sgronbloHey can you get a better clojure repl that has auto-completion and maybe even some fancy syntax highlighting?
08:50mrBlisssgronblo: Emacs + SLIME
08:50sgronblothat goes against my religious beliefs :)
09:00robonobohow do i get a default on cond? just (cond (condition) (thing) (condition) (thing) (true) (default))?
09:00robonoboor is there a more idiomatic way to do that?
09:01robonobotrue should be without brackets ofcourse
09:01mrBlissrobonobo: :else is the convention
09:01robonobook
09:02Raynes&(cond (= 1 0) 10 true 20)
09:02sexpbot⟹ 20
09:02Raynes&(cond (= 1 0) 10 :else 20)
09:02sexpbot⟹ 20
09:05mrBlissRaynes: some more silly names for a book on Clojure: "Structure and Interpretation of Clojure Programs" (SICP), "On Clojure" (like PG's On Lisp), "The Art of Clojure Programming" (Knuth), "Clojure: The Good Parts (Everything)" (Crockford).
09:05mrBlissI really think you should stick with "Sexpbook" though :)
09:05midsThe Holy Clojure
09:06RaynesSurprisingly, a lot of people think I should stick with "Meet Clojure".
09:07RaynesI could compromise. I could name it "Meet Clojure: The Sexpbook" ;)
10:17arkh"Clojure: The Good Parts (Everything minus some Java warts)"
10:18robonobojava warts sounds like an awful condition
10:19robonobothey're huge and they won't go away
10:19arkhcould be worse: VB warts
10:19robonoboyou monster!
10:19arkh; )
10:23arkhIs there a macro written like the following? (filter coll_of_funcs coll)
10:24opqdonutwhat would it do?
10:24arkhact like filter but apply an arbitrary number of functions to each item in coll, returning the first non-nil value (and skipping any remaining funcs for that item in coll)
10:25arkhI have a bunch of re's I'd like to try to match on text and there's enough of them that I don't want to use regex ORs
10:26opqdonutjust use some?
10:26opqdonut,(doc some)
10:26clojurebot"([pred coll]); Returns the first logical true value of (pred x) for any x in coll, else nil. One common idiom is to use a set as pred, for example this will return :fred if :fred is in the sequence,...
10:27opqdonutso something like (some #(re-match % the-string) collection-of-res)
10:27arkhoh, nice. That works
10:33arkhit's not pretty but maybe this will work: (for [s strings] (some (#re-find % s) collection-of-res))
10:33kjeldahlAnybody knows why congomongo returns my mongdb integers as doubles? Normal behaviour?
10:51robonobois there an opposite of (nil? x)? not-nil?
10:56kjeldahlrobonobo: Think not, only (not (nil? x))
10:56robonobokjeldahl: bumme
10:56robonobor
10:56opqdonut,(doc negate)
10:56clojurebotTitim gan éirí ort.
10:56robonobowhat now?
10:56opqdonuthmmh, I was pretty sure negate would've been #(comp not %)
10:57mrBlissopqdonut: ##(doc complement)
10:57sexpbot⟹ "([f]); Takes a fn f and returns a fn that takes the same arguments as f, has the same effects, if any, and returns the opposite truth value."
10:57kjeldahlrobonobo: (defn not-nil? [x] (not (nil? x))) ??
10:57opqdonutah, complement
10:58mrBlissrobonobo: in which context do you need it? Usually you can just do (if x .. ..)
10:58robonobofor every? or some
10:58mrBlissthen use identity
10:59robonoboi know i can do it with (not) but that's not pretty
10:59mrBliss##(every? identity [nil 1])
10:59sexpbot⟹ false
10:59robonoboooh
10:59opqdonut##(filter identity [false nil])
10:59sexpbot⟹ ()
11:00opqdonut##(filter #(not (nil? %)) [false nil])
11:00sexpbot⟹ (false)
11:00mrBlisspay attention to ^^ though :)
11:23Chousukeremember also (remove nil? ...) :P
11:31dedeibelHi there - I am new to clojure and have a little problem you might help me with. I have an agent of a vector of ints and want to get the doubled value of each of them. Now I would use "map" to calculate over all entries, but using "send" this is more difficult since the collection is set as second parameter and uses the agent value as the first parameter. Is there common way to solve the problem? A different function? I was having the problem
11:34mrBliss,(let [a (agent [1 2 3])] (send a (fn [coll] (map #(* % 2) coll))) (await a) @a)
11:34clojurebot(2 4 6)
11:35mrBlissdedeibel: ^^ not the most elegant solution, but I can't think of anything better.
11:35companion_cubewould (partial map #(* % 2)) replace (fn [coll] (map #(* % 2) coll)) ?
11:36mrBlisscompanion_cube: yes, that's better :)
11:38dedeibelah
11:38dedeibelthanks, that look kind of nice
11:38dedeibellooks
11:39dedeibelso many handy functions/macros to learn at the beginning :-)
11:40companion_cube(doc) is imho very useful at the beginning
11:40mrBlissor (find-doc a-regex)
11:42mrBlissdedeibel: I also recommend http://clojuredocs.org/
11:44dedeibelThank you. Looks well categorized. Mostly I am using the API reference on clojure.org and the wiki. But it sometimes lacks some examples which would speed up things.
11:44dedeibelNice, I see, there are some one clojuredocs
12:03pdki feel ya there
12:03pdki had no idea what -> and ->> really did until i saw a code sample
13:18gfrlogdoes anybody know about using the input and output streams with nailgun?
13:43phenom_anyone here using emacs on a mac ?
14:04wolveriancan I make a macro that generates a function whose name is a concatenation of a macro parameter and the question mark? I'm failing to use syntax (un)quoting correctly as this is my first macro.
14:04opqdonut,(symbol (str 'wolverian "?"))
14:04clojurebotwolverian?
14:05opqdonut;)
14:06amalloy&(let [name 'test] `(defn ~(symbol (str name "?")) [] (...)))
14:06sexpbot⟹ (clojure.core/defn test? [] (...))
14:07amalloywolverian: ^
14:10wolverianthanks!
14:17wolverianhuh. `(defn ~(symbol (str name "?")) ...) gives me the function #'user/(quote paramvalue)?
14:18wolverian(where paramvalue is the symbol passed in name)
14:19RaynesAre you passing 'paramvalue or paramvalue? The quotes are significant.
14:20wolverianright, that was the problem. just realized it myself. thanks.
14:28timmcYay! I just discovered Pico Editor. It is basically the perfect Clojure editor for my tastes.
14:28tomojany lamina users in? consider (blocking (fn [_] @geo/filtered-pidls)) vs (blocking (constantly @geo/filtered-pidls))
14:28timmc(I.e., it has bugs and misfeatures that don't bother me.)
14:28tomojwill the second still block?
14:29wolverianand here I am, learning Emacs for the tenth time just to feel awesome using SLIME... :)
14:29timmcwolverian: I never did get the hang of emacs. I feel so inadequate. :-P
14:29tomojyes, it will it seems :(
14:30wolveriantimmc: it's probably even harder for me, since I've been using Vim since forever.
14:30wolverianI'd just like to meet the person who gets vimclojure's repl support working. he must have superpowers.
14:31timmcI grew up with Windows -- the standard WIMP keybindings (C-s = save, etc.) are burned into my finger muscles.
14:32gfrlogtimmc: I grew up with querty and switched to dvorak in a couple months. I'm sure switching to emacs can be done.
14:32RaynesC-x-C-s isn't that much of a leap.
14:33TimMcThe hardest thing to change is block navigation. C-arrow and such.
14:34tomojconfirmed, the second blocks
14:34TimMcgfrlog: I was limping along with emacs about 6 months ago -- it can definitely be done -- but I've lost all my progress by now.
14:34amalloyTimMc: paredit uses C-arrow for some really handy list-manipulation commands
14:34RaynesI'm ashamed to say that I rarely use special movement key coords in Emacs.
14:34RaynesI just use the mouse and arrow keys.
14:34tendantHello, Can i ask how to use multi-bytes characters in slime-repl?
14:34TimMcamalloy: Much to my surprise. :-P
14:35TimMctendant: What OS?
14:35tendantubuntu 10.10
14:36TimMctendant: If you're using emacs in a terminal in Gnome, C-S-u gets you unicode input.
14:36TimMcC-S-u 2 1 2 0 <space> prints the ℠ mark, for instance.
14:36TimMcor... it should. Maybe emacs captures that?
14:37RaynesTimMc: Also something to think about: you could switch C-s with C-x-C-s and have your typical saving command and have C-x-C-s for searching.
14:37TimMcRaynes: Then I have two problems.
14:37tendantTimMc: I can type in those characters in emacs buffer. The problem is I cannot run clojure function containing multi-bytes chars.
14:37RaynesTimMc: Emacs isn't regex.
14:38TimMcYes. But I would then have to learn *two* things to get back to using it: Emacs keybindings *and* configuration.
14:39RaynesThat's a sure sign that Emacs isn't for you. You had it right the first time. ;p
14:40TimMcWhen was I right?
14:40TimMcOh! I get it.
14:40TimMc(If you're not configuring emacs, you're not really using emacs.)
14:45tendantI have configured slime-net-coding-system like this: http://stackoverflow.com/questions/3101279/how-do-i-use-unicode-utf-8-characters-in-clojure-regular-expressions/3318137#3318137
14:47tendantbut it still doesn't work
14:52LuytI was always used to run clojure under diablo-jdk (freebsd), but I just verified it runs under OpenJDK-6 too.
15:01markskilbeckHow would you go about changing the number 12345 into the collection [1 2 3 4 5]?
15:02amalloy&(map #(Integer/parseInt %) (str 12345))
15:02sexpbotjava.lang.ClassCastException: java.lang.Character cannot be cast to java.lang.String
15:02amalloy&(map #(Integer/parseInt (str %)) (str 12345))
15:02sexpbot⟹ (1 2 3 4 5)
15:03amalloymarkskilbeck: if efficiency matters there are better ways, but this works
15:04amalloysee also https://github.com/amalloy/bit-packer if you do care about speed, or want to use bases other than ten
15:04markskilbeckamalloy: it doesn't matter - just playing around, although I'll bookmark that repo.
15:04markskilbeckAnd thanks.
15:05robonobomarkskilbeck: is that for euler?
15:05markskilbeckrobonobo: good guess.
15:05robonobohaha
15:05markskilbeck;)
15:20robonobowhat's the funciton to get the second element of a seq again?
15:20robonobos/funciton/function
15:20sexpbot<robonobo> what's the function to get the second element of a seq again?
15:21amalloy&(doc second)
15:21sexpbot⟹ "([x]); Same as (first (next x))"
15:21robonobowhy thank you
15:22amalloyhey robonobo, sexpbot has a cool feature to help you find the function you're looking for, btw
15:22amalloy$findfn [8 10 22 1] 10
15:22sexpbot[clojure.core/second clojure.core/fnext clojure.core/rand-nth]
15:22robonobowow
15:22robonoboawesome
15:22robonobo$findfn [8 10 22 1] 22
15:22sexpbot[]
15:23robonobobroke it
15:23amalloyheh, no. there's just no function that does that
15:23robonoboyeah, i know
15:23amalloy$findfn [8 10 22 1] 2 22
15:23sexpbot[clojure.core/deliver clojure.core/nth clojure.core/get clojure.core/trampoline]
15:23robonobois there a way i could do this in the repl?
15:23robonoboi only know of (find-doc)
15:24amalloyrobonobo: uhmmmm, the function was written in sexpbot for sexpbot. you could copy and paste it into your repl
15:24amalloyor just /msg sexpbot if you don't want to clutter the channel
15:24robonobooh, i see your the author
15:24robonobos/your/you're
15:24sexpbot<robonobo> oh, i see you're the author
15:25amalloyrobonobo: kindasorta. __joshua wrote it; i helped and improved
15:26robonobowhat would happen if you would give it something that would result in an infinite loop?
15:26amalloyrobonobo: it's sandboxed with a timeout
15:26amalloy$findfn (range)
15:26sexpbot[]
15:27amalloyit tries all the functions it knows, giving each one up to (iirc) 50ms to see if it gives the desired results, and terminating it otherwise
15:28robonobovery cool
15:28robonobouhm
15:28amalloyum indeed
15:28amalloythat has worked in the past
15:28robonobodid we break it?
15:29_na_ka_na_is there a way to include \n in . in regexes, doing (.|\n)+ looks ugly
15:30_na_ka_na_on a related note why doesn't [.\n]+ work ?
15:31amalloy_na_ka_na_: metacharacters lose their special meaning inside []
15:32_na_ka_na_hmm found this
15:32_na_ka_na_http://download.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html#DOTALL
15:32_na_ka_na_how do i use the ?s flag
15:33amalloy#"(?s)....."
15:34_na_ka_na_i get this PatternSyntaxException Dangling meta character '?' near index 0
15:35amalloy&#"(?s)....."
15:35sexpbot⟹ #"(?s)....."
15:35phenom_argh, why does my Aquamacs show ^X rather than C-x ?
15:35amalloyworks for me
15:39_na_ka_na_oh my bad I skipped the () around ?s ..
15:39_na_ka_na_works thanks!
15:41TimMcWhat is the idiomatic way to non-lazily execute a function n times?
15:41amalloy&(doc dotimes)
15:41sexpbot⟹ "Macro ([bindings & body]); bindings => name n Repeatedly executes body (presumably for side-effects) with name bound to integers from 0 through n-1."
15:42TimMcAh, fantastic!
15:42_na_ka_na_TimMc, also look at repeatedly if you care for return values
15:43_na_ka_na_but that's lazy, so you'll need a doall
15:44TimMc_na_ka_na_: I was playing with `repeatedly`, but didn't know about `doall`. Thanks! (I'll stick with `dotimes` though.)
15:46_na_ka_na_TimMc, just make a note that with dotimes you wont capture the return values
15:46TimMcOne of these days I will skim through the entire clojure.core API so I know about all of these things.
15:47_na_ka_na_suppose I'm reading a file, after reading a few times I decide ok now I need to read the entire file in memory (from here on), how do I slurp the reader (from its current position) ?
15:49_na_ka_na_s/after reading a few times/after reading a few lines/
15:49sexpbot<_na_ka_na_> suppose I'm reading a file, after reading a few lines I decide ok now I need to read the entire file in memory (from here on), how do I slurp the reader (from its current position) ?
15:50cobol_expertare defrecord's visible outside the package in which they're defined? I'm having a heckuva time trying to :use one
15:51amalloycobol_expert: they're java classes: import, not use
15:51cobol_expertah! thanks!
15:51_na_ka_na_aah looking at slurp's source, it does exactly what I want, if only it took a reader as input!
15:57amalloy_na_ka_na_: (clojure.string/join \newline (line-seq reader))?
15:58_na_ka_na_amalloy, yeah but something like slurp-reader will be so cool
15:58_na_ka_na_plus no worries about the kind of \newline
15:59_na_ka_na_&(= \newline \n)
15:59sexpbot⟹ false
15:59_na_ka_na_why is that false?
16:00_na_ka_na_&(int \newline)
16:00sexpbot⟹ 10
16:00_na_ka_na_&(int \n)
16:00sexpbot⟹ 110
16:00_na_ka_na_&(int \r)
16:00sexpbot⟹ 114
16:01amalloy_na_ka_na_: \n is the character 'n'
16:03_na_ka_na_amalloy, aah yes i realized as soon as i saw the ascii table
16:04_na_ka_na_&(= (str \newline) "\n")
16:04sexpbot⟹ true
16:10wolverianis there a standard version of def that can define multiple bindings? e.g. (deffoo x 2 y 3)?
16:13amalloywolverian: none that i know of
16:14wolverianokay. macroing it was easy enough.
16:14amalloyare you sure that's really what you want anyway? perhaps (def config-settings {:x 2 :y 3}) would suit your purposes better
16:15wolverianyeah, it probably would, in the long run (i.e. when I'm out of hack hack hack mode)
16:19amalloywolverian: careful, it's easy to stay in that mode and end up with an annoying pile of trash
16:25wolverianyeah. fixing my macros now.. :)
16:27wolverianis there a form (condfoo value & clauses) where a clause is a pair pred body, and the first (pred value) true is chosen?
16:28wolveriani.e. like cond except the same value is given to each predicate automatically
16:30kjeldahlAnybody know why congomongo/mongodb returns my ints as doubles? I.e. an integer value 1 in the document is returned as 1.0 when used with Clojure (not in the mongo shell).
16:30raekit could perhaps be done with condp
16:31wolveriancondp is the reverse of what I want, sort of.
16:31raek,(condp #(%1 %2) "foo" number? :number string? :string)
16:31clojurebot:string
16:32wolverianyeah, that works. thanks :)
16:32robonobokjeldahl: maybe you could try the congomongo mailing list (http://groups.google.com/group/congomongo-dev)
16:34kjeldahlrobonobo: Yeah, I'll try. It has a total of 18 messages or so since inception this summer, so I'm not crossing my fingers.. :-)
16:35robonobokjeldahl: or you could try the mongodb irc
16:35amalloyyeah, i got decent help in their irc channel
16:35amalloythe one time i wandered in
16:37robonobokjeldahl: why don't you just use (int)?
16:39kjeldahlrobonobo: Yeah, I can hardcode those, like I did to stringify the _id (to make it easier to jsonify the docs), but differently from the _id, those ints typically appear more places.. And it doesn't seem to make sense. Thanks anyway.
17:13phenom_hey folks, people using aquamacs here ?
17:18ounce9hi yes
17:18phenom_ounce9: in the minibuffer, does C-x show up at ^X for me?
17:18_na_ka_na_can anyone tell me where can I download the complete clojure-contrib-1.3.0-alpha4.jar ?
17:19_na_ka_na_building clojure-clojure-contrib-3daaafd produces an empty jar for me
17:19phenom_did you do mvn install ?
17:19phenom_and dd it build all the modules ?
17:19_na_ka_na_no I'm checking in modules/complete/target
17:19_na_ka_na_I did mvn assembly:assembly
17:20_na_ka_na_do I need to mvn compile before that?
17:20phenom_you need to run "mvn instal"
17:20_na_ka_na_but I just want to build
17:20phenom_* mvn install
17:20_na_ka_na_not install
17:20phenom_i know, it'll build
17:21_na_ka_na_ok if you say, running install
17:22ounce9I get C-x-
17:22ounce9not sure what you mean
17:23phenom_it's weird ... i get "^X"
17:24ounce9may be a version thing
17:25_na_ka_na_phenom_, its still empty
17:26_na_ka_na_the complete-1.3.0-alpha4.jar
17:26phenom_in /modules/complete/target ?
17:26_na_ka_na_mvn install says build successful
17:26_na_ka_na_yup
17:26phenom_hmmm
17:26phenom_you may have downoaded the wrong zip file ?
17:27_na_ka_na_I have clojure-clojure-contrib-1.3.0-alpha4-0-g3daaafd.zip
17:27_na_ka_na_do you have link to the correct one?
17:28phenom_https://github.com/clojure/clojure-contrib/zipball/1.3.0-alpha4
17:30_na_ka_na_that's the one i have
17:31phenom_then something is definately up with your build
17:31phenom_i used that just earlier today to do a build (which took quite a long time)
17:32phenom_what is your terminal output telling you ?
17:33_na_ka_na_trying again
17:38_na_ka_na_same problem
17:38_na_ka_na_here's the build output
17:38_na_ka_na_[INFO] Unnamed - org.clojure.contrib:standalone:jar:1.3.0-alpha4 SUCCESS [5.106s]
17:38_na_ka_na_[INFO] Clojure Contrib ....................................... SUCCESS [0.075s]
17:38_na_ka_na_[INFO] ------------------------------------------------------------------------
17:38_na_ka_na_[INFO] ------------------------------------------------------------------------
17:38_na_ka_na_[INFO] BUILD SUCCESSFUL
17:38_na_ka_na_[INFO] ------------------------------------------------------------------------
17:38_na_ka_na_[INFO] Total time: 2 minutes 54 seconds
17:39_na_ka_na_phenom_, can you share the jar
17:39Raynes_na_ka_na_: http://gist.github.com
17:40raekhttp://build.clojure.org/releases/org/clojure/clojure/1.3.0-alpha4/
17:40Mimisbrunnrwow
17:40raekhttp://build.clojure.org/releases/org/clojure/clojure/1.3.0-alpha4/clojure-1.3.0-alpha4.jar
17:41_na_ka_na_Raynes, sorry my bad
17:42_na_ka_na_raek, I need contrib alpha4
17:42raekhttp://build.clojure.org/releases/org/clojure/contrib/complete/1.3.0-alpha4/ ?
17:43raekor check the contrib/ dir for the module you want
17:43_na_ka_na_thanks I was looking in the clojure-contrib directory
17:45_na_ka_na_raek, even this is empty size 1.8K ?
17:46raekstrange
17:47raekhrm, or was complete the module that depended on all the others?
17:47raekhttp://build.clojure.org/releases/org/clojure/contrib/standalone/1.3.0-alpha4/standalone-1.3.0-alpha4.jar
17:48raekseems so. this might be the whole thing ^
17:54_na_ka_na_raek, thanks that does seem to be the one
17:54_na_ka_na_but when I use it I get this error: https://gist.github.com/782233
18:48TimMcIs there any way to type a float literal in Clojure?
18:48dsop(float x)?
18:48TimMc:-/
18:49TimMcThat's a type coercion.
18:49dsopthen i dont know
18:50amalloy&0.1f maybe?
18:50sexpbotjava.lang.NumberFormatException: Invalid number: 0.1f
18:52amalloyTimMc: (float 0.1) should resolve at compile time, making it effectively a literal
18:53TimMcamalloy: I was hoping for something more succinct to write. :-(
18:53amalloyTimMc: why do you need a float?
18:55TimMcamalloy: http://download.oracle.com/javase/6/docs/api/java/awt/geom/Path2D.Float.html#curveTo%28float,%20float,%20float,%20float,%20float,%20float%29
18:57TimMcI need 6 of them.
19:03dnolen,0.1
19:03clojurebot0.1
19:03dnolen,1.1e6
19:03clojurebot1100000.0
19:04dnolenin 1.3.0 that's a float literal.
19:04dnolendouble literal I mean
19:04dnolentimmc: ^
19:04amalloydnolen: he's looking for actual floats
19:06RaynesI, myself, don't care for doubles. I don't use any numbers that can't keep me at the top of the water.
19:07amalloyTimMc: you could try (clojure.lang.Reflector/invokeMatchingMethod foo (map float [.1 .1 . 1 .1 .1 .1]))
19:09amalloyor...something like that. i don't use it so i dunno the syntax but clojure.lang.Reflector might be interesting to you
19:17TimMcblerg
19:17TimMcI'm not *that* interested in having literals.
20:00phenom_are there any online resources that are a good intro to clojure ?
20:00phenom_something like a learnyousomeclojure
20:05TimMcIsn't one of the Clojure books free for download?
21:46bdeshamhi all
21:47bdeshamI'm running Clojure with Java 1.6.0 on OS X. importing java.awt.geom.Line2D works fine, but java.awt.geom.Line2D.Float gives a ClassNotFoundException. any idea what I should look at?
21:48Raynesbdesham: Is Float an inner class?
21:48bdeshamheh
21:48bdeshamRaynes: yes, over on ##java they told me that it is
21:49bdeshambut I don't have enough java experience to understand quite what that means
21:49RaynesI believe, but don't quote me on this, that the syntax for accessing inner classes is $. So, java.awt.geom.Line2D$Float
21:49bdeshamif it helps, I also tried importing java.awt.geom.Line2D and then using (Line2D.Float. 1.0 1.0 1.0 1.0), but got the same error
21:49bdeshamRaynes: I'll try that
21:50amalloyugh, the xxx.Float/Double classes in java.awt are a gross example of devs using a new feature (inner classes) just because it's new
21:50amalloy(import java.awt.geom.Line2D$Float)...(Line2D$Float. args) is how you do it, i think, bdesham
21:52bdeshamhmm
21:52bdeshamwell now I'm getting "Unable to resolve classname" instead of a ClassNotFoundException
21:53Raynesamalloy: I don't think he has to import the inner class, but the outer class. Right?
21:53amalloyRaynes: not sure
21:53amalloy&java.awt.geom.Line2D$Double
21:53sexpbot⟹ java.awt.geom.Line2D$Double
21:54amalloy&(import java.awt.geom.Line2D)
21:54sexpbot⟹ java.awt.geom.Line2D
21:54amalloy&Line2D$Double
21:54sexpbotjava.lang.Exception: Unable to resolve symbol: Line2D$Double in this context
21:54amalloy&(import java.awt.geom.Line2D$Double)
21:54sexpbot⟹ java.awt.geom.Line2D$Double
21:54amalloy&Line2D$Double
21:54sexpbot⟹ java.awt.geom.Line2D$Double
21:54bdeshamaha
21:54amalloyRaynes: BLAM! i win
21:54bdeshamwhat seems to work is (import 'java.awt.geom.Line2D$Float) ... (Line2D$Float. 1 1 1 1)
21:55amalloyisn't...isn't that exactly what i said, bdesham?
21:55amalloy(PS you don't need to quote imports)
21:55bdeshamhehe
21:56bdeshamI think what I tried after your suggestion was (import 'java.awt.geom.Line2D) only, and then using Line2D$Float
21:56bdeshambut you need to include the inner class name in the import too
21:56bdeshamso yes, you were right ;-)
21:56bdeshamthanks all
21:56amalloyyeah, it's a bit silly. but the explanation is, at the bytecode level inner classes (more or less) don't exist
21:57amalloythey're just regular classes with a $ in the name
21:58bdeshamI see
22:27bdeshamwhat's the difference between importing a class via (:ns whatever (:import (java.something class))) and later via (import java.something.class) ?
22:34_na_ka_na_bdesham, the only difference is that you can refer to the shorthand 'class' in 'whatever' ns only after the import
22:34amalloybdesham: one of them is in the ns form, the other isn't :P
22:34tonylAFAIK, (ns (:import ...)) uses import inside
22:34amalloyie, there isn't one
22:34bdeshamoh, ok
22:34bdeshamwell that clears that up then ;-)
22:35amalloybdesham: fwiw, the (foo.bar baz) vs foo.bar.baz distinction is unrelated to ns vs non-ns
22:38bdeshamthat's a nice thing to keep in mind
22:40bdeshamis is possible to define a multimethod of two arguments where only one is dispatched on?
22:40bdeshamfor example, (f x y) gets routed to (f1 x y) or (f2 x y) depending on the value of (g x)
22:41_na_ka_na_bdesham, yes, just define dispatch-fn as (fn [x _] (g x))
22:42bdeshamexcellent, thanks
22:42bdeshamI knew there was something I was missing
22:42bdeshamthat's an example of destructuring, right?
22:43_na_ka_na_no, that's just regular fn parameters, _ is a symbol like x, y
22:44_na_ka_na_(let [[x y] [1 2]] ..) is an example of destructuring
22:44_na_ka_na_where you de-structure [1 2]
22:45_na_ka_na_if x were [x1 x2], we could have written (fn [[x1 x2] y] ..) essentially de-structuring x
22:45Scriptorif instead of [1 2] you had [z 2] or something like that, would it still try to destructure or say that y is undefined in the current scope?
22:46_na_ka_na_&(let [[x y] [1 2]] [x y])
22:46sexpbot⟹ [1 2]
22:46_na_ka_na_&(let [[x y] [1 2 3 4]] [x y])
22:46sexpbot⟹ [1 2]
22:47_na_ka_na_&(let [[x y] [1 [2 3 4]]] [x y])
22:47sexpbot⟹ [1 [2 3 4]]
22:47_na_ka_na_&(let [[x y] [1] [x y])
22:47sexpbotjava.lang.Exception: Unmatched delimiter: )
22:47_na_ka_na_&(let [[x y] [1]] [x y])
22:47sexpbot⟹ [1 nil]
22:47Scriptorer, what does the ? mean?
22:47Scriptoroh
22:48_na_ka_na_&(let [[x y] [[1 2] [3 4]]] [x y])
22:48sexpbot⟹ [[1 2] [3 4]]
22:49Scriptorso having the nested vector literals inside it causes it to try to destructure?
22:51amalloyScriptor: every let form "tries" to destructure
22:51_na_ka_na_&(let [[x y] (list (list 1 2) (list 3 4))] [x y])
22:51sexpbot⟹ [(1 2) (3 4)]
22:52_na_ka_na_&(let [[x y] '((1 2) (3 4))] [x y])
22:52sexpbot⟹ [(1 2) (3 4)]
22:52amalloyit does so by taking each *complete form* on the left (first in the pair, anyway), and assigning the matching other form
22:53amalloyfor simple symbols that's a simple assignment; for vectors and maps it involves recusive destructuring
23:17TimMcI can't find good documentation on all the forms I can use in an (import ...) statement.
23:18TimMcI could swear there's a way to "rename" the Java classes I import, but I can't find complete docs.
23:18amalloyTimMc: i don't think that exists
23:18tonylAs far as i know there isn't
23:19tonylI don't know if alias might do it
23:19TimMcSo you can only rename namespaces?
23:20amalloy$source import
23:20sexpbotimport is http://is.gd/TYmLaD
23:21amalloyTimMc: when in doubt, read the source. there's no allowance for anything complicated in import
23:21TimMcI don't know enough Clojure to read that yet.
23:21TimMcBut I'll take your word for it.
23:22amalloyTimMc: import is just turning (import (foo bar baz)) into (import* foo.bar) (mport* foo.baz)
23:22TimMcAh.
23:23tonyland since java class names are not symbols we can't alias them
23:26TimMcSo I'm stuck with java.awt's RenderingHints?
23:28TimMctonyl: What does that mean, "not symbols"?
23:29tonylsymbols are use to bind a name (symbol) with a value
23:29tonylalias let's you create an alias for a symbol
23:30tonyllike (alias 'cstr 'clojure.string) would create a cstr as a shortcut for clojure.string
23:30amalloytonyl: check out Namespace.java - it looks like there's code for binding any symbol to any class name
23:30tonylgreat, thanks amalloy
23:30amalloyi'm not sure if it's possible to get at that code though :P
23:30TimMcamalloy: Where's this now?
23:31tonylhttps://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Namespace.java
23:31amalloyline 123 or so
23:50tonylI can't seem to find a straight answer to what thunk means
23:51tonylin the context of Symbol.java , does anyone have an idea?
23:51thunk<joke here>
23:51tonylhehe
23:51Scriptortonyl: can you link us to the line in the source, if there is one?
23:52tonylhttps://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Symbol.java#L40
23:56tonylit might be an old comment that has nothing to do with the current code, I don
23:56tonylI don't know, but it got me thinking
23:57Scriptornope, not an old comment, here's the original commit : https://github.com/clojure/clojure/commit/01e67b1f2070b1e862e2e4e55680513943be58fb
23:57amalloytonyl: a function taking no arguments
23:58Scriptorthat's all? And here I was trying to figure out how unevaluated pieces of code had anything to do with it :P
23:58amalloyScriptor: they're synonymous if you look at it right
23:58tonylbut the function does take arguments