2008-04-08
| 13:23 | drewr | I love that lisps handle rational numbers correctly, but is this the only option when you want a float? |
| 13:23 | drewr | user> (/ 3 2) |
| 13:23 | drewr | 3/2 |
| 13:23 | drewr | user> (* (/ 3 2) 1.0) |
| 13:23 | drewr | 1.5 |
| 13:24 | Chouser | (float (/ 3 2)) |
| 13:24 | drewr | Chouser: You'd think searching the api page I would have found that. :-) |
| 13:24 | Chouser | :-) |
| 13:26 | Chouser | I don't know if there's a way to from float to ratio, though. |
| 13:26 | drewr | Does it bother anyone else that the docstring comes before the parameters in a function def? |
| 13:27 | Chouser | there can be multiple parameter sets. |
| 13:27 | Chouser | In which case any other placement of the docsstring get a bit awkward. |
| 13:28 | drewr | OK, multiple arity. |
| 13:28 | Chouser | yessir |
| 13:28 | drewr | Well, I guess it's a good tradeoff then. |
| 13:30 | Chouser | I think that's the rationale, anyway. |
| 13:30 | drewr | That's reverse of every Python, elisp, CL, probably others. Trying to get used to it. |
| 13:31 | Chouser | well, it's a odd syntax for multiple arity too, but I find I like the convenience. |
| 13:31 | drewr | From the code I've read so far, I agree. |
| 13:31 | Chouser | It's quite nice for setting up default params. |
| 14:42 | Chouser | (/ (long (* 1.5 1000)) 1000) |
| 15:10 | drewr | Chouser: Nice :-) |
| 15:11 | rhickey | drewr: what's nice? |
| 15:11 | Chouser | (/ (long (* 1.5 1000)) 1000) |
| 15:11 | Chouser | for converting a float to a ratio |
| 15:11 | Chouser | I think he was being fascetious. |
| 15:11 | drewr | ;-) |
| 15:13 | rhickey | hmm... yes, CL's rationalize |
| 15:14 | Chouser | BTW, I'm enjoying the reader syntax discussion in the group, independant of any final decision. |
| 15:15 | rhickey | :) |
| 15:16 | Chouser | And I also wish (oh how I wish) to be using Clojure for work instead of C++. |
| 15:17 | rhickey | use it to generate C++ |
| 15:17 | Chouser | heh. |
| 15:18 | abrooks | Which thread is the reader thread? ("Syntactic extensibility"?) |
| 15:18 | Chouser | abrooks: yes |
| 15:18 | Chouser | I'm reading about composable monkey patching instead of writing C++ code. |
| 15:18 | rhickey | will be out in novel form soon |
| 15:18 | abrooks | Heh. |
| 15:19 | drewr | That explanation of generic functions was the most concise and helpful I've seen. |
| 15:19 | rhickey | great! |
| 15:23 | Chouser | Is there a way to dispatch multimethods on params other than the first? |
| 15:24 | rhickey | sure, the dispatch fn is an arbitrary fn of _all_ of the arguments |
| 15:25 | rhickey | you can use any subset of the arguments, their types, values, attributes, look up in a db, etc |
| 15:25 | Chouser | ok, so my confusion may be because all the examples I've seen have methoeds with arity 1 |
| 15:26 | rhickey | not this one: http://clojure.sourceforge.net/features/runtime_polymorphism.html |
| 15:26 | Chouser | ah, ok, that helps. thanks. |
| 15:53 | rhickey | user=> (rationalize 1.5) |
| 15:53 | rhickey | 3/2 |
| 15:53 | rhickey | user=> (rationalize 1.2345) |
| 15:53 | rhickey | 2469/2000 |
| 16:14 | Chouser | :-) thanks. |
| 16:14 | Chouser | the name is from CL? We could have floatize, too. |
| 16:15 | rhickey | yes, from CL - you have float already |
| 16:15 | abrooks | Chouser: That would be floatnlize. :) |
| 16:16 | rhickey | but it's not the same, i.e. not ratio |
| 16:16 | rhickey | (rationalize 1) -> 1 |
| 16:16 | Chouser | ah, ok. |
| 16:17 | Chouser | (floatnlize 1) -> 1 |
| 16:17 | rhickey | I don't think so |
| 17:39 | MarkJP | hmmm |
| 17:39 | MarkJP | user=> (= (.. (new Object) (getClass) (getDeclaredMethod "finalize" nil) (getReturnType)) (class Void)) |
| 17:39 | MarkJP | false |
| 17:39 | MarkJP | shouldn't that be true? |
| 17:42 | abrooks | Don't you want t wrap (class ....) around the first contained form? |
| 17:42 | abrooks | Or is that your point.. that you shouldn't have to? |
| 17:42 | MarkJP | didn't think I had to |
| 17:42 | MarkJP | let me try |
| 17:42 | MarkJP | that works |
| 17:42 | abrooks | Right. |
| 17:43 | MarkJP | should I have to? |
| 17:43 | MarkJP | doesnt getReturnType return a class |
| 17:43 | Chouser | I don't think that's what you mean. |
| 17:43 | Chouser | (class Void) -> class java.lang.Class |
| 17:44 | MarkJP | ohhh |
| 17:44 | Chouser | so you want just Void not (class Void). |
| 17:44 | MarkJP | that doesnt work either |
| 17:44 | Chouser | right |
| 17:44 | abrooks | I think the comparison still doesn't... work. |
| 17:44 | MarkJP | user=> (= (.. (new Object) (getClass) (getDeclaredMethod "finalize" nil) (getReturnType)) Void) |
| 17:44 | MarkJP | false |
| 17:45 | MarkJP | yep |
| 17:45 | abrooks | Need more tea. |
| 17:45 | Chouser | getReturnType is returning just void. I'm not sure how that's different from Void. |
| 17:47 | MarkJP | got it: |
| 17:47 | MarkJP | (= (.. (new Object) (getClass) (getDeclaredMethod "finalize" nil) (getReturnType)) (. Void TYPE)) |
| 17:47 | Chouser | nice |
| 17:47 | MarkJP | thx for setting me straight |
| 17:47 | Chouser | What are you working on? |
| 17:48 | MarkJP | turning a clojure proxied class into java code :p |
| 17:48 | MarkJP | need to know when I have to use the keyword "return" |
| 23:46 | Chouser | Shouldn't this work? (binding [x 5] x) |
| 23:47 | Chouser | I must be up too late. It seems like that should just return 5 instead of: java.lang.Exception: Unable to resolve var: x in this context |