#clojure logs

2008-10-07

03:07cccccan i raise errors/exceptiosn deliberately in clojure?
03:07cccclike if i define factorial and someone passes -1 can i have it raised a "factorial not defined for negative numbers"-error then or i should just return nil?
03:26hoeckcccc: just like in java, only with parens :) : (throw (Exception. "exception message"))
03:55Lau_of_DKGents - Good morning - Can somehere show me how to apply zip/edit ? I'm not getting the [loc f & args] syntax
04:13hoeckLau_of_DK: good morning, maybe: (apply zip/edit loc f arglist)?
04:22Lau_of_DKIts not quite working out for me
04:22Lau_of_DKAltering a single node in an xml tree is proving pretty difficult
04:24hoeckI'm don't like xml, i try to ignore it where i can
04:25hoeckI'm / I
04:25Lau_of_DKoh... I think its quite handy
06:00Lau_of_DKuser=> (apply (fn [x] (str x)) "clj")
06:00Lau_of_DKjava.lang.IllegalArgumentException: Wrong number of args passed to: fn
06:00Lau_of_DKWhat wrong with this ?
06:09Vanessai want to be able to: cons (val, result-of-function) to ((hello 10) transfer 20))
06:09Vanessahow do i cons a list and have it eval a function inside he list?
06:09Vanessalike if i quite it just conses the quoted expression instead of the result of it
06:10Vanessalike hello anywhere there?
06:14Lau_of_DKYou mean something like this:
06:14Lau_of_DK(def fib-seq
06:14Lau_of_DK (concat
06:14Lau_of_DK [0 1]
06:14Lau_of_DK ((fn rfib [a b]
06:14Lau_of_DK (lazy-cons (+ a b) (rfib b (+ a b)))) 0 1)))
06:14Lau_of_DK?
06:14H4nsLau_of_DK: apply expects an argument list to apply to a function, not a single argument
06:14H4nslisppaste8: url
06:14lisppaste8To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.
06:15H4nsplease use that for pasting code that is longer than one line.
06:15Lau_of_DKH4ns, I will submit to your will
06:17Vanessa(cons '(1 (* 2 1)) '((3 4) (5 6))) ->
06:17Vanessa((1 (* 2 1)) (3 4) (5 6))
06:17Vanessabut i want (* 2 1) to be evaluated
06:17Vanessa-> ((1 2) (3 4) (5 6))
06:17H4nsVanessa: you are quoting '(1 (* 2 1)), so nothing in it is evaluated
06:18H4nsVanessa: (cons (list 1 (* 2 3)) ()) => ((1 6))
06:22lisppaste8vanessa pasted "wordcounting" at http://paste.lisp.org/display/68095
06:22Vanessa^^
06:22Lau_of_DKWhats a kiteboard?
06:23Vanessawait i changed
06:23Vanessalau: something you danes are quite good
06:23Vanessai changed a little wait
06:24Vanessa^^
06:25Lau_of_DKYou changed?
06:25lisppaste8vanessa pasted "wordc" at http://paste.lisp.org/display/68096
06:27Vanessa(cons (list 1 2) '()) doesnt work, that seems to be the problem
06:27Vanessawhy not?
06:27Vanessa(cons 1 '()) enither
06:28Vanessaworks in other lisps
06:28Lau_of_DKWould (cons 1 (list nil)) work for you ?
06:28Vanessanil
06:28Vanessayes
06:30Lau_of_DKuser=> (zip/edit (first (xml-> xml-data :l1 :l2)) (fn [x] (parse-str x)) (list "<test>new val</test>"))
06:31Lau_of_DKCan somebody fill me into, as to why this complains of bad number of args for fn
06:40Lau_of_DKrhickey, you wrote this stuff initially, how do I change the content of 1 node in an XML tree, and still keep the rest of the tree?
06:40hoeckLau_of_DK: cause zip/edit expects a function that takes 2 args, but your fn takes only one arg
06:41Lau_of_DKHow would you set it up ?
06:41leafwLau_of_DK: (fn [x y] ( .... ))
06:42hoeckLau_of_DK: mind pasting a small example with xml testdata?
06:42Lau_of_DKsure
06:45lisppaste8Lau_of_DK pasted "XML Edit" at http://paste.lisp.org/display/68097
06:45Lau_of_DKThis hopefully gives you an idea of what Im going for
06:50Vanessahow can i set clojure-mode to just load the file into the interpreter in the other window, not start the interpreter in the currecnt window?
07:00Lau_of_DKhoeck , you got the idea? :)
07:06hoeckyeah, just give me a second
07:10Lau_of_DKsure :)
07:18Vanessaif i ahve a (apply list is-a-hash-map) and want to sort the result(looking like (["hello" 1] ["transfer" 12]) ) on the second key(the ints), how do i do that?
07:25rhickeyVanessa: (sort #(compare (val %1) (val %2)) {"hello" 1 "atransfer" 12})
07:26rhickeyyou don;t need the apply list
07:27Vanessaok but ^^ is not working
07:28rhickeydo you have the latest Clojure?
07:28rhickeysvn 1053
07:28Vanessa: Unable to resolve symbol: compare in this context
07:28Vanessanah from june
07:28rhickeyah
07:29Vanessai download the new one
07:29Vanessanow
07:40Vanessashouldnt running clojure.jar from the win com prompt start the repl?
07:40Vanessawhen i do nothign happens
07:40Vanessajava clojure...
07:41Vanessaexception blarf
07:41Vanessashould i be able just unzip and then do java clojure.jar in the directory?
07:41H4nsjava -cp clojure.jar clojure.lang.Repl
07:42rhickeyor java -jar clojure.jar
07:42rhickeyVanessa: by latest I meant the latest from svn
07:43rhickeymight work with sept release
08:05Vanessahow do i sort in descending order so i dont have to reverse
08:05Vanessaah change 1 and 2
08:05Vanessawhat si it that it does really?
08:06Vanessa(sort #(compare (val %2) (val %1)) tuples))
08:06Vanessa% is usually mod but not here right
08:07drewr#() is alternate reader syntax for an anonymous fn.
08:07drewr% is bound to the arg, if there is only one.
08:07drewr%1, %2, etc. are bound to the args for more than one.
08:08parth_mVenessa: http://en.wikibooks.org/wiki/Clojure_Programming#Anonymous_Functions
08:08abrooks%& is the "rest" argument. I learned about that recently.
08:14drewrCool, didn't know that.
08:17ChouserLau_of_DK: after "changing" a zip node, use zip/root on the result to get the whole tree including any changes.
08:36Vanessahow can i sum over this? (("account" 21) ("BUSINESS" 22) ("email" 23) ("money" 27))
08:37Vanessa(reduce + #( something?
08:37Vanessaiw ant to some the ints obv...
08:37rhickeyif it was still in a map you could just (reduce + (vals amap))
08:39lisppaste8hoeck annotated #68097 with "xml edit" at http://paste.lisp.org/display/68097#1
08:40hoeckLau_of_DK: you're right, using xml this way is really handy
08:42hoeckbtw, chouser: you rock! for doing this xml stuff and gen-interface! thanks!
08:45gnuvinceVanessa: how about (reduce + (map #(nth % 1) coll))?
08:49Chouserhoeck: heh, thanks.
08:52lisppaste8glarf pasted "spamfilter" at http://paste.lisp.org/display/68099
08:52glarfi posted my spamfilter ^^
08:53glarfcomments on style and stuff is appreciated
08:53glarfmy first lispprogram that actually doesns omething useful :)
08:54glarfit is a spamfilter that takes a file with spamemails, good emails and then an email to test and then accuracy(how many of the most common words found to compare)
09:26Chouserglarf: rather than [w (hd words) wr (tl words)], you could say [[w & wr] words] -- shorter, and doesn't need the non-standard hd and tl
09:36glarfcool haskell-like patternmathcin, very nice
09:36glarfhow do i force float-division?
09:37ChouserI don't know enough haskell to say, but I think it's a somewhat simpler mechanism -- "destructuring"
09:37glarfdo i have to convert one of the dividors to float or do * 1.0 ?
09:37Chouseryeah, wrap (float) around the whole thing or a divisor
09:37glarfok just (float var)
09:44ChouserI think count-all-words could be just (map #(count-word % lst) set)
09:48glarfcorrect, vn
09:49danlarkinhaskell-like?! more like prolog-like
10:07Chouserglarf: and I think count-words could be: (reduce (fn [occ w] (if (> (count w) 4) (assoc occ w 1) (merge-with + occ {w 1}))) {} (split file " "))
10:10glarfis there a way to shorten the massive error-messages?
10:11glarfliek normally the first sentence says something useful, then there is 30 rows of stuff that doesnt tell me anything
10:11Chouserat the repl they're only one line
10:12Chouserwhen generated from code in a file, those other error lines are often helpful for figuring out what lines of code are involved.
10:14glarfchouser: count-words, hmm it doesnt give any errors and it the program works however the result is not the same, 0.71 in one case, 0.52 in the other, i will look into it
10:16glarf2or merge-with will add values for keys that are equal?
10:23glarf2for some reason your functiond eosnt ignore the short words
10:23glarf2(> (count w) 4)
10:25Chousermerge-with uses the given function to merge vals when keys are the same. The function I gave was +
10:26glarf2ah now isee the error
10:28Chousernote there are no longer any uses of first/rest, so no need to use your aliases.
10:33glarf2im switching toa cond within the reduce
10:33glarf2how do i do with else.
10:33glarf2when the word is shorter than 4 chars i dont want to do anything
10:34Chouser:else occ
10:35glarf2yes
10:36lisppaste8glarf pasted "count-words" at http://paste.lisp.org/display/68103
10:37glarf2still a little bit shorter
10:38Chouserah, I see what I misunderstood about your algorithm.
10:41lisppaste8Chouser annotated #68103 with "filter instead of cond" at http://paste.lisp.org/display/68103#1
10:49blackdog`with svn should i not be able to say (supers {}) as map implemetns java.util.Map now?
10:51glarf2chouser: isnt that inefficient though, it goes over the list once to filter and another to reduce right?
10:51wwmorgan_blackdog: try (supers (class {}))
10:51blackdog`ah
10:51blackdog`thanks
10:57Chouserglarf2: O(n) either way, and since filter is lazy, each word is getting the size check then the reduce step before the next word is taken.
10:58ChouserI bet it's comparable, but feel free to run some time tests and see which is better.
10:59glarf2ok thanks is there something i have to think about or when combining map filter and reduce i can count on it being the same as doing it all within a for-loop in an imperative language
10:59glarf2anyway 2*O(n) is still slower than O(n) right?
11:00glarf2but as you said now they re both O(n)
11:02gnuvinceIf it's lazy, it should be pretty much the same performance.
11:02Chouserin yours, each word is looked up in occ before either assoc or size test. In mine each gets a size check, only long words go to merge-with. I'm not sure that's 2*the work.
11:04Chouseryou'd really have to run some test to see which is faster, as there are several differences. Creating a little hash-map for merge-with might be more expensive in mine than the extra word lookup in yours, for example.
11:04ChouserI'd be surprised is the difference was much either direction.
11:06glarf2i was thinking in un-lazy reduce/filter/map iterating twice over the list
11:06scottjWhat's the recommended way to get an integer from a float?
11:07wwmorgan_scottj: rounding or truncating?
11:07scottjwwmorgan_: truncating
11:07wwmorgan_(int x)
11:08scottjoh, missed that in the docs. I was searching for integer
11:10glarf2is there a time-function?
11:10glarf2or how do you profile?
11:10glarf2with your watch? :)
11:10Chouser(doc time)
11:13glarf2ok that retuend instantly
11:13glarf2which shoudlt happen
11:13glarf2�m testing ona huge file
11:13glarf2took 20 seconds before
11:13glarf2took 0.03 msec with time...
11:14Chousergot the right answer?
11:14glarf2no, no answer
11:14wwmorgan_glarf2: your function is probably lazy. Wrap it in a doall
11:14glarf2"Elapsed time: 0.028774 msecs"
11:14glarf2user.run__2537@15c30f6
11:14glarf2(time run)
11:14glarf2run = (defn run [] (classify f1 f2 f3 50))
11:14Chousertry (time (run))
11:14glarf2ah ofc
11:28glarf2chouser: the one using cond is slightly faster
11:28glarf213sec vs 14 sec
11:28Chouserok
11:41danlarkinis java 1.5 the same as "Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.x)
11:41danlarkinwhy did they change the naming scheme :'(
11:45ChouserI think it is the same, and I have no idea. I think someplaces it's also called 5.0
11:48scottjI'm not seeing in the docs how to find the length/size of a collection. ?
11:48Chouser(doc count)
11:49scottjIn this case rick is wrong. There are too many good words :)
11:49Chouser:-)
11:52rhickeysize is relative, and may have units, length implies distance, not a good fit for non-sequences
11:53rhickeycount is about number, and also is a verb
11:54Chouserrhickey: I can't find anywhere that ever inits the vector held inside LazilyPersistentVector. vestigal feature?
11:54Chouseroh, scratch that, I see it.
11:54lisppaste8rgr annotated #68103 with "ignore this" at http://paste.lisp.org/display/68103#2
11:55glarf2i never feel like i need macros, are they overhyped? when using imperative languages i miss higher order functions, but never macros
11:55glarf2reddit: http://items.sjbach.com/16/some-notes-about-clojure
11:56Chouserin my experience, one very rarely needs to write macros in any language that has them.
11:56ChouserI frequently want them in languages that don't (JavaScript!) but if they exist, someone probably already wrote the macro I want.
11:58rhickeythey are quite important to keeping the size of Clojure's core down
12:00scottjWhat is the common functional way of doing two for loops, one inside the other?
12:00Chouser(for [a [1 2] b [3 4]] (list a b))
12:00Chouserreturns: ((1 3) (1 4) (2 3) (2 4))
12:00cemerickMacros can be indispensable in a domain-specific setting.
12:15Chouserright -- when you need them, there's no substitute.
12:53scottjAnyone else running ubuntu? Is the blue text near the bottom of http://clojure.org/reader hard for you to read? I'm wondering if it's just something on my computer setup or if the style for the examples in the docs might be hard for lots of linux users
12:54scottjIt is much easier to read on my Windows computer..
12:54Chouserscottj: ubuntu here -- the only blue text I see is the code snippet. looks ok to me.
12:56blackdog`how's clojurescript going Chouser?
12:57blackdog`still have steam? :)
12:57Kerris2hello, I need help with using the Repl with JLine
12:58Kerris2I've copied the contents of the jline folder into the clojure folder, but
12:58Kerris2java -cp jline-0.9.94.jar:clojure.jar jline.ConsoleRunner clojure.lang.Repl doesn't work :|
12:58Chouserblackdog`: a bit -- as of last night, trying to fill in some missing pieces in PersistentList and LazilyPersistentVector
12:59blackdog`are you going to implement dosync and STM?
12:59scottjChouser: does it look like http://www.mediafire.com/?zimewyqynny for you?
13:00Kerris2maybe it'll work if I add both to the classpath
13:00Kerris2got to go now
13:02Chouserscottj: mine looks a little darker to me.
13:45blackdog`would it be possible to add a print method to see an array of java strings? rather than this [Ljava.lang.String;@1465ca2 ?
13:45kotarakTry (seq array-here). Help me with the inspector.
13:45kotarakHelped...
13:46blackdog`yea, i'm doing it by converting to a vec right now, but at the repl it would be a bit nicer
13:47blackdog`i was thinking giving the print multi methods now it could be quite easy to do
13:49Chouser(defmethod print-method (Class/forName "[Ljava.lang.String;") [a w] (.write w (str "[" (apply str (interpose " " a)) "]")))
13:49blackdog`:) thought so
13:50ChouserI guess that's not really right.
13:50blackdog`works for ,e
13:50blackdog`me
13:50blackdog`very neat
13:51Chousermaybe:
13:51Chouser(defmethod print-method (Class/forName "[Ljava.lang.String;") [a w] (.write w (str "(into-array" (apply str (map #(str " \"" % \") a)) ")")))
13:51kotarakThe right is probably to check for .isArray in the :default implementation. At least are Arrays handled like this eg. in nth.
13:51blackdog`first one was better :P
13:52Chouserkotarak: yeah, this one's pretty specific.
13:52blackdog`good enough!
14:13glarfanihi i started with the (considering my lisp-noobness) ambitious project of creating an object-system for clojure.
14:13Chouseryikes
14:13glarfaniim not sure about gensyms
14:14glarfanisymbol# right?
14:14hoeckglarfani: or (gensym)
14:16H4nsXis there a way to query a form for its class? the compiler seems to know anyway when it finds out the methods that can be called in a dot expression. is that information available to clojure programs, too?
14:16kotarak(class ...) maybe?
14:17H4nsXkotarak: that will give me the class of a value. i need to compile-time class so that my macro can introspect into it.
14:17H4nsXs/to/the/
14:17rhickeyH4ns: (resolve 'java.util.HashMap)
14:18H4nsXrhickey: ah, cool. trying that, thanks!
14:19eyerisCould someone point me to the documentation for how to invoke clojure as a compiler?
14:19eyerisI can only seem to find the `java -cp clojure.jar clojure.lang.Repl`
14:19kotarakThere is no .clj to bytecode-in-file compiler at the moment.
14:20eyerisIs there a "just compile and run this .clj" invocation?
14:20eyerisnon-interactive
14:20Chouserclojure.lang.Script
14:20kotarakclojure.lang.Script
14:20eyerisIs there an echo in here? :)
14:21kotarak... echo in here? ... in here? ... here? ;)
14:21danlarkinwow the clojure REPL is forming a habit... I'm trying to tab-complete in my emails...
14:22kotarakWith certain editors this might work...
14:22H4nsXrhickey: no, that don't work - i am propably mislead anyway. i wrongly assumed that the method lookup would happen at compile time, whereas it is propably clear that it happens at run time.
14:23ChouserH4nsX: if the object type is known at compile time, it is resolved then.
14:23Chouserif not, it's "reflection" and can be flagged with *warn-on-reflection*
14:23H4nsXChouser: ah, ok. thanks. i'll play some more.
14:23rhickeyH4nsX: I'm not sure what you are trying to do, but Clojure tries to avoid runtime lookup
14:25rhickeyIf you are trying to write a macro, resolve will give you the class, your macro may need to do some reflection if you are trying to auto-build wrappers, but the code it emits can avoid reflection
14:25H4nsXrhickey: i would like to have a more pleasant syntax for getters and setters and am thinking about i could implement that. something in the lines of (getp object :fieldName) and (setp object :fieldName value)
14:26rhickeyyou should look at bean
14:26H4nsXok, will read up on resolve and bean, thanks!
14:26rhickeyyou could make a lazy version of bean
14:27rhickey(bean (java.util.Date.))
14:27H4nsXuh, that is cute.
14:28H4nsXmaybe i can just use that for starters and make it lazy once i feel it hurting me.
14:28H4nsX(but my plan is to stay scalable to multiple cores, so it may never hurt me)
14:29eyerisIs there a repository of example code I can browse through?
14:30rhickeyeyeris: there's the wiki, also: http://blog.thinkrelevance.com/2008/9/16/pcl-clojure
14:30rhickeyand http://writingcoding.blogspot.com/2008/06/clojure-series-table-of-contents.html
14:31rhickeyand clojure-contrib
14:31rhickeyand boot.clj
14:31eyerisThanks
14:31hoeckand boot.clj
14:31hoeckoops
14:31shooverThere's a nice chunk of practical clojure in http://github.com/jochu/swank-clojure/tree/master
14:40gnuvinceChouser: just a followup on yesterday, the problem was definitely with my network, so fetching pages in my Clojure script is now much faster
14:40Chousergnuvince: ok, good to know.
14:44glarfanicant i create a hash-map with a gensym-key or use gensyms outside macros?
14:45cemerickglarfani: (gensym) works fine outside of macros
14:45Hunwhat's a use for a hashmap with a gensym-key?
14:46rhickeyglarfani: sure: (hash-map (gensym) 1 (gensym) 2)
14:50lisppaste8rhickey pasted "reader object literals" at http://paste.lisp.org/display/68112
14:50rhickeysomeone was musing about defining print-method for arrays, without read support it's not that useful
14:50rhickeyalso, for AOT compilation I'll need readable representation of more objects
14:51Chouserhey, my string printer kinda worked -- printed (into-array ...)
14:51Chouserbut yours is, of course, better. :-)
14:51rhickeythe paste is what I'm thinking about, would allow print-methods to target this generic constructor form
14:52Chouserwould print now differentiate between hash-map and sorted-map (for example)?
14:52rhickey#<classname ctor args ...>
14:52rhickeyChouser: there might still be special handling for those
14:53rhickeythese would be striclty literals - no evaluated args
14:53rhickeystrictly
14:55Chouserlooks pretty good to me. JavaScript knows how to "print" lots of things that the JVM doesn't, and I could drop those into this syntax pretty easily.
14:55ChouserI think.
14:56rhickey#[...] would get evaluation support, like the built-in collections
14:56rhickeymaking it easier to call Java variadics
15:00chmuhi, is it possible to add metadata to structs? (with-meta (create-struct :x :y) { :mymeta 123 }) doesn't work (IncompatibleClassChangeError)
15:00Chouseris there something that prevents Java variadics from being supported directly?
15:02Chouserchmu: you can put metadata on a struct map
15:02Chouser(defstruct coord :x :y) (with-meta (struct coord 1 2) {:mymeta 123})
15:03chmuChouser: I would like to add metadata to the "type" and not to the instance.
15:04chmuChouser: Specifically I would like to add "type information" to members
15:05rhickeyChouser: the problem with supporting variadics directly is you can't tell, when being passed an array arg, if that is intended to be the entire set of variadics or simply first of one - in Java you use type casts to help the compiler
15:06Chouserrhickey: oh, type casts on the calling side? bleh.
15:06rhickeyright, bleh
15:06rhickeychmu: right now those struct basis objects are opaque
15:07Chouserthat's interesting, though, because I think I'm supporting them fine in JavaScript.
15:07chmurhickey: Ok, maybe I should define my own "struct" then?
15:09rhickeychmu: you could always stick the basis object inside something else which held your extra data, then define a constructor fn that encapsulated that
15:10glarfanii want to make a function assoc! that : (assoc! some_map "hello" 12) -> (def some_map (assoc some_map "hello" 12)). but when i do as that i am returned a new map even if deffing to the variable passed
15:10glarfanido i need to use a macro or this is clojure immutabilti?
15:10chmurhickey: ok, thanks
15:10chmurhickey: I also tried to associate metadata with the symbol but ran into a problem with macros and metadata
15:10chmurhickey: (defmacro create-bla [name val] `(def #^{:Some :MetaData} ~name ~val))
15:11chmuMetadata can only be applied to IObjs
15:11rhickeychmu: you have to understand the macro output will not be re-read, what you are trying to emit there is reader syntax for metadata - you could instead (with-meta...) the name symbol itself
15:12rhickeysee defn in boot.clj
15:13chmurhickey: Alright, so its not possible to "escape" the metadata construct?
15:14rhickeychmu: once your are defining the macro reading is over, but code is data and you can produce a form with metadata certainly
15:14rhickeyglarfani: I'm not sure anyone will help you do that - what you are trying to do is very much not in the spirit of Clojure
15:15chmurhickey: thnx
15:16gnuvincerhickey: does Clojure allow the creation of reader macros?
15:17rhickeygnuvince: not so far, and not likely until I figure out how to make them interoperate. Unlike regular macros there are no namespaces to prevent clashes between two sets of reader macros
15:17gnuvinceok
15:18rhickeyof course I could have used up all the good characters by then :)
15:18glarfanirhickey: lol ok but im playing with clojure to learn more than anything else. learn about lisp, macros, language design etc.
15:18Chouserglarfani: you could write a function that does something like that on a ref
15:19Chouserbut just because you can doesn't mean you should.
15:19rhickeyglarfani: you'll learn the most by trying to avoid doing that :)
15:25Chouserrhickey: would you prefer posts with patches to have "PATCH" in the subject or something? Or would that just be ..um... bait.
15:43Chouserrhickey: there are a few things that could be Reversible that aren't (ArraySeq, StringSeq, Range, maybe others).
15:43ChouserIs that on purpose or just because rseq's not likely to be needed on those.
16:01gnuvincerhickey: do you think it would be do-able/reasonable to auto-escape backslashes in regex literals? Being able to write #"\d" instead of #"\\d"
16:03Chousergnuvince: this has been discussed at length, but the interested parties gave up before reaching a conclusion.
16:03Chouser(myself included)
16:04Chouserwe should give it a good think and come up with a real solution.
16:04abrooksgnuvince: Unfortunately, the regex literals are parsed as Java strings. Departing from that MAY be the right thing but it's not a minor departure.
16:05gnuvinceI admit that I haven't looked at the source code before suggesting this (not that it would help much, I don't know Java.)
16:05ChouserI really want to do better. Clojure controls the reader, so we should make regex less painful. But there are edge cases that need to be thought out.
16:06Chouserhttp://groups.google.com/group/clojure/browse_thread/thread/81b361a4e82602b7/0313c224a480a161
16:06abrooksChouser: Right but there's the concern that a regex literal would look different from a string literal that is turned into a regex (or if they looked the same, they'd act differently). That would be yucky.
16:06gnuvinceI'll read that tonight.
16:09Chouserheh. yeah. good luck. :-)
16:10Chouserseriously though, I suspect there's a nice clean solution in there, but we can't just suspect or suppose, we need to provide sufficient evidence.
16:10Chouser...and do it soon enough that rhickey will consider including what's bound to be a breaking change to the reader.
16:10gnuvinceIndeed
16:11Chouserabrooks: hm, interesting, though it might be hard to get rich to give up more reader chars for regex. :-)
16:11gnuvinceI don't dislike syntax when it helps, but gratitious additions are just bloat.
16:11cemerickI'd think that regex literals could be interpreted as "raw" strings, a la python...
16:11abrooksWould it be bad to have three regex syntaxes? I think Rich might balk.
16:11gnuvincecemerick: that would prevent somebody from using hex or octal literals
16:12gnuvince(though they could use (re-pattern "\xc3")...)
16:12cemerickgnuvince: yeah, that's quite the edge case compared to forcing everyone to type \\d
16:12gnuvincecemerick: I agree
16:12ChouserJava regex knows how to parse hex literals to mean matching only that char
16:12Chouseralso octal literals.
16:13Chouserso passing those "raw" into the Java Pattern should Just Work.
16:13ChouserI *think* almost everything works out like this, but someone needs to do the grunt work to demonstrate there aren't nasty corner cases lurking.
16:15abrooksChouser: You're right. Pattern still knows all of the escapes that you'd want to do as string escapes.
16:18abrooksChouser: Currently Pattern.pattern() returns a string identical to the input: (. #"\\\\dfoo" (pattern))
16:20abrooksChouser: I'm really torn here. The Java situation is really horrible. Needing to think about more than one escaping level at a time is painful and prone to error. Being out of parity with the printable string form would be bad as well.
16:21ChouserI'm not torn at all. I don't care what .pattern returns, as long as clojure prints the same thing it reads.
16:22ChouserIn my opinion, the current syntax is not good at all. To match a double quote (single char) you currently have to write #"\\\""
16:22Chouserunacceptible.
16:23Chouserbut we want to get it right once, and clearly #""" isn't going to work, so we have to work out the details
16:24Chouserhm, you strike that -- you can also say #"\""
16:25abrooksChouser: ... right. :)
16:25Chouser...which just proves Java Pattern is actually helping us out here -- we can pass in \" as raw and Pattern will do the right thing for us.
16:26abrooksAs long as a Clojure regex can display the string in the same form as a literal regex or a regex created from a string so user input regexes are the same as user displayed regexes are the same as progammer visible regexes, I'm cool.
16:28Chouserwhee: (prn-str (str \\))
16:29abrooksAck.
16:29gnuvinceouch
16:31ozzileeChouser: Why isn't #""" clearly going to work?
16:33ozzileeNevermind, I was thinking of something else.
16:33abrooksozzilee: Which quote terminates the regex? Consider that #"" " foo" and #""" foo" are the same.
16:33ozzileeabrooks: Well, I was thinking of """This is a raw string"""
16:33abrooksAh, heh. Gotcha.
16:35duck1123does anyone know why I'm getting the message "java.lang.Exception: Unable to resolve symbol: progn in this context (NO_SOURCE_FILE:1)" when I try to open slime?
16:36Hunold slime i guess
16:36duck1123I also see this: (progn (load "/usr/share/common-lisp/source/slime/swank-loader.lisp" :verbose t) (funcall (read-from-string "swank-loader:init")) (funcall (read-from-string "swank:start-server") "/tmp/slime.31791" :coding-system "iso-latin-1-unix")) which I think is the problem
16:36Hunprogn is common lisp
16:36danlarkinas for raw strings, I like the way python does it... prefixing the string literal with a lowercase R
16:36Hunyou need a head cvs to use it in clojure
16:37danlarkinso r"raw string", r'raw string', r'''raw string''' and r"""raw string""" are all the same, raw strings
16:37ozzilee#"""<([A-Z][A-Z0-9]*)\b[^>]*>(.*?)</\1>""" looks ok to me.
16:38duck1123I'm running a version from git from 2008-10-04
16:38Chouserhuh. "\\" works, (= (str \\) "\\") is true, but #"\\" breaks
16:39Hunduck1123: of slime and swank_clojure
16:39wwmorgan_Chouser: I think because \ is not a valid java regex
16:40duck1123Hun: the swank_clojure should've been from the same day
16:40Chouserok, I think this may not be too bad.
16:40Hunthen it might be your slime. it tries to load the common lisp sources in clojure (which obviously fails)
16:40Chouser(defn prptn [p w] (.write w "#\"") (.write w (.replace (.pattern p) "\"" "\\\"")) (.write w "\"\n"))
16:41ChouserThat prints a Pattern using the proposed new syntax, just like abrooks wants.
16:41Chouser" and \ must be (and when printed, are) escaped with a \
16:42abrooksChouser: Great -- but (.pattern #"foo") should return the right thing by default, IMO.
16:42Chousereverything else is raw and literal, and I think you can match anything.
16:42Chouserabrooks: can't, that's Java's method
16:42abrooksIs there a Pattern interface?
16:42Chouserbut (prn #"foo") can be made to use the implementation of prptn.
16:45abrooksChouser: Would it be reasonable for an arity-1 prptn just return the apropriate string instead of write()ing?
16:46Chouserreplace "defn prptn" with "defmethod print-method java.util.regex.Pattern" to plug it in (and throughly confuse yourself as you now have a non-standard prn)
16:50abrooksBy appropriate string, I mean the form that you'd use in the literal format, not the What Would Java Do string.
16:51Chouserabrooks: it would just be confusing, because the printer of the repl will stick a bunch of backslashes in there so it can be read by the current reader.
16:53abrooksChouser: I'm now confused. I was assuming you were talking about the future modified reader which didn't require slashing everything to death.
16:54Chouserprptn writes out a string that a proposed future reader could just read.
16:54Chouserdefining it today as a print-method allows you to use today's prn to print out these future reader strings.
16:55ChouserI thought you were asking for a prptn-1 that takes a single arg and returns a string -- this would not be useful today for the reason I gave.
16:57abrooksChouser: I was asking for that but I wanted it for the future usefulness. Also for other things (str "My pattern -->" (prptn #"foo") "<--")
16:57abrooksprptn is probably not a useful name in that case.
16:58Chouserprptn is not meant to be a name that would ever be using in the proposed future clojure.
16:58abrooksPerhaps would be a separate function which would do what I want.
16:58abrooksChouser: Ah. AH HA!
16:58Chouseryou could use (prn "My pattern -->" #"foo" "<--")
16:59abrooksChouser: Only if I wanted to prn it. If I wanted to do something else with it (such as stick it in XHTML or a database do other processing) I'd want a string.
17:00Chousergah, well, then you'd probably get what .pattern produces. Why would you do that?
17:00Chouserno, if you want to represent code as data in a string, use prn
17:01Chouseror prn-str or whatever.
17:01Chouser(str [1 2]) ==> "<vector: - 2 items>"
17:12persiI it possible to compile and load .java files into closure?
17:12persiclojure/closure
17:12Hunyou can just import classes
17:13persidoes that work for iterative development?
17:13persii.e. can I reimport?
17:13Hunhaven't tried, but i think so
17:14persithanks. will try.
17:14ChouserI don't think so -- once a class is loaded, I think it's done.
17:15Chouserwhich is part of why gen-class works the way it does, allowing you to swap in new method implementations even though Java doesn't let you actually change the class.
17:16persidarn.
17:16persiso not really any help for developing java code.
17:16persireally was hoping for a repl around my java library development.
17:16Hunbean shell?
17:18persibean?
17:18persii'm a lisper, not a java person.
17:18Hunah, ok :)
17:18persineed to develop some java and just wished for iterative development.
17:18persithought clojure could help.
17:19Chouserpersi: it's a JVM restriction, I think.
17:19ChouserMaybe you could something with creating new classloaders on the fly or something, but that's all over my head.
17:20persiChouser: yea, figured that much. just going to go back to the stoneages of compile run rinse-repeat.
17:24kotarakpersi: as long as you handle your object from clojure, you could do (YourClass-possible-method your-obj with some args). When you are satisfied, create a corresponding gen-class and its available from Java.
17:30persikatarak: But i'm developing a .java and using javac to make a .class. Can I do what your saying with this?
17:30persikotarak: But i'm developing a .java and using javac to make a .class. Can I do what your saying with this?
17:31kotarakProbably not. But why do you need Clojure then? My idea was: create a Java class via gen-class. If you have a new method, but are not sure, test from the clojure side as described. Then finally add the definition of the method to gen-class call and it is available.
17:56scottjIs there a function I'm missing that's like (first-that pred coll) and returns the first value in coll that satisfies the predicate?
17:58Chouser(doc some)
18:00wwmorgan_some is slightly different: it returns the first true value of (map pred coll)
18:01wwmorgan_scottj: I think the best you can do is (first (filter pred coll))
18:02duck1123we need a clojure bot in here like what fsbot does in #emacs
18:02Chouserwwmorgan_: ah, good point.
18:03scottjI think first-that could be written as a macro by wrapping the predicate in an if that returns the arg if true
18:04Chouserwouldn't need a macro, just wwmorgan_'s code
18:04wwmorgan_yeah, laziness saves the day there, you fall out at the first true result
18:04Chouseryup
18:04scottjwwmorgan_: even if your collection is not lazy?
18:05wwmorgan_scottj: right, because filter is lazy
18:05scottjoh cool
18:11duck1123is there an easy way to add a folder to the classpath within clojure?
18:11Chouser(doc add-classpath)
18:13duck1123thanks, I must have missed that one
18:13Chousernp
18:14scottjChouser: after running that should (. System (getProperty "java.class.path")) return anything different?
18:14Chouserscottj: not sure -- I wouldn't be surprised if it didn't. I think it changes the classpath of some other classloader.
18:16scottjok, I don't think it changes
18:17duck1123I'm not seeing it change
18:18Chouserbut does it work?
18:18Chouseras in, can you load the class you want?
18:53scottjFrom a basic clojure setup what has to be done to use psummary and inspect-table? I tried the following but it gives a class not found exception I think on ParallelArray (I'm not sure if slime modifies the error messages)
18:53scottj(ns foo (:require [clojure.parallel :as par]) (:use clojure.inspector)
20:32rntzis there some sort of searchable documentation for clojure? (like hoogle for haskell)
20:45rhickeyrntz: there's (find-doc "regex string"), also http://clojure.googlegroups.com/web/manual.pdf
21:09rntzrhickey: thank you