#clojure logs

2009-12-29

01:34unfo-if I have (defn myfun [single-arg] (....)) and then call (map myfun a-seq) does that get interpreted as for each element in a-seq apply the fn "myfun" OR for each element in the collection nil apply fn "myfun a-seq" ?
01:35woobyunfo-: each element
01:36unfo-ok, ty
01:36woobynp
01:36wooby,(map (fn [x] (+ x 1) [1 2 3])
01:36woobyoh, no clojurebot anymore
01:37woobygood thing, that's missing a paren anyways
01:37unfo-:)
01:37woobyi'm out, see ya
01:37unfo-i just got in @office :) see ya
01:55defni have some code: (file-seq *my-dir*), where *my-dir* is (def *my-dir* (java.io.File. "/home/etc/etc/etc"))
01:56defnhow do i get just the filename of each file in that file-seq?
01:56defnright now it looks like #<File /Users/defn/git/cljex/src/docs/core-docs/_with-in-str> #<File /Users/defn/git/cljex/src/docs/core-docs/_with-loading-context>
01:56defnetc.
01:56defni want to just get the str _with_in_str
01:57unfo-(reduce #(.getFilename %) (file-seq *my-dir*)) or something similar?
01:57unfo-dunno if file.getFilename() is the proper java function to call
02:00defnunfo-: http://java.sun.com/javase/6/docs/api/java/io/File.html
02:00defnunfo-: im new to the java docs -- could you point me in the right direction?
02:03vydefn: (map #(.getName %) (file-seq (java.io.File. "/etc/modprobe.d")))
02:03defnvy: i figured it out at the exact moment you posted that
02:03defnthanks :)
02:04defnhow do you do the intersection of two sets?
02:07mitchellhdefn: http://richhickey.github.com/clojure/clojure.set-api.html#clojure.set/intersection
02:13unfo-defn, oh sorry. was debugging a work problem, but glad you got it working :)
02:13defnhehe thanks
02:13defnmitchellh: thanks for that. works like a charm
02:14defnif im making a (defn xyz [] (comment "do something here"))
02:14defnshould i be a def?
02:14defnit*
02:14unfo-i use defn for functions and def for vars
02:15defnfor instance (defn compose-examples [] (let [examples (get-file-names-to-set *examples*) core-docs (get-file-names-to-set *core-docs)] (intersection examples core-docs))
02:15defnin a way that seems like a fn
02:15defnbut in another sense it's really only a var
02:16defni suppose whenever you dont need an input, it's a def
02:17unfo-from the Programming Clojure book: (defn whole-numbers [] (iterate inc 1))
02:17unfo-that's an infinite list, so it is not the same as your constant sequence of file names
02:18unfo-defn, that's a pretty good description but what about: whenever you do computation it is a function :-)
02:19unfo-defn, you are calling 3 functions in that def :-)
02:19unfo-whereas if you would say (def my-name "John Doe")
02:20unfo-defn, but this is totally based on my gut feeling, not in actual knowledge of clojure idioms :-)
02:20defnunfo-: sure, i understand that i will have functions there no matter what
02:20defnbut i just struggle to draw the line between function with no inputs
02:21defnversus var with functions inside of it
02:21unfo-defn, check out clojure-contrib @ github for examples?-)
02:21unfo-i'm sure there are plenty of def's there :)
02:35tomojhmm, how do I depend on a jar that isn't a clojure project for which I can write a project.clj?
03:13sparievhello, I have questions about clojureql
03:13sparievdoes it support IN predicate, like "id IN (1,2,3)"
03:14tomojis it possible to dynamically take a keyword like :english and get Language/ENGLISH where ENGLISH is a constant in the java class Language?
03:16sparievand is it possible to use some kind of connection pooling (ie c3p0) with clojureql ?
03:38vytomoj: Is there a Java class named Language?
03:40vy,(java.util.Locale. (name :english))
03:41vyclojurebot: help
03:41vyclojurebot: (java.util.Locale. (name :english))
03:42mitchellhvy: It appears clojurebot is MIA
03:42vytomoj: Anyway, see (java.util.Locale. (name :english))
04:49vu3rdd,quit
07:38dabdanyone knows where I can find zip-query.clj? is is referenced in the documentation for xml-> but I can't find it in clojure-contrib
07:40the-kennydabd: I think they refer to "xml.clj": http://github.com/richhickey/clojure-contrib/blob/81b9e71effbaf6aa2945cd684802d87c762cdcdd/src/clojure/contrib/zip_filter/xml.clj#L86
07:43dabdthe-kenny: thx
08:32fliebelGood morning
08:32LauJensenGood morning
08:33fliebelWhat is the normal way to "change" an object's meta? I can do (with-meta a (do-something (meta a))), but that seems strange to do.
08:34fliebelThere are alter-meta! and vary-met, but I'm not sue which to use and how
08:34fliebel+a
08:36chouserfliebel: (vary-meta a do-something)
08:36fliebelchouser: okay, what's the difference with the other one?
08:37chouser,(meta (vary-meta {:a 1} assoc :my :meta))
08:37Chousukeno bot :o
08:37fliebel*runs to repl*
08:38fliebelcool
08:38chouseralter-meta! is for reference types (a.k.a. identities). It changes their metadata in-place.
08:39fliebelyew :S
08:39fliebelthat is not very immutable is it?
08:40chouserwell, they're identities not persistent things. They're mutable by nature.
08:40fliebelso it's ok to use that all over the place?
08:41chouserI don't think there's any object that both alter-meta! and vary-meta both work on
08:41fliebelhuh… ah!
08:42fliebelSomething else: I;m trying to get rid of all the loop…recur structures, but I have some strange ones I'm not sure which function I should use.
08:44chousernot all loop/recurs should be gotten rid of. :-)
08:44fliebelBasically I need to iterate over a sequence, but the first half of it is done one at a time and made into meta the other half is parsed and gets the meta attached to it.
08:47chousermaybe if you can paste that loop?
08:48fliebelwhere is the paste thing?
08:48chouserlisppaste8: url?
08:48chouserlisppaste8: url
08:48chouserhuh. things are broken this morning.
08:48fliebelmeh… http://gist.github.com/265321
08:49fliebelthat is the old one, without metadate
08:50lisppaste8To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.
08:50lisppaste8To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.
08:51chouserthat doesn't work, does it?
08:52fliebelnope, I'm messing around with it
08:52chouserok
08:52fliebelJust to illustrate what I'm doing
08:53fliebelI'm practically parsing metadata form a file and attaching it to the remainder of the file.
08:53chouserwhat indicates the difference?
08:56fliebelthe re
08:56fliebelif there is a line without data the rest is considered content
08:58fliebelI just came to the conclusion that doing anything to your date destroys the meta :(
08:58cemerickchouser: nice title :-)
08:58chouserfliebel: what?
08:58chousercemerick: what?? what title?
08:59fliebel,(meta (rest (with-meta [] {:a "b" :c "d"})))
08:59cemerickchouser: "Joy of Clojure": http://manning.com/catalog/undercontract.html
09:00LauJensencemerick: I wonder why they didn't go with "Joyjure" :)
09:00cemerickLauJensen: "Joy of..." has a long and proud history ;-)
09:00chousercemerick: ooh, there it is. Hadn't seen that. :-)
09:00LauJensenReally
09:00cemerickchouser: I think fogus tweeted it this morning...?
09:01cemerickLauJensen: Sure. Joy of (Sex|Cooking|Vegan Baking), etc.
09:01cemerickNow we can add Clojure to that canon. :-D
09:02LauJensenVegan is a disease is it not ?
09:02chousercemerick: ah, I'm behind on my tweets.
09:02cemerickLauJensen: I think that volume was about baking vegans, not baking *for* vegans.
09:03fliebelchouser: Is there any function that would fit my loop? I keep comming back to reduce, but did not yet figure out how to do so.
09:03LauJensenhehe
09:03chouserfliebel: ah, well, seqs are something else. metadata treats them as cons cells -- each cell gets its own metadata. :-P
09:04fliebelchouser: huh...
09:05chouserbut the metadata should be maintained if you assoc/dissoc/conj/etc...
09:05fliebelchouser: You're saying that if I attach metadata to a seq it gets attached to the first item?
09:06chouserfliebel: the first cell, yes.
09:06fliebelso… (meta (first (with-meta [] {:a "b" :c "d"}))) should work?
09:07fliebelnope… nor does butlast
09:08chouser,(meta (rest (cons 2 (with-meta (seq [3 4 5]) {:my :meta}))))
09:10fliebelhaha, cool, it works… I'm not sure if I understand that....
09:11chouserhuh. but lists act different than seqs in this regard
09:12fliebeluhoh… Can I attach metadata in any possible way to a string?
09:12chouserno
09:13chouserStrings are final Java objects. no place to store metadata
09:13fliebelnooooooooo! I just converted half of my application to use metadata instead of [data meta] only to discover that at the point I arrive at a string it does not work anymore!
09:14chouser(-> '(3 4 5) (with-meta {:my :meta}) (conj 2) meta) ;=> {:my :meta}
09:14chouser(-> (seq [3 4 5]) (with-meta {:my :meta}) (conj 2) meta) ;=> nil
09:14fliebelIs there some other way to store a string that can contain meta?
09:16chouseryou can put the string in a collection that supports metadata :-P
09:16fliebelliek this? (println (apply str (seq "hallo wereld")))
09:17chouserI was thinking (with-meta ["foo"] {:my :meta})
09:17fliebelbut then I need to use (first foo) every time I need it :(
09:18fliebelcan't I write some ns that extends string?
09:18cemerick(with-meta (atom "foo") {:my :meta}) will let you use @foo :-|
09:19cemerickfliebel: String is final -- can't subclass it
09:19chousercemerick: but not vary-meta :-P
09:19cemerickdetails, details :-)
09:19chousereven protocols won't really help since you need a place to store the metadata
09:20cemerickmaybe we can put together a with-meta protocol that uses a global weak map for string metadata...
09:20chouserright. that'd be the only solution, I think.
09:20cemerickmight not even be so bad, outside of interned strings...
09:20chousereven Java 7 pie-in-the-sky interface injection won't help for the same reason.
09:21fliebelHow about… using future… then the template can uuuhm… compile somweher I don't mind :D
09:22cemerickfliebel: you can define a with-meta of your own right now that dispatches to clojure.core/with-meta for IObj things, and store metadata for other types in a global map.
09:23fliebelI think I like the future option… except that metadata is gone as soon as you need it :P
09:23cemerickjust don't intern strings, and you'll be fine.
09:26fliebelintern strings?
09:27chouseroh, because then you can't have different metadata for two strings with the same text.
09:28fliebelhmhm, but what is interning strings?
09:30cemerick,google java string intern
09:30cemerick~google java string intern
09:30cemerickhrmph
09:30cemerick,search java string intern
09:31fliebel,(with-meta (future (println "hi")) {:a "test"}) ;java.lang.ClassCastException
09:32fliebelSo I can't add meta to agents and future call either! :(
09:34fliebelBut.. this works fine! #^String (str "hallo wereld")
09:34fliebelthat is also metadata, right?
09:34cemerickthat's a type hint
09:35cemericktechnically, yes, :tag metadata on the form following the hint
09:35fliebelcemerick: but a type hint is meta data, isn't it?
09:35cemerickit's metadata on the list '(str "hallo wereld") though, not on the string itself.
09:35fliebelhmmm
09:36fliebelstupid java strings....
09:37cemericktheir being final is important for other things. It's the lack of a mixin protocol of some sort in the jvm itself that trips this up.
09:37fliebelso what do I do now? I have some data to put with the string…
09:37chouser(with-meta ["foo"] {:my :meta})
09:38fliebelThe only other option is writing my own with-meta?
09:38chousernot pretty, but any other solution is going to end up doing something essentially like that, I think.
09:39fliebelhow about (with-meta #("foo") {:my :meta})
09:39chouserdid you try it?
09:40fliebelno...
09:40cemerickchouser: mean bastard ;-)
09:40chouserYou can't attach metadata to fns via with-meta either
09:40fliebelso… really only collections? :(
09:40cemerickfliebel: no, anything that implements clojure.lang.IObj
09:40fliebelbeing?
09:41chousercollections and reference types, I guess.
09:41cemerick...or any type you create that implements IObj
09:41rhickeyand symbols
09:41fliebel:D How do i create a type?
09:44fliebelMaybe I'll just add the data to the meta i.e. just use :body data, I'll have to do something ugly anyway :(
09:50rhickeyfliebel: deftype in new branch
09:51chouser(defn metafn [o m] (proxy [clojure.lang.IFn clojure.lang.IMeta] [] (meta [] m) (invoke [] o)))
09:51rhickeyimplements meta support (IObj) automatically
09:51chouser(meta (metafn "hello" {:my :meta})) ;=> {:my :meta}
09:51chouser((metafn "hello" {:my :meta})) ;=> "hello"
09:53rhickeychouser: yikes, I'll move up fn metadata support :)
09:53rhickeywill just be IMeta, not IObj
09:56chouser:-)
09:58fliebelchouser: that looks fun, but hacky :)
09:59fliebelchouser: I don't seem to have an invoke function
10:13piccolinoCan someone help me figure out what is going on in either of the two revisions of this code? https://gist.github.com/264592/
10:15chouserfliebel: invoke is a method of IFn
10:17fliebelchouser: ah… Thanks for your help. I decided to go for one big map with the data included in the meta as it were.
10:17chouserfliebel: sounds less hacky. :-)
10:18fliebelchouser: indeed… now I need to do (:body data) instead of (first data) or (deref data)
10:18fliebeland can just do the same for the meta
10:19fliebelBut it would be great if metadata on values was possible someday.
10:20chouserpiccolino: I think your older version of deftype usage is correct
10:20piccolinoThat's what I would have thought.
10:20piccolinoBut it won't work.
10:20chouserpiccolino: your defprotocol may be the problem
10:20chousertry (position [obj] [obj newpos] "") ?
10:21piccolinoUgh. Thank god this stupidity will be logged for posterity on #clojure log.
10:21piccolinoThanks chouser.
10:21piccolinoThat was driving me nuts.
10:21chouserpiccolino: np
10:22_fogus_,(let [[f & r] [1 2 3]] [f r])
10:22chouserclojurebot's on vacation, apparently.
10:23_fogus_Oh well, my question... is r constructed from (rest) or (next)?
10:24_fogus_Looks like next, but my head swims when I look at the code for destructuring
10:29chouserheh. yeah, 'next'
10:29chouserthere has been some talk of an alternate & for 'rest', but not much demand.
10:31_fogus_I'm on the side of keeping it the way it is, I get confused by the alternative & forms in other languages
10:33chouseryeah, turns out 'rest' is needed pretty rarely -- just carefully constrained lazy-seq-producing code. special syntax there doesn't seem justified.
10:35_fogus_Are there implications of using (fn foo [[f & r]] (lazy-seq ... (foo r))) over (fn foo [s] (lazy-seq ... (rest s))) ?
10:36chouseryes, with 'next' foo will force the incoming seq one step further ahead than it needs to.
10:38_fogus_And by next you mean [[& r]]
10:38chouseryes
10:38chouser(rest s) only forces as much as (first s) already did.
10:39_fogus_I see
10:41_fogus_thanks!
10:41chouser:-) sure!
10:49rhickeyDoes the description here: http://clojure.org/special_forms which mentions that & is destructured via nthnext, need something more?
11:02fliebelI'm having 2 strange problems: I'm getting clojure.lang.MapEntry cannot be cast to clojure.lang.IDeref, but I'm not using deref of @ anywhere that I'm aware of. the other problem is an unmatched delimiter: ), while my editor shows none.
11:07_fogus_rhickey: Is this discussion on nthnext in destructuring new?
11:08rhickey_fogus_: no
11:09rhickeyI recently fixed the URL and changed the word rest to remaining
11:09rhickeybut the reference to nthnext was there
11:10_fogus_rhickey: I suppose I missed that then. It would have eliminated my question above had I originally absorbed it.
11:13_fogus_rhickey: I read it as c is bound to (nthnext coll 2) where coll is destructured as [[a b & c]]
11:15rhickey_fogus_: right. What's missing is some prose distinguishing that from a call to rest, but I don't really want to digress at that point
11:19_fogus_rhickey: Perhaps adding that digression in the section about sequences would be useful instead, with some additional talk about the implications on the lazy sequence recipe
11:39fliebelHow can I find a java.lang.NullPointerException? I encounter tons of them, and it takes me hours to find them. I think exception handling in Clojure is horrid.
11:40chouser:-(
11:40rhickeyrc3 is up: http://code.google.com/p/clojure/downloads/list
11:40chouserusually a full stack trace will point you right at the line that's failing. Are you able to get that far easily?
11:41fliebelchouser: no, it's always pointing to line 0
11:41fliebelException in thread "main" java.lang.NullPointerException (kickstart.clj:0)
11:41chouserfliebel: are you loading the code dynamically somehow, via slime or something? Or from named files on disk?
11:42fliebeljust clj file.clj
11:42chouserfliebel: that's odd. are there any other lines from your own .clj files mentioned elsewhere in the stack trace?
11:43chouserperhaps under a cause printed later in the stacktrace?
11:43fliebelchouser: Yea, everything under 100 is mine I guess :P
11:44fliebelchouser: there are more of them, the 2 I found are just simple function call to the possible error.
11:44chouserI'd recommend looking at the first lines printed under the last cause.
11:45fliebelI'll show you the trace...
11:45fliebelthen you can tell me what to look for
11:45chouserok
11:45fliebelhttp://gist.github.com/265321
11:47chouserok, you can completely ignore the outer cause (printed first) that's all Clojure setup stuff. Skip right down to "Caused by: ...", this is the "root cause"
11:47fliebelah
11:47fliebelso it is either kickstart.clj:5 or generator.clj:20
11:47chouserFile.<init> is the root-most error line. That's the ctor for File, so probably what amounts to a call like (File. null)
11:47chouser(File. nil), sorry
11:48chouserright. so, does generator.clj:20 create a File instance?
11:48fliebelnot directly… It invokes a function that creates some.
11:49chouserwhat does it pass in?
11:49chousera filename string?
11:50fliebelno, a sequence of maps containing a filename somwhere… at least it should
11:50fliebelat least I know now that it's a missing file at utterson.core$writer
11:51chouserso yeah, I'd look at generator.clj:20 and kickstart.clj:5 -- maybe print out some values there to make sure they look like you expect them to.
11:51chouseror put breakpoints there if you're set up for such things.
11:52fliebelbreakpoints?
11:52fliebelI only did that in Javascript :P
11:53chouseryeah, I don't do them much in Clojure. Apparently some of the IDE plugins support them.
11:54fliebelNot macvim I guess...
11:59fliebelWorking! Indeed the destinationg got lost somewhere,
12:07fliebelhuh, i'm overlooking something… A function that should get called for every file is called only once it seems, but all the files are outputted. Just putting a print statement over there prints only once.
12:40jweissi thought def would produce public variables? i keep getting "xyz is not public" when i "use" it in a ns form in another file.
12:41jweissi also tried defvar but i get the same error.
12:42chouserthat's weird
12:42jweissby the way, the doc for ns is woefully insufficient.
12:42tolstoyIt could use a few examples.
12:43jweissthe only example doesn't even use multiple items in any of the refer/require/import etc
12:43technomancyjweiss: this has come up on the mailing list
12:43technomancyjweiss: the consensus was that the proper solution is to make the usage simpler so it will be easier to document. =)
12:44jweisstechnomancy: that'd be better :)
12:44technomancybut it'll have to wait for 1.2
12:44jweissthat's ok
12:44technomancy(which is going to be an awesome release)
12:44jweissanyway, can someone see what's wrong with this:
12:44jweiss(ns vara.api.hooks
12:44jweiss (:use com.ashafa.clutch
12:44jweiss [vara :only (mydb)]))
12:44jweissmydb is not public
12:44jweiss [Thrown class java.lang.IllegalAccessError]
12:45technomancyjweiss: (:use [com.ashafa.clutch.vara :only (mydb)])
12:45jweisstechnomancy: no, my intent was to use only "mydb" from the namespace "vara".
12:46technomancyjweiss: oh, vara is its own top-level ns?
12:46jweisstechnomancy: yeah
12:46technomancyit's not recommended to have namespaces without a dot in them
12:46jweissah
12:46jweissdid not know that
12:46technomancynot sure if that's the problem here, but yeah.
12:47jweissthis could use a little work for 1.2 also - apparently you can't use java classes in the default package either.
12:47jweiss(without a package name)
12:47jweissthese are some very arbitrary limitations that i'm sure were not intentional and probably fixable
12:48chouserdoesn't java also have some trouble supporting classes in the default package? certain things you can't do?
12:48jweisschouser: nothing that i'm aware of
12:48technomancyis there a notion of strong code ownership in contrib? I'm wondering if it would be kosher to apply mattrepl's fix for #44 without waiting for ataggart's go-ahead.
12:49chousertechnomancy: My impression is that that's acceptible, assuming you're confident it's a good fix.
12:50jweissis there any good convention for what to name your "main" or "core" clj file for a project? x.core? x.main? since i have to give it some name in addition to the toplevel ns...
12:50technomancycemerick: what was your objection to just turning off AOT for logging.clj?
12:50technomancythat seems like the simplest fix
12:51technomancyjweiss: core is the most common
12:51jweisstechnomancy: k thx
12:53technomancychouser: yeah, I'm not sure I understand 100% the implications of mattrepl's fix
12:53technomancybut cemerick raised objections I don't understand to the obvious fix
13:07rrc7cz,(use 'clojure.contrib.pprint)
13:07jweisstechnomancy: i'm starting to think this "mydb is not public" error might be a circular dependency problem. my core ns uses one item from my "hooks" ns, and "hooks" uses one item from "core". do ihave to be careful doing mutual :use(s)?
13:07rrc7czhow does the ClojureBot work? I'm trying to confirm that the error I'm getting in my latest pull from master is just my prob
13:10replacarrc7cz: clojurebot doesn't support contrib
13:10rrc7czokay
13:10replacathe source is at http://github.com/hiredman/clojurebot
13:11rrc7czcool, thanks
13:11arohner_I didn't get a response to http://groups.google.com/group/clojure/browse_frm/thread/d4dd1a0a1ffee6c5#
13:12arohner_can anyone comment on whether this is a bug or I'm doing something stupid?
13:16jweissanyone know if it's possible to have 2 ns's have :use clauses that point to each other?
13:16jweissi keep getting "xyz is not public" and i know that it IS public
13:16jweissmaybe it's because the first file loads its deps first, and when the dep points back at the original file, the stuff it needs hasn't been defined yet?
13:17arohner_jweiss: ns declarations can't fix circular loads
13:17arohner_my guess is you have a circular loading problem
13:17jweissarohner_ what's the solution?
13:18jweissi guess i could put the mutally used items in a 3rd namespace...
13:18drewrjweiss: yes, factor out those vars
13:18arohner_jweiss: yeah. The only solution is don't circular load
13:19arohner_rhickey: Is this a bug? http://groups.google.com/group/clojure/browse_frm/thread/d4dd1a0a1ffee6c5#
13:20arohner_or am I doing something wrong?
13:24rrc7czCan anyone confirm (use 'clojure.contrib.pprint) works on clojure + clojure.contrib master HEADs? I'm getting "java.lang.IllegalStateException: Var clojure.core/chunked-seq? is unbound. (dispatch.clj:90)"
13:31arohner_rrc7cz: sorry, I can't help you. I can confirm that the new branch + contrib from about a week ago works. that's what I'm running
13:31rhickeyarohner_: yes, generated conj is not as flexible as e.g. hash-map conj yet
13:31rhickeyrrc7cz: make sure you run 'ant clean' first on any new contrib build
13:32arohner_rhickey: if you give me a hint, I can work on a patch. I got lost on where that call to nth came from on the second line of the stack trace
13:32cemericktechnomancy: where's the ticket regarding logging? I'm not remembering the issue off the top of my head.
13:34rhickeyarohner_: it's from the destructuring here: http://github.com/richhickey/clojure/blob/new/src/clj/clojure/core_deftype.clj#L168
13:34rrc7czrhickey: that did it; I was rebuilding with the -Dclojure.jar set for pprint. It's working now, thanks
13:35rhickeyarohner_: it needs instead to mimic: http://github.com/richhickey/clojure/blob/new/src/jvm/clojure/lang/APersistentMap.java#L31
13:36arohner_rhickey: great! thanks
13:36rhickeyarohner_: best to place that code (which can be implemented in terms of calls to assoc) in a helper fn which is called by .cons
13:36jweissi am sure this must be possible but i'm not finding the answer in the docs- if i want to name my function in my namespace "assert", i get an error "Name conflict, can't def assert because namespace: vara.api.hooks refers to:#'clojure.core/assert
13:36jweiss [Thrown class java.lang.Exception]" - how do i use my own function instead of clojure.core's
13:37jweisssince core is used implicitly...
13:37technomancycemerick: it's http://www.assembla.com/spaces/clojure-contrib/tickets/44
13:38arohner_jweiss: you need a refer clojure.core :except assert
13:38jweissarohner_ ok i'll try that ,thanks
13:38arohner_if you refer clojure.core explicitly in your ns declaration, you can control which vars get imported
13:41arohner_jweiss: sorry, :exclude. (doc ns) has an example of how to do it
13:44cemericktechnomancy: I was just looking out for those environments where AOT is required (either because of security policy or issues with loading runtime-generated classes in various module systems).
13:46defnhmm -- anyone ever read Manning books before>?
13:47drewrdefn: I read the Perl OO book a long time ago
13:47defnAre they good books?
13:47drewrall depends on the author
13:47defnI've never seem them -- kind of surprising really
13:48technomancydefn: the typesetting on their ebooks is sometimes amateurish and the covers are silly. other than that yeah, it's all up to the author.
13:48defndrewr: there's a new clojure book coming out
13:48chousertwo
13:49drewrdefn: I looked through the first chap of rathore's book
13:49defnchouser: i already pre-ordered one
13:49cemerickchouser: do you guys have TOC somewhere?
13:49chouser"Clojure in Action" is partially available as an e-book now. "Joy of Clojure" will hopefully be available soon.
13:49defnahhh, manning has two
13:49defni ordered the apress clojure book from amazon
13:49defnerr pre-ordered
13:50chousercemerick: nothing public yet. and it keeps changing. :-P
13:50drewrI'm looking forward to advanced CS books that speak Clojure
13:50cemerickchouser: when I saw fogus asking about CPS, I got excited :-)
13:50chouser:-) well, hopefully we won't disappoint.
13:51defnim looking forward to getting a job someday programming clojure
13:51defnbut im not holding my breath just yet :)
13:51arohner_defn: you have to make your own luck
13:52arohner_defn: you could say rhickey decided he wanted a job programming clojure
13:52defnarohner_: sure -- i hear you there
13:52defnim not one of the "I learned Java so I should get a job by default" guys
13:53defnim just gonna keep hacking clojure and trying to do interesting stuff -- eventually someone will say "hey, can you do that for me?", and hopefully they say "hey, can you do this for me all the time?"
13:55chouserdefn: maybe there are people who know if a plan like that is good or not. But until they speak up, it sure sounds reasonable. Hope it goes well for you. :-)
13:55_fogus_cemerick: I'm still trying to think of an intuitive way to explain CPS, and then come up with a compelling Clojure case. It's a double whammy at this point.
13:57cemerick_fogus_: yeah, either way, stuff that pushes boundaries is good. I suppose I'm not where the market is, but more "let me tell you what an atom is" isn't going to make my socks roll up and down anymore. :-)
13:58jweissi've heard it said that some people think 'eval' shouldn't be used at all, but what's the alternative? i tried to make a macro to read a string and turn it into the form data to define a fn. but i'm not sure how to go beyond that and have the macro return the actual function, without using eval.
13:59chousercemerick: such information is also rather dull to write. we have every intention of pushing past that level.
13:59cemerickheh
13:59cemerickI'm suddenly reminded of those Java tomes from yesteryear that simply printed the javadoc-of-the-time.
14:00arohner_jweiss: if you're reading a string, you can just read it. There are a few cases where eval is the only option, but they're rare
14:00arohner_jweiss: as in (read) it
14:00drewrI want the clojure PAIP or SICP that then pushes the envelope with concurrent overtones
14:00_fogus_Chouser and I wrote up a whole intro chapter and honestly, I have to say that I admire authors who can sustain that type of work for an entire book.
14:00drewrmore examples like ants.clj
14:00arohner__fogus_: yeah, can you just go ahead and write another SICP?
14:00arohner_:-)
14:00jweissarohner_ but my macro just returns the form (fn [x] (inc x)) - i want it to be a function, not the form
14:01chouserjweiss: sounds like you're close. Can you paste that macro?
14:01jweiss(defmacro eval-hook [fn-str]
14:01jweiss (read-string fn-str))
14:01drewrarohner_: rhickey has set high standards around here ;-)
14:02chouserjweiss: (eval-hook "(prn :hi)") prints :hi for me -- doesn't it work for you?
14:03jweisschouser: hehe would be nice if i actually called the macro instead of macro-expand-1 on it :)
14:03jweissduh
14:03chouser:-)
14:03chouserthough note it'll only work for literal strings.
14:03cemerickI'm not sure SICP needs rewriting. On Lisp though, that's ripe for a refresh.
14:04chouser(let [x "(prn :hi)"] (eval-hook x)) ; failure
14:05_fogus_cemerick: Wouldn't that be ANSI CL?
14:05chousercemerick: I already wrote the chapter on how to do anaphric macros in Clojure.
14:05jweisschouser: hm, i think that'll be ok, these are strings i'm pulling from a couchdb instance. so it should always be literal
14:05chouseranaphoric
14:05chouserjweiss: no, probably not.
14:05rrc7czI'd rather see The Little Schemer series in Clojure.. but the name would be hell to say
14:05arohner_jweiss: you might not even need a macro in that case
14:05cemerick_fogus_: I mean with a clojure bias :-)
14:05chouserjweiss: if you're pulling strings from somewhere at runtime and want to treat them like code, then you really do need eval.
14:05jweisschouser: oh wait you're right
14:06drewrcemerick: rewrite isn't what I had in mind; just that academic caliber
14:06_fogus_Before I started working on the book, I was considering doing a whole series of blog posts along the Little Schemer lines
14:06arohner_jweiss: and that wouldn't be a macro. Just read-string + eval
14:06jweisschouser: ok good to know this is one of the times when eval really is needed.
14:06cemerickI never could get into the Little Schemer series.
14:06jweissthat's the way i wrote it originally
14:07cemerickI get too impatient with the narrative. I want to see the hill I'm climbing.
14:07arohner_cemerick: yeah, I never got into it either. I find I rarely think about the problem the same way the author presents it
14:07arohner_so I always got lost in the transitions from one little problem to the next
14:08jweisschouser: one thing about using eval is it's always evaluated in the clojure.core namespace
14:08jweisswhich i'd rather not do
14:08technomancycemerick: I don't get it. what kind of environments require .class files?
14:08rrc7czfor me it's the opposite: I have to push myself a bit through SICP, but the Schemer series just felt lightweight
14:08rrc7czlightweight and fun. You get immediate feedback because it's like a neverending series of puzzles
14:09chouserjweiss: I don't think that's right. It seems to use the current value of *ns*
14:09rrc7czalthough I still don't get the chapter where they explain Y
14:09chouser,(eval '(prn *ns*))
14:09drewrI think the camel book is what I'm targeting -- an idiomatic book by the language author that goes in depth but also contains plenty of examples
14:09technomancyit seems like if your environment requires .class files then it's up to you to make sure all your stuff is AOT'd
14:09jweisschouser: ok, maybe i'm misreading the symptoms here, i'm calling my own "assert" but it tries to call core's instead, i thought it was because of the reason i stated, but maybe i didn't exclude assert correctly
14:10technomancyit shouldn't be the duty of contrib
14:12_fogus_rrc7cz: No one does.
14:16cemericktechnomancy: I was under the impression that android couldn't cope with loading from .clj files at all. The same was true for the module system in netbeans 6.5 at some point, although that was patched before 6.7 if memory serves.
14:16rrc7czfogus: that's heartening to know. The book looks like it was designed for children. Being crushed by that chapter made me feel even worse when it's covered in elephant cartoons and jokes about ice cream
14:17chouserhehe
14:23technomancycemerick: but the process of preparation for android will need to AOT everything anyway
14:24technomancyso what does it matter if contrib's build does it or not?
14:25cemerickI think it'd be a shame if AOT needed to be performed on every clojure lib one wanted to use. This goes back to lib authors providing slim and AOT artifacts.
14:25technomancyI don't understand why that's a shame
14:26technomancypreparing code for android is already a pretty involved task; adding AOT to it is not a big deal
14:27tolstoyIs there a simple clojure way to get all the text from an InputStream?
14:27devlinsftolstoy: c.c.duck-streams
14:27tolstoydevlinsf: I've been looking at that.
14:27devlinsftolstoy: Does slurp* work?
14:28tolstoyAlas, (duck/slurp* (duck/reader (-> request :body))) gets me nothing. (Compojure.)
14:28devlinsfHmmm
14:28cemericktechnomancy: There are other advantages to AOT'ing code (faster startup, interop with various tools, weak obfuscation) -- totally aside from any particular deployment target's requirements.
14:29devlinsftolstoy: Did you try it w/o the intermediate call to reader?
14:29devlinsftolstoy: slurp* has an implicit one
14:29tolstoydevlinsf: yep.
14:29devlinsftolstoy: Hmmm... You got me
14:29devlinsfStupid question
14:30tolstoyMaybe my "POST" isn't working like I think it does. That might be it.
14:30devlinsftolstoy: what is (class (:body request))?
14:30tolstoyUsing http-agent for that.
14:30tolstoyorg.mortbay.jetty.HttpParser$Input
14:31technomancycemerick: interop is only an advantage for a small set of nses, and obfuscation is a miniscule use case
14:31devlinsftolstoy: and it extends input stream?
14:31tolstoyNo idea. Can't seem to find java-doc for Jetty at the moment.
14:32devlinsfTry isa?
14:33tolstoyOkay.
14:33tolstoyYeah, that class descends from InputStream.
14:33devlinsfHmmm.. totally stumped :(
14:34devlinsfDid anyone on the Compojure list know what to do
14:34chousertolstoy: it gets you nothing? no error?
14:34defnwhatcha tryin to do?
14:34tolstoychouser: right. No error. Just an empty, uh, string, I think.
14:35tolstoyOn one side: (http-agent "http://myapp&quot; :method "POST" :body "<some-stuff/>")
14:35tolstoyOn the compojure side: (println (-> request :body))
14:36cemericktechnomancy: Then I'm out of objections, until I hit a specific problem. It might be worthwhile to dig back into the discussion that occurred when clojure.core began applying AOT regularly. I remember it being a very welcome move.
14:36tolstoy:character-encoding nil, :body #<Input org.mortbay.jetty.HttpParser$Input@4c5e43ee>,
14:36chousertolstoy: are you sure the body is not in fact empty?
14:37tolstoychouser: I'm not sure of that. Which is why I'm trying to print it out. I'll check the sender.
14:38chouseror use an alternate client, just to check it. curl or wget, for example.
14:38rrc7czwhy does clojure.zip/append-child require the node to already have children?
14:38tolstoyHTTP Client (Mac thing) proves that the POST is not arriving. Phew!
14:39tolstoyduck-streams slurp* works like I'd hoped it would, so that'l all cool.
14:39technomancycemerick: yeah, in the case of logging.clj there are already other contrib namespaces that are excluded from AOT
14:39rrc7czand for that matter, why doesn't clojure.zip/children return an empty seq instead of throwing an exception when the node is a leaf?
14:40devlinsftolstoy: Glad it worked out (sorta)
14:40tolstoydevlinsf: Yeah. Now I have to figure out why http-agent isn't posting the body in :body.
14:40devlinsftolstoy: Sounds like fun. Good luck.
14:40tolstoyProbably some inappropriately bound *out*.
14:41devlinsftolstoy: Or laziness
14:41devlinsfThat's bit me before with I/O
14:53tolstoyI wonder if http-agent is broken?
14:54tolstoyIf I post :body "a=1&b=2" I can get them via :params in compojure. Content-length is 7. But no payload. Weird.
14:54tolstoyYet some other http-client works fine.
14:57tolstoyMaybe it's the content-type....
14:59tolstoyYep. That was it. c.c.http.agent assumes if the method is a post, the body is application/x-www-form-urlencoded, which messes things up, I guess, for Jetty.
15:01defnhmmm, i have clojureql via clojars but i cant seem to (use) it
15:02defn[org.clojars.snuxoll/clojureql "1.0.0"]
15:12jweisswould using in-ns be a valid (simple) way to run code in a sandbox (so that code i'm loading from a db and eval'ing only has access to certain stuff, i don't want my users to be able to write and execute stuff in some of my namespaces)
15:13replacajweiss: I don't think that's sufficient
15:13jweissi mean, it doesn't have to be *impossible* - i basically just want to stop accidental screw ups
15:13arohner_jweiss: yes, it will stop accidental screwups, it won't do anything to prevent intentional breaking
15:14replacajweiss: users will still have complete access to your system. If that's ok, then you shhould be good
15:14jweissarohner_ yeah, all they'd have to do is "use" the ns's i want to protect and voila, but better protection will have to wait
15:14replacajweiss: otherwise, I recommend you look at clojurebot. That uses some "standard" java sandboxing
15:15jweissreplaca: ok thx
15:15jweissit's on github right?
15:15jweissnvm got it
15:37LauJensenBlogged about improving Clojure-mode's highlighting using Enlive: http://www.bestinclass.dk/index.php/2009/12/enlive-vs-clojure-mode/
15:39devlinsfLauJensen: This is awesome
15:39LauJensenWow - You read it already? :)
15:39devlinsfRSS
15:39LauJensenAhh, great - glad you liked it
15:43devlinsfLauJensen: Could we get your work merged into swank-clojure?
15:43LauJensenThen it should be cleaned up a little, but I think technomancy can take care of that pretty quickly ?
15:45devlinsftechnomancy: Please? :)
15:46chouserit seems odd for the information to flow from clojure namespaces, through the doc processing to html, to github, through http back to clojure.
15:46LauJensenchouser: But how else would you show off Enlive ?
15:46chouserheh
15:47LauJensenActually I pasted some code in here a few weeks ago which printed all functions in any namespace, didn't save it though
15:48q1Lau use this.
15:48q1(defn print-public-binds "Prints all binds defined in library $sym." [s] (doseq [k (keys (ns-publics s))] (println k)))
15:49q1(doseq [s *supported-libraries*] (print-public-binds s))
15:49LauJensenq1 I'll stick with Enlive, but we need to get technomancy motivated to employ either technique :)
15:49q1:)
15:50q1I'm probably the only one using slickedit for clojure dev heh.
15:52LauJensenq1, whats that?
15:55q1Just a heavy-duty editor written in C/C++: http://www.slickedit.com/ ; it's heavily customizable.
15:56cemerickslickedit has always been appealing, but its lack of a useful OS X version is a problem for me.
15:56technomancyI'll merge a swank-clojure patch that read it directly from the ns for sure
15:56technomancyenlive is great for a tutorial, but not for everyday work. =)
15:57q1i thnik that makes the most sense.
15:58cemerickdoes it make sense to put symbol tables and such right into core?
16:00q1hehe. for DOS? slickedit is still speedy, i like that aspect of it.
16:00rrc7cztechnomancy: "enlive is great for a tutorial, but not for everyday work" why's that? I'm using it in my new project and I'd be interested in any thoughts
16:01devlinsfrrc7cz: It's not good for THIS problem
16:01technomancyrrc7cz: I mean for the purposes of determining what vars are in clojure.core
16:02rrc7czgot it
16:03q1tech: if you need a jump start, i can send you some clojure code.
16:04technomancywell there's two potential packges
16:04technomancy0) update clojure-mode to match the current list from clojure.core
16:04rhickeyq1: yeah, and for OS/2 also
16:04technomancyand 1) add a feature to swank-clojure to add to that list at runtime
21:00chouserhmph. someone stepped on my router power cord -- lost about 5 hours of IRC logging.
21:00chouserI hope nothing momentus was discussed?
21:19polypusbest way of getting last two items in collection?
21:19the-kenny,(doc take-last)
21:19polypusty, looks like clojurebots dead
21:20the-kennyYes :(
21:20polypus~ping
21:20the-kennyMay he rest in peace
21:20polypus:)
21:22polypustoo bad split-at doesn't take negative indices. would be nice if it started from the end backwards in that case
21:23the-kennyhm.. I think it's more intuitive to pass a reversed sequence
21:24polypusright!
21:38_mstchouser: nothing momentous, but I can give you a dump of my erc buffer if you're worried about historical accuracy ;)
21:44polypus is there a function like vector which returns a map: (map* :foo "bar") -> {:foo "bar"}
21:54chouser_mst: eh. Thanks for the offer. If the format doesn't match exactly, it probably isn't worth the effort to convert it.
21:55chouserpolypus: hash-map or array-map
21:55_mstpolypus: it depends a bit on what you're trying to do. If you've just got a key and value, I'd use the literal syntax above. If you've got a collection of keys and another of values, I'd use zipmap to turn it into a map. If you've got a collection like (key1 val1 key2 val2), maybe (apply hash-map that-coll)
21:55_mstchouser: yeah, it's unlikely to match. Plus I seem to be something like 16 hours ahead, so converting the times wouldn't be much fun :)
21:55polypusty, zipmap is what i need
21:55chouserbleh. timezones.
21:57duperis there a way with irb to display the ruby statements that make up a class initialize method?
21:59chouserduper: this is #clojure
22:00duperw00pz wrong window sorry guys
22:00polypusduper: do you mean introspecting to get the actual source? cuz ruby doesn't support that.
22:01duperreflection i guess
22:01duperdoes clojure support that
22:03chouserduper: for any function (var, really) defined in a named .clj file in the classpath, you can print its source code with (source foo)
22:04dupercan you treat that as datat to rewrite it on the fly?
22:04fanaticoduper: yes. http://clojure.org/macros
22:05chouserprobably, though 'source' will still use the contents of the file each time, so what it prints could become out of date.
23:05technomancydevlinsf: looks like that clojure-mode patch doesn't apply cleanly on the latest git master
23:05devlinsftechnomancy: BLARGH!
23:05technomancywere you basing it off a copy from elpa?
23:05devlinsftechnomancy: Hmm... I pulled this afternoon. Did you do anything since then?
23:06devlinsfOoh... maybe
23:06technomancymy last commit was last week
23:07technomancyadding defprotocol and friends
23:08devlinsfurl = git://github.com/jochu/clojure-mode.git
23:08devlinsfI pull from thee
23:08devlinsfthere
23:08devlinsfIs that the wrong one?
23:08wdouglastechnomancy: By the way the slime-fuzzy from your slime repo on get has the same problem =(
23:09technomancydevlinsf: yeah, try s/jochu/technomancy/
23:09devlinsfAh
23:09technomancyI mean to keep the jochu one up to date, but I forget a lot
23:09devlinsfhttp://github.com/technomancy/clojure-mode
23:09devlinsfThat one?
23:09technomancyyup
23:10devlinsfOkay.
23:10devlinsfDid you see the sample png, though?
23:12technomancydevlinsf: yeah, I like the way it looks
23:12technomancyusing the warning face for deprecated stuff is a good idea
23:12devlinsfOkay. And the green for "extended" is good too?
23:13technomancyyeah, I think so
23:13technomancywhat's the name of that face?
23:13devlinsfGImme a sec...
23:14devlinsffont-lock-type-face
23:14technomancythat's fine... those are always used loosely anyway
23:14devlinsfThere's also this cool looking one for single quoted stuff, that's light blue
23:15devlinsfIn el mode, anyway
23:15technomancythat's not in the screenshot though?
23:15devlinsfA long term idea might be using it for quoted data structures
23:15devlinsfNo.
23:15devlinsfIt's in the clojure-mode file
23:16devlinsfI figured I'd try to sell one change at a time.
23:16devlinsfTwo is pushing it :)
23:16devlinsfAnd three... well, I don't even know where to start
23:16technomancyhehe
23:17technomancyif you could get an updated patch from the latest, I will apply it post haste
23:18technomancywdouglas: what was the problem with fuzzy again?
23:19wdouglastechnomancy: synchronous lisp evaluation error
23:19devlinsftechnomancy: just pulled from the proper repo... will get hacking
23:19technomancymuch obliged
23:20wdouglasjava.util.concurrent.RejectedExecutionException
23:20technomancyfeels like these days I don't have time to hack on my own projects, but if I squeeze I can find enough time to apply patches that people send me. =)
23:20wdouglasYou are working through others, technical manager of oss =)
23:21technomancyit's easier than herding cats at least
23:26wdouglashttp://pastebin.com/m262e42f0 is a paste of debugger and backtrace. I really need to work on being able to debug in emacs.
23:30technomancywdouglas: some of that old swank-clojure code is just so crazy
23:31technomancya lot of it was implemented before many features we take for granted today
23:31technomancyand a lot of it is needlessly complicated
23:31technomancy... or at least appears that way, so then when you make changes to simplify it turns out the break important stuff because there's no test coverage. =\
23:31technomancy(swap! timed-out (constantly true)) ; <= someone is unaware of the reset! function? or what...
23:32wdouglasI'm sure that was emacs 18 or something
23:38wdouglasSo when it does the slime-rex call in the slime-eval from the error I'd think there were multiple at once and clojure throws an error from that.
23:39wdouglasNow to try and verify speculation
23:40technomancythat timeout stuff should be replaced with java.util.Timer, I think
23:41technomancyI have no idea why the future would throw a rejected execution exception though =\ no calls to cancel or anything
23:42wdouglasIt doesn't make much sense since this will work if you are running from a regular slime instead of a lein swank
23:42technomancywdouglas: oh! I didn't realize that
23:43technomancydo you know if the versions of swank-clojure.jar are the same?
23:43wdouglasOh.. they might not be. I was just using clojureql lein project
23:43wdouglasI will try that out.
23:44wdouglasI'm using clojure 1.0 on the default slime
23:55technomancythat's probably it