2009-01-25
| 00:00 | Cark | actually you should do your requires in the ns form |
| 00:00 | Cark | so you could have something like this : |
| 00:00 | hiredman | eee: did you pass -server to java? |
| 00:01 | eee | um, I don't run things like that. whatever netbeans does |
| 00:01 | hiredman | java has two different vms |
| 00:01 | Cark | (ns org.mysite.my-lib (:use [clojure.contrib.math :exclude [mod]]) |
| 00:01 | eee | which is dead working on this again |
| 00:01 | hiredman | -server and -client |
| 00:02 | hiredman | -server does all the cool jitstuff |
| 00:02 | hiredman | -client does not |
| 00:02 | eee | well can someone whose setup is working convert my filtrem to use lists and time again |
| 00:03 | eee | against separate from contrib |
| 00:03 | ayrnieu | ,(defn eenie-meenie-mynie-moe [list] (nth list (mod 15 (count list)))) (eenie-meenie-mynie-moe '(pizza pork pb-and-j)) |
| 00:03 | clojurebot | DENIED |
| 00:03 | eee | my environment is clearly hosed |
| 00:03 | Cark | eee : why don't you try with the basic repl ? |
| 00:05 | gnuvince_ | Chouser: Sorry to bother, did you get a chance to look at my greatest-least package? |
| 00:05 | hiredman | clojurebot: does not allow defns |
| 00:05 | clojurebot | I don't understand. |
| 00:05 | ayrnieu | ,(let [e-m-m-m (fn [list] (nth list (mod 15 (count list))))] (e-m-m-m '(pizza pork pb-and-j))) |
| 00:05 | clojurebot | pizza |
| 00:05 | hiredman | er |
| 00:06 | eee | i don't think time works right |
| 00:06 | hiredman | time is very simple |
| 00:06 | Chouser | 'mod' is removed from 'math' now |
| 00:06 | ayrnieu | it may not provide wallclock time, eee. |
| 00:06 | eee | lazy things continue to process after the timer comes back |
| 00:07 | eee | you could run someting that hangs for an hor |
| 00:07 | eee | hour |
| 00:07 | hiredman | eee: wrap in doall |
| 00:07 | eee | and then it prints .123 |
| 00:07 | Cark | benchmarking is hard =) |
| 00:07 | eee | oh |
| 00:07 | eee | ok |
| 00:07 | hiredman | eee: that is host laziness works |
| 00:07 | hiredman | it defers execution |
| 00:07 | hiredman | how |
| 00:07 | eee | laziness dumb |
| 00:07 | eee | :) |
| 00:08 | eee | i can just imagine the fun I'll have trying to get coworkers to use the language |
| 00:08 | eee | there's aren't fewer gotcha's . .. just different ones |
| 00:09 | Chouser | gnuvince_: very briefly. were you going to integrate Jason Wolfe's maximal-elements or whatever that's called? |
| 00:14 | eee | what does this mean? #(< % x) |
| 00:14 | eee | percent |
| 00:14 | ayrnieu | ,(let [x 5] (#(< % x) 2)) |
| 00:14 | clojurebot | true |
| 00:14 | hiredman | is #() is a kind of function literal |
| 00:14 | ayrnieu | ,(let [x 5] (#(< % x) 7)) |
| 00:14 | clojurebot | false |
| 00:14 | eee | but the percent? |
| 00:15 | hiredman | % is the first argument |
| 00:15 | hiredman | % or %1 |
| 00:15 | hiredman | %2 is the second |
| 00:15 | eee | oh |
| 00:15 | hiredman | etc |
| 00:15 | ayrnieu | ,(let [x 5] ((fn [percent] (< percent x)) 2)) |
| 00:15 | clojurebot | true |
| 00:15 | eee | 1st areg of let |
| 00:16 | eee | arg |
| 00:16 | hiredman | no |
| 00:16 | hiredman | the first arg of the function |
| 00:16 | Chouser | #(+ % %2) is the same as (fn [a b] (+ a b)) |
| 00:23 | eee | oh |
| 00:24 | eee | i like that |
| 00:24 | gnuvince_ | Chouser: I did, but I changed the name and the code. |
| 00:24 | gnuvince_ | Chouser: There are 8 functions now: greatest, greatest-by, all-greatest, all-greatest-by and the same thing for least. |
| 00:25 | eee | do I automatically have contrib available? |
| 00:25 | eee | i just use enclojure |
| 00:27 | Chouser | Does greatest-by always return the same thing as (first (all-greatest-by ...)) ? |
| 00:27 | eee | wow! |
| 00:27 | eee | now I know lazy was messing up the timing |
| 00:27 | eee | mine is faster than filter |
| 00:27 | eee | so anything that uses two passes with filter is way slower |
| 00:28 | Chouser | gnuvince_: If so, and if the all-* functions produces lazy seqs, then you'd could have half as many functions. |
| 00:31 | gnuvince_ | I don't see how they could produce a lazy sequence: they need to go until the end of the sequence to find the greatest element |
| 00:32 | eee | anyone have access to the contrib 'separate' implementation? |
| 00:32 | Chouser | gnuvince_: heh. good point. |
| 00:32 | Chouser | sorry, I'm apparently not thinking very clearly |
| 00:33 | gnuvince_ | Chouser: don't worry about it :) |
| 00:33 | Chouser | eee: "access"? |
| 00:34 | Chouser | gnuvince_: I'm just trying to think of ways to reduce the number of new functions needed to express the range of related functionality. |
| 00:34 | hiredman | clojurebot: contrib? |
| 00:34 | clojurebot | contrib is http://code.google.com/p/clojure-contrib/ |
| 00:34 | eee | what is the implementation for separate. someone listed it before but it is off my screen |
| 00:34 | Chouser | eee: http://code.google.com/p/clojure-contrib/source/browse/trunk/src/clojure/contrib/seq_utils.clj#37 |
| 00:34 | ayrnieu | http://www.catholic.com/audio/2008/MP3/ca081212a.mp3 |
| 00:35 | ayrnieu | huh, that's wrong. |
| 00:35 | ayrnieu | http://code.google.com/p/clojure-contrib/source/browse/trunk/src/clojure/contrib/seq_utils.clj |
| 00:35 | eee | thanks |
| 00:36 | hiredman | ugh |
| 00:36 | hiredman | my internet is so slow |
| 00:37 | ayrnieu | yow, I really hate this style. (defn name "long comment" [args] ...) |
| 00:37 | eee | wow. it really is way faster |
| 00:37 | eee | i guess the lack of branching and more efficient looping? |
| 00:38 | Chouser | gnuvince_: ok, let me try again. even 'greatest' has to consume all its args. is boundary any more efficient than boundary-all? |
| 00:38 | eee | i dunno, it calls filter twice, but calling filter once is slow |
| 00:38 | hiredman | is doall recursive? does it realize lazy-seqs recursively? |
| 00:39 | Chouser | hiredman: no |
| 00:39 | hiredman | ah |
| 00:39 | Chouser | ,(second (doall [(iterate inc 0) [1 2]])) |
| 00:39 | clojurebot | [1 2] |
| 00:40 | Chouser | ,(seconde (iterate inc 0)) ; lazy |
| 00:40 | clojurebot | java.lang.Exception: Unable to resolve symbol: seconde in this context |
| 00:40 | Chouser | ,(second (iterate inc 0)) ; lazy |
| 00:40 | clojurebot | 1 |
| 00:41 | Chouser | (second (doall (iterate inc 0))) ; hangs |
| 00:41 | hiredman | ,(second (doall (iterate inc 0))) |
| 00:41 | clojurebot | Execution Timed Out |
| 00:42 | hiredman | sure, "hangs" |
| 00:42 | ayrnieu | ,(second (first (doall [(iterate inc 0) [1 2]]))) |
| 00:42 | clojurebot | 1 |
| 00:43 | Chouser | gnuvince_: I gotta go. I'm not stopping any other contrib member from putting your code in, but personally I'd like to see if there's any sane way to pack the functionality of those 8 fns into 1 or 2 fns. |
| 00:47 | gnuvince_ | Chouser: I'll look into it |
| 01:02 | gnuvince_ | You can't |
| 01:02 | gnuvince_ | You call it on a Reader or a Stream |
| 01:02 | hiredman | ,(doc read) |
| 01:02 | clojurebot | "([] [stream] [stream eof-error? eof-value] [stream eof-error? eof-value recursive?]); Reads the next object from stream, which must be an instance of java.io.PushbackReader or some derivee. stream defaults to the current value of *in* ." |
| 01:03 | technomancy | so I need to instantiate some kind of stream? |
| 01:04 | hiredman | you nead a java.io.PushbackReader |
| 01:05 | technomancy | right... but I can't make one by passing a File in |
| 01:06 | technomancy | I guess I need a reader? |
| 01:06 | technomancy | to make a reader? |
| 01:06 | hiredman | FileReader |
| 01:06 | Cark | (-> file FileReader. PushbackReader.) |
| 01:06 | Cark | something like that i guess |
| 01:07 | technomancy | yay hoops |
| 01:07 | technomancy | thanks though |
| 01:08 | technomancy | is this considered reasonable, or is it just one of those, "yeah, the language is still young, so it's got some rough edges" moments? |
| 01:25 | technomancy | If I want to look up a docstring for a function given a symbol, (:doc ^#'my-func) works... but what if I want to make it dynamic? |
| 01:26 | gnuvince_ | technomancy: (:doc (meta (var my-func))) |
| 01:27 | technomancy | gnuvince_: that's what I tried |
| 01:27 | technomancy | this doesn't work: (let [x filter] (:doc (meta (var x)))) |
| 01:27 | technomancy | maybe I'm misunderstanding var |
| 01:28 | technomancy | docstrings that point to web sites? hrm. |
| 01:28 | technomancy | that may be taking "Don't Repeat Yourself" a bit too literally. =) |
| 01:28 | gnuvince_ | That's because x is not a var |
| 01:29 | gnuvince_ | technomancy: special forms can't have meta data, so they can't have doc. |
| 01:29 | technomancy | right, I need to look up the docstring for the function that x is bound to... ah. but the function doesn't have the docstring, the var does? |
| 01:30 | technomancy | that's ... problematic. |
| 01:30 | technomancy | I guess I'll have to write this as a macro then. |
| 01:31 | gnuvince_ | Look at how it's done for doc |
| 01:31 | ayrnieu | ,(let [x filter] (doc x)) |
| 01:31 | clojurebot | java.lang.Exception: Unable to resolve var: x in this context |
| 01:32 | ayrnieu | ,(macroexpand '(doc x)) |
| 01:32 | clojurebot | (let* [m__63__auto__ (clojure.core/meta (var x)) al__64__auto__ (:arglists m__63__auto__) docstring__65__auto__ (:doc m__63__auto__)] (.replaceAll (.replaceAll (clojure.core/str al__64__auto__ "; " docstring__65__auto__) "\n" "") (clojure.core/str \\ \s) " ")) |
| 01:32 | durka42 | ,(macroexpand-1 '(doc x)) |
| 01:32 | clojurebot | (clojure.core/let [m__63__auto__ (clojure.core/meta (var x)) al__64__auto__ (:arglists m__63__auto__) docstring__65__auto__ (:doc m__63__auto__)] (.replaceAll (.replaceAll (clojure.core/str al__64__auto__ "; " docstring__65__auto__) "\n" "") (clojure.core/str \\ \s) " ")) |
| 01:32 | ayrnieu | ,(macroexpand-1 '(doc x)) |
| 01:32 | clojurebot | (clojure.core/let [m__63__auto__ (clojure.core/meta (var x)) al__64__auto__ (:arglists m__63__auto__) docstring__65__auto__ (:doc m__63__auto__)] (.replaceAll (.replaceAll (clojure.core/str al__64__auto__ "; " docstring__65__auto__) "\n" "") (clojure.core/str \\ \s) " ")) |
| 01:32 | ayrnieu | hm. |
| 01:32 | ayrnieu | interactively, it macroexpands to (clojure.core/print-doc (var x)) |
| 01:33 | durka42 | ,(= doc clojure.core/doc) |
| 01:33 | clojurebot | java.lang.Exception: Can't take value of a macro: #'clojure.core/doc |
| 01:33 | durka42 | ,(= (var doc) (var clojure.core/doc)) |
| 01:33 | clojurebot | true |
| 01:35 | technomancy | can't map a macro over a list, of course. |
| 01:36 | technomancy | I guess this is where I use Emacs rectangle commands for "code generation" |
| 01:37 | ayrnieu | what are you trying to do? |
| 01:38 | technomancy | I've got a list of symbols that refer to functions, and I want to get a list of the corresponding docstrings |
| 01:38 | durka42 | hmm, you can do something dumb like (map #(eval `(doc ~%)) '[filter print-doc]) |
| 01:39 | technomancy | durka42: was about to do that, actually. |
| 01:39 | technomancy | much to my shame. |
| 01:39 | durka42 | it feels like a goto or something |
| 01:39 | durka42 | or using a void* |
| 01:40 | technomancy | (my version was going to use read-string, which is far worse) |
| 01:40 | durka42 | that would add an extra step |
| 01:40 | durka42 | (+ 2 3) |
| 01:40 | clojurebot | *suffusion of yellow* |
| 01:42 | Cark | technomency : i have some code to search the metadata of symbols in namespaces |
| 01:42 | Cark | what to get it ? |
| 01:42 | Cark | err i mean: want to get it |
| 01:42 | ayrnieu | "want in on it?" |
| 01:43 | technomancy | Cark: sure |
| 01:43 | Cark | clojurebot: paste? |
| 01:43 | clojurebot | paste is http://paste.lisp.org/new/clojure if it's working |
| 01:43 | durka42 | lisppaste8: is it working? |
| 01:44 | lisppaste8 | cark pasted "doc search stuff" at http://paste.lisp.org/display/74206 |
| 01:44 | technomancy | thanks |
| 01:44 | Cark | you're welcome |
| 01:48 | technomancy | ok, I need to set the namespace before this will work |
| 01:49 | technomancy | at runtime it tries to look it up in clojure.core |
| 01:50 | technomancy | (let [*ns* mire.commands] ...) blows up though; what's the right way to do that? |
| 01:50 | Cark | (doc binding) |
| 01:50 | clojurebot | binding => var-symbol init-expr Creates new bindings for the (already-existing) vars, with the supplied initial values, executes the exprs in an implicit do, then re-establishes the bindings that existed before.; arglists ([bindings & body]) |
| 01:50 | technomancy | in-ns? |
| 01:50 | technomancy | binding blows up the same way |
| 01:51 | Cark | what are you trying to achieve ? |
| 01:51 | ayrnieu | (defn- all-symbols [] "Don't really get all symbols." (meta (vals (list (ns-publics mire.commands))))) |
| 01:51 | technomancy | ayrnieu: that looks perfect |
| 01:52 | ayrnieu | well, that's wrong because it calls meta on a list. |
| 01:52 | technomancy | right, but I get the idea |
| 01:52 | Cark | ,(find-ns 'user) |
| 01:52 | clojurebot | #<Namespace user> |
| 01:52 | Cark | (ns-publics (find-ns 'user)) |
| 01:53 | durka42 | ,(ns-publics 'user) |
| 01:53 | clojurebot | {} |
| 01:54 | ayrnieu | ,(ns-publics 'clojure.core) |
| 01:54 | clojurebot | {sorted-map #'clojure.core/sorted-map, read-line #'clojure.core/read-line, re-pattern #'clojure.core/re-pattern, keyword? #'clojure.core/keyword?, val #'clojure.core/val, *compile-path* #'clojure.core/*compile-path*, max-key #'clojure.core/max-key, list* #'clojure.core/list*, ns-aliases #'clojure.core/ns-aliases, the-ns #'clojure.core/the-ns, == #'clojure.core/==, longs #'clojure.core/longs, special-form-anchor #'clojure. |
| 01:54 | technomancy | ayrnieu: thanks a bunch |
| 01:54 | technomancy | I need to head off though; getting late here |
| 01:54 | durka42 | ,(keys (ns-publics 'clojure.core)) ; human-readable |
| 01:54 | clojurebot | (sorted-map read-line re-pattern keyword? val *compile-path* max-key list* ns-aliases the-ns == longs special-form-anchor instance? syntax-symbol-anchor format sequential? fn? empty dorun time remove-method gensym not= *3 unchecked-multiply doseq bit-or aset-byte if-not hash-set unchecked-dec some nil? string? second keys for *2 long-array cond bit-set fn sorted? ns-unalias ns-publics dosync all-ns long with-open init-pro |
| 01:55 | durka42 | (doc longs) |
| 01:55 | clojurebot | It's greek to me. |
| 01:55 | durka42 | me too, that's why i asked |
| 02:09 | hiredman | http://gist.github.com/51721 <-- I took a stab at (scope ...) |
| 02:16 | Cark | shouldn't you be running the functions backward ? |
| 02:16 | hiredman | ah |
| 02:17 | hiredman | or I could just change the vectors to lists |
| 02:17 | Cark | true |
| 02:18 | hiredman | so fixed |
| 02:19 | hiredman | clojurebot: horizons? |
| 02:19 | clojurebot | Titim gan �ir� ort. |
| 02:19 | hiredman | clojurebot: horizons is http://gist.github.com/51721 |
| 02:19 | clojurebot | Ok. |
| 02:21 | hiredman | ~ seen oudeis? |
| 02:21 | clojurebot | oudeis was last seen joining #clojure, 1 minutes ago |
| 02:22 | hiredman | huh |
| 02:22 | hiredman | I could have sworn I saw him part |
| 02:29 | Cark | ~ seen oudeis? |
| 02:29 | Cark | ~ seen oudeis? |
| 02:29 | clojurebot | oudeis was last seen joining #clojure, 9 minutes ago |
| 02:46 | hiredman | ~ seen mrsolo |
| 02:46 | clojurebot | mrsolo was last seen joining #clojure, 82 minutes ago |
| 02:47 | hiredman | hmmmm |
| 02:57 | yoeljacobsen | Q: I'm trying to use enclojure and when I try to run the automatically generated project I get the following error: <No main class found> |
| 02:57 | yoeljacobsen | Main class is of course configured.. |
| 02:57 | yoeljacobsen | Any idea? |
| 02:58 | lisppaste8 | ayrnieu pasted "RFC: apropos.clj" at http://paste.lisp.org/display/74207 |
| 03:00 | hiredman | yoeljacobsen: what is the exact exception? |
| 03:00 | hiredman | show us some code |
| 03:01 | hiredman | lisppaste8: url? |
| 03:01 | lisppaste8 | To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste. |
| 03:01 | yoeljacobsen | No exception - Netbeans complains for no main class |
| 03:01 | hiredman | oh, well netbeans I know nothing about |
| 05:00 | Lau_of_DK | There's a Clojure to-do list on some Backpack(?) site somehwere, anyone got link ? |
| 05:03 | Lau_of_DK | clojurebot: todo? |
| 05:03 | clojurebot | todo is http://richhickey.backpackit.com/pub/1597914 |
| 05:03 | Lau_of_DK | broken link |
| 05:12 | Lau_of_DK | clojurebot: todo is not what you think it is |
| 05:12 | clojurebot | Roger. |
| 05:12 | Lau_of_DK | clojurebot: todo? |
| 05:12 | clojurebot | todo is not what you think it is |
| 05:12 | Lau_of_DK | Hmm |
| 06:47 | drhz | There's a small typo in API decrtiption for (empty? coll). IS ..(seq x) rather than (not (empty? x)), SHOULD BE: ..(seq? x) rather than (not (empty? x)) |
| 07:52 | leafw | "things supporting seq and stream" --> why not "Flow"? Or Iterable (although this one exists in java, but it *is*) |
| 07:53 | Chouser | drhz: nope. (seq x) is right |
| 07:53 | Lau_of_DK | Chouser: He quit |
| 07:53 | Chouser | oh. so he did. |
| 07:54 | Youhou | Hmm... I think there is a function missing from the zipper API. I need zip/root-loc and it isn't there. I would expect it to behave just like zip/root, but return a location instead of just one node. Am I missing something? |
| 07:55 | Youhou | The reasoning being -- I've done some "modifications" to my tree, now I want to zip up to the top and pass the root to another function which will walk it again. |
| 07:59 | ayrnieu | well, the source is here if you want to add this: http://code.google.com/p/clojure/source/browse/trunk/src/clj/clojure/zip.clj |
| 07:59 | Youhou | sure -- I just wanted to check, perhaps I'm missing something obvious, or perhaps I'm doing something I'm not supposed to. |
| 08:00 | ayrnieu | I think you haven't missed anything. |
| 08:12 | acieroid | hmm |
| 08:12 | acieroid | Is there some example of how extends java classes ? |
| 08:13 | acieroid | because I just found that I have to use gen-class |
| 08:13 | acieroid | but I don't know how |
| 08:21 | karmazilla | acieroid: "have to use gen-class" - means you have tried with proxy but discarded the approach? |
| 08:22 | acieroid | not tried proxy |
| 08:22 | Youhou | Hmm. Should I write to the group (about zip/root-loc) or submit an issue? |
| 08:22 | acieroid | I didn't find any documentation on this topic, except the api |
| 08:24 | karmazilla | acieroid: gen-class, I think, is for when you need to instantiate objects of the class from Java, or control class creation with main methods. |
| 08:25 | Youhou | Is there something that corresponds to CL's #-(and) idiom? I would like to be able to "comment-out" entire forms, instead of lines... |
| 08:25 | acieroid | ok karmazilla |
| 08:25 | karmazilla | ,(doc comment) |
| 08:25 | clojurebot | "([& body]); Ignores body, yields nil" |
| 08:25 | acieroid | I'll look at proxy so |
| 08:28 | Youhou | Thanks, that's what I was looking for. |
| 08:29 | Fib | Is there any way to use a macro with 'apply'? Is the idea of doing so misguided? |
| 08:29 | Youhou | No, that was not what I was looking for. |
| 08:29 | Youhou | I need a reader macro -- something that will disappear into thin air. (comment) won't let me disable function arguments, for example. |
| 08:31 | Youhou | Reading http://clojure.org/reader seems to imply there is nothing of the kind. |
| 08:31 | karmazilla | Fib: use a #() |
| 08:32 | leafw | karmazilla: where is #() documented? |
| 08:32 | Youhou | leafw: http://clojure.org/reader, which I'm reading right now :-) |
| 08:34 | leafw | thanks |
| 08:35 | leafw | as Isuspected, #() is an anonymous function literal ... so that, wrapping a (comment ..), can make it just disappear? |
| 08:36 | clojurebot | svn rev 1232; made eval use ephemeral classloader in all cases |
| 08:36 | Fib | karmazilla: what if I have a variable number of args to apply to, though? |
| 08:37 | karmazilla | yes, I was wondering about that. You can have %& for var-args in #()'s though |
| 08:37 | Youhou | (comment ...) doesn't do what I need -- I want to disable any form within the code, for example one of function arguments. I just want the reader to skip whatever I marked, something that directly corresponds to CL's #-(and) conditional. I would love to see, for example #!() for this. This |
| 08:40 | Fib | karmazilla: yeah, but then I'm left with the original problem, since if I have the varargs in the form of a vector, I still need to apply the macro to the varargs |
| 08:40 | Fib | I suppose there's always eval... |
| 08:43 | karmazilla | maybe the idea really is misguided :) supposedly, the number of arguments is not known until runtime, but by then all macros are expanded |
| 08:47 | Fib | that's what I thought :) |
| 08:50 | Chouser | Youhou: I think something like what you want is planned. |
| 08:50 | Chouser | Youhou: for now perhaps you could write your own macro to do it? |
| 08:52 | Youhou | Chouser: I don't think I can -- it needs to be a reader macro. My macro will return nil and that nil will remain. |
| 08:53 | Chouser | I'm not saying it'd be as general a solution -- your macro would have to wrap the next level out in order to produce the form you need without the nil in it. |
| 08:55 | Youhou | Chouser: then it isn't nearly as convenient :-( -- frankly, it misses the point then, I'd rather reformat the code and use ;; to comment out forms. This really calls for #! or something similar, a built-in reader macro. |
| 08:55 | Youhou | I'm actually surprised no one noticed -- it is such a useful tool when developing code. |
| 08:57 | Chousuke | #! is already a comment though :/ |
| 08:57 | Chousuke | just not what you want. |
| 08:58 | Youhou | It is? That is not documented at http://clojure.org/reader, then. |
| 08:59 | Chousuke | IIRC it was added to make unix-style clojure scripts possible. |
| 09:00 | Youhou | Ouch. I see. Well, then #* or anything else, really, but it has to be short and easy to type, as it is used very often. CL actually doesn't make it very easy with #-(and) |
| 09:03 | Chousuke | have you made a post to the group about this yet? |
| 09:29 | Chouser | as I said, this has come up before -- I believe Rich has said it's a feature he plans to include. |
| 09:39 | Youhou | I will post about this -- and about the zipper issue. |
| 12:19 | BigTom | hi |
| 12:20 | BigTom | I am trying to do something like reduce but my reduce function has more than 2 parameters |
| 12:20 | BigTom | one of the parameters is a map for aggregating stuff |
| 12:20 | BigTom | is there an idiom for this? |
| 12:21 | BigTom | I am trying to avoid loops and mutable structures |
| 12:21 | kotarak | BigTom: it depends on what you want to do. Several aggregating parameters, or several lists, which are traversed in parallel? |
| 12:22 | BigTom | several parameters |
| 12:22 | kotarak | (reduce (fn [[aggr1 aggr2] list-item] ....) [init-aggr1 init-aggr2] the-list) |
| 12:22 | kotarak | Your fn has to return a vector. |
| 12:23 | BigTom | urgh |
| 12:24 | BigTom | give me a minute to parse that |
| 12:24 | kotarak | It uses destructuring in the argument vector. |
| 12:24 | kotarak | ((fn [[a b] x] (+ a b x)) [1 2] 3) => 6 |
| 12:25 | BigTom | ok, thanks |
| 12:26 | BigTom | I am going to go a bit quiet now while I work it through |
| 12:26 | bergermeister | I have a cool but hard slime problem |
| 12:26 | bergermeister | Are there any slime experts online? |
| 12:52 | BigTom | kotarak: thanks, getting there now |
| 12:53 | kotarak | BigTom: good to hear :) |
| 12:53 | kotarak | Do you know about destructuring? |
| 13:00 | BigTom | I know the basics |
| 13:00 | kotarak | Ok. It's a powerfull tool. |
| 13:00 | BigTom | {:keys [:a :b]} etc |
| 13:00 | BigTom | haven't used it on vectors so much |
| 13:01 | BigTom | main problem at the moment is when to pick reduce/for/doseq/doall |
| 13:01 | kotarak | doseq for side-effects w/o return value |
| 13:01 | kotarak | doall for side-effects w/ return value |
| 13:01 | WizardofWestmarc | reduce is pretty straight forward, when you want to condense a list of values down to one in some form or fashion |
| 13:02 | WizardofWestmarc | like adding all of the ints in a list together |
| 13:02 | WizardofWestmarc | or finding the biggest in the list |
| 13:02 | kotarak | reduce to transform a list into something else |
| 13:02 | durka42 | i thought side-effects w/o return is dorun |
| 13:02 | BigTom | I am ok with the basic cases, its aggregating structured data out of list/lists |
| 13:03 | BigTom | I think it is nearly always reduce |
| 13:03 | kotarak | durka42: dorun over a list containing only nils seems ugly to me. But as always: YMMV. |
| 13:04 | kotarak | I prefer (doseq [line lines] (println line)) over (dorun (map #(println %) lines)). |
| 13:05 | durka42 | i agree |
| 13:06 | BigTom | I had to force an evaluation a while back with doall. |
| 13:06 | BigTom | it blew the stack otherwise |
| 13:06 | BigTom | I still haven't worked out why |
| 13:06 | kotarak | dorun/doall might be interesting to get a seq of something depending on a resource. (with-open [stream (open afile)] (doall (map #(do-something-with-line %) (line-seq stream))) or something like that. |
| 13:07 | BigTom | I am trying to get a short version to recreate it |
| 13:20 | BigTom | what is the best way to filter specific values out of a map? |
| 13:21 | durka42 | there is filter, and remove |
| 13:21 | durka42 | for maps dissoc might be useful |
| 13:21 | duck1123 | Ok, I think I'm ready to start writing test cases using test-is, does anyone know where a good example of an ant task that runs all test is? |
| 13:22 | duck1123 | Or better yet, a way to integrate that with emacs |
| 13:22 | Chousuke | ,(hash-map (remove (fn [[k v]] (> v 5)) {:a 6 :b 1 :c 7})) |
| 13:22 | clojurebot | java.lang.IllegalArgumentException: No value supplied for key: ([:b 1]) |
| 13:22 | Chousuke | hmm |
| 13:22 | Chousuke | not quite like that I guess :/ |
| 13:22 | BigTom | I am using filter but I am struggling to get the value |
| 13:23 | BigTom | You get a leaf node as the value back from the map don't you? |
| 13:25 | kotarak | ,(into {} (filter #(> 0 (second %)) {:a 2 :b 0 :c 7})) |
| 13:25 | clojurebot | {} |
| 13:26 | Chousuke | wrong predicate :) |
| 13:26 | kotarak | ,(apply hash-map (filter (fn [[k v]] (> v 5)) {:a 6 :b 1 :c 7})) |
| 13:26 | clojurebot | {[:a 6] [:c 7]} |
| 13:26 | Chousuke | ,(apply hash-map (apply concat (remove (fn [[k v]] (> v 5)) {:a 6 :b 1 :c 7}))) |
| 13:26 | clojurebot | {:b 1} |
| 13:27 | durka42 | ,(into {} (filter second {:a 1 :b 2 :c nil})) |
| 13:27 | clojurebot | {:b 2, :a 1} |
| 13:29 | durka42 | ,(into {} (filter #(> (second %) 0) {:a 2 :b 0 7})) |
| 13:29 | clojurebot | 5 |
| 13:29 | durka42 | huh? |
| 13:30 | durka42 | ,(into {} (filter #(> (second %) 0) {:a 2 :b 0 :c 7})) |
| 13:30 | clojurebot | {:c 7, :a 2} |
| 13:30 | Chousuke | that's: java.lang.ArrayIndexOutOfBoundsException: 5 (NO_SOURCE_FILE:11) |
| 13:30 | durka42 | yes, it is |
| 13:30 | durka42 | my irc client didn't copy the :c smiley |
| 13:32 | BigTom | wow, almost too much information :-) |
| 13:32 | BigTom | I have it now |
| 13:32 | durka42 | breaking news: programmers discover more than one way to do the same thing |
| 13:32 | BigTom | I didn't know about clojurebot |
| 13:32 | durka42 | :) |
| 13:32 | Chousuke | into is nice though. |
| 13:34 | BigTom | Yes it is, though I think my problem works better with the list of vectors |
| 13:34 | BigTom | ,(+ 1 1) |
| 13:34 | clojurebot | 2 |
| 13:34 | BigTom | cool :-) |
| 13:34 | durka42 | (+ 10 10) |
| 13:34 | clojurebot | *suffusion of yellow* |
| 13:35 | durka42 | ~seen kotarak |
| 13:35 | clojurebot | kotarak was last seen in #clojure, 8 minutes ago saying: ,(apply hash-map (filter (fn [[k v]] (> v 5)) {:a 6 :b 1 :c 7})) |
| 13:35 | Chousuke | for some reason, clojurebot has a separate maths module that can't count past 7 |
| 13:35 | Chousuke | (+ 1 2) |
| 13:35 | clojurebot | 3 |
| 13:35 | durka42 | i thought it was 4 |
| 13:35 | Chousuke | ,(+ 7) |
| 13:35 | clojurebot | 7 |
| 13:35 | durka42 | (+ 2 2) |
| 13:35 | clojurebot | 4 |
| 13:35 | Chousuke | (+ 4 4) |
| 13:35 | clojurebot | *suffusion of yellow* |
| 13:35 | durka42 | (+ 2 3) |
| 13:35 | clojurebot | *suffusion of yellow* |
| 13:36 | Chousuke | hmm? :/ |
| 13:36 | durka42 | no trouble with negatives though |
| 13:36 | durka42 | (* 1234 -27) |
| 13:36 | Chousuke | I wonder why the functionality even is there. |
| 13:36 | durka42 | (- 2 1234) |
| 13:36 | clojurebot | -1232 |
| 13:38 | duck1123 | (+ 2 2) => 5 |
| 13:38 | clojurebot | *suffusion of yellow* |
| 13:44 | durka42 | clojurebot: (+ 2 2) is 5 |
| 13:44 | clojurebot | c'est bon! |
| 13:44 | durka42 | clojurebot: (+ 2 2) |
| 13:44 | clojurebot | (+ 2 2) is 5 |
| 13:44 | durka42 | clojurebot: (+ 2 2) is 5, for large values of 2 |
| 13:44 | clojurebot | 'Sea, mhuise. |
| 13:45 | durka42 | ~(+ 2 2) |
| 13:45 | clojurebot | (+ 2 2) is 5, for large values of 2 |
| 13:45 | bergermeister | Exception in thread "AWT-EventQueue-0" java.lang.NoSuchMethodError: clojure.lang.Util.equal(Ljava/lang/Object;Ljava/lang/Object;)Z |
| 13:45 | bergermeister | Current svn has a bug in it. |
| 13:46 | bergermeister | that line should real clojure.lang.util.equals |
| 13:48 | bergermeister | nope, it is fixed |
| 13:54 | duck1123 | clojurebot: (+ 2 2) is <reply>5 (for large values of 2) |
| 13:54 | clojurebot | Ok. |
| 13:54 | duck1123 | (+ 2 2) |
| 13:54 | clojurebot | 4 |
| 13:55 | duck1123 | clojurebot: (+ 2 2) |
| 13:55 | clojurebot | 5 (for large values of 2) |
| 14:24 | BigTom | (reduce (fn [[n p] c] (+ (* n p) c)) 0 [[2 3] [4 5]]) |
| 14:25 | durka42 | ,(reduce (fn [[n p] c] (+ (* n p) c)) 0 [[2 3] [4 5]]) |
| 14:25 | clojurebot | java.lang.UnsupportedOperationException: nth not supported on this type: Integer |
| 14:26 | BigTom | thanks |
| 14:26 | kotarak | The 0 is not a vector. |
| 14:26 | kotarak | you mean probably (fn [c [n p]] ...) |
| 14:27 | BigTom | so I did :-/ |
| 14:28 | BigTom | Cheers :-) |
| 14:32 | Youhou | Ok -- so coming from a CL background, I've been looking for &key. Haven't found it. How do people do without keyword arguments? |
| 14:32 | Youhou | I could probably zip up "& args" into a map and do a destructuring binding -- is there an idiom for that? |
| 14:33 | kotarak | (defn foo [arg1 arg2 & options] (let [{:keys [keyword1 keyword2] :or {keyword1 default1 keyword2 default2}} (apply hash-map options)] ...)) |
| 14:33 | kotarak | (foo val1 val2 :keyword2 bar) |
| 14:34 | clojurebot | svn rev 1233; fixed definline, patch from Chouser |
| 14:34 | Youhou | Right -- but this begs to be turned into a macro -- and I'm puzzled -- am I missing something, or do people think that keyword arguments are not the way to go? Or is such a macro in there somewhere? |
| 14:35 | kotarak | Obviously keyword args aren't use often enough to be a pain. |
| 14:38 | Youhou | Intriguing. Perhaps that's because clojure is still young. After a while you do get libraries with functions that take 40 parameters, and then it becomes unwieldy to use positional arguments. (libraries for fetching with http come to mind) |
| 14:38 | WizardofWestmarc | well as you point out you can cheat by putting a dict as a passed in param |
| 14:39 | WizardofWestmarc | then you just find which values are valid keys in the set and use that to determine what parts they want to do |
| 14:39 | Youhou | I'm not disputing the language design choice -- I'm just surprised that some sort of popular way of implementing keyword args hasn't emerged yet. |
| 14:39 | WizardofWestmarc | not as pretty/obvious on skim as the CL way I admit |
| 14:40 | WizardofWestmarc | well, how many projects of significant size exist on clojure? |
| 14:40 | BigTom | kotarak, durka42 & Chousuke: thanks for the help |
| 14:40 | WizardofWestmarc | because until you have some larger things built on it, stuff like that won't become a common problem. |
| 14:40 | kotarak | BigTom: np |
| 14:40 | danlarkin | Youhou: http://paste.lisp.org/display/69347 |
| 14:40 | BigTom | I have nailed euler problem 5 |
| 14:40 | BigTom | and learned a lot, |
| 14:40 | BigTom | cheers |
| 14:41 | kotarak | BigTom: http://clojure-euler.wikispaces.com SPOILER WARNING! |
| 14:41 | Youhou | danlarkin: oh, cool -- that's exactly the kind of macro I've been thinking about |
| 14:42 | BigTom | Thanks |
| 14:42 | WizardofWestmarc | yeah, lots of spoilers on clojure-euler |
| 14:42 | WizardofWestmarc | but some SLICK code too |
| 14:42 | WizardofWestmarc | I learned a lot looking at some other people's solutions |
| 14:42 | Lau_of_DK | WizardofWestmarc: You talking about my code cracker? :) |
| 14:42 | WizardofWestmarc | like Chouser's way of calculating triangle |
| 14:43 | WizardofWestmarc | err triangle numbers |
| 14:43 | Lau_of_DK | oh... |
| 14:43 | WizardofWestmarc | well, I've only looked at the early ones :P |
| 14:43 | WizardofWestmarc | I don't think I've seen any you posted to the euler wiki yet |
| 14:44 | WizardofWestmarc | I really need to take the time to wrap my head around lazy seqs/etc better |
| 14:44 | WizardofWestmarc | I never realized it could use itself to calculate the value of next w/map |
| 14:45 | durka42 | eh? |
| 14:45 | WizardofWestmarc | you can reference a lazy seq inside it's own definition |
| 14:45 | durka42 | how do you do that? |
| 14:45 | durka42 | i feel like i've wanted to in the past |
| 14:46 | BigTom | do they ever use more then one letter for variables? |
| 14:46 | WizardofWestmarc | lemme find the fib example, since that one is even crazier |
| 14:46 | BigTom | I think my answers look a lot more verbose |
| 14:47 | WizardofWestmarc | this is it: (def fibs (lazy-cons 0 (lazy-cons 1 (map + (rest fibs) fibs)))) |
| 14:48 | Lau_of_DK | WizardofWestmarc: http://clojure-euler.wikispaces.com/Problem+059 This is the only one I was sorta happy with |
| 14:51 | WizardofWestmarc | hm |
| 14:51 | WizardofWestmarc | Lau_of_DK: I like the way you build the combinations set list |
| 14:52 | Lau_of_DK | cool |
| 14:53 | WizardofWestmarc | I have to say, euler's proving an even better way to learn clojure then I'd hoped |
| 14:53 | WizardofWestmarc | really have to dig into the api/clojure-contrib to solve some of them |
| 14:53 | WizardofWestmarc | at least cleanly ;-) |
| 14:53 | BigTom | Yeah (though mine are anything but clean so far :-/ ) |
| 14:53 | sooth | b |
| 14:54 | sooth | sorry |
| 14:54 | Lau_of_DK | WizardofWestmarc: We started clojure-euler partly for fun, and partly to do one-up on the other languages who had attempted the same. Then kotarak went and solved 215 and suddenly we werent playing anymore :) |
| 14:54 | WizardofWestmarc | haha |
| 14:54 | WizardofWestmarc | yeah I noticed 215 was posted |
| 14:54 | kotarak | Lau_of_DK: yeah, beat me! Harder! Harder! |
| 14:54 | WizardofWestmarc | BigTom: I know what you mean, mine haven't been great beyond the super easy ones |
| 14:54 | BigTom | Well, I shall treat that as a challenge... |
| 14:55 | WizardofWestmarc | but they're slowly getting better |
| 14:55 | BigTom | That is my hope too |
| 14:55 | BigTom | I think I'll post me answers so other beginners don't feel intimidated :-) |
| 14:57 | WizardofWestmarc | I've skipped a few problems because I simply don't know a clean enough way to do it to my satisfaction, and I refuse to use the code I see in clojure-euler |
| 14:57 | WizardofWestmarc | like #8 |
| 14:57 | WizardofWestmarc | oh, another one I liked was some of the posted answers for 9 |
| 14:57 | WizardofWestmarc | it's easy to do that one ugly |
| 14:57 | WizardofWestmarc | but holy cow the clean way to do it is sexy as hell |
| 14:59 | BigTom | (I peeked for 3 :-/ but it spoiled the fun so I'm going to have to wait to see the others |
| 15:08 | AWizzArd | rhickey: is there something like a call-arguments-limit for Clojures apply? |
| 15:14 | Chouser | AWizzArd: there's no limit on the size of the seq passed to apply. Is that what you're asking? |
| 15:15 | AWizzArd | yes |
| 15:15 | AWizzArd | of course, the limits of the hardware |
| 15:16 | Chouser | AWizzArd: nope, not even that. |
| 15:16 | AWizzArd | ;-) |
| 15:16 | AWizzArd | Chouser: I wish there were no limits in hardware |
| 15:16 | AWizzArd | but I think you are talking about lazyness |
| 15:17 | Chouser | well, I'm not *completely* joking. I believe the seq passed to apply could be too large to fit in memory all at once. |
| 15:17 | Chouser | but that might not be right. I haven't tested it. |
| 15:18 | AWizzArd | in CL one would for example do (reduce #'+ (loop for i from 1 to 5000 collect i)) |
| 15:18 | Chousuke | well, you can pass infinite seqs to apply |
| 15:18 | Chousuke | so why not. |
| 15:19 | AWizzArd | because if you put apply at the place of reduce the system *might* complain about it: APPLY: too many arguments given to + (clisp, 32-Bit, Windows) |
| 15:19 | Chousuke | ,(apply + (range 5000)) |
| 15:19 | clojurebot | 12497500 |
| 15:19 | Chousuke | ,(apply + (range 500000)) |
| 15:19 | clojurebot | 124999750000 |
| 15:20 | Chousuke | ,(apply + (range 50000000)) |
| 15:20 | AWizzArd | yes |
| 15:20 | Chousuke | hmm |
| 15:20 | clojurebot | 1249999975000000 |
| 15:20 | Chousuke | yay |
| 15:20 | AWizzArd | and the timing does not differ from reduce |
| 15:20 | Chousuke | well, + uses reduce internally |
| 15:22 | AWizzArd | ,(with-out-str (time (apply + (range 5000000)))) |
| 15:22 | clojurebot | "\"Elapsed time: 338.841 msecs\"\n" |
| 15:22 | AWizzArd | ,(with-out-str (time (reduce + (range 5000000)))) |
| 15:22 | clojurebot | "\"Elapsed time: 329.607 msecs\"\n" |
| 15:22 | AWizzArd | same |
| 15:33 | Chousuke | you don't need the with-out-str |
| 15:34 | AWizzArd | (time nil) |
| 15:34 | AWizzArd | ,(time nil) |
| 15:34 | clojurebot | "Elapsed time: 0.09 msecs" |
| 15:34 | clojurebot | svn rev 1234; Made Atream.Iter an IFn, so can act as generator |
| 15:35 | AWizzArd | What does that mean? |
| 15:35 | AWizzArd | was is an Atream.Iter? |
| 15:35 | AWizzArd | what is an.. |
| 15:36 | rhickey | AWizzArd: streams stuff |
| 15:38 | Lau_of_DK | rhickey: All the underlying theory of this streams vs seqs vs nil punning vs speed, where can I go read up on it ? |
| 15:38 | rhickey | Lau_of_DK: there's no single place |
| 15:39 | Lau_of_DK | oh - you wanna do a short webinar then, Ive got Yugma open :) |
| 15:39 | Chouser | there are still decisions to be made, aren't there? A bit early to document very heavily |
| 15:40 | rhickey | Chouser: right, and the issues are subtle, but it has been discussed here and on the group |
| 15:40 | Lau_of_DK | Chouser: I just meant the theory governing these decisions, nothing to do with docs |
| 15:40 | Chouser | Lau_of_DK: If you just want to use it when it's done, I'd wait patiently until it's intergrated into trunk. Then people can work up docs, examples, etc. |
| 15:41 | Lau_of_DK | Chouser: I still dont want docs / examples, I just want to understand the power of streams in comparison to what were doing now, and why this is contrary to nil-punning, that type of stuff |
| 15:41 | Chouser | if you want in on it earlier than that, I think it's reasonable to expect to have to exert a bit more effort. Search the group, the IRC logs, read http://clojure.org/streams |
| 15:41 | Lau_of_DK | I got that streams will give us something like continuations, but thats it |
| 15:42 | Chouser | hm, I don't think that's right. |
| 15:45 | Chousuke | streams are like unix pipes aren't they. you can only read the data once, and then do whatever you want with it, and pass it forward (or not) |
| 15:47 | Lau_of_DK | Is this in anyway connection with LFE? |
| 15:47 | Chousuke | I don't think so |
| 15:47 | Chousuke | LFE was an alternative model for doing the stream stuff, but I think rhickey scrapped it. |
| 15:49 | Chousuke | which is good, I think, since I was completely unable to understand how they worked :P |
| 15:53 | hiredman | no |
| 15:54 | hiredman | LFE is for safe resoure usage |
| 15:56 | hiredman | ~seen rhickey |
| 15:56 | clojurebot | rhickey was last seen in #clojure, 16 minutes ago saying: Chouser: right, and the issues are subtle, but it has been discussed here and on the group |
| 15:58 | AWizzArd | So, LFE won't make it into Clojure? |
| 16:03 | Chouser | I believe that's correct. |
| 16:06 | Chouser | BDFL said "LFE offered resource management and safety, |
| 16:06 | Chouser | I think scope + safe streams is easier, and definitely faster" |
| 16:07 | AWizzArd | And that Atream.Iter stuff is about this issue? |
| 16:09 | Chouser | That's part of "safe streams", yes. |
| 16:15 | Chousuke | It's supposed to be AStream though :) |
| 16:17 | StartsWithK | Chouser: what do BDFL and LFE acronyms stand for? |
| 16:18 | Chouser | LFE is Left Fold Enumerator |
| 16:18 | Chouser | BDFL is Benevolent Dictator For Life, a.k.a. Rich. |
| 16:18 | StartsWithK | :) |
| 16:19 | StartsWithK | what are my options for parser construction under java? |
| 16:20 | StartsWithK | are there any parser combinators like spirit/yard? |
| 16:20 | Chousuke | there's fnparse on github |
| 16:22 | hiredman | http://github.com/hiredman/clojurebot/blob/fe80fe2b641b3b8aba6c5ee4064a61f0737c2b37/hiredman/horizon.clj <-- speaking of scope |
| 16:24 | durka42 | The Universe has ended unexpectedly: RuntimeException: Naked Singularity. We apologize for any inconvenience. (A)bort, (R)etry, (I)gnore, Report to (G)od |
| 16:30 | stuarthalloway | Chouser: I have added :dir and :env options to shell-out in SVN r413. Also unit tests for the helper functions (but not for sh itself). |
| 16:31 | Lau_of_DK | stuarthalloway: Shell-out was your way of getting the current dir? |
| 16:31 | stuarthalloway | Chouser: I am going to let my laptop out of my sight for several hours, but if you find anything that irritates you send me an email or castigate me on the mailing list and I will fix it later tonight. :-) |
| 16:31 | stuarthalloway | Lau_of_DK: shell-out is in contrib, and provides a simple "sh" function |
| 16:32 | Lau_of_DK | k |
| 16:32 | stuarthalloway | Lau_of_DK: I have added the ability to bind a dir for multiple operations, so I can get some rake-like goodness going in lancet. |
| 16:33 | Lau_of_DK | ok :) |
| 16:36 | Chousuke | btw, isn't the new stream-utils.clj in contrib misnamed? |
| 16:36 | Chousuke | should be stream_utils.clj |
| 17:21 | cconstantine | Newbie to clojure here... I have two vectors ([1 2 3] [1 2 3]) and I want to add them together to get a vector like [2 4 6]. How would I go about doing that? |
| 17:22 | Chousuke | ,(map + [1 2 3] [1 2 3]) |
| 17:22 | clojurebot | (2 4 6) |
| 17:22 | Chousuke | or ,(into [] (map + [1 2 3] [1 2 3])) |
| 17:22 | Chousuke | If you really want a vector |
| 17:22 | cconstantine | I knew it was something stupid simple like that, thanks :) |
| 17:24 | Chousuke | generally though, forcing things into concrete data structures is not as clojurey as just using seqs |
| 17:25 | Chouser | ,(vec (map + [1 2 3] [1 2 3])) |
| 17:25 | clojurebot | [2 4 6] |
| 17:25 | Chousuke | right, that too :p |
| 17:26 | Chouser | ;-) |
| 17:30 | AWizzArd | rhickey: would it be difficult to put & rest parameters into a vector instead of a list? |
| 17:30 | Chousuke | AWizzArd: yes, as rest can be infinite. |
| 17:30 | Chousuke | it's a seq, not a list. |
| 17:31 | AWizzArd | ok |
| 17:31 | AWizzArd | for macros it would be nice though, as it could reduce time for debugging |
| 17:32 | Chousuke | well you can always do (let [rest (vec rest)] ...) |
| 17:32 | AWizzArd | in several cases where a macro has a & rest parameter and one wants to go through that sequence the typical pattern is '~rest |
| 17:32 | AWizzArd | but thousands of Clojurists will do ~rest at first, without quoting it |
| 17:32 | Chousuke | '~rest? why? :/ |
| 17:33 | AWizzArd | (map identity 'rest) ==> (map identity (1 2 3)) ==> Can't call 1 |
| 17:33 | AWizzArd | uhm, wrong |
| 17:33 | AWizzArd | `(map identity ~rest) ==> (map identity (1 2 3)) ==> Can't call 1 |
| 17:33 | Chousuke | I'd use ~@(map identity rest) |
| 17:33 | AWizzArd | but `(map identity '~rest) ==> (map identity '(1 2 3)) ==> (1 2 3) |
| 17:33 | Chousuke | or maybe just ~(map identity rest) |
| 17:34 | AWizzArd | you don't always want to do this |
| 17:34 | Chousuke | well, true. |
| 17:34 | AWizzArd | it's not really a big issue |
| 17:34 | AWizzArd | I just did not think about this infinity thing |
| 17:35 | Chousuke | yeah, your code would get quite bloated if you expanded an infinite list :/ |
| 17:35 | AWizzArd | otherwise, if it would have been no problem to put the & rest into a vector one could have thought about it. Would probably not break code |
| 17:36 | AWizzArd | Chousuke: well, if your box has infinite memory this may not be a problem anymore |
| 17:36 | Chousuke | or if you could have lazy code. |
| 17:37 | Chousuke | something that appears in the source file only when it's really read |
| 17:37 | AWizzArd | nice |
| 18:11 | danlarkin | is there a way to get all "handlers" for a multimethod? |
| 18:12 | Chouser | (methods print-method) |
| 18:12 | Chouser | it's new! |
| 18:12 | danlarkin | perfect! |
| 18:16 | red_fish_ | ,(apply (fn [& rest] (println (first rest))) (repeat "hello world!")) |
| 18:16 | clojurebot | hello world! |
| 18:18 | Chousuke | :) |
| 18:24 | hiredman | clojurebot does not deal with newlines well |
| 18:31 | durka42 | i noticed that when i tried to sendMsg-who with \n's in it it was displayed as one message |
| 18:33 | hiredman | yeah there is some stuff to strip newlines |
| 18:34 | durka42 | i didn't know if that is just an irc custom |
| 18:34 | durka42 | is it better to send as multiple messages? |
| 18:35 | hiredman | I dunno |
| 18:49 | Chouser | the irc wire protocol is newline-separated, I believe. |
| 19:15 | dreish | There's not much need for ' in clojure, is there? |
| 19:15 | cooldude127 | quote? |
| 19:15 | dreish | yes |
| 19:15 | cooldude127 | why because of literal vector syntax? |
| 19:15 | dreish | That and keywords, I think. |
| 19:16 | danlarkin | dreish: it's still useful sugar |
| 19:16 | dreish | Oh, certainly. I can't imagine a Lisp without it. |
| 19:16 | dreish | I just realized after finishing a 600-line lib that I hadn't used it once. |
| 19:16 | hiredman | heh |
| 19:17 | cooldude127 | lol |
| 19:37 | danlarkin | ,(var (val (first (methods print-method)))) |
| 19:37 | clojurebot | java.lang.ClassCastException: clojure.lang.PersistentList cannot be cast to clojure.lang.Symbol |
| 19:38 | danlarkin | :( how do I accomplish that |
| 19:39 | hiredman | ,(methods print-method) |
| 19:39 | clojurebot | {nil #<core$fn__5228 clojure.core$fn__5228@13bedc4>, clojure.lang.IPersistentMap #<core$fn__5322 clojure.core$fn__5322@1ec4535>, java.lang.Number #<core$fn__5246 clojure.core$fn__5246@4b62a7>, java.lang.Class #<core$fn__5370 clojure.core$fn__5370@88e83d>, java.lang.String #<core$fn__5305 clojure.core$fn__5305@1900f17>, java.util.regex.Pattern #<core$fn__5379 clojure.core$fn__5379@26807f>, clojure.lang.Symbol #<core$fn__52 |
| 19:39 | hiredman | uh |
| 19:40 | hiredman | you can't |
| 19:40 | hiredman | it is all function objects |
| 19:40 | hiredman | what are you trying to do? |
| 19:40 | danlarkin | I want to get metadata for one of the methods |
| 19:41 | danlarkin | for my own function, not print-method, that's just for example |
| 19:41 | hiredman | matedata is attached to the multimethod var |
| 19:42 | hiredman | the defmethod stuff have no vars and no metadata |
| 19:42 | hiredman | unlessyou do something weird and attach metadata to the function object (dunno if that is possible) |
| 19:42 | danlarkin | Oh. damn. |
| 19:42 | danlarkin | Hmmmmm |
| 19:43 | danlarkin | it would really be nice if the individual methods were allowed metadata |
| 19:43 | hiredman | *shrug** |
| 19:55 | Chouser | I think it'd be nice to be able to put metadata on Fn objects, but that's apparently a bit tricky to accomplish. |
| 20:00 | danlarkin | metadata on defmethods would be perfect |
| 20:00 | Chouser | danlarkin: what specific metadata are you looking for? |
| 20:04 | danlarkin | well I'd like each function attaching itself to the multimethod to define a :help key for printing to the command line |
| 20:05 | AWizzArd | What is Clojures equivalent to CLs subseq? (subseq '(10 20 30 40 50 60 70) 3 6) ==> (40 50 60) |
| 20:05 | Chouser | hm... you could write an alternative to defmethod that instead of adding a fn to the table, adds a Var instead. |
| 20:06 | hiredman | ,(doc subseq) |
| 20:06 | clojurebot | "([sc test key] [sc start-test start-key end-test end-key]); sc must be a sorted collection, test(s) one of <, <=, > or >=. Returns a seq of those entries with keys ek for which (test (.. sc comparator (compare ek key)) 0) is true" |
| 20:06 | Chouser | Vars, when called, deref and call their value, so it ought to work transparently, but you'd have a place to hang some extra meta-data. |
| 20:06 | AWizzArd | yes, I've already seen that hiredman. That is not the equivalent. |
| 20:06 | hiredman | I see |
| 20:07 | Chouser | AWizzArd: (take 3 (drop 6 myseq)) |
| 20:07 | AWizzArd | I need something like subvec, but for lists |
| 20:07 | hiredman | I just knew there was something called subseq, and wanted to see what the difference is |
| 20:07 | Chouser | oh, (take 3 (drop 3 myseq)) I guess |
| 20:08 | danlarkin | Chouser: here's the body of defmethod: `(. ~multifn addMethod ~dispatch-val (fn ~@fn-tail))) |
| 20:08 | Chouser | danlarkin: yes |
| 20:08 | AWizzArd | Chouser: oki, that would do it, thx |
| 20:33 | danlarkin | lisppaste8: url |
| 20:33 | lisppaste8 | To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste. |
| 20:33 | lisppaste8 | danlarkin pasted "defmethod using vars" at http://paste.lisp.org/display/74247 |
| 20:34 | danlarkin | Chouser: there's my attempt |
| 20:34 | danlarkin | kinda works |
| 20:34 | Chouser | heh |
| 20:34 | Chouser | "kinda"? |
| 20:34 | danlarkin | well it doesn't get the metadata I assign |
| 20:34 | danlarkin | but it does have :ns and :file and :line etc |
| 20:34 | Chouser | ah |
| 20:38 | Chouser | it might be easiest to accept another arg for the meta-map |
| 20:38 | Chouser | like defn does |
| 20:38 | Chouser | otherwise, if you want to use #^{} before the multifn, you might be able to extract the metadata from that symbol and apply it to the var |
| 20:39 | danlarkin | yeah I'm looking at the definition of defn now |
| 20:56 | Chouser | greatest-by and greatest already differ only by a predicate, but I guess always providing 'identity' as a first arg for the common case of would be a bit annoying. |
| 21:00 | Chouser | having the defaults act like all-* and using 'first' when you only want one would be sligtly less memory efficient if there are lots of equally-maximal values. Would that be acceptible, or is the goal of reducing the number of global vars not sufficent? |
| 21:03 | gnuvince_ | Chouser: I guess it depends; if it stays in its own module, I don't see the problem. |
| 21:04 | gnuvince_ | Also, I'd would prefer if I only had to write (greatest x y) instead of (first (greatest identity x y)) |
| 21:04 | Chouser | heh. yeah. |
| 21:06 | gnuvince_ | I looked at it last night, and the only way to reduce the number of functions is to make the interface more awkward (IMO) |
| 21:06 | Chouser | Has Jason Wolfe responded to your code at all? |
| 21:06 | gnuvince_ | no |
| 21:07 | Chouser | I agree the number of functions is not a problem if it stays in its own lib |
| 21:08 | Chouser | having a whole lib for these seems a little extravagant. I guess it's not a big problem yet. |
| 21:08 | gnuvince_ | It doesn't really fit into any other existing library |
| 21:12 | aperotte | Chouser: I noticed your discussion on google groups about accessing this in gen-class and setting things post-construction. Has there been any more talk about how to get around those constructor issues? |
| 21:39 | danlarkin | Hm... (my-defmethod manager-dispatch :default #^{:foo 'bar} [& args] (println args)) is very weird, the my-defmethod macro doesn't get passed the metadata map... it's like I didn't type it |
| 21:42 | Chouser | passed using #^{} or just {} ? |
| 21:43 | danlarkin | #^{} |
| 21:43 | cooldude127 | danlarkin: that probably won't work |
| 21:43 | cooldude127 | it will try to attach that map to the thing after it |
| 21:44 | cooldude127 | use a plain map |
| 21:44 | danlarkin | but it works with defn :( |
| 21:44 | Chouser | it gets attached to the following symbol |
| 21:44 | cooldude127 | exactly |
| 21:45 | Chouser | try (prn (meta muti-name)) in there somewhere |
| 21:46 | danlarkin | Hm. yep, gets attached to the thing after it |
| 21:47 | danlarkin | so I guess (my-defmethod #^{:foo 'bar} manager-dispatch :default [& args] (println args)) should be the syntax? |
| 21:52 | gnuvince_ | Any of you guys actually works with Clojure? |
| 22:02 | hiredman | huh? |
| 22:02 | Chouser | you mean get paid for writing Clojure code? |
| 22:06 | hiredman | I often find myself writing clojure while I am work... |
| 22:07 | LordOfTheNoobs | At work and for work tend to be somewhat different things of course. :) |
| 22:07 | hiredman | indeed |
| 22:09 | gnuvince_ | Chouser: yeah |
| 22:25 | arohner | I had a totally random idea, that sounded kind of cool |
| 22:25 | cooldude127 | do tell |
| 22:26 | gnuvince_ | indeed |
| 22:26 | arohner | let's say I have a function named foo, that I want to do some argument checking, and the arguments are such that it can be done at compile time |
| 22:26 | arohner | I could make a macro that shadows foo, does the argument checking and then calls the fn-foo, right? |
| 22:27 | arohner | i.e. (defn foo ... ) |
| 22:27 | hiredman | no |
| 22:27 | hiredman | macros and functions share a common namespace |
| 22:27 | arohner | hiredman: why not? |
| 22:28 | hiredman | calling foo inside a macro called foo would just be a recursive macro |
| 22:28 | hiredman | in clojure macros are functions with special metadata |
| 22:29 | arohner | could I rename the old function during the macro call? |
| 22:29 | hiredman | no |
| 22:29 | hiredman | because creating the macro clobbers the function |
| 22:31 | arohner | maybe it would require an extra step, but this still seems possible |
| 22:31 | hiredman | :P |
| 22:31 | arohner | because wrapping fns is easy and well known |
| 22:31 | arohner | (defn foo ... ) |
| 22:32 | arohner | (compile-check foo (assert-args ...)) |
| 22:32 | arohner | where compile check is a macro that takes the name of an existing defn |
| 22:32 | hiredman | *shrug* |
| 22:32 | arohner | it would move foo to a new name, and then create a new macro named foo |
| 22:32 | hiredman | the thing is |
| 22:33 | orange80a | can anybody recommend a good Clojure tutorial for an experience java programmer who knows nothing about lisp-related languates? |
| 22:34 | hiredman | function application happens at a different stage then macro expansion |
| 22:34 | arohner | after, right? |
| 22:35 | hiredman | so really you want another function |
| 22:35 | hiredman | a macro would do the swapping sure |
| 22:35 | hiredman | but the assert stuff you would need another function |
| 22:35 | arohner | I was looking to use a macro to get 'compile time checking', in the case where the arguments can be validated at compile time |
| 22:36 | hiredman | not gonna happen |
| 22:36 | arohner | oh, ok, I see the problem |
| 22:36 | arohner | even if the macro expanded to everything I want, that code still won't get run until my function is called at run time |
| 22:38 | ayrnieu | Hedgehog had a special form that would generate an error if it survived macroexpansion. |
| 22:38 | LordOfTheNoobs | clojurebot: what is tutorial? |
| 22:38 | clojurebot | Titim gan �ir� ort. |
| 22:39 | ayrnieu | orange, you could try running a scheme tutorial by clojure. You'll need to do a bit of translation. |
| 23:37 | technomancy | dang; scala and clojure are neck-and-neck on github |
| 23:37 | technomancy | their book isn't even in beta yet though; weak sauce! |
| 23:43 | gnuvince_ | technomancy: they got a few books out |
| 23:43 | gnuvince_ | http://www.amazon.com/s/ref=nb_ss_gw?url=search-alias%3Daps&field-keywords=scala&x=0&y=0 |
| 23:44 | technomancy | oh; I thought the prags' one was the first |
| 23:44 | technomancy | gnuvince_: that's only two books. one of them is out of stock, and one of them is pre-order. |
| 23:45 | technomancy | clojure wins again! |
| 23:46 | technomancy | heh... "Programming Scala" and "Programming in Scala"... these guys should communicate with each other |