2008-10-04
| 01:11 | avida | /whois qmrw |
| 04: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 ;) |
| 04:10 | Pupeno | Good morning. |
| 05: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 |
| 05:42 | arnfred | when I'm writing: (import '(java.util.scanner)) |
| 05:42 | arnfred | it seems ok |
| 05:42 | arnfred | but then when I'm trying to do: (new Scanner blah), it comes up with an error |
| 05:43 | arnfred | Can anybody tell me what I'm doing wrong? |
| 05:48 | hoeck | hi arnfred: its (import '(java.util Scanner)) |
| 05:49 | arnfred | okay, and then when I use it, I can use (new Scanner blah) ? |
| 05:50 | arnfred | or rather, what can I do to use it afterwards? |
| 05:50 | hoeck | arnfred: yes, or (Scanner. blah), import doesn't complain when tryin to import non-existing classes |
| 05:51 | arnfred | hmm, I can't get anything else that errors out of my interpreter right now |
| 05:52 | arnfred | I think the class is imported alright, but I can't seem to use it |
| 05:52 | arnfred | I should probably read up on this somewhere |
| 05:52 | arnfred | thanks a lot for your help though |
| 05:53 | hoeck | arnfred: what are you trying? |
| 05:53 | arnfred | I'm trying to read in a couple of numbers and add them together and then spit them out |
| 05:54 | arnfred | basic basic stuff ;) |
| 05:54 | arnfred | just to get a feeling for the language |
| 06:00 | hoeck | ah, okay, feel free to ask whatever you want to know |
| 06: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 |
| 06:09 | rottcodd | arnfred: this might help: http://en.wikibooks.org/wiki/Clojure_Programming#Links_to_more_Examples |
| 06: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 |
| 06:11 | arnfred | thanks a lot, I'll look into it |
| 06: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. |
| 06:57 | hoeck | Pupeno: try (find-doc "file") for searching docstrings containing "file" |
| 06:57 | hoeck | and (file-seq (java.io.File. "/home")) |
| 08:33 | Hun | hi there |
| 08:33 | jgracin | hi Hun |
| 09:19 | Pupeno | Using Slime, can I compile the whole file? |
| 09:20 | Hun | C-c C-k |
| 09:21 | Hun | (ok, that's compile-and-load... but i think it might be what you want) |
| 09:21 | Pupeno | yes, that's what I want. |
| 09:22 | Pupeno | I thought it was not working, because it issues an ugly message, but it is. |
| 09: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 |
| 09:24 | Pupeno | Hun: what do you use with Clojure? |
| 09:25 | Hun | i experimented a bit in the repl 4 months ago and managed to get slime running today :) |
| 09:25 | Hun | and took the last 3 hours getting java api documentation to work properly inside emacs |
| 09:26 | Pupeno | Java documentation inside emacs? kewl, I want that! |
| 09:26 | Pupeno | bbl |
| 09:27 | rhickey | Hun: yes please, how (java api in emacs)? |
| 09:27 | Hun | try a combination of emacs-w3/w3m (whichever you get to run) and javadoc-help |
| 09:27 | Hun | you have to download the java documentation for it being fast |
| 09:27 | Hun | http://surfnet.dl.sourceforge.net/sourceforge/javadochelp/javadoc-help.el |
| 09: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 | H4nsX | 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 | drewr | clojure/foo => fn foo in clojure ns |
| 14:20 | drewr | clojure.xml/foo => fn foo in clojure.xml ns |
| 14:20 | drewr | They're package names. The periods are the delimiters. |
| 14:21 | drewr | 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 | Hun | 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 | Hun | 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 | Hun | 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 | Hun | 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 | Pupeno | 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 | Hun | 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 | Hun | 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 | H4nsX | 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 | H4nsX | 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 | H4nsX | 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 | Chouser | What's the problem? |
| 15:44 | duck1123 | do I still need to set swank-clojure-jar-path? |
| 15:44 | duck1123 | 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 | duck1123 | 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 | duck1123 | I tried both ways |
| 15:49 | duck1123 | (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 | duck1123 | 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:55 | duck1123 | would it matter if I had code to set up sbcl higher in my init script? |
| 15:56 | duck1123 | 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 | Pupeno | 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 | H4nsX | 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 | lisppaste8 | 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 | Pupeno | 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 | Pupeno | 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 | Pupeno | 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 | Hun | 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 | Pupeno | 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 | Hun | the old let was a straightforward translation of (let ((x 3) (y 5)) ...) to ((lambda (x y) ...) 3 5) |
| 18:20 | Hun | so you just need 2 maps for implementation |
| 18:20 | Hun | 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 | Hun | 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 | Pupeno | Anyway, time to sleep around here. |
| 18:36 | Pupeno | 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 | Chouser | (some #{element} v) works too, linear time. |
| 20:06 | gnuvince_ | I have 4 elements, so I can live with linear time |
| 20:07 | gnuvince_ | although... |
| 20:07 | gnuvince_ | order doesn't matter in that particular collection (playing card suits) |
| 20:07 | gnuvince_ | 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 | gnuvince_ | 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 |