#clojure logs

2008-10-04

01:11avida /whois qmrw
04:08prunedtree<lisppaste8> baetis-fly pasted "Faster nsieve vs. prunedtree" at http://paste.lisp.org/display/67899 << this is cute, but If I wanted to write C code I wouldn't be here ;)
04:10PupenoGood morning.
05:42arnfredHi there, I'm just starting learning clojure at the moment but so far I'm having a little trouble importing java's scanner so that I can get some user input
05:42arnfredwhen I'm writing: (import '(java.util.scanner))
05:42arnfredit seems ok
05:42arnfredbut then when I'm trying to do: (new Scanner blah), it comes up with an error
05:43arnfredCan anybody tell me what I'm doing wrong?
05:48hoeckhi arnfred: its (import '(java.util Scanner))
05:49arnfredokay, and then when I use it, I can use (new Scanner blah) ?
05:50arnfredor rather, what can I do to use it afterwards?
05:50hoeckarnfred: yes, or (Scanner. blah), import doesn't complain when tryin to import non-existing classes
05:51arnfredhmm, I can't get anything else that errors out of my interpreter right now
05:52arnfredI think the class is imported alright, but I can't seem to use it
05:52arnfredI should probably read up on this somewhere
05:52arnfredthanks a lot for your help though
05:53hoeckarnfred: what are you trying?
05:53arnfredI'm trying to read in a couple of numbers and add them together and then spit them out
05:54arnfredbasic basic stuff ;)
05:54arnfredjust to get a feeling for the language
06:00hoeckah, okay, feel free to ask whatever you want to know
06:02arnfredthanks, hoeck, will do : ) for now I'm trying to find a good introduction online to practical clojure, that is, no fibonacci but lot's of I/O, so if you happen to know any, then I'm all ears
06:09rottcoddarnfred: this might help: http://en.wikibooks.org/wiki/Clojure_Programming#Links_to_more_Examples
06:10hoeckarnfred: clojure.contrib is agood source too, eg.: http://clojure-contrib.svn.sourceforge.net/viewvc/clojure-contrib/trunk/src/clojure/contrib/duck_streams/duck_streams.clj?revision=150&amp;view=markup
06:11arnfredthanks a lot, I'll look into it
06:30PupenoIs there any list/manual of i/o related functions in Clojure? or... how do I iterate over all files in a dir and that kind of stuff.
06:57hoeckPupeno: try (find-doc "file") for searching docstrings containing "file"
06:57hoeckand (file-seq (java.io.File. "/home"))
08:33Hunhi there
08:33jgracinhi Hun
09:19PupenoUsing Slime, can I compile the whole file?
09:20HunC-c C-k
09:21Hun(ok, that's compile-and-load... but i think it might be what you want)
09:21Pupenoyes, that's what I want.
09:22PupenoI thought it was not working, because it issues an ugly message, but it is.
09:24Hunwhen it doesn't work, the debugger should pop up (at least that is the case in CL). haven't tried to much with clojure yet
09:24PupenoHun: what do you use with Clojure?
09:25Huni experimented a bit in the repl 4 months ago and managed to get slime running today :)
09:25Hunand took the last 3 hours getting java api documentation to work properly inside emacs
09:26PupenoJava documentation inside emacs? kewl, I want that!
09:26Pupenobbl
09:27rhickeyHun: yes please, how (java api in emacs)?
09:27Huntry a combination of emacs-w3/w3m (whichever you get to run) and javadoc-help
09:27Hun you have to download the java documentation for it being fast
09:27Hunhttp://surfnet.dl.sourceforge.net/sourceforge/javadochelp/javadoc-help.el
09:28rhickeyHun: thanks
11:20H4nsXhi. is the debugger supposed to work in enclojure? i've tried setting a breakpoint, but it seems to be ignored.
11:20H4nsXoh. there is #enclojure, never mind me
11:24Hunhi H4nsX. the world is small :)
11:25H4nsXHun: yes. especially when it comes to people who grok parentheses
11:25Huntrue
14:06PupenoIn the API, I see it says clojure, clojure.xml, etc. Are those namespaces?
14:19HunPupeno: i think that are java's namespaces. clojure's are divided with /
14:19drewrPupeno: They're Clojure package delimiters.
14:19drewrclojure/foo => fn foo in clojure ns
14:20drewrclojure.xml/foo => fn foo in clojure.xml ns
14:20drewrThey're package names. The periods are the delimiters.
14:21drewrs/package/namespace/g
14:30Pupenois there a pretty-print somewhere?
14:32Hunif it's only for debugging, slime's inspector works...
14:32PupenoHun: mh, I never used it.
14:34Hunwhen you're running slime, hit C-c I after an expression
14:34Hunyou can browse from there on
14:34scottjdoes slime work better if you don't use slime-fancy?
14:34H4nsXHun: you need to assign everything to variables that you want to inspect, right?
14:35Hunnot necessarily... you can also eval in there
14:35Hunso (* 5 5) C-c I goes to 25
14:35H4nsXHun: ah, ok.
14:35Pupeno"error in process filter: Keyword argument :id not one of (:title :type :content)", except loading, nothing else works for me on Slime.
14:36HunPupeno: try a current svn version
14:36Hunit's only in for a few days
14:36H4nsXPupeno: works for me if i follow the directions. current slime, swank-clojure from git
14:36Huni had the same error
14:37Hunmy emacs loaded an older slime version from a previous lispbox installation
14:38PupenoI wonder what is it with Slime that for 5 years or so nothing but the absolutely latest patch from SVN worked.
14:39Hunit's rewritten every few months :)
14:39PupenoHun: I suppose they don't read Joel On Software
14:39Hunmaybe it's better this way ;)
14:40PupenoHun: I doubt it.
14:40PupenoHun: you said SVN, but on Slime I've found a point to cvs, are they still using cvs?
14:41Hunyep
14:41Huni use `current svn' as `whatever is newest in their vcs of choice'
14:41PupenoHun: ok.
14:42Huncoincidentally, this made some bugs happen for me with stumpwm
14:42Huni was using its cvs head. but they switched to git a year ago. so i tried to commit bugfixes against a long obsolete version
14:43PupenoAlso, did anyone managed to create an enclojure project?
14:44H4nsXi created one, but i can't debug with it, so i'm back to slime
14:52H4nsXum. somehow, it seems as if the dot operator does not nest, is that true?
14:53PupenoHun: the inspector looks nice, but I have a lot of maps one inside another and I need to get a feeling of the tree, so I really need a pretty printer.
14:55HunH4nsX: there's ..
14:56H4nsXHun: i'll look at that.
14:58H4nsXi really want to access two objects from different java classes in one expression - .. seems to be useful if one wants to access the same class multiple times
14:58H4nsXi must admit that i do not yet have a good grasp at how java names are specified in clojure
15:30ChouserI can't think of any way in which the . operator doesn't nest.
15:30ChouserWhat's the problem?
15:44duck1123do I still need to set swank-clojure-jar-path?
15:44duck1123I can't get slime to connect
15:44Pupenoduck1123: I do set it.
15:44Hunhow are you trying? i needed it
15:44duck1123I'm getting a no class def found
15:46Pupenoduck1123: that's likely to be the jar not being found. Why don't you just set it?
15:47duck1123I did
15:47duck1123I just can't figure out why it's not finding the jar
15:48Pupenoduck1123: are you using ~?
15:48duck1123no
15:48duck1123I tried both ways
15:49duck1123(setq swank-clojure-jar-path "/home/duck/clojure/clojure.jar")
15:50Pupenoduck1123: are you doing it before (require 'swank-clojure-autoload)?
15:50duck1123yes
15:50duck1123but after the clojure mode
15:50Pupenome too.
15:50Hunyou might have to restart emacs if you got that wrong. swank-clojure.... only reads that var once
15:55duck1123would it matter if I had code to set up sbcl higher in my init script?
15:56duck1123I think I got it by renaming ~/clojure/ to ~/.clojure/
15:56Pupenoduck1123: I got rid (commented out) all the sbcl code, I'd try that first.
15:57PupenoI just wrote a one liner that dives inside an XML up to certain element and gives me all the tag-names of the subelements... I just love Lisp... it's taking me some time to get re-used to it, oh! the power!
15:59duck1123How well does clojure work in a servlet environment?
16:17PupenoHow do I 'add' an item to a map? (that is, get a *new* map with the new key/value pair)
16:17H4nsXChouser: never mind. i am totally confused by the error messages.
16:18H4nsXPupeno: conj does that
16:18rhickeyalso assoc
16:19Pupenowhich one should I use?
16:19H4nsXPupeno: rhickey is certainly more authoritative :)
16:20rhickeyif you have separate key and value, then assoc, but of you have key/value pairs from some process, then conj:
16:20H4nsXChouser: |-- java.lang.Exception: Unable to resolve symbol: setDataHandler in this context (cc-test.clj:13)
16:20PupenoH4nsX: yes, but he said 'also' ;)
16:20rhickey(assoc m k v) === (conj m [k v])
16:20Pupenorhickey: thanks.
16:21H4nsXChouser: i kept looking at this, thinking that i have some problem with my imports where the problem seems to be that i put the form somewhere where clojure could not find the type (?)
16:24PupenoDo we have a proffered pastebin?
16:25H4nsXhttp://paste.lisp.org/
16:26rhickeylisppaste8: url
16:26lisppaste8To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.
16:26lisppaste8Pupeno pasted "add-or-inc" at http://paste.lisp.org/display/67934
16:27PupenoIs there a better way to write that add-or-inc?
16:27PupenoIt adds elements to a map, but the next time increments the counter.
16:30lisppaste8rhickey annotated #67934 with "add-or-inc" at http://paste.lisp.org/display/67934#1
16:31rhickeyleverages the fact that get can take an optional default value if not found
16:32Pupenorhickey: thanks! :)
18:06PupenoIs there a reverse of filter? that is, negating the predicate.
18:07rhickeyPupeno: you can just complement the predicate
18:07Pupenorhickey: you mean I can do it without creating an anonymous function?
18:08rhickey(complement pred)
18:08Pupenorhickey: oh! excellent :)
18:08PupenoThanks.
18:08rhickeynp
18:10Hunwhich i think just creates an anonymous function
18:10rhickeyyes
18:10PupenoHun: well, yes... I was just going for legibility, I don't care about one more or less anonymous function ;)
18:11Hunin that case it's easy to create a toolset of some functional stuff :)
18:11Hunlike compose, foldl, foldr, unfold, curry, uncurry, and so on (depending on what is missing)
18:15PupenoHun: well, I was about to create an only-if, which was going to be like filter but reversing the predicate; no problem creating it, but if it already existed I wanted to use it.
18:15Pupenorhickey: is there any reason why the argument to let is a vector instead of a map?
18:17Huna map would be too crass for those old-school-lispers. we're used to having a list (aka seq) there
18:18PupenoHun: well, I understand, but Clojure doesn't seem designed for old-school-lispers (and I'm very thankful about it). A map seemed like the right data structure for that task.
18:18rhickeyPupeno: let bindings are sequential but map literals are hashed, random order
18:19Hunnot really. a vector (as a list) is pretty predictable where everything ends up. maps are all over ram
18:19rhickeysomeone suggested parallel let using map literal
18:19Hunin no order
18:20Hunthe old let was a straightforward translation of (let ((x 3) (y 5)) ...) to ((lambda (x y) ...) 3 5)
18:20Hunso you just need 2 maps for implementation
18:20Hunand get the parallel assignment for free
18:20rhickeyHun: Clojure already has compose, reduce and very nice anon fns with #() that allow partial binding of any position(s)
18:21Pupenorhickey: I thought about that. If I do {a b c d}, isn't b always to be evaluated before d?
18:21Hunrhickey: oh, cool. then not so much stuff is missing :)
18:21Huni really like my unfolds
18:22rhickeyPupeno: first the map will be read, then presented to the compiler with random order
18:22Hunnot random. but hard-to-predict
18:22rhickeyHun: right
18:23Pupenorhickey: oh! so there's no guarantee that b is evaluated before d?
18:26rhickeyPupeno: the compiler wouldn't be able to tell which you wrote first once the map was read
18:36PupenoOh, ok, makes sense, I suppose.
18:36PupenoAnyway, time to sleep around here.
18:36Pupenorhickey: Thank you for writing Clojure!
18:52H4nsXrhickey: does clojure support class annotations? i'm working with a class library which wants me to annotate my derived classes to specify their threading behaviour.
18:53rhickeyH4nsX: not yet
18:54H4nsXrhickey: high or low on your list? will propably require a different proxy syntax?
18:57rhickeyH4nsX: not on the radar yet
19:00H4nsXrhickey: ok. it is propably more design work than implementationally hard, and i might be able to change the library so that the behavior can be controlled through a base class constructor parameter. thanks.
20:00gnuvince_Is there a function to determine if an element is in a collection?
20:00Chouserwhat kind of collection?
20:03gnuvince_Chouser: vectors
20:04rhickey(first (filter #{element} v)))
20:05ChouserIt's going to be linear time, though. Slow. If you're going to do that a lot you might consider using a hash or set instead of a vector.
20:06Chouser(some #{element} v) works too, linear time.
20:06gnuvince_I have 4 elements, so I can live with linear time
20:07gnuvince_although...
20:07gnuvince_order doesn't matter in that particular collection (playing card suits)
20:07gnuvince_So I guess I could be using a set
20:07Chouserplus then you can just say (v element) -- faster *and* more succinct.
20:08gnuvince_Yeah
20:08gnuvince_I'm doing my usual "learn a new language with a not-too-trivial problem"
20:09Chouser:-)
20:09gnuvince_A Cribbage points counter