#clojure log - Oct 04 2008

The Joy of Clojure
Main Clojure site
Google Group
List of all logged dates

1:11 avida: /whois qmrw

4:08 prunedtree: <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 ;)

4:10 Pupeno: Good morning.

5:42 arnfred: Hi 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

5:42 when I'm writing: (import '(java.util.scanner))

5:42 it seems ok

5:42 but then when I'm trying to do: (new Scanner blah), it comes up with an error

5:43 Can anybody tell me what I'm doing wrong?

5:48 hoeck: hi arnfred: its (import '(java.util Scanner))

5:49 arnfred: okay, and then when I use it, I can use (new Scanner blah) ?

5:50 or rather, what can I do to use it afterwards?

5:50 hoeck: arnfred: yes, or (Scanner. blah), import doesn't complain when tryin to import non-existing classes

5:51 arnfred: hmm, I can't get anything else that errors out of my interpreter right now

5:52 I think the class is imported alright, but I can't seem to use it

5:52 I should probably read up on this somewhere

5:52 thanks a lot for your help though

5:53 hoeck: arnfred: what are you trying?

5:53 arnfred: I'm trying to read in a couple of numbers and add them together and then spit them out

5:54 basic basic stuff ;)

5:54 just to get a feeling for the language

6:00 hoeck: ah, okay, feel free to ask whatever you want to know

6:02 arnfred: thanks, 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

6:09 rottcodd: arnfred: this might help: http://en.wikibooks.org/wiki/Clojure_Programming#Links_to_more_Examples

6:10 hoeck: arnfred: 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&view=markup

6:11 arnfred: thanks a lot, I'll look into it

6:30 Pupeno: Is 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.

6:57 hoeck: Pupeno: try (find-doc "file") for searching docstrings containing "file"

6:57 and (file-seq (java.io.File. "/home"))

8:33 Hun: hi there

8:33 jgracin: hi Hun

9:19 Pupeno: Using Slime, can I compile the whole file?

9:20 Hun: C-c C-k

9:21 (ok, that's compile-and-load... but i think it might be what you want)

9:21 Pupeno: yes, that's what I want.

9:22 I thought it was not working, because it issues an ugly message, but it is.

9:24 Hun: when 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

9:24 Pupeno: Hun: what do you use with Clojure?

9:25 Hun: i experimented a bit in the repl 4 months ago and managed to get slime running today :)

9:25 and took the last 3 hours getting java api documentation to work properly inside emacs

9:26 Pupeno: Java documentation inside emacs? kewl, I want that!

9:26 bbl

9:27 rhickey: Hun: yes please, how (java api in emacs)?

9:27 Hun: try a combination of emacs-w3/w3m (whichever you get to run) and javadoc-help

9:27 you have to download the java documentation for it being fast

9:27 http://surfnet.dl.sourceforge.net/sourceforge/javadochelp/javadoc-help.el

9:28 rhickey: Hun: thanks

11:20 H4nsX: hi. is the debugger supposed to work in enclojure? i've tried setting a breakpoint, but it seems to be ignored.

11:20 oh. there is #enclojure, never mind me

11:24 Hun: hi H4nsX. the world is small :)

11:25 H4nsX: Hun: yes. especially when it comes to people who grok parentheses

11:25 Hun: true

14:06 Pupeno: In the API, I see it says clojure, clojure.xml, etc. Are those namespaces?

14:19 Hun: Pupeno: i think that are java's namespaces. clojure's are divided with /

14:19 drewr: Pupeno: They're Clojure package delimiters.

14:19 clojure/foo => fn foo in clojure ns

14:20 clojure.xml/foo => fn foo in clojure.xml ns

14:20 They're package names. The periods are the delimiters.

14:21 s/package/namespace/g

14:30 Pupeno: is there a pretty-print somewhere?

14:32 Hun: if it's only for debugging, slime's inspector works...

14:32 Pupeno: Hun: mh, I never used it.

14:34 Hun: when you're running slime, hit C-c I after an expression

14:34 you can browse from there on

14:34 scottj: does slime work better if you don't use slime-fancy?

14:34 H4nsX: Hun: you need to assign everything to variables that you want to inspect, right?

14:35 Hun: not necessarily... you can also eval in there

14:35 so (* 5 5) C-c I goes to 25

14:35 H4nsX: Hun: ah, ok.

14:35 Pupeno: "error in process filter: Keyword argument :id not one of (:title :type :content)", except loading, nothing else works for me on Slime.

14:36 Hun: Pupeno: try a current svn version

14:36 it's only in for a few days

14:36 H4nsX: Pupeno: works for me if i follow the directions. current slime, swank-clojure from git

14:36 Hun: i had the same error

14:37 my emacs loaded an older slime version from a previous lispbox installation

14:38 Pupeno: I wonder what is it with Slime that for 5 years or so nothing but the absolutely latest patch from SVN worked.

14:39 Hun: it's rewritten every few months :)

14:39 Pupeno: Hun: I suppose they don't read Joel On Software

14:39 Hun: maybe it's better this way ;)

14:40 Pupeno: Hun: I doubt it.

14:40 Hun: you said SVN, but on Slime I've found a point to cvs, are they still using cvs?

14:41 Hun: yep

14:41 i use `current svn' as `whatever is newest in their vcs of choice'

14:41 Pupeno: Hun: ok.

14:42 Hun: coincidentally, this made some bugs happen for me with stumpwm

14:42 i 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:43 Pupeno: Also, did anyone managed to create an enclojure project?

14:44 H4nsX: i created one, but i can't debug with it, so i'm back to slime

14:52 um. somehow, it seems as if the dot operator does not nest, is that true?

14:53 Pupeno: Hun: 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:55 Hun: H4nsX: there's ..

14:56 H4nsX: Hun: i'll look at that.

14:58 i 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:58 i must admit that i do not yet have a good grasp at how java names are specified in clojure

15:30 Chouser: I can't think of any way in which the . operator doesn't nest.

15:30 What's the problem?

15:44 duck1123: do I still need to set swank-clojure-jar-path?

15:44 I can't get slime to connect

15:44 Pupeno: duck1123: I do set it.

15:44 Hun: how are you trying? i needed it

15:44 duck1123: I'm getting a no class def found

15:46 Pupeno: duck1123: that's likely to be the jar not being found. Why don't you just set it?

15:47 duck1123: I did

15:47 I just can't figure out why it's not finding the jar

15:48 Pupeno: duck1123: are you using ~?

15:48 duck1123: no

15:48 I tried both ways

15:49 (setq swank-clojure-jar-path "/home/duck/clojure/clojure.jar")

15:50 Pupeno: duck1123: are you doing it before (require 'swank-clojure-autoload)?

15:50 duck1123: yes

15:50 but after the clojure mode

15:50 Pupeno: me too.

15:50 Hun: you might have to restart emacs if you got that wrong. swank-clojure.... only reads that var once

15:50 * Pupeno runs out of ideas.

15:55 duck1123: would it matter if I had code to set up sbcl higher in my init script?

15:56 I think I got it by renaming ~/clojure/ to ~/.clojure/

15:56 Pupeno: duck1123: I got rid (commented out) all the sbcl code, I'd try that first.

15:57 I 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:59 duck1123: How well does clojure work in a servlet environment?

16:17 Pupeno: How do I 'add' an item to a map? (that is, get a *new* map with the new key/value pair)

16:17 H4nsX: Chouser: never mind. i am totally confused by the error messages.

16:18 Pupeno: conj does that

16:18 rhickey: also assoc

16:19 Pupeno: which one should I use?

16:19 H4nsX: Pupeno: rhickey is certainly more authoritative :)

16:20 rhickey: if you have separate key and value, then assoc, but of you have key/value pairs from some process, then conj:

16:20 H4nsX: Chouser: |-- java.lang.Exception: Unable to resolve symbol: setDataHandler in this context (cc-test.clj:13)

16:20 Pupeno: H4nsX: yes, but he said 'also' ;)

16:20 rhickey: (assoc m k v) === (conj m [k v])

16:20 Pupeno: rhickey: thanks.

16:21 H4nsX: Chouser: 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:24 Pupeno: Do we have a proffered pastebin?

16:25 H4nsX: http://paste.lisp.org/

16:26 rhickey: lisppaste8: url

16:26 lisppaste8: To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.

16:26 Pupeno pasted "add-or-inc" at http://paste.lisp.org/display/67934

16:27 Pupeno: Is there a better way to write that add-or-inc?

16:27 It adds elements to a map, but the next time increments the counter.

16:30 lisppaste8: rhickey annotated #67934 with "add-or-inc" at http://paste.lisp.org/display/67934#1

16:31 rhickey: leverages the fact that get can take an optional default value if not found

16:32 Pupeno: rhickey: thanks! :)

18:06 Is there a reverse of filter? that is, negating the predicate.

18:07 rhickey: Pupeno: you can just complement the predicate

18:07 Pupeno: rhickey: you mean I can do it without creating an anonymous function?

18:08 rhickey: (complement pred)

18:08 Pupeno: rhickey: oh! excellent :)

18:08 Thanks.

18:08 rhickey: np

18:10 Hun: which i think just creates an anonymous function

18:10 rhickey: yes

18:10 Pupeno: Hun: well, yes... I was just going for legibility, I don't care about one more or less anonymous function ;)

18:11 Hun: in that case it's easy to create a toolset of some functional stuff :)

18:11 like compose, foldl, foldr, unfold, curry, uncurry, and so on (depending on what is missing)

18:15 Pupeno: Hun: 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:15 rhickey: is there any reason why the argument to let is a vector instead of a map?

18:17 Hun: a map would be too crass for those old-school-lispers. we're used to having a list (aka seq) there

18:18 Pupeno: Hun: 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:18 rhickey: Pupeno: let bindings are sequential but map literals are hashed, random order

18:19 Hun: not really. a vector (as a list) is pretty predictable where everything ends up. maps are all over ram

18:19 rhickey: someone suggested parallel let using map literal

18:19 Hun: in no order

18:20 the old let was a straightforward translation of (let ((x 3) (y 5)) ...) to ((lambda (x y) ...) 3 5)

18:20 so you just need 2 maps for implementation

18:20 and get the parallel assignment for free

18:20 rhickey: Hun: Clojure already has compose, reduce and very nice anon fns with #() that allow partial binding of any position(s)

18:21 Pupeno: rhickey: I thought about that. If I do {a b c d}, isn't b always to be evaluated before d?

18:21 Hun: rhickey: oh, cool. then not so much stuff is missing :)

18:21 i really like my unfolds

18:22 rhickey: Pupeno: first the map will be read, then presented to the compiler with random order

18:22 Hun: not random. but hard-to-predict

18:22 rhickey: Hun: right

18:23 Pupeno: rhickey: oh! so there's no guarantee that b is evaluated before d?

18:26 rhickey: Pupeno: the compiler wouldn't be able to tell which you wrote first once the map was read

18:36 Pupeno: Oh, ok, makes sense, I suppose.

18:36 Anyway, time to sleep around here.

18:36 rhickey: Thank you for writing Clojure!

18:52 H4nsX: rhickey: 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:53 rhickey: H4nsX: not yet

18:54 H4nsX: rhickey: high or low on your list? will propably require a different proxy syntax?

18:57 rhickey: H4nsX: not on the radar yet

19:00 H4nsX: rhickey: 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:00 gnuvince_: Is there a function to determine if an element is in a collection?

20:00 Chouser: what kind of collection?

20:03 gnuvince_: Chouser: vectors

20:04 rhickey: (first (filter #{element} v)))

20:05 Chouser: It'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:06 (some #{element} v) works too, linear time.

20:06 gnuvince_: I have 4 elements, so I can live with linear time

20:07 although...

20:07 order doesn't matter in that particular collection (playing card suits)

20:07 So I guess I could be using a set

20:07 Chouser: plus then you can just say (v element) -- faster *and* more succinct.

20:08 gnuvince_: Yeah

20:08 I'm doing my usual "learn a new language with a not-too-trivial problem"

20:09 Chouser: :-)

20:09 gnuvince_: A Cribbage points counter

Logging service provided by n01se.net