clojurescript: js* question
I know it is not the done thing but I have a question regarding js* I have a complex fn defined in a javascript file. it is self contained and uses no globals. It is not currently worth my while to rewrite. I can use this by doing: (def my-fn (js* "...file contents with escaped chars...")) and the my-fn is callable in the defined namespace. I can use a foreign-libs compiler option but I don't want the function in the global namespace. I would like to define a macro read-js* that reads from a file on the class path and allows (def my-fn (read-js* "js/js-file.js")) is this possible? I have tried but run into problems with js* - for a start I can't find where it is defined. I have tried: (def f (js* (from-local-file "js/file.js"))) where from-local-file is a macro that resolves to a string of the file contents - but this throws an exception. Is there a more appropriate way to do this? for reference - the js file I am using is a very slightly modified form of http://www.webtoolkit.info/javascript-md5.html Thanks for any pointers. Dave -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
[Ann] [cljs-hash "0.0.1"] - hash functions for clojurescript
currently md5, sha1, sha356 * clojars [cljs-hash "0.0.1"] * github https://github.com/davesann/cljs-hash Dave -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Persistent Data Structure and Persistent Types
Hi, I'm post the question at clojure group because I am looking for way to solve a problem which clojure's persistent data structure seem fit. I am use CLR (C#) as programming language and I'm developing a simulation application. Without going to much into detail the simulation involve activities with properties and executing them using some algorithm in a loop. Each cycle of the loop is a single step in the simulation and I would like to keep all the information of each step, without killing the application memory or CPU. This is where the persistent data structure seem like a good fit, the both persist and have great performance. My problem is how to manage the rest of the data. I each step I have list of activities, because the might change on each step, and the list of properties of each activity. Taking Clojure (and Rich's) attitude to the limit both activities and properties should be immutable as well as the data structures holding them. But (there's always a but) the data should be able to change inside a single step. So it means every change I made to activity I should replace the old activity with the new activity in the current step vector. Also each change the activity's property I should copy the activity (because it is immutable) and replace the old activity with the new one again. Is that a good way to go? I couldn't find much documentation about how to create full immutable application. I understand I'm mixing functional and OO principles, I hope I'm not to wrong about it. Thank you, Ido. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: A Bug of map function?
Thanks Alan. Hope this will be changed. On 2月14日, 上午3时06分, Alan Malloy wrote: > If this is a bug, it's in eval, not in map. eval apparently just > doesn't like to be handed lazy sequences, or something: > > repl-1=> (eval `(quote ~(lazy-seq nil))) > CompilerException java.lang.UnsupportedOperationException: Unknown > Collection type, compiling:(NO_SOURCE_PATH:14) > > ;; just to demonstrate that these are the same value: > repl-1=> (= `(quote ~(lazy-seq nil)) > repl-1=*`'~(map identity ())) > true > > This looks like it's caused > byhttps://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/C... > - it should probably be testing for ISeq, not IPersistentList. > > On Feb 13, 1:02 am, Eric Fong wrote: > > > > > > > > > => (eval `'~(map identity [1 2 3])) > > (1 2 3) > > > => (eval `'~(map identity ())) > > CompilerException java.lang.UnsupportedOperationException: Unknown > > Collection type, compiling:(NO_SOURCE_PATH:135) > > > => (eval `'~(map identity nil)) > > CompilerException java.lang.UnsupportedOperationException: Unknown > > Collection type, compiling:(NO_SOURCE_PATH:138) > > > try the above in repl, clojure 1.3, why the exception occured? -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
replace a list element
Hi, I am new to clojure and I am very excited about learning the language. I have a question about replacing an element in a list. I have elements that look like this : {:id G__781, :value 1} The list looks like this: ({:id G__821, :value 1} {:id G__820, :value 1} {:id G__819, :value 1} {:id G__818, :value 1} {:id G__817, :value 1}) I want to update an element in the list by conjoining a new list with an updated element. For example, I'll update the head of the list: ({:id G__821, :value 10} {:id G__820, :value 1} {:id G__819, :value 1} {:id G__818, :value 1} {:id G__817, :value 1}) My update code (it really builds a new list with and replaces the updated element) looks like this: (defn update-id-list [id-list new-id new-id-list] (doseq[old-id id-list new-id-list (conj new-id-list (choose-id old-id new-id) )] (println "New List " new-id-list)) new-id-list) (defn choose-id[old-id new-id] (if (= (:id old-id) (:id new-id)) new-id old-id)) This doesn't work. It never conjoin's elements and ultimately returns an empty list. I've tried using various other methods but I keep going in circles. Any ideas why this wouldn't work? Thanks, James -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: ClojureScript def, vars, and binding
To redeem myself for the noob threading mistake, *I've implemented Var and friends in ClojureScript*: https://github.com/brandonbloom/clojurescript/compare/8ba4849e60e5957cdac36ef6946c647e824ca3c8...vars This branch includes (almost) the full set of relevant functionality, but for performance and interop reasons, only applies to vars def-ed with ^:dynamic. Here's a repl session: ClojureScript:cljs.user> (def ^:dynamic x "root binding") (var cljs.user.x) ClojureScript:cljs.user> x "root binding" ClojureScript:cljs.user> #'x (var cljs.user.x) ClojureScript:cljs.user> ((binding [x "dynamic binding"] (fn [] x))) "root binding" ClojureScript:cljs.user> ((binding [x "dynamic binding"] (bound-fn [] x))) "dynamic binding" Complete list of newly supported forms: - var - alter-root-var - bound-fn - bound-fn* - bound? - get-thread-bindings - push-thread-bindings - thread-bound? - var-get - var-? - with-bindings - with-bindings* I'm filling out my contributor agreement and will start a parallel thread on clojure-dev to see if we can get this integrated! Cheers, Brandon -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Persistent Data Structure and Persistent Types
> Is that a good way to go? I couldn't find much documentation about how to > create full immutable application. > I understand I'm mixing functional and OO principles, I hope I'm not to > wrong about it. I've done more or less this exact thing in C# before. What I've found to be most useful, is to take make yourself a T4 template (or hand code the classes) that will generate objects in the following format: public class Point { int _x; int _y; public Point(int x, int y) { _x = x; _y = y; } public int X { get { return _x;}} public int Y{ get { return _y;}} public Point WithX(int x) { return new Point(x, _y); } public Point WithY(int y) { return new Point(_x, y); } } I say use T4 templates to help you because there will be a ton of code to write if you don't. What I like about this approach is that you have the option to modify one member, or all members, depending on your needs. So if you want to scale a point, you can simply do: p1 = new Point(1, 1); p2 = new Point(p1.X * 2, p1.Y * 2); Or if you only need to modify a single element: p3 = p2.WithX(0); All that being said...after going down that route, I don't really recommend it that much. C# was never really designed to work well with immutable types, it just ends up looking like super ugly clojure code. If you can, try using ClojureCLR embedded in your app, or even F#. Both of those will be much easier than trying to do it in C#. Timothy -- “One of the main causes of the fall of the Roman Empire was that–lacking zero–they had no way to indicate successful termination of their C programs.” (Robert Firth) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: replace a list element
On Mon, Feb 13, 2012 at 5:16 PM, James wrote: > Hi, > > I am new to clojure and I am very excited about learning the > language. I have a question about replacing an element in a list. I > have elements that look like this : > > {:id G__781, :value 1} > > The list looks like this: > > ({:id G__821, :value 1} {:id G__820, :value 1} {:id G__819, :value 1} > {:id G__818, :value 1} {:id G__817, :value 1}) > > I want to update an element in the list by conjoining a new list with > an updated element. For example, I'll update the head of the list: > ({:id G__821, :value 10} {:id G__820, :value 1} {:id G__819, :value 1} > {:id G__818, :value 1} {:id G__817, :value 1}) > > My update code (it really builds a new list with and replaces the > updated element) looks like this: > > (defn update-id-list [id-list new-id new-id-list] > (doseq[old-id id-list > new-id-list (conj new-id-list (choose-id old-id new-id) )] > (println "New List " new-id-list)) new-id-list) > > (defn choose-id[old-id new-id] > (if (= (:id old-id) (:id new-id)) new-id old-id)) > > This doesn't work. It never conjoin's elements and ultimately returns > an empty list. I've tried using various other methods but I keep > going in circles. > > Any ideas why this wouldn't work? Functions like conj create and return a new list, rather than modify the original in-place. You'd need to change your doseq to something like: (for [old-id id-list] (choose-id old-id new-id)) I'd also use better names, perhaps (for [old-entry entry-list] (choose-entry old-entry new-entry)) But for this sort of job you might be better off using a larger map: {G__821 {:id G__821 :value 1} G__820 {:id G__820 :value 1} ... } (assoc entry-map old-id new-entry) e.g. (assoc entry-map G__821 {:id G__821 :value 10}) or even (update-in entry-map [id :value] (constantly new-value)) e.g. (update-in entry-map [G__821 :value] (constantly 10)) If you actually transform the old value with a function to get the new one, so much the better: (update-in entry-map [G__821 :value] #(* 10 %)) etc. Incidentally, are all of these symbols G__xxx defined somewhere? You might want keywords or strings instead, to avoid having to quote them to avoid errors. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Released: nREPL 0.2.0-beta1
I have released nREPL 0.2.0-beta1, which should show up in Maven central soon. For those that don't know, nREPL is "a Clojure network REPL that provides a REPL server and client, along with some common APIs of use to IDEs and other tools that may need to evaluate Clojure code in remote environments": https://github.com/clojure/tools.nrepl This release is the result of gathering ideas, feedback, and requirements from dozens of people that need to have a REPL backend in a variety of environments, and want to maximize interoperability of Clojure tooling — much of which inevitably ends up grounding out at running or connecting to a REPL somewhere. This release marks a thorough breaking change from every aspect the last release of nREPL, 0.0.5. (The rationale for this is detailed in design notes in the project's wiki, for those that haven't followed along.) The result is that a design that settles a number of failings of nREPL's original design, and which provides a number of different vectors of extensibility — similar in many respects to those provided by Ring — that I hope people will take advantage of to build astonishingly cool tools. Note that pre-release versions of many Clojure tools are already using snapshots of nREPL 0.2.0, including Counterclockwise, Leiningen, and Reply, and as far as I know, more are on their way. My plans for the near future are to continue to tighten up the documentation, and release an HTTP transport: a Ring handler that exposes nREPL as an HTTP API. If you have any questions or find some shortcoming, bug, or problem with this release, please reply here or ping me on irc or twitter (`cemerick` in either case). Happy tooling, - Chas -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Hierarchical logs
Thanks, Alan, The solution I used looks exactly like yours: (defn mktree [vz [i out?]] (if out? (-> vz (zip/append-child i) zip/up ) (-> vz (zip/append-child [i]) zip/down zip/rightmost))) (defn as-tree [tracelist] (zip/root (reduce mktree (zip/vector-zip []) tracelist))) Thinking about it some more, I don't think I'm going to come up with a solution that's any more efficient or easy to code as this one. The real "work" is figuring out where the next element needs to be inserted. Zipper keeps that information as part of the data structure so it doesn't have to be re-calculated every iteration. My previous solution using loop had kept an accumulator (a list of indices to pass to assoc-in). -jeff On Feb 12, 3:42 am, Alan Malloy wrote: > I toyed with some simple ways of doing this, but I don't think any of > them will actually work out. I think the advice you got in #clojure to > use zippers is probably correct. Here's a sketch I bashed out that > seems to do roughly what you want:https://gist.github.com/1807340(I > took the liberty of wrapping the whole thing in another [] under the > assumption you'd want to record multiple top-level calls; if not you > can just call first on the result). > > On Feb 11, 8:39 pm, jweiss wrote: > > > > > > > > > I've been working on a tracing library, that works much like > > clojure.contrib.trace (based on it, actually). One sticky problem > > I've found is, hierarchical logs are really crappy to try to stream to > > a file. You can't just keep writing to the end of the file - new data > > needs to be inserted before existing end-tags. So what I'm doing is > > storing the data as a list, until I know the data is complete, and > > then i turn it back into a tree to write the file. > > > However I can't think of a simple way to do it, even though it seems > > like a simple operation. > > > I want to turn this list of pairs (first item is the fn call or return > > value, the second is a truthy value marking whether it's a call or > > return) > > > '[[(+ 1 (- 5 2) nil] > > [(- 5 2) nil] > > [3 true] > > [4 true]] > > > I want to turn that into > > [(+ 1 (- 5 2)) > > [(- 5 2) > > 3] > > 4] > > > Is there a simple way to do this? -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: replace a list element
I'd use clojure.core/replace It takes a replacement-map in the form of {before after, ...} and a collection. It replaces all befores with the corresponding afters: => (replace {:answer 42} [:the :answer :to :life]) [:the 42 :to :life] On Mon, Feb 13, 2012 at 23:16, James wrote: > Hi, > > I am new to clojure and I am very excited about learning the > language. I have a question about replacing an element in a list. I > have elements that look like this : > > {:id G__781, :value 1} > > The list looks like this: > > ({:id G__821, :value 1} {:id G__820, :value 1} {:id G__819, :value 1} > {:id G__818, :value 1} {:id G__817, :value 1}) > > I want to update an element in the list by conjoining a new list with > an updated element. For example, I'll update the head of the list: > ({:id G__821, :value 10} {:id G__820, :value 1} {:id G__819, :value 1} > {:id G__818, :value 1} {:id G__817, :value 1}) > > My update code (it really builds a new list with and replaces the > updated element) looks like this: > > (defn update-id-list [id-list new-id new-id-list] > (doseq[old-id id-list > new-id-list (conj new-id-list (choose-id old-id new-id) )] > (println "New List " new-id-list)) new-id-list) > > (defn choose-id[old-id new-id] > (if (= (:id old-id) (:id new-id)) new-id old-id)) > > This doesn't work. It never conjoin's elements and ultimately returns > an empty list. I've tried using various other methods but I keep > going in circles. > > Any ideas why this wouldn't work? > > Thanks, > James > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with your > first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en -- Moritz Ulrich -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: ForkJoin updates
Here's a new blog post describing the effect the improved fork-join pool has had on Akka actors: http://letitcrash.com/post/17607272336/scalability-of-fork-join-pool -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: ClojureScript def, vars, and binding
This is interesting. However it seems, at least to me, like a big change with too little justification. When you're CA is in, please setup a design document for this line of development - http://dev.clojure.org/display/design/ClojureScript. David On Tue, Feb 14, 2012 at 5:15 AM, Brandon Bloom wrote: > To redeem myself for the noob threading mistake, *I've implemented Var > and friends in ClojureScript*: > > > https://github.com/brandonbloom/clojurescript/compare/8ba4849e60e5957cdac36ef6946c647e824ca3c8...vars > > This branch includes (almost) the full set of relevant functionality, but > for performance and interop reasons, only applies to vars def-ed with > ^:dynamic. > > Here's a repl session: > > ClojureScript:cljs.user> (def ^:dynamic x "root binding") > (var cljs.user.x) > ClojureScript:cljs.user> x > "root binding" > ClojureScript:cljs.user> #'x > (var cljs.user.x) > ClojureScript:cljs.user> ((binding [x "dynamic binding"] (fn [] x))) > "root binding" > ClojureScript:cljs.user> ((binding [x "dynamic binding"] (bound-fn [] x))) > "dynamic binding" > > Complete list of newly supported forms: > >- var >- alter-root-var >- bound-fn >- bound-fn* >- bound? >- get-thread-bindings >- push-thread-bindings >- thread-bound? >- var-get >- var-? >- with-bindings >- with-bindings* > > I'm filling out my contributor agreement and will start a parallel thread > on clojure-dev to see if we can get this integrated! > > Cheers, > Brandon > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: clojurescript: js* question
I don't think ClojureScript is going to support what you want, js* is an implementation detail - not something for general use. You can however provide your own special form that does what you want. The ClojureScript compiler is built on top of multimethods so you can just add parse/emit cases for your new special form. David On Tue, Feb 14, 2012 at 4:29 AM, Dave Sann wrote: > I know it is not the done thing but I have a question regarding js* > > I have a complex fn defined in a javascript file. it is self contained and > uses no globals. > It is not currently worth my while to rewrite. > > I can use this by doing: > (def my-fn (js* "...file contents with escaped chars...")) > > and the my-fn is callable in the defined namespace. > > I can use a foreign-libs compiler option but I don't want the function in > the global namespace. > > > I would like to define a macro read-js* that reads from a file on the > class path and allows > > (def my-fn (read-js* "js/js-file.js")) > > is this possible? I have tried but run into problems with js* - for a > start I can't find where it is defined. > > I have tried: > (def f (js* (from-local-file "js/file.js"))) > > where from-local-file is a macro that resolves to a string of the file > contents - but this throws an exception. > > Is there a more appropriate way to do this? > > for reference - the js file I am using is a very slightly modified form of > http://www.webtoolkit.info/javascript-md5.html > > Thanks for any pointers. > > Dave > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: what stack traces include / exclude regarding monads
I guess the use of domonads leaves behind do statements with m_bind's and m_result's... and since these expressions are not fn's, they don't count as method calls and are thus not part of the stack trace. But if I'm mistaken or if anyone has figured out how to use monads and still get detailed stack traces, please do let me know. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: [Ann] [cljs-hash "0.0.1"] - hash functions for clojurescript
or there are some in goog.cryptwhich I didn't see when I did this...you won't find sha356 though - that's special :) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: clojurescript: js* question
Ok, I'll leave it for now, but that is good to know. thanks Dave -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Error in the example on the Multimethods page?
Hi, I've just been brushing up my knowledge about clojure multimethods and was wondering about an example at http://clojure.org/multimethods (see below). What I don't get is how a (class []) gets dispatched to ::collection. (class []) returns clojure.lang.PersistentVector which doesn't seem to satisfy the isa? relationship. Thx Las (defmulti foo class)(defmethod foo ::collection [c] :a-collection)(defmethod foo String [s] :a-string) (foo []):a-collection (foo (java.util.HashMap.)):a-collection (foo "bar"):a-string -- László Török -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Error in the example on the Multimethods page?
On Tue, Feb 14, 2012 at 3:14 PM, László Török wrote: > What I don't get is how a (class []) gets dispatched to ::collection. > > (class []) returns clojure.lang.PersistentVector which doesn't seem to > satisfy the isa? relationship. > > (defmulti foo class) > (defmethod foo ::collection [c] :a-collection) > (defmethod foo String [s] :a-string) > > (foo []) > :a-collection > > (foo (java.util.HashMap.)) > :a-collection > > (foo "bar") > :a-string This is depending on the line earlier in the page that did: (derive java.util.Collection ::collection) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Error in the example on the Multimethods page?
Hi, the ancestor chain seems to be: c.l.PersistentVector -> c.l.APersistentVector -> j.u.List -> j.u.Collection Meikel -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Error in the example on the Multimethods page?
Damn, I missed that, it's getting late, thanks! 2012/2/14 Aaron Cohen > On Tue, Feb 14, 2012 at 3:14 PM, László Török wrote: > > > What I don't get is how a (class []) gets dispatched to ::collection. > > > > (class []) returns clojure.lang.PersistentVector which doesn't seem to > > satisfy the isa? relationship. > > > > (defmulti foo class) > > (defmethod foo ::collection [c] :a-collection) > > (defmethod foo String [s] :a-string) > > > > (foo []) > > :a-collection > > > > (foo (java.util.HashMap.)) > > :a-collection > > > > (foo "bar") > > :a-string > > This is depending on the line earlier in the page that did: > > (derive java.util.Collection ::collection) > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en -- László Török -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Problem with the Chas Emerick: "Modeling the world ..." video
Hi, Saw that the video was available in the podcast feed but it stops playing around 13:40 looked on blip tv and it does something similar. Is someone aware of the issue? I'd love to see the end of the talk. Thanks. Julio -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: ClojureScript def, vars, and binding
Can we continue the conversation on this thread while my CA waits on the USPS? Three things to cover: 1) motivation 2) design 3) impact 1. Why do I want this? Why would anyone want this? - Better parity with JVM Clojure - async Javascript (ie. nearly all Javascript) makes the binding macro effectively useless without bound-fn - Some common Clojure behaviors, like printing to a dynamically bound *out*, can't currently exist across an async boundary. See *print-fn* in CLJS - I'd like to create a dom manipulation library that has a *dom* dynamic variable, which acts like current working directory for dom manipulation functions. I've got some crazy ideas that I want to experiment with here, especially once I implement add-watch: I think I can achieve pretty seamless UI data binding. 2. Design - Are Vars still useful without threads? - Yes, but only dynamic vars - async callbacks and threads have a lot of common design considerations - Performance - Price is equivalent to that of JVM Clojure - Extra indirection for def and deref - Shared stack of dynamic binding frames - Hash lookup on each access - Opt-in price for the Var indirection - Treat ^:dynamic as that opt-in mechanism; no impact for static vars - Potential optimization: Leverage Javascript's prototypical inheritance instead of Frame type - Required compiler analysis - Metadata for resolved vars - Not available for external libraries - OK, because we only care about ^:dynamic vars - Interop - Vars declared as ^:dynamic differ from static ones: they are wrapped in the Var type - binding, etc are only applicable to dynamic vars, not useful to non-ClojureScript callers - External callers can still use deref and alter-var-root 3. Impact - Breaking change for binding macro - New behavior matches JVM clojure: binding only works on dynamic vars - Simply marking any affected vars as ^:dynamic should be enough to upgrade - Potentially breaking changes for any cljs.core vars that are changed to ^:dynamic - *print-fn* and other printing vars - Only breaking for Javascript interop usages, still source compatible How's that? Anything I missed? Complaints? Concerns? Questions? Cheers, Brandon -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: A Bug of map function?
A sequence is equal to a list because Clojure defines = to compare similar collections by their contents. For example, the vector [1 2 3] is equal (by the = function) to the list (1 2 3). `eval` calls the Clojure compiler. The compiler operates on lists returned by the reader, so I would not expect it to work on lazy sequences. -S -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: ClojureScript def, vars, and binding
I put your notes here, http://dev.clojure.org/display/design/Dynamic+Binding How are you ensuring that the binding frames are local to a particular asynchronous block of code and that they are removed when that asynchronous block of code exits? David On Tue, Feb 14, 2012 at 3:41 PM, Brandon Bloom wrote: > Can we continue the conversation on this thread while my CA waits on the > USPS? > > Three things to cover: 1) motivation 2) design 3) impact > >1. Why do I want this? Why would anyone want this? > - Better parity with JVM Clojure > - async Javascript (ie. nearly all Javascript) makes the binding > macro effectively useless without bound-fn > - Some common Clojure behaviors, like printing to a dynamically > bound *out*, can't currently exist across an async boundary. See > *print-fn* > in CLJS > - I'd like to create a dom manipulation library that has a *dom* > dynamic variable, which acts like current working directory for dom > manipulation functions. I've got some crazy ideas that I want to > experiment > with here, especially once I implement add-watch: I think I can achieve > pretty seamless UI data binding. >2. Design > - Are Vars still useful without threads? > - Yes, but only dynamic vars > - async callbacks and threads have a lot of common design > considerations > - Performance > - Price is equivalent to that of JVM Clojure > - Extra indirection for def and deref > - Shared stack of dynamic binding frames > - Hash lookup on each access > - Opt-in price for the Var indirection > - Treat ^:dynamic as that opt-in mechanism; no impact for static > vars > - Potential optimization: Leverage Javascript's > prototypical inheritance instead of Frame type > - Required compiler analysis > - Metadata for resolved vars > - Not available for external libraries > - OK, because we only care about ^:dynamic vars > - Interop > - Vars declared as ^:dynamic differ from static ones: they are > wrapped in the Var type > - binding, etc are only applicable to dynamic vars, not useful > to non-ClojureScript callers > - External callers can still use deref and alter-var-root > 3. Impact > - Breaking change for binding macro > - New behavior matches JVM clojure: binding only works on > dynamic vars > - Simply marking any affected vars as ^:dynamic should be enough > to upgrade > - Potentially breaking changes for any cljs.core vars that are > changed to ^:dynamic > - *print-fn* and other printing vars > - Only breaking for Javascript interop usages, still source > compatible > > How's that? Anything I missed? Complaints? Concerns? Questions? > > Cheers, > Brandon > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: A Bug of map function?
On Tue, Feb 14, 2012 at 5:00 PM, Stuart Sierra wrote: > A sequence is equal to a list because Clojure defines = to compare similar > collections by their contents. For example, the vector [1 2 3] is equal (by > the = function) to the list (1 2 3). > > `eval` calls the Clojure compiler. The compiler operates on lists returned > by the reader, so I would not expect it to work on lazy sequences. Macro expansions can use lazy sequences and work; e.g. (defmacro ... ... ~(map ...) ...) I think what's legal in a macro output should be legal in eval input. More to the point, if it looks and quacks like a (list of thingies) it should behave as one if evaluated, precisely because transforming forms using the native sequence functions is a powerful metaprogramming technique and having to wrap every such thing in (apply list ...) or (list* ...) is going to be a pain that might as well be avoidable and easily is avoidable. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: A Bug of map function?
eval doesn't mind lazy seqs as input: user=> (map identity ['quote ()]) (quote ()) user=> (class (map identity ['quote ()])) clojure.lang.LazySeq user=> (eval (map identity ['quote ()])) () But it can't handle a form that contains an (evaluated) empty lazy seq. Another example: user=> (eval `(quote ~(range -1))) CompilerException java.lang.UnsupportedOperationException: Unknown Collection type, compiling:(NO_SOURCE_PATH:53) I think Alan pointed to bug. The empty-expr needs to check for LazySeq instances as well. On Feb 14, 2:00 pm, Stuart Sierra wrote: > A sequence is equal to a list because Clojure defines = to compare similar > collections by their contents. For example, the vector [1 2 3] is equal (by > the = function) to the list (1 2 3). > > `eval` calls the Clojure compiler. The compiler operates on lists returned > by the reader, so I would not expect it to work on lazy sequences. > > -S -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Hierarchical logs
It occurred to me that ultimately what I want is just a pretty-printed output that I can put on a webpage and apply syntaxhighlighter to. I should be able to use a custom pprint dispatch to take this [[(+ 5 (- 4 2 (* 9 3)) (* 5 (+ 6 3))) nil] [(- 4 2 (* 9 3)) nil] [(* 9 3) nil] [27 true] [-25 true] [(* 5 (+ 6 3)) nil] [(+ 6 3) nil] [9 true] [45 true] [25 true]] and print something like this: (+ 5 (- 4 2 (* 9 3)) (* 5 (+ 6 3))) (- 4 2 (* 9 3)) (* 9 3) 27 -25 (* 5 (+ 6 3)) (+ 6 3) 9 45 25 Without even converting it into a tree. But I am having a hard time finding an example of custom dispatch, or docs on how to write one. I really just want things printed the same as pprint currently does, but being able to specify extra indent for the whole block. I had originally planned to output html where each item was properly nested as html divs, but I think that is getting overly complex. -jeff On Feb 14, 10:14 am, jweiss wrote: > Thanks, Alan, > > The solution I used looks exactly like yours: > > (defn mktree [vz [i out?]] > (if out? > (-> vz (zip/append-child i) zip/up ) > (-> vz (zip/append-child [i]) zip/down zip/rightmost))) > > (defn as-tree [tracelist] > (zip/root (reduce mktree (zip/vector-zip []) tracelist))) > > Thinking about it some more, I don't think I'm going to come up with a > solution that's any more efficient or easy to code as this one. The > real "work" is figuring out where the next element needs to be > inserted. Zipper keeps that information as part of the data structure > so it doesn't have to be re-calculated every iteration. My previous > solution using loop had kept an accumulator (a list of indices to pass > to assoc-in). > > -jeff > > On Feb 12, 3:42 am, Alan Malloy wrote: > > > > > > > > > I toyed with some simple ways of doing this, but I don't think any of > > them will actually work out. I think the advice you got in #clojure to > > use zippers is probably correct. Here's a sketch I bashed out that > > seems to do roughly what you want:https://gist.github.com/1807340(I > > took the liberty of wrapping the whole thing in another [] under the > > assumption you'd want to record multiple top-level calls; if not you > > can just call first on the result). > > > On Feb 11, 8:39 pm, jweiss wrote: > > > > I've been working on a tracing library, that works much like > > > clojure.contrib.trace (based on it, actually). One sticky problem > > > I've found is, hierarchical logs are really crappy to try to stream to > > > a file. You can't just keep writing to the end of the file - new data > > > needs to be inserted before existing end-tags. So what I'm doing is > > > storing the data as a list, until I know the data is complete, and > > > then i turn it back into a tree to write the file. > > > > However I can't think of a simple way to do it, even though it seems > > > like a simple operation. > > > > I want to turn this list of pairs (first item is the fn call or return > > > value, the second is a truthy value marking whether it's a call or > > > return) > > > > '[[(+ 1 (- 5 2) nil] > > > [(- 5 2) nil] > > > [3 true] > > > [4 true]] > > > > I want to turn that into > > > [(+ 1 (- 5 2)) > > > [(- 5 2) > > > 3] > > > 4] > > > > Is there a simple way to do this? -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en