#clojure logs

2009-03-08

01:07brennancI 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:08cmvkkyou could do [& args] as the arglist, then call (apply hash-map args) I guess
01:09brennancyup, hash-map was what I was looking for. thanks
01:09hiredman...
01:10hiredmanyou could just (myfunc {:key1 "val1" :key2 "val2"})
01:10brennancyes, but the less typing I have to do to call it the better
01:11brennancwant to make it as convenient as possible
01:13hiredmanwhy not leave out the keys then?
01:14Raynes{ isn't that hard to type is it? }
01:15brennancthe order may be different and all of them are optional
01:15hiredmanRaynes: half as hard if your editor automagically inserts the closing bracket
01:16brennancthe 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:16hiredmanpastbin
01:17brennanchttp://paste.lisp.org/display/76650
01:17Raynesbrennanc: (defn my-func "doc goes here" [] (println (doc my-func)))
01:18brennancoops
01:18RaynesThe documentation goes before the parameters vector.
01:20Raynes(doc ..) was the best idea ever.
01:20clojurebotGabh mo leithsc�al?
01:20brennancyup, doc definitely helps me learn a lot
01:20brennancis there something to list all functions inside a namespace?
01:21hiredmanhttp://clojure.org/namespaces
01:22hiredman,(ns-interns *ns*)
01:22clojurebot{}
01:22hiredman,(ns-interns 'clojure.core)
01:22clojurebot{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:22hiredmanthat is everything def'ed in a namespace
01:23RaynesOh that's useful.
01:23brennanccool
01:23Raynesbrennanc: This is why they call LISP "Interactive programming."
01:23brennancsometimes I need to find a function and suspect one exists. that will help me find it.
01:23hiredman(doc find-doc)
01:23clojurebotPrints documentation for any var whose documentation or name contains a match for re-string-or-pattern; arglists ([re-string-or-pattern])
01:24brennancthat one isn't as useful unless you already know what it is called
01:24brennancI tried to find stuff in a namespace using that one already
01:24hiredmanbrennanc: it takes a regex
01:24Raynesbrennanc: If you know regex it's can find virtually anything.
01:24hiredman(find-doc "ns")
01:25Raynes,(find-doc "ns")
01:25clojurebot------------------------- 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:25brennancbut only by name, not by category or by namespace
01:26brennancdoesn't help you find anything really unless it has some keyword you are looking for in the name
01:27hiredmanactually it looks through the doc string too
01:27RaynesMan, you said that just as I typed the final word of it...
01:27brennanccool
03:31dcnstrctI have two lists and I'd like to create a 3rd list out of only the items which are found in both lists
03:31dcnstrctwhat function would work best for this ?
03:33dcnstrct("foo" "bar" "baz") ("foo") result should be: ("foo")
03:35cmvkklook at sets maybe
03:36dcnstrctoh good idea, just add everything to a set and it will automatically remove the dups
03:36cmvkkyou want the intersection of the lists, though
03:37cmvkk,(intersection #{'foo 'bar 'baz} #{'foo})
03:37clojurebotjava.lang.Exception: Unable to resolve symbol: intersection in this context
03:37dcnstrctoh yah you're right
03:37cmvkkhmm, that doesn't work?
03:37hoeck,(doc clojure.set/intersection)
03:37clojurebot"([s1] [s1 s2] [s1 s2 & sets]); Return a set that is the intersection of the input sets"
03:37cmvkkoh yeah, it's in its own namespace.
03:37leafwthe mighty set namespace.
03:38dcnstrctperfecto, thnx gentlemen
03:43dcnstrctis there a simple way to create a set from a list ?
03:43hiredman,(set '(a b c d))
03:43clojurebot#{a c b d}
03:43dcnstrctdurrr
03:43dcnstrctthnx
03:47leafwby the way I don't think I've ever seen the clojure.set/index fn used or explained
03:48leafwmay anybody care to produce an example of usage
03:57hoeck,(clojure.set/index '#{{:name clojure :runtime jvm} {:name java :runtime jvm} {:name c :runtime linux}} '(:runtime))
03:57clojurebot{{:runtime jvm} #{{:runtime jvm, :name clojure} {:runtime jvm, :name java}}, {:runtime linux} #{{:runtime linux, :name c}}}
04:00hoeckleafw: it's a like the sql group-by statement
04:01leafwthanks hoeck
04:01hoeckops, i mean "its a bit like .."
04:46Drakesonhow 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:55Drakesonactually, nevermind. it wasn't c.c.sql's fault.
05:54cgrayhi, is the preferred way to access the key of a map (map key) or (key map)?
05:54cgray(in terms of speed I mean)
05:57hoeckcgray: (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:57cgrayhoeck: okay, thanks... that seems more intuitive for me to write anyway
05:58hoeckwhereas (key map) calls RT/get
05:58hoeckgotta go
06:17Lau_of_DKclojurebot: madison?
06:17clojurebotPardon?
06:17Lau_of_DKclojurebot: where is madison?
06:17clojurebotexcusez-moi
06:17Lau_of_DKDoes anyone know where/if danlarking upped Madison Square Clabango ?
06:56leafwis there any way to do "unquote splicing" in javascript? Just wondering.
06:56leafwshort of eval.
07:06Lau_of_DKGuys - 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:08ChousukeLau_of_DK: while true; do wget website; done ? :P
07:08Lau_of_DKI'll need some throttling and statistics
07:09Chousukethrottling is easy... statistics might be trickier :)
07:10hiredman500 hits an hour sounds pretty low
07:10hiredmananyway, forget using firefox for that sort of thing
07:10Lau_of_DKk
07:11hiredmanyou want something http_load
07:11Lau_of_DKI can write it up very quickly in clojure, but I wouldnt bother if there was already a tool for it
07:11hiredmanhttp://www.acme.com/software/http_load/
07:12Lau_of_DKthanks big guy
07:21Lau_of_DK./http_load -parallel 5 -fetches 1200 -verbose urls
07:21Lau_of_DK--- 60.0027 secs, 868 fetches started, 863 completed, 5 current
07:21Lau_of_DK1200 fetches, 5 max parallel, 3.9144e+06 bytes, in 82.2166 seconds
07:21Lau_of_DK3262 mean bytes/connection
07:21Lau_of_DK14.5956 fetches/sec, 47610.8 bytes/sec
07:21Lau_of_DKmsecs/connect: 0.31139 mean, 9.771 max, 0.047 min
07:21Lau_of_DKmsecs/first-response: 335.476 mean, 1039.42 max, 115.676 min
07:21Lau_of_DKHTTP response codes:
07:21Lau_of_DK code 200 -- 1200
07:21Lau_of_DK
07:21Lau_of_DKPretty descent statistics
07:33Lau_of_DKWhats the way to go,when you want to manage a thread-pool with Clojure?
07:53Lau_of_DKWasnt there a HTTP client in contrib at one point?
07:55ayrnieuLau - 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:55Lau_of_DKAs I understand, 'send' will dispatchs only as many agents as makes sense on your system in regards to performance right?
07:56kotarakI got the impression.
07:56Lau_of_DKYea - So that would be good for me, but I'd want to know how many were active at every point
08:03ayrnieuLau - 'send' uses a threadpool of size determined by the number of processors you have; send-off uses an expandable theradpool.
08:03Lau_of_DKk
08:04ayrnieu(inc Runtime.getProcessors) or something.
08:05Lau_of_DKRegarding the HTTP client in contrib - anybody know where it went/is?
08:21eivindglI'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:22eivindglis it possible to browse a library from the repl, something like in python?
08:30fyuryueivindgl: yes, you just have to require/use it (or import it, if it's a java library)
08:31Lau_of_DKThat doesnt really make it 'browseable' does it?
08:32ayrnieueivindgl - what does python do?
08:32fyuryuLau_of_DK: not sure what "browseable" actally means, I thought about doing (doc fn-name) and trying things out
08:33eivindglayrnieu, I can import a library and then read general information about it. as in (use '[clojure.contrib]) (doc clojure.contrib)
08:33eivindglI want to check if there's any procedure that finds the prime factors of a given number, how would I proceed?
08:34ayrnieuuseful, possible, but not practiced.
08:35ayrnieueivindgl - (find-doc "prime") (apropos "prime") [after you write that], ( cd ~/foo/clojure-contrib; find .|grep clj|xargs egrep prime )
08:38eivindglayrnieu: I find-doc and apropos was very useful indeed. thanks!
08:58jwinter_,(doc ns-map)
08:58clojurebot"([ns]); Returns a map of all the mappings for the namespace."
08:58jwinter_ns-map doesn't have the prettiest output, but you could use it to write your own code to browse libraries
10:24teHow difficult would it be to interop with Java by using JRuby to get to the JVM
10:28Chouserte: http://groups.google.com/group/clojure/browse_thread/thread/41e811c158d7881f/b31dc456fb5280ed
10:36teChouser: whoa
10:41Chouserte: ?
10:42lisppaste8Lau pasted "Time?" at http://paste.lisp.org/display/76656
10:42Lau_of_DKIs it due to the opening of the stream, or is there something Im not getting about time?
10:42teChouser: that's cool
10:42Chouserte: oh. good. :-) first google hit on "clojure jruby"
10:43ted'oh
10:43tei just assumed that was a crazy idea
10:43teplus there isn't a whole lot on clojure yet, so i dont think to google things like that i guess
10:44Lau_of_DKlook Chouser, now you made him get all defensive :)
10:44telol
10:44tei jsut dont wanna be a pain in the ass in here
10:44tejust*
10:45Lau_of_DKDont worry, questions belong in here, no matter their level .)
10:46teLau_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:47Lau_of_DKCompojure 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:48tewhoa, dude.
10:48teThat's huge
10:48Lau_of_DKYea - He rewrote it from scratch
10:48Lau_of_DKAs far as I understood
10:49teLau_of_DK: do you have the place he upped it to?
10:49tei googled it and found you hunting, have you gotten ahold of it?
10:49Lau_of_DKIm not sure he upped it yet
10:49Lau_of_DKAsk him tonight, I think he'll check in, in a few hours
10:50Lau_of_DKChouser: Do you get my time-example?
10:54Lau_of_DKnvm., its the stream opening and the url, that takes alot of time apparantly
10:54Lau_of_DKfirst hit on google "clojure time" :)
11:01teLauwhat's his nick?
11:09Chouseran instance of B (derived from A) cannot access protected members of any instance of A other than itself. :-(
11:10teclojurebot: haskell
11:10clojurebotYo 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:42Chouserproxy is already sufficient for public instance methods and fields, public static methods and fields, and protected instance methods.
11:43ChouserThat leaves protected instance methods, and protected class methods and fields.
11:43Chouserbleh, oops.
11:44ChouserThat leaves protected instance fields, and protected class methods and fields.
11:45ChouserIt seems worth trying to generate public instance getters and setters for those.
11:47ChouserI 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:48rhickeyChouser: I just dropped in, but I get a sense of trying to further enhance proxy?
11:48Chouserno recent previous discussion on the topic, I just don't have a better place to keep notes. :-)
11:49ChouserI just fixed up some gen-class issues, and now I'd like to make the irrelevant by adding sufficient features to proxy.
11:49Chousermake them
11:50rhickeyI'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:51rhickeybasically a version of fn that could create instances of things other than IFn and define methods other than invoke()
11:52Chouserare these thoughts related to the hooks used earlier by the lazy-seq definition?
11:52rhickeyYes, 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:54rhickey(fn [x] 42) => (instance [AFn] (invoke [x] 42))
11:54Chouserso these things could be compiled just like fns are now -- generated names, so you'd interact with their instances rather than the class.
11:55Chouserand rather than mucking about with a map of method defs, you'd generate a whole new class if you wanted to update behavior.
11:55kotarak_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:55rhickeyChouser: 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:56rhickeyChouser: right, no mapping or lookup in dispatch, also you could have (possibly primitive) 'fields' by simply closing over
11:56Chouserbut 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:57rhickeyChouser: the actual class would be a further derivee, with a numbered name
11:57Chouserah!
11:58rhickey(class (instance [AFn :as MyFn] (invoke [x] 42))) ==> MyFn__1234
11:58Chouserso 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:59rhickeyThere's so much power in fn right now that could be leveraged, closing over, primitive fields, compilation etc
11:59rhickeyChouser: right, some notion of class scope
12:00rhickeyalthough I'm not sure anything more than (.protectedMember this) is needed
12:00rhickeyThose could work because you are actually in the scope of a derived member
12:00Chouserok, if the code compiled by 'instance' really is directly in the class def itself, it might "just work"
12:01rhickeyChouser: it totally should
12:01Chousersimilarly for static protected members.
12:02rhickeyChouser: right, just some additional compiler goop for generating the invokesuper instruction
12:02rhickeysorry invokespecial
12:04Chouserso 'this' would be special so the compiler could recognize it?
12:05rhickeyI think so, unlike the early use of thisfn, it is unlikely that instance-generating macros will be nested the way nested fns were
12:06Chouserhmmm.
12:08rhickeycould still do the (instance this-name [Supers] ...) thing
12:08ChouserI suppose it could ... right.
12:09Chouserkeeping the set of this-names in a Compiler dynamic var, so it can know when to use invokespecial
12:09rhickeyI think if I had gen-interface and this instance thing I could define Clojure in Clojure with no perf loss
12:09Chousernice
12:10rhickeypresuming atom for all things that are now volatiles
12:10rhickeyplus a new mutex reference that I'm already thinking about
12:10leafwrhickey: what is the goal of writing clj in clj?
12:10rhickeyUnfortunately Terracotta can;t handle AtomicReference at present :(
12:12eevar__(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:12rhickeyleafw: 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:13Chousereevar__: try (take 10 (fibo))
12:13eevar__okies, thanks
12:14Chousereven if Clojure/Java never uses it, I can imagine there being a cononical self-hosted Clojure for use by the various ports.
12:15rhickeyleafw: 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:15leafwreads like a challenge. Would still need the JVM I guess.
12:15ChouserClojure/Java might still have a bit of a performance edge, or be more adaptable to other Java platforms like Terracotta.
12:16leafwrhickey: I am familiar with SBCL written in SBCL.
12:16rhickeyChouser: It would be a goal to make that not so
12:16Chouserbut for CLR, JS, etc. to be able to share a common set of collection definitions alone would be a big win.
12:16Chouserand a common Compiler would be nice too.
12:16rhickeyChouser: collections and the reader and the compiler...
12:17rhickeyall you need is a code-gen and some RT helpers
12:18leafwsounds promising. Clojure could become an invasive language: invading any VM out there, with a common lib/toolkit.
12:18rhickeythe 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:19Chouserit surprised me when I learned that Clojure used a non-clojure-collection AST
12:19rhickeyleafw: Clojure could live anywhere there's a simple object model
12:19leafwwhat would accessing the AST give the programmer that we don't have already via eval or macros?
12:19rhickeyChouser: yeah, I hate that, a side effect of starting from scratch
12:19Chouserleafw: the compiler knows more about the form than is expressed in the plain form
12:20rhickeyleafw: the AST doesn't change macros, but makes things much easier for code generators, editors and other tools
12:20Chousertype inference, for example.
12:20Chouseror "inferred types" would be more accurate I guess.
12:20rhickeyright- I could easily see Datalog-based add on type or other constraint checking
12:21leafwrhickey: 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:22leafw(what clj is lacking according to me, in all my shortsightedness)
12:22leafwChouser: I use vim for any coding, but for debugging i'd be great to let an IDE point out logical errors.
12:23blbrowndoes 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:24ChouserI still need to look at waterfront.
12:24kotarakleafw: 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:25Chouserkotarak: yet
12:25leafwkotarak: you created the vimrc file for clj?
12:26blbrown...what time is it 11 or 12
12:26kotarakleafw: a created VimClojure and Gorilla (now merged with the former). Now working on smart omni completion.
12:26kotarak17:25
12:26blbrown12 dammit
12:26Chouser12:25 EDT
12:27leafwkotarak: thanks so much :)
12:29Chouserrhickey: so is there any part of 'instance' that I could help with, or should I just leave you alone.
12:30leafwkotarak: the screencast video is no longer available.
12:33rhickeyChouser: 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:34rhickeyThe easiest route is to copy Compiler.FnExpr and FnMethod and hack into InstanceExpr and InstanceMethod
12:34rhickey(or maybe other names)
12:35rhickeyAt the root, the behavior of instance is a generic version of that of fn
12:36ChouserI see. This will need integration with the Compiler, unlike proxy.
12:37rhickeyChouser: that's the problem, it would be much simpler to write in Clojure, as would the rest of the compiler
12:37Chouserheh. right.
12:37Chouseras would everything.
12:38rhickeyThe compiler's 5000 lines of Java, I'd be surprised if it was 1000 lines of Clojure
12:39rhickeyI 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:40Chousukeif you did that, would it be possible to remove most of the other 5k?
12:41Chousukeeventually, that is
12:41rhickeyOne 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:43rhickeythe first step would be an analyzer for Clojure in Clojure that yielded a Clojure AST
12:44ChouserUsing the existing Compiler$Foo classes?
12:44rhickeyChouser: no, Clojure AST is all Clojure data structures
12:45rhickeyThen code gen is just an (emit target-generator expr context) multimethod
12:45Chouserso 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:45Chouserlike ClojureScript has. :-)
12:46rhickeyyou'd want to abstract out both code gen and also type reflection
12:46Chouserwould the Clojure AST be the original forms decorated with more metadata? or new structmaps/
12:47rhickeyChouser: probably the latter, with the former embedded, they lose 1:1 at some points
12:48rhickeyThere's also some simple rewriting that currently occurs in place
12:48rhickeysome things can't be expressions without being wrapped in lambdas
12:49tehttp://blog.rubyenrails.nl/articles/2008/12/12/calling-clojure-from-jruby
12:49teim 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:49ChouserI need to undestand the purpose and usage of the Compiler .emit() methods.
12:49kotarakleafw: 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:49Chousernot those
12:50Chouserthe .eval() methods
12:51rhickeyChouser: 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:51Chouseroh, ok.
12:51leafwte: so, is that folder in your classpath? Ask your interpreter: (System/getProperty "class.path")
12:51teleafw: okay let me check
12:52teleafw: java.lang.Exception: No such namespace: System (NO_SOURCE_FILE:0)
12:53leafwte: was "java.class.path", sorry.
12:53leafwand that is one bizarre error. Call then as java.lang.System
12:54te[...] clojure-contrib.jar:.:classes"
12:54tethats the end of my output
12:54tethe other two things are just my clojure.jar and clojure-contrib.jar
12:55teso no nl/rubyenrails is not in my classpath
12:56teleafw: can you get that guy's example working?
12:56leafwdidn't try.
12:57teleafw: its not in my classpath, how do i (compile 'nl.rubyenrails.Blog)
12:58tetechnically because i have the classes dir in rubyenrail it should work
13:00tei give up
13:00leafwte: http://tinyurl.com/arhwk8
13:04Chouserrhickey: first step is analyze, not read?
13:07rhickeyChouser: right, the result of a Clojure read would be no different
13:07Chouserok
13:07rhickeyThe compiler is the prize, then instance, then anything is replaceable
13:09rhickeyanalyze would need to take a pluggable reflector abstraction to handle types, interface implied by Reflector
13:09rhickeyUse of interfaces would be fine too, since there will be a portable way to define them
13:10rhickeyAn important point is that interfaces will remain important, never will be replaced by multimethods for perf reasons
13:12rhickeyinterfaces are highest-perf polymorphism, but closed sets of functions, multimethods are more flexible and open, but have higher dispatch costs
13:12Chouserthough the flexibility of multimethods would probably be worthwhile for compile time processing, right?
13:12rhickeyalso interfaces are not insertable after the fact
13:13rhickeyChouser: sure, multimethods would be fine for compiler's analyze/emit etc
13:13rhickeyThe Java compiler is a reimplementation fo CL code that used generic functions
13:19rhickeyinterestingly, I moved away from the GFs once I started generating Java/C# source, don't remember why
13:20rhickeyhttp://code.google.com/p/clojure/source/browse/trunk/src/lisp/clojure.lisp?r=300
13:23rhickeyso. 1600 lines of CL, emits Java and C# source
13:24ChouserI've got 15 lines so far -- 1% done!
13:34rhickeyhah!
13:36rhickeyChouser: 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:37Chouserok
13:37rhickeyOne reader change I might make is to move syntax-quote to the compiler
13:37Chouserok, makes sense.
14:03digashi think it has to do with an ability to construct quoted cycles at the read-time w/ character-macros #n= and #n#
14:05rhickeydigash: yikes, can't do that anyway, no #n= yet
14:07gnuvince_Hello everyone
14:07digashwhat about cl #. :)
14:07ayrnieudigash - clojure spells that #=
14:07gnuvince_What's going on? Compiler rewrite?
14:09digash(define bar (quote #.(let ((list '(0 1))) (set-cdr! (cdr list) list) list)))
14:10digashthat is another reason for quote at the read time makes it easier to deal with this mess.
14:12Chousergnuvince_: just some sunday-afternoon amusement.
14:14rhickeyayrnieu: #= is not quite #., all of the args must be read-time constants, it is not full read-time eval
14:14ayrnieuah.
14:17digashbtw, this is straight from "Lisp In Small Pieces"
14:17digashp144
14:18ayrnieuwhat, that (define bar ...) ?
14:18digashyep
14:24gnuvince_Chouser: so no compiler bootstrapping?
14:25Chousergnuvince_: well, maybe...
14:25digashhttp://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:36rlbIs sqlitejdbc the best choice for use from clojure right now?
14:41rhickeydigash: yeah, I like that too. syntax-quote is somewhat complicated by vectors, maps and metadata
14:42rlb(I also noticed javasqlite...)
14:43cp2hah, http://pastebin.com/d7fe66f73
14:54p_lrlb: well, with sqlitejdbc you are keeping yourself to industry-standard API ;-)
14:57rlbHmm, there's also hsql...
15:19pjstadigshould the nodes member of a BitmapIndexedNode ever be sparse?
15:20pjb3,(let [x 1] (eval '(+ x 1)))
15:20clojurebotDENIED
15:20pjstadigI'm tracking down an error with TC where adding to a PersistentHashMap causes an NPE
15:20pjb3That ends up throwning java.lang.Exception: Unable to resolve symbol: x in this context (NO_SOURCE_FILE:59)
15:20rhickeypjstadig: no
15:21pjb3Is that the way it is, you can't refer to let bound locals in an eval statement?
15:21pjstadigit's trying to create a new BitmapIndexedNode with a nodes array that has holes in it
15:21pjstadigthe first node especially is null which causes an NPE in the constructor
15:21rhickeypjstadig: by holes you mean nulls?
15:21pjstadigyeah
15:22pjstadigi've run into this before, and it was usually related to a hashCode or object identity issue
15:23pjstadiglike where an object that should be the same is hashing differently because its a TC object instead of a local object
15:28rhickeypjstadig: I still don't see how a null gets in there
15:28rhickeynull is specially handled in without, and assoc only inserts new LeafNode
15:30rhickeypjb3: the eval has no connection to the lexical scope
15:31pjb3rhickey: yeah, that appears to be the case
15:31pjb3I'll just have to use a macro to do what I'm trying to do
15:32pjb3Basically I'm getting a data structure from somewhere else that I want to eval in the context of the let locals
15:32pjb3So if I do
15:32pjb3(let [x 1] (my-marco get-data))
15:32pjb3had have that expand to
15:32pjb3(let [x 1] (+ x 1))
15:32pjb3then it should work, right?
15:34rhickeyit will probably look like (my-macro [x 1] (get-data))
15:34rhickeyunless your macro has hardwired 'x
15:36pjb3get-data will return '(+ x 1)
15:36pjb3and I want to assign a value to x for the purposes of evaling it
15:36pjb3get-data is really more like get-template
15:37pjb3that would return something like
15:37pjb3(str "Dear " recipient ",\n")
15:38pjb3so I would do (let [recipient "Rich"] (eval-template (get-template :dear-john-letter)))
15:39pjstadigrhickey: it's obviously something related to TC going haywire
15:39pjstadigjust had to be sure
15:39pjb3(get-template :dear-john-letter) returns (str "Dear " recipient ",\n")
15:39pjb3so what I ultimately want to do is
15:39pjb3(let [recipient "Rich"] (str "Dear " recipient ",\n"))
15:40rhickeypjstadig: ok, if ever you think you've found a bug, just let me know
15:40pjstadigit's happening when trying to intern a new var
15:40pjstadigafter reconnecting to TC
15:47pjstadigok
15:48pjstadigif i switch namespaces and then back again to user
15:48pjstadigi can def a new var
15:49pjstadigit must be something about the way the second JVM is connecting and booting up
15:49Lau_of_DKGood evening gents
15:57AWizzArdrhickey: very good suggestion that you made (GG), about the use of Hashmaps in Clojure
16:01rhickeyAWizzArd: thanks, all those apis are so close to being interoperable
16:03AWizzArdCurrently 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:06dcnstrctquick 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:07dcnstrctinput ("foo" "bar" baz") output should be: 0 because "foo" is in position one.
16:08eivindglanybody 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:09dcnstrct["foo", "bar", "baz"].each_with_index { |str, idx| return idx if str == "foo" }
16:09dcnstrctthats how it might look in Ruby for example
16:09Lau_of_DKdcnstrct: I have a hack in mind :)
16:09Lau_of_DK,(count (take-while #(not= % "foo") ["bar" "foo" "biz"]))
16:09clojurebot1
16:10dcnstrctwow it works, but I'm not familiar with take-while I'll look it up
16:10dcnstrctthnx this'll do for now
16:10AWizzArd,(doc take-while)
16:10clojurebot"([pred coll]); Returns a lazy sequence of successive items from coll while (pred item) returns true. pred must be free of side-effects."
16:10Lau_of_DK,(take-while #(< 5 %) (range 10))
16:11clojurebot()
16:11gnuvince_dcnstrct: it does waht it says: takes element from a seq while a predicate holds.
16:11rhickey,(.indexOf ["foo" "bar" "baz"] "foo")
16:11clojurebot0
16:11Raynesrhickey: Damn you. I was about to say that :(
16:11Lau_of_DKuuuh hickey :)
16:11gnuvince_,(.indexIf ["bar" "baz"] "foo")
16:11clojurebotjava.lang.IllegalArgumentException: No matching method found: indexIf for class clojure.lang.LazilyPersistentVector
16:11gnuvince_,(.indexOf ["bar" "baz"] "foo")
16:12clojurebot-1
16:12dcnstrct:) thnx ppl.
16:14gnuvince_rhickey always has the shortest code, cause he's one of the few who really knows Java here, I think
16:14RaynesI don't know Java, but I knew that method and I was typing it but he finished before me.
16:18leafwif you don't use an IDE, your fingers memorize th API, particularly for all the main interfaces: List, Map, Set, Collection.
16:20dcnstrctjava.lang.IllegalArgumentException: No matching method found: indexOf for class clojure.lang.LazyCons
16:20dcnstrctI guess I need to turn it into a list first.
16:20leafwright.
16:22rhickeydcnstrct: that looks like old Clojure
16:22rhickeyall seqs now implement List
16:23dcnstrctoh junk you're right it is. Glad to know that I'll upgrade.
16:23AWizzArdwb kotarak
16:34dcnstrctnow with the clojure from SVN it's a different error
16:34dcnstrctjava.lang.IllegalArgumentException: No matching field found: indexOf for class clojure.lang.PersistentList
16:34dcnstrcthrmm I'll play aorund /w it
16:35Raynesdcnstrct: Paste your code?
16:36dcnstrctnevermind I found I introduced a typo.. works great now that I have new clojure
16:58Lau_of_DKGuys - 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:00durka42you could queue them up somewhere and have an agent dispatch them on a timer
17:01Lau_of_DKThats true
17:01Lau_of_DKThats not bad
17:02durka42i've done that in java, and my code was probably horribly un-thread-safe
17:02durka42but clojure can help with that
17:03Lau_of_DKit sure can
17:03rlbYou could also make a "producer" that will only produce one value per however long.
17:04rlbi.e. a timed sequence/queue.
17:04Lau_of_DKWhat would you see being the advantage of that approach ?
17:04mgarrissis it standard practice to use a '-' between words in a namespace? example: (ns foobar.two-words)
17:05kotarakmgarriss: sure, why not? Just remember that the corresponding file is foobar/two_word.clj
17:06mgarrisskotarak: good to know. thx
17:06rlbLau_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:06Lau_of_DKok
17:06rlbLau_of_DK: basically I was wondering about a lazy, time-metered, sequence.
17:07Lau_of_DKI'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:07rlbLau_of_DK: I suspect that the other approach is more likely to be what you want unless you have special needs.
17:08Lau_of_DKI have a special need, I have a contract from a customer with performance demands I need to document are met :)
17:18hiredmanyou could, instead of directly executing your send-offs, send them to a scheduledthreadpoolexecutor
17:18Lau_of_DKHow would that work ?
17:19hiredmanactually, hmmmmm
17:19hiredman~jdoc java.util.concurrent.ScheduledThreadpoolExecutor
17:20Lau_of_DK404
17:20hiredmanupper case p
17:20kotarakcapital P?
17:20Lau_of_DKlarge p ?
17:20kotarak,(.toUpperCase "p")
17:20clojurebot"P"
17:20Lau_of_DKInteresting - only one downside, I already implemented the other solution :)
17:21kotarakLau_of_DK: in Thread*p*ool
17:21Lau_of_DKI'll have a looksie in a bit, thanks
17:21Lau_of_DKIm kidding you guys, I knew it :)
17:21hiredmanactually, I think it might be btter to proxy Executor anyway
17:21hiredman*couhg*
17:21hiredmanYes, well
17:23hiredmanI have a concurrent directory walker (returns a recursive file listing) that uses a threadpoolexecutor
17:23hiredmanit makes my poor c2d spin and spin
17:24Lau_of_DKcan my worker func only take the one arg a ?
17:28Lau_of_DKor does send-off just hardcoded pass *agent* as the first arg, and then the rest as you please?
17:30Chouser*agent* is bound to the currently running agent. the first arg is the state of the agent.
17:30hiredmanyeah
17:31Lau_of_DK(defn worker [a x y z] (do stuff) (send-off *agent* worker (inc x) (inc y) (int z)))
17:31Lau_of_DKwould that fly ?
17:38rosejnAnyone know how to apply arguments to a java method? For example, (apply .startsWith '("asdf" "as"))
17:38rosejnwhich doesn't work...
17:38Chouserrosejn: can't really do it.
17:38rosejndarn
17:39rosejnchouser: any way to work around this? I need to call a java method with variable arguments that I create from Clojure.
17:39Chouserthere might be a way that involves runtime reflection.
17:40cmvkkcan you wrap it in a function of its own?
17:40Chouserthe method sig includes variable args?
17:40rosejnyeah, Object...
17:40kotarakrosejn: http://paste.lisp.org/display/67182
17:42Chouserbut if you just want to pass in args to method like foo( String, Object... ) you don't need reflection
17:43rosejnkotarak: cool, thanks!
17:43rosejnhow do you do it then?
17:44Chouserit actually wants an array of Object
17:45lisppaste8Lau pasted "stress-test" at http://paste.lisp.org/display/76669
17:45Chouser,(String/format "%s and %s" (into-array ["one" "two"]))
17:45clojurebot"one and two"
17:45Lau_of_DK2 questions, 1) will this produce reliable results when it runs? 2) why doesnt it run ?
17:48rosejnchouser: is it possible to call an instance method like that, or does it have to be static?
17:48Chouserinstance methods work the same way
17:48fyuryuwhat's the equivalent of Java's super(args); in Clojure? (using gen-class)
17:50Chouserfyuryu: use :exposes-methods to give the super's method a new name, then call that.
17:50rlbOK, I hacked sqlitejdbc to work with openjdk-6 (at least it appears to work)...
17:50fyuryuChouser: ah, thanks
17:56durka42Lau_of_DK: define "doesn't run"?
17:58StartsWithKlisppaste8: help
17:58lisppaste8To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.
17:58lisppaste8Lau annotated #76669 "error" at http://paste.lisp.org/display/76669#1
18:01durka42the NPE seems to come from clojure.lang.Numbers/divide
18:02Lau_of_DKOh youre right - its not being cast
18:03durka42but i don't see where anything is null
18:04lisppaste8StartsWithK pasted "Swing builder first run" at http://paste.lisp.org/display/76671
18:04Lau_of_DKI've cast the 2 ints now, but it still goes NPE
18:04Lau_of_DKLooks like replicate is borking
18:05Lau_of_DKwhich it shouldnt
18:06StartsWithKjust 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:06Lau_of_DKSure would be nice if Clojure just said "Line 25 produces this error"
18:07durka42{:thead-count "3", :rpm "3", :url "http://www.google.com&quot;}
18:07durka42you need those to be numbers
18:07StartsWithKand knows how to 'erase' lexical scope, so widgets can be created on the spot and reference other widgets that are created after it
18:08durka42oh...
18:08durka42you misspelled thread
18:08durka42hence nil
18:08Lau_of_DKI just saw that :(
18:08Lau_of_DKGuess I cant blame Rich for that one
18:08durka42online 30
18:10Lau_of_DKIt runs fine now
18:10Lau_of_DKJust hopes it produces accurate results
18:11Lau_of_DKI think my fetch-site needs to be fitted to report 404's and 500's
18:15leafwI am having trouble reading the value of a static field in a static subclass
18:15leafw,(println javax.swing.event.HyperlinkEvent.EventType/ACTIVATED)
18:16clojurebotjava.lang.ClassNotFoundException: javax.swing.event.HyperlinkEvent.EventType
18:16leafw,(println javax.swing.event.HyperlinkEvent$EventType/ACTIVATED)
18:16clojurebot#<EventType ACTIVATED>
18:16leafwaha
18:16leafwthe sign of the $
18:16Lau_of_DKIts all about the money
18:17leafwsaid Francisco d'Anconia.
18:24Lau_of_DKI think it was 'Maya'
18:31hiredmanI think seque is what I want, I just cannot fiure out how to use it
18:33Chouserit acts like (map identity ...)
18:33Chouserexcept the ... part can run on ahead of the thing that's taking from map.
18:34hiredmanok, maybe not
18:35hiredmanwait
18:35hiredmanseque is for making a seq out of queue?
18:38hiredmanI think I will just use a lbq and a lazy-seq
18:53hiredman~def future-call
19:05spacema__anyone had trouble getting clojure compiling on os x with java 1.6?
19:05spacema__I'm seeing this error: Apple AWT Startup Exception : *** -[NSCFArray insertObject:atIndex:]: attempt to insert nil
19:06spacema__it's talked about at 19:45 on the logs here http://clojure-log.n01se.net/date/2008-11-15.html
19:06spacema__but that doesn't seem like a really nice solution - anyoen got something better?
19:11hiredman~def seq
19:12durka42~def in-ns
19:15hiredman,(import 'java.util.concurrent.LinkedBlockingQueue)
19:15clojurebotnil
19:16hiredman,(let [q (doto (LinkedBlockingQueue.) (.put 1) (.put 2)) s (seq q)] (.put q 3) s)
19:16clojurebot(1 2 3)
19:16hiredmanmmmmm
19:16hiredman,(let [q (doto (LinkedBlockingQueue.) (.put 1) (.put 2)) s (seq q)] (.put q 3) (class s))
19:16clojurebotclojure.lang.IteratorSeq
19:27AWizzArd,(let [[f & r] #{10 20 30}] (println f r))
19:27clojurebotjava.lang.UnsupportedOperationException: nth not supported on this type: PersistentHashSet
19:28AWizzArdhow again is destructuring done for sets?
19:29kotarak,(let [[f & r] (seq #{10 20 30})] (println f r))
19:29clojurebot10 (20 30)
19:29rhickeyAWizzArd: there's no basis for destructuring sets, you could seq it for positional destructuring
19:29Raynes,(doseq [[a b] [1 2 3 4]] (+ a b))
19:29clojurebotjava.lang.UnsupportedOperationException: nth not supported on this type: Integer
19:30AWizzArdoki, thx
19:30RaynesHrm. Maybe I should read the doseq part of Programming Clojure again...
19:30durka42Raynes: are you thinking of partition perhaps?
19:30leafwwhat is the best way to get the last elemnt of a vector?
19:31durka42,(doseq [[a b] (partition 2 [1 2 3 4])] (prn (+ a b)))
19:31clojurebot3 7
19:31Raynes,(last [1 2 3])
19:31clojurebot3
19:31Raynes^
19:31leafwlast -- ok, should have guessed :)
19:31RaynesI apparently have no clue how destructuring works.
19:32durka42you provide a data structure of things to bind to, exactly mirroring the data structure that the values come from
19:32Raynes(doc partition)
19:32clojurebotReturns 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:32kotarakleafw: peek
19:32durka42,(partition 2 [1 2 3 4])
19:32clojurebot((1 2) (3 4))
19:32kotarak,(peek [1 2 3])
19:32clojurebot3
19:32RaynesOh I see.
19:33kotarakleafw: last is O(n), peek O(1), IIRC
19:33RaynesIs prn a println wrap?
19:33RaynesOr is it different in some way.
19:33kotarak,(prn "Hello")
19:33clojurebot"Hello"
19:34kotarak,(println "Hello")
19:34clojurebotHello
19:34RaynesAh.
19:34durka42println wraps prn with *print-readably* bound to nil
19:35leafwkotarak: thanks
19:36Raynes,(doseq [[a b] ["a" "b"]] (println (str a b)))
19:36clojurebota b
19:42hiredmanhmmm
19:43rhickey,(str \a nil)
19:43clojurebot"a"
19:54dreish,(class (eval (list 'quote (symbol "{:a 1}"))))
19:54clojurebotDENIED
19:54dreishMeh.
19:54dreishanswer: clojure.lang.PersistenArrayMap
19:54dreisht
20:06durka42i get clojure.lang.Symbol
20:10zakwilsonBreath of fresh air, isn't it?
20:11mgarrissi'm excited about a language for the first time since i found ruby
20:12hiredmanis there something in core that will make a lazy-seq out of a blockingqueue?
20:12rhickey,(doc seque)
20:12clojurebot"([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:12mgarrissi just moved to emacs after years with vim, elisp made me realize my "too many parenthesis" argument was idiotic
20:13mgarrissclojure seems like the right LISP to learn
20:13ChouserI'm trying out a new working theory about the parens.
20:14hiredmanrhickey: I just don't get that
20:14Chouserin c-ish languages, foo() means a function call.
20:15ChouserIn most lisps, (foo) could be anything -- part of a cond expression, an arg list, a function call, who knows?
20:15rhickeyhiredman: seque will put a blocking queue in line between a lazy seq and its consumer
20:16Chouserit takes more context, and specific knowledge of sufficient builtin words in order know anything about that pattern.
20:16Chouserwhich 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:17Chousukeyou managed to confuse me for a moment there :)
20:17ChousukeI read your (for me) as lisp
20:17rhickeyhiredman: try it:
20:17rhickey(def sq (seque 4 (map #(do (prn %) %) (range 1000000))))
20:17rhickey(take 10 sq)
20:17hiredmanrhickey: that seems like the reverse of what I want
20:17Chouserbindings use vectors, literal data collections use [] or {}
20:17ChouserChousuke: ha!
20:17cmvkkon 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:17rhickeyhiredman: someone else has a queue you want to consume?
20:17hiredmanyes
20:18Chousukecmvkk: vectors and maps are functions :)
20:18cmvkkwell that's true...
20:18Chousercmvkk: don't other lisps have non-list data types?
20:18ChousukeI think "operation" is a better word
20:18cmvkkyeah but you don't see them in calling position.
20:18Chousukeor operator
20:18cmvkkis what i meant.
20:18Chouseroh, I see.
20:19zakwilsonA vector is a function of its index. Vectors and maps are functions in the mathematical sense when used that way.
20:19zakwilsonIt's things that might do IO mutation or some such that aren't.
20:19Chouserone of the few exceptions is the proxy form, where (foo [] ...) defines a method named foo
20:19zakwilsonerr... IO or mutation.
20:20cmvkknot to mention any other macro that repurposes the list form for whatever, but i suppose that's not in the core
20:21Chousersure's it's possible, but it's not common.
20:21zakwilsonIt 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:21hiredmanrhickey: I think what I really want is not possible
20:21Chousukein clojure it can be done only when it helps readability
20:22Chousukein the proxy case, I think having a list is somewhat more readable than vectors
20:22cmvkkit might help to prepend the method defs with "method" to make them look more like defn calls or whatever?
20:22ChouserChousuke: I agree [foo [] ...] would feel a bit weird.
20:22hiredmana 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:23hiredmanmy producers are just not co-ordinated enough for that
20:23Chouserhiredman: yeah, you'd have to have a "done" sentinel in there.
20:23Chouserwhich is what seque does, iirc.
20:23rhickeyhiredman: that's a general problem with queues, termination is an application-level problem
20:25hiredmanI have a sneaky feel .poll is just asking for a race
20:25hiredmanfeeling
20:32slashus21Why does running (seque 4 (range 200)) over and over again sometimes produce different results?
20:33hiredmandifferent?
20:33slashus21The resulting sequence is different.
20:33slashus21different length, different numbers.
20:33Chouserlooks the same to me.
20:34hiredmansame here too
20:34Chouseryou should always get a sequence starting with 0 and going in order to 199
20:34hiredmanslashus21: is (seque 4 (range 200)) exactly what you are doing?
20:34slashus21hiredman: I am just toying with it.
20:35hiredmanits output in the repl is identical to (range 200)
20:35Chouserif you ever see a number out of order or the the range starting or ending with different numbers, that would be significant.
20:35slashus21(seque 2 (lazy-seq (range 20)))
20:35slashus21(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:35slashus21disregard (lazy-seq
20:35slashus21same results without it
20:36Chouserhmph
20:37Raynes(doc seque
20:37clojurebotIt's greek to me.
20:37RaynesOops
20:37Raynes(doc seque)
20:37clojurebotCreates 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:38Chouser,(first (filter #(not= % 20) (repeatedly #(count (seque (range 20))))))
20:38clojurebotExecution Timed Out
20:39Chouserslashus21: I'd recommand a clean and rebuild. You've got something screwy going on.
20:39slashus21(seque (range 20)) is consistent, but (seque n (range 20)) isn't
20:39ImOuttaYourMonadhow can I combine for with a function to update soemthing? like get all pixels form an image?
20:39slashus21,(first (filter #(not= % 20) (repeatedly #(count (seque 2 (range 20))))))
20:39clojurebot34
20:42slashus21Is this the correct behavior?
20:42ChouserI don't think so
20:45slashus21,(first (filter #(not= % 2000) (repeatedly #(count (seque (range 2000))))))
20:46clojurebotExecution Timed Out
20:46slashus21,(first (filter #(not= % 500) (repeatedly #(count (seque (range 500))))))
20:46clojurebotExecution Timed Out
20:46slashus21I don't think this works either.
20:46Chouser,(first (filter #(not= (count %) 20) (repeatedly #(seque 10 (range 20)))))
20:46clojurebot(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:09ImOuttaYourMonaddoes clojure have letrec?
21:09ImOuttaYourMonadnesting loop seems really awkward
21:09rhickey,(doc letfn)
21:09clojurebot"([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:12gnuvince_rhickey: read your post regarding maps. Nice (although I guess I'm guilty of using vectors myself)
21:22ChouserWell, I'm not seeing what's wrong with seque.
21:22slashus21Chouser: I have been looking at it too.
21:22Chouserok, I'll leave you to it.
21:23slashus21Chouser: Any idea of what could be wrong?
21:24Chousernot really. small queues seem to exasperate it.
21:24slashus21Small buffer sizes in comparison to the actual queue size?
21:27Chousersmall blocking queue compared to a large blocking queue, for the same sized input seq
21:28Chousernot much code there, seems like it ought to be easy to track down.
21:28Chouser:-)
21:43Chouserslashus21: if you give up, please post to the group so we don't lose track of the bug.
21:43hiredmanhttp://github.com/hiredman/odds-and-ends/blob/47e32cbfe21957dc538722ed4f62b77899735954/pwalker.clj my parallel directory walker if anyone is interested
21:43slashus21Chouser: Okay
21:57Chouserrhickey: have you looked at error-kit at all?
21:58rhickeyChouser: briefly, I found it baffling
21:58Chouserhm. great.
21:58rhickeyI can't say I gave it enough effort, just a first impression
21:59Chouserok, just curious.
21:59rhickeyI wonder, have you described the motivation somewhere - what problem does it solve?
21:59rhickeyFWIW I feel the same way about CL conditions - very complex
21:59Chouseryeah
22:00Chouserwell, I posted to the group -- that's the most explanation I've given.
22:02Chouserbut I don't think I justified all the features. I didn't want to leave out any features of CL's conditions.
22:04rhickeyI wonder about these stack-based error handling mechanisms in the face of concurency
22:04rhickeyseems like you want error queues or something
22:04rhickeyat least for reporting
22:05Chouserwell, it's all thread-local.
22:05rhickeyright, but when the error is in an agent...
22:06Chouseryes, error-kit doesn't address that at all.
22:07Chouserbut, 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:57hiredmanhttp://twitter.com/clojurebot/status/1298555118 it works!
22:59cmvkkhmm
22:59cmvkkit's hard to think of 'clojurebot' as an IRC bot now then
22:59cmvkkit's more like a bot with an IRC component
22:59hiredmanmuahahah
23:00iceyi'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:00iceyi'm doing (def randstr (dotimes [x 10] (get mychars (rand 10)))
23:00iceybut it always comes back as an empty list
23:01iceymychars is a just a string
23:02danlarkin__I love the clojurebot icon
23:13hiredmandanlarkin__: :(
23:13danlarkin__hiredman: why the long face, I wasn't being sarcastic
23:14hiredmanI was just going to change it
23:14hiredmanand now I have to keep it
23:14danlarkin__bahaha
23:14Chousericey: mychars is a String? I don't think 'get' will work.
23:14Raynes(doc get)
23:14Chouseroh. hm, I guess it does.
23:14clojurebotReturns the value mapped to key, not-found or nil if key not present.; arglists ([map key] [map key not-found])
23:17iceyChouser: 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:17Chousericey: dotimes always returns nil
23:18iceychouser: I'm getting closer by using a "for" now... at least poking around like this is a good learning experience :D
23:18Chouser(apply str (take 10 (repeatedly #(get mychars (rand 10)))))
23:19iceyChouser: you sir, are a gentleman and a scholar.
23:19Chouseryou're too kind.
23:20iceyyou 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:20Chouseryou could use 'for', I think.
23:20RaynesThere are several ways too do everything.
23:20Chouser(apply str (for [i (range 10)] (get mychars (rand 10))))
23:21iceyYeah, the next thing I was trying was (def mystr (for [i (range 1 10)]) (do (get-randchars))))
23:21RaynesUs new people choose the most verbose and ugly ways.
23:21iceyapply was the other missing link
23:24RaynesI need to start commenting my code with a rhyme. "It makes me so sad that this code sucks oh so bad."
23:38Raynes"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:40Raynesyou're* just noticed that.
23:47cmvkkokay i've talked about this before, but I have this system where values are calculated with chains of closures,
23:47cmvkka 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:48cmvkkany 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:48cmvkkwould it be sensible to replace this with some sort of concurrent system, using agents or something?
23:48cmvkki feel like i don't have a good grasp on how to make this concurrent at all.
23:49cmvkkyou 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:57durka42could you use futures?
23:58cmvkkmaybe...i've heard of those but i guess I understand them less than anything else.
23:59cmvkkthey're not in the API but they're in core.clj, heh