#clojure logs

2011-02-09

00:00amalloy&(class 1)
00:00sexpbot⟹ java.lang.Integer
00:01Raynes&(type 1)
00:01sexpbot⟹ java.lang.Integer
00:55cobol_experthttp://stackoverflow.com/questions/4938195/in-clojure-is-there-are-recursive-version-of-code-logging
00:55cobol_expert^ not mine, but i'm curious
01:08amalloycobol_expert: it doesn't make sense to "automatically" apply this to every sub-function because everything is a function
01:08amalloybut there is a tracing feature somewhere in contrib
01:09amalloyhttp://stackoverflow.com/questions/2352020/debugging-in-clojure
01:14arohneris there an xml parser that returns a vector in the same format as c.c.prxml?
01:24no_mindI have a lazy sequence of maps, like this ({"key0" "itemvalue0"} {"key1" "itemvalue1"} {"key2" "itemvalue2"}) . I want to merge all the itemms of seq into one map. How do I do this ?
01:26khaliGis it normal that the order of function defns matters when using require?
01:30khaliGoh i see, have to use declare around that.. that's odd :/
02:07defnamalloy_: CDT, maybe?
02:23khaliGwhat's the idiomatic way of updating a vector in an agent?
02:24khaliGi can see how to add an element to it, for example, but what if you want to change one element somewhere else
02:42scottjhow do you get the var associated with a local? does this require eval? (let [x a-var] (var x)) won't work. I want a function (defn foo [x] ...(var x))
03:15khaliGwth does replace do for a vector?!
03:17scottj? (replace {1 2} [1]) => [2]
03:17aamarsame thing as a seq, no?
03:19khaliGive been playing with it on the repl for 15 minutes and i still dont understand what it's doing..
03:20scottjit's like s/1/2/
03:20scottjsearch and replace
03:20khaliGright that's what i want to do but i cant get it to work the way i expect
03:20scottjpaste something
03:21khaliGsay i have a vector [1 2 3 4 5] and i want to replace the 4 with "four"
03:21scottj,:test
03:21clojurebot:test
03:22scottj,(replace {4 "four"} [1 2 3 4 5])
03:22clojurebot[1 2 3 "four" 5]
03:22khaliGthat works, but it does something completely different with what i was trying [4 "four"]
03:23scottj,(doc replace)
03:23clojurebot"([smap coll]); Given a map of replacement pairs and a vector/collection, returns a vector/seq with any elements = a key in smap replaced with the corresponding val in smap"
03:23scottjnote "given a *map*"
03:23khaliGmap vs vector
03:23scottjor the name of the arg, smap
03:23khaliGi read that doc several times too :/
03:24scottjhappens to the best
03:24khaliGi didn't parse the map as an actual map not just a collection of pairs
03:24khaliGscottj, thanks.
04:30khaliGwhat's the best clojure data structure/approach for this? :/
04:33khaliGhttp://www.clojure.pastebin.com/bmuwjzBt
04:36AWizzArdkhaliG: I do this with a closure over a proxy
04:37khaliGAWizzArd, tried to do the same thing really
04:37khaliGbut im stuck with finding a good mutable data structure for a table
04:37AWizzArd(let [data (atom nil)] (proxy [AbstractTableModel TableModelHelper] [] ...))
04:38khaliGAWizzArd, does your table allow user edits?
04:39AWizzArdAnd my TableModelHelper is a definterface that works directly on data, and offers getTableData, setTableData, setTableCell, clearTable, etc
04:39khaliGoh that is cool
04:39khaliGwhat does setTableCell do?
04:39khaliGas in behind the scenes
04:39AWizzArdMy docstring says: "Resets table-data vector with 'data' and updates the table."
04:40khaliGso you build a whole new table?
04:40AWizzArd(.setTableCell my-proxy new-data)
04:40AWizzArd(.setTableData my-proxy new-data) I mean
04:40AWizzArdnot Cell
04:40AWizzArdYes, this builds a whole table.
04:40khaliGok
04:40AWizzArdWhen the user clicks on the "Request" button it queries data from the server and can simply put it into the table.
04:40khaliGwell if i'm only changing one cell i dont want to rebuild a whole table (just because i'm lazy)
04:40AWizzArdThe interface gives me direct access to the atom.
04:41AWizzArdkhaliG: exactly, that is what (setTableCell [row, column-key, data]) is for.
04:41khaliGhow is your table stored internally?
04:42AWizzArdAs I showed above: let [data (atom nil)]
04:42AWizzArdor (atom []) I had
04:42khaliGso you have a vector of rows?
04:42AWizzArdYes.
04:43AWizzArdsetTableData will (reset! table-data data) the atom, and it fires via (.fireTableDataChanged ^AbstractTableModel this)
04:43khaliGunderstood
04:44AWizzArdThis approach I found to be pretty useful. May work for you.
04:44khaliGmy tables are tiny so i dont mind doing it that way
04:44AWizzArdScales very well.
04:45AWizzArdFor huge tables however one wants handlers that can take streaming data from a web server, and updates the table on the fly and not only when all data has arrived at the client side.
04:50khaliGgetting the feeling in clojure i wont find nice and easy to use mutable structures where i can just call a set! on them, it will be much harder than that
04:52ejacksonkhaliG: not at all - its really easy.
04:53ejacksonkhaliG: I spent yesterday banging around with JFreeChart which is the dark heart of mutability, and its tremendously easy.
04:55AWizzArdkhaliG: What about an atom and reset! ?
04:55AWizzArd(let [x (atom 10)] (println x) (reset! x 55) (println x))
04:55AWizzArd,(let [x (atom 10)] (println x) (reset! x 55) (println x))
04:55clojurebot#<Atom@10463c3: 10>
04:55clojurebot#<Atom@10463c3: 55>
04:55khaliGyea i get that part
04:56khaliGbut something like making a new vector thats different by one element at a given index?
04:56AWizzArdAs I see it, it fits very exactly what you asked for. Only that it is called 'reset!' and not 'set!'.
04:56khaliGreplace works on value not index
04:56AWizzArd,(assoc [10 20 30 40 50] 2 10000)
04:56clojurebot[10 20 10000 40 50]
04:57khaliGman i would never have guessed assoc would do that!
04:57AWizzArdBut this is a totally different issue now. A moment ago you criticized that Clojure does not offer you a mutable data structure that you can just set!.
04:57AWizzArdVectors are tries under the hood.
04:58AWizzArdTheir key is the index in the vec.
04:59khaliGassoc+set will do the trick for my problem
04:59AWizzArd,(let [a (atom [10 20 30 40])] (println @a) (swap! a assoc 2 99) (println @a))
04:59clojurebot[10 20 30 40]
04:59clojurebot[10 20 99 40]
05:13khaliGassoc will become my new best friend
05:14khaliGyay my table reflects user input changes :)
05:37AWizzArdkhaliG: grats
05:57khaliGis it possible to return an agent from a method in a proxied java class?
06:02khaliGdoesn't look like it, not just an agent but any random method added
06:03TobiasRaedermorning
06:03khaliGmorning
06:13khaliGAWizzArd, how did you define your helper class?
06:17AWizzArdkhaliG: definterface
06:17khaliGthanks
06:20khaliGhard to find docs on it :/
06:28tscheiblis it a bug that I have to 'rm -rf classes' first before i do 'lein ring war'? .. otherwise I get some 'duplicate entry' error
06:34khaliGAWizzArd, do you have a small example of definterface? i've looked everywhere without any luck
06:39khaliGAWizzArd, nm, i figured it out
07:33AWizzArdkhaliG: even though you figured it out, here an example of definterface: https://github.com/clojure/clojure/blob/master/src/clj/clojure/gvec.clj
07:33AWizzArdThis was used for implementing (vector-of :int) & co.
08:22jcromartielet's say I have n students, and want to divide them into tables of m students each
08:22jcromartieI can get a bunch of possible tables from c.c.combinatorics/combinations
08:22jcromartiebut that is only all tables of 5 over the whole set of students
08:28ejacksonand you want ?
08:34jcromartiesets of tables which only contain different students
08:34jcromartiesay
08:34jcromartie'(#{#{jim bob} #{sally sue}} #{#{jim sue} #{sally bob}} ...)
08:36fliebeljcromartie: I still don't get it, but I'm thinking abotu something with shuffle, partition, distinct, etc...
08:37jcromartiebasically, given a classroom... how many seating arrangements are there
08:37jcromartiewith a fixed table size
08:40jcromartieyeah I've been tinkering with this for a while but it just hasn't "clicked"
08:43jcromartiemost of the time I come up with some insane number of possibilities
08:43jcromartiebecause I haven't limited it right
08:45fliebeljcromartie: Logos!
08:46jcromartiehm that might be a good idea, actually
08:46jcromartiealthough I think I have an algorithm, starting with the set of all possible table arrangements
08:48fliebeljcromartie: So, you have x persons, sitting at a 2x tables in pairs?
08:48fliebelno x/2
08:49jcromartieno
08:50jcromartiex persons, sitting at x/n tables in groups of n
08:53fliebeljcromartie: And you want to know?
08:53jcromartiehow many ways you can arrange seats at the tables
08:54fliebelWithout permutations of the same persons for one table, I assume?
09:00kilo_hi
09:01AWizzArdHey kilo_.
09:01kilo_newbie here
09:02AWizzArdWelcome.
09:02joegallowell, welcome. and hello.
09:02kilo_hi AWizzArd
09:02kilo_thanks ! i'm planning to start of f by installing clojure box.
09:02fliebeljcromartie: Hm, there seem to be *a lot* of combinations :P
09:02kilo_:)
09:02kilo_hi
09:02jcromartiefliebel: yup
09:03jcromartieespecially with 30 kids and tables of 5
09:03jcromartieer, 25
09:03fliebel(distinct (map set (repeatedly #(map set (partition 5 (shuffle (range 20)))))))
09:05jcromartieyeah the shuffle is the trick
09:06fliebeljcromartie: That would go on forever.
09:06jcromartieso say I have the set of unique tables
09:06jcromartiebasically, (set (map set (c.c.combinatorics/combinations students n)))
09:07jcromartiethat's easy
09:07jcromartie1.5 seconds later...
09:07jcromartieI have 7288 tables
09:07fliebelgood :)
09:07AWizzArdkilo_: did you already see http://java.ociweb.com/mark/clojure/article.html ?
09:09jcromartienow from there, I've got this
09:09jcromartie(remove #(some % (first tables)) (rest tables))
09:09jcromartiewhich finds the rest of the potential tables for the first table
09:09jcromartieeasy
09:10kilo_i got this : http://news.ycombinator.com/item?id=1086562
09:10kilo_AWizzArd: yes, got it today
09:16fliebeljcromartie: ##(distinct (map #(set (map set (partition 2 %))) (clojure.contrib.combinatorics/permutations (range 6))))
09:16sexpbotjava.lang.ClassNotFoundException: clojure.contrib.combinatorics
09:17jcromartiepermutations are too intensive, fliebel
09:17jcromartiehttp://www.wolframalpha.com/input/?i=25!
09:17fliebelI see, that are a lot of permutations...
09:18jcromartiebut I think I've got it
09:18fliebeljcromartie: paste?
09:18jcromartiestarting with the combinations it's pretty easy to find a valid set for any one table
09:18jcromartieyeah just a minute
09:28ejacksonjcromartie: sorry, I stepped away. Do want the number of possible combinations, or to actually realise the sets of possible combinations ?
09:28edoloughlinTrying to add tests to an existing leiningen project... I've tried creating $PROJDIR/test/core.clj, $PROJDIR/test/$PROJDIR/core.clj and $PROJDIR/test/$PROJDIR/test/core.clj but I'm still getting "could not locate XXX on classpath" errors. Any ideas?
09:33ejacksonjcromartie: the former is, I think, \sum_{i=1}^{5} (5i)C5
09:33jcromartiehm weird
09:35ejacksonabout 72 000
09:36jcromartieout of memory
09:36jcromartieawesome
09:36jcromartie:P
09:37ejacksonthe factorials like to explode
09:37khaliGthere is an algorithm for generating them lazily so you don't run out of memory
09:39fliebelhm, probably another dead alleyway: ##(let [s (map set (combinations (range 20) 5))] (reduce (fn [t n] (if (not-any? #(seq (clojure.set/intersection n %)) t) (conj t n) t)) [(first s)] (next s)))
09:39sexpbotjava.lang.Exception: Unable to resolve symbol: combinations in this context
09:46jcromartiethat would explode in terms of computations
09:47jcromartiealthough maybe not too bad
09:47raekedoloughlin: how do you name the source and test namespaces? where do you put their corresponding files? what requires and uses do you have?
09:48raekedoloughlin: what we need to know to debug your problem would be all the 'ns' forms of your files, along with the file path for each one
09:52jowagHi, in deftype, do I have to implement all methods of the chosen interface or not?
09:53edoloughlinraek: I'm trying to retrospectively create tests on a lein project that doesn't have any. I've just created a core.clj file in the test subdirectory - there are no other test files. Do you want a directory listing? It's all of the form $PROJ/src, $PROJ/src/controllers, $PROJ/src/domain etc. and I have $PROJ/test
09:53jowage.g. is this correct? (deftype A [] IFn (invoke [this] (do something)))
09:54edoloughlinSorry: that should have been $PROJ/src/myproj/controllers etc. - I omitted the top level namespace
09:57raekedoloughlin: there is no automatic relationship between source and test code
09:58raekedoloughlin: the test namespaces are ordinary namespaces containing ordinary code
09:58edoloughlinraek: So what does 'lein test' look for as its starting point?
09:58raekso it sound like there's something wrong with when you in the test namespace require/use the source namespace
09:59raekedoloughlin: I think it loads all source files under test/
09:59raekbut I'm not sure, so check the lein docs on that one
09:59edoloughlinraek: Ok. Thanks.
09:59raek(I usually launch my tests straight from emacs)
10:03fliebeljcromartie: How is your code doing?
10:03jcromartiemeh
10:03jcromartiethe issue is something I failed to mention: a set of restrictions on what exactly defines a valid table
10:04jcromartie:P
10:04jcromartiethere are a bunch of students who cannot sit together
10:04jcromartieand so by filtering on that, I get a limited number of tables
10:04fliebeljcromartie: Oh, this starts to look more and more as a logic programming problem ;)
10:04jcromartieyeah
10:04jcromartiebut actually
10:04jcromartieit might be impossible to sit this particular set of restrictions
10:05jcromartieI think a better approach would be a Monte Carlo simulation
10:05jcromartieand make the restrictions less rigid
10:05jcromartieso you can score the seating
10:05fliebeljcromartie: If ti is impossible, Logos will tell you.
10:05jcromartiehm, nea
10:05jcromartieneat
10:05jcromartielink/
10:05jcromartie?
10:05jcromartie(https://github.com/swannodette/logos)
10:05fliebel$google clojure logos
10:05sexpbotFirst out of 11900 results is: Logos v0.4 - Closing in on SWI-Prolog ? - Clojure | Google Groups
10:05sexpbothttp://groups.google.com/group/clojure/browse_thread/thread/564d7885630549db
10:06fliebelI ordered The Reasoned Schemer to learn this stuff :)
10:06jcromartie$google logos clojure
10:06sexpbotFirst out of 12000 results is: Logos v0.4 - Closing in on SWI-Prolog ? - Clojure | Google Groups
10:07sexpbothttp://groups.google.com/group/clojure/browse_thread/thread/564d7885630549db
10:07jcromartieweird
10:07jcromartiein my browser I get a bunch of stuff about Clojure logo graphics :P
10:07AWizzArd(:
10:08AWizzArdyou can try bing instead and see if that performs better
10:08fliebelOr DuckDuckGo, or…
10:11jcromartiefliebel: I'm afraid this is all greek to me
10:11jcromartieI've never done Prolog
10:12fliebeljcromartie: That is why I ordered the book… It's Italian to me. I can follow it a bit, but not write it.
10:13jcromartiewell then maybe in that case I should say it's all Thai to me or something
10:15fliebeljcromartie: I think the musicians example is useful to you. If you extend that a little, you could use it to determine valid neighbors.
10:19ejacksonjcromartie: if you can assign a score to the set of arrangements then indeed, a MC approach is a good one. You could optimise that score using simulated annealing pretty easily.
10:19ejacksonlogic programming is going to give you all the solutions, which is not what you want, you just want one that is good enough.
10:20fliebelejackson: Why would logic programming do that to you? doesn't that depend entirely on how you write it?
10:21fliebel$google Monte Carlo simulation
10:21sexpbotFirst out of 627000 results is: Monte Carlo method - Wikipedia, the free encyclopedia
10:21sexpbothttp://en.wikipedia.org/wiki/Monte_Carlo_method
10:21ejacksonfliebel: I'm no expert, but it operates by performing a search for the complete set of suitable solutions.
10:22clgvejackson: but prolog for example stops with the first valid solution and you have to use special statements to get all solutions
10:23ejacksonclgv: i did not know that
10:23fliebelHm, I don;t know about Logos, but if it does this stuff lazily, you could do (first) on it.
10:30jcromartiefliebel: the issue is when it gets fuzzy... say you have a set of restrictions that makes it impossible from a logic programming standpoint
10:31ejacksonjcromartie: such as ? It sounds a lot like the Zebra problem.
10:33jcromartiewell, let's say you really have restrictions that yield no solutions
10:33jcromartieit would be better, in this case, to let it be "good enough"
10:34ejacksonthen optimising a score is superior
10:34clgvjcromartie: if there are restriction that make you problem unsolvable - can't you do a mathematical analysis in advance to see if you can get crtieria on that?
10:34ejackson(as an aside http://intensivesystems.net/tutorials/logic_prog.html for the zebra problem)
10:36jcromartieclgv: I don't know that much math.
10:38jcromartiegreat, thanks ejackson
10:49fliebelHah, when you're talking about the devil, you step on his tail :) The Reasoned Schemer just arrived :D
10:53ejacksonfliebel: good luck, its a tough read :)
10:53jcromartiehuh looks like http://kanren.sourceforge.net/ is pretty much broken
10:53jcromartielinks, that is
10:53ejacksonyeah, I had little luck with that either
10:54fliebelejackson: Thanks :)
11:30semperos1anyone know how to get slime's M-. working on Windows? I do have an unzip utility on the path, but I still get errors
11:38dnolenanybody ever tried constraint logic programming in Clojure a la Mozart/Oz ? Or played around with this, http://jacop.osolpro.com/ (Java Constraint Solver)?
11:39companion_cubei've not played with it in clojure, but i know a bit of jacop
11:39dnolencompanion_cube: any opinions, thoughts about it?
11:39companion_cubeit's cool :)
11:40companion_cubemost of the API is creating objects
11:40dnolencompanion_cube: anything specific you used it for that you can talk about? :)
11:41companion_cubei did not use it, i've worked a bit with one of the guys that writes it
11:41dnolencompanion_cube: heh, cool.
11:42raekletting two threads share an unsynchronized mutable object is not much different from abusing global variables
11:43AWizzArdright
11:43ejacksonso it is.
11:53gkoIf I want to use SLIME for both Clojure and Common Lisp, should I really stick to ELPA's SLIME (20100404) or can use CVS version? (swank-clojure in ELPA's wants SLIME 20091016)
11:55puredangeranyone out there worked with emacs + lein + cdt ? I'm looking for advice on how to get emacs-cdt working with separate lein swank
11:56puredangerI have "lein cdt" working targeting my process in emacs with "lein swank" but I would really like to be running the cdt repl in emacs as well (maybe a separate emacs if that's easier)
11:57puredangerThe lein cdt hooks seem to install the jdt options for lein swank such that I can't start two lein swanks as they collide on the jvm debug ports
11:57puredangeris there a technomancy in the house?
11:59raekNow I feel that I really understand what "Mutable stateful objects are the new spaghetti code" means
12:07ejacksonraek: aren't insights like that great !
12:10technomancypuredanger: I haven't used cdt yet, sorry. it may have port numbers hard-coded in?
12:11puredangertechnomancy: it does fer sure
12:11technomancytime for a patch then
12:11puredangertechnomancy: yeah, maybe I'll try that. just hard to believe no one hasn't had this issue already
12:13technomancyI guess lots of people only keep one swank server running at once or at least don't start cdt until they need it
12:15ohpauleezpuredanger: I use cdt with lein-cdt, but I use nailgun, sorry
12:40cinchtechnomancy: when my project.clj has a :main section and i call "lein swank", it runs the main instead of starting swank, is that normal or did i misconfigure something?
12:42technomancycinch: :main should point to a namespace that contains a -main function; it shouldn't have anything happening at the top level except def/defn forms.
13:01hvwow! java chokes on (Double/parseDouble "2.2250738585072012e-308")
13:03cinchtechnomancy: thanks for the info. i think i found a minor bug, which happend when i had (defn -main [] ) instead of -main with a body. (brb)
13:08khaliGwhen using proxy, how do you call another method in the superclass -- i'm thinknig (.method this) which seems to compile at least
13:09amalloykhaliG: that sounds right to me. are you having trouble with it?
13:10khaliGamalloy, yeah, but it may be unrelated
13:11raekkhaliG: that sounds right. in java, the bytecode for foo() is the same as this.foo()
13:11fogus`,(doc proxy-super)
13:11clojurebot"([meth & args]); Use to call a superclass method in the body of a proxy method. Note, expansion captures 'this"
13:13amalloykhaliG: https://gist.github.com/27effcd9c46a0ca6f701 works as expected
13:13raekah. my utterance would be for the particular situation where you don't override that method.
13:14amalloyyou should only need proxy-super if you want to call a superclass's method when you also override that method
13:14fogus`(inc amalloy)
13:14sexpbot⟹ 5
13:16khaliGyea i think my program is failing for an unrelated reason, thanks guys
13:16amalloykhaliG: if the superclass method you're trying to call is protected you have to jump through some hoops
13:17khaliGnope, not protected it's a method of AbstractTableMOdel and i'm calling it like (.fireTableChanged this)))))
13:18khaliGbut it's not forcing a redraw of the table for some reason
13:19khaliGooh, my mistake! i should have called .fireTableDataChanged
13:19amalloykhaliG: swing, what fun
13:19khaliGsweet :)
13:19khaliGamalloy, yes but it's much much better in clj
13:20fogus`"Clojure: Making Swing less repulsive since 2007"
13:21khaliGfogus`, well said
13:25amalloyScriptor: pharen looks just enough like clojure to make me comfortable, and enough like CL to trip me up :)
13:26Scriptoramalloy: thansk, though I swear any CL-yness is completely accidental :p
14:00mattmitchelli'm using :require in my namespace, which uses the :as option to bring in a function. Is it possible to access this same :as function from another namespace?
14:01amalloymattmitchell: i don't think so. you can use alias or immigrate or something, which are in contrib, but it's generally frowned on
14:01mattmitchellamalloy: oh really? interesting.
14:02raekmattmitchell: :require-:as and :use-:only only affects the namespace they occur in. to get the same effect in another namespace, you have to specify it there too.
14:02mattmitchellraek: ok i'll do that. thanks.
14:04raekthe point is to let each namespace author shorten fully qualified names (like foo.bar/some-fn) to something shorter (like b/some-fn or some-fn) whatever way the author of that namespace feels like
14:07lotiagreetings all. is there a way to have lein use the version of clojure and clojure-contrib from clones of their respective git repos?
14:07amalloy$google lein checkout dependency
14:07sexpbotFirst out of 1200 results is: technomancy/leiningen - GitHub
14:07sexpbothttps://github.com/technomancy/leiningen
14:07amalloybah
14:08amalloyanyway lotia, i think lein calls them checkout dependencies; that's about all i know, but it should be enough for you to find out how to use them
14:08danlarkinyou can also use a SNAPSHOT, that's probably closer to what you really want
14:10lotiaamalloy, danlarkin: thank you
14:12raeklotia: I think SNAPSHOT versions are what you are looking for. (unless you want a less than a few days old version or apply your own patches, in which case I would recommend using the checkouts feature)
14:13raekhttp://build.clojure.org/snapshots/org/clojure/ <-- version can be found here
14:13lotiaraek: this is more from an i'm curious perspective rather than how would i use it for a real project perspective
14:14raeke.g. [org.clojure/clojure "1.3.0-SNAPSHOT"]
14:15raekok.
14:15lotiaraek: thanks
14:17raekSNAPSHOT = use a frequently built version, leiningen checkouts = override that with version with a checked-out/cloned version in the file system
14:20shikaga_Question: I have 2 files in the same directory and I include (:use class1) in the namespace of class2. But when I try to compile I get an error that says that class1.clj cannot be found in the classpath
14:20shikaga_What am I doing wrong?
14:22shikaga_What confuses me even further is that my test file created automatically by leiningen has no problem locating the file when using "lein test"
14:24khaliGis there a switch like construct?
14:24amalloykhaliG: there are cond and case, depending on what you want
14:25khaliGamalloy, case sounds like what i want, i have some keys and i want to eval an exp depending on key
14:27amalloykhaliG: there's also plain old maps: ##(let [options {:a first, :b second} type :a data [0 1 2 3]] ((options type) data))
14:27sexpbot⟹ 0
14:27khaliGvery cool
14:28amalloymultimethods are a nice generalization of all this; case is an optimized version when all your key types are compile-time literals
14:33raekshikaga_: are you sure that the names of the namespaces matches the paths of the source files?
14:34raekshikaga_: also, you have to use their fully qualified names, even though they are in the same directory
14:36shikaga_Yeah
14:36shikaga_I think I am not fully understanding how namespaces are working
14:36shikaga_investigating now
14:36shikaga_thatnks
14:40pdkit's not like java where every .java file has to have a public class with the same name as its filename
14:44amalloyshikaga_: heh. here i am, putting off writing an article about managing clojure namespaces, and not even #clojure is a safe haven :)
14:45rsenior`amalloy: ping
14:45amalloyrsenior`: pong
14:46Scriptorquick question, what does clojure use internally as its hash function for hashmaps?
14:46amalloyScriptor: Object.hashCode()
14:47Scriptorah, thanks!
14:47rsenioramalloy: the issue I was talking to you about yesterday, I finally traced it down and was able to get better example code around it http://groups.google.com/group/leiningen/browse_thread/thread/cd433a9e8ac689c1
14:48hiredmanthat is not a lein issue
14:48hiredmanthat is the clojure compiler
14:49amalloyrsenior: weird
14:49rseniorreally?
14:50hiredmanlein doesn't do anything with classloaders
14:50rseniorwhen I ran it from the command line, without lein, it seemed to work ok
14:50rseniordoesn't compile/eval-in-project run compilation in an ant created classloader?
14:51hiredmanno, it starts a new jvm (at least in all releases, dunno about on master)
14:51hiredmanit does use ant to launch the new jvm, but the classloader won't be shared between them
14:54rseniorI'm still a little puzzled as to why it would work from the command line (passed in as -e to clojure.main, just like how Leiningen does it)
14:54hiredmanfor a simple solution to your multimethod problem, you could dispatch on the name of the class instead of the class
14:55hiredmanrsenior: *shrug*
14:56rsenioryeah, I've talked through some workarounds with coworkers, that was one of them
14:59khaliGis it idiomatic to define small helper functions using let?
14:59kryftI read "idiotic" :P
15:00amalloykhaliG: yeah, that's fine
15:00amalloyyou can use letfn if you like, though i don't
15:00brehautkhaliG: yes i think it is. especially for functions that closure locals but are growing large
15:01khaliGcool thanks
15:01khaliGnah i'm lazy less syntax to learn :P
15:03amalloymy thoughts exactly
15:13khaliGhm it doesnt like (. Boolean class)
15:14amalloykhaliG: Boolean is already the class
15:15khaliGoh yea, good point
15:15amalloy&(map class [Boolean Boolean/TYPE])
15:15sexpbot⟹ (java.lang.Class java.lang.Class)
15:16amalloyhm, not the point i intended to make.
15:16amalloy&[Boolean Boolean/TYPE]
15:16sexpbot⟹ [java.lang.Boolean boolean]
15:18fliebelweird… ##(class boolean)
15:18sexpbot⟹ clojure.core$boolean
15:18amalloyfliebel: boolean is a function
15:19amalloy&(boolean 10)
15:19sexpbot⟹ true
15:19fliebelamalloy: I know, so what did Boolean/TYPE just return?
15:19amalloy&(str Boolean/TYPE)
15:19sexpbot⟹ "boolean"
15:19amalloygrr
15:20hiredmanBoolean/TYPE is used by the clojure compiler internally for the clojure readable name of the boolean primitive's class
15:20hiredmanwhich is, I dunno, Z I think
15:20amalloyhttp://download.oracle.com/javase/1.4.2/docs/api/java/lang/Boolean.html#TYPE
15:20amalloyhiredman: yeah, i think it's Z
15:20hiredman,(Class/forName "Z")
15:20clojurebotjava.lang.ClassNotFoundException: Z
15:21hiredmanwell, I should say "type" not "class" above
15:21fliebelSo, Boolean/TYPE is not just a symbol, but something magic for the compiler, that evaluates to a primitive?
15:22hiredmanBoolean is a symbol too
15:22amalloy,(.getMethod Class "isArray" (into-array []))
15:22clojurebotjava.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.Class;
15:22amalloy,(.getMethod Class "isArray" (into-array Class []))
15:22clojurebot#<Method public native boolean java.lang.Class.isArray()>
15:22hiredmanthere is by default, an entry in all namespaces that maps the symbol Boolean to the class Boolean
15:23amalloysomehow or other you can find the class name for primitive booleans :P
15:23anthony__If I have an external file with a bunch of forms (def "a" 1) (def "b" 2) etc...and I want to read/eval all of them, how do I do that? (eval (read-string (slurp "file"))) only does the first one.
15:23hiredmanthere is no class for primitives though
15:23amalloyhiredman: yes there is
15:23hiredmanno there isn't
15:23hiredmanthere is a type
15:24hiredmanprimitive arrays have a classname (due to the jvm sort of kind of sometimes treating arrays as objects)
15:24hiredman,(Class/forName "[Z")
15:24clojurebot[Z
15:24hiredman,(Class/forName "Z")
15:24clojurebotjava.lang.ClassNotFoundException: Z
15:24amalloyfrom the javadoc for Class: "The primitive Java types (boolean, byte, char, short, int, long, float, and double), and the keyword void are also represented as Class objects."
15:25hiredmanthat is a java specific fiction, I believe
15:25amalloyhiredman: kindasorta
15:26amalloy&(.getComponentType (class (boolean-array 2)))
15:26sexpbot⟹ boolean
15:26pdkin javaland
15:26amalloyis a Class object, which represents the primitive type boolean
15:27pdkhaving primitives not be able to be treated like composite objects is supposed to be a good idea for some reason
15:27fliebelinteresting
15:27hiredmanamalloy: it very well may be, but sexpbot is ignored, so *shrug*
15:27pdkTHE PRIMITIVE BOXING ARMY MARCHES FORWARD
15:27amalloy,(.getComponentType (class (boolean-array 2)))
15:27clojurebotboolean
15:27amalloypdk: i don't think anyone thinks it's a good idea, but it was a convenient idea when java was written
15:27hiredman,(class (.getComponentType (class (boolean-array 2))))
15:27clojurebotjava.lang.Class
15:27fliebelhiredman: Why is sexpbot ignored?
15:28amalloyfliebel: he doesn't like sexpbot
15:28hiredmanfliebel: it does a lot of annoying things
15:28hiredmanat least it used to, hard to say now since it's been on ignore
15:28amalloyheh
15:29amalloyi think Raynes listens to community complaints if it does something annoying in #clojure, but of course you're entitled to ignore it
15:29fliebelhiredman: Only thing I ever noticed it doing without explicit command is mentioning Clojars updates.
15:29hiredmanfliebel: that is clojurebot, unless sexpbot does that too
15:29amalloyno, just clojurebot
15:29amalloyfliebel: hang out in #sexpbot sometime. there are a lot of features that are explicitly disabled in #clojure to reduce clutter
15:30amalloybut anyway, this discussion was about primitive types, not the robot wars
15:31khaliGheh :)
15:33fliebelamalloy: Sorry, I was poking at hiredman to test LauJensen's statement that he is rude and insulting. False so far :) But about the primitives… Is there a way to get to Boolean/TYPE without actually using that?
15:33amalloyfliebel: two ways have just been demonstrated: ##(Boolean/TYPE) and ##(.getComponentType (boolean-array 0))
15:33sexpbot(Boolean/TYPE) ⟹ boolean
15:33sexpbot(.getComponentType (boolean-array 0)) java.lang.IllegalArgumentException: No matching field found: getComponentType for class [Z
15:34hiredmanfliebel: for what purpose?
15:34amalloyer
15:34amalloy&(.getComponentType (class (boolean-array 0)))
15:34sexpbot⟹ boolean
15:34hiredmanI have been rude and insulting to LauJensen, but he deserved it
15:34fliebelhiredman: Curiosity, I wondered why I should write Boolean?TYPE rather than jus [B or something.
15:35amalloyfliebel: ^"[B" is an array of bools, not a bool
15:35amalloyis the typehint for an array of bools, that is
15:35hiredmanBoolean/TYPE is readable bby the reader, [B isn't
15:35fliebelI see.
15:36amalloy|afk-foreman
15:36amalloy|afk-forenick length limitations
15:36hiredmanthe compile may provide something like ^booleans for type hinting, it does for some of the other primitives
15:36fliebelamalloy: Can I aslo do ^Boolean/TYPE for a type hint?
15:36fliebelah
15:36hiredmancompiler
15:54andyfingerhutIn Clojure 1.2, is there a way to declare a method with a return value that is an array of Java primitives specifically? That is, not just defaulting to an Object, which all Java arrays are, but specifically an array of primitives?
15:54andyfingerhutSorry, I meant all of that "in a definterface"
15:55amalloy_andyfingerhut: we had a long discussion about this like half an hour ago; you probably want to just check out the logs. tl;dr: ^"[D" should be the type-hint for an array of doubles
15:56amalloy_&(class (double-array 1))
15:56sexpbot⟹ [D
15:56andyfingerhutSorry I missed it.
15:56hiredman^doubles actually
15:58hiredmanhttps://guthub.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Compiler.java#L975
15:59andyfingerhutSo I can AOT compile a program with either ^"[D" or ^doubles as the type hint for a method return value in a definterface, but if I then try to do clojure.contrib.repl-utils/show with the name of the interface, I get a run time error NoClassDefFoundError: java/lang/doubles
15:59andyfingerhutIs the type hint working, but there is perhaps a bug in repl-utils/show?
16:01hiredmandefinterface may not know how to do the ^doubles thing
16:01andyfingerhutOr the ^"[D" thing, apparently.
16:02amalloy_hiredman: oh, that's handy. what about an array of double arrays?
16:04andyfingerhutdefinterface seems to have the same limitation in type-hinting arguments to methods: Java primitives can be hinted fine, and individual references of Object or any subclass, but not arrays of any kind (that I've found a syntax for).
16:04hiredmanamalloy_: I think you are best off using ^objects in that case
16:05hiredmanandyfingerhut: you could inspect the output of the definterface macro
16:05andyfingerhuthiredman: You mean the byte codes it emits?
16:05andyfingerhutOr just the macroexpansion?
16:06hiredmanthe second
16:06andyfingerhutI'll try that...
16:06hiredmanyou may need to pull the form apart and inspect the metadata on different pieces too
16:08khaliGis there a looping construct to perform side-effects over a sequence?
16:09khaliG(this is for setting the width for table columns in swing)
16:09fliebelkhaliG: doseq?
16:10khaliGfliebel, sounds liek the thing, thank you
16:25scottjcan anyone explain this behavior, (defn ^{:a 1} foo []) (meta foo) => no {:a 1} then (defn ^{:a 2} foo []) (meta foo) => {:a 1}
16:34scottjthat's in clojure 1.2. something must be different in 1.3 bc all those meta calls return nil
16:34raekscottj: I get nil both times (1.3)
16:34raekscottj: the metadata you put on the symbol ends up on the var, rather than the function object
16:35raekbut that behaviour in 1.2 looks a bit weird to me
16:35raek(meta #'foo)
16:37khaliGis there a way to print to string?
16:38raekkhaliG: pr-str
16:38khaliGraek, cheers
16:38brehaut,(with-out-str (prn "hello"))
16:38clojurebot"\"hello\"\n"
16:38raek&(pr-str [:foo "bar"])
16:38sexpbot⟹ "[:foo \"bar\"]"
16:38scottjraek: in 1.2 the (meta foo) will return old data while (meta #'foo) returns latest
16:40scottjthe reason I wanted to put the data on the function instead of the var is it seems easier to get at. if I have foo then (let [x foo] (meta x)) will work while it won't if the data's on the var I'm not sure how to get to it if there's indirection
16:43fliebelscottj: Maybe you could do a macro to do (def (with-meta (fn)))
16:43raekscottj: what are you using the metadata for?
16:45scottjraek, type checking. I have an abstraction that can be either maps or fns
16:46scottj something like (defn slice? [x] (or (instance? slice.core.Slice x) (and (fn? x) (:slice (meta x)))))
16:47raekthen I believe what fliebel makes sense.
16:48raekif you are inspecting the functions rather than the vars
16:48raek*what fliebel suggested
16:48scottjwell I'd be happy to inspect the var but in the function slice? I pasted I'm not sure how to do that since calling (var x) will fail
16:49raekin general, you can't go from function object to var object
16:50scottjas in (defn foo [x] (var x)) (foo map) ?
16:50raekvar is a special form.
16:50raekthe symbol representing the var must be known at compile time
16:50scottjyeah, so there's no macro trickery to make that work you'd have to call (foo #'map)?
16:51raekthen you can't use it with anonymous functions, or functions that has been letted or passed though a function parameter on the way...
16:52scottjok so was fliebel saying (def fn-name (with-meta (fn declaration...)) instead of defn?
16:52raekif you need the metadata on the function, then put it on the function
16:52raekyes
16:52raek(def foo (with-meta (fn [x] ...) {:a 1}))
16:54scottjgosh that's annoying that defn doesn't work that way bc now I have to set the metadata for arglist etc manually
16:54raekyou can write a macro for that...
16:55scottjI think this will work, thanks for the help!
16:55raeknp.
17:07semperostrying to do a basic gen-class
17:07semperoshere's my code
17:07semperoshttps://gist.github.com/819398
17:07semperosstacktrace included for when I run "lein compile"
17:08semperoswhat am I doing wrong?
17:09raeksemperos: the JVM doesn't allow names with dashes in them (the "-" prefix is removed by clojure, so it doesn't count)
17:09semperosheh
17:10semperosnow I remember that
17:10semperosraek: thank you
17:10raek(this is why - in namespace names are translated into _ in file names)
17:11semperosraek: yep
17:11semperosI'm a little spoiled by recent JRuby use
17:11semperoswhich auto-converts between underscored and camel-cased method names
17:11semperosso you can write it either way in your jruby
17:12semperosI pay attention to is for namespaces, wasn't even thinking about it for the function call, but makes perfect sense
18:03jhultenI am having an issue reading a property file... https://gist.github.com/819513
18:03jhultenIf anyone has pointers, it would be appreciated.
18:25markskilbeckHow would I send color-coding escape characters to something like println?
18:26beliefHey guys, what is the best resource to getting started learning clojure for an experienced Java developer?
18:27pdkthe books programming clojure or practical clojure would work
18:27pdkgrab a primer on lisp like the online version of sicp as well perhaps
18:28beliefthanks pdk
18:28beliefwill check them out
18:28markskilbeckbelief: http://clojure.blip.tv/file/982823/
18:28clojurebot#<RuntimeException java.lang.RuntimeException: java.lang.Exception: 502>
18:29pdkyou so silly clojurebot
18:29markskilbeckchuckle chuckle
18:29beliefthanks markskilbeck had not come across those videos
18:38rata_hi
19:23_Vi"user=> (ns qqq (:use some.namespace))" -> It parse some/namespace.clj. How to make it to parse the file again?
19:23_Vi(without reloading JVM)
19:26dakrone_Vi: (ns qqq (:use [some.namespace] :reload-all))
19:28_Vidakrone, Thanks, it works.
19:31dakronenp
19:39amalloymarkskilbeck: re color codes, you should be able to include any characters you want in your string with \x or \u escapes
19:40markskilbeckamalloy: thanks
19:40amalloyhm, not \x, i guess
19:40amalloy&"\u000a\u0007"
19:40sexpbot⟹ "\n"
19:41amalloyresults in \n and a bell noise in my repl
20:16no_mindI have a string with & characters in ti. I want to split into smaller strings at & characters and store sub strings as a vector, in the order they appear in original string. How do I do this ?
20:17brehaut,(vec (.split "foo&bar&baz" "&"))
20:17clojurebot["foo" "bar" "baz"]
20:18brehautno_mind: does that answer your question?
20:19brehautsecondly, if you are doing this for HTTP, im sure there a library in ring to do it for you
20:19no_mindbrehaut: yup, thanks
20:29amalloybrehaut: what, no regexes?
20:30no_mindI have couple of webpages as html files. Is there a library that can take html pages, fill values from database and render the page. These are html forms and I want to edit some entities in the application
20:31brehautamalloy: fine ##((comp vec (partial take-nth 2) (partial re-seq #"[^&]*")) "foo&bar&baz")
20:31sexpbot⟹ ["foo" "bar" "baz"]
20:31brehautno_mind: sounds a lot like enlive
20:32no_mindamalloy: any advantage of using regex in this situation ?
20:32brehautno_mind: its a joke at my expense
20:32no_mindok
20:41mec_with emacs (clojurebox) is there a way when i eval in a buffer to send it to the repl so the result is printed instead of just flashing in the messages window?
20:48amalloymec_: C-c C-c evaluates a top-level form, so that will probably work?
20:51mec_amalloy: C-c C-c is just giving me an error, i usually use C-x C-e or M-C-x, but that will only return the result in the messages window not the repl
20:52amalloymec_: C-c C-c wants you to run C-c C-k at least once to compile the whole file, so that the namespace exists
20:52amalloynot ideal, but...
20:53qedamalloy: can't you just C-x C-e the (ns ...) and then C-c M-p, set the namespace in the repl, and then C-c?
20:53qedC-c C-c rather
20:53amalloyqed: probably, yes
20:53qedmy way sounds more complicated to explain, but i think is a bit more natural
20:54qedi dont like to load everything into the REPL at once usually
20:54amalloyqed: i usually load it all, myself. what do you use incremental loading for?
20:55qedamalloy: ill walk through code -- looking at the way functions behave along the way
20:55qedin order to get a feel for the code
20:56amalloyqed: for other people's code, or your own?
20:57qedboth sometimes :)
20:58qedi like to load up incrementally -- it usually goes pretty quick and by the time im done i have more of it in my head and can make better decisions about design etc.
20:58qedC-c C-k seems like a sledge hammer -- i like to whittle
20:59amalloyfair enough
21:01qedamalloy: but of course, if i make some sweeping change like renaming something throughout several files then I C-c C-k like a mad man :)
21:03mec_This is mainly for a scratch file that doesnt have a (ns ...) so I can keep track of dev in the repl. I really just want whatever I eval to behave as If i copied it into the repl first and hit enter
21:04qedmec_: check out C-h C-x C-e and see what it calls versus what C-c C-c calls
21:06mec_C-c C-c just gives namespace error, C-h C-x C-e is undefined
21:06qederr C-h k C-x C-e
21:06mec_ slime-eval-last-expression
21:06no_mindis it possible to merge two vectors and create a new vector ?
21:07brehaut,(concat [1 2 3] [:a :b])
21:07clojurebot(1 2 3 :a :b)
21:07qed,(apply conj [1 2 3 4] [5 6 7 8])
21:07clojurebot[1 2 3 4 5 6 7 8]
21:07qedbrehaut's is the right way though :)
21:07amalloyno_mind: well yes, but the usefulness of an answer will depend on what you mean by "possible" and "merge"
21:08amalloy(and also possibly "vector")
21:08qed:D
21:08qedbrehaut: i've found that most of the time with clojure it's best to phrase your question in terms of what you're trying to achieve
21:08qederr no_mind
21:08brehautheh
21:08qedan example would be better is what i'm saying...
21:08no_mindamalloy: let me rephrase, say have two vectors [a b c] and [d e] I want to create a vector which has [a b c d e] , in that order
21:09qed,(concat [1 2 3] [4 5])
21:09clojurebot(1 2 3 4 5)
21:09mec_,((comp vec concat) [1 2 3] [4 5 6])
21:09qedseems to do the job, no_mind -- no?
21:09clojurebot[1 2 3 4 5 6]
21:09brehaut$findfn [1 2 3] [4 5] [1 2 3 4 5]
21:09sexpbot[clojure.set/union clojure.core/lazy-cat clojure.core/concat clojure.core/into]
21:09brehautqed, like that? ;)
21:10mec_zomg i wants it
21:10qedi was going to suggest into actually
21:10brehaut$findfn inc [1 2 3] [2 3 4]
21:10sexpbot[clojure.core/map clojure.core/pmap clojure.core/keep]
21:10brehaut,(doc keep)
21:10clojurebot"([f coll]); Returns a lazy sequence of the non-nil results of (f item). Note, this means false return values will be included. f must be free of side-effects."
21:10amalloyhaha pmap. way to go sexpbot, solve these problems with the magic of threading
21:11mec_interesting
21:11brehauthuh. keep is cool
21:11qed,(into [] (concat [1 2 3] [4 5 6]))
21:11clojurebot[1 2 3 4 5 6]
21:12brehaut,(into #{} (concat [1 2 3] '(4 5 6 1))
21:12clojurebotEOF while reading
21:12brehautbah
21:12qednaughty!
21:12amalloyinto is the right answer, though
21:12mec_where can i get findfn
21:12qedmec_: sexpbot ;)
21:12amalloymec_: nobody's bothered to write a version that doesn't live in sexpbot
21:12qed$findfn #{:a 1} [1 2 3]
21:12sexpbot[]
21:13qed$findfn [1 2 3] [3 2 1]
21:13sexpbot[clojure.core/rseq clojure.core/reverse]
21:13amalloybut you can ask him via /msg sexpbot findfn blah blah blah
21:13gfrlogI can't bind symbols in a macro can I? ("Can't use qualified name as parameter"...)
21:14amalloygfrlog: there are two ways to do it depending on your goal
21:14gfrloge.g., local variables that I want the caller to be able to access
21:14gfrlogI know about the x# thing
21:14amalloyah, then you want the other answer
21:14brehauthaha the other answer
21:14gfrlog:) I guess so, because I'm assuming x# is inappropriate here
21:14mec_,(source findfn)
21:14clojurebotjava.lang.Exception: Unable to resolve symbol: source in this context
21:14qedbinary answers, only in clojure/.
21:14gfrlogsince I want it to work before being rewritten
21:14amalloy&`(let [~'x 10])
21:14sexpbot⟹ (clojure.core/let [x 10])
21:14brehautmec_ its part of sexpbot, rather than clojure
21:15amalloy$whatis sexpbot
21:15sexpbotsexpbot is http://github.com/Raynes/sexpbot
21:15qedmec_: cd-client could be nice for you
21:15gfrlogholy jackwagon
21:15qedlol
21:15mec_ah ok
21:15qedjackwagon...
21:16qedhttps://github.com/Raynes/sexpbot/blob/master/src/sexpbot/plugins/clojure.clj
21:16amalloyhttps://github.com/Raynes/sexpbot/blob/master/src/sexpbot/plugins/clojure.clj#L156 for findfn,
21:16qed:)
21:16gfrlogamalloy: could you explain what is going on with your 3 kinds of quotes? I've not seen most of thoes outside a macro
21:16amalloygfrlog: macros aren't special; ` works anywhere
21:16qed$`(let [x 10])
21:16amalloybut i can't defmacro in sexpbot or clojurebot
21:16qed,`(let [x 10])
21:16clojurebot(clojure.core/let [sandbox/x 10])
21:17amalloy&`(let [x 10])
21:17sexpbot⟹ (clojure.core/let [clojure.core/x 10])
21:17gfrlogthis is witchcraft, right?
21:17qed,`(let [~x 10])
21:17clojurebotjava.lang.Exception: Unable to resolve symbol: x in this context
21:17amalloylol
21:17qed,`(let ['x 10])
21:17clojurebot(clojure.core/let [(quote sandbox/x) 10])
21:17qed,`(let [~'x 10])
21:17clojurebot(clojure.core/let [x 10])
21:17amalloygfrlog: http://hubpages.com/hub/Clojure-macro-writing-macros is something i wrote recently and is semi-on-topic
21:18amalloysearch for ~' to skip to the relevant part
21:19_ViI want clojure.lang.PersistentArrayMap, but with overridden toString. How it's better to do it?
21:19amalloy_Vi: ##(doc proxy)?
21:20sexpbot⟹ "Macro ([class-and-interfaces args & fs]); class-and-interfaces - a vector of class names args - a (possibly empty) vector of arguments to the superclass constructor. f => (name [params*] body) or (name ([params*] body) ([params+] body) ...) Expands to code which cre... http://gist.github.com/819794
21:20qed,'~`'~'!
21:20clojurebot(clojure.core/unquote (clojure.core/seq (clojure.core/concat (clojure.core/list (quote quote)) (clojure.core/list (quote !)))))
21:20qed*evil grin*
21:21gfrlogamalloy: that is quite
21:21qedI thought proxy had fallen out of favor...
21:21gfrlogI think ~' works though, since I'm getting other errors; so thanks!
21:21amalloyquite...anything in particular?
21:22gfrlogquite describably by adverbs maybe?
21:22amalloyqed: maybe. i don't know any better way to get actual implementation inheritance
21:23qedamalloy: reify?
21:23brehautamalloy: the alternative would to reify the whole interface, closuring the map in question i think
21:23amalloyright, but you have to do the whole interface
21:23qed^^ -- My understanding is that since 1.2 you should almost always be using reify
21:24qedproxy is niche
21:24brehautqed but this is the niche in question is it not?
21:24hiredmanproxy will generally be much slower
21:24qedand then hiredman comes in and owns everyone's face
21:24_Vi(proxy [clojure.lang.PersistentArrayMap] [{:key "val"}] (toString [] "qqq")) ;; What's wrong here?
21:25hiredman_Vi: why are you doing that?
21:25qed_Vi: the parens. lisp is a filthy, filthy language.
21:25_ViHow to create map {:key "val"}, but with overridden toString?
21:26brehaut_Vi you would want to closure over that map; its not a property of the proxy object itself
21:27_Vibrehaut, How to do it?
21:27brehaut(let [map {:key "val}] (proxy ...)
21:27brehaut)
21:27qedahhh yes...
21:27brehautand dont call it map, thats a terrible name
21:27brehaut(shadows a core method)
21:28hiredmanbrehaut: no
21:28brehauthaha no all of it, or one particular part?
21:28hiredman_Vi: I question your need to override .toString
21:28hiredmanbrehaut: all of it
21:28qedlol
21:28amalloybrehaut: proxying a closure won't be any better than reifying one
21:28qedno.
21:28qedfin.
21:28amalloyand if you're going to all the work, you might as well be fast with reify
21:28_Vihiredman, I'm inserting it to javax.swing.DefaultListModel.
21:29hiredman_Vi: and why does that require an overriden .toString?
21:30tomojbrehaut: shadowing isn't terrible
21:30_Vihiredman, It is displayed as '{:key "value"}' in gui instead of, for example, 'value'.
21:31gfrlog,(class *out*)
21:31clojurebotjava.io.StringWriter
21:31hiredman_Vi: if you want "value" you should put in value
21:31_Vihiredman, And how to retrieve the details of selected list item then?
21:33_Vi(let [q {:key "val"}] (proxy [clojure.lang.PersistentList] [q] (toString [] "qqq"))) ;; works
21:33hiredman_Vi: I don't have your code here, and I don't know what you are doing, but it seems like storing stuff you don't want to display in a swing coponent is a bad idea
21:33_Vi(let [q {:key "val"}] (proxy [(type q)] [q] (toString [] "qqq"))) ;; why doesn't it work?
21:34qedthere's too much java implicit in this question for me to be genuinely helpful.
21:35hiredmancomponent
21:35qedhiredman: you're going to have to offer more than that if you want him to understand you
21:35hiredmanand the javadoc for javax.swing.DefaultListModel says it is based on Vector, which is a bad idea in general
21:35qed_Vi: i dont mean to be rude, but im guessing your first language is not english
21:37_Viqed, What is not meaningful and needs revision?
21:37qedhiredman: is there a reason deftype shouldn't be considered here?
21:38brehaut_Vi: (str (let [m {:key "val"}] (proxy (Object) [] (toString [] "123"))))
21:38hiredmanqed: why should it be considered?
21:38gfrlogwhat's the easiest way for me to create a "middleware" java.io.Writer to use with *out*?
21:38qedhiredman: im asking you an open question -- does it have any bearing on this discussion in your opinion?
21:38tomojbrehaut: what's m for?
21:38brehaut_Vi: you need to pass the class or interface you want to proxy to the first arg of proxy (as per (doc proxy)); no superconstructure args. b) probably should use reify if its just the tostring you want and c) everything hiredman says
21:39brehauttomoj: presumably you'd do something smart with it insdie the proxy
21:39hiredmandeftype shouldn't generally be considered because defrecord is far more useful
21:39tomojthat sounds nuts
21:39hiredmanI should say in most cases
21:39qedI think proxy is definitely wrong here
21:40qederr I'll concede in a similar fashion and say that, in most cases, proxy is wrong
21:40hiredman(into list (vals {:key "value"})
21:40qedit used to be the only way, but we have so many more options to solve problems like this post 1.2
21:40hiredmanproxy, if anything, would be more correct in this case, because proxy would allow you to overide a method without have to implement the entire interface
21:41brehaut_Vi: corrected for tomoj's observation (str (let [m {:key "val"}] (proxy (Object) [] (toString [] (:key m)))))
21:41brehaut"val"
21:41tomojqed: isn't this a problem not worth solving?
21:41qedtomoj: DeMorgan's
21:42tomojis this problem worth solving? (I expect not)
21:43_Vibrehaut, If I replace "str" with ":key" I get "nil" instead of "\"val\"", so it's not like a map.
21:43tomojer, figured you wanted me to rephrase, but now that I think about it, what do you mean, "DeMorgan's"?
21:43qedtomoj: tomoj the double negative :)
21:44brehaut_Vi: are you wanting a map, or are you wanting something you can pass to your swing thingimy that takes a map and returns a string for display
21:44qedis not this a problem not worth solving?
21:44qedhttp://en.wikipedia.org/wiki/De_Morgan's_laws
21:45_Vibrehaut, I want subclass of map that is like PersistentHashMap, but with little bit of my functionality (toString).
21:45tomojdid you read it before linking it to me? I was considering sending you that link :)
21:45qedtomoj: actually ive completely screwed that up -- for some reason i think of demogran when i think of double negation
21:45brehaut_Vi: you do not want a subclass; this is not java. prefer delegation over inheritance
21:45hiredman_Vi: why do you need a subclass of PHM?
21:47_Vihiredman, To make an object that have certain differences from PHM but still compatible with it in all other places.
21:47qedtomoj: sorry about that :D
21:47hiredman_Vi: why do you need that?
21:48_Vihiredman, Here I'm trying to use it for DefaultListModel (but may be this can be useful in other places as well).
21:48hiredmanthat doesn't make sense
21:48brehaut_Vi are you familiar with the idea 'seperation of concerns'?
21:48hiredmanjust call a make-displayable function on it before hand
21:48qed_Vi: http://en.wikipedia.org/wiki/Separation_of_concerns
21:50brehaut_Vi: the basic idea here is that the data model aspect of your program (represented by the persistent hash map) is a seperate aspect to displaying it in a DefualtListModel. Because of this you should not have a piece of code that acts in both roles
21:51_Vibrehaut, OK, considering creating separate special object like DisplayableItem with reference to the map.
21:51brehaut_Vi if all you need is a ToString, theres already a built in type that provides ToString for you easily: String. you wont need to go to the effort of creating a new type.
21:52brehaut_Vi: just make a function that takese your map and produces a string that is the display value
21:52brehautalso sorry about the dotnet there
21:53brehaut_Vi: because your map is immutable, any object that just returns a tostring of it equivalent to just that string anyway
21:53qedaside: I constantly wonder about Java in clojure programs and what role it should play in practice
21:53_Vibrehaut, OK. Considering Clojure's classes as final and non-extendable (not-easily-extendable) for future.
21:54_Vibrehaut, The map is not just a string. When accessed from other places it is like a map.
21:54brehautqed its interesting eh; theres definate merit to it, but where does that leave clr clj, or js-clj or whatever
21:54brehaut_Vi and in those places, just provide the map
21:55qedbrehaut: i dont know man -- i kind of find using java in clojure programs to be sort of dirty -- it's not an objective criticism, it's more of a visceral reaction on my part
21:55tomojI'd bet if we had to write everything from scratch in pure clojure, clr and js wouldn't even be on the map
21:56_Viqed, Is using Java in Clojure like using asm in C?
21:56qed_Vi: no not at all
21:56brehautqed sure but at the same time, imagine clojure's web libs without all the stuff ring builds on
21:56qedclojure was /built/ to use java
21:56tomojs/we/they/
21:56sexpbot<tomoj> I'd bet if they had to write everything from scratch in pure clojure, clr and js wouldn't even be on the map
21:56qedi just find it sort of repugnant
21:56tomojsomeday I'm going to murder you, sexpbot
21:57qedtomoj: sexpbot knows more clojure than you do
21:57qedhe spends all day in this channel, every day, logging, watching, waiting, plotting...
21:57_Viqed, It makes the code less lispy?
21:58_Viqed, Public channel logs is one of the source of information. Sometimes I find answers there.
21:58qed_Vi: my opinion is somewhat extreme. java is so disgusting to me that even something as innocent as java.lang.String can make me want to kill someone
21:58qedbut that is definitely not the whole story
21:58qedusing java is a huge win for clojure
21:58qedi just personally go out of my way to not use it
21:59_Viqed, To love Clojure, while hating Java? Strange feeling?
21:59qedi like the lisp in clojure -- i like the JVM in clojure, but the Java, well, that's another story
22:02qedbrehaut: tell me im being irrational, spoiled, etc.
22:02brehautnah
22:02brehauti have no love for java.lang
22:03qedthat sounds like the seed of a rap song
22:03qedi gotz no luv 4 java.lang, son
22:03brehauthaha
22:04qedbrehaut: did you go to clojure conj?
22:04brehautqed nope; im literally on the wrong side of the world
22:04qedif you're on the wrong side and im on the "right" side, then we're all on the wrong side
22:04brehauthaha
22:06brehautqed where is your wrong side?
22:07gfrlogI bet he lives on the wrong side of the earth's crust
22:07brehauthes a hyperborian?!
22:08gfrlogthat is a strange word
22:09gfrlogsomething starting with "hypo" might do
22:10gfrlog,(clojure.java.io/make-output-stream "/dev/null")
22:10clojurebotjava.lang.IllegalArgumentException: No single method: make_output_stream of interface: clojure.java.io.IOFactory found for function: make-output-stream of protocol: IOFactory
22:10brehautgfrlog: in Hellboy, the Hyperboreans are the first race of man, and the decendants live secretly deep under the earth, occasionally rising up to try to reclaim their land
22:10brehautHyperborea was actually supposed to be on teh top of the world; eg the artic
22:11gfrlogokay. So I shouldn't take hints from the etymology then
22:11brehautnope
22:11gfrloghypocrustian
22:11gfrloghypocrustacian?
22:12gfrloganybody know the easiest way to replace *out* with /dev/null?
22:12zippy314gfrlog: (binding [*err* (java.io.PrintWriter. (writer "/dev/null"))] ... )
22:12gfrlog,(clojure.java.io/output-stream "/dev/null")
22:12clojurebotjava.security.AccessControlException: access denied (java.io.FilePermission /dev/null write)
22:13gfrlogzippy: that looks good, thanks
22:13zippy314just replace *err* with *out* (I was copying from my code)
22:13gfrlogright
22:13Scriptoranybody know exactly which algorithm Object.hashCode() uses?
22:14gfrlogdoesn't it return an int?
22:14gfrlog,(class (.hashCode "hooha"))
22:14clojurebotjava.lang.Integer
22:14hiredmanfor the default impl .hashCode could just be the pointer address
22:14gfrlog,(.hashCode 382)
22:14clojurebot382
22:14Scriptoryea, that seems to be the typical case
22:14hiredmanthe impl for a specific class can be whatever
22:14amalloyScriptor, hiredman: yes, for Object hash is just the memory address
22:15brehaut,(.hashCode (Object.))
22:15clojurebot15771477
22:15brehautthats closer to the 'default'
22:15amalloy&((juxt hash str) (Object.))
22:15sexpbot⟹ [5749406 "java.lang.Object@57ba9e"]
22:16brehaut" (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.)" – http://download.oracle.com/javase/1.4.2/docs/api/java/lang/Object.html#hashCode()
22:16amalloy&((juxt #(Integer/toHexString (hash %)) str) (Object.))
22:16sexpbot⟹ ["aa6e7e" "java.lang.Object@aa6e7e"]
22:17brehauthave some ellipsis for that preceeding quote: … …
22:18amalloy$sed -brehaut s/(.*)/...$1...
22:18sexpbot<brehaut> ...have some ellipsis for that preceeding quote: … ….........
22:18amalloyhm. more dots than i expected, but w/e
22:18hiredman^- if I actually saw that output it would be annoying
22:18amalloyhiredman: yeah, but that's me being annoying, not sexpbot :)
22:19amalloybut enabling and/or encouraging, you're right i'm sure
22:25bytecoloris this an appropriate way to bind *out* to /dev/null? (binding [*out (java.io.OutputStreamWriter. (java.io.FileOutputStream "/dev/null"))] (println "foo"))
22:25bytecolorI missed the response to the previous question, if there was one...
22:25hiredmanhttp://commons.apache.org/io/api-release/org/apache/commons/io/output/NullOutputStream.html
22:28bytecolorI missed an asterisk in *out*, and a period after Stream :/
22:29amalloyhiredman: funny stuff in there. i like the BrokenOutputStream
22:33bytecolor(alter-var-root (var paip.eliza1/variable?) (fn [_] #(some #{%} '(x y z))))
22:33bytecoloris there a proper way to do that? basically change a function in another namespace?
22:34bytecolorthat's a hackish way I figured out that works, but it just feels wrong on a number of levels ;)
22:35tomojone level likely being just what you're trying to do
22:35tomojwhy do you want to change it?
22:45amalloysritchie_: ping
23:09amalloy$mail sritchie http://commons.apache.org/io/api-release/org/apache/commons/io/input/SwappedDataInputStream.html looks like it would help with your pymath or whatever the problem library was
23:09sexpbotMessage saved.
23:15amalloybrehaut: how interested would you be in a version of findfn that worked like: $findfn (map $ [1 2 3]) [2 3 4] returns inc?
23:16brehautthat would be cool