2009-06-20
| 00:45 | blbrown_win2_ | if you do a compile, is gen-class really needed? |
| 00:51 | replaca | blbrown_win2_: only if you want to create a named Java class |
| 00:54 | blbrown_win2_ | replaca, what is a named Java class, one that doesn't use some non standard naming convention |
| 00:55 | blbrown_win2_ | http://clojure.org/compilation well I guess it is in the docs |
| 00:57 | replaca | blbrown_win2_: no, any class with methods that can be called from java in the normal way |
| 00:57 | replaca | blbrown_win2_: are you a java guy? |
| 00:57 | hiredman | blbrown_win2_: the classes generated by clojure have some gensym'ed name, so it is hard to new them up, because you need to know the name for new to work |
| 00:57 | blbrown_win2_ | replaca, yea |
| 00:57 | hiredman | with gne-class you can specify a name |
| 00:57 | blbrown_win2_ | sounds like it is not required and like you said, useful for using clojure from java |
| 00:58 | replaca | so if you want to create a class that you could easily use 'v = new MyClass()', b.bar(), etc. then you need gen-class |
| 00:58 | replaca | but usually when you're just writing clojure code, gen-class is not only unnecessary, but bad form |
| 00:59 | replaca | but if you need it, you need it |
| 01:03 | replaca | in other news, I *hate* classpaths! |
| 01:05 | blbrown_win2_ | what is wrong with classpath |
| 01:06 | blbrown_win2_ | seems pretty simple you have a list of jars, you list them |
| 01:07 | replaca | it's just a pain to track everything |
| 01:08 | replaca | plus, what i'm doing doing, i'm building jars while I'm using them so I have to munge it on the fly |
| 01:08 | replaca | compared to python, ruby, .net, etc. it just seems to get in the way more |
| 01:09 | replaca | (though .net has some huge nastiness when you try to get tricky) |
| 01:09 | blbrown_win2_ | I wish you could track which jar a class was loaded from |
| 01:10 | blbrown_win2_ | seem like that would be an issue thing to do, with the jar command, java should inject some kind of filepath signature from where the jar was built or something |
| 01:10 | replaca | it's just one of those things I seem to spend an inordinate amount of time worrying about and I never really think about it in any other language I use |
| 01:10 | replaca | blbrown_win2_: yeah, that would be a nice feature |
| 01:11 | samuels` | hey d00ds |
| 01:11 | blbrown_win2_ | there are a couple of things I like about it. For example, with my application now, I wrote a custom class loader. Where i click on one jar and it (the java code) automatically finds the jars needed. Kind of like maven but working off the filesystem |
| 01:11 | blbrown_win2_ | replaca, people seem to have classpath issues if they use the default global classpath |
| 01:14 | tgevaert | quit |
| 01:15 | tgevaert | heh |
| 01:15 | tgevaert | /quit |
| 01:15 | replaca | blbrown_win2_: yeah, it can be powerful in cases like that, no doubt. I always make a custom one, cause there seems to be no useful default one. But I still seem to spend an unusual amount of time mucking with it. |
| 01:16 | replaca | hey samuels` |
| 01:16 | replaca | welcome |
| 01:17 | blbrown_win2_ | replaca, yea. actually there was one issue where I had a classnotdeferror and for the life of me couldn't figure it out |
| 01:17 | samuels` | replaca: what shall we talk about |
| 01:17 | blbrown_win2_ | wtf is the difference between classnotfound and classnotdef...never did figure that one |
| 01:18 | replaca | samuels`: I don't know. I'm hacking up the new autodoc robot for clojure-contrib |
| 01:18 | replaca | blbrown_win2_: I don't want to figure things like that out either! :-) |
| 01:19 | samuels` | replaca: have you seen "the hangover" ? |
| 01:19 | replaca | samuels`: not yet. heard it was good though |
| 01:20 | replaca | it kind of scares me! |
| 01:20 | samuels` | why? |
| 01:21 | samuels` | out of interest |
| 01:21 | blbrown_win2_ | guess it depends if you are a drinker or not...im a drinker, except for tonight |
| 01:21 | samuels` | where does the 'j' in clojure come from? |
| 01:21 | samuels` | java? |
| 01:21 | replaca | I get a wicked headache just thinking about the premise. A few too many mornings like that |
| 01:21 | samuels` | hehehe |
| 01:21 | replaca | java and a pun on the zh sound in closure |
| 01:21 | samuels` | ah ok |
| 01:22 | samuels` | btw is TCO slated for the jvm any time soon? |
| 01:23 | replaca | samuels`: not too soon it seems. Rumors keep starting, but not substantiated. Rich didn't sound too optimistic in the short-term lasd I heard |
| 01:23 | replaca | *last |
| 01:24 | samuels` | ok thx |
| 01:24 | replaca | don't find it bothers me too much, though, in practice |
| 01:25 | replaca | (not that I wouldn't like to have it) |
| 01:25 | slashus2 | recur works fine |
| 01:26 | replaca | yeah, not a purdy, but that doesn't bother me much |
| 01:26 | replaca | *not as |
| 01:27 | slashus2 | I like explicit. |
| 01:28 | replaca | I get that argument |
| 02:22 | blbrown_win2_ | In the clojure code, what is a call to Var.deref? Is that when you reference a variable not a local variable . E.g. (def abc 1) (println abc) |
| 02:27 | replaca | blbrown_win2_: I don't think I understand the question |
| 02:28 | replaca | Actually, reading more closely, the answer is yes |
| 02:28 | blbrown_win2_ | http://gnuvince.wordpress.com/2009/05/11/clojure-performance-tips/ I was reading this blog and he mentions deref. When is the jvm Var.deref called |
| 02:29 | replaca | ahh, yes. That's when Var.deref is called. |
| 02:29 | blbrown_win2_ | (let [abc 1] (println abc) . is jvm: Var.deref called here |
| 02:30 | replaca | blbrown_win2_: no, abc is not a Var in that case |
| 02:30 | replaca | vars are always created with def or one of its derivitives |
| 02:31 | replaca | and can then be bound with binding |
| 02:31 | blbrown_win2_ | like in the blog, I wonder why there is a penalty for using deref as opposed to local variables |
| 02:35 | replaca | because they are bound thread locally and the language needs to do a lookup through a special per thread structure |
| 02:36 | replaca | my battery just died, which means it's time to crash for me, too! |
| 02:36 | replaca | good night all! |
| 02:51 | blbrown_win2_ | replaca, still there? wanna see something cool |
| 03:01 | blbrown_win2_ | http://spreadsheets.google.com/pub?key=rNB3pttScIyEdLM_kp2rejg&gid=4 |
| 03:16 | cp2 | neat |
| 03:20 | blbrown_win2_ | here is the app I was testing. http://code.google.com/p/lighttexteditor/ code is not idiomatic which is probably why I am seeing issues |
| 09:04 | Chouser | there was talk of writing up a style guide -- that hasn't happened, right? |
| 09:14 | rhickey | Chouser: right |
| 09:22 | StartsWithK | hi |
| 09:22 | StartsWithK | can someone explain what does this http://www.assembla.com/wiki/show/clojure/Getting_Tests_Into_Clojure mean |
| 09:23 | StartsWithK | is clojure including test-is, templates and java-utis in core distribution? |
| 09:24 | rhickey | StartsWithK: we're working out how to get tests into clojure, seeing what would need to move over etc |
| 09:24 | rhickey | trying to avoid template, actually |
| 09:25 | StartsWithK | and test-is? will that make it official clojure testing library? |
| 09:25 | rhickey | StartsWithK: not so much official, just the one Clojure uses to test itself |
| 09:26 | rhickey | will not be called test-is |
| 09:26 | StartsWithK | if so, is it to late to ask that clj-unit could be used in consideration |
| 09:26 | rhickey | StartsWithK: you need to convince people to write their tests with it, test-is is being used by many in contrib |
| 09:27 | StartsWithK | and for java-utils, will it go full, or will thigs like with-system-properties, and as-file as-str be stripped from it |
| 09:27 | StartsWithK | i think that with-system-properties even has a race condition |
| 10:07 | Chouser | StartsWithK: I think it's mostly about getting the clojure tests into the clojure project. Currently the clojure tests use test-is, so it has to come along too. |
| 10:09 | StartsWithK | Chouser: so, test framework dosn't need to be a part of clojure.jar distribution? something like that |
| 10:22 | Chouser | well, if it's included in the clojure repo, it would seem a shame to make it unavailable to users of the jar, don't you think? |
| 10:25 | StartsWithK | in such a situation it will become a official testing framework for clojure, and as such, i don't see it as a good option |
| 10:26 | StartsWithK | official more by convinience than anything else |
| 10:29 | StartsWithK | not saying that is a bad thing that clojure gets one, but it will affect a lot of people, so maybe evaluation of other testing frameworks shoud be done |
| 10:30 | Chouser | I guess my point is it's not a matter of evalutation, it's a matter of the actual clojure tests that have been written |
| 10:30 | Chouser | 160 tests containing 2953 assertions. |
| 10:30 | rhickey | StartsWithK: the tests for clojure are written in test-is, there's nothing to evaluate bout that. This isn't a declaration of merit as much as a recognition of use (not that it doesn't have merit) |
| 10:32 | StartsWithK | rhickey: i get that, but if included in core, and with current lack of infrastructure for package and distribute clojure libraries to other users, using test-is derivative in core will be the first choice for many |
| 10:33 | rhickey | StartsWithK: true |
| 10:33 | StartsWithK | (package and distribuate in automated way) |
| 10:33 | rhickey | but making clojure dependent on some other package has its own problems |
| 10:33 | StartsWithK | that is the catch 22 for both sides |
| 10:34 | rhickey | clojure's lack of deps has served it well, IMO |
| 10:34 | rhickey | StartsWithK: only if you think there is harm to test-is, I don't |
| 10:35 | StartsWithK | rhickey: compared to clj-unit that uses only functions and one macro (for exception handling), test-is has magic symbols (_1 _2) and requires a full tree walker to execute its tests |
| 10:36 | rhickey | StartsWithK: that part of test-is is being reconsidered right now |
| 10:36 | StartsWithK | there was even a talk about 'compatibility' layer so it can be used with some other contrib library |
| 10:36 | Chouser | rhickey: is there any chance Gashinsky's first name has a typo on http://clojure.org/contributing |
| 10:37 | StartsWithK | rhickey: thats good to hear |
| 10:37 | rhickey | Chouser: yup |
| 10:37 | rhickey | will fix |
| 10:38 | Chouser | thanks |
| 10:39 | bpattison | I'm looking for a function that applies a fn to every item in a list -- I know its clojure core somewhere -- any anyone help me out |
| 10:41 | Chouser | bpattison: 'map'? |
| 10:42 | Chouser | ,(map #(* % %) (range 10)) |
| 10:42 | clojurebot | (0 1 4 9 16 25 36 49 64 81) |
| 10:43 | bpattison | I tried that once, but I try it again -- I must have confused myself |
| 10:43 | bpattison | thanks! |
| 10:43 | Chouser | sure! So you haven't given up entirely on clojure yet? |
| 10:44 | bpattison | oh. no. clojure's great! -- I just can't find the time to work on it -- but my little parser project is sputtering along |
| 10:50 | bpattison | any fustration comes from thinking in OO where data comes first, then find the function to work on the data -- so its easy to say find methods that work on strings or files, or whatever -- where in clojure your looking for functions that match a algorithmic pattern -- so 1) its harder to conceptualize and 2) its harder to find functions that already exists because you can't base your searches on "strings", "file", etc. |
| 10:56 | blbrown_win2 | general question. map is call to a sequence and returns a new sequence. What is a function like haskells _Map. Where you iterate over a sequence but DONT return the sequence |
| 10:57 | Chouser | blbrown_win2: for side effects? or what is returned? |
| 11:03 | Chouser | blbrown_win2: anyway, you might want 'doseq' |
| 11:16 | blbrown_win2 | Chouser, I was looking at trying to speed up some code, thought a map variant might help. I have another question. I know we should use (SomeClass. or .someMethod) but with the older form (. someMethod sdfs) is the call to '.' an actually function? |
| 11:17 | blbrown_win2 | I wonder if I should get rid of that call to '.' |
| 11:31 | dreish | blbrown_win2: (.method o) is converted to (. o method) at macro expansion time. |
| 11:31 | dreish | ,(macroexpand '(.method o)) |
| 11:31 | clojurebot | (. o method) |
| 11:32 | bpattison | I have (map str '(a b c)) --> ("a", "b", "c") -- but I want to get it to ("abc") -- any ideas? |
| 11:32 | dreish | apply str |
| 11:32 | bpattison | perfect -- thanks |
| 11:33 | dreish | reduce str if the seq might get long. |
| 12:16 | lenst | why is length an issue? |
| 12:22 | mattrepl | think it has to do with maximum arity of Java methods |
| 12:27 | lenst | ,(apply + (range 1 1000000)) |
| 12:27 | clojurebot | 499999500000 |
| 12:27 | lenst | is there such a limit? |
| 12:28 | mattrepl | thought there was to Methods |
| 12:31 | mattrepl | interesting, looks like I was mistaken |
| 12:31 | lenst | ,(apply (fn [& xs] (if (and (seq xs) (< (first xs) 1000)) (recur (rest xs)) 17)) (iterate inc 0)) |
| 12:31 | clojurebot | 17 |
| 12:32 | mattrepl | looking at AFn, it just converts the extra args to an array |
| 12:35 | lenst | RestFn is also interesting |
| 12:38 | Chouser | dreish: actually, apply str is better regardless of the length of the string. |
| 12:39 | dreish | Why is that? I wasn't watching this window, but my reason was that apply holds the head, and reduce doesn't. |
| 12:39 | Chouser | there's a limit on the number of individual args to a fn, but no limit on the size of the 'rest args' seq |
| 12:40 | dreish | Why is that an advantage for apply? Seems like that would be equivalent. |
| 12:40 | mattrepl | right, which is 21, including the rest seq that gets converted to an array |
| 12:40 | Chouser | dreish: hm, that's an interesting point. |
| 12:41 | mattrepl | was that number arbitrary? |
| 12:41 | Chouser | well, I don't think it's always convert to an array |
| 12:42 | mattrepl | well it's defined using varargs (i.e., type is Object...) |
| 12:44 | lenst | look at RestFn not AFn |
| 12:45 | lenst | ,(parents (class (fn [& xs]))) |
| 12:45 | clojurebot | #{clojure.lang.RestFn} |
| 12:47 | Chouser | ,(parents (class (fn [x]))) |
| 12:47 | clojurebot | #{clojure.lang.AFunction} |
| 12:49 | rhickey | chunked range rocks! |
| 12:50 | mattrepl | so for RestFn, the last argument could be the rest of the seq, not necessarily an array, but eventually it's converted to an array when IFn#invoke is called |
| 12:51 | dreish | rhickey: Is it in the master branch? |
| 12:51 | rhickey | dreish: not yet |
| 12:51 | rhickey | will push to chunks branch in a seq |
| 12:51 | lenst | mattrepl: don't think so, last arg will be the rest sequence. See applyTo method in RestFn |
| 12:54 | Chouser | heh. in a "sec"? |
| 12:55 | Chouser | the rest arg can be infinite. |
| 12:55 | mattrepl | lenst: that calls doInvoke, which I would imagine calls IFn#invoke, but I suppose it doesn't have to |
| 12:55 | dmos | ah, just checking, what is the current state of maven2 for building clojure? The pom at http://github.com/richhickey/clojure seems to be not functional (including the generated version), and also differs slightly from the last committed on trunk in svn... |
| 12:57 | lenst | mattrepl: that would be bad because RestFn.invoke calls doInvoke |
| 12:57 | Chouser | ,(take 20 (apply (fn [& xs] (filter even? xs)) (iterate inc 0))) |
| 12:57 | clojurebot | (0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38) |
| 12:57 | Chouser | so that's a fn that just took an infinite number of args and returned a lazy seq. |
| 12:57 | Chouser | returned an infinite lazy seq. |
| 12:57 | dreish | Impossible! Magic! |
| 12:58 | Chouser | I know, fantastic, isn't it? |
| 12:58 | cp2 | this _must_ be the work of the devil |
| 12:58 | dreish | (apply + (range 1000000)) is usually one of the first things I show people. |
| 12:59 | Chouser | rhickey: are you actively seeking help on the checked seq fns? |
| 12:59 | dreish | They think it's going to crash the repl, and it comes back with the answer in a fraction of a second. |
| 12:59 | Chouser | iterate could be chunked, I would think. |
| 13:00 | mattrepl | great, now I'm going to have to examine bytecode to be satisfied... =) |
| 13:04 | rhickey | Chouser: I am now, just wanted to do the basics - map/reduce/filter/range myself to sanity check the ideas. all pushed to chunks branch now |
| 13:06 | rhickey | everyone please try the chunks branch when you have time on your own code - I want to make sure the chunked versions are fully compatible with existing code - so far I haven't touched any client code, just swapped out chunked versions under the hood - quite thrilling |
| 13:07 | dnolen | dmos: some people are it seems. |
| 13:08 | dmos | Mmh, but clojure itself is not buildable with maven, is it? |
| 13:10 | quidnunc | Anybody have an example of using zip-select in enlive? |
| 13:29 | jtal | is there a way to walk through a large file without a loop? |
| 13:30 | drewr | jtal: map/filter over line-seq? Depends on what kind of data is in there. |
| 13:30 | jtal | just plain text but very large |
| 13:31 | jtal | will map use the same piece of memory for each iteration? |
| 13:32 | jtal | that is, for each line |
| 13:32 | dreish | Why would that matter? |
| 13:32 | drewr | jtal: It won't retain the head of the seq, if that's what you mean. |
| 13:32 | jtal | memory used wont grow right? |
| 13:32 | drewr | Right. |
| 13:33 | jtal | and the whole file doesnt have to go into memory initally? |
| 13:33 | dreish | jtal: The GC will clean up as you progress through the file. |
| 13:33 | jtal | awesome |
| 13:34 | jtal | I'm using java.io.BufferedReader btw just in case thats not the cool thing to use :> |
| 13:34 | clojurebot | ☕ |
| 13:34 | jtal | <-- new to java and clojure |
| 13:34 | Chouser | jtal: sounds right |
| 13:34 | dreish | Isn't there something like (line-seq (reader filename))? |
| 13:35 | jtal | ah you're right |
| 13:35 | Chouser | there's clojure.contrib.duck-streams/reader |
| 13:35 | dreish | Thanks I just shut down my emacs in preparation for a reboot, or I'd have checked. |
| 13:36 | dreish | I wrote an auto-closing line-seq, but I can't remember where I put it. |
| 13:37 | dreish | I think it's at the office. |
| 13:38 | Chouser | duck-stream/read-lines does that |
| 13:38 | jtal | are you guys using lojure at work? |
| 13:38 | jtal | c |
| 13:38 | dreish | I have, a little. |
| 13:39 | quidnunc | ,seen cgrand |
| 13:39 | clojurebot | java.lang.Exception: Unable to resolve symbol: seen in this context |
| 13:40 | quidnunc | ,last cgrand |
| 13:40 | clojurebot | #<core$last__3771 clojure.core$last__3771@1509f8b> |
| 13:40 | dreish | clojurebot: seen cgrand |
| 13:40 | clojurebot | cgrand was last seen quiting IRC, 226 minutes ago |
| 13:40 | Chouser | ~seen cgrand |
| 13:40 | clojurebot | cgrand was last seen quiting IRC, 227 minutes ago |
| 16:50 | slashus2 | I was playing with the new chunked seqs branch. I was excited to test the performance of it, but it seems something like (reduce + (range 1000000)) is a lot slower. |
| 17:09 | slashus2 | I think it is range that has slowed down on the sequence generation. |
| 17:20 | slashus2 | I guess there is a lot more going on inside of range now. |
| 18:30 | blbrown_win2 | gnuvince_, hey, I liked your clojure performance article |
| 18:30 | blbrown_win2 | Ive been using it all weekend diagnosis problems |
| 18:31 | gnuvince_ | blbrown_win2: thanks; just some things I found out and decided to write. |
| 18:37 | Jetien | Hi can somebody tell me the difference between the two calls "java -cp #jars clojure.lang.Script #script" and "java -cp #jars clojure.lang.Script #script --"? The first one doesn't one doesn't show JFrame calls, but the second does. |
| 18:38 | hiredman | -- tells java to stop expecting arguments? |
| 18:39 | hiredman | I am not sure if that is correct though |
| 18:39 | hiredman | also, use clojure.main instead of clojure.lang.Script |
| 18:39 | Jetien | yes, but since there are no arguments after -- what difference does it make? |
| 18:40 | Jetien | ok |
| 18:41 | hiredman | what is the context? |
| 18:41 | Jetien | I'm trying to run http://java.ociweb.com/mark/programming/ClojureSnake.html and one call succeeds and the other doesn't |
| 18:42 | hiredman | so you are using a shell script launcher thing? |
| 18:42 | Jetien | yes |
| 18:42 | hiredman | well, pastbin that |
| 18:42 | hiredman | lisppaste8: url? |
| 18:42 | lisppaste8 | To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste. |
| 18:43 | hiredman | as far as I know there is no official shell script launcher |
| 18:43 | lisppaste8 | Jetien pasted "clj script" at http://paste.lisp.org/display/82197 |
| 18:44 | hiredman | ah, well, there you go $* |
| 18:44 | Jetien | ok, i need to clarify |
| 18:44 | Jetien | i was entering the commands manually in the console without the $* |
| 18:44 | hiredman | oh |
| 18:45 | hiredman | ick |
| 18:45 | Jetien | the reason i'm trying to find out why the version with "--" works and the other doesn't is this: |
| 18:45 | hiredman | scriptname=$1 then $* is a bad idea |
| 18:45 | hiredman | Jetien: "doesn't" means you get some kind of exception, or what? |
| 18:46 | Jetien | no it just runs silently |
| 18:46 | Jetien | no swing gui is opened at all |
| 18:46 | hiredman | uh |
| 18:46 | Jetien | im using vimclojure and there's the same problem, that's why i'm trying to figure this out |
| 18:47 | hiredman | vimclojure is odd, I would not trust it to indicate a problem |
| 18:47 | hiredman | as in, any issues you have while using vimcloure are just as likely to be vimclojure's as they are something else's |
| 18:48 | Jetien | but the behaviour is the very same |
| 18:48 | Jetien | i call (com.ociweb.snake/main) - no errors, but silent |
| 18:48 | hiredman | 2 + 3 = 5 and so does 1 + 4 |
| 18:49 | hiredman | (if *command-line-args* (main)) |
| 18:49 | Jetien | yes i admit you're right but it's a possibility |
| 18:49 | hiredman | at the bottom of the snake code |
| 18:49 | Jetien | yes, that's why i start main manually |
| 18:49 | arbscht | *command-line-args* is (--) when you pass -- |
| 18:50 | hiredman | Jetien: ok, so, to start clojure, what exactly are you typing? |
| 18:51 | Jetien | um..that's strange...it's working now - not in vimclojure though |
| 18:52 | Jetien | i guess it was the *command-line-args* guard after all |
| 18:52 | Jetien | but this still doesn't explain why it's not working in the repl of vimclojure |
| 20:30 | krumholt_ | what is the equivalent to funcall in clojure? |
| 20:31 | slashus2 | I don't think you need it. |
| 20:31 | Raynes | What is funcall? >_> |
| 20:32 | krumholt_ | (def a (fn [] (+ 3 4)) now i want to call the function in a |
| 20:32 | Anniepoo | (a) |
| 20:32 | Anniepoo | ?? |
| 20:32 | Raynes | ^ |
| 20:33 | krumholt_ | yes (a). ok another example. (defn foo () "bar") (def a 'foo) |
| 20:34 | Raynes | I think you mean (defn foo [] "bar")? |
| 20:34 | krumholt_ | yes |
| 20:34 | krumholt_ | sry |
| 20:34 | slashus2 | Why did you quote the foo before you assigned it to a? |
| 20:35 | Raynes | (def a (foo)) |
| 20:35 | slashus2 | Raynes: I think he wants to assign foo to a, not the result of it. |
| 20:35 | Chouser | or (def a foo) depending on what you mean |
| 20:35 | cemerick | krumholt_: there is no funcall -- there's apply. Clojure is a lisp-1. |
| 20:35 | krumholt_ | ok i got it thanks |
| 20:35 | krumholt_ | so i cannot assign a value and a function to a symbol |
| 20:36 | Chouser | well, you can't assign to a "symbol" anyway, but what you mean is correct |
| 20:36 | krumholt_ | yes bind |
| 20:36 | krumholt_ | ok thanks |
| 20:36 | Chouser | there are not separate namespaces for values vs. functions. |
| 20:36 | bpattison | (defmulti concat_fruit :kind) |
| 20:36 | bpattison | (defmethod concat_fruit :apple [a b] (str a b "apple")) |
| 20:36 | bpattison | (defmethod concat_fruit :oragne [a b] (str a b "orange")) |
| 20:36 | bpattison | (concat_fruit {:kind :apple} "b") |
| 20:36 | bpattison | "{:kind :apple}bapple" |
| 20:36 | bpattison | (defmethod concat_fruit :lemon [a b c] (str a b c "lemon")) |
| 20:36 | bpattison | (concat_fruit {:kind :lemon} "b" "c") |
| 20:36 | bpattison | java.lang.IllegalArgumentException: Wrong number of args passed to keyword: :kind (NO_SOURCE_FILE:0) |
| 20:36 | bpattison | Can anyone tell me why or how to work around multi-methods not accepting 3 arguments? |
| 20:37 | krumholt_ | Chouser, ok thanks. i was used to that from cl and got confused. |
| 20:37 | krumholt_ | thanks everyone |
| 20:37 | Chouser | bpattison: the problem is that your dispatch "function" :kind doesn't take 3 args. |
| 20:38 | Chouser | bpattison: you want to dispatch on the :kind of the first arg? |
| 20:38 | bpattison | that's correct -- the first arg |
| 20:38 | Chouser | krumholt_: I was meant to be pedantic about your use of "symbol" not your use of "assign" |
| 20:38 | bpattison | so I need to define a dispatch function that takes 3 args? |
| 20:39 | Chouser | krumholt_: symbols in clojure do not hold values (or functions) |
| 20:39 | Chouser | bpattison: yes. probably something like (defmulti concat_fruit (fn [a & args] (:kind a))) |
| 20:39 | Chouser | bpattison: and next time please use paste |
| 20:40 | Chouser | lisppaste8: url? |
| 20:40 | lisppaste8 | To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste. |
| 20:40 | Anniepoo | can somebody explain 'state' as it's used in http://clojure.org/state |
| 20:41 | Chouser | krumholt_: I'm not sure exactly how CL works, but in Clojure a literal symbol in your code may refer to a local or to a Var. Those are what are bound to values. |
| 20:41 | bpattison | I will try |
| 20:42 | bpattison | chouser -- that worked like a champ -- so how did it know how to handle 2 args? |
| 20:43 | Chouser | the "& args" part means take any number of remaining args and put them in a seq bound to "args" |
| 20:43 | krumholt_ | Chouser, hm not exactly sure i get it. i will experiment a little more |
| 20:43 | clojurebot | Who?? |
| 20:44 | Chouser | krumholt_: it's a pretty subtle point. it may not matter to you. |
| 20:44 | Chouser | Anniepoo: "state" is any variable or object data member that hangs around getting its value changed from time to time |
| 20:44 | Chouser | A |
| 20:45 | krumholt_ | Chouser, i think i get it the symbol binds to a var. i can get the the var with #'foo |
| 20:45 | Anniepoo | ok |
| 20:45 | Anniepoo | how is that not an identity? |
| 20:45 | Chouser | Anniepoo: for example the session values for a web app would be one kind of state |
| 20:45 | Anniepoo | ok |
| 20:45 | Anniepoo | yes, I was thinking of the entries in an LDAP |
| 20:46 | Anniepoo | as identities. |
| 20:46 | cemerick | krumholt_: I've long since forgotten the finer points of CL, but clojure's model is definitely simpler around symbols, etc. It'll click for you. Internalizing this is critical: http://clojure.org/vars |
| 20:46 | krumholt_ | cemerick, thanks |
| 20:47 | Anniepoo | identity "the port we're listening on" - which is buried, assuming we're an app level programmer, in some library after we open the serversocket |
| 20:48 | Anniepoo | so the :state entry in a :gen-class is a symbol bound to something that hangs around? |
| 20:48 | Anniepoo | on a per object level? |
| 20:48 | Chouser | Anniepoo: yes |
| 20:48 | Anniepoo | thanks., I get that |
| 20:48 | Chouser | but clojure is careful to make sure these identities control how their state changes |
| 20:49 | Anniepoo | now I'm confused what the exact syntax of :state is in :gen-class |
| 20:49 | Chouser | the simplest being an atom -- it only ever has one value. The only ways to change it require that they happen in order |
| 20:50 | Anniepoo | right. Hence the odd constructs like let |
| 20:50 | Chouser | this is how it's different from java, for example, where you could have a static class member foo with data members bar and baz. Threads go read, write, and generally mess around with bar and baz uncontrolled. |
| 20:51 | Anniepoo | right |
| 20:51 | Chouser | so you have a question about gen-class syntax? |
| 20:51 | Anniepoo | well, as I understand it in Clojure you can't mess around with bar and baz if they're not static either??? |
| 20:52 | Chouser | well, if they're actually java data members, you can still do what you want :-P |
| 20:52 | Anniepoo | yah, suppose I have a simple case - I want to subclass some java class and attach some data to it |
| 20:53 | Chouser | but you wouldn't do that. you would make bar and baz be, say, refs: (def foo {:bar (ref 0), :baz (ref 0)}) |
| 20:53 | Anniepoo | I want to make a JButton, when you click it it changes from whatever's in the text to "HI" |
| 20:53 | Anniepoo | and when you click again it changes back - so I need to keep the old value |
| 20:54 | Chouser | a jbutton has a hold wad of state inside it. |
| 20:54 | quidnunc | cgrand: Is the definition of text-node correct? zip-pred tests z/branch? but that will be false for a string node I think. |
| 20:54 | Anniepoo | sure, of course |
| 20:55 | Chouser | Anniepoo: but yes, it would be sensible to try to ignore that and store your old value in a nice clean clojure reference object. |
| 20:55 | Anniepoo | yes |
| 20:57 | Anniepoo | yah, my real example is too complex to ask about, so I'm making up an example |
| 20:57 | Chouser | :-) |
| 20:57 | Anniepoo | but just trying to understand how I glue some extra data to a java object when subclassing |
| 20:58 | Anniepoo | in effect getting a member variable |
| 20:58 | Chouser | ah, yes. |
| 20:58 | Chouser | do you need to add methods, or is proxy sufficient? |
| 20:59 | Anniepoo | I need to store additional state |
| 20:59 | Anniepoo | I'm making a clojure editor, the 'button' is a panel that maps to a clojure form, I need to attach it to the model |
| 20:59 | Chouser | yes, but you can do that via closures with proxy. |
| 21:00 | Chouser | I mean, a proxy can close over additional state. |
| 21:00 | Anniepoo | ?? |
| 21:02 | Chouser | (def obj (let [v (atom 0)] (proxy [Object] [] (toString [] (str (swap! v inc)))))) |
| 21:03 | Chouser | that creates a proxy that closes over v, and stores the proxy object in obj |
| 21:03 | samuels | Chouser: dont you think that let should just be replaced by let* (and called simply 'let') so that it's easier for noobs |
| 21:04 | Chouser | now each time you call (.toString obj) or just print it at the repl, it'll inc v and return a string with the new value of that state |
| 21:04 | Chouser | samuels: already is. |
| 21:04 | samuels | really? |
| 21:04 | samuels | ah ok, i just remember seeing a let* in the 'programming clojure' book |
| 21:04 | Anniepoo | far out! |
| 21:07 | Anniepoo | that's why the (atom 0) |
| 21:08 | Anniepoo | this language will either save my soul or damn me to heck |
| 21:08 | Anniepoo | darn me to heck? |
| 21:11 | Anniepoo | thanks!- I'll go stick head back in clojure book |
| 21:13 | Chouser | Anniepoo: right. without atom you could still close over a value, but you couldn't change it. |
| 21:17 | Anniepoo | I keep wanting my OOP. |
| 21:17 | Chouser | Anniepoo: you'll get over it. :-) |
| 21:19 | Chouser | well, I'm still working to get there. the more stateful the task at hand, the harder I'm pulled toward OO concepts. |
| 21:19 | Anniepoo | I feel like I'm a novice in a religious order... yes teacher, I will get used to sleeping on the floor and eating only a handful of rice each day |
| 21:20 | Anniepoo | isn't it appropriate to have OO concepts some times? |
| 21:20 | Anniepoo | suppose you're doing something that would be well handled in an OOP language |
| 21:21 | Anniepoo | a game with pieces with varying capabilities perhaps |
| 21:21 | Chouser | yes |
| 21:21 | Chouser | have you looked at multimethods? |
| 21:22 | Anniepoo | I've been programming since before OOP came along, so it's not totally foreign |
| 21:22 | Anniepoo | don't multimethods end up distributing the code that handles a class all over? |
| 21:22 | Anniepoo | I mean, I remember structured programmers resistant to OOP who would put case statements everywhere |
| 21:23 | Chouser | you can distribute the code however you want -- group the methods by dispatch object or by method, your choice. |
| 21:24 | Anniepoo | ah, cool, I didn't know that |
| 21:24 | krumholt_ | can i change a var in a let form? i want to do (let [a 1] (???set??? a 2)(print a)) |
| 21:26 | Chouser | krumholt_: vars generally should only be changed within a thread-local binding. Is that what you want? |
| 21:26 | krumholt_ | yes |
| 21:26 | Chouser | oh, wait. |
| 21:26 | Chouser | that's not a var |
| 21:26 | slashus2 | You can't do that with a local. |
| 21:27 | Chouser | what slashus2 said. |
| 21:27 | slashus2 | You can create an atom or a ref and change them sort of. |
| 21:27 | Chouser | krumholt_: you can do (let [a 1, a 2] (print a)) |
| 21:27 | slashus2 | (let [a (atom 1)] (reset! a 2)) |
| 21:28 | krumholt_ | slashus2, that seems to be what i want |
| 21:28 | Chouser | krumholt_: we probably need to know more about what you're really trying to do. |
| 21:28 | Anniepoo | (let [a (atom 1)] (swap! a 2) (print a)) Is that what he's trying to do? Or am I bogus? |
| 21:29 | krumholt_ | something like: (let [counter 0] (defn inccount [] (incf counter)) (defn show [] counter)) |
| 21:29 | Chouser | it's rarely necessary or idiomatic to use an atom or other reference type within a purely local scope. |
| 21:30 | Anniepoo | (let [a 1] (let [b (inc a)] (print b))) is that the idiomatic way? |
| 21:31 | Chouser | Anniepoo: sure, that's better than using atom. |
| 21:31 | Anniepoo | (let [a 1] ...bunch of stuff...(let [b (inc a)] ... bunch more stuff... (print b))) |
| 21:35 | krumholt_ | ok thanks. it is not exactly what i want, but than again i shouldn't be doing that anyway. i am just trying to get a feeling of what i can and cant do with clojure |
| 21:46 | Anniepoo | (let [a (atom 1)] (swap! a 2) (print @a)) did I need this? |
| 21:46 | Anniepoo | (@ sign) |
| 21:47 | gnuvince_ | Anniepoo: @x is syntax for (deref x) |
| 21:47 | Anniepoo | yes |
| 21:48 | Anniepoo | but I have to deref here? |
| 21:48 | gnuvince_ | so x is the ref and @x is the actual value, so you need the @a depending on what you want to display |
| 21:48 | slashus2 | For atoms and refs, yes. |
| 22:12 | Anniepoo | is there a way to ifdef out code in Clojure? |
| 22:13 | Anniepoo | I'm in the frustrating noobie situation that I changed a working program and broke it, now I can't get back to where I was |
| 22:13 | duck1123 | there's if |
| 22:13 | Anniepoo | kk |
| 22:13 | duck1123 | what exactly are you wanting to do? |
| 22:16 | Chouser | you can "comment out" a s-expr using #_ |
| 22:16 | Anniepoo | thanks |
| 22:16 | Chouser | ,(+ 4 #_ (garbage i don't want) 5) |
| 22:16 | clojurebot | 9 |
| 22:17 | duck1123 | Chouser: I didn't know about that one. does that remove it completely, or return nil |
| 22:18 | duck1123 | I've run into issues with (comment) changing my return value |
| 22:19 | duck1123 | ,(do 1 #_ (+ 1 1)) |
| 22:19 | clojurebot | 1 |
| 22:21 | Chouser | duck1123: right, removes it at read time. Does not insert (or return) nil. |
| 22:21 | slashus2 | #| |# will come later? |
| 22:22 | Chouser | what is that? block comment? |
| 22:22 | slashus2 | That removes it at read time. |
| 22:23 | Chouser | dunno. |
| 22:23 | Chouser | should it nest? |
| 22:24 | duck1123 | I still say that XQuery has the friendliest commenting system |
| 22:24 | duck1123 | (: this is a comment :) |
| 22:24 | arbscht | ha |
| 22:26 | Anniepoo | strange. I've got a window that was working fine. I messed with the stuff I asked about earlier, tried runnign it, and the window gets no repaint event |
| 22:26 | Anniepoo | breaking in with the debugger always stops with, of all things, somewhere in file input operations |
| 22:28 | slashus2 | Anniepoo paste it in http://paste.lisp.org/ |
| 22:28 | Anniepoo | kk |
| 22:29 | Anniepoo | lisppaste8: /url? |
| 22:29 | lisppaste8 | To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste. |
| 22:30 | lisppaste8 | Anniepoo pasted "wont redraw" at http://paste.lisp.org/display/82208 |
| 22:30 | Anniepoo | sorry to ask for help with what should be a simple case of going back to what I had before |
| 22:33 | duck1123 | odd that you're not using the ns macro |
| 22:34 | Anniepoo | I'm a total noob |
| 22:34 | Anniepoo | I'm lucky I haven't shot myself with this thing yet |
| 22:34 | Chouser | what's the problem? |
| 22:34 | Chouser | I get a window with 2 sets of 3 labels |
| 22:35 | Anniepoo | mouse over it |
| 22:35 | Anniepoo | sometimes it redraws, sometimes not |
| 22:35 | Anniepoo | sometimes it comes up, draws the frame, never draws the content area |
| 22:36 | Anniepoo | swing threading weirdness? |
| 22:36 | Anniepoo | hard to believe - It worked consistently before |
| 22:36 | Chouser | maybe need to flush stdout? |
| 22:36 | Anniepoo | I've noticed that print doesn't give me output, just println |
| 22:37 | Anniepoo | wonder why it started this |
| 22:37 | Chouser | print doesn't flush the output |
| 22:37 | Chouser | dunno why you wouldn't have had that problem before. |
| 22:38 | Anniepoo | because every mouse action must end with an up and that's println |
| 22:38 | Chouser | if I sprinkle in (flush) after every (print ...) I seem to get good output |
| 22:38 | Anniepoo | kk |
| 22:41 | Anniepoo | strange |
| 22:41 | Anniepoo | I did that, didn't help |
| 22:41 | Anniepoo | lisppaste8: url? |
| 22:41 | lisppaste8 | To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste. |
| 22:42 | lisppaste8 | Anniepoo annotated #82208 "untitled" at http://paste.lisp.org/display/82208#1 |
| 22:42 | Anniepoo | ok, there's my version |
| 22:42 | Anniepoo | I tried restarting my ide |
| 22:43 | Chouser | I guess I'm not quite sure what you're wanting. |
| 22:43 | Anniepoo | I'd like the window to repaint and not hang |
| 22:43 | Anniepoo | it's not reliably repainting on my system |
| 22:44 | lisppaste8 | Chouser annotated #82208 "my flushes" at http://paste.lisp.org/display/82208#2 |
| 22:44 | Chouser | I don't know what you mean by "repaint" you're expecting the boxes to draw differently somehow? |
| 22:45 | Anniepoo | I'm expecting them to draw |
| 22:45 | Anniepoo | I see the corner of my IDE inside, on about 50% of the runs |
| 22:46 | Anniepoo | on the other 50% I get the initial draw |
| 22:46 | Anniepoo | but then when I move the mouse over the windo it gives me a wait cursor |
| 22:46 | Chouser | I can resize and move around the window and it still looks good. |
| 22:46 | Anniepoo | and nothing else happens |
| 22:46 | Anniepoo | !!!! |
| 22:47 | Anniepoo | can you move your mouse over the windo? It should print some commas and [] |
| 22:47 | Anniepoo | I never get that output |
| 22:47 | Chouser | yes, I get commas and [] |
| 22:48 | Chouser | and dots |
| 22:48 | Chouser | Anniepoo: what's your ide? |
| 22:48 | Anniepoo | IntelliJ |
| 22:48 | Anniepoo | yah, it's working for you |
| 22:48 | Anniepoo | hmm... I think I installed the old CloJet at one point and borked my install somehow |
| 22:49 | Anniepoo | I get an ide error complaining that it's already got a language called Clojure |
| 22:49 | Anniepoo | but the odd part is, I didn't mess with the IDE at all |
| 22:49 | Anniepoo | I was working fine |
| 22:49 | Anniepoo | asked you the question earlier |
| 22:49 | Anniepoo | about how to keep state |
| 22:50 | Anniepoo | added a toy demo of it and tried to run, It did this |
| 22:50 | Chouser | java -cp clojure.jar:clojure-contrib.jar clojure.main -i yourcode.clj |
| 22:50 | Chouser | that's how I'm running it. |
| 22:50 | Anniepoo | let me try it from the cmd line |
| 23:00 | lisppaste8 | Anniepoo annotated #82208 "untitled" at http://paste.lisp.org/display/82208#3 |
| 23:00 | Anniepoo | yah, I always get this when I start intellij |
| 23:02 | Anniepoo | ok, I'm going to do a hard reboot |
| 23:18 | Anniepoo | ok, that's maximally strange |
| 23:18 | Anniepoo | I rebooted the machine and that fixed it |
| 23:22 | Chouser | wow |
| 23:22 | Chouser | yummy |
| 23:24 | Anniepoo | there's a race condition between two plugins apparently |
| 23:25 | Chouser | nice |
| 23:25 | Chouser | well, glad you found a way forward. Sorry it was a random bug absorbing your time :-/ |
| 23:25 | Anniepoo | what's the status of clo-jet? |
| 23:25 | Chouser | I'm off to bed. |
| 23:26 | Anniepoo | yah, sorry to take your time with this noob stuff |
| 23:26 | Anniepoo | I appreciate it |