#clojure logs

2011-01-21

00:15Deranderamalloy: no kidding
00:17amalloyDerander: oh good, it's not just my browser then?
00:17Derandernope
00:18Deranderalso, I'm a little confused at how a ruby example on #2 would take 35 lines as opposed to python's 10. if I understand the python there is nothing particularly difficult to accomplish in ruby
00:21hiredmanwhen reading anything on bestinclass.dk, it is important to remember that lau (the author) is an ignorant know nothing
00:21hiredmanI think that will explain any questions you may have
01:53LauJensenMorning all
01:57Scriptormorning LauJensen
02:09notsonerdysunnywhat is the official current source repository for clojure-contrib .. https://github.com/richhickey/clojure-contrib seems very old .. (last commit is 6 months ago .. )
02:10tomojhttps://github.com/clojure/clojure-contrib
02:12notsonerdysunnythanks tomoj
02:18notsonerdysunnywhere is data.finger-tree located .. it does not seem to be in either of clojure or clojure-contrib..
02:18notsonerdysunnyin sources that is..
02:19notsonerdysunnyI know there is a seperate repo for data.finger-tree .. but I was hoping it was going to be part of clojure or clojure-contrib.. am I missing something?
02:21notsonerdysunnyoh it is github.com/clojure/data.finger-tree.git .. ..
02:22notsonerdysunnyit is a seperate module .. how can I get the whole thing?
02:26tomojI don't think the author considers it ready enough to publish it
02:27tomoj.. or is it now?
02:27tomojit wasn't under clojure/ when I last looked
02:28notsonerdysunnyoh ic ..
03:16Licensermorning
03:58TobiasRaedermorning :)
03:58mduerksengreetings ^^
05:53LauJensenCan I get some input on this please? http://gist.github.com/789530
07:14bartjis there a HTML Parser which does lazy evaluation of nodes
07:14bartjthis is for web scraping btw
07:18hoeckLauJensen: nice! what about making sql-case more like a clojure cond? https://gist.github.com/789596
07:19LauJensenhoeck: Im actually working on that this very moment :)
07:19LauJensenhoeck: why the two ??'s after :alias
07:20hoeckLauJensen: because it looks like a "condp" or clojure "case" to me and at first I thought the :alias was the column to switch on
07:20LauJensenah ok
07:20hoeckand then late recognized is was the sql "as alias"
07:21LauJensenIt can be done exactly as condp actually, but Im not sure I want to support that syntax
07:21hoeckno, I guess thats not necessary, a nicer sql case, without the WHEN should be enough
07:21hoecka lispy case that is
07:22LauJensenyes - and its just one macro away :}
07:25hoeckLauJensen: how do you handle sql-"as" in select statements?
07:26LauJensenAre you asking me how to alias a column?
07:27hoeckLauJensen: no, rather subqueries in the select clause, like select (select ...) as bar from foo
07:27LauJensenhoeck: You never specify that yourself, ClojureQL works out when to do subselects
07:27LauJensenclojureql.core> (-> (table :t1) (sort [:id]) (sort [:wage]))
07:27LauJensenSELECT * FROM (SELECT t1.* FROM t1 ORDER BY t1.id asc) ORDER BY wage asc
07:27LauJensen
07:38ZabaQAre the eror messages always so java-esqe?
07:39LauJensenZabaQ: Yes sir
07:39ZabaQAh wel.
07:41LauJensenZabaQ: If you're a little nutty you could initialize your namespace like so (ns nuts (:refer-clojure :rename '{first car second cdr})) .... :)
07:42ZabaQI'm not so traditionalist :-)
08:16bsteuber1where did incanter.chrono go?
08:16bsteuber1or is there another recommended time conversion lib now?
08:17fliebelbsteuber1: I don't know, but I heard some people use clj-time, which is based in yoda, or something like that.
08:18LauJensenhoeck: there you go:
08:18LauJensenclojureql.core> (project (table :t1) [:id (case :alias (> :x 5) "low" (> :x 10) "high" :else "average")])
08:18LauJensenSELECT t1.id,CASE WHEN (x > ?) THEN low WHEN (x > ?) THEN high ELSE average END AS alias FROM t1
08:18LauJensen
08:20bsteuber1fliebel: clj-time seems less complete than what I believe was stuart halloways example code in several talks
08:21hoeckLauJensen: fine :)
08:21bsteuber1e.g. for creating java.sql.Date from it - though I'm sure it's dead simple :)
08:22hoeckLauJensen: the only thing that bothers me is the :alias, though I admit that I don't have any better ideas where to place them instead
08:23LauJensenhoeck: :( I thought it was such a great idea
08:24hoeck[:id (case (< :x 10) :else foo :as :alias)] ?
08:24LauJensenewww
08:24LauJensenWell... maybe...
08:25hoeckLauJensen: how do I write in clojureQL select id as foo?
08:25LauJensenSame way
08:25LauJensenclojureql.core> (project (table :t1) [[:id :as :foo]])
08:25LauJensenSELECT t1.id AS foo FROM t1
08:25LauJensen
08:25hoeckLauJensen: then why not use this for case too?
08:26LauJensenIts only a matter of taste
08:26hoeckI mean, at least its constistent and you don't have to remember where to place your alias
08:26LauJensenThats true
08:26hoeckLauJensen: taste, exactly :)
08:28hoeckLauJensen: those where just my 2c, I hope I will not have to use sql-case too often
08:28LauJensenhoeck: And I appreciate them, thanks
08:30fliebelHm… Exactly what overhead is eliminated by using chunks? Is it just the creation of a new seq for every step? If so, do transients still benefit from chunked behavior? Why isn't a chunk a seq? The implementation of map for example uses the .nth method(not in the IChunk interface) to iterate over the chunk in a one-by-one manner.
08:31clgvwhy not: (project (table :t1) [(as :id :foo)]]) ?
08:32bsteuber1interesting, calling bean on a java.sql.Date gives an exception
08:32bsteuber1at least in 1.2.0
08:32clgvoops messed up a bracket
08:33chouserfliebel: Less allocation per seq step. Yes. Transients aren't seqs. What would be the benefit?
08:34chouserfliebel: if map used seq to walk the chunk, it would still have to allocate an object for each step, ruining the only value chunks have.
08:34fliebelchouser: Sorry, is you last message "fliebel: if map used seq…"?
08:35fliebelI killed my irc client :(
08:35chouserfliebel: yep, you're all caught up
08:42fliebelchouser: I'm thinking about it… It seems a chunk does implement Indexed, which makes sense. So I could do (nth) on them rather than (.nth)(like map does) How 'private' are chunks?
08:43clgvis there something like a join-operation on to sequences?
08:43clgvs/to/two/
08:43sexpbot<clgv> is there something like a join-operation on two sequences?
08:44fliebelclgv: You mean like ##(doc concat)?
08:44sexpbot⟹ "([] [x] [x y] [x y & zs]); Returns a lazy seq representing the concatenation of the elements in the supplied colls."
08:44fliebelclgv: Or like.. clojure.unify/join?
08:44clgvnope. I have an attribute that is a UID in the objects of both sequences
08:45clgv&(doc clojure.unify/join)
08:45sexpbotjava.lang.Exception: Unable to resolve var: clojure.unify/join in this context
08:45fliebelMy bad… http://clojure.github.com/clojure/clojure.set-api.html#clojure.set/join
08:46clgv&(doc clojure.set/join)
08:46sexpbot⟹ "([xrel yrel] [xrel yrel km]); When passed 2 rels, returns the rel corresponding to the natural join. When passed an additional keymap, joins on the corresponding keys."
08:46clgvwhat is the "rel" supposed to mean? a map?
08:46chouserfliebel: I think chunks are a public interface, though it may be wise to think of it as a bit experimental yet and subject to change.
08:47chouserclgv: A relation -- a set of maps
08:48fliebelchouser: Okay, thanks.
08:48clgvchouser: I know the mathematical definition of relation. how does this relate to a set of maps?
08:49clgvrelation: a->b c->d relates to #{ {a b} {c d} }?
08:50fliebel&(clojure.set/join [{:a 1 :c 2}] [{:a 1 :b 2} {:a 1 :d 4}])
08:50sexpbot⟹ #{{:d 4, :a 1, :c 2} {:b 2, :a 1, :c 2}}
08:50chouserclgv: http://en.wikipedia.org/wiki/Relation_(database)
08:51chouserclgv: clojure.set uses a map instead of a tuple, so each item in the set knows the names of its attributes
08:51clgvlol database relations are conceptually mathematical ones ;)
08:53clgvhm ok. I can use that one, since I have a list of deftypes and not sets of maps ;)
08:53clgv*cant
08:53fliebelclgv: records, on the other hand, would implement the right interfaces I think...
08:55clgvfliebel: I would have needed a more general method using predicates ;)
08:56chouserdefrecords should work fine, though you'd still need sets of them, not lists of them
08:58clgvbut I have a more elaborate check to do that determines if two objects belong together. it cant be done with simple value matching.
08:59chouserah. well, if you look at the implementations of the clojure.set functions, I think you'll find most of them to be pretty simple
09:01clgvI guess I'll break it down to a some or first-filter expression
09:39arkhis there a convention for magic numbers? ALLCAPS? I understand earmuffs are only for dynamic vars and things I def are 'constants' buf is there another naming convention for things like (def utc-offset 6) ?
09:39arkh.s/buf/but
09:40stuartsierraThere is no fixed convention.
09:40arkhthere should be ; )
09:40arkhbut thank you
09:40puredangerGiven (defprotocol P (foo [_])) (defrecord R [] P (foo [_] "foo")) is it a bug that (isa? R P) returns false but (isa? R user.P) returns true ? R does implement P as expected if you check with reflection.
09:40chouserI sometimes use allcaps because Java static final fields often do
09:41arkhI like having them stand out
09:42stuartsierraThere was an old Common Lisp convention, used inconsistently, to have constants in + signs like +my-constant+
09:42puredangerah, I see that (class P) returns PersistentArrayMap as that's the protocol mapping but user.P is the actual Java class
09:47arkhis the official clojure FAQ at http://en.wikibooks.org/wiki/Clojure_Programming/FAQ ? I'd like to contribute.
09:48stuartsierraIt's probably moved to Confluence
09:52arkhone can get to the above link from clojure.org:Wiki -> en.wikibooks.org/wiki/Clojure_Programming:FAQ . Does clojure.org need to be updated?
09:54arkh... and the first question wasn't meant to be a trap. I found the path from clojure.org after asking it :/
09:59LauJensenFinally! Something that worked on MySQL, Postgres AND sqlite3 without any tweaks! https://gist.github.com/789530
10:01stuartsierraarkh: I'll point it out to Core
10:02arkhstuartsierra: it's something I'd like to contribute to - thanks
10:03stuartsierraarkh: More recent FAQ is at http://dev.clojure.org/display/doc/FAQ
10:08stuartsierraContrib parent POM 0.0.20 released!
10:09stuartsierrahttp://build.clojure.org/job/build.poms/74/
10:09clgvwhat is a POM?
10:09stuartsierra"Project Object Model" - the Maven build configuration file.
10:10clgvso what is the essential message?
10:10stuartsierraFor authors with contrib libraries on build.clojure.org, time to update.
10:11clgvok :)
10:14chouserstuartsierra: that's just cemerick and fogus`, right?
10:14stuartsierrachouser: want in?
10:14stuartsierrafinger-tree is yours, right?
10:14fogus`will do
10:15chouserstuartsierra: yep
10:15stuartsierrachouser: OK, that's next up then.
10:17chouseryay!
10:21edoloughlinAnyone know in clojureQl, if the PK is an auto-incremented int how do I get the value created after a (conj!)
10:21LauJensenedoloughlin: You're looking to execute the statement "SELECT LAST_INSERT_INDEX()" right?
10:22fogus`stuartsierra: Do you mean 0.0.21?
10:22stuartsierraNo, 0.0.20 release
10:22fogus`Hmmm. I was already using that then
10:22edoloughlinDid not know about that fn. How does it behave if there are multiple threads doing inserts?
10:23stuartsierrafogus: no, I think you had 0.0.20-SNAPSHOT
10:23edoloughlinHaven't seen how to do transactions in clojureQl... (just started using it)
10:24edoloughlinCan clojureQl be wrapped in contrib.sql transactions?
10:24fogus`stuartsierra: Yep. That's right
10:25stuartsierraSo I want you to drop the "-SNAPSHOT"
10:25LauJensenedoloughlin: I havent built in transaction support yet - I want something similar to dosync, however you should be able to wrap your calls in clojure.contrib.sql/with-transaction for now. And no LAST_INSERTED_INDEX() is not usable in a multithreaded environment. I'll see if I can let the actual IDX be returned as metadata
10:25stuartsierraAs soon as it hits Maven Central, that is.
10:26fogus`stuartsierra: I like how you dropped that last line in there so casually. :p
10:26edoloughlinOk. Pretty new to Clojure, must find out about metadata now. Thanks.
10:26stuartsierrafogus: I keep forgetting about it, sorry.
10:26fogus`stuartsierra: Just playing. :-)
10:26LauJensenedoloughlin: Feel free to join us in #clojureql if you want more frequent updates
10:26chouserI'm ready when Maven Central is.
10:26edoloughlinWill do. See you there.
10:54abedrawould anyone be interested in having a "pair with a core member" session on Fridays?
10:55abedrathe idea being you are working on something in core or contrib that you would like some help on
10:55pjstadigdo we get to choose what we work on? :)
10:55abedrapjstadig, yes as long as it is in contrib or core
10:55pilot1123hello
10:55pjstadigsounds like fun
10:55abedrapjstadig, which also means that you would have to have a signed CA
10:55pjstadigsure
10:55abedrathe intent being that the work then gets pushed into the project
10:56chouserabedra: I think it sounds like a great idea, though I don't think I'd be likely to take advantage of it myself very often.
10:56abedrachouser, true, but you are already rocking
10:57pjstadigi hear grumblings about pet issues once in a while, perhaps pairing fridays would help people feel like their issues are being worked
10:57abedrachouser, the real intent is to help people get ramped up on the projects and the workflow and get settled into the patch routine
10:57abedrapjstadig, yes and fridays is when Clojure/core is the most accessible
10:57abedrapjstadig, this is certainly not something we are looking to make wildly public right now
10:58pjstadigunderstood
10:58abedrapjstadig, but it would be nice to give it a try a couple of times just to see how it works
10:58pjstadiglike you said, you'd have to be a CA signer
10:58stuartsierrachouser: http://build.clojure.org/job/data.finger-tree/
10:59abedrapjstadig, and if the result is that a patch gets created, the issues is much more likely to get screened since there is a patch available
11:00pilot1123I'm using frm-save and frm-load from http://groups.google.com/group/clojure/browse_thread/thread/cb5246d07142a3dc?pli=1 . When I try load saved hashmap with structures I got error: No matching method found: create. In the saved file before every struct there is: #=(clojure.lang.PersistentStructMap/create {...})
11:00chouserstuartsierra: excellent! thanks!
11:00pilot1123What should I do to load this structurs?
11:00abedrastuartsierra, sweeeeeet
11:04fbru02abedra: I would love to help
11:08stuartsierrachosuer: finger-tree tests fail because of an `import` that uses hyphens in the package name.
11:10fogus`Yay. I'm all POM'd up
11:10jsnhey guys, total noob question
11:10jsni'm trying to use gen-class
11:10jsnwith lein swank
11:11jsnand just can't find the class anywhere
11:11jsnis there a for-dummies guide somewhere?
11:11jsngoogle has been failing me so far
11:11bsteuber1jsn: you need to tell leiningen to aot-compile that namespace
11:11jsnok thanks
11:13bsteuber1jsn: so add sth. like :aot [my.ns another.ns] to your project.clj
11:14fogus`abedra: Late to the discussion, but yes, I would be interested one day
11:15meliponewhat's a predicate to test if something is a list or not?
11:16tonyllist?
11:17Raynes&(list? '(1 2 3))
11:17sexpbot⟹ true
11:17Raynes&(list? [1 2 3])
11:17sexpbot⟹ false
11:17meliponewhat's this ampersand for?
11:18tonylfor sexpbot
11:18Raynessexpbot's evaluation prefix. It just tells sexpbot to evaluate the code.
11:18meliponecool, I didn't know about sexpbot here
11:20tonylalso there is ##() to evaluate
11:20sexpbot⟹ ()
11:20tonyllike this ##(list? #{4 5 3})
11:20sexpbot⟹ false
11:21meliponecool, how can I find a list of all predicates in clojure? I tried (find-doc "?") but that doesn't work
11:22qbg(apropos "?")
11:22meliponethere's apropos in clojure too? (dance of joy)
11:23qbgapropos is from clojure.repl, but it is in user by default in 1.3
11:23meliponeah, that's why it didn't work for me
11:24abedrafogus`, awesone
11:25qbgSome CLers are hating on Clojure on reddit
11:26qbgSo sad...
11:26stuartsierraSo what else is new?
11:26qbgThey made me install SBCL again to defeat their argument
11:27qbgI haven't needed to optimize CL code in some time
11:27fogus`http://knowyourmeme.com/i/000/062/355/original/Pigboots-Haters-gonna-hate.jpg?1280364642
11:27qbgIn other news, enhanced primitive support FTW
11:28puredangermelipone: find-doc takes a regex so I think you'd want (find-doc "\\?")
11:28qbgpuredanger: find-doc also searches docstrings
11:28qbgProbably not that useful here then
11:28puredangermelipone: or (find-doc #"\?")
11:29puredangerqbg: true, it's a sledgehammer
11:29qbgYou might get too many results
11:29puredangerqbg: I tried it and get you a bunch but they are almost all the actual predicates
11:29qbgThough I don't think ? appears much in a typical docstring...
11:29puredangerqbg: of which there happen to be a lot
11:31fogus`,(for [[k v] (ns-map 'clojure.core) :when (re-find #"\?" (name k))] k)
11:31clojurebot(keyword? chunked-seq? is-annotation? instance? sequential? fn? nil? string? sorted? false? ...)
11:42meliponepuredanger: thanks
11:42meliponehow do I find the size of a list?
11:42stuartsierra`count`
11:43meliponestuartsierra: thanks
11:43meliponeI didn't like clojure at first too
12:11LauJensenclojureql.core> (meta (conj! (table db :users) {:name "Frank" :title "Dev"}))
12:11LauJensen{:last-index 25}
12:11LauJensen
12:31KruppeIs there a situation to use StructMaps over records? I'm having trouble thinking of one.
12:32chouserKruppe: I don't think so.
12:32Kruppechouser: so StructMaps are basically obsolete?
12:32chouserKruppe: I think that's right.
12:32RaynesPretty much.
12:32Kruppechouser: alright, thanks. That's sort of what I was thinking.
12:48timvisherhi all
12:50tonylhello
12:50timvisheranyone have any opinions about whether or not it's a good idea to use a clojure data structure for maintaining a 'database' of a couple of thousand items rather than going with something like H2?
12:53chouser,(time (let [db (into {} (for [i (range 5000)] [i (Math/sqrt i)]))] (db 3601)))
12:53clojurebot"Elapsed time: 36.778 msecs"
12:53clojurebot60.00833275470999
12:54timvisherperhaps some context is waranted. :)
12:55chousertimvisher: could be. :-)
12:56timvisherI've got a large collection of wallpaper. I read them in as structs/maps/records/?. Their attributes are {:file , :resolution , :tags}. Essentially I'm interested in being able to filter the collection based on :resolution and :tags.
12:56timvisherThis seems like something Clojure would be very efficient at
12:56timvisherAt the same time a DB would almost certainly be more efficient
12:57timvisherbut rather than test I was wondering if others thought this was a bad thing to even bother trying to do
13:00timvisherI could always try both and profile
13:00timvisherhas anyone else tried this?
13:02dakronetimvisher: could check out datalog also for storing it if you want a db-ish thing
13:02timvisherpartly I was thinking there'd be an ease of implementation. At the close of system I could write the contents of the seq out to a flat file and then read it in at start up.
13:02dnolentimvisher: DB has to deal with disk, I'd be very surprised if a DB was faster then doing thing in memory with Clojure. And I'd expect for in memory operations for Clojure to be as fast if not faster than in-memory DBs. Throw in a lot of concurrency and I think Clojure will blow those in-memory dbs away.
13:03qbgIf there aren't that many, a seq of the maps would likely be good enough
13:04timvisherThat was my thought. I don't think this would ever grow to more than a couple thousand
13:04dnolentimvisher: I would use clojure.set, you might still want to create indexes.
13:05timvisherMy only concern would be the (File. ...) reference. I could always switch that to a path string and then coerce it into a File. whenever I needed a full-blooded reference
13:05timvisherdnolen: could you explain that a bit further?
13:06dnolentimvisher: you might want faster queries on a particular property, you'll need an index in order to not have to search through everything.
13:07timvisherdnolen: I understand that. I was particularly interested in how clojure.set would help me with that. Reading the docs, though, I get where you're coming from. That's a good point.
13:08replacatimvisher: I've been building an in-memory structure to represent a 23000 bug bugzilla database with ~90000 discrete events (comments, reassignments, etc.). It does slow down a little when I do things the "dumb" way but mostly it works great. I just spit the datastructure out to a file periodically so I can reload and then I have a func that monitors bugzilla itself for new activity. Overall it works pretty well, and it's very simple
13:08chouserI really doubt a few thousand maps with 3 items each is going to stress anything, even with File objects in there
13:08dnolentimvisher: you can store the records and the indexed records in refs. Then when you add a record, you can update all the records and the indexes in a transaction.
13:08timvisherchouser: I don't mean for performance, I mean for the 'serialization'.
13:08chouserI'd be curious if even reading the directory entries was slow enough to bother you -- might might not need to maintain a separate copy of the items on disk at all
13:08dnolentimvisher: clojure.set has an index fn
13:09timvisherchouser: object references don't write out to disk in a reader friendly form right.
13:09timvisher?
13:09chousertimvisher: oh, probably not.
13:09qbgIf you wanted to get nasty, you could serialize it
13:09timvisherqbg: no nastiness, please. ;)
13:10chouseroh, the tags aren't stored in the wallpaper files at all?
13:10replacatimvisher: one of the great thhings about working this way (in my app) is it's easy to write functions that think about actions in sequence (i.e., find the point in the history where the state of the bug changed so that y is true) which is hard when you're looking at individual changes
13:10timvisherreplaca: that's an interesting report
13:10timvisherreplaca: that makes it sound like I should have no trouble whatsoever with this little endeavor
13:11qbghttp://clojuredocs.org/clojure_core/clojure.set/index
13:11timvisherchouser: nope. The files are just dumb references
13:11qbgThat is more helpful than the docstring
13:11chousertimvisher: I would be tempted, if I were you, to store the tags in the image files themselves.
13:12chousereven if they were also stored in an external db or file.
13:12timvisherchouser: reasoning?
13:12timvisherguard against corruption or something?
13:13chouserright, less fragile. files can be renamed, moved, etc without losing their tags
13:13timvishermmm
13:13chouserI'm not saying I recommended it necessarily, just that I'd be tempted.
13:14chouserI have these thoughts when dealing with photos as well, and am vaguely unhappy with all solutions.
13:14timvisherultimately the goal is to have an 'iWallpaper' (*cringe*) app that maintains an app organized library of wallpaper
13:14qbgI wonder how much faster clojure.set/intersection would be if you did awesome tricks with the tree structure of hash sets
13:14timvisherso users shoudln't be down in the library messing with files.
13:15timvisherhowever at some point I had the idea of also allowing user managed libraries and in that case I think you're probably right
13:16qbgSHA1 -> tags would be another (slower, more robust?) option
13:16timvisherI guess the biggest problem I'd see initially with that is that I'd be forced to read the whole file at start up somehow, rather than just loading the raw datastructure back into memory
13:16timvisherqbg: nice idea
13:16timvisherthat could be a nice way to guard against corruption in the future
13:17timvisherWell that gives me plenty to chew on. You guys rock. :)
13:17timvisherIf you're interested I'm mostly playing with this over [here](https://github.com/timvisher/wallpapers)
13:18timvisherIt's my first 'real' clojure project so we'll see where it goes.
13:18chouserqbg: that's really interesting, actually. hm...
13:18chouserwhat the world needs now is for me of all people to write a photo management app
13:19KirinDavechouser: The linux world, perhaps.
13:19qbgIt would be simple in the sense that users can organize the files using anything they wish
13:19KirinDaveHave you TRIED processing & managing RAW files on linux? It's about as simple as training a dog to scratch your back *gently*.
13:20qbgApps like that in theory already exist
13:20qbgWe had to write an app like that for kids for our software development class at my university
13:20qbgIt was not good at all
13:21timvisherlol
13:22qbgIt was also our second project using Swing
13:22timvisheri had played with the idea of munging this concept with something like Aperture/iPhoto but I somewhat like the idea of a library devoted just to wallpaper.
13:22timvisherthe other reason I'm doing it is because I'm attempting to have fine grained control over how and what is currently rotating on my desktop
13:22timvisherso the library mangagement part of it is 1/2 of what I'm doing
13:22timvisherThe other goal is te be crossplatform, hense the JVM
13:39ZabaQno describe, no apropos..I'm lost
13:41dnolen,(doc doc)
13:41clojurebot"([name]); Prints documentation for a var or special form given its name"
13:41dnolen,(doc find-doc)
13:41clojurebot"([re-string-or-pattern]); Prints documentation for any var whose documentation or name contains a match for re-string-or-pattern"
13:42dnolenZabaQ: ^
13:42ZabaQah
13:48ZabaQthx
13:58mefestoHey everyone. I'm trying to externalize the configuration for various parts an app im working on and would like to know if I'm heading in the wrong direction. This is the approach I'm using: https://gist.github.com/9fc92555710ac4d2b330
13:58mefestois that totally incorrect usage of defonce?
14:24chousermefesto: you might consider making the config just an sexpr
14:25chouserlike: {:home-dir "/home/myapp" ...}
14:25chouserthat way you could read it without eval'ing it. Faster, less chance for abuse, though of course less flexible
14:26mefestochouser: interesting. one thing that im doing, which might be totally wrong, is that i use the config namespace elsewhere so that it's the central place to look.
14:27mefestoso in that case would i read in that expr and re-def some var in the config ns?
14:28mefesto(def config {:home-dir "/home/myapp" ...})
14:29mefestofor some reason i feel like im abusing namespaces :)
14:29chousermefesto: yeah, you might consider that. treating the configuration as a value (a map) that can be passed around, stored, saved, recalled, etc. rather than a live, mutable, one-off namespace
14:30chouserbut it also means you can't have code in your config, like that doto stuff you've got would have to be factored out somehow. Not sure if it's worth it in the end or not.
14:30mefestodo you know how people manage different configurations for, say, a ring/moustache app?
14:31mefestoi'd imagine they'd have a similar setup to ruby on rails where there is a test, devel and prod configuration
14:31technomancymefesto: read your config from the classpath
14:31ohpauleezmefesto: People use pallet or Chef
14:31chousergood libs don't depend on file layouts. :-)
14:32chouseryou pass configuration details/functions to ring for it to use
14:32technomancytest config goes in dev-resources/config/whatever, default config goes in resources/config/whatever, then you can override it at deploy time with additional classpath entries
14:32ohpauleezthat's the best answer
14:33ohpauleez(chouser 's), but I like the classpath solution too
14:36mefestowhat i'd like is to be able to distribute the jar to different servers here and run it with different configurations that could be very different from each other. Like on server1 we might want it to use a different database so at the command line something like this would be great: java -jar myapp.jar <config-file>
14:37ohpauleezmefesto: If you're doing different deployments, and they are true deployments, I would use Pallet or Chef
14:37mefestoi think for that case chouser's suggestion is the way to go.
14:37mefestoohpauleez: ok i'll look into those. thanks.
14:37ohpauleezthe other option is yes, you make more functional, and take conf settings are params
14:37ohpauleezmefesto: cool
14:38raekwhat is the easiest way of loading a file on the class path (e.g. using c.j.io)?
14:38mefestoraek: yeah i think there is a resource function in there
14:39raekis a "named resource" the same as a file on the classpath?
14:40mefestoraek: yeah something like (io/resource "com/example/app/blah.txt")
14:41mefestoand for loading clojure code from the classpath there 'load
14:41raekok, that's really simple. I wonder why I thought it was more complicated than that.
14:44mefestois the ring-jetty-adapter just meant for rapid testing or is it appropriate for use in a production environment?
14:48ohpauleezmefesto: More for rapid development, but I've deployed it as a pool behind nginx before
14:48ohpauleezfor a low traffic service
14:49ohpauleezdepends on the demand of the production environment, and what kind of service you're putting up
14:50mefestoohpauleez: i want put up a http/json service run internally for use by some of our web apps
14:51ohpauleezI'd either cut it over to use aleph, or if the load was low, I'd just leave it running on jetty like it is.
14:53ohpauleezI personally like Jetty more than tomcat, but you see more tomcat deployments in prod
14:54mefestoyeah i was wanting to move to jetty but the ajp stuff seems to only work with tomcat
14:54mefestoi did try to use mod_proxy to talk to jetty but ran into problems.
14:55mefestoour setup is https -> apache -> mod_jk -> jboss/tomcat
14:55mefestotrying to do: https -> apache -> mod_proxy -> jetty (http:8080) didn't workout for me :(
15:07mefestough i still can't seem to get my head around these configuration options :-\ here is a really lame example of some ring-ish code: https://gist.github.com/ca2c6bb1480411531a13
15:08mefestousing some of the other techniques previously mentioned, how can i abstract out the config/dbspec stuff? or am i going about connection management in the wrong way with ring?
15:20mefestochouser: is this closer to what you were saying? https://gist.github.com/6b981042c27cacfd975a
15:21chousermefesto: yeah. what do you think?
15:22mefestoyeah that works for me. still trying to figure out how to handle the file locations tho
15:23mefestochouser: thanks for the help :)
15:24chousernp. hope it works out well.
15:32meliponeI'm having some problems with simple IO. here's my function: (defn printList [coll filename]
15:32melipone ;; scrape a url and save its content to filename
15:32melipone (let [out (java.io.FileWriter. filename)]
15:32melipone (doseq [reports coll]
15:32melipone (.write out report)
15:32melipone (.newline out))
15:32melipone (.close out)))
15:33melipone
15:33meliponeI get java.lang.IllegalArgumentException: No matching method found: write for class java.io.FileWriter (NO_SOURCE_FILE:0)
15:34meliponesorry, it should be: (defn printList [coll filename]
15:34melipone ;; scrape a url and save its content to filename
15:34melipone (let [out (java.io.FileWriter. filename)]
15:34melipone (doseq [report coll]
15:34melipone (.write out report)
15:34melipone (.newline out))
15:34melipone (.close out)))
15:34melipone
15:34bobo_melipone: gist.github.com
15:34qbguse a gist please
15:34meliponewhat's a gist?
15:35bobo_melipone: its on http://gist.github.com
15:35qbgYou should take a look at with-open
15:35qbg,(doc with-open)
15:36qbg&(doc with-open)
15:36sexpbot⟹ "Macro ([bindings & body]); bindings => [name init ...] Evaluates body in a try expression with names bound to the values of the inits, and a finally clause that calls (.close name) on each name in reverse order."
15:36qbgNo clojurebot it seems
15:37qbgWhat are you passing to printList (BTW, print-list would be more idiomatic, and print-coll or print-seq might be better yet)
15:37meliponehere's the gist: https://gist.github.com/790371
15:37qbgI suspect you want (str report) instead of report in the write call
15:37meliponeok, I like with-open because it's like Lisp
15:37meliponeqbg: thanks
15:43meliponeI modified my gist to use with-open but I still get the same error
15:44qbgTry my second suggestion
15:44mefestomelipone: and you are passing a string to .write ?
15:46mefestomelipone: https://gist.github.com/f8ccca7765e204ca78f3
15:47meliponeokay, let me try that
15:47meliponeit's true that my doseq is not working as intended
15:48mefestooops i guess there's no println on ... convert to a print writer or change to (.write out (str item))
15:50mefestoupdated:
15:50mefestohttps://gist.github.com/f8ccca7765e204ca78f3
15:53meliponeokay, that's better
15:53meliponewhy isn't .newline working tho?
15:54mefestoare you using PrintWriter?
15:55qbgYou should check out clojure.java.io/writer
15:56meliponeit's working now with PrintWriter
15:56mefestomelipone: PrintWriter doesn't have a newLine method. clojure.java.io/writer returns a BufferedWriter which does have a newLine
16:16mefestochouser: my bases are covered. i feel much better about this setup :) https://gist.github.com/8cea49536a6288ee4d7e
16:19pkinneymore idiomatic, and print-coll or print-seq might be better yet)
16:19pkinney20:37 < melipone> here's the gist: https://gist.github.com/790371
16:20pkinney(sorry, issues trying to copy + paste)
16:28clizzinis there a function that's like conj but guarantees addition of the item to the end of a sequence instead of possibly adding the item at the beginning of the sequence?
16:29__name__how do i make a multimethod that is safe for third party users of my code to add methods to? all tutorials so far suggest using a keyword for determining type, but i can collisions there.
16:29__name__*see possible
16:30qbgclizzin: Why do you need such a thing?
16:30qbgIt would not be efficient in general
16:31kumarshantanuhi, is it possible to make a regular Java object to behave like a map for reading values?
16:31mefestokumarshantanu: (bean obj)
16:32kumarshantanumefesto -- it is not a bean I want to turn into a map
16:32mefestoah
16:32clizzinqbg: eh, basically this is what i have right now: (clojure.string/join "-" (conj (map name fields) v)). but that puts v at the beginning of the resulting string and i want it at the end. the other way is obviously to do (str (clojure.string/join "-" (map name fields)) "-" v), but that seemed kind of unnecessarily cumbersome, plus makes me repeat the delimiter.
16:32mefestokumarshantanu: so other than typical getter methods?
16:33dnolen__name__: namespaced keywords
16:33dnolen,::foo
16:33clojurebot:sandbox/foo
16:33kumarshantanumefesto: i was wondering about extend-protocol etc
16:33__name__dnolen: thank you :)
16:34__name__dnolen: is this the way it's done by real clojurers too or am i just seeking a refugee for my oop thoughts?
16:34qbgclizzin: If you are only going to do it once, you could do (concat <seq> [v])
16:34__name__*refuge
16:34dnolen__name__: depends on whether you really, truly, actually need polymorphism. if you do, then you're on the right track. if you don't just use maps, way simpler.
16:35dnolenmaps and regular functions I mean.
16:35__name__dnolen: yes, i got that.
16:35__name__dnolen: clojure has somehow opened me the eyes that it is probably better to separate data from the way the data is viewed.
16:35clizzinqbg: nah, it's going to happen a bunch of times. i'll just use the latter method i mentioned. thanks for the help!
16:36dnolenclizzin: also concat
16:36dnolen,(concat '(1 2 3) [4])
16:36clojurebot(1 2 3 4)
16:37clizzindnolen, qbg: isn't the concern here that it hurts performance to wrap that single value up in a vector?
16:37qbgIt shouldn't be that expensive
16:37dnolenclizzin: not any more than it does trying to put something at the end of something that can't be put there quickly.
16:38qbgUsing concat in a recursive loop will tend to be bad though because the thunks will pile up
16:39dnolenclizzin: if you're going for perf and you want to put something at the end might be better to replace the map with a custom fn that uses loop/recur + vector transient
16:41clizzindnolen, qbg: i see. good info, thanks for the tips!
16:48xf0what is the best way to install clojure mode into Emacs if I already use slime with common-lisp and prefer not to use emacs starter kit?
16:49qbgClone clojure-mode, put it on the load path, and require it
16:50qbgAlso, use lein swank from leiningen for the server
16:50qbgDon't need to touch the slime configuration at all
16:50mefestois clojure from elpa not recommended?
16:50mefesto*clojure-mode
16:51qbgThat would be another option
16:51jweiss_in terms of build/deployment (via leiningen), would it be proper for me to name a file that's valid clojure but just consists of a single data structure (no namespace) .clj and put in under src?
16:51jweiss_or should i name it .txt and put it in resources or something
16:52jweiss_i use the read function to pull this data into my program
16:52tonyljweiss_: or load-file
16:52tonylI would put it in resources but still with a .clj suffix
16:53qbgAny reason why the file isn't in a namespace with a (def <name> <data-structure>) as being its contents?
16:53qbgThen just require/use the namespace from the places that need it?
16:54jweiss_qbg: the file is produced as output by another program that's not clojure
16:57Raynes$seen cemerick
16:57sexpbotcemerick was last seen quitting 21 hours and 12 minutes ago.
17:03arkhhow do I call a function with items from a collection? e.g. (foo '(:one :two :three))
17:03arkher.. instead of the above, making it (foo :one :two :three)
17:03mefestoarkh: (apply foo coll)
17:04arkhmefesto: thank you
17:08jweiss_anyone know why the resulting file here is empty? -> (pprint [1 2 3] (FileWriter. "/tmp/blah"))
17:09mefestojweiss_: did you flush the writer?
17:09jweiss_mefesto: no, didn't realize i had to do that myself
17:09mefestojweiss_: wrap it in a (with-open ...)
17:09mefestoon close it should flush
17:11jweiss_mefesto: sweet, that did it. thanks
17:11mefestonp
17:18__name__why do the statements that use namespace data from ns not go into its body but rather as a separate expr?
17:20amalloy__name__: you mean, why isn't every clojure file wrapped with (ns blah (defn foo []...)...)
17:21__name__yes
17:21__name__it would allow different namespaces in one file.
17:21amalloy__name__: that wouldn't really be a feature :P
17:21__name__amalloy: i don't know.
17:22__name__amalloy: it's a java unfeature to only allow a class per file :)
17:22amalloywhen you tell clojure to look up foo.bar, it has to either open up ./foo/bar.clj, or search every file in the classpath
17:22__name__does it not do the link upon compilation?
17:22__name__like java does?
17:22amalloyyou don't have to compile clojure code until you want to run it
17:23__name__how does that make a difference?
17:23__name__it is compiled at some time …
17:24amalloybut the whole library isn't necessarily compiled at once
17:24amalloyyou're using foo.bar so you compile that file, and it needs foo.baz, so that gets compiled too. then later you use fdsa.fjei2 and that gets compiled
17:25amalloythere's not any clear win for allowing multiple namespaces in a file; it'd likely be less readable most of the time
17:26amalloyand it would make the (ns) macro way more complicated, and it would mean none of your code ever lives at the top level, which is bizarre
17:26__name__amalloy: thanks
17:27__name__amalloy: it just seemed to make more sense the other way to me
17:33xf0so swank-clojure doesn't contain any emacs functions anymore? you have to start swank manually and do M-x slime-connect?
17:45zanesAre there known issues with swank-clojure installation via ELPA?
17:45zanesI keep getting errors.
17:46xf0zanes: i had them too, that's one of the reasons i'm trying to do manual setup
17:46xf0I just don't understand where should I put swank-clojure files...
17:47dnolenzanes: xfo: use technomancy's version of package.el, don't try to do it manually.
17:47dnolenhttps://github.com/technomancy/package.el
17:49pdkis clojure.contrib.io the preferred idiomatic means of clojure file i/o
17:49amalloypdk: clojure.java.io is more standard if it has the features you need
17:52xf0dnolen: I think I tried package.el but my ~/.emacs.d/ became just too complex and quite a number things of things stopped working :(
17:52xf0dnolen: I prefer to understand what is going on in my .emacs.d
17:53dnolenxf0: well, getting everything setup manually is *very* hard and even harder to maintain :( good luck.
17:53amalloydnolen: really? i think i set mine up manually and had no idea how to use emacs at the time
17:54dnolenamalloy: that's not my experience, I maintained my emacs setup for a year and a half. I also live on the cutting edge of Clojure versions, things were continually breaking. so I gave up.
17:55mattrepltechnomancy: what's the recommended way for adding to the project classpath in lein now that eval-in-project's handler is deprecated?
17:55amalloydnolen: hm, maybe not. i see that there's a ~/.emacs.d/init-clojure.el that i didn't write
17:55dnolenamalloy: perhaps things are better now, but I was burned too many times.
17:56amalloybut i don't know what that stuff is doing, because i downloaded clojure-mode to ~/opt, and added some stuff to .emacs to load clojure-mode from there
17:57dnolenamalloy: that's the other thing, I would continually forget exactly where things were. Exactly what things talked to each other. SLIME would break, swank would break, Clojure would break. etc. package.el all the way for me. reduce the variables and all that.
18:00dnolenat one point I really wanted to run Common Lisp & Clojure too under Emacs, but it was too hard - LispWorks fills that gap now and all the Emacs commands work there just fine when I want to work through PAIP. Geiser/Emacs for Scheme.
18:03zanesdnolen: technomancy's version of package.el saved me a lot of pain. Thank you.
18:04dnolenzanes: np
18:27zanesIf I installed clojure via homebrew how do I make swank-clojure aware of it? When I try to M-x slime I get: "It looks like Clojure is not installed. Install now? "
18:28qbgzanes: Why not use lein swank instead?
18:31zanesqbg: Don't I need a project for that? What if I just want a REPL?
18:34bsteuberzanes: (setq swank-clojure-classpath (list "path/to/clojure.jar" "contrib.jar" "swank-clojure.jar")
18:35qbgzanes: Yes, that is a downside.
18:35qbgAlso, swank-clojure.el is deprecated
18:36bsteuberzanes: add the above to your .emacs, then M-x slime should work
18:36bsteuberat least for me it did
18:37bsteuberhave to get some sleep - bye
18:39amalloyzanes, qbg: cake will launch a swank server from the "global project", and i know lein has a similar feature but i always need to ask technomancy how to make it happen
18:49doubleagentWhat is the preferred way to extend a class eg create a new HttpServlet?
18:49amalloydoubleagent: ##(doc proxy) is easiest, usually
18:49sexpbot⟹ "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/790661
19:26raekdoubleagent: when deploying servlets, gen-class might be useful too. ring has a useful macro: http://clojuredocs.org/ring/ring.util.servlet/defservice
19:51zakwilsonI'm having a problem wherin clojure.contrib.java-utils doesn't have as-str and hiccup needs as-str. This is with [org.clojure/clojure-contrib "1.2.0"] in leiningen and no other versions of contrib showing up in the classpath. Where should I start looking to track this down?
19:54dnolenzakwilson: did you try contrib 1.1.0 ?
19:55zakwilsondnolen: I did not. The function appears to exist in the source on github, but not in the jar: https://github.com/clojure/clojure-contrib/blob/1.2.x/src/main/clojure/clojure/contrib/java_utils.clj
19:58dnolenzakwilson: huh seems like it should work, isn't there a hiccup ML ?
20:00zakwilsonIf by ML you mean mailing list, I'm pretty sure there is, or a google group or some such.
20:14dnolenhmm, so is ISeq the most important indicator of a sequential interface for anything that is not a PersistentVector/Set/Map ?
20:14dnolenI thought it was Sequential, but it seems to me it's really ISeq
20:16hiredmanvectors implement Sequential, it really has nothing to do with seqs
20:16amalloydnolen: (coll? x) might be what you want?
20:16dnolenhiredman: I know they do
20:16dnolenbut lazy seq don't
20:17dnolenamalloy: I'm working with protocols and types.
20:18dnolenI need to know what interface to use for sequential things that are not map/set/vector
20:18amalloydnolen: and you're looking for one type that includes X, but not Y
20:18dnolenamalloy: exactly non-overlapping
20:18dnolenotherwise you encounter the issue where you don't know what implementation you're gonna get with extend-type extend-protocol
20:18hiredmandnolen: sounds like sequential is exactly what you want
20:19dnolenhiredman: I have different algorithms for map/set/vector
20:19dnoleni need map/set/vector/everything-else
20:19amalloy&(remove (set (mapcat (comp supers class) [#{} [] {}])) (set (mapcat (comp supers class) [() (list 1) (range)])))
20:19sexpbot⟹ (clojure.lang.IReduce clojure.lang.Obj clojure.lang.ASeq clojure.lang.IPersistentList clojure.lang.ISeq)
20:20amalloydnolen: not a 100% great algorithm but it looks like ISeq is your best bet?
20:20hiredmandnolen: do map/set/vector/sequential/seq
20:20hiredmanvectors are not ISeqs
20:21dnolenhiredman: but vectors are sequential, if I extend to vector and sequential one of those implementation might override the other right?
20:21hiredmanare
20:21hiredmanoh
20:21hiredmanI didn't actually read the list and see vector there
20:22hiredman,(seq? '(1 2))
20:22clojurebottrue
20:22dnolenamalloy: nice, I was guessing ISeq but I just wanted to hear from other folks.
20:23amalloydnolen: note that my lame expr there found things "not implemented by any of set/map/vector, but implemented by *any* of list/seq" rather than *every* of list/seq
20:23amalloyso use caution, but it's a good starting point
21:08zanestechnomancy: Do you want bugs filed for v2 of the ESK?
22:00ossarehembedding a repl server into my app - should I be using nrepl or swank?
22:06amalloyossareh: nrepl sounds right to me but i don't know how finished it is
22:07tomojno swank support, right
22:10tomojany IDE support?
22:16ossarehamalloy: I'm going stick with swank
22:17ossarehworked well last time I had to do this.
23:48Eugene_guys i am currently a CS student stuck between choose c# and java. Ultimately I want to end up coding in one of the lisps or at least scala c#
23:49Eugene_is it possible to get a job using functional languages?
23:49Eugene_and where can one get such a job
23:49danlarkinno
23:49danlarkinit is literally impossible
23:49Eugene_so what about c# vs java then
23:49danlarkinthere is a worldwide ban on programming professionally using a functional language
23:49Eugene_come on im serrious : (
23:49danlarkinso am I
23:49Eugene_its so tough to figure it out not being in the industry
23:50Eugene_if that is true then the only real choices are c# and java
23:50Eugene_but that is hard to decide too
23:54hiredmanI must confess to creating higher order functions to get code to format more prettily in emacs