2008-10-23
| 00:08 | AWizzArd | is (ensure ref) basically a lock? |
| 00:19 | arohner` | is there a good way to prevent "overwrapping" your arguments because of &rest args? |
| 00:19 | arohner` | i.e. (defn foo [& args] args) (foo (foo (foo 1))) => (((1))) |
| 00:20 | arohner` | or am I doing something wrong by getting into that situation? |
| 00:30 | AWizzArd | What would you expect should (foo (foo (foo 1))) return? |
| 00:31 | arohner` | I'm not sure. I'm just not aware of a clean solution to the problem |
| 00:32 | arohner` | I could say "if the rest argument is already a list, don't add another list around it", but that is very ugly |
| 00:33 | AWizzArd | I don't see the problem |
| 00:33 | AWizzArd | If you do [& args] it means args will be a list. |
| 00:36 | AWizzArd | Asking "IF the rest argument is already a list .." makes not too much too much sense as it will always be one. |
| 00:37 | arohner` | I'm not sure if/where the problem is. All i know is that I'm passing arguments from one rest parameter to another, and I end up with big nested loops. |
| 00:37 | arohner` | i.e. that (foo (foo (foo 1))) example. I started with 1 by itself, and ended up with (((1))) |
| 00:38 | AWizzArd | oh, maybe you want to magically have the parens around the argument to be removed? |
| 00:38 | AWizzArd | (some-function rest) ==> as if you said: (some-function 10 20 30) and not (some-function (10 20 30))? |
| 00:39 | arohner` | yeah, sort of |
| 00:39 | AWizzArd | (apply foo (foo 1)) ==> 1 |
| 00:39 | arohner` | I'm not sure what the right solution is |
| 00:39 | AWizzArd | you need to apply these arguments, that's the right solution |
| 00:39 | AWizzArd | you can not solve it otherwise |
| 00:39 | arohner` | huh. ok. |
| 00:39 | arohner` | I'll try that |
| 00:39 | arohner` | thanks |
| 00:40 | AWizzArd | apply is a "magic function" that you can not implement yourself for the current "level" of programming.. You would need to provide one for an interpreter inside your language. |
| 00:40 | AWizzArd | (+ 1 2 3) = (apply + '(1 2 3)) |
| 01:12 | Lau_of_DK | Morning all! =) |
| 06:31 | alvin-x | when I run this snippet: http://paste.lisp.org/display/69045 with clojure.lang.Script, I see the output from println, but not data gets to the file on disk; if i do a (. output flush) or (. output close) the string does get to the disk.... |
| 06:31 | alvin-x | is this a java thing or a manifestation of clojure's lazyness? |
| 06:31 | alvin-x | . out* not output |
| 06:32 | tWip | I think that's just bufferedwriter |
| 06:32 | alvin-x | probably |
| 06:39 | alvin-x | it happens at the FileWriter level too; no output without flush/close. |
| 06:43 | tWip | what os? |
| 06:43 | alvin-x | win32 |
| 06:44 | tWip | doesn't windows lock files that are open for writing? |
| 06:46 | alvin-x | i'm not sure; have to dig in MSDN. i just expect all buffered data to be written out on process exit. |
| 06:46 | cemerick | that's definitely not something to be relied upon |
| 06:48 | alvin-x | isn't that supposed to happen in unix/posix at least? |
| 06:49 | alvin-x | my process cleanly exited --- didn't die by a fatal signal or exception; |
| 06:50 | cemerick | I don't know about posix exit semantics, but no VM I've worked with will guarantee that anything is cleaned up before it exits. |
| 06:51 | alvin-x | hm |
| 06:51 | cemerick | Actually, most specify that you should expect buffered data, finalizers, etc., won't be flushed/run/whatever |
| 06:52 | Chousuke | doesn't cost anything to just close everything at the end anyway :) |
| 06:54 | alvin-x | not easy to know where "end" is sometimes, without a destructor mechanism... |
| 06:55 | alvin-x | no matter, i'll just flush whenever i write |
| 06:55 | cemerick | that's what finally blocks/forms are for |
| 06:56 | cemerick | flushing on every write essentially eliminates the benefits of buffering |
| 06:59 | alvin-x | is there some form in clojure that i could use to ensure file closing?(with-open ? |
| 07:01 | alvin-x | :) |
| 07:02 | cemerick | yeah, with-open will automatically close the Closable object you bind in it |
| 07:02 | cemerick | I don't think there's a form that will autoflush, but most (if not all) outputstream impls flush on close iirc |
| 07:04 | alvin-x | ha, this will work for JDBC too. nice. |
| 07:05 | jao | hi. in slime, when i compile a file (C-cC-k) and get errors, the compiler-notes window pops, but i cannot navigate from there to the error locations. is that normal? |
| 07:05 | cemerick | alvin-x: yes, indeed |
| 08:38 | rhickey | anyone want to tackle a simple pprint for Clojure? |
| 08:47 | jdz | that would be nice as hell :) |
| 08:47 | cemerick | and very helpful in enclojure |
| 08:47 | alvin-x | and probably non-trivial |
| 08:48 | jdz | well, one could learn a lot from CL's pretty-printer |
| 08:48 | rhickey | a first cut could be much less ambitious yet useful |
| 08:49 | jdz | like support for print-width and print-length |
| 08:49 | jdz | and depth |
| 08:49 | rhickey | jdz: yes |
| 08:49 | hoeck | and printing 'foo instead of (quote foo) |
| 08:51 | rhickey | I just don't see when I'll get time to do it myself |
| 08:51 | jdz | i could try doing it, but must finish a paper in a week... |
| 08:51 | jdz | and then there is some work queued after that... |
| 08:51 | rhickey | Wow - Clojure group just crossed 700 members and 5k messages |
| 08:54 | Chousuke | it says here it has 698 members. |
| 08:54 | rhickey | My admin screen says 712 |
| 08:54 | Chousuke | I guess it hasn't updated yet, then |
| 08:55 | Chousuke | I just added myself. |
| 08:55 | cemerick | db consistency isn't key on g-g :-) |
| 08:56 | jdz | cemerick: consistency does not like concurrence |
| 08:58 | Chousuke | I keep dreaming of making a roguelike game in clojure but I don't have enough time to get started :/ |
| 08:58 | cemerick | I'd say that scalability is more the driving factor, but sure :-) |
| 08:58 | Chousuke | it'd just be so much fun to include a repl in-game |
| 09:39 | lisppaste8 | j-dot pasted "*ns* binding" at http://paste.lisp.org/display/69052 |
| 09:40 | j-dot | Does anyone know why, in the code I just pasted, the 'bar var is set in the 'user ns instead of the 'foo ns? |
| 09:41 | j-dot | How do I go about def'ing a var in another namespace from within a 'do or 'binding expression? |
| 09:42 | wwmorgan | j-dot: (resolve 'bar) is nil when I run it. Could you have def'd it in user earlier? |
| 09:43 | Chouser | yeah, it's because *ns* controls the namespace resolution at compile time, so the original value is used when compiling that whole expression. By the time you actually bind and use in-ns to set it, it's too late. |
| 09:44 | j-dot | ah, I see ... thanks, Chouser |
| 09:44 | rhickey | j-dot: you need to control the ns where the code is compiled - the entire expression is compiled in the user ns, and def resolved there, then you execute the expression, getting runtime effects that don't matter |
| 09:44 | j-dot | That makes sense, thanks |
| 10:08 | rhickey | looking at proposed do-with, what is the preference - add do-with or breaking enhancement to doto (you'd just have to add . before method names) |
| 10:09 | H4ns | rhickey: better modify doto than having two things that do something subtly different in the base language |
| 10:09 | Chouser | I'd be content with a breaking change |
| 10:09 | H4ns | (certainly, i don't have a large code base that will break) |
| 10:10 | Chouser | esp. if it's coming at roughly the same time as a bunch of other simple structural breaking changes (like vectors for binding in if-let, deseq, etc.) |
| 10:10 | Lau_of_DK | Good afternoon gents |
| 10:10 | Chouser | Lau_of_DK: hi |
| 10:25 | walters_ | rhickey: is the asm code in clojure a permanent fork or is it safe to use the system asm library? |
| 10:27 | charliekilo | aplogize upfront ... I'm watching Cojure for Java Programmers ...I got everything installed (Clojure, Aquamacs, clojure-mode), can bring up inferior-lisp, butr CAN'T figure out how he does that two frames trick with evaluate line in clj document in the inferior-lisp evaluator ... what's the magic key combination? |
| 10:28 | Lau_of_DK | The default in emacs is Ctrl-X Ctrl-X I believe |
| 10:29 | rhickey | walters_: it's not really a fork, just a snapshot, using a more current version is really a matter of compatibility between ASM versions - what are you trying to achieve? |
| 10:29 | tWip | I think it is C-M-x |
| 10:29 | walters_ | rhickey: we (Fedora) try to avoid shipping duplicated source |
| 10:31 | rhickey | walters_: do you ship multiple versions of things? |
| 10:31 | walters_ | rhickey: yeah, asm2 and asm3 |
| 10:31 | Chousuke | charliekilo: two frames? do you mean how inf-lisp is at the bottom and the file buffer is at the top? |
| 10:31 | charliekilo | neither C-X C-X or C-M-x does not work for me ... is that part of Emacs or clojure-mode |
| 10:32 | Chousuke | do you have the clojure repl running? |
| 10:32 | charliekilo | Chousuke: yep ... like he does in the video ... top has (. Math PI) and I'm truying to have 3.14... show up in bottom |
| 10:33 | Chousuke | C-x C-e works for me |
| 10:33 | rhickey | walters_: the clojure asm is just a subset, just what's needed for Clojure runtime, done for size and ease of building |
| 10:33 | charliekilo | Chousuke: the bottom has 'user=>' running and I can eval stuff there ... |
| 10:33 | walters_ | rhickey: aright, i may try to do a patch then to optionally build vs system asm |
| 10:34 | rhickey | walters_: ok |
| 10:34 | Chousuke | charliekilo: then you should be able to use C-M-x or C-x C-e to evaluate forms in any buffer that's in clojure-mode |
| 10:34 | Chousuke | charliekilo: if your buffer is in clojure-mode you should see a clojure menu in the menubar when the buffer is active |
| 10:36 | charliekilo | Chousuke: ahh ... it top window one was not in clujure mode ... it works now ... awesome!! ... thanks alot !!!! |
| 10:39 | rhickey | walters_: are you going to use jarjar or something to allow multiple libs to use different ASMs? |
| 10:40 | walters_ | rhickey: that one is a bit of a mess; i think language implementations should probably use a private classloader for now; hopefully the Java 7 module stuff will sort this out somewhat more |
| 10:41 | rhickey | walters_: I think private classloader is a non-starter, as classloader issues usually push up to library consumers, containers etc |
| 10:41 | gnuvince | rhickey: the "Differences with other lisps" page mentions that the Clojure reader is side-effect free. I'm curious about the kind of side effects the CL reader has; it seems like this ought to be a pure function, take in a stream of characters and produce a data structure. |
| 10:41 | rhickey | that's why you see private-packages ASM |
| 10:42 | rhickey | gnuvince: the CL reader interns symbols |
| 10:42 | walters_ | rhickey: well, you could only use the separate classloader for the compiler, the generated bytecode would still be loaded in the main classloader, i think that would avoid most issues |
| 10:43 | rhickey | walters_: it gets really sticky, but the consumer often dictates classloaders, so I've been striving to reduce any dependencies on my own |
| 10:43 | walters_ | rhickey: understood, yeah |
| 10:44 | rhickey | I don't see a compelling reason not to sub-package ASM, it's so small |
| 10:57 | lisppaste8 | Lau_of_DK pasted "Euler52 - Sequences" at http://paste.lisp.org/display/69055 |
| 10:57 | Lau_of_DK | Gentlemen, I have a case here, were all my debug-steps work as they should, but when I try to produce the end result by parsing a seq of seqs, I get an incorrect output. Can somebody show me the error of my ways ? |
| 11:01 | Chouser | Lau_of_DK: can you include an example of find= working? |
| 11:02 | Lau_of_DK | Working? |
| 11:02 | Chouser | you have an example of it producing incorrect results, right? Can you include and example of it producing correct results? |
| 11:03 | Lau_of_DK | No, because if it did produce correct results, we wouldnt be having this discussion :) But its a modded version of this: http://clj-me.blogspot.com/search?q=Google and it seems to work well for cgrande |
| 11:03 | Chousuke | Lau_of_DK: nitpick: n-seq could be simply (iterate #(+ n %) n), no? |
| 11:04 | Lau_of_DK | If you replace the + with a * then yes :) |
| 11:04 | Lau_of_DK | (btw., I like nitpicking, good to learn those things) |
| 11:06 | Chousuke | well, + is the correct function to get what your comment has. with * you get: (take 4 (mul-seq 3)) -> (3 9 27 81) |
| 11:07 | Lau_of_DK | oh ok |
| 11:08 | Lau_of_DK | but, n-seq / map producdes the correct sequence |
| 11:08 | Lau_of_DK | If you check the link to Euler, Im searching for the first hit where 1x n and 2x n ... 6x n, use the same digits |
| 11:08 | Chousuke | mapping works but the multiplication is unnecessary. :) |
| 11:08 | Lau_of_DK | so it needs to be (1 2 3) (2 4 6) (3 6 9) ... |
| 11:11 | Chousuke | whoops. accidentally evaluated a lazy sequence in the repl ;( |
| 11:11 | Chousuke | an infinite one, too |
| 11:13 | Chouser | Chousuke: not uncommon, unfortunately. |
| 11:13 | rhickey | *print-length* patch welcome |
| 11:14 | drewr | If I have a data structure of JdbcConnections that I set as available or unavailable in a ref, how what's the best way to block when all of them are busy? |
| 11:14 | drewr | s/how // |
| 11:15 | drewr | My gut is that Clojure will handle this automatically, but I want to make sure I set it up right. |
| 11:17 | rhickey | drewr: use j.u.concurrent for workflow: http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/package-summary.html |
| 11:17 | rhickey | maybe Semaphore? |
| 11:18 | rhickey | but there is so much presumption in your question |
| 11:18 | rhickey | another architecture is to put a fixed pool of resources in a queue - pull one off to work, put it back when done, will block on empty queue |
| 11:18 | rhickey | I think that's better |
| 11:19 | Chouser | rhickey: you could just about maintain a todo list of things you're *not* going to do, that others could. pprint, *print-length*, due diligence on vector binding forms, etc. |
| 11:20 | drewr | rhickey: Thanks, that sounds like the behavior I want. |
| 11:21 | rhickey | Chouser: yes, definitely, just need to choose where. So far all of the free trac-like things I've seen allow anyone to enter tickets, e.g. Google Code |
| 11:21 | Chouser | rhickey: By the way, I spent last evening staring into Numbers.java. I think I get it now -- pretty clever set of indirections. |
| 11:22 | rhickey | Chouser: yeah, that still needs profiling |
| 11:23 | rhickey | but so far perf is dominated by boxing rather than branching |
| 11:23 | Chouser | Before understanding what was going on there, Clojure script was doing (+ 1 (/ 5 2)) -> "15/2" |
| 11:23 | Chouser | that's close enough, right? |
| 11:23 | rhickey | :) |
| 11:29 | Chouser | unless the todo list is going to be terrbily long or have high turnover, you might just keep a text file in clojure-contrib, or a message pinned to the top of the google group. |
| 11:33 | Lau_of_DK | No insights into my paste? :) |
| 11:36 | Chouser | Lau_of_DK: I've got it loaded in a repl, but haven't learned anything helpful yet. |
| 11:39 | rhickey | Clojure's ToDo list: http://richhickey.backpackit.com/pub/1597914 |
| 11:40 | rhickey | I didn't realize the thing I was using had public viewing ^^^ |
| 11:40 | Lau_of_DK | Chouser, thanks, its good to know you're on it ! :) |
| 11:40 | Chouser | rhickey: heh. |
| 11:40 | drewr | rhickey: Nice! |
| 11:40 | rhickey | I'll split off requests for implementations into it's own list |
| 11:42 | rhickey | its |
| 11:43 | Chouser | ah, that's good. Now I can know when to stop bugging you about patches I've sent in. :-) |
| 11:44 | drewr | Looks like LinkedBlockingQueue will do exactly what rhickey described. |
| 11:56 | drewr | http://bc.tech.coop/blog/081023.html |
| 11:57 | drewr | Bit of JSwat example at the end. |
| 12:13 | H4ns | another common lisper on the band wagon :) |
| 12:16 | Chousuke | Lau_of_DK: I think I found the problem |
| 12:17 | Chousuke | at least, I managed to modify the algorithm so that it produces 142857 which seems to be the correct answer. |
| 12:18 | Lau_of_DK | Can you enlighten me and annote ? |
| 12:19 | Chousuke | Lau_of_DK: your recur in find= seems incorrect |
| 12:19 | hircus | Lau_of_DK: hiyas |
| 12:20 | Lau_of_DK | hircus, hey man :) |
| 12:21 | Lau_of_DK | Ok Chousuke, please annote so that I can try and understand |
| 12:21 | hircus | tried #76 yet? |
| 12:21 | Lau_of_DK | Not yet |
| 12:21 | Lau_of_DK | I'm almost done with < 50's |
| 12:21 | hircus | pretty much the SICP count-change problem, but with the number of choices being high enough that it's impossible to brute-force it |
| 12:21 | Chousuke | after the first iteration seqs becomes ((2 3 4 5 6) (2 4 6 8 10 12) (3 6 9 12 15 18)), so you keep dropping the first element from the first sequence and sorting them until all the firsts match |
| 12:21 | hircus | ah, you're doing it sequentially; I just scatter-shot the problems :) |
| 12:22 | Chousuke | which in this case happens at 6 :/ |
| 12:22 | Lau_of_DK | oh |
| 12:22 | Lau_of_DK | oh yes I see, its only the first seq that I (rest) |
| 12:22 | Lau_of_DK | How did you cure it? |
| 12:23 | Chousuke | I did (recur (map rest seqs)) |
| 12:23 | Lau_of_DK | yea Im trying that now |
| 12:24 | Lau_of_DK | Thanks Chousuke, I really appreciate you putting in the work, I had starred myself blind on it |
| 12:24 | Lau_of_DK | How long did it take to compute on your system ? |
| 12:24 | Chousuke | hmm now I got a stack overflow error. |
| 12:24 | Lau_of_DK | How did you reach 142857 ? |
| 12:26 | Chousuke | apparently the sorting is needed to keep it from overflowing the stack |
| 12:27 | Lau_of_DK | Yea, for some reason, otherwise its quite redundant |
| 12:27 | Lau_of_DK | Mine is still computing |
| 12:27 | Chousuke | really weird |
| 12:28 | Chousuke | is sort destructive? |
| 12:28 | Chouser | no |
| 12:29 | Chousuke | well what |
| 12:29 | Chousuke | lisppaste8: url |
| 12:29 | lisppaste8 | To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste. |
| 12:31 | digash` | http://www.google.com/trends?q=clojure&ctab=0&geo=all&date=ytd&sort=0 |
| 12:32 | lisppaste8 | chousuke pasted "weirdness" at http://paste.lisp.org/display/69058 |
| 12:32 | digash` | i like this trend |
| 12:33 | Chouser | digash`: nice. This will be fun to watch: http://www.google.com/trends?q=clojure%2C+lisp |
| 12:33 | Chousuke | I also modified n-seq to be just (iterate #(+ % n) n)) but the rest is the same |
| 12:35 | Lau_of_DK | Chousuke, you really should anote, instead of pasting a new, gives better overview |
| 12:35 | Chousuke | ah right, forgot the annotation capability. |
| 12:36 | hircus | Lau_of_DK: oh wow, Petite Chez Scheme actually computes #76 by brute force |
| 12:36 | hircus | trying to work out a cleaner solution |
| 12:37 | Chousuke | but still that doesn't make sense. :/ |
| 12:37 | Chousuke | why does a let affect recur so that it doesn't overflow the stack? |
| 12:38 | danlarkin | certain forms can become reentry points or whatever |
| 12:38 | Lau_of_DK | hircus, looking forward to seeing it |
| 12:38 | danlarkin | I don't know if let is one of them, though |
| 12:39 | hircus | Lau_of_DK: #78 is very similar and can't be brute-forced, so yes, will have to do it :) I just need pen and paper to work it out |
| 12:40 | lisppaste8 | Chousuke annotated #69055 with "Weirdness" at http://paste.lisp.org/display/69055#1 |
| 12:40 | Lau_of_DK | hircus, have a look at that paste |
| 12:41 | Lau_of_DK | Chousuke, I should have asked, sorry, I pasted in your name, a complete copy of your other paste |
| 12:41 | Chouser | let is not a recur target. I can't figure out what's going on. |
| 12:41 | hircus | weird! |
| 12:41 | Lau_of_DK | Chousuke, that one where you say "this works", doesnt return on my system, I dont get a reply |
| 12:42 | hircus | s1 & etc were not even used at all? |
| 12:43 | Lau_of_DK | no, not in Chosukes attempt |
| 12:43 | hircus | .. |
| 12:43 | Chousuke | Lau_of_DK: it does on mine |
| 12:43 | Lau_of_DK | really, what is your secret? |
| 12:44 | Lau_of_DK | because using your exact code... does not return :) |
| 12:44 | lisppaste8 | Chousuke annotated #69055 with "my n-seq" at http://paste.lisp.org/display/69055#2 |
| 12:44 | Chousuke | Lau_of_DK: try with that. |
| 12:45 | hircus | how should n-seq.. oh |
| 12:46 | Lau_of_DK | oh, sorry me |
| 12:46 | Lau_of_DK | silly me |
| 12:46 | Lau_of_DK | even |
| 12:46 | hircus | Lau_of_DK: was your n-seq eagerly-evaluating? |
| 12:46 | Lau_of_DK | no, it was lazy |
| 12:46 | hircus | so.. still not sure what was the problem |
| 12:46 | Lau_of_DK | oh wait |
| 12:46 | hircus | sort will force evaluation, right? |
| 12:46 | Lau_of_DK | typo - I was fiddling with it a minute ago, corrupted it |
| 12:47 | Lau_of_DK | sort (in this case) only deals with the head |
| 12:47 | hircus | that's the only difference I could think of |
| 12:47 | hircus | yes, but sort forces evaluation of the entire sequence |
| 12:47 | lisppaste8 | Chouser annotated #69055 with "also works" at http://paste.lisp.org/display/69055#3 |
| 12:47 | Lau_of_DK | anyway, the Euler is solved, but it raises a question about stack-usage |
| 12:47 | Chouser | hircus: I think that proves your hypothesis. |
| 12:48 | hircus | Chouser: the last paste? looks like it |
| 12:48 | Chousuke | so it was being too lazy? :/ |
| 12:48 | hircus | a bit surprised that lazy sequences are put on the stack, but hey |
| 12:48 | Lau_of_DK | Chouser, you run doall on infiniate sequences? |
| 12:48 | Chouser | this isn't the final answer. |
| 12:48 | Chouser | Lau_of_DK: no |
| 12:49 | Chouser | don't run sort on infinite seqs either. :-) |
| 12:49 | Lau_of_DK | Americans... |
| 12:50 | hircus | seems easier to do #52 by converting to strings, anyway |
| 12:50 | Chousuke | (map n-seq [1 2 3 4 5 6]) is a finite sequence of infinite sequences; the doall just forces the n-seq to be called. |
| 12:50 | Lau_of_DK | hircus, can you run it in 2 secs with strings ? |
| 12:50 | hircus | for a number, convert to a string then to a seq of chars then sort |
| 12:50 | hircus | aha, no |
| 12:50 | Lau_of_DK | Chousuke, OH! |
| 12:51 | Lau_of_DK | I didnt know that |
| 12:51 | hircus | actually, I can |
| 12:51 | hircus | 0.174secs in Python |
| 12:51 | Chousuke | removing the doall from find= and putting it in the find= call like so (find= (doall (map n-seq [1 2 3 4 5 6])) will work |
| 12:51 | hircus | start it at 125874, though, no need to start from 0 :) |
| 12:52 | Chousuke | whoops, missing a parenthesis |
| 12:52 | Chousuke | I wonder if irssi has a syntax highlighting plugin :/ |
| 12:54 | Hun | hmm... one could use emacs rcirc + multi-major-mode for this |
| 12:56 | Chousuke | this stack overflow problem looks like something that might bite again if there's a lot of laziness :/ |
| 12:56 | Lau_of_DK | Chousuke, I believe youre right |
| 12:57 | Lau_of_DK | I had to take off, but I'd like to thank everybody who helped bring me up to speed, youve been a fantastic help!! Have a good evening |
| 13:01 | gnuvince | Has it been discussed here how to translate the "classical" Haskell solution for sieve of erasthesomethings to Clojure? In Haskell it's usually: let { primes = sieve [2..]; sieve (x:xs) = filter [n | n <- xs, n `mod` x /= 0] } |
| 13:09 | gnuvince | hmmm |
| 13:09 | gnuvince | are LazyCons really lazy? |
| 13:24 | leafw | can one make a function that takes multiple sets of arguments (easy). but where some of these are private? I.e. [x] is private, but [x y] is public. |
| 13:25 | gnuvince | leafw: I don't think you can. Use a nested function for that. |
| 13:25 | leafw | ok |
| 13:25 | leafw | thanks |
| 13:26 | leafw | but aren't nested functions public? Perhaps defined only in a let, I guess |
| 13:27 | leafw | oh, or with #^{:private true}, I guess |
| 13:34 | leafw | can't a function refer to itself within its own declaration? |
| 13:35 | lisppaste8 | leafw pasted "fibonacci" at http://paste.lisp.org/display/69060 |
| 13:36 | leafw | first one works, second fails to compile |
| 13:36 | wwmorgan | leafw: try using a named anonymous function |
| 13:36 | leafw | sorry: named anonymous function? |
| 13:37 | leafw | isn't that what the let is doing in this casE? |
| 13:38 | lisppaste8 | wwmorgan annotated #69060 with "compiles" at http://paste.lisp.org/display/69060#1 |
| 13:38 | gnuvince | leafw: let don't allow recursion. |
| 13:39 | leafw | thanks people. That (fn this [...] ) is new to me. |
| 13:57 | Hun | leafw: you could do it like the second one by implementing the y-combinator |
| 13:59 | gnuvince | @url |
| 13:59 | gnuvince | lisppaste8: url |
| 13:59 | gnuvince | lisppaste8: url? |
| 13:59 | lisppaste8 | To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste. |
| 13:59 | lisppaste8 | To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste. |
| 13:59 | leafw | Hun: show me |
| 14:00 | gnuvince | leafw: did you try the infinite fib list solution? |
| 14:00 | lisppaste8 | gnuvince pasted "How's this implementation of rests?" at http://paste.lisp.org/display/69061 |
| 14:00 | Hun | leafw: i don't have a running clojure on this machine, so this might not work |
| 14:00 | Hun | (defn y (fun) |
| 14:00 | Hun | (fn [& args] (apply fun fun args))) |
| 14:03 | lisppaste8 | Chouser annotated #69061 with "Another "rests"" at http://paste.lisp.org/display/69061#1 |
| 14:04 | leafw | Hun: haven't ever used the y-comb |
| 14:05 | leafw | 've read about it, that's all. |
| 14:05 | leafw | your impl looks .. will trye |
| 14:05 | Hun | the basic idea is that the function gets itself as its first arg |
| 14:05 | Hun | which is what y does on the fn |
| 14:05 | Hun | end the function defines where to recourse |
| 14:06 | leafw | andinitial args to the fun are passed how? |
| 14:06 | leafw | trying |
| 14:09 | Hun | they are passed through to the function. that definition might not work, depending on how apply works in clojure |
| 14:10 | AWizzArd | Moin |
| 14:57 | lisppaste8 | jochu annotated #69060 with "Using an infinite lazy seq" at http://paste.lisp.org/display/69060#2 |
| 15:38 | leafw | woah : jochu, that was awesome. |
| 15:39 | leafw | although I don't understand it. |
| 15:40 | leafw | lazy-cat concats two sequences, but you give it an array [0 1] and then the result of a mapping that involves sums, but I don't see how it sums the right pair of numbers. |
| 15:41 | leafw | somehow, the lazy-cat is defining the fibonacci sequence itself, in abstract form. This is briliant, reads almost like prolog |
| 15:42 | Chouser | yeah, impressive. The summing is of each fib and fib offset by one (via rest) |
| 15:45 | duck1123 | how can I retrieve just the doc-string of a function? (doc) prints it, but doesn't return anything and (meta) doesn't return it either. |
| 15:46 | wwmorgan | duck1123: (with-out-str (doc doc)) |
| 15:47 | wwmorgan | also (:doc ^#'doc) |
| 15:48 | duck1123 | that's what I wanted |
| 15:48 | duck1123 | thanks |
| 16:00 | AWizzArd | rhickey: Thanks for your comments about Currying Rich. I still think we could do it, with something else instead of #(). Maybe �() or something like that. |
| 16:02 | Chouser | AWizzArd: I don't know how to type that thing. |
| 16:02 | duck1123 | that's going to be hell to type |
| 16:02 | Chouser | And although it looks ok in the browser, in this window it just shows up as the rectangle used when a font doesn't have that glyph. |
| 16:03 | AWizzArd | you all still use this 1886 keyboard layout yes? ;-) |
| 16:03 | cemerick | � is option-6 on Macs, fwiw |
| 16:03 | AWizzArd | This qwerty stuff |
| 16:03 | AWizzArd | Shift 3 I guess on qwerty maybe? |
| 16:03 | Chouser | served me well so far |
| 16:03 | H4ns | AWizzArd: it is not ascii, forget it. |
| 16:04 | AWizzArd | H4ns: why not doing unicode? I would like to have greek symbols in my source. My keyboard layout can produce them so easily. |
| 16:04 | H4ns | AWizzArd: you certainly don't want things in the base language that only germans can type with reasonable effort |
| 16:05 | rhickey | I was thinking of something like this for apply/curry: #(@ + 5), where #(@ ...) means (fn [& args] (apply ... args)) |
| 16:05 | AWizzArd | Well sure, and the � is just an example. It can be anything else that makes sense. My point is just: let us have currying. |
| 16:05 | rhickey | @ being special as first form in #() |
| 16:05 | duck1123 | we should start using ? in code instead of #() |
| 16:06 | H4ns | AWizzArd: your point is: rhickey, implement currying! :) |
| 16:06 | rhickey | but not sure about more symbol overload |
| 16:06 | rhickey | currying is overrated |
| 16:06 | H4ns | i like partial application a lot, but i don't need no fancy syntax for that. |
| 16:06 | rhickey | #() is pretty neat as is |
| 16:07 | AWizzArd | H4ns: well yes, I showed my implementation of it in Google Groups. I just can't implement reader macros. |
| 16:07 | duck1123 | rhickey: the doc-string for -> has a redundant 'macro' in it. |
| 16:08 | AWizzArd | !(rgb _ 123) or having the @ or $(..) or whatever. |
| 16:10 | rhickey | there's already partial and #(), this doesn't seem pressing |
| 16:12 | gnuvince | currying is, in my opinion, one of the two pillars of unreadable Haskell code. |
| 16:12 | rhickey | :) |
| 16:12 | Chouser | heh |
| 16:13 | gnuvince | the other is succinct function composition |
| 16:13 | gnuvince | Check the forums of Project Euler, especially answers from the French Jedai |
| 16:14 | gnuvince | it's 3 lines of nothing but function composition of curried functions with a bunch of curry, uncurry and flip thrown in for good measure. |
| 16:18 | AWizzArd | I see partial as not too useful. The whole idea behind currying is to have syntactic sugar, to save a few keystrokes. So, (partial ..) is too long imo. |
| 16:29 | duck1123 | what is the difference between a var quote and a normal quote? |
| 16:30 | duck1123 | nvm, I found it |
| 16:35 | Chouser | (partial foo) seems a _bit_ nicer than (fn [& x] (apply foo x)) |
| 16:36 | Chouser | and even a bit nicer than #(apply foo %&) |
| 16:48 | meredydd | Chouser: Also, doesn't (partial) date from before the introduction of #(...)? |
| 17:08 | Chouser | meredydd: I think so |
| 17:11 | schwartzwald | what do clojurers think of scala? |
| 17:11 | schwartzwald | clojure is an alternative, not a replacement for java right? |
| 17:12 | Chouser | I came to clojure seeking refuge from Scala's type system. |
| 17:12 | kotarak | scala seems to be more verbose in syntax than Clojure or ML... |
| 17:12 | schwartzwald | or it would be a reasonable to write JAVA(enterprise)-stuff in clojure? i tried scala bu it felt pretty heavy and unflexible, like java |
| 17:12 | AWizzArd | Chouser: yes, but $(foo) is even nice than #(apply foo %&) or (partial foo) |
| 17:12 | schwartzwald | yes scala seemed great on paper but it didnt feel good |
| 17:12 | AWizzArd | Clojure is a functional programming language. It makes sense to have currying. |
| 17:13 | Chouser | schwartzwald: I don't know why you wouldn't be able to write whatever you want in Clojure. It's pretty practical. |
| 17:14 | kotarak | AWizzArd: How do you distinguish: (defn foo ([x] ...) ([x y] ...)) $(foo z)? |
| 17:14 | Chouser | kotarak: apply does that for you. |
| 17:15 | AWizzArd | app.. yes |
| 17:15 | Chouser | if you replace $(foo z) with (partial foo z) |
| 17:15 | kotarak | Chouser: I was asking for currying. When I curry, how do I decide which form to use? |
| 17:16 | AWizzArd | kotarak: can you be more specific? |
| 17:16 | kotarak | (foo z) is legal. (foo a b) is also legal. What does $(foo z) mean, the first or the curried second? |
| 17:16 | AWizzArd | btw, I want to replace $(foo z) with (fn [& args] (apply foo z args)) |
| 17:17 | AWizzArd | if you want to curry away some earlier args you would do it this way: $(foo _ z) |
| 17:17 | AWizzArd | just read in google groups, it's explained there |
| 17:17 | AWizzArd | http://groups.google.com/group/clojure/t/36c77eec86a0930b |
| 17:18 | AWizzArd | I used #(foo _ z) in that posting, but rhickey gave good arguments why to leave #() untouched so far. Now I suggest to think about having some other character. And that could even be recycled for a later addon like an infix reader for math. |
| 17:19 | AWizzArd | We just need some other symbol than #. It could be a $ or a ! or maybe <foo _ z>. |
| 17:20 | AWizzArd | I would implement it myself as a reader macro, but at this point CLJ doesn't allow us to access the *readtable*, so read macros need to be written in assem... in Java. |
| 17:20 | wwmorgan | AWizzArd: you could implement it as a non-reader macro too, right? |
| 17:21 | AWizzArd | yes, and I did that, just click the link |
| 17:21 | AWizzArd | It's also not bad, but I think ($ < 5) is not as nice to read as $(< 5) |
| 17:33 | emacsen | rhickey, so, I've been reading about Lisp50, and here's the problem Clojure has. All the great language designers are weird looking. There's even a site my gf sent me to: Language designer or serial killer. You have to match the photo with the description. You look like a normal, regular (non-geek) man. Thus, I'm afraid, Clojure may be doomed to failure. |
| 17:33 | emacsen | ;) |
| 17:34 | Hun | popcorn and tacos for everyone! |
| 17:37 | emacsen | Hun: It's mainly a joke. I actually disagree with McCarthy. Languages /do/ need a single face, at least in the beginning. |
| 17:38 | Hun | true. i also believe that anybody needs a big beard. not that i have one though :/ |
| 17:38 | emacsen | beards are really optional. that's more a Unix thing |
| 17:39 | wwmorgan | http://blogs.microsoft.co.il/blogs/tamir/archive/2008/04/28/computer-languages-and-facial-hair-take-two.aspx The English really makes it hilarious |
| 17:45 | danlarkin | I wonder when I'll become a famous language designer |
| 17:48 | walters | the fact that matz grew a beard just for that article is awesome |
| 19:29 | blbrown | http://groups.google.com/group/clojure/browse_thread/thread/f07b1a70eab5f8e2 anyone have an answer for this one |
| 19:34 | Chouser | blbrown: you want that for all functions defined after a certain point? Or just certain functions? |
| 19:34 | blbrown | Chouser, ideally of them. And the ability to print when a function is called is just one example. E.g. I might want to time how long a function executes |
| 19:38 | blbrown | Chouser: going to leave me hanging? |
| 19:40 | Chouser | blbrown: I think it's possible, but it's hacking around at a level I don't have much experience with. |
| 19:40 | Chouser | so I'm trying some things. |
| 19:41 | shoover | What about using the ns-* functions to get all the symbols in a given namespace. You could test a symbol's metadata to see if it's a function, then rebind thread-locally using binding and set!. Of course, that will only hold as long as you're in the binding scope. |
| 19:41 | blbrown | they say in lisp, you can use macros to achieve what I want |
| 19:41 | blbrown | shoover: that is an idea |
| 19:41 | Chouser | shoover: ooh, that's better than what I'm trying. |
| 19:43 | shoover | Rich always mentions binding when people talk about logging and timing, so it should work |
| 19:44 | Chouser | yeah, now that you describe that, I think I may have seen code for it go by on the google group |
| 19:45 | shoover | blbrown: and you can wrap all that binding stuff in a macro, so there's your lisp way |
| 19:45 | blbrown | shoover: you have some code or examples I can look at. I will give you a reddit karma point if you code up something in 10 minutes |
| 19:48 | shoover | Chouser will beat me now that he knows what to do :) |
| 19:49 | Chouser | hehe |
| 19:50 | shoover | lisppaste8: url |
| 19:50 | lisppaste8 | To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste. |
| 19:50 | lisppaste8 | shoover pasted "wrapping an existing function" at http://paste.lisp.org/display/69085 |
| 19:50 | lisppaste8 | Chouser pasted "trace" at http://paste.lisp.org/display/69086 |
| 19:50 | shoover | no macro there, but it shows the binding process |
| 19:53 | shoover | Chouser: nice, with the var-get and trace-fn |
| 19:53 | blbrown | If you have used ASM, I did it with asm (and obviously reflection) but I was also looking for the clojure way. http://asm.objectweb.org/ |
| 19:54 | blbrown | Chouser, shoover: thanks guys |
| 19:54 | shoover | I thought there was something in the metadata to flag a fn, but I don't see it now that I look at my ^#'bar |
| 19:55 | Chouser | :arglists ? |
| 19:56 | shoover | yeah, that's close enough, as long as it doesn't have the macro flag |
| 20:36 | emacsen | anyone know if there's audio/video of lisp50? |
| 20:37 | rhickey | They recorded it, but I don't know that it's available yet |
| 20:37 | emacsen | k |
| 20:43 | lisppaste8 | Chouser annotated #69086 with "trace namespace" at http://paste.lisp.org/display/69086#1 |
| 20:46 | Chouser | blbrown: That's as far as I'll mess with it. |
| 20:46 | Chouser | I imagine you could make is so that the details of trace-wrap could be passed in. |
| 20:48 | blbrown | Chouser, that is cool, thanks |
| 21:03 | duck1123 | is anyone here familiar with compojure |
| 21:04 | duck1123 | I'm trying to figure out how I can create a folder under app/ and have a file in there named other than the folder's name |
| 21:22 | chrisdone | rhickey: what is the font used in your Clojure for Lisp Programmers presentation (up on Blip.tv)? it's gorgeous and I want it! |
| 21:24 | danlarkin | chrisdone: looks a lot like Monaco to me |
| 21:28 | rhickey | chrisdone: yes, monaco for the code |
| 21:29 | duck1123_ | is it possible to have clojure files named other than the name of the last folder? |
| 21:29 | chrisdone | danlarkin, rhickey: thank you :-) |
| 21:30 | danlarkin | duck1123: it sure is |
| 21:31 | duck1123 | I'm trying to set up my namespaces for compojure, but it keeps wanting me to name it the same as the folder name |
| 21:31 | crathman | since the wiki says that sicp is not optimal for learning clojure, figured I'd be a contrarian.... :-) |
| 21:32 | crathman | chapter #1 has been translated to clojure - http://www.codepoetics.com/wiki/index.php?title=Topics:SICP_in_other_languages |
| 21:33 | duck1123 | otherwise I get: Could not locate Clojure resource on classpath: mycyclopedia/view/view.clj |
| 21:33 | danlarkin | duck1123: having not used compojure I can't comment on any naming scheme it enforces |
| 21:33 | danlarkin | duck1123: but I can say the limitation isn't one imposed by clojure itself |
| 21:33 | duck1123 | I don't think it really imposes anything other than what clojure does |
| 21:35 | duck1123 | the wiki pretty much says to do the same thing: Now we have to create a file in the classpath with the filename "example/ourlib/ourlib.clj". |
| 21:36 | danlarkin | well I've been using files that are named differently than their containing directory, but perhaps I'm doing things different |
| 21:37 | duck1123 | do I have to explicitly add the folder to the classpath, or do you happen to have an example? |
| 21:37 | duck1123 | I noticed that clojure.contrib uses the same pattern |
| 21:50 | Chouser | naming the .clj the same as its folder allows the .clj to be loaded via the ns macro, require, use, etc. |
| 21:51 | duck1123_ | so if I wanted to name it something else, I couldn't use the ns macro |
| 21:52 | Chouser | your file could still use ns, but nothing else could load your file using ns. |
| 21:52 | duck1123_ | so how would I load it? That may almost be acceptable in this very limited senario |
| 21:53 | Chouser | you could use load or load-file |
| 21:53 | duck1123_ | this file would only ever be loaded by one other file, I would go the proper route for anything else |
| 22:25 | ericthor | anything change on the gen-class front recently? I have a clojure gen-class extending a java class. I have a mypackage/ClassName/ClassName.clj... |
| 22:26 | ericthor | and the function names are (defn ClassName-extendedClassFunc[this]) |
| 22:26 | ericthor | I can create an instance of the class but when I call any function I'm getting an AbstractMethodError...this used to work? |
| 22:30 | Chouser | was it working since the fn names changed to ClassName-fnName? |
| 22:32 | ericthor | Chouser: it worked as fn names are classname-fnnames |
| 22:32 | ericthor | Chouser: has that changed since? |
| 22:34 | ericthor | Chouser: might be time to redo my genclass stuff...going to turn in. Thanks for the help |
| 22:34 | ericthor | Chouser: I probably just have some out of sync clojure stuff |
| 22:35 | Chouser | There were changes to genclass in August, but none since. |
| 22:51 | larrytheliquid | if i have a map that has a certain key, and a function that takes a parameter that would ideally be the same name as the map key, is there a convention to distinguish the two? |
| 22:51 | larrytheliquid | ie: description vs description-param |
| 23:02 | Chouser | I don't think I understand. It's common to use keywords for map keys. |
| 23:03 | Chouser | does that help? |
| 23:06 | larrytheliquid | say i have something like (defstuct my-data :description), and then (defn do-something [description] ... ) |
| 23:07 | larrytheliquid | inside do-something description would shadow the description method in the struct |
| 23:09 | Chouser | ah, for structs! |
| 23:10 | larrytheliquid | ah nevermind, i didn't realize that the symbol in the struct :description would be part of the method name too |
| 23:10 | larrytheliquid | so no conflicts |
| 23:10 | Chouser | um, no convention I'm aware of. |
| 23:10 | larrytheliquid | the colon* |
| 23:10 | larrytheliquid | the colon takes care of the difference |
| 23:11 | Chouser | ok, good. |
| 23:14 | Chouser | I can't get definline to work. Anyone know how to use it? |
| 23:22 | duck1123 | has anyone here managed to get slime working with compojure? |
| 23:23 | duck1123 | I can get standard clojure working, sbcl works, but I keep getting that stupid progn error when I try to use compojure |