2009-03-08
| 01:07 | brennanc | I have a function that is passed like (my-func :key1 "val1" :key2 "val2) and want all the params to show up in a map, how do I get them to show up as map without passing it as a map? |
| 01:08 | cmvkk | you could do [& args] as the arglist, then call (apply hash-map args) I guess |
| 01:09 | brennanc | yup, hash-map was what I was looking for. thanks |
| 01:09 | hiredman | ... |
| 01:10 | hiredman | you could just (myfunc {:key1 "val1" :key2 "val2"}) |
| 01:10 | brennanc | yes, but the less typing I have to do to call it the better |
| 01:11 | brennanc | want to make it as convenient as possible |
| 01:13 | hiredman | why not leave out the keys then? |
| 01:14 | Raynes | { isn't that hard to type is it? } |
| 01:15 | brennanc | the order may be different and all of them are optional |
| 01:15 | hiredman | Raynes: half as hard if your editor automagically inserts the closing bracket |
| 01:16 | brennanc | the docstring of my defn is not showing up. Do I need to do something special so I can see it when I do (doc my-func)? |
| 01:16 | hiredman | pastbin |
| 01:17 | brennanc | http://paste.lisp.org/display/76650 |
| 01:17 | Raynes | brennanc: (defn my-func "doc goes here" [] (println (doc my-func))) |
| 01:18 | brennanc | oops |
| 01:18 | Raynes | The documentation goes before the parameters vector. |
| 01:20 | Raynes | (doc ..) was the best idea ever. |
| 01:20 | clojurebot | Gabh mo leithsc�al? |
| 01:20 | brennanc | yup, doc definitely helps me learn a lot |
| 01:20 | brennanc | is there something to list all functions inside a namespace? |
| 01:21 | hiredman | http://clojure.org/namespaces |
| 01:22 | hiredman | ,(ns-interns *ns*) |
| 01:22 | clojurebot | {} |
| 01:22 | hiredman | ,(ns-interns 'clojure.core) |
| 01:22 | clojurebot | {sorted-map #'clojure.core/sorted-map, read-line #'clojure.core/read-line, re-pattern #'clojure.core/re-pattern, keyword? #'clojure.core/keyword?, asm-type #'clojure.core/asm-type, 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/==, generate-class #'clojure |
| 01:22 | hiredman | that is everything def'ed in a namespace |
| 01:23 | Raynes | Oh that's useful. |
| 01:23 | brennanc | cool |
| 01:23 | Raynes | brennanc: This is why they call LISP "Interactive programming." |
| 01:23 | brennanc | sometimes I need to find a function and suspect one exists. that will help me find it. |
| 01:23 | hiredman | (doc find-doc) |
| 01:23 | clojurebot | Prints documentation for any var whose documentation or name contains a match for re-string-or-pattern; arglists ([re-string-or-pattern]) |
| 01:24 | brennanc | that one isn't as useful unless you already know what it is called |
| 01:24 | brennanc | I tried to find stuff in a namespace using that one already |
| 01:24 | hiredman | brennanc: it takes a regex |
| 01:24 | Raynes | brennanc: If you know regex it's can find virtually anything. |
| 01:24 | hiredman | (find-doc "ns") |
| 01:25 | Raynes | ,(find-doc "ns") |
| 01:25 | clojurebot | ------------------------- clojure.set/index ([xrel ks]) Returns a map of the distinct values of ks in the xrel mapped to a set of the maps in xrel with the corresponding values of ks. ------------------------- clojure.set/join ([xrel yrel] [xrel yrel km]) When passed 2 rels, returns the rel corresponding to the natural join. When passed an additional keymap, joins on the corresponding keys. --------------------- |
| 01:25 | brennanc | but only by name, not by category or by namespace |
| 01:26 | brennanc | doesn't help you find anything really unless it has some keyword you are looking for in the name |
| 01:27 | hiredman | actually it looks through the doc string too |
| 01:27 | Raynes | Man, you said that just as I typed the final word of it... |
| 01:27 | brennanc | cool |
| 03:31 | dcnstrct | I have two lists and I'd like to create a 3rd list out of only the items which are found in both lists |
| 03:31 | dcnstrct | what function would work best for this ? |
| 03:33 | dcnstrct | ("foo" "bar" "baz") ("foo") result should be: ("foo") |
| 03:35 | cmvkk | look at sets maybe |
| 03:36 | dcnstrct | oh good idea, just add everything to a set and it will automatically remove the dups |
| 03:36 | cmvkk | you want the intersection of the lists, though |
| 03:37 | cmvkk | ,(intersection #{'foo 'bar 'baz} #{'foo}) |
| 03:37 | clojurebot | java.lang.Exception: Unable to resolve symbol: intersection in this context |
| 03:37 | dcnstrct | oh yah you're right |
| 03:37 | cmvkk | hmm, that doesn't work? |
| 03:37 | hoeck | ,(doc clojure.set/intersection) |
| 03:37 | clojurebot | "([s1] [s1 s2] [s1 s2 & sets]); Return a set that is the intersection of the input sets" |
| 03:37 | cmvkk | oh yeah, it's in its own namespace. |
| 03:37 | leafw | the mighty set namespace. |
| 03:38 | dcnstrct | perfecto, thnx gentlemen |
| 03:43 | dcnstrct | is there a simple way to create a set from a list ? |
| 03:43 | hiredman | ,(set '(a b c d)) |
| 03:43 | clojurebot | #{a c b d} |
| 03:43 | dcnstrct | durrr |
| 03:43 | dcnstrct | thnx |
| 03:47 | leafw | by the way I don't think I've ever seen the clojure.set/index fn used or explained |
| 03:48 | leafw | may anybody care to produce an example of usage |
| 03:57 | hoeck | ,(clojure.set/index '#{{:name clojure :runtime jvm} {:name java :runtime jvm} {:name c :runtime linux}} '(:runtime)) |
| 03:57 | clojurebot | {{:runtime jvm} #{{:runtime jvm, :name clojure} {:runtime jvm, :name java}}, {:runtime linux} #{{:runtime linux, :name c}}} |
| 04:00 | hoeck | leafw: it's a like the sql group-by statement |
| 04:01 | leafw | thanks hoeck |
| 04:01 | hoeck | ops, i mean "its a bit like .." |
| 04:46 | Drakeson | how does the "parametrized" sql query work? specifically, I should not need escaping when I use, for instance, ["title=?" title] as the parametrized query, right? |
| 04:55 | Drakeson | actually, nevermind. it wasn't c.c.sql's fault. |
| 05:54 | cgray | hi, is the preferred way to access the key of a map (map key) or (key map)? |
| 05:54 | cgray | (in terms of speed I mean) |
| 05:57 | hoeck | cgray: (map key) should be a little bit faster, as it it implemented as a method of the map and directly calls (.valAt map key) |
| 05:57 | cgray | hoeck: okay, thanks... that seems more intuitive for me to write anyway |
| 05:58 | hoeck | whereas (key map) calls RT/get |
| 05:58 | hoeck | gotta go |
| 06:17 | Lau_of_DK | clojurebot: madison? |
| 06:17 | clojurebot | Pardon? |
| 06:17 | Lau_of_DK | clojurebot: where is madison? |
| 06:17 | clojurebot | excusez-moi |
| 06:17 | Lau_of_DK | Does anyone know where/if danlarking upped Madison Square Clabango ? |
| 06:56 | leafw | is there any way to do "unquote splicing" in javascript? Just wondering. |
| 06:56 | leafw | short of eval. |
| 07:06 | Lau_of_DK | Guys - Is there a firefox addon, or a stand-alone tool for linux, which is good for testing the stability of websites? I need to apply a load of ~500 hits / hour, and see how the server handles that |
| 07:08 | Chousuke | Lau_of_DK: while true; do wget website; done ? :P |
| 07:08 | Lau_of_DK | I'll need some throttling and statistics |
| 07:09 | Chousuke | throttling is easy... statistics might be trickier :) |
| 07:10 | hiredman | 500 hits an hour sounds pretty low |
| 07:10 | hiredman | anyway, forget using firefox for that sort of thing |
| 07:10 | Lau_of_DK | k |
| 07:11 | hiredman | you want something http_load |
| 07:11 | Lau_of_DK | I can write it up very quickly in clojure, but I wouldnt bother if there was already a tool for it |
| 07:11 | hiredman | http://www.acme.com/software/http_load/ |
| 07:12 | Lau_of_DK | thanks big guy |
| 07:21 | Lau_of_DK | ./http_load -parallel 5 -fetches 1200 -verbose urls |
| 07:21 | Lau_of_DK | --- 60.0027 secs, 868 fetches started, 863 completed, 5 current |
| 07:21 | Lau_of_DK | 1200 fetches, 5 max parallel, 3.9144e+06 bytes, in 82.2166 seconds |
| 07:21 | Lau_of_DK | 3262 mean bytes/connection |
| 07:21 | Lau_of_DK | 14.5956 fetches/sec, 47610.8 bytes/sec |
| 07:21 | Lau_of_DK | msecs/connect: 0.31139 mean, 9.771 max, 0.047 min |
| 07:21 | Lau_of_DK | msecs/first-response: 335.476 mean, 1039.42 max, 115.676 min |
| 07:21 | Lau_of_DK | HTTP response codes: |
| 07:21 | Lau_of_DK | code 200 -- 1200 |
| 07:21 | Lau_of_DK | |
| 07:21 | Lau_of_DK | Pretty descent statistics |
| 07:33 | Lau_of_DK | Whats the way to go,when you want to manage a thread-pool with Clojure? |
| 07:53 | Lau_of_DK | Wasnt there a HTTP client in contrib at one point? |
| 07:55 | ayrnieu | Lau - well, clojure comes with two threadpools. You could extend that mechanism to make it more general, user-controllable, or you could copy it in part. |
| 07:55 | Lau_of_DK | As I understand, 'send' will dispatchs only as many agents as makes sense on your system in regards to performance right? |
| 07:56 | kotarak | I got the impression. |
| 07:56 | Lau_of_DK | Yea - So that would be good for me, but I'd want to know how many were active at every point |
| 08:03 | ayrnieu | Lau - 'send' uses a threadpool of size determined by the number of processors you have; send-off uses an expandable theradpool. |
| 08:03 | Lau_of_DK | k |
| 08:04 | ayrnieu | (inc Runtime.getProcessors) or something. |
| 08:05 | Lau_of_DK | Regarding the HTTP client in contrib - anybody know where it went/is? |
| 08:21 | eivindgl | I'm learning clojure and I'm trying to get an overview of the contrib library. what are the options? there's this site http://clojure.org/libraries, but I find it somewhat lacking (at least for me) |
| 08:22 | eivindgl | is it possible to browse a library from the repl, something like in python? |
| 08:30 | fyuryu | eivindgl: yes, you just have to require/use it (or import it, if it's a java library) |
| 08:31 | Lau_of_DK | That doesnt really make it 'browseable' does it? |
| 08:32 | ayrnieu | eivindgl - what does python do? |
| 08:32 | fyuryu | Lau_of_DK: not sure what "browseable" actally means, I thought about doing (doc fn-name) and trying things out |
| 08:33 | eivindgl | ayrnieu, I can import a library and then read general information about it. as in (use '[clojure.contrib]) (doc clojure.contrib) |
| 08:33 | eivindgl | I want to check if there's any procedure that finds the prime factors of a given number, how would I proceed? |
| 08:34 | ayrnieu | useful, possible, but not practiced. |
| 08:35 | ayrnieu | eivindgl - (find-doc "prime") (apropos "prime") [after you write that], ( cd ~/foo/clojure-contrib; find .|grep clj|xargs egrep prime ) |
| 08:38 | eivindgl | ayrnieu: I find-doc and apropos was very useful indeed. thanks! |
| 08:58 | jwinter_ | ,(doc ns-map) |
| 08:58 | clojurebot | "([ns]); Returns a map of all the mappings for the namespace." |
| 08:58 | jwinter_ | ns-map doesn't have the prettiest output, but you could use it to write your own code to browse libraries |
| 10:24 | te | How difficult would it be to interop with Java by using JRuby to get to the JVM |
| 10:28 | Chouser | te: http://groups.google.com/group/clojure/browse_thread/thread/41e811c158d7881f/b31dc456fb5280ed |
| 10:36 | te | Chouser: whoa |
| 10:41 | Chouser | te: ? |
| 10:42 | lisppaste8 | Lau pasted "Time?" at http://paste.lisp.org/display/76656 |
| 10:42 | Lau_of_DK | Is it due to the opening of the stream, or is there something Im not getting about time? |
| 10:42 | te | Chouser: that's cool |
| 10:42 | Chouser | te: oh. good. :-) first google hit on "clojure jruby" |
| 10:43 | te | d'oh |
| 10:43 | te | i just assumed that was a crazy idea |
| 10:43 | te | plus there isn't a whole lot on clojure yet, so i dont think to google things like that i guess |
| 10:44 | Lau_of_DK | look Chouser, now you made him get all defensive :) |
| 10:44 | te | lol |
| 10:44 | te | i jsut dont wanna be a pain in the ass in here |
| 10:44 | te | just* |
| 10:45 | Lau_of_DK | Dont worry, questions belong in here, no matter their level .) |
| 10:46 | te | Lau_of_DK: do you have a project suggestion? I tried messing with compojure but I'm still a little bewildered, and iat the same time anxious to make something neat |
| 10:47 | Lau_of_DK | Compojure is very cool - But danlarking is soon-to-launch 'Madison Square Clabango' which is a full port of Django to Clojure - I really have high hopes for it |
| 10:48 | te | whoa, dude. |
| 10:48 | te | That's huge |
| 10:48 | Lau_of_DK | Yea - He rewrote it from scratch |
| 10:48 | Lau_of_DK | As far as I understood |
| 10:49 | te | Lau_of_DK: do you have the place he upped it to? |
| 10:49 | te | i googled it and found you hunting, have you gotten ahold of it? |
| 10:49 | Lau_of_DK | Im not sure he upped it yet |
| 10:49 | Lau_of_DK | Ask him tonight, I think he'll check in, in a few hours |
| 10:50 | Lau_of_DK | Chouser: Do you get my time-example? |
| 10:54 | Lau_of_DK | nvm., its the stream opening and the url, that takes alot of time apparantly |
| 10:54 | Lau_of_DK | first hit on google "clojure time" :) |
| 11:01 | te | Lauwhat's his nick? |
| 11:09 | Chouser | an instance of B (derived from A) cannot access protected members of any instance of A other than itself. :-( |
| 11:10 | te | clojurebot: haskell |
| 11:10 | clojurebot | Yo dawg, I heard you like Haskell, so I put a lazy thunk inside a lazy thunk so you don't have to compute while you compute. |
| 11:42 | Chouser | proxy is already sufficient for public instance methods and fields, public static methods and fields, and protected instance methods. |
| 11:43 | Chouser | That leaves protected instance methods, and protected class methods and fields. |
| 11:43 | Chouser | bleh, oops. |
| 11:44 | Chouser | That leaves protected instance fields, and protected class methods and fields. |
| 11:45 | Chouser | It seems worth trying to generate public instance getters and setters for those. |
| 11:47 | Chouser | I don't know enough to have an opinion, except that I hate being forced to use gen-class because of some Java lib's use of protected. |
| 11:48 | rhickey | Chouser: I just dropped in, but I get a sense of trying to further enhance proxy? |
| 11:48 | Chouser | no recent previous discussion on the topic, I just don't have a better place to keep notes. :-) |
| 11:49 | Chouser | I just fixed up some gen-class issues, and now I'd like to make the irrelevant by adding sufficient features to proxy. |
| 11:49 | Chouser | make them |
| 11:50 | rhickey | I've been thinking a lot about this - basically when do I go to Java and why - I think what is needed is for a proxy-like instance-maker that doesn't proxy. It offers the full power of closures, coupled with direct inline definitions of methods (so they will have full super/protected access + this), and no calling overhead for lookup/indirection |
| 11:51 | rhickey | basically a version of fn that could create instances of things other than IFn and define methods other than invoke() |
| 11:52 | Chouser | are these thoughts related to the hooks used earlier by the lazy-seq definition? |
| 11:52 | rhickey | Yes, I've come to realize that fn is just an instance of this thing I'm describing, and is needlessly tied to making IFns |
| 11:54 | rhickey | (fn [x] 42) => (instance [AFn] (invoke [x] 42)) |
| 11:54 | Chouser | so these things could be compiled just like fns are now -- generated names, so you'd interact with their instances rather than the class. |
| 11:55 | Chouser | and rather than mucking about with a map of method defs, you'd generate a whole new class if you wanted to update behavior. |
| 11:55 | kotarak_ | rhickey: short bug report: AOT compilation looses metadata on namespaces. eg. the docstring is gone, when loading from .class files. Should I open an issue? |
| 11:55 | rhickey | Chouser: right, but you could name the class, such a name would be bound to the things it implements, much as is proxy - the only thing you couldn't dynamically redefine would be the set of supers |
| 11:56 | rhickey | Chouser: right, no mapping or lookup in dispatch, also you could have (possibly primitive) 'fields' by simply closing over |
| 11:56 | Chouser | but if you provide a new method def, and there's no indirection, doesn't that require a new class def and therefore a new class name? |
| 11:57 | rhickey | Chouser: the actual class would be a further derivee, with a numbered name |
| 11:57 | Chouser | ah! |
| 11:58 | rhickey | (class (instance [AFn :as MyFn] (invoke [x] 42))) ==> MyFn__1234 |
| 11:58 | Chouser | so that gives you better performance than proxy, plus a named interface for the thing, but you'd still need some kind of api to get at protected fields |
| 11:59 | rhickey | There's so much power in fn right now that could be leveraged, closing over, primitive fields, compilation etc |
| 11:59 | rhickey | Chouser: right, some notion of class scope |
| 12:00 | rhickey | although I'm not sure anything more than (.protectedMember this) is needed |
| 12:00 | rhickey | Those could work because you are actually in the scope of a derived member |
| 12:00 | Chouser | ok, if the code compiled by 'instance' really is directly in the class def itself, it might "just work" |
| 12:01 | rhickey | Chouser: it totally should |
| 12:01 | Chouser | similarly for static protected members. |
| 12:02 | rhickey | Chouser: right, just some additional compiler goop for generating the invokesuper instruction |
| 12:02 | rhickey | sorry invokespecial |
| 12:04 | Chouser | so 'this' would be special so the compiler could recognize it? |
| 12:05 | rhickey | I think so, unlike the early use of thisfn, it is unlikely that instance-generating macros will be nested the way nested fns were |
| 12:06 | Chouser | hmmm. |
| 12:08 | rhickey | could still do the (instance this-name [Supers] ...) thing |
| 12:08 | Chouser | I suppose it could ... right. |
| 12:09 | Chouser | keeping the set of this-names in a Compiler dynamic var, so it can know when to use invokespecial |
| 12:09 | rhickey | I think if I had gen-interface and this instance thing I could define Clojure in Clojure with no perf loss |
| 12:09 | Chouser | nice |
| 12:10 | rhickey | presuming atom for all things that are now volatiles |
| 12:10 | rhickey | plus a new mutex reference that I'm already thinking about |
| 12:10 | leafw | rhickey: what is the goal of writing clj in clj? |
| 12:10 | rhickey | Unfortunately Terracotta can;t handle AtomicReference at present :( |
| 12:12 | eevar__ | (defn fibo [] (map first (iterate (fn [[a b]] [b (+ a b)]) [0 1]))) ; is this a valid function definition? -- I assume not, as (take 10 fibo) throws an exception |
| 12:12 | rhickey | leafw: I'm not saying I'm going to do that. Some possible goals are: demonstrating that Clojure needs nothing from Java, much easier ports to JS/CLR/(Python/ObjC?), easier extension in Clojure itself, a new accessible AST defined in terms of Clojure types, etc |
| 12:13 | Chouser | eevar__: try (take 10 (fibo)) |
| 12:13 | eevar__ | okies, thanks |
| 12:14 | Chouser | even if Clojure/Java never uses it, I can imagine there being a cononical self-hosted Clojure for use by the various ports. |
| 12:15 | rhickey | leafw: plus you'd have the full power of Clojure to use in all of its definition, a true bootstrap unlike the current incremental self definition starting from Java |
| 12:15 | leafw | reads like a challenge. Would still need the JVM I guess. |
| 12:15 | Chouser | Clojure/Java might still have a bit of a performance edge, or be more adaptable to other Java platforms like Terracotta. |
| 12:16 | leafw | rhickey: I am familiar with SBCL written in SBCL. |
| 12:16 | rhickey | Chouser: It would be a goal to make that not so |
| 12:16 | Chouser | but for CLR, JS, etc. to be able to share a common set of collection definitions alone would be a big win. |
| 12:16 | Chouser | and a common Compiler would be nice too. |
| 12:16 | rhickey | Chouser: collections and the reader and the compiler... |
| 12:17 | rhickey | all you need is a code-gen and some RT helpers |
| 12:18 | leafw | sounds promising. Clojure could become an invasive language: invading any VM out there, with a common lib/toolkit. |
| 12:18 | rhickey | the AST being hidden is a big drawback - on of the points McCarthy made at OOPSLA was that langs should have accessible ASTs, and that Lisps code-as-data wasn't that |
| 12:19 | Chouser | it surprised me when I learned that Clojure used a non-clojure-collection AST |
| 12:19 | rhickey | leafw: Clojure could live anywhere there's a simple object model |
| 12:19 | leafw | what would accessing the AST give the programmer that we don't have already via eval or macros? |
| 12:19 | rhickey | Chouser: yeah, I hate that, a side effect of starting from scratch |
| 12:19 | Chouser | leafw: the compiler knows more about the form than is expressed in the plain form |
| 12:20 | rhickey | leafw: the AST doesn't change macros, but makes things much easier for code generators, editors and other tools |
| 12:20 | Chouser | type inference, for example. |
| 12:20 | Chouser | or "inferred types" would be more accurate I guess. |
| 12:20 | rhickey | right- I could easily see Datalog-based add on type or other constraint checking |
| 12:21 | leafw | rhickey: what clojure is lacking is pprecisely an IDE that understands it and helps in writing. All fwd to that, if clj/clj helps to it. |
| 12:22 | leafw | (what clj is lacking according to me, in all my shortsightedness) |
| 12:22 | leafw | Chouser: I use vim for any coding, but for debugging i'd be great to let an IDE point out logical errors. |
| 12:23 | blbrown | does jedit have clojure/lisp support. jedit is normally good for adding new language support. And I am working on a text editor, but it will be a while before anyone wants to use it. |
| 12:24 | Chouser | I still need to look at waterfront. |
| 12:24 | kotarak | leafw: I'm working heavily on making Clojure in Vim more fun. But's unlikely, that I will come with some solution for the debugger problem.... |
| 12:25 | Chouser | kotarak: yet |
| 12:25 | leafw | kotarak: you created the vimrc file for clj? |
| 12:26 | blbrown | ...what time is it 11 or 12 |
| 12:26 | kotarak | leafw: a created VimClojure and Gorilla (now merged with the former). Now working on smart omni completion. |
| 12:26 | kotarak | 17:25 |
| 12:26 | blbrown | 12 dammit |
| 12:26 | Chouser | 12:25 EDT |
| 12:27 | leafw | kotarak: thanks so much :) |
| 12:29 | Chouser | rhickey: so is there any part of 'instance' that I could help with, or should I just leave you alone. |
| 12:30 | leafw | kotarak: the screencast video is no longer available. |
| 12:33 | rhickey | Chouser: One key problem is that it doesn't exist in Java yet, so can it be first defined in Clojure or will this be the last effort preceding bootstrapping? |
| 12:34 | rhickey | The easiest route is to copy Compiler.FnExpr and FnMethod and hack into InstanceExpr and InstanceMethod |
| 12:34 | rhickey | (or maybe other names) |
| 12:35 | rhickey | At the root, the behavior of instance is a generic version of that of fn |
| 12:36 | Chouser | I see. This will need integration with the Compiler, unlike proxy. |
| 12:37 | rhickey | Chouser: that's the problem, it would be much simpler to write in Clojure, as would the rest of the compiler |
| 12:37 | Chouser | heh. right. |
| 12:37 | Chouser | as would everything. |
| 12:38 | rhickey | The compiler's 5000 lines of Java, I'd be surprised if it was 1000 lines of Clojure |
| 12:39 | rhickey | I guess that's where I'm at - I look at instance and know it's the right thing, but shudder at adding another 1k to Compiler.java |
| 12:40 | Chousuke | if you did that, would it be possible to remove most of the other 5k? |
| 12:41 | Chousuke | eventually, that is |
| 12:41 | rhickey | One nice thing about bootstrapping on a working Clojure is that you can do it incrementally - you don't have to re-write the world, could just do the compiler, then add instance to the new compiler, then redefine the collections in terms of instance ... |
| 12:43 | rhickey | the first step would be an analyzer for Clojure in Clojure that yielded a Clojure AST |
| 12:44 | Chouser | Using the existing Compiler$Foo classes? |
| 12:44 | rhickey | Chouser: no, Clojure AST is all Clojure data structures |
| 12:45 | rhickey | Then code gen is just an (emit target-generator expr context) multimethod |
| 12:45 | Chouser | so after that first step, you'd still not be able to use it without either some updates to Compiler emit methods, or rewriting them in Clojure as well. |
| 12:45 | Chouser | like ClojureScript has. :-) |
| 12:46 | rhickey | you'd want to abstract out both code gen and also type reflection |
| 12:46 | Chouser | would the Clojure AST be the original forms decorated with more metadata? or new structmaps/ |
| 12:47 | rhickey | Chouser: probably the latter, with the former embedded, they lose 1:1 at some points |
| 12:48 | rhickey | There's also some simple rewriting that currently occurs in place |
| 12:48 | rhickey | some things can't be expressions without being wrapped in lambdas |
| 12:49 | te | http://blog.rubyenrails.nl/articles/2008/12/12/calling-clojure-from-jruby |
| 12:49 | te | im following that tutorial, but im getting java.io.FileNotFoundException: Could not locate nl/rubyenrails/Blog__init.class or nl/rubyenrails/Blog.clj on classpath: (NO_SOURCE_FILE:0) |
| 12:49 | Chouser | I need to undestand the purpose and usage of the Compiler .emit() methods. |
| 12:49 | kotarak | leafw: hmm.. the screencast link works for me. Although it's totally outdated. I'm working on a new set of screencasts.... Alone the time to do it .... |
| 12:49 | Chouser | not those |
| 12:50 | Chouser | the .eval() methods |
| 12:51 | rhickey | Chouser: most of the evals could go away, early on there was the ability to eval things for the repl without wrapping in fns, now almost everything is wrapped - it's plenty fast and ensures the same behavior |
| 12:51 | Chouser | oh, ok. |
| 12:51 | leafw | te: so, is that folder in your classpath? Ask your interpreter: (System/getProperty "class.path") |
| 12:51 | te | leafw: okay let me check |
| 12:52 | te | leafw: java.lang.Exception: No such namespace: System (NO_SOURCE_FILE:0) |
| 12:53 | leafw | te: was "java.class.path", sorry. |
| 12:53 | leafw | and that is one bizarre error. Call then as java.lang.System |
| 12:54 | te | [...] clojure-contrib.jar:.:classes" |
| 12:54 | te | thats the end of my output |
| 12:54 | te | the other two things are just my clojure.jar and clojure-contrib.jar |
| 12:55 | te | so no nl/rubyenrails is not in my classpath |
| 12:56 | te | leafw: can you get that guy's example working? |
| 12:56 | leafw | didn't try. |
| 12:57 | te | leafw: its not in my classpath, how do i (compile 'nl.rubyenrails.Blog) |
| 12:58 | te | technically because i have the classes dir in rubyenrail it should work |
| 13:00 | te | i give up |
| 13:00 | leafw | te: http://tinyurl.com/arhwk8 |
| 13:04 | Chouser | rhickey: first step is analyze, not read? |
| 13:07 | rhickey | Chouser: right, the result of a Clojure read would be no different |
| 13:07 | Chouser | ok |
| 13:07 | rhickey | The compiler is the prize, then instance, then anything is replaceable |
| 13:09 | rhickey | analyze would need to take a pluggable reflector abstraction to handle types, interface implied by Reflector |
| 13:09 | rhickey | Use of interfaces would be fine too, since there will be a portable way to define them |
| 13:10 | rhickey | An important point is that interfaces will remain important, never will be replaced by multimethods for perf reasons |
| 13:12 | rhickey | interfaces are highest-perf polymorphism, but closed sets of functions, multimethods are more flexible and open, but have higher dispatch costs |
| 13:12 | Chouser | though the flexibility of multimethods would probably be worthwhile for compile time processing, right? |
| 13:12 | rhickey | also interfaces are not insertable after the fact |
| 13:13 | rhickey | Chouser: sure, multimethods would be fine for compiler's analyze/emit etc |
| 13:13 | rhickey | The Java compiler is a reimplementation fo CL code that used generic functions |
| 13:19 | rhickey | interestingly, I moved away from the GFs once I started generating Java/C# source, don't remember why |
| 13:20 | rhickey | http://code.google.com/p/clojure/source/browse/trunk/src/lisp/clojure.lisp?r=300 |
| 13:23 | rhickey | so. 1600 lines of CL, emits Java and C# source |
| 13:24 | Chouser | I've got 15 lines so far -- 1% done! |
| 13:34 | rhickey | hah! |
| 13:36 | rhickey | Chouser: when you get to fn, do instance instead, we can define fn as macro expanding into instance, as long as your compiler doesn't use instance, only fn, it won't need itself before it exists |
| 13:37 | Chouser | ok |
| 13:37 | rhickey | One reader change I might make is to move syntax-quote to the compiler |
| 13:37 | Chouser | ok, makes sense. |
| 14:03 | digash | i think it has to do with an ability to construct quoted cycles at the read-time w/ character-macros #n= and #n# |
| 14:05 | rhickey | digash: yikes, can't do that anyway, no #n= yet |
| 14:07 | gnuvince_ | Hello everyone |
| 14:07 | digash | what about cl #. :) |
| 14:07 | ayrnieu | digash - clojure spells that #= |
| 14:07 | gnuvince_ | What's going on? Compiler rewrite? |
| 14:09 | digash | (define bar (quote #.(let ((list '(0 1))) (set-cdr! (cdr list) list) list))) |
| 14:10 | digash | that is another reason for quote at the read time makes it easier to deal with this mess. |
| 14:12 | Chouser | gnuvince_: just some sunday-afternoon amusement. |
| 14:14 | rhickey | ayrnieu: #= is not quite #., all of the args must be read-time constants, it is not full read-time eval |
| 14:14 | ayrnieu | ah. |
| 14:17 | digash | btw, this is straight from "Lisp In Small Pieces" |
| 14:17 | digash | p144 |
| 14:18 | ayrnieu | what, that (define bar ...) ? |
| 14:18 | digash | yep |
| 14:24 | gnuvince_ | Chouser: so no compiler bootstrapping? |
| 14:25 | Chouser | gnuvince_: well, maybe... |
| 14:25 | digash | http://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node367.html here is another one of my favorite references on the subject of quoting. |
| 14:36 | rlb | Is sqlitejdbc the best choice for use from clojure right now? |
| 14:41 | rhickey | digash: yeah, I like that too. syntax-quote is somewhat complicated by vectors, maps and metadata |
| 14:42 | rlb | (I also noticed javasqlite...) |
| 14:43 | cp2 | hah, http://pastebin.com/d7fe66f73 |
| 14:54 | p_l | rlb: well, with sqlitejdbc you are keeping yourself to industry-standard API ;-) |
| 14:57 | rlb | Hmm, there's also hsql... |
| 15:19 | pjstadig | should the nodes member of a BitmapIndexedNode ever be sparse? |
| 15:20 | pjb3 | ,(let [x 1] (eval '(+ x 1))) |
| 15:20 | clojurebot | DENIED |
| 15:20 | pjstadig | I'm tracking down an error with TC where adding to a PersistentHashMap causes an NPE |
| 15:20 | pjb3 | That ends up throwning java.lang.Exception: Unable to resolve symbol: x in this context (NO_SOURCE_FILE:59) |
| 15:20 | rhickey | pjstadig: no |
| 15:21 | pjb3 | Is that the way it is, you can't refer to let bound locals in an eval statement? |
| 15:21 | pjstadig | it's trying to create a new BitmapIndexedNode with a nodes array that has holes in it |
| 15:21 | pjstadig | the first node especially is null which causes an NPE in the constructor |
| 15:21 | rhickey | pjstadig: by holes you mean nulls? |
| 15:21 | pjstadig | yeah |
| 15:22 | pjstadig | i've run into this before, and it was usually related to a hashCode or object identity issue |
| 15:23 | pjstadig | like where an object that should be the same is hashing differently because its a TC object instead of a local object |
| 15:28 | rhickey | pjstadig: I still don't see how a null gets in there |
| 15:28 | rhickey | null is specially handled in without, and assoc only inserts new LeafNode |
| 15:30 | rhickey | pjb3: the eval has no connection to the lexical scope |
| 15:31 | pjb3 | rhickey: yeah, that appears to be the case |
| 15:31 | pjb3 | I'll just have to use a macro to do what I'm trying to do |
| 15:32 | pjb3 | Basically I'm getting a data structure from somewhere else that I want to eval in the context of the let locals |
| 15:32 | pjb3 | So if I do |
| 15:32 | pjb3 | (let [x 1] (my-marco get-data)) |
| 15:32 | pjb3 | had have that expand to |
| 15:32 | pjb3 | (let [x 1] (+ x 1)) |
| 15:32 | pjb3 | then it should work, right? |
| 15:34 | rhickey | it will probably look like (my-macro [x 1] (get-data)) |
| 15:34 | rhickey | unless your macro has hardwired 'x |
| 15:36 | pjb3 | get-data will return '(+ x 1) |
| 15:36 | pjb3 | and I want to assign a value to x for the purposes of evaling it |
| 15:36 | pjb3 | get-data is really more like get-template |
| 15:37 | pjb3 | that would return something like |
| 15:37 | pjb3 | (str "Dear " recipient ",\n") |
| 15:38 | pjb3 | so I would do (let [recipient "Rich"] (eval-template (get-template :dear-john-letter))) |
| 15:39 | pjstadig | rhickey: it's obviously something related to TC going haywire |
| 15:39 | pjstadig | just had to be sure |
| 15:39 | pjb3 | (get-template :dear-john-letter) returns (str "Dear " recipient ",\n") |
| 15:39 | pjb3 | so what I ultimately want to do is |
| 15:39 | pjb3 | (let [recipient "Rich"] (str "Dear " recipient ",\n")) |
| 15:40 | rhickey | pjstadig: ok, if ever you think you've found a bug, just let me know |
| 15:40 | pjstadig | it's happening when trying to intern a new var |
| 15:40 | pjstadig | after reconnecting to TC |
| 15:47 | pjstadig | ok |
| 15:48 | pjstadig | if i switch namespaces and then back again to user |
| 15:48 | pjstadig | i can def a new var |
| 15:49 | pjstadig | it must be something about the way the second JVM is connecting and booting up |
| 15:49 | Lau_of_DK | Good evening gents |
| 15:57 | AWizzArd | rhickey: very good suggestion that you made (GG), about the use of Hashmaps in Clojure |
| 16:01 | rhickey | AWizzArd: thanks, all those apis are so close to being interoperable |
| 16:03 | AWizzArd | Currently we (my company) are in the phase of laying out the core data structures, and we decided to go with maps of maps. Your posting supports our idea. |
| 16:06 | dcnstrct | quick question. I have a list of strings, and I'd like to find out the position in the list where the first appearance of the string "foo" can be found. Can anyone help me think of what functions I should be paying attention to for this ? |
| 16:07 | dcnstrct | input ("foo" "bar" baz") output should be: 0 because "foo" is in position one. |
| 16:08 | eivindgl | anybody here using emacs with slime? how do i stop/cancel an execution. I'm writing quite a lot of endless loops these days :p |
| 16:09 | dcnstrct | ["foo", "bar", "baz"].each_with_index { |str, idx| return idx if str == "foo" } |
| 16:09 | dcnstrct | thats how it might look in Ruby for example |
| 16:09 | Lau_of_DK | dcnstrct: I have a hack in mind :) |
| 16:09 | Lau_of_DK | ,(count (take-while #(not= % "foo") ["bar" "foo" "biz"])) |
| 16:09 | clojurebot | 1 |
| 16:10 | dcnstrct | wow it works, but I'm not familiar with take-while I'll look it up |
| 16:10 | dcnstrct | thnx this'll do for now |
| 16:10 | AWizzArd | ,(doc take-while) |
| 16:10 | clojurebot | "([pred coll]); Returns a lazy sequence of successive items from coll while (pred item) returns true. pred must be free of side-effects." |
| 16:10 | Lau_of_DK | ,(take-while #(< 5 %) (range 10)) |
| 16:11 | clojurebot | () |
| 16:11 | gnuvince_ | dcnstrct: it does waht it says: takes element from a seq while a predicate holds. |
| 16:11 | rhickey | ,(.indexOf ["foo" "bar" "baz"] "foo") |
| 16:11 | clojurebot | 0 |
| 16:11 | Raynes | rhickey: Damn you. I was about to say that :( |
| 16:11 | Lau_of_DK | uuuh hickey :) |
| 16:11 | gnuvince_ | ,(.indexIf ["bar" "baz"] "foo") |
| 16:11 | clojurebot | java.lang.IllegalArgumentException: No matching method found: indexIf for class clojure.lang.LazilyPersistentVector |
| 16:11 | gnuvince_ | ,(.indexOf ["bar" "baz"] "foo") |
| 16:12 | clojurebot | -1 |
| 16:12 | dcnstrct | :) thnx ppl. |
| 16:14 | gnuvince_ | rhickey always has the shortest code, cause he's one of the few who really knows Java here, I think |
| 16:14 | Raynes | I don't know Java, but I knew that method and I was typing it but he finished before me. |
| 16:18 | leafw | if you don't use an IDE, your fingers memorize th API, particularly for all the main interfaces: List, Map, Set, Collection. |
| 16:20 | dcnstrct | java.lang.IllegalArgumentException: No matching method found: indexOf for class clojure.lang.LazyCons |
| 16:20 | dcnstrct | I guess I need to turn it into a list first. |
| 16:20 | leafw | right. |
| 16:22 | rhickey | dcnstrct: that looks like old Clojure |
| 16:22 | rhickey | all seqs now implement List |
| 16:23 | dcnstrct | oh junk you're right it is. Glad to know that I'll upgrade. |
| 16:23 | AWizzArd | wb kotarak |
| 16:34 | dcnstrct | now with the clojure from SVN it's a different error |
| 16:34 | dcnstrct | java.lang.IllegalArgumentException: No matching field found: indexOf for class clojure.lang.PersistentList |
| 16:34 | dcnstrct | hrmm I'll play aorund /w it |
| 16:35 | Raynes | dcnstrct: Paste your code? |
| 16:36 | dcnstrct | nevermind I found I introduced a typo.. works great now that I have new clojure |
| 16:58 | Lau_of_DK | Guys - I need to implement a throttle on my send-off dispatching. Can someone hint, how I'll implement something like 50 dispatches per minute in a sensible way ? |
| 17:00 | durka42 | you could queue them up somewhere and have an agent dispatch them on a timer |
| 17:01 | Lau_of_DK | Thats true |
| 17:01 | Lau_of_DK | Thats not bad |
| 17:02 | durka42 | i've done that in java, and my code was probably horribly un-thread-safe |
| 17:02 | durka42 | but clojure can help with that |
| 17:03 | Lau_of_DK | it sure can |
| 17:03 | rlb | You could also make a "producer" that will only produce one value per however long. |
| 17:04 | rlb | i.e. a timed sequence/queue. |
| 17:04 | Lau_of_DK | What would you see being the advantage of that approach ? |
| 17:04 | mgarriss | is it standard practice to use a '-' between words in a namespace? example: (ns foobar.two-words) |
| 17:05 | kotarak | mgarriss: sure, why not? Just remember that the corresponding file is foobar/two_word.clj |
| 17:06 | mgarriss | kotarak: good to know. thx |
| 17:06 | rlb | Lau_of_DK: not sure. I was wondering if it might be useful if you wanted more composability, but don't really have anything concrete in mind. |
| 17:06 | Lau_of_DK | ok |
| 17:06 | rlb | Lau_of_DK: basically I was wondering about a lazy, time-metered, sequence. |
| 17:07 | Lau_of_DK | I'll consider it, for now it just seems very simple to calculate the number of agents you need to dispatch per minute, and do (map agent (replicate rpm 0)) and dispatch them from a timer |
| 17:07 | rlb | Lau_of_DK: I suspect that the other approach is more likely to be what you want unless you have special needs. |
| 17:08 | Lau_of_DK | I have a special need, I have a contract from a customer with performance demands I need to document are met :) |
| 17:18 | hiredman | you could, instead of directly executing your send-offs, send them to a scheduledthreadpoolexecutor |
| 17:18 | Lau_of_DK | How would that work ? |
| 17:19 | hiredman | actually, hmmmmm |
| 17:19 | hiredman | ~jdoc java.util.concurrent.ScheduledThreadpoolExecutor |
| 17:20 | Lau_of_DK | 404 |
| 17:20 | hiredman | upper case p |
| 17:20 | kotarak | capital P? |
| 17:20 | Lau_of_DK | large p ? |
| 17:20 | kotarak | ,(.toUpperCase "p") |
| 17:20 | clojurebot | "P" |
| 17:20 | Lau_of_DK | Interesting - only one downside, I already implemented the other solution :) |
| 17:21 | kotarak | Lau_of_DK: in Thread*p*ool |
| 17:21 | Lau_of_DK | I'll have a looksie in a bit, thanks |
| 17:21 | Lau_of_DK | Im kidding you guys, I knew it :) |
| 17:21 | hiredman | actually, I think it might be btter to proxy Executor anyway |
| 17:21 | hiredman | *couhg* |
| 17:21 | hiredman | Yes, well |
| 17:23 | hiredman | I have a concurrent directory walker (returns a recursive file listing) that uses a threadpoolexecutor |
| 17:23 | hiredman | it makes my poor c2d spin and spin |
| 17:24 | Lau_of_DK | can my worker func only take the one arg a ? |
| 17:28 | Lau_of_DK | or does send-off just hardcoded pass *agent* as the first arg, and then the rest as you please? |
| 17:30 | Chouser | *agent* is bound to the currently running agent. the first arg is the state of the agent. |
| 17:30 | hiredman | yeah |
| 17:31 | Lau_of_DK | (defn worker [a x y z] (do stuff) (send-off *agent* worker (inc x) (inc y) (int z))) |
| 17:31 | Lau_of_DK | would that fly ? |
| 17:38 | rosejn | Anyone know how to apply arguments to a java method? For example, (apply .startsWith '("asdf" "as")) |
| 17:38 | rosejn | which doesn't work... |
| 17:38 | Chouser | rosejn: can't really do it. |
| 17:38 | rosejn | darn |
| 17:39 | rosejn | chouser: any way to work around this? I need to call a java method with variable arguments that I create from Clojure. |
| 17:39 | Chouser | there might be a way that involves runtime reflection. |
| 17:40 | cmvkk | can you wrap it in a function of its own? |
| 17:40 | Chouser | the method sig includes variable args? |
| 17:40 | rosejn | yeah, Object... |
| 17:40 | kotarak | rosejn: http://paste.lisp.org/display/67182 |
| 17:42 | Chouser | but if you just want to pass in args to method like foo( String, Object... ) you don't need reflection |
| 17:43 | rosejn | kotarak: cool, thanks! |
| 17:43 | rosejn | how do you do it then? |
| 17:44 | Chouser | it actually wants an array of Object |
| 17:45 | lisppaste8 | Lau pasted "stress-test" at http://paste.lisp.org/display/76669 |
| 17:45 | Chouser | ,(String/format "%s and %s" (into-array ["one" "two"])) |
| 17:45 | clojurebot | "one and two" |
| 17:45 | Lau_of_DK | 2 questions, 1) will this produce reliable results when it runs? 2) why doesnt it run ? |
| 17:48 | rosejn | chouser: is it possible to call an instance method like that, or does it have to be static? |
| 17:48 | Chouser | instance methods work the same way |
| 17:48 | fyuryu | what's the equivalent of Java's super(args); in Clojure? (using gen-class) |
| 17:50 | Chouser | fyuryu: use :exposes-methods to give the super's method a new name, then call that. |
| 17:50 | rlb | OK, I hacked sqlitejdbc to work with openjdk-6 (at least it appears to work)... |
| 17:50 | fyuryu | Chouser: ah, thanks |
| 17:56 | durka42 | Lau_of_DK: define "doesn't run"? |
| 17:58 | StartsWithK | lisppaste8: help |
| 17:58 | lisppaste8 | To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste. |
| 17:58 | lisppaste8 | Lau annotated #76669 "error" at http://paste.lisp.org/display/76669#1 |
| 18:01 | durka42 | the NPE seems to come from clojure.lang.Numbers/divide |
| 18:02 | Lau_of_DK | Oh youre right - its not being cast |
| 18:03 | durka42 | but i don't see where anything is null |
| 18:04 | lisppaste8 | StartsWithK pasted "Swing builder first run" at http://paste.lisp.org/display/76671 |
| 18:04 | Lau_of_DK | I've cast the 2 ints now, but it still goes NPE |
| 18:04 | Lau_of_DK | Looks like replicate is borking |
| 18:05 | Lau_of_DK | which it shouldnt |
| 18:06 | StartsWithK | just manged to run first example with swing builder lib, needs more work but for now it can reduce the need for proxy with listeners, it aoutdiscovers appropriate listener |
| 18:06 | Lau_of_DK | Sure would be nice if Clojure just said "Line 25 produces this error" |
| 18:07 | durka42 | {:thead-count "3", :rpm "3", :url "http://www.google.com"} |
| 18:07 | durka42 | you need those to be numbers |
| 18:07 | StartsWithK | and knows how to 'erase' lexical scope, so widgets can be created on the spot and reference other widgets that are created after it |
| 18:08 | durka42 | oh... |
| 18:08 | durka42 | you misspelled thread |
| 18:08 | durka42 | hence nil |
| 18:08 | Lau_of_DK | I just saw that :( |
| 18:08 | Lau_of_DK | Guess I cant blame Rich for that one |
| 18:08 | durka42 | online 30 |
| 18:10 | Lau_of_DK | It runs fine now |
| 18:10 | Lau_of_DK | Just hopes it produces accurate results |
| 18:11 | Lau_of_DK | I think my fetch-site needs to be fitted to report 404's and 500's |
| 18:15 | leafw | I am having trouble reading the value of a static field in a static subclass |
| 18:15 | leafw | ,(println javax.swing.event.HyperlinkEvent.EventType/ACTIVATED) |
| 18:16 | clojurebot | java.lang.ClassNotFoundException: javax.swing.event.HyperlinkEvent.EventType |
| 18:16 | leafw | ,(println javax.swing.event.HyperlinkEvent$EventType/ACTIVATED) |
| 18:16 | clojurebot | #<EventType ACTIVATED> |
| 18:16 | leafw | aha |
| 18:16 | leafw | the sign of the $ |
| 18:16 | Lau_of_DK | Its all about the money |
| 18:17 | leafw | said Francisco d'Anconia. |
| 18:24 | Lau_of_DK | I think it was 'Maya' |
| 18:31 | hiredman | I think seque is what I want, I just cannot fiure out how to use it |
| 18:33 | Chouser | it acts like (map identity ...) |
| 18:33 | Chouser | except the ... part can run on ahead of the thing that's taking from map. |
| 18:34 | hiredman | ok, maybe not |
| 18:35 | hiredman | wait |
| 18:35 | hiredman | seque is for making a seq out of queue? |
| 18:38 | hiredman | I think I will just use a lbq and a lazy-seq |
| 18:53 | hiredman | ~def future-call |
| 19:05 | spacema__ | anyone had trouble getting clojure compiling on os x with java 1.6? |
| 19:05 | spacema__ | I'm seeing this error: Apple AWT Startup Exception : *** -[NSCFArray insertObject:atIndex:]: attempt to insert nil |
| 19:06 | spacema__ | it's talked about at 19:45 on the logs here http://clojure-log.n01se.net/date/2008-11-15.html |
| 19:06 | spacema__ | but that doesn't seem like a really nice solution - anyoen got something better? |
| 19:11 | hiredman | ~def seq |
| 19:12 | durka42 | ~def in-ns |
| 19:15 | hiredman | ,(import 'java.util.concurrent.LinkedBlockingQueue) |
| 19:15 | clojurebot | nil |
| 19:16 | hiredman | ,(let [q (doto (LinkedBlockingQueue.) (.put 1) (.put 2)) s (seq q)] (.put q 3) s) |
| 19:16 | clojurebot | (1 2 3) |
| 19:16 | hiredman | mmmmm |
| 19:16 | hiredman | ,(let [q (doto (LinkedBlockingQueue.) (.put 1) (.put 2)) s (seq q)] (.put q 3) (class s)) |
| 19:16 | clojurebot | clojure.lang.IteratorSeq |
| 19:27 | AWizzArd | ,(let [[f & r] #{10 20 30}] (println f r)) |
| 19:27 | clojurebot | java.lang.UnsupportedOperationException: nth not supported on this type: PersistentHashSet |
| 19:28 | AWizzArd | how again is destructuring done for sets? |
| 19:29 | kotarak | ,(let [[f & r] (seq #{10 20 30})] (println f r)) |
| 19:29 | clojurebot | 10 (20 30) |
| 19:29 | rhickey | AWizzArd: there's no basis for destructuring sets, you could seq it for positional destructuring |
| 19:29 | Raynes | ,(doseq [[a b] [1 2 3 4]] (+ a b)) |
| 19:29 | clojurebot | java.lang.UnsupportedOperationException: nth not supported on this type: Integer |
| 19:30 | AWizzArd | oki, thx |
| 19:30 | Raynes | Hrm. Maybe I should read the doseq part of Programming Clojure again... |
| 19:30 | durka42 | Raynes: are you thinking of partition perhaps? |
| 19:30 | leafw | what is the best way to get the last elemnt of a vector? |
| 19:31 | durka42 | ,(doseq [[a b] (partition 2 [1 2 3 4])] (prn (+ a b))) |
| 19:31 | clojurebot | 3 7 |
| 19:31 | Raynes | ,(last [1 2 3]) |
| 19:31 | clojurebot | 3 |
| 19:31 | Raynes | ^ |
| 19:31 | leafw | last -- ok, should have guessed :) |
| 19:31 | Raynes | I apparently have no clue how destructuring works. |
| 19:32 | durka42 | you provide a data structure of things to bind to, exactly mirroring the data structure that the values come from |
| 19:32 | Raynes | (doc partition) |
| 19:32 | clojurebot | Returns a lazy sequence of lists of n items each, at offsets step apart. If step is not supplied, defaults to n, i.e. the partitions do not overlap.; arglists ([n coll] [n step coll]) |
| 19:32 | kotarak | leafw: peek |
| 19:32 | durka42 | ,(partition 2 [1 2 3 4]) |
| 19:32 | clojurebot | ((1 2) (3 4)) |
| 19:32 | kotarak | ,(peek [1 2 3]) |
| 19:32 | clojurebot | 3 |
| 19:32 | Raynes | Oh I see. |
| 19:33 | kotarak | leafw: last is O(n), peek O(1), IIRC |
| 19:33 | Raynes | Is prn a println wrap? |
| 19:33 | Raynes | Or is it different in some way. |
| 19:33 | kotarak | ,(prn "Hello") |
| 19:33 | clojurebot | "Hello" |
| 19:34 | kotarak | ,(println "Hello") |
| 19:34 | clojurebot | Hello |
| 19:34 | Raynes | Ah. |
| 19:34 | durka42 | println wraps prn with *print-readably* bound to nil |
| 19:35 | leafw | kotarak: thanks |
| 19:36 | Raynes | ,(doseq [[a b] ["a" "b"]] (println (str a b))) |
| 19:36 | clojurebot | a b |
| 19:42 | hiredman | hmmm |
| 19:43 | rhickey | ,(str \a nil) |
| 19:43 | clojurebot | "a" |
| 19:54 | dreish | ,(class (eval (list 'quote (symbol "{:a 1}")))) |
| 19:54 | clojurebot | DENIED |
| 19:54 | dreish | Meh. |
| 19:54 | dreish | answer: clojure.lang.PersistenArrayMap |
| 19:54 | dreish | t |
| 20:06 | durka42 | i get clojure.lang.Symbol |
| 20:10 | zakwilson | Breath of fresh air, isn't it? |
| 20:11 | mgarriss | i'm excited about a language for the first time since i found ruby |
| 20:12 | hiredman | is there something in core that will make a lazy-seq out of a blockingqueue? |
| 20:12 | rhickey | ,(doc seque) |
| 20:12 | clojurebot | "([s] [n-or-q s]); Creates a queued seq on another (presumably lazy) seq s. The queued seq will produce a concrete seq in the background, and can get up to n items ahead of the consumer. n-or-q can be an integer n buffer size, or an instance of java.util.concurrent BlockingQueue. Note that reading from a seque can block if the reader gets ahead of the producer." |
| 20:12 | mgarriss | i just moved to emacs after years with vim, elisp made me realize my "too many parenthesis" argument was idiotic |
| 20:13 | mgarriss | clojure seems like the right LISP to learn |
| 20:13 | Chouser | I'm trying out a new working theory about the parens. |
| 20:14 | hiredman | rhickey: I just don't get that |
| 20:14 | Chouser | in c-ish languages, foo() means a function call. |
| 20:15 | Chouser | In most lisps, (foo) could be anything -- part of a cond expression, an arg list, a function call, who knows? |
| 20:15 | rhickey | hiredman: seque will put a blocking queue in line between a lazy seq and its consumer |
| 20:16 | Chouser | it takes more context, and specific knowledge of sufficient builtin words in order know anything about that pattern. |
| 20:16 | Chouser | which is one reason that clojure source is so much easier (for me) to read than CL. In Clojure (foo) almost always means a function (or macro) call. |
| 20:17 | Chousuke | you managed to confuse me for a moment there :) |
| 20:17 | Chousuke | I read your (for me) as lisp |
| 20:17 | rhickey | hiredman: try it: |
| 20:17 | rhickey | (def sq (seque 4 (map #(do (prn %) %) (range 1000000)))) |
| 20:17 | rhickey | (take 10 sq) |
| 20:17 | hiredman | rhickey: that seems like the reverse of what I want |
| 20:17 | Chouser | bindings use vectors, literal data collections use [] or {} |
| 20:17 | Chouser | Chousuke: ha! |
| 20:17 | cmvkk | on the other hand, Clojure introduces new ambiguity, because now you can't count on foo being a function. It could be a vector or a map. |
| 20:17 | rhickey | hiredman: someone else has a queue you want to consume? |
| 20:17 | hiredman | yes |
| 20:18 | Chousuke | cmvkk: vectors and maps are functions :) |
| 20:18 | cmvkk | well that's true... |
| 20:18 | Chouser | cmvkk: don't other lisps have non-list data types? |
| 20:18 | Chousuke | I think "operation" is a better word |
| 20:18 | cmvkk | yeah but you don't see them in calling position. |
| 20:18 | Chousuke | or operator |
| 20:18 | cmvkk | is what i meant. |
| 20:18 | Chouser | oh, I see. |
| 20:19 | zakwilson | A vector is a function of its index. Vectors and maps are functions in the mathematical sense when used that way. |
| 20:19 | zakwilson | It's things that might do IO mutation or some such that aren't. |
| 20:19 | Chouser | one of the few exceptions is the proxy form, where (foo [] ...) defines a method named foo |
| 20:19 | zakwilson | err... IO or mutation. |
| 20:20 | cmvkk | not to mention any other macro that repurposes the list form for whatever, but i suppose that's not in the core |
| 20:21 | Chouser | sure's it's possible, but it's not common. |
| 20:21 | zakwilson | It might be interesting to have a language where anything defined as a function can't have side effects, introducing a new name (say, "procedure") for things that can. |
| 20:21 | hiredman | rhickey: I think what I really want is not possible |
| 20:21 | Chousuke | in clojure it can be done only when it helps readability |
| 20:22 | Chousuke | in the proxy case, I think having a list is somewhat more readable than vectors |
| 20:22 | cmvkk | it might help to prepend the method defs with "method" to make them look more like defn calls or whatever? |
| 20:22 | Chouser | Chousuke: I agree [foo [] ...] would feel a bit weird. |
| 20:22 | hiredman | a lazy-seq ontop of a lbq that blocks well the queue is still being fed, but once are the producers are done it terminates |
| 20:23 | hiredman | my producers are just not co-ordinated enough for that |
| 20:23 | Chouser | hiredman: yeah, you'd have to have a "done" sentinel in there. |
| 20:23 | Chouser | which is what seque does, iirc. |
| 20:23 | rhickey | hiredman: that's a general problem with queues, termination is an application-level problem |
| 20:25 | hiredman | I have a sneaky feel .poll is just asking for a race |
| 20:25 | hiredman | feeling |
| 20:32 | slashus21 | Why does running (seque 4 (range 200)) over and over again sometimes produce different results? |
| 20:33 | hiredman | different? |
| 20:33 | slashus21 | The resulting sequence is different. |
| 20:33 | slashus21 | different length, different numbers. |
| 20:33 | Chouser | looks the same to me. |
| 20:34 | hiredman | same here too |
| 20:34 | Chouser | you should always get a sequence starting with 0 and going in order to 199 |
| 20:34 | hiredman | slashus21: is (seque 4 (range 200)) exactly what you are doing? |
| 20:34 | slashus21 | hiredman: I am just toying with it. |
| 20:35 | hiredman | its output in the repl is identical to (range 200) |
| 20:35 | Chouser | if you ever see a number out of order or the the range starting or ending with different numbers, that would be significant. |
| 20:35 | slashus21 | (seque 2 (lazy-seq (range 20))) |
| 20:35 | slashus21 | (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19) |
| 20:35 | slashus21 | disregard (lazy-seq |
| 20:35 | slashus21 | same results without it |
| 20:36 | Chouser | hmph |
| 20:37 | Raynes | (doc seque |
| 20:37 | clojurebot | It's greek to me. |
| 20:37 | Raynes | Oops |
| 20:37 | Raynes | (doc seque) |
| 20:37 | clojurebot | Creates a queued seq on another (presumably lazy) seq s. The queued seq will produce a concrete seq in the background, and can get up to n items ahead of the consumer. n-or-q can be an integer n buffer size, or an instance of java.util.concurrent BlockingQueue. Note that reading from a seque can block if the reader gets ahead of the producer.; arglists ([s] [n-or-q s]) |
| 20:38 | Chouser | ,(first (filter #(not= % 20) (repeatedly #(count (seque (range 20)))))) |
| 20:38 | clojurebot | Execution Timed Out |
| 20:39 | Chouser | slashus21: I'd recommand a clean and rebuild. You've got something screwy going on. |
| 20:39 | slashus21 | (seque (range 20)) is consistent, but (seque n (range 20)) isn't |
| 20:39 | ImOuttaYourMonad | how can I combine for with a function to update soemthing? like get all pixels form an image? |
| 20:39 | slashus21 | ,(first (filter #(not= % 20) (repeatedly #(count (seque 2 (range 20)))))) |
| 20:39 | clojurebot | 34 |
| 20:42 | slashus21 | Is this the correct behavior? |
| 20:42 | Chouser | I don't think so |
| 20:45 | slashus21 | ,(first (filter #(not= % 2000) (repeatedly #(count (seque (range 2000)))))) |
| 20:46 | clojurebot | Execution Timed Out |
| 20:46 | slashus21 | ,(first (filter #(not= % 500) (repeatedly #(count (seque (range 500)))))) |
| 20:46 | clojurebot | Execution Timed Out |
| 20:46 | slashus21 | I don't think this works either. |
| 20:46 | Chouser | ,(first (filter #(not= (count %) 20) (repeatedly #(seque 10 (range 20))))) |
| 20:46 | clojurebot | (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19) |
| 21:09 | ImOuttaYourMonad | does clojure have letrec? |
| 21:09 | ImOuttaYourMonad | nesting loop seems really awkward |
| 21:09 | rhickey | ,(doc letfn) |
| 21:09 | clojurebot | "([fnspecs & body]); Takes a vector of function specs and a body, and generates a set of bindings of functions to their names. All of the names are available in all of the definitions of the functions, as well as the body. fnspec ==> (fname [params*] exprs) or (fname ([params*] exprs)+)" |
| 21:12 | gnuvince_ | rhickey: read your post regarding maps. Nice (although I guess I'm guilty of using vectors myself) |
| 21:22 | Chouser | Well, I'm not seeing what's wrong with seque. |
| 21:22 | slashus21 | Chouser: I have been looking at it too. |
| 21:22 | Chouser | ok, I'll leave you to it. |
| 21:23 | slashus21 | Chouser: Any idea of what could be wrong? |
| 21:24 | Chouser | not really. small queues seem to exasperate it. |
| 21:24 | slashus21 | Small buffer sizes in comparison to the actual queue size? |
| 21:27 | Chouser | small blocking queue compared to a large blocking queue, for the same sized input seq |
| 21:28 | Chouser | not much code there, seems like it ought to be easy to track down. |
| 21:28 | Chouser | :-) |
| 21:43 | Chouser | slashus21: if you give up, please post to the group so we don't lose track of the bug. |
| 21:43 | hiredman | http://github.com/hiredman/odds-and-ends/blob/47e32cbfe21957dc538722ed4f62b77899735954/pwalker.clj my parallel directory walker if anyone is interested |
| 21:43 | slashus21 | Chouser: Okay |
| 21:57 | Chouser | rhickey: have you looked at error-kit at all? |
| 21:58 | rhickey | Chouser: briefly, I found it baffling |
| 21:58 | Chouser | hm. great. |
| 21:58 | rhickey | I can't say I gave it enough effort, just a first impression |
| 21:59 | Chouser | ok, just curious. |
| 21:59 | rhickey | I wonder, have you described the motivation somewhere - what problem does it solve? |
| 21:59 | rhickey | FWIW I feel the same way about CL conditions - very complex |
| 21:59 | Chouser | yeah |
| 22:00 | Chouser | well, I posted to the group -- that's the most explanation I've given. |
| 22:02 | Chouser | but I don't think I justified all the features. I didn't want to leave out any features of CL's conditions. |
| 22:04 | rhickey | I wonder about these stack-based error handling mechanisms in the face of concurency |
| 22:04 | rhickey | seems like you want error queues or something |
| 22:04 | rhickey | at least for reporting |
| 22:05 | Chouser | well, it's all thread-local. |
| 22:05 | rhickey | right, but when the error is in an agent... |
| 22:06 | Chouser | yes, error-kit doesn't address that at all. |
| 22:07 | Chouser | but, an error-kit error is a clojure map, so you can queue 'em up or whatever you would have done with a Java Exception. |
| 22:57 | hiredman | http://twitter.com/clojurebot/status/1298555118 it works! |
| 22:59 | cmvkk | hmm |
| 22:59 | cmvkk | it's hard to think of 'clojurebot' as an IRC bot now then |
| 22:59 | cmvkk | it's more like a bot with an IRC component |
| 22:59 | hiredman | muahahah |
| 23:00 | icey | i'm sure this is a totally obvious thing, but i'm having a tough time figuring out what i should be doing... i'm trying to store the results of some gets into a string. |
| 23:00 | icey | i'm doing (def randstr (dotimes [x 10] (get mychars (rand 10))) |
| 23:00 | icey | but it always comes back as an empty list |
| 23:01 | icey | mychars is a just a string |
| 23:02 | danlarkin__ | I love the clojurebot icon |
| 23:13 | hiredman | danlarkin__: :( |
| 23:13 | danlarkin__ | hiredman: why the long face, I wasn't being sarcastic |
| 23:14 | hiredman | I was just going to change it |
| 23:14 | hiredman | and now I have to keep it |
| 23:14 | danlarkin__ | bahaha |
| 23:14 | Chouser | icey: mychars is a String? I don't think 'get' will work. |
| 23:14 | Raynes | (doc get) |
| 23:14 | Chouser | oh. hm, I guess it does. |
| 23:14 | clojurebot | Returns the value mapped to key, not-found or nil if key not present.; arglists ([map key] [map key not-found]) |
| 23:17 | icey | Chouser: Is there a better way to deal with a string than get? I just want to get 10 random characters out of a string, and use that new 10 random characters as a new string. |
| 23:17 | Chouser | icey: dotimes always returns nil |
| 23:18 | icey | chouser: I'm getting closer by using a "for" now... at least poking around like this is a good learning experience :D |
| 23:18 | Chouser | (apply str (take 10 (repeatedly #(get mychars (rand 10))))) |
| 23:19 | icey | Chouser: you sir, are a gentleman and a scholar. |
| 23:19 | Chouser | you're too kind. |
| 23:20 | icey | you should have seen the behemoth i was hacking together to try to figure this out; I don't think I would have ever gotten to "repeatedly" |
| 23:20 | Chouser | you could use 'for', I think. |
| 23:20 | Raynes | There are several ways too do everything. |
| 23:20 | Chouser | (apply str (for [i (range 10)] (get mychars (rand 10)))) |
| 23:21 | icey | Yeah, the next thing I was trying was (def mystr (for [i (range 1 10)]) (do (get-randchars)))) |
| 23:21 | Raynes | Us new people choose the most verbose and ugly ways. |
| 23:21 | icey | apply was the other missing link |
| 23:24 | Raynes | I need to start commenting my code with a rhyme. "It makes me so sad that this code sucks oh so bad." |
| 23:38 | Raynes | "Clojure makes you fly like Python does to Python users. Haskell puts you in the seat of a really hawt and fast car and gives you an endless stretch of road and infinite gas. It really just depends on if your afraid of heights. :D" |
| 23:40 | Raynes | you're* just noticed that. |
| 23:47 | cmvkk | okay i've talked about this before, but I have this system where values are calculated with chains of closures, |
| 23:47 | cmvkk | a closure gets called with a number, it calls its 'input' closures with that number, takes the return values, generates a new value from them, then returns it. |
| 23:48 | cmvkk | any number of closures, different types of closures take different numbers of closures as input, etc. they can even be fed back into each other recursively. |
| 23:48 | cmvkk | would it be sensible to replace this with some sort of concurrent system, using agents or something? |
| 23:48 | cmvkk | i feel like i don't have a good grasp on how to make this concurrent at all. |
| 23:49 | cmvkk | you could have closures be replaced with callback fns on watchers attached to their input agents or something, maybe? but there's just all sorts of problems with any method I come up with. |
| 23:57 | durka42 | could you use futures? |
| 23:58 | cmvkk | maybe...i've heard of those but i guess I understand them less than anything else. |
| 23:59 | cmvkk | they're not in the API but they're in core.clj, heh |