Re: Why IPersistentList doesn't extend ISeq?
The docs you quoted seem to answer your question. Not all lists are valid seqs. In particular, the empty list is a valid list but not a valid seq. So if the empty list implemented ISeq, it would be lying. If the empty list implements IPersistentList, then IPersistentList can't implement ISeq. Phil On Sep 3, 2012 12:44 AM, Andrei Zhlobich a.zhlob...@gmail.com wrote: Why IPersistentList doesn't extend ISeq? Clojure docs say: Lists are collections. They implement the ISeq interface directly (except for the empty list, which is not a valid seq) At this moment EmptyList implements ISeq, but PersistentList doesn't. It seems very strange for me. Also PersistentQueue implements IPersistentList, but semantically it is not a list. I think we can do 2 changes in hierarchy: 1) extend IPersistentList from ISeq; 2) extend PersistentQueue directly from IPersistentStack instead of IPersistentList. Is it possible? -- 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: using take-while with pred function that has state
On Sun, Sep 2, 2012 at 10:25 PM, Stephen Compall stephen.comp...@gmail.com wrote: On Fri, 2012-08-31 at 05:08 -0700, shaobohou wrote: I have written the following function using take-while and a pred function with an atom to store the set of unique tokens. It works Only because in the current implementation, take-while happens to be called in coll order, which is not a guarantee of the API. Can you say what this means (the note about take-while being called in coll order)? Does it mean that it's not a guarantee of the API that the predicate passed to take-while be called *successively* on the items in the collection passed in? I would have hoped that would be guaranteed---otherwise you might be forcing the computation of elements of a lazy sequence unnecessarily, which could be expensive, even if there are no side-effects, or (potentially, at least) raise an exception that would otherwise not be raised. -- Ben Wolfson Human kind has used its intelligence to vary the flavour of drinks, which may be sweet, aromatic, fermented or spirit-based. ... Family and social life also offer numerous other occasions to consume drinks for pleasure. [Larousse, Drink entry] -- 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: ClojureSphere updated
2012/9/3 Justin Kramer jkkra...@gmail.com ClojureSphere has been updated with a new domain, refreshed index, and some new features: http://www.clojuresphere.com/ Justin, The new version looks great! I have noticed that ClojureSphere points to a fork of the Midje repository at https://github.com/bmabey/Midje while the canonical repository is https://github.com/marick/Midje. Is it a data aggregation issue or it actually tries to cover all the forks? -- MK http://github.com/michaelklishin http://twitter.com/michaelklishin -- 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: Why IPersistentList doesn't extend ISeq?
I should really check the source before replying. EmptyList does indeed implement ISeq, so my argument doesn't hold. Phil On 3 September 2012 07:01, Philip Potter philip.g.pot...@gmail.com wrote: The docs you quoted seem to answer your question. Not all lists are valid seqs. In particular, the empty list is a valid list but not a valid seq. So if the empty list implemented ISeq, it would be lying. If the empty list implements IPersistentList, then IPersistentList can't implement ISeq. Phil On Sep 3, 2012 12:44 AM, Andrei Zhlobich a.zhlob...@gmail.com wrote: Why IPersistentList doesn't extend ISeq? Clojure docs say: Lists are collections. They implement the ISeq interface directly (except for the empty list, which is not a valid seq) At this moment EmptyList implements ISeq, but PersistentList doesn't. It seems very strange for me. Also PersistentQueue implements IPersistentList, but semantically it is not a list. I think we can do 2 changes in hierarchy: 1) extend IPersistentList from ISeq; 2) extend PersistentQueue directly from IPersistentStack instead of IPersistentList. Is it possible? -- 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: Possible to merge destructuring :or defaults with :as?
Hi Stephen, Thanks for the reply! Such behavior would be quite surprising; to see why, desugar :keys: I may well be missing something, but I'm not sure I see your problem here. (defn foo [ {x :x y :y :as args :or {x x-default y y-default}}] args) This is checking input args for an :x keyword. If found, it's binding the associated value to 'x. Else it's binding the default value to 'x. Either way, it's also binding all the args as originally given to 'args. So with (foo :y boo!) we have at this point: * All args as originally given, bound to 'args. So '(:y boo!) * A map of symbols to default values. So {x x-default y y-default} * Bindings as a result of the destructuring. So [x x-default y boo!] What I'm suggesting might be useful, is destructuring sugar to bind one additional map: {:x x-default :y boo!}. The clojure.core/destructure code is pretty hairy, so I may be missing some implementation-specific reason why this would be difficult to do. But I don't see anything logically inconsistent or surprising about wanting to do it. It'd be just another binding, and so not outside the scope of what destructure is tasked with doing. Indeed, I find real-world situations coming up quite often where this would be a useful convenience. When you want this, (let [{blah} (merge my-defaults kwargs)] Unfortunately (again, unless I'm missing something) this fails on two counts. One, it loses the transparency of the defaults to callers (the original motivation I described). Two, it loses the convenience that :or gives of actually having the symbols automatically bound as well. I.e. to really match the functionality I'm talking about, you'd need to get more verbose: (defn foo [ {:keys [x y] :as args}] (let [merged-args (merge {:x x-default} args) {:keys [x y]} merged-args] merged-args)) And, indeed, the repetition in this form makes it clear (I think) why this would ideally be the domain of the destructuring itself. Does that make sense? -- *Peter Taoussanis* ptaoussa...@gmail.com twitter.com/ptaoussanis +66 (0)82 597 2595 (Thailand) -- 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: Problems with Leiningen and Clojure 1.4
On Fri, Aug 31, 2012 at 7:38 PM, Martin martin9...@gmail.com wrote: Hi Im having problems using Leiningen together with Clojure 1.4 (and 1.3) on Windows 7. Using Leiningen version 1.5.2 I can create a new project and use lein deps to download clojure version 1.2.1. However if I change dependencies in project.clj to org.clojure/clojure 1.4.0, I run into trouble. Running lein deps downloads clojure-1.4.0.jar to lib. Running lein repl gives: Warning: *classpath* not declared dynamic and thus is not dynamically rebindable, but its name suggests otherwise. Please either indicate ^:dynamic *classpath* or change the name. (NO_SOURCE_PATH:1) REPL started; server listening on localhost:50497. It starts up and gives me a prompt, but whatever I write at the prompt (even just enter) freezes the program, forcing me to exit with ctrl-c. I also tried using Leiningen 2.0.0. It automatically creates a project with Clojure 1.3.0 as dependency. Running lein deps gives no error but I cant find Clojure 1.3.0 downloaded anywhere. There is a .lein folder in C:\Users\Martin which contains a couple of jars but not the main Clojure one. Running lein repl starts clojure 1.3.0 without errors, but as above, as soon as I type anything it freezes. Any ideas? Wipe out any traces of leiningen by removing $HOME/.lein install the latest lein again (the latest 2 version) now running `lein new foo` should create a blank project with clojure 1.4 as a dependency: denis@zeus:~/tmp$ lein new foo Generating a project called foo based on the 'default' template. To see other templates (app, lein plugin, etc), try `lein help new`. denis@zeus:~/tmp$ cat foo/project.clj (defproject foo 0.1.0-SNAPSHOT :description FIXME: write description :url http://example.com/FIXME; :license {:name Eclipse Public License :url http://www.eclipse.org/legal/epl-v10.html} :dependencies [[org.clojure/clojure 1.4.0]]) -- 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: I want to know how can I run it?
1. java -cp ./org/clojure/clojure/1.4.0/clojure-1.4.0.jar clojure.main 2. cut paste your code in the REPL 3. type (start) [enter] On Fri, Aug 31, 2012 at 3:36 AM, gearss gearss8...@gmail.com wrote: I have a file named pong.clj, it isunder following, I want to know how can I run it? Thank you. (ns example.game.pong (:use [penumbra opengl] [clojure.contrib.def]) (:require [penumbra [app :as app] [text :as text]])) (def ball-width 0.03) (def ball-height 0.03) (def paddle-width 0.02) (def paddle-height 0.15) ;;; (defn abs [x] (Math/abs x)) (defn intersect-1d [[a b] [x y]] (and (= a y) (= b x))) (defn intersect-2d [[a b c d] [x y z w]] (and (intersect-1d [a c] [x z]) (intersect-1d [b d] [y w]))) (defn reflector [[x y w h] f] (let [r [x y (+ x w) (+ y h)]] (fn [region velocity] (if (intersect-2d region r) (f velocity) velocity (defvar boundaries [(reflector [0 -1 1 1] (fn [[x y]] [x (abs y)])) (reflector [0 1 1 1] (fn [[x y]] [x (- (abs y))])) (reflector [-1 0 1 1] (fn [[x y]] [(abs x) y])) (reflector [1 0 1 1] (fn [[x y]] [(- (abs x)) y]))]) (defn update-ball [state dt] (let [ball (concat (:p state) (map + (:p state) [ball-width ball-height])) v (reduce #(%2 ball %1) (:v state) (conj boundaries (reflector [0.01 (:left state) paddle-width paddle-height] (fn [[x y]] [(abs x) y])) (reflector [(- 0.99 paddle-width) (:right state) paddle-width paddle-height] (fn [[x y]] [(- (abs x)) y]] (assoc state :v v :p (map + (:p state) (map (partial * dt) v) (defn draw-ball [pos] (push-matrix (apply translate pos) (draw-quads (vertex 0 0) (vertex ball-width 0) (vertex ball-width ball-height) (vertex 0 ball-height ;;; (defn update-opponent-paddle [state] (let [[x y] (:p state) [vx vy] (:v state) dt (/ (- 1 x) vx) dy (- (+ y (* vy dt)) (:right state))] (assoc state :v-right (if (neg? vx) 0 (/ dy dt) (defn update-player-paddle [state] (assoc state :v-left (cond (app/key-pressed? :up) -1 (app/key-pressed? :down) 1 :else 0))) (defn update-paddle [dt v pos] (min (- 1 paddle-height) (max 0 (+ pos (* dt v) (defn draw-paddle [x y] (push-matrix (translate x y) (draw-quads (vertex 0 0) (vertex paddle-width 0) (vertex paddle-width paddle-height) (vertex 0 paddle-height ;;; (defn reset-game [state] (assoc state :v [0.4 0.8] :p [0.5 0.5] :left 0.5, :v-left 0.0 :right 0.5, :v-right 0.0)) (defn init [state] (app/vsync! true) (app/title! Pong) (app/periodic-update! 2 update-opponent-paddle) (reset-game state)) (defn reshape [[x y w h] state] (ortho-view 0 1 1 0 -1 1) state) (defn update [[delta _] state] (- state (update-player-paddle) (assoc :left (update-paddle delta (:v-left state) (:left state))) (assoc :right (update-paddle delta (:v-right state) (:right state))) (update-ball delta))) (defn display [[delta _] state] (draw-ball (:p state)) (draw-paddle 0.01 (:left state)) (draw-paddle (- 0.99 paddle-width) (:right state)) (app/repaint!)) (defn start [] (app/start {:display display, :reshape reshape, :update update, :init init} {})) -- 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
clojure.org/getting_started: not up to date
On http://clojure.org/getting_started: Download http://clojure.org/downloads and unzip Clojure. In the directory in which you expanded clojure.zip, run: java -cp clojure-1.4.0.jar clojure.main Should be just: java -jar clojure-1.4.0.jar It's a detail, but an important one, as it's the first contact for most of the new Clojure users. Denis On Mon, Sep 3, 2012 at 9:00 AM, Denis Labaye denis.lab...@gmail.com wrote: 1. java -cp ./org/clojure/clojure/1.4.0/clojure-1.4.0.jar clojure.main 2. cut paste your code in the REPL 3. type (start) [enter] On Fri, Aug 31, 2012 at 3:36 AM, gearss gearss8...@gmail.com wrote: I have a file named pong.clj, it isunder following, I want to know how can I run it? Thank you. (ns example.game.pong (:use [penumbra opengl] [clojure.contrib.def]) (:require [penumbra [app :as app] [text :as text]])) (def ball-width 0.03) (def ball-height 0.03) (def paddle-width 0.02) (def paddle-height 0.15) ;;; (defn abs [x] (Math/abs x)) (defn intersect-1d [[a b] [x y]] (and (= a y) (= b x))) (defn intersect-2d [[a b c d] [x y z w]] (and (intersect-1d [a c] [x z]) (intersect-1d [b d] [y w]))) (defn reflector [[x y w h] f] (let [r [x y (+ x w) (+ y h)]] (fn [region velocity] (if (intersect-2d region r) (f velocity) velocity (defvar boundaries [(reflector [0 -1 1 1] (fn [[x y]] [x (abs y)])) (reflector [0 1 1 1] (fn [[x y]] [x (- (abs y))])) (reflector [-1 0 1 1] (fn [[x y]] [(abs x) y])) (reflector [1 0 1 1] (fn [[x y]] [(- (abs x)) y]))]) (defn update-ball [state dt] (let [ball (concat (:p state) (map + (:p state) [ball-width ball-height])) v (reduce #(%2 ball %1) (:v state) (conj boundaries (reflector [0.01 (:left state) paddle-width paddle-height] (fn [[x y]] [(abs x) y])) (reflector [(- 0.99 paddle-width) (:right state) paddle-width paddle-height] (fn [[x y]] [(- (abs x)) y]] (assoc state :v v :p (map + (:p state) (map (partial * dt) v) (defn draw-ball [pos] (push-matrix (apply translate pos) (draw-quads (vertex 0 0) (vertex ball-width 0) (vertex ball-width ball-height) (vertex 0 ball-height ;;; (defn update-opponent-paddle [state] (let [[x y] (:p state) [vx vy] (:v state) dt (/ (- 1 x) vx) dy (- (+ y (* vy dt)) (:right state))] (assoc state :v-right (if (neg? vx) 0 (/ dy dt) (defn update-player-paddle [state] (assoc state :v-left (cond (app/key-pressed? :up) -1 (app/key-pressed? :down) 1 :else 0))) (defn update-paddle [dt v pos] (min (- 1 paddle-height) (max 0 (+ pos (* dt v) (defn draw-paddle [x y] (push-matrix (translate x y) (draw-quads (vertex 0 0) (vertex paddle-width 0) (vertex paddle-width paddle-height) (vertex 0 paddle-height ;;; (defn reset-game [state] (assoc state :v [0.4 0.8] :p [0.5 0.5] :left 0.5, :v-left 0.0 :right 0.5, :v-right 0.0)) (defn init [state] (app/vsync! true) (app/title! Pong) (app/periodic-update! 2 update-opponent-paddle) (reset-game state)) (defn reshape [[x y w h] state] (ortho-view 0 1 1 0 -1 1) state) (defn update [[delta _] state] (- state (update-player-paddle) (assoc :left (update-paddle delta (:v-left state) (:left state))) (assoc :right (update-paddle delta (:v-right state) (:right state))) (update-ball delta))) (defn display [[delta _] state] (draw-ball (:p state)) (draw-paddle 0.01 (:left state)) (draw-paddle (- 0.99 paddle-width) (:right state)) (app/repaint!)) (defn start [] (app/start {:display display, :reshape reshape, :update update, :init init} {})) -- 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: screencast corruption
@Ben Thank you for uploading. Will check it out. On Mon, Sep 3, 2012 at 1:13 AM, Ben Smith-Mannschott bsmith.o...@gmail.comwrote: You should be able to download it from here for the next few days: https://dl.dropbox.com/u/8238674/clojure-sequences.mov // Ben On Sun, Sep 2, 2012 at 6:56 PM, Andrew Rafas andras.ra...@gmail.com wrote: I would appreciate, Thank you very much, Andrew On Sunday, September 2, 2012 4:19:10 PM UTC+1, bsmith.occs wrote: I can't fix the version posted on blip.tv, but I downloaded it over a year ago when it was still working. It's a 107 MB quicktime file encoded using H.264. Running time is 1 hour 14 minutes. I could make it available somewhere, if that would help. // Ben On Sun, Sep 2, 2012 at 12:37 PM, Mayank Jain fires...@gmail.com wrote: Confirmed. The video is indeed broken. On Sun, Sep 2, 2012 at 3:34 PM, Andrew Rafas andras...@gmail.com wrote: Hi! I just wanted to watch this screencast (Clojure Sequences) as I really need that little table which compares C#, Java and Clojure sequences. However the video on this link seems to be like 5 seconds long instead of more than an hour. Can you fix it? Or do you have the slides somewhere? http://blip.tv/clojure/clojure-sequences-740581 Thanks, Andrew -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clo...@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+u...@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 clo...@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+u...@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 -- 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: Possible to merge destructuring :or defaults with :as?
In case you are primarily interested in clojure functions with keyword arguments (or optional arguments), you might check if clojure.options (https://github.com/guv/clojure.options/) suits you. -- 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: Why IPersistentList doesn't extend ISeq?
At this time empty list is a valid seq. user = (list? ()) true Sources: https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/PersistentList.java#L129 -- 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: using take-while with pred function that has state
(map #(do %2 %1) c1 c2) is a neat trick I hadn't seen in this context; thanks for showing me! On Sunday, September 2, 2012 10:26:07 PM UTC-7, Stephen Compall wrote: On Fri, 2012-08-31 at 05:08 -0700, shaobohou wrote: I have written the following function using take-while and a pred function with an atom to store the set of unique tokens. It works Only because in the current implementation, take-while happens to be called in coll order, which is not a guarantee of the API. Will this be problem in my implementation if I am calling it from multiple threads? No. And what would be the more idiomatic way of implementing this kind of behaviour? Consider this restructuring: (- ss (map tok-fn), (reductions (partial apply merge) #{}), (take-while #(...)), (map #(do %2 %1) ss), last) Use of `atom' for this sort of thing is certainly an antipattern, so consider any alternative that suits you. -- Stephen Compall ^aCollection allSatisfy: [:each | aCondition]: less is better than -- 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: Why IPersistentList doesn't extend ISeq?
I know it :) Actually clojure has 3 implementations of IPersistentCollection: 1) PersistentList - it is already ISeq 2) EmptyList - it is ISeq (!) https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/PersistentList.java#L129 3) PersistentQueue - semantically it it not a list EmptyList it the only possible exception from the rule (list? x) = (seq? x). But... it is a seq! -- 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
Reflecting over protocols in macros for clojurescript
Hi there. I'm having a play around with ClojureScript, and I'd find it really useful to be able to be able to create some Mockito style test spies. Ultimately, I'd like to be able to generate a spie by reflecting over a protocol and find out what operations it supports programatically. However, now that I've looked core.cljs from the ClojureScript source code, it doesn't seem like the compiler actually keeps track of which protocols support which operations--is that right? Is there some other way of discovering the operations that a cljs protocol supports, or would i need to write my own analysis for this? Thanks, -- Ceri Storey -- 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: anonymous functions with names
Just 2 cents: A name you give to the anonymous function also appears in the stack traces instead of the things like fn_123_4532, which is very convenient for debugging. On Friday, August 31, 2012 5:52:55 PM UTC+2, Erlis Vidal wrote: Hi guys, I've been reading but I'm still confused about the difference between an anonymous function with name vs a defn function (fn my-func1[x] x) (defn my-func2[x] x) Thanks, Erlis -- 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: anonymous functions with names
Thanks, this is a *very* useful bit of information. On Monday, 3 September 2012 10:30:21 UTC+1, dmirylenka wrote: Just 2 cents: A name you give to the anonymous function also appears in the stack traces instead of the things like fn_123_4532, which is very convenient for debugging. On Friday, August 31, 2012 5:52:55 PM UTC+2, Erlis Vidal wrote: Hi guys, I've been reading but I'm still confused about the difference between an anonymous function with name vs a defn function (fn my-func1[x] x) (defn my-func2[x] x) Thanks, Erlis -- 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: anonymous functions with names
@dmirylenka Thanks. That is useful to know. On Mon, Sep 3, 2012 at 3:00 PM, dmirylenka daniilmirile...@gmail.comwrote: Just 2 cents: A name you give to the anonymous function also appears in the stack traces instead of the things like fn_123_4532, which is very convenient for debugging. On Friday, August 31, 2012 5:52:55 PM UTC+2, Erlis Vidal wrote: Hi guys, I've been reading but I'm still confused about the difference between an anonymous function with name vs a defn function (fn my-func1[x] x) (defn my-func2[x] x) Thanks, Erlis -- 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: Reflecting over protocols in macros for clojurescript
(with apologies for the accidental double posting). 2012/9/3 Ceri Storey ceri.sto...@gmail.com Hi there. I'm having a play around with ClojureScript, and I'd find it really useful to be able to be able to create some Mockito style test spies. Ultimately, I'd like to be able to generate a spie by reflecting over a protocol and find out what operations it supports programatically. However, now that I've looked core.cljs from the ClojureScript source code, it doesn't seem like the compiler actually keeps track of which protocols support which operations--is that right? Is there some other way of discovering the operations that a cljs protocol supports, or would i need to write my own analysis for this? Thanks, -- Ceri Storey -- Ceri Storey -- 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
Found bug in contains? used with vectors.
I use Clojure 1.4.0 and wanted to use 'contains?' on a vector and get following results: = (contains? [1 2 3] 3) false = (contains? [1 2 3] 2) true As it seems 'contains?' does not check for the last entry in the vector. And an other question. Why does contains? returns everytime 'false' when used on a list? = (contains? (list 1 2 3) 1) false = (contains? (list 1 2 3) 2) false = (contains? (list 1 2 3) 3) false -- 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: Found bug in contains? used with vectors.
'contains?' tests if a key is in a collection. Vector is an associative data structure, with keys being indexes. A vector of length 3 has the key 2, but not key 3. Thanks, Ambrose On Mon, Sep 3, 2012 at 7:03 PM, Goldritter marcus.goldritter.lind...@googlemail.com wrote: I use Clojure 1.4.0 and wanted to use 'contains?' on a vector and get following results: = (contains? [1 2 3] 3) false = (contains? [1 2 3] 2) true As it seems 'contains?' does not check for the last entry in the vector. And an other question. Why does contains? returns everytime 'false' when used on a list? = (contains? (list 1 2 3) 1) false = (contains? (list 1 2 3) 2) false = (contains? (list 1 2 3) 3) false -- 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: Found bug in contains? used with vectors.
From the book Clojure Programming http://www.clojurebook.com/, Page 101 : *It is a common mistake for Clojure programmers to initially believe that contains? always searches for the presence of a value in a collection, that is, that it would be appropriate to use to determine if the vector [0 1 2 3] contained a particular numeric value. This misconception can lead to some very confusing results:* *(contains? [1 2 3] 3)* *;= false* *(contains? [1 2 3] 2)* *;= true* *(contains? [1 2 3] 0)* *;= true* *Of course, the results above are correct, since contains? is only checking to see if any mapping exists for the provided key—in this case, the indices 3, 2, and 0. To check for the existence of a particular value in a collection, it is typical to use some* -- 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: Found bug in contains? used with vectors.
Ah ok. So I need to transform a vector and/or a list into a set first. Thanks. Am Montag, 3. September 2012 13:05:52 UTC+2 schrieb Ambrose Bonnaire-Sergeant: 'contains?' tests if a key is in a collection. Vector is an associative data structure, with keys being indexes. A vector of length 3 has the key 2, but not key 3. Thanks, Ambrose On Mon, Sep 3, 2012 at 7:03 PM, Goldritter marcus.goldr...@googlemail.comjavascript: wrote: I use Clojure 1.4.0 and wanted to use 'contains?' on a vector and get following results: = (contains? [1 2 3] 3) false = (contains? [1 2 3] 2) true As it seems 'contains?' does not check for the last entry in the vector. And an other question. Why does contains? returns everytime 'false' when used on a list? = (contains? (list 1 2 3) 1) false = (contains? (list 1 2 3) 2) false = (contains? (list 1 2 3) 3) false -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clo...@googlegroups.comjavascript: Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+u...@googlegroups.com javascript: 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: Found bug in contains? used with vectors.
Goldritter marcus.goldritter.lind...@googlemail.com writes: Ah ok. So I need to transform a vector and/or a list into a set first. No, not really. All clojure collections implement java.util.Collection, so you can always use (.contains your-coll something) to check if your-coll contains something. However, keep in mind that this does a linear search for lists, sequences or vectors. So if your algorithm relies on containment checks, you might be better off using sets directly. Bye, Tassilo -- 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: Found bug in contains? used with vectors.
this is probably the single most confusing name in clojure! :-) why can't we make it contains-key? ? Jim On 03/09/12 12:14, Goldritter wrote: Ah ok. So I need to transform a vector and/or a list into a set first. Thanks. Am Montag, 3. September 2012 13:05:52 UTC+2 schrieb Ambrose Bonnaire-Sergeant: 'contains?' tests if a key is in a collection. Vector is an associative data structure, with keys being indexes. A vector of length 3 has the key 2, but not key 3. Thanks, Ambrose On Mon, Sep 3, 2012 at 7:03 PM, Goldritter marcus.goldr...@googlemail.com javascript: wrote: I use Clojure 1.4.0 and wanted to use 'contains?' on a vector and get following results: = (contains? [1 2 3] 3) false = (contains? [1 2 3] 2) true As it seems 'contains?' does not check for the last entry in the vector. And an other question. Why does contains? returns everytime 'false' when used on a list? = (contains? (list 1 2 3) 1) false = (contains? (list 1 2 3) 2) false = (contains? (list 1 2 3) 3) false -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clo...@googlegroups.com javascript: Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+u...@googlegroups.com javascript: For more options, visit this group at http://groups.google.com/group/clojure?hl=en 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 -- 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: Found bug in contains? used with vectors.
You could try the function some. = (some #{3} [1 2 3]) 3 = (some #{3} [1 2 5]) nil This uses a set as a predicate function. Greg On Monday, September 3, 2012 7:03:07 AM UTC-4, Goldritter wrote: I use Clojure 1.4.0 and wanted to use 'contains?' on a vector and get following results: = (contains? [1 2 3] 3) false = (contains? [1 2 3] 2) true As it seems 'contains?' does not check for the last entry in the vector. And an other question. Why does contains? returns everytime 'false' when used on a list? = (contains? (list 1 2 3) 1) false = (contains? (list 1 2 3) 2) false = (contains? (list 1 2 3) 3) false -- 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: using take-while with pred function that has state
I have used the following in the past in some utils I have for seqs: (defn take-while-reduce fancy take accumulating a reduced value on taken items this value can then be tested in the take fn e.g (take-while-reduce 0 (fn [v i] (inc v)) (fn [v i] (= v i)) [1 2 3 5 6 7]) = (1 2 3) [initial reduce-fn pred coll] (when-let [s (seq coll)] (let [[f r] coll reduce-value (reduce-fn initial f)] (if (pred reduce-value f) (cons f (take-while-reduce reduce-value reduce-fn pred r)) (comment ;; examples ;; take while value increment (take-while-reduce 0 (fn [v i] (inc v)) (fn [v i] (= v i)) [1 2 3 5 6 7]) ;; acts like a line break (take-while-reduce 0 (fn [v i] (+ v (count i))) (fn [v i] ( v 20)) (ccsu/partition the quick brown fox jumps #\s+)) ) ; ccsu/partition is the old clojure contrib str-utils2 - it's a while since I did this Dave On Friday, 31 August 2012 22:08:03 UTC+10, shaobohou wrote: Hi, I am trying to write a function which takes a list of strings, tokenize each one, and maximise N such that the number of unique tokens in the first N strings is less than some number M. I have written the following function using take-while and a pred function with an atom to store the set of unique tokens. It works and is just as fast as a messier loop/recur version. (defn take-as-many-as-possible-until [ss tok-fn m] (let [items (atom #{})] (- (fn [v] (swap! items (partial apply merge) (tok-fn v)) ( (count @items) m)) (take-while ss However, I have noticed that the take-while documentation says that the pred function should be side-effect free. Will this be problem in my implementation if I am calling it from multiple threads? And what would be the more idiomatic way of implementing this kind of behaviour? Thanks, Shaobo -- 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
when looking for performance, consider 'cheating' !
Hi all, this is basically a continuation of my previous thread Functional performance vs imperative complexity...for those of you who are still interested here is what I learnt during the process. I should note that i finally got the performance I was after without sacrificing any immutability at all! so , how did I do that after all that moaning and complaining? well, if I'm honest I *cheated* !!! let me explain: first some history: --precalculating all the logical moves of chess pieces (except pawn) had a dramatic improvement (cheat #1) --after realizing that i should not be starting the search at depth 4 but at depth 3 instead (because the algorithm only starts searching on the children of the root node - that means that whenever i was starting with 4 it was actually going down to level 5), time went down dramatically. apparently, combinatorial explosion dominates after level 4. --so, in essence i was able to go down to level 4 in roughly 12 sec, but without checking if the king is left exposed! as soon as i added that check (on every single move) time went back up to 5 minutes! you can easily see why that is (for every move you have to check all the opponents moves)...essentially it goes another level down on every node!). so again i was very disappointed with performance...this is where cheat #2 comes in! I don't really need to check if a move exposes the king during search do I? I only need to check this when people are playing on the actual gui...not while searching the game-tree!!! I CAN CHEAT! *I can give the king a ridiculously high value (100 or 1000) and skip the 'exposes?' check!* so, yes, on the way down it will explore a move which exposes the king but , on the way up, it will simply NOT choose it!!! there is no way losing 100 points can be compensated! now, of course this is for the naive static evaluator...I need to slightly alter when a game ends in order to have the same behaviour working with a different eval. function that doesn't consider the pieces values. and I can cheat again!!! very simply: I need to end the game when some team is missing a king!!! as opposed to looking whether the king is threatened and whether he cannot move (checkmate)! It is also cheaper, to say 'give me the 2 kings and whichever is nil the other is the winner', than 'give me all the moves of this team to check if some threatens the king and then give all the moves of the king to check if he can escape'. Of course for the gui, we might want the fancy version that ends the game a la checkmate, but for training genetically merely ending the game when someone loses his king suffices!!! That organism that gave up his king will simply not evolve (cheat #4)!! Presumably i don't have to tell you that I'm now back down to 12 sec which makes me very happy and everything works great! so what is the lesson? you don't really need the right algorithm - you just need to cheat!!! (half-joking) :-) Jim ps: checkers goes down to level 6 potentially 8 quite easily...of course in checkers half the time you MUST make a jump so the whole team has a single move, so things are indeed very different. -- 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: using take-while with pred function that has state
I have used the following (from a bunch of utils I have for seqs) in the past to do this kind of thing. You will need to define the reduce-fn and the predicate you need. examples below in the comment. (defn take-while-reduce fancy take accumulating a reduced value on taken items this value can then be tested in the take fn e.g (take-while-reduce 0 (fn [v i] (inc v)) (fn [v i] (= v i)) [1 2 3 5 6 7]) = (1 2 3) [initial reduce-fn pred coll] (when-let [s (seq coll)] (let [[f r] coll reduce-value (reduce-fn initial f)] (if (pred reduce-value f) (cons f (take-while-reduce reduce-value reduce-fn pred r)) (comment ;; examples (take-while-reduce 0 (fn [v i] (inc v)) (fn [v i] (= v i)) [1 2 3 5 6 7]) ;; acts like a line break (take-while-reduce 0 (fn [v i] (+ v (count i))) (fn [v i] ( v 20)) (ccsu/partition the quick brown fox jumps #\s+)) ) ; ccsu is the old clojure contrin str-utils2 On Friday, 31 August 2012 22:08:03 UTC+10, shaobohou wrote: Hi, I am trying to write a function which takes a list of strings, tokenize each one, and maximise N such that the number of unique tokens in the first N strings is less than some number M. I have written the following function using take-while and a pred function with an atom to store the set of unique tokens. It works and is just as fast as a messier loop/recur version. (defn take-as-many-as-possible-until [ss tok-fn m] (let [items (atom #{})] (- (fn [v] (swap! items (partial apply merge) (tok-fn v)) ( (count @items) m)) (take-while ss However, I have noticed that the take-while documentation says that the pred function should be side-effect free. Will this be problem in my implementation if I am calling it from multiple threads? And what would be the more idiomatic way of implementing this kind of behaviour? Thanks, Shaobo -- 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
Protocol methods, name shadowing and dot notation
Hello there, I'm not quite sure whether is convenient for each method implementation to possibly shadow previous names, particularly those of clojure.core. (defprotocol Example (get [this])) The previous example redefines get in the current namespace. But is that we usually mean by method? That's more of what one would expect of a * function* definition. Given a file in a mainstream OOP lang, one can define N get methods in N classes and no bad things will happen, as they are attached to the classes, not the namespace. In principle, with protocols and records, Clojure is trying to distil the best of OOP. But this detail, in my opinion, seriously hampers such a goal. Maybe get could have clojure.core semantics when the first argument does not implement Example. I doubt it'd yield clear code though, as it overloads meaning. There is actually a way to work around this: (ns protocols) (defprotocol Prot (first [this])) (ns usage) (defrecord Rec [] protocols.Prot (first [this] A value.)) (first (Rec.)) ; clojure.core/first gets called. This wouldn't happen in the previous namespace! (.first (Rec.)) ; protocols.Prot.first gets called. However, it feels like exploiting implementation details. In fact, *it won't work in ClojureScript*: one would be only left with the option of using :refer-clojure. Which in practice means don't: library authors or even programmers in a team can't expect their API consumers to unqualify names from clojure.core. In my opinion, the problem lies in that the (.method obj) syntax has too low-level semantics: it seems to mean just interop call. Shouln't it be leveled-up to the more general method call? It maps well to both Java and JavaScript, and probably any language. Thus, I believe that ideally, calls to Clojure *methods* should be dot-prefixed. It'd allow us to freely/fearlessly choose whatever name we can come up for a protocol method. Otherwise there would effectively exist about 500 reserved words (OTOH, one gets a convenient warning when shadowing an existing name). Furthermore, this would blur the popular conception that dot-syntax is ugly in lisps. Rich has writtenhttp://www.reddit.com/r/programming/comments/6jgnp/why_arc_is_bad_for_exploratory_programming/c040ptn : In Clojure I can close a file like this: (.close file) That's a 'Java' call. Now, I could write a Clojure 'library' that let me say: (close file) but I really have better things to do, and so do the people that use Clojure. (his point doesn't completely map to mine. But it can help changing your mind) Finally, I believe that method calls should be visually obvious, as their output can potentially depend on the fields of the implementing record/type, however immutable: (defprotocol Foo (method [this])) (defrecord Bar [x y z] Foo (method [this] A value.)) If we run (method a-bar-instance), x, y and z are, in a way, implicit arguments that method receives, since it has access to them. How do we tell function calls from method calls? Is it immediately obvious the presence of these implicit arguments? Just as Rich warns us against *unlabeled* mutationhttp://www.deftitlenil.com/2011/09/notes-strangeloop-programming-languages.html, I feel concerned with unlabeled method calls. So my proposal would be: - Acknowledge the dot-calls as a feature of defrecord/deftype methods, rather than a syntax that happens to work - Make dot-calls possible in ClojureScript. As a nice side-effect, this would simplify calling ClojureScript from JavaScript (someone other than me has had this problem toohttp://stackoverflow.com/questions/9018326/how-do-i-create-an-js-object-with-methods-and-constructor-in-clojurescript ). At least from the point of view of someone that isn't too familiar with the Clojure internals, I see no downsides - although I tried it! For instance, given that one can call (.first ()), I thought that then one could call (.first (ARecord.)), which would ruin my whole idea. But fortunately, that isn't the case. My question is quite simply - do you agree? Are these semantics Clojure(Script) should look forward? Thank you very much for your attention. -- 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: Protocol methods, name shadowing and dot notation
Correction: records/types actually include plenty of dot-accesible methods, though less than lists -for instance- do. (mapv println (.getMethods (.getClass (ARecord. -- 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: Protocol methods, name shadowing and dot notation
On Mon, Sep 3, 2012 at 9:17 PM, vemv v...@vemv.net wrote: At least from the point of view of someone that isn't too familiar with the Clojure internals, I see no downsides - although I tried it! For instance, given that one can call (.first ()), I thought that then one could call (.first (ARecord.)), which would ruin my whole idea. But fortunately, that isn't the case. An obvious downside is that method calls are not first-class, and function calls are. Thanks, Ambrose -- 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: Protocol methods, name shadowing and dot notation
Hi, In principle, dispatch is orthogonal to namespacing. It is true that traditional OO systems complect these two things, but there is no inherent need to do so. Separating dispatch (i.e., methods) from namespacing is simpler and more flexible. This is especially useful when you have multiple inheritance, since the traditional problem of name collisions of unrelated methods does not occur in a system that separates namespaces from types, but there are other advantages as well (such as the nice uniformity of being able to reference methods as first-class functions without resorting to lambda-expressions). Matthias -- 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: Protocol methods, name shadowing and dot notation
Would it be feasible to efficiently make them first class? Surely this isn't a new question, as many would desire to write (mapv .toString (range 10)) rather than (mapv #(.toString %) (range 10)). Couldn't find info on that topic... *(just an example, I know there's str) On Monday, September 3, 2012 3:37:05 PM UTC+2, Ambrose Bonnaire-Sergeant wrote: An obvious downside is that method calls are not first-class, and function calls are. Thanks, Ambrose -- 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: ClojureSphere updated
Michael, I actually think it's a project.clj parsing issue. Midje's is a little non-standard looking. I've opened an issue for it. Thanks for the feedback and report, Justin On Monday, September 3, 2012 2:15:28 AM UTC-4, Michael Klishin wrote: 2012/9/3 Justin Kramer jkkr...@gmail.com javascript: ClojureSphere has been updated with a new domain, refreshed index, and some new features: http://www.clojuresphere.com/ Justin, The new version looks great! I have noticed that ClojureSphere points to a fork of the Midje repository at https://github.com/bmabey/Midje while the canonical repository is https://github.com/marick/Midje. Is it a data aggregation issue or it actually tries to cover all the forks? -- MK http://github.com/michaelklishin http://twitter.com/michaelklishin -- 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: clojure.org/getting_started: not up to date
This will work only if A) there is a manifest in the jar specifying which class contains the main method B) if you do not need to add libraries explicitly, -cp is ignored when you use -jar Clojure.org is correct, especially regarding b). If you happen to need to add libs to your REPL, -jar is a dead end. If you happen to create a specific main for your own app, using -jar is much more complex to setup. Luc P On http://clojure.org/getting_started: Download http://clojure.org/downloads and unzip Clojure. In the directory in which you expanded clojure.zip, run: java -cp clojure-1.4.0.jar clojure.main Should be just: java -jar clojure-1.4.0.jar It's a detail, but an important one, as it's the first contact for most of the new Clojure users. Denis On Mon, Sep 3, 2012 at 9:00 AM, Denis Labaye denis.lab...@gmail.com wrote: 1. java -cp ./org/clojure/clojure/1.4.0/clojure-1.4.0.jar clojure.main 2. cut paste your code in the REPL 3. type (start) [enter] On Fri, Aug 31, 2012 at 3:36 AM, gearss gearss8...@gmail.com wrote: I have a file named pong.clj, it isunder following, I want to know how can I run it? Thank you. (ns example.game.pong (:use [penumbra opengl] [clojure.contrib.def]) (:require [penumbra [app :as app] [text :as text]])) (def ball-width 0.03) (def ball-height 0.03) (def paddle-width 0.02) (def paddle-height 0.15) ;;; (defn abs [x] (Math/abs x)) (defn intersect-1d [[a b] [x y]] (and (= a y) (= b x))) (defn intersect-2d [[a b c d] [x y z w]] (and (intersect-1d [a c] [x z]) (intersect-1d [b d] [y w]))) (defn reflector [[x y w h] f] (let [r [x y (+ x w) (+ y h)]] (fn [region velocity] (if (intersect-2d region r) (f velocity) velocity (defvar boundaries [(reflector [0 -1 1 1] (fn [[x y]] [x (abs y)])) (reflector [0 1 1 1] (fn [[x y]] [x (- (abs y))])) (reflector [-1 0 1 1] (fn [[x y]] [(abs x) y])) (reflector [1 0 1 1] (fn [[x y]] [(- (abs x)) y]))]) (defn update-ball [state dt] (let [ball (concat (:p state) (map + (:p state) [ball-width ball-height])) v (reduce #(%2 ball %1) (:v state) (conj boundaries (reflector [0.01 (:left state) paddle-width paddle-height] (fn [[x y]] [(abs x) y])) (reflector [(- 0.99 paddle-width) (:right state) paddle-width paddle-height] (fn [[x y]] [(- (abs x)) y]] (assoc state :v v :p (map + (:p state) (map (partial * dt) v) (defn draw-ball [pos] (push-matrix (apply translate pos) (draw-quads (vertex 0 0) (vertex ball-width 0) (vertex ball-width ball-height) (vertex 0 ball-height ;;; (defn update-opponent-paddle [state] (let [[x y] (:p state) [vx vy] (:v state) dt (/ (- 1 x) vx) dy (- (+ y (* vy dt)) (:right state))] (assoc state :v-right (if (neg? vx) 0 (/ dy dt) (defn update-player-paddle [state] (assoc state :v-left (cond (app/key-pressed? :up) -1 (app/key-pressed? :down) 1 :else 0))) (defn update-paddle [dt v pos] (min (- 1 paddle-height) (max 0 (+ pos (* dt v) (defn draw-paddle [x y] (push-matrix (translate x y) (draw-quads (vertex 0 0) (vertex paddle-width 0) (vertex paddle-width paddle-height) (vertex 0 paddle-height ;;; (defn reset-game [state] (assoc state :v [0.4 0.8] :p [0.5 0.5] :left 0.5, :v-left 0.0 :right 0.5, :v-right 0.0)) (defn init [state] (app/vsync! true) (app/title! Pong) (app/periodic-update! 2 update-opponent-paddle) (reset-game state)) (defn reshape [[x y w h] state] (ortho-view 0 1 1 0 -1 1) state) (defn update [[delta _] state] (- state (update-player-paddle) (assoc :left (update-paddle delta (:v-left state) (:left state))) (assoc :right (update-paddle delta (:v-right state) (:right state))) (update-ball delta))) (defn display [[delta _] state] (draw-ball (:p state)) (draw-paddle 0.01 (:left state)) (draw-paddle (- 0.99 paddle-width) (:right state)) (app/repaint!)) (defn start [] (app/start {:display display, :reshape reshape, :update update, :init init} {})) -- 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
Re: Protocol methods, name shadowing and dot notation
Hi Matthias, I can't disagree with you, and am open to change my mind. Just a question. Given again this example: (ns protocols) (defprotocol P (get [_])) (ns app) (defrecord R [] protocols/P (get [_] 42)) (can you call R's get without resorting to dot-notation, this is, with a namespace qualification instead? I couldn't achieve it - perhaps I'm missing something. On Monday, September 3, 2012 3:40:38 PM UTC+2, Matthias Benkard wrote: Hi, In principle, dispatch is orthogonal to namespacing. It is true that traditional OO systems complect these two things, but there is no inherent need to do so. Separating dispatch (i.e., methods) from namespacing is simpler and more flexible. This is especially useful when you have multiple inheritance, since the traditional problem of name collisions of unrelated methods does not occur in a system that separates namespaces from types, but there are other advantages as well (such as the nice uniformity of being able to reference methods as first-class functions without resorting to lambda-expressions). Matthias -- 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: ClojureSphere updated
2012/9/3 Justin Kramer jkkra...@gmail.com: ClojureSphere has been updated with a new domain, refreshed index, and some new features: http://www.clojuresphere.com/ Awesome work! Kudos, -- Marco Dalla Stella web: http://marco.dallastella.name twitter: http://twitter.com/mdallastella -- 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: I want to know how can I run it?
On Thursday, August 30, 2012 9:36:14 PM UTC-4, gearss wrote: I have a file named pong.clj, it isunder following, I want to know how can I run it? Thank you. Hi gearss. See Launching a Script at http://clojure.org/repl_and_main . ---John -- 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: clojure.org/getting_started: not up to date
Btwy, using leiningen's repl hides all these issues... Luc This will work only if A) there is a manifest in the jar specifying which class contains the main method B) if you do not need to add libraries explicitly, -cp is ignored when you use -jar Clojure.org is correct, especially regarding b). If you happen to need to add libs to your REPL, -jar is a dead end. If you happen to create a specific main for your own app, using -jar is much more complex to setup. Luc P On http://clojure.org/getting_started: Download http://clojure.org/downloads and unzip Clojure. In the directory in which you expanded clojure.zip, run: java -cp clojure-1.4.0.jar clojure.main Should be just: java -jar clojure-1.4.0.jar It's a detail, but an important one, as it's the first contact for most of the new Clojure users. Denis On Mon, Sep 3, 2012 at 9:00 AM, Denis Labaye denis.lab...@gmail.com wrote: 1. java -cp ./org/clojure/clojure/1.4.0/clojure-1.4.0.jar clojure.main 2. cut paste your code in the REPL 3. type (start) [enter] On Fri, Aug 31, 2012 at 3:36 AM, gearss gearss8...@gmail.com wrote: I have a file named pong.clj, it isunder following, I want to know how can I run it? Thank you. (ns example.game.pong (:use [penumbra opengl] [clojure.contrib.def]) (:require [penumbra [app :as app] [text :as text]])) (def ball-width 0.03) (def ball-height 0.03) (def paddle-width 0.02) (def paddle-height 0.15) ;;; (defn abs [x] (Math/abs x)) (defn intersect-1d [[a b] [x y]] (and (= a y) (= b x))) (defn intersect-2d [[a b c d] [x y z w]] (and (intersect-1d [a c] [x z]) (intersect-1d [b d] [y w]))) (defn reflector [[x y w h] f] (let [r [x y (+ x w) (+ y h)]] (fn [region velocity] (if (intersect-2d region r) (f velocity) velocity (defvar boundaries [(reflector [0 -1 1 1] (fn [[x y]] [x (abs y)])) (reflector [0 1 1 1] (fn [[x y]] [x (- (abs y))])) (reflector [-1 0 1 1] (fn [[x y]] [(abs x) y])) (reflector [1 0 1 1] (fn [[x y]] [(- (abs x)) y]))]) (defn update-ball [state dt] (let [ball (concat (:p state) (map + (:p state) [ball-width ball-height])) v (reduce #(%2 ball %1) (:v state) (conj boundaries (reflector [0.01 (:left state) paddle-width paddle-height] (fn [[x y]] [(abs x) y])) (reflector [(- 0.99 paddle-width) (:right state) paddle-width paddle-height] (fn [[x y]] [(- (abs x)) y]] (assoc state :v v :p (map + (:p state) (map (partial * dt) v) (defn draw-ball [pos] (push-matrix (apply translate pos) (draw-quads (vertex 0 0) (vertex ball-width 0) (vertex ball-width ball-height) (vertex 0 ball-height ;;; (defn update-opponent-paddle [state] (let [[x y] (:p state) [vx vy] (:v state) dt (/ (- 1 x) vx) dy (- (+ y (* vy dt)) (:right state))] (assoc state :v-right (if (neg? vx) 0 (/ dy dt) (defn update-player-paddle [state] (assoc state :v-left (cond (app/key-pressed? :up) -1 (app/key-pressed? :down) 1 :else 0))) (defn update-paddle [dt v pos] (min (- 1 paddle-height) (max 0 (+ pos (* dt v) (defn draw-paddle [x y] (push-matrix (translate x y) (draw-quads (vertex 0 0) (vertex paddle-width 0) (vertex paddle-width paddle-height) (vertex 0 paddle-height ;;; (defn reset-game [state] (assoc state :v [0.4 0.8] :p [0.5 0.5] :left 0.5, :v-left 0.0 :right 0.5, :v-right 0.0)) (defn init [state] (app/vsync! true) (app/title! Pong) (app/periodic-update! 2 update-opponent-paddle) (reset-game state)) (defn reshape [[x y w h] state] (ortho-view 0 1 1 0 -1 1) state) (defn update [[delta _] state] (- state (update-player-paddle) (assoc :left (update-paddle delta (:v-left state) (:left state))) (assoc :right (update-paddle delta (:v-right state) (:right state))) (update-ball delta))) (defn display [[delta _] state] (draw-ball (:p state)) (draw-paddle 0.01 (:left state)) (draw-paddle (- 0.99 paddle-width) (:right state)) (app/repaint!)) (defn start [] (app/start {:display display, :reshape reshape, :update update, :init init} {})) -- 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
Re: Reflecting over protocols in macros for clojurescript
On Mon, Sep 3, 2012 at 5:20 AM, Ceri Storey ceri.sto...@gmail.com wrote: Hi there. I'm having a play around with ClojureScript, and I'd find it really useful to be able to be able to create some Mockito style test spies. Ultimately, I'd like to be able to generate a spie by reflecting over a protocol and find out what operations it supports programatically. However, now that I've looked core.cljs from the ClojureScript source code, it doesn't seem like the compiler actually keeps track of which protocols support which operations--is that right? Is there some other way of discovering the operations that a cljs protocol supports, or would i need to write my own analysis for this? Thanks, -- Ceri Storey Are you referring to the ability when using Clojure on the JVM to get the map of data from referencing the protocol itself? user= (defprotocol IFoo (-foo [a b])) IFoo user= IFoo {:on-interface user.IFoo, :on user.IFoo, :sigs {:-foo {:doc nil, :arglists ([a b]), :name -foo}}, :var #'user/IFoo, :method-map {:-foo :-foo}, :method-builders {#'user/-foo #user$eval319$fn__320 user$eval319$fn__320@76d2796e}} ? David -- 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: Protocol methods, name shadowing and dot notation
You have reused a name already bound in the `protocols` namespace. You cannot bind two things to the same var. On the other hand, precisely because namespaces are not complected with protocol dispatch, you can easily free the `get` identifier for your purposes by doing exactly what you would do if you wanted to reuse the identifier in some other way: (ns protocols (:refer-clojure :exclude [get])) (defprotocol P (get [_])) (ns app) (defrecord R [] protocols/P (protocols/get [_] 42)) You can now call `protocols/get` by namespace qualification (or by importing it into the current namespace): user (in-ns 'app) app (protocols/get (-R)) 42 Matthias -- 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: I want to know how can I run it?
On Monday, September 3, 2012 11:34:02 AM UTC-4, John Gabriele wrote: On Thursday, August 30, 2012 9:36:14 PM UTC-4, gearss wrote: I have a file named pong.clj, it isunder following, I want to know how can I run it? Thank you. Hi gearss. See Launching a Script at http://clojure.org/repl_and_main . Whoops. Sorry --- just noticed you have some dependencies in there. A few things: * Of course, as a prerequisite, you'll need to have Java installed. * Since you've got dependencies, it will probably be easiest to install [leiningen](http://leiningen.org/), then use it to create a new project (`lein new app example.game.pong`) and put your code into that new project. * you'll need to edit your project's project.clj file to include the penumbra dependency. Note though that the [penumbra github page](https://github.com/ztellman/penumbra) mentions that it's no longer under active development. More info in [this thread](https://groups.google.com/forum/?fromgroups=#!topic/penumbra-lib/3hFqFZYCeaI). * I don't know about the opengl dependency. * Regarding the dependency on clojure.contrib.def, note that the contrib libraries have undergone a change since older versions of Clojure: they're no longer one big monolithic distribution, but instead are now modular (and distributed separately). I haven't used defvar (presumably from clojure.contrib.def) before. [This page](http://dev.clojure.org/display/design/Where+Did+Clojure.Contrib+Go) has a note about it, and specifically mentions defvar. Hope that helps a bit. ---John -- 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: Protocol methods, name shadowing and dot notation
Oh, I understand. Works in ClojureScript as well! I noticed that in this line (protocols/get [_] 42) One can safely drop the namespace qualification. Thank you very much Matthias - this issue was certainly a blocker for me. On Mon, Sep 3, 2012 at 5:54 PM, Matthias Benkard mulkiat...@gmail.comwrote: You have reused a name already bound in the `protocols` namespace. You cannot bind two things to the same var. On the other hand, precisely because namespaces are not complected with protocol dispatch, you can easily free the `get` identifier for your purposes by doing exactly what you would do if you wanted to reuse the identifier in some other way: (ns protocols (:refer-clojure :exclude [get])) (defprotocol P (get [_])) (ns app) (defrecord R [] protocols/P (protocols/get [_] 42)) You can now call `protocols/get` by namespace qualification (or by importing it into the current namespace): user (in-ns 'app) app (protocols/get (-R)) 42 Matthias -- 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: clojure.org/getting_started: not up to date
On Mon, Sep 3, 2012 at 5:40 PM, Softaddicts lprefonta...@softaddicts.cawrote: Btwy, using leiningen's repl hides all these issues... yes, and Emacs is one of the best for hacking Clojure code ... But not necessarily for new users, who don't know Emacs or Java. And even better than lein: You can't beat an online REPL for a quick Clojure experience, like http://tryclj.com/ It would be cool if an online REPL was available just on the front page of clojure.org Luc This will work only if A) there is a manifest in the jar specifying which class contains the main method B) if you do not need to add libraries explicitly, -cp is ignored when you use -jar Clojure.org is correct, especially regarding b). If you happen to need to add libs to your REPL, -jar is a dead end. If you happen to create a specific main for your own app, using -jar is much more complex to setup. Luc P On http://clojure.org/getting_started: Download http://clojure.org/downloads and unzip Clojure. In the directory in which you expanded clojure.zip, run: java -cp clojure-1.4.0.jar clojure.main Should be just: java -jar clojure-1.4.0.jar It's a detail, but an important one, as it's the first contact for most of the new Clojure users. Denis On Mon, Sep 3, 2012 at 9:00 AM, Denis Labaye denis.lab...@gmail.com wrote: 1. java -cp ./org/clojure/clojure/1.4.0/clojure-1.4.0.jar clojure.main 2. cut paste your code in the REPL 3. type (start) [enter] On Fri, Aug 31, 2012 at 3:36 AM, gearss gearss8...@gmail.com wrote: I have a file named pong.clj, it isunder following, I want to know how can I run it? Thank you. (ns example.game.pong (:use [penumbra opengl] [clojure.contrib.def]) (:require [penumbra [app :as app] [text :as text]])) (def ball-width 0.03) (def ball-height 0.03) (def paddle-width 0.02) (def paddle-height 0.15) ;;; (defn abs [x] (Math/abs x)) (defn intersect-1d [[a b] [x y]] (and (= a y) (= b x))) (defn intersect-2d [[a b c d] [x y z w]] (and (intersect-1d [a c] [x z]) (intersect-1d [b d] [y w]))) (defn reflector [[x y w h] f] (let [r [x y (+ x w) (+ y h)]] (fn [region velocity] (if (intersect-2d region r) (f velocity) velocity (defvar boundaries [(reflector [0 -1 1 1] (fn [[x y]] [x (abs y)])) (reflector [0 1 1 1] (fn [[x y]] [x (- (abs y))])) (reflector [-1 0 1 1] (fn [[x y]] [(abs x) y])) (reflector [1 0 1 1] (fn [[x y]] [(- (abs x)) y]))]) (defn update-ball [state dt] (let [ball (concat (:p state) (map + (:p state) [ball-width ball-height])) v (reduce #(%2 ball %1) (:v state) (conj boundaries (reflector [0.01 (:left state) paddle-width paddle-height] (fn [[x y]] [(abs x) y])) (reflector [(- 0.99 paddle-width) (:right state) paddle-width paddle-height] (fn [[x y]] [(- (abs x)) y]] (assoc state :v v :p (map + (:p state) (map (partial * dt) v) (defn draw-ball [pos] (push-matrix (apply translate pos) (draw-quads (vertex 0 0) (vertex ball-width 0) (vertex ball-width ball-height) (vertex 0 ball-height ;;; (defn update-opponent-paddle [state] (let [[x y] (:p state) [vx vy] (:v state) dt (/ (- 1 x) vx) dy (- (+ y (* vy dt)) (:right state))] (assoc state :v-right (if (neg? vx) 0 (/ dy dt) (defn update-player-paddle [state] (assoc state :v-left (cond (app/key-pressed? :up) -1 (app/key-pressed? :down) 1 :else 0))) (defn update-paddle [dt v pos] (min (- 1 paddle-height) (max 0 (+ pos (* dt v) (defn draw-paddle [x y] (push-matrix (translate x y) (draw-quads (vertex 0 0) (vertex paddle-width 0) (vertex paddle-width paddle-height) (vertex 0 paddle-height ;;; (defn reset-game [state] (assoc state :v [0.4 0.8] :p [0.5 0.5] :left 0.5, :v-left 0.0 :right 0.5, :v-right 0.0)) (defn init [state] (app/vsync! true) (app/title! Pong) (app/periodic-update! 2 update-opponent-paddle) (reset-game state)) (defn reshape [[x y w h] state] (ortho-view 0 1 1 0 -1 1) state) (defn update [[delta _] state] (- state (update-player-paddle) (assoc :left (update-paddle delta (:v-left state) (:left state))) (assoc :right (update-paddle delta (:v-right state) (:right state))) (update-ball delta))) (defn display [[delta _]
Re: webnoir on openshift (Paas by RedHat), little guide
Yes, I know it is an issue, but I didn't really find any other PaaS (free to start) without such problem... On Monday, September 3, 2012 3:21:02 AM UTC+2, raould wrote: now if only they had a webinar that explained the utterly horrendous leagaleze nightmare tolsoty-length terms and conditions. On Fri, Aug 31, 2012 at 2:49 PM, John Holland jbho...@gmail.comjavascript: wrote: This is awesome! On Friday, August 31, 2012 4:31:38 PM UTC-4, Simone Mosciatti wrote: A little guide to use webnoir on openshift http://sisciatech.tumblr.com/post/29614188595/webnoir-in-openshift English is not my first language, if you find any mistake please let me know. I hope it will be useful to somebody. Simone -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clo...@googlegroups.comjavascript: Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+u...@googlegroups.com javascript: 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: using take-while with pred function that has state
On Sun, 2012-09-02 at 23:02 -0700, Ben Wolfson wrote: Can you say what this means (the note about take-while being called in coll order)? Does it mean that it's not a guarantee of the API that the predicate passed to take-while be called *successively* on the items in the collection passed in? Yes, that's what it means. Sorry I was not more clear. I would have hoped that would be guaranteed Nevertheless, by declaring pred must be free of side-effects, `take-while' is refusing to make that promise, among many others. otherwise you might be forcing the computation of elements of a lazy sequence unnecessarily, which could be expensive, even if there are no side-effects, or (potentially, at least) raise an exception that would otherwise not be raised. In general, you may not assume that more elements of a lazy sequence than you need will not be computed. I exempt `reductions', `iterate', and any sequences derived from those in my own practice; you may be more or less comfortable with such exemptions. user= (first (map print [1 2 3 4])) 1234nil user= (first (map print '(1 2 3 4))) 1nil There's some misinformation on the web about exactly how this works; I recommend reading the implementations of map, filter, and concat in core.clj to gain a better understanding of seq chunking. -- Stephen Compall ^aCollection allSatisfy: [:each|aCondition]: less is better -- 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: using take-while with pred function that has state
On Mon, 2012-09-03 at 01:12 -0700, Alan Malloy wrote: (map #(do %2 %1) c1 c2) is a neat trick I hadn't seen in this context; thanks for showing me! Perhaps you'd also like to advocate for the inclusion of `first-arg', which has several other uses, in core? :) -- Stephen Compall ^aCollection allSatisfy: [:each|aCondition]: less is better -- 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: Reflecting over protocols in macros for clojurescript
2012年9月3日月曜日 16時54分34秒 UTC+1 David Nolen: On Mon, Sep 3, 2012 at 5:20 AM, Ceri Storey ceri@gmail.comjavascript: wrote: Are you referring to the ability when using Clojure on the JVM to get the map of data from referencing the protocol itself? I did not even know you could do that, but that does look like it could be useful. I'm really looking for something like clojure.reflect/reflect, I think. Okay--I'd missed that the information gets recorded in the namespaces var in cljs.analyse, so I think that I shoudl be able to do what I want with a combination of cljs.analyse/resolve-var , get-namespaces, and inspecting the results. Is there a better way that I've missed that anyone knows of? I'll have a play and at least try to gist the results. Thanks! user= (defprotocol IFoo (-foo [a b])) IFoo user= IFoo {:on-interface user.IFoo, :on user.IFoo, :sigs {:-foo {:doc nil, :arglists ([a b]), :name -foo}}, :var #'user/IFoo, :method-map {:-foo :-foo}, :method-builders {#'user/-foo #user$eval319$fn__320 user$eval319$fn__320@76d2796e}} ? David -- 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: Reflecting over protocols in macros for clojurescript
On Mon, Sep 3, 2012 at 5:57 PM, Ceri Storey ceri.sto...@gmail.com wrote: Okay--I'd missed that the information gets recorded in the namespaces var in cljs.analyse, so I think that I shoudl be able to do what I want with a combination of cljs.analyse/resolve-var , get-namespaces, and inspecting the results. Is there a better way that I've missed that anyone knows of? That sounds reasonable. Out of curiosity what do you want to do with that information? David -- 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: Reflecting over protocols in macros for clojurescript
2012/9/3 David Nolen dnolen.li...@gmail.com On Mon, Sep 3, 2012 at 5:57 PM, Ceri Storey ceri.sto...@gmail.com wrote: Okay--I'd missed that the information gets recorded in the namespaces var in cljs.analyse, so I think that I shoudl be able to do what I want with a combination of cljs.analyse/resolve-var , get-namespaces, and inspecting the results. Is there a better way that I've missed that anyone knows of? That sounds reasonable. Out of curiosity what do you want to do with that information? Essentially, I'd like to be able to create some mock objects for test-driving some UI code (the mocks are mostly to help make it obvious when I'm doing too much in one place), although I'm still very much experimenting for the time being. -- 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 -- Ceri Storey -- 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: Question about sets
In the early days of Clojure, it was clear that Rich was reading every post on the Clojure mailing list. He didn't respond to every single thread, of course, but when new issues were raised, he would frequently chime in, That's a good point, please create a patch for that or That's something that's never going to change. This created a clear path for bug reports, feature requests, and improvement suggestions. Basically, the path was to post on the mailing list. If it was something that had been already discussed in the past, one could count on the community to point to the relevant thread. If it was something new, one could count on it eventually being evaluated by Rich and an official judgment made. The community was instructed not to submit any kind of patch without a go-ahead from Rich. I don't know what the path is now. I feel that in the past year, there have been several times where people have raised meaningful issues about Clojure and received no official response. It's hard to know whether this is an intentional rejection through ignoring, or whether it's just that those messages happened to slip beneath the radar. Maybe Rich didn't see them, and without his go-ahead, no one moved forward with them. As a recent example, consider the issue I raised last month about sets, which in 1.3 were changed so that via several methods of construction (either literal notation or the hash-set constructor), they now throw an error, breaking code that previously worked, reducing the utility of set notation, and imposing on users the need to remember the idiosyncrasies of which methods of set construction impose this constraint and which don't. The majority of those who weighed in on the issue agreed with my complaint. The set issue was even discussed on the Mostly Lazy podcast as an example of how, even though Clojure gets a lot of the big ideas right, there seem to be a lot of little things that Clojure still hasn't nailed. In any case, there was a great deal of useful discussion about the set issue, and then... silence. There are a couple of points here: 1. I use Clojure regularly. The little things may be little, but when you use Clojure regularly, those little things do start to grate after a while. I would very much like to see Clojure on a path to resolve the little things, so that the language becomes increasingly pleasurable to use. To do this, the community would benefit for a very clear mechanism for raising, discussing, evaluating, and resolving these issues. The hope that Rich reads the thread approach doesn't appear to be working any more. For example, on whitehouse.gov, you can start a petition and if enough people sign the petition within a given length of time, the president's office will issue an official statement about it. That's the kind of thing I'm thinking about. Rich's time is valuable, but it would be nice to know that any issue that reaches a certain level of visibility will receive an official yea or nay rather than languish in silence. 2. There was significant support for my suggestion to revert set behavior back to 1.2 and solve the problem which motivated the change by bringing array-maps into accord with the behavior of the other maps and sets. This email is also my way of bumping the thread and bringing it again to everyone's attention. This is something I'd very much like to see resolved. --Mark -- 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: clojure.org/getting_started: not up to date
I've been playing with Go a lot recently, and I have found the documentation / new user experience very good: http://golang.org/ On Mon, Sep 3, 2012 at 2:19 PM, Denis Labaye denis.lab...@gmail.com wrote: On Mon, Sep 3, 2012 at 5:40 PM, Softaddicts lprefonta...@softaddicts.ca wrote: Btwy, using leiningen's repl hides all these issues... yes, and Emacs is one of the best for hacking Clojure code ... But not necessarily for new users, who don't know Emacs or Java. And even better than lein: You can't beat an online REPL for a quick Clojure experience, like http://tryclj.com/ It would be cool if an online REPL was available just on the front page of clojure.org Luc This will work only if A) there is a manifest in the jar specifying which class contains the main method B) if you do not need to add libraries explicitly, -cp is ignored when you use -jar Clojure.org is correct, especially regarding b). If you happen to need to add libs to your REPL, -jar is a dead end. If you happen to create a specific main for your own app, using -jar is much more complex to setup. Luc P On http://clojure.org/getting_started: Download http://clojure.org/downloads and unzip Clojure. In the directory in which you expanded clojure.zip, run: java -cp clojure-1.4.0.jar clojure.main Should be just: java -jar clojure-1.4.0.jar It's a detail, but an important one, as it's the first contact for most of the new Clojure users. Denis On Mon, Sep 3, 2012 at 9:00 AM, Denis Labaye denis.lab...@gmail.com wrote: 1. java -cp ./org/clojure/clojure/1.4.0/clojure-1.4.0.jar clojure.main 2. cut paste your code in the REPL 3. type (start) [enter] On Fri, Aug 31, 2012 at 3:36 AM, gearss gearss8...@gmail.com wrote: I have a file named pong.clj, it isunder following, I want to know how can I run it? Thank you. (ns example.game.pong (:use [penumbra opengl] [clojure.contrib.def]) (:require [penumbra [app :as app] [text :as text]])) (def ball-width 0.03) (def ball-height 0.03) (def paddle-width 0.02) (def paddle-height 0.15) ;;; (defn abs [x] (Math/abs x)) (defn intersect-1d [[a b] [x y]] (and (= a y) (= b x))) (defn intersect-2d [[a b c d] [x y z w]] (and (intersect-1d [a c] [x z]) (intersect-1d [b d] [y w]))) (defn reflector [[x y w h] f] (let [r [x y (+ x w) (+ y h)]] (fn [region velocity] (if (intersect-2d region r) (f velocity) velocity (defvar boundaries [(reflector [0 -1 1 1] (fn [[x y]] [x (abs y)])) (reflector [0 1 1 1] (fn [[x y]] [x (- (abs y))])) (reflector [-1 0 1 1] (fn [[x y]] [(abs x) y])) (reflector [1 0 1 1] (fn [[x y]] [(- (abs x)) y]))]) (defn update-ball [state dt] (let [ball (concat (:p state) (map + (:p state) [ball-width ball-height])) v (reduce #(%2 ball %1) (:v state) (conj boundaries (reflector [0.01 (:left state) paddle-width paddle-height] (fn [[x y]] [(abs x) y])) (reflector [(- 0.99 paddle-width) (:right state) paddle-width paddle-height] (fn [[x y]] [(- (abs x)) y]] (assoc state :v v :p (map + (:p state) (map (partial * dt) v) (defn draw-ball [pos] (push-matrix (apply translate pos) (draw-quads (vertex 0 0) (vertex ball-width 0) (vertex ball-width ball-height) (vertex 0 ball-height ;;; (defn update-opponent-paddle [state] (let [[x y] (:p state) [vx vy] (:v state) dt (/ (- 1 x) vx) dy (- (+ y (* vy dt)) (:right state))] (assoc state :v-right (if (neg? vx) 0 (/ dy dt) (defn update-player-paddle [state] (assoc state :v-left (cond (app/key-pressed? :up) -1 (app/key-pressed? :down) 1 :else 0))) (defn update-paddle [dt v pos] (min (- 1 paddle-height) (max 0 (+ pos (* dt v) (defn draw-paddle [x y] (push-matrix (translate x y) (draw-quads (vertex 0 0) (vertex paddle-width 0) (vertex paddle-width paddle-height) (vertex 0 paddle-height ;;; (defn reset-game [state] (assoc state :v [0.4 0.8] :p [0.5 0.5] :left 0.5, :v-left 0.0 :right 0.5, :v-right 0.0)) (defn init [state] (app/vsync! true) (app/title! Pong) (app/periodic-update! 2 update-opponent-paddle) (reset-game state)) (defn reshape [[x y w h] state] (ortho-view 0 1 1 0 -1 1) state) (defn update [[delta _] state] (- state
Re: Question about sets
On Mon, Sep 3, 2012 at 6:06 PM, Mark Engelberg mark.engelb...@gmail.com wrote: I don't know what the path is now. I feel that in the past year, there have been several times where people have raised meaningful issues about Clojure and received no official response. It's hard to know whether this is an intentional rejection through ignoring, or whether it's just that those messages happened to slip beneath the radar. Maybe Rich didn't see them, and without his go-ahead, no one moved forward with them. My understanding is the sort of discussion you are referring to has moved to clojure-dev by necessity because of the volume of posts on this list. http://clojure.org/contributing hints as much. My understanding is also that anyone can open an issue in JIRA for something they believe is a bug. In any case, there was a great deal of useful discussion about the set issue, and then... silence. Open an issue in JIRA. Ask the folks here who agreed with your point of view to vote on the issue. All issues get raised on clojure-dev one way or another (esp. if they have a patch attached). example, on whitehouse.gov, you can start a petition and if enough people sign the petition within a given length of time, the president's office will issue an official statement about it. That's the kind of thing I'm thinking That would seem to match the voting on JIRA issues point above. 2. There was significant support for my suggestion to revert set behavior back to 1.2 and solve the problem which motivated the change by bringing array-maps into accord with the behavior of the other maps and sets. This email is also my way of bumping the thread and bringing it again to everyone's attention. This is something I'd very much like to see resolved. Again, open an issue in JIRA with a patch (you have a signed CA on file so there's no obstacle). That will guarantee the issue gets reviewed. -- Sean A Corfield -- (904) 302-SEAN An Architect's View -- http://corfield.org/ World Singles, LLC. -- http://worldsingles.com/ Perfection is the enemy of the good. -- Gustave Flaubert, French realist novelist (1821-1880) -- 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: genuine help needed to speed up minimax algorithm!
Did you figure out what was going on? -- 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
reporting function inputs as part of exceptions
I'm working on a project where it would be quite convenient to have the input values to the function reported in any exceptions that get thrown. I'm guessing the way to do this would be to create a replacement defn which had a try catch and threw a new error with the inputs captured. Has anyone tried this, know of a better way, or a library that helps in this way? -- 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
clj-logging-config, lein2 and AOT compilation == NullPointerException
Hi all, I've been debugging an issue in my Clojure app deployed on Heroku and after some time I finally tracked it down to what appears to be an issue when AOT compiling the project while using clj-logging-config [1] It works without any issues if I let Clojure compile my namespaces on the fly. As soon as I AOT compile, I can't run my jetty server any longer. This led me to open an issue [2] with clj-logging-config where you can find some extra info on my setup. I'm posting this here in the hopes someone has been through this before and that the solution is something trivial I've overlooked. [1] https://github.com/malcolmsparks/clj-logging-config [2] https://github.com/malcolmsparks/clj-logging-config/issues/15 Thanks, Leonardo Borges www.leonardoborges.com -- 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: using take-while with pred function that has state
On Mon, Sep 3, 2012 at 1:58 PM, Stephen Compall stephen.comp...@gmail.com wrote: I would have hoped that would be guaranteed Nevertheless, by declaring pred must be free of side-effects, `take-while' is refusing to make that promise, among many others. It seems like a leap to go from pred being free of side-effects to refusing to make *that* promise. If the reason that pred must be free of side-effects that take-while is *thereby* free to call pred on the elements of coll in arbitrary order then actually only *some* side-effects need to be banned. (Maybe you want to track how many times pred has been called---that's a side effect but it shouldn't interfere with pred's being called more than strictly necessary for take-while to get the right answer, since, after all, if pred is called more than is strictly necessary, that's exactly what you wanted to know.) And in refusing to make that promise, take-while is also doing *more* than just requiring that pred be free of (some) side-effects, it's also saying that take-while *itself* (i.e., *not* 'first') reserves the right to have the side-effecty function of forcing the computation of *arbitrary* amounts of a lazy sequence. Side note: the concept of *pred*, specifically, being free of side-effects seems underdetermined. Is (fn [f] (even? (f))) free of side-effects? It is iff f is. What if I pass in, not the pure function f, but rather the impure function (memoize f)? (memoize f) isn't *visibly* side-effecty to its caller (the way some Haskell people are willing to sell their souls and say, well, you can use unsafePerformIO as long as *you* know it's safe...), but it isn't side-effect-free sensu stricto. In general, you may not assume that more elements of a lazy sequence than you need will not be computed. I exempt `reductions', `iterate', and any sequences derived from those in my own practice; you may be more or less comfortable with such exemptions. user= (first (map print [1 2 3 4])) 1234nil user= (first (map print '(1 2 3 4))) 1nil I'm aware of seq chunking; it seems tangential to the main concern here. The following two questions are distinct: - will calling first on a lazy seq cause more than just its first element to be computed? - will take-while cause more of a lazy seq to be realized than is present in its output *because it calls pred on arbitrary elements of the seq*? Of course take-while might cause more of a lazy seq to be realized than is present in its output because of seq chunking. But I'd *hope* that it wouldn't exacerbate that by reserving the right to work like, say, this, where n is the largest number of elements of a seq calling first might compute: 1. Realize the first 1000n elements of a seq, retaining them in memory. 2. Call pred on those elements in reverse order. 3. If pred was true for all of them, realize the next 1000n elements, etc., otherwise return a lazy seq of the first stretch of elements for which pred returned true. That admittedly would be insane, but if pred is free of side-effects (and computing the elements of the collection is also free of side-effects) it would be correct. -- Ben Wolfson Human kind has used its intelligence to vary the flavour of drinks, which may be sweet, aromatic, fermented or spirit-based. ... Family and social life also offer numerous other occasions to consume drinks for pleasure. [Larousse, Drink entry] -- 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: using take-while with pred function that has state
On Tue, Sep 4, 2012 at 1:24 AM, Ben Wolfson wolf...@gmail.com wrote: On Mon, Sep 3, 2012 at 1:58 PM, Stephen Compall stephen.comp...@gmail.com wrote: Of course take-while might cause more of a lazy seq to be realized than is present in its output because of seq chunking. But I'd *hope* that it wouldn't exacerbate that by reserving the right to work like, say, this, where n is the largest number of elements of a seq calling first might compute: 1. Realize the first 1000n elements of a seq, retaining them in memory. 2. Call pred on those elements in reverse order. 3. If pred was true for all of them, realize the next 1000n elements, etc., otherwise return a lazy seq of the first stretch of elements for which pred returned true. That admittedly would be insane, but if pred is free of side-effects (and computing the elements of the collection is also free of side-effects) it would be correct. It wouldn't even be all that insane if you had 1000 otherwise idle cores sitting around and an expensive enough predicate. -- 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: reporting function inputs as part of exceptions
Slingshot's throw+ generates an exception object that includes, among other things, all the locals in the context of your throw. On Monday, September 3, 2012 9:03:42 PM UTC-7, Timothy Pratley wrote: I'm working on a project where it would be quite convenient to have the input values to the function reported in any exceptions that get thrown. I'm guessing the way to do this would be to create a replacement defn which had a try catch and threw a new error with the inputs captured. Has anyone tried this, know of a better way, or a library that helps in this way? -- 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