Re: [beginner] help understand this function

2017-03-18 Thread Walter van der Laan
The value of 'maps' can be, for example; [{:lat 1 :lng 4} {:lat 2 :lng 3}]. If you enter (min [{:lat 1 :lng 4} {:lat 2 :lng 3}]) in the repl the result will be {:lat 1 :lng 3} If you replace 'min' by its definition you get; (min [{:lat 1 :lng 4} {:lat 2 :lng 3}]) => (zipmap [:lat :lng] (

Re: recursive bindings not available in let form?

2016-12-02 Thread Walter van der Laan
AFAIK there are two options. You can add a symbol after fn: (let [fib (fn y [x] (cond (< x 2) x :else (+ (y (- x 2)) (y (- x 1)] (fib 5)) Or, as Bobby already suggested, you can use letfn: (letfn [(fib [x] (cond (<

Re: Adding JDBC drivers to Clojars

2016-09-23 Thread Walter van der Laan
There is no need to push jdbc drivers to clojars. I have never used Vertica but perhaps it helps if I show you how to add the two jdbc-drivers that I do use. Example 1; postgres The details for the postgres-driver can be found here: http://mvnrepository.com/artifact/org.postgresql/postgresql

Re: How to spec a plain map with exclusive groups of :req keys?

2016-06-15 Thread Walter van der Laan
You can wrap s/keys in s/and to add additional predicates, eg; (s/and (s/keys) #(or (::secret %) (and (::user %) (::pwd % You can also match the map with a predicate instead of s/keys, eg; #(and (map? %) (or (::secret %) (and (::user %) (::pwd % The the first option, with s/keys, will c

Re: ANN: ClojureScript 1.9.14, clojure.spec port

2016-06-01 Thread Walter van der Laan
It's like magic. I added some specs to cljc namespaces and it just works! I'm making domain specific error messages with just a few lines of code. This is a huge leap forward. Thank you, and all involved, so much. -- You received this message because you are subscribed to the Google Groups "Cl

Re: Clojure as first language

2016-02-21 Thread Walter van der Laan
Check out the presentation that Tommy Hall gave at EuroClojure: https://vimeo.com/100425264 >From slide 12 onward he describes his Clojure implementation of geomlab and how it can be used to teach children how to program -- You received this message because you are subscribed to the Google Gro

Re: Core functions for searching lists of values

2016-01-28 Thread Walter van der Laan
You could use 'select-keys' to filter the hashmaps; (defn submap? [m1 m2] (= m1 (select-keys m2 (keys m1 (filter (partial submap? {:quad-col 0 :quad-row 0}) test-galaxy) (filter (partial submap? {:sec-row 4 :sec-col 4}) test-galaxy) (filter (partial submap? {:type :star}) test-galaxy) --

Re: Suggestions on staying up to date with Clojure

2015-09-29 Thread Walter van der Laan
Planet Clojure: http://planet.clojure.in/ On Tuesday, September 29, 2015 at 2:04:22 AM UTC+2, Jonathon McKitrick wrote: > > What list of blogs, websites, and/or feeds would you suggest for someone > who does not work with Clojure full time that will maximize exposure to > advancements in the la

Re: How do I access components of a system map

2015-03-15 Thread Walter van der Laan
Hi, This is an example from http://github.com/stuartsierra/component (defn get-user [database username] (execute-query (:connection database) "SELECT * FROM users WHERE username = ?" username)) Here 'database' is a component which is passed to 'get-user' as an argument. The component

Re: Registering commands in a command language

2014-05-29 Thread Walter van der Laan
You can do this using multimethods. defmulti and defmethod will allow you to do everything you ask for apart from adding a doc-string to each command. Have a look at: http://clojuredocs.org/clojure_core/clojure.core/defmulti On Thursday, May 29, 2014 3:05:56 AM UTC+2, Will Duquette wrote: > > I

Re: Do not understand the -> macro here

2014-04-30 Thread Walter van der Laan
You have to replace the underscore with a function. The value of (= (_ [1 2 3 4 5]) 5) must be true. So the value of (_ [1 2 3 4 5]) must be 5. So the function you are looking for will have to return the last element of the array. On Wednesday, April 30, 2014 5:28:26 PM UTC+2, Roelof Wobben wro

Re: Light table

2014-04-17 Thread Walter van der Laan
I recently moved from Emacs to Light Table for Clojurescript and I like working with it. I created a tutorial that outlines my Clojurescript workflow using Light Table: github.com/wvdlaan/todomvc For my work on the JVM I still use Emacs because old habits die hard. But I expect to move to Light

Re: How to do this correct in Clojure

2014-04-08 Thread Walter van der Laan
This will only give you one nil: (doseq [i (range 1 1)] (let [val (Math/sqrt i) diff (Math/abs (- (Math/pow val 2) (* val val)))] (when (> diff 1.1755025E-38) (println (format "Different for %d (%e)" i diff) On Tuesday, April 8, 2014 9:28:44 PM UTC+2, Cecil Westerhof wr

Re: Clojure 1.6.0-RC1 - LAST CHANCE, PLEASE TEST

2014-03-19 Thread Walter van der Laan
I moved to 1.6 two weeks ago for development and have had no problem. I had to change some tests because they depended on the order of elements if you seq a hashmap. On Tuesday, March 18, 2014 3:21:22 PM UTC+1, Alex Miller wrote: > > Hello all, > > We would love to release Clojure 1.6.0 final s

Re: XOR two arrays into a third on Clojure

2014-03-13 Thread Walter van der Laan
Try this: (defn inplace-xor [^bytes a ^bytes b ^bytes out] (let [ln (count a)] (loop [x 0] (if (< x ln) (do (aset-byte out x (bit-xor (aget a x) (aget b x))) (recur (inc x))) On Thursday, March 13, 2014 6:26:33 AM UTC+1, Ignacio Corderi wrote: > > Hey g

Re: Getting started - overcoming my first obstacles

2014-03-07 Thread Walter van der Laan
Hi Florian, To unpack your edn-acls I entered these expressions in a repl. Each expression goes one step deeper, so it is only the last expression that you need to unpack the acls. The other steps are included to illustrate the process. (for [acl edn-acls] {:acl acl}) (for [acl edn-acls

Re: Is Clojure right for me?

2013-12-27 Thread Walter van der Laan
First, regarding OO. When programming Clojure I never think about adding objects to the application, I think "how can I extend the language so it is better tailored to my application domain?". And for a lot of domains good libraries are already available. So, for the example that you gave I woul

Re: map> vs map< in core.async

2013-12-13 Thread Walter van der Laan
Please try these exercises if you want to know what a channel is: https://github.com/halgari/clojure-conj-2013-core.async-examples/blob/master/src/clojure_conj_talk/core.clj Op vrijdag 13 december 2013 11:01:57 UTC+1 schreef Joachim De Beule: > > Thanks, that indeed did the trick. > > More genera

Re: [ANN] A post on CLJS DOM manipulation libraries

2013-12-12 Thread Walter van der Laan
Hi Dave, Thanks for the overview. I found one error. When running the Google Clojure example on its own this expression gives an error: (first (query "#menu ul")) This is because 'first' depends on the protocols implemented in domina.events. This expression will fix the error: (aget (query "#m

Re: atom and vector .. remove prolbem

2013-12-09 Thread Walter van der Laan
Hi, You could try to do it like this... Use a hashmap instead of a vector in the atom: (def room-list (atom {})) Insert rooms using a hashmap for the user-id's: (swap! room-list assoc "67890" {:user-list {"id-3" {:name "name-3"}}}) You can now find a user in a room like this: (get-in @room-list

Re: Reactive Patterns with Atoms - am I using too much state?

2013-11-30 Thread Walter van der Laan
An alternative that I'm looking at is pedestal 0.3.0. It sort of works like this... ;; Create a transform-channel and transform-function to handle all changes to 'state' (defn init [] (let [c (chan)] (go (while true (when-let [[path v] (! transform-chan [path v])) ;; Change the

Re: help choosing dev environment for clojure

2012-11-27 Thread Walter van der Laan
It is possible to execute forms in a debugging context but AFAIK there is no easy setup that allows you to step through the execution. The easiest way to evaluate forms in context is to setup emacs as described here http://clojure-doc.org/articles/tutorials/emacs.html. This will allow you to se

Re: DAG (Direct Acyclic Graph) and Bayesian Network help

2012-07-14 Thread Walter van der Laan
Chas Emerick did a presentation on this: http://blip.tv/clojure/chas-emerick-modeling-the-world-probabilistically-using-bayesian-networks-in-clojure-5961126 But AFAIK the "raposo" library has not been published yet. On Saturday, July 14, 2012 4:20:17 PM UTC+2, Simone Mosciatti wrote: > > Hi guys

Re: Term rewriting systems implemented in Clojure

2012-04-21 Thread Walter van der Laan
A few years back I copied a small rewrite system from Scheme to Clojure while watching the SICP video lectures. It's a nice use case for a rewrite system. You can enter a mathematical function and the system will rewrite the function to its derivative. > > Perhaps this code plus the videos will

Re: Newbie question about rebinding local variables

2012-04-20 Thread Walter van der Laan
You can save state in an atom like this: (def state (atom (new-game))) ; initial state (swap! state move \x [1 1]) ; make a move -- 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 po

Re: Newbie question about rebinding local variables

2012-04-20 Thread Walter van der Laan
You could start with pure functions to handle the game logic, e.g.: (defn new-game [] [[\- \- \-] [\- \- \-] [\- \- \-]]) (defn print-game [game] (doseq [row game] (println (apply str row (defn move [game mark pos] (assoc-in game pos mark)) (print-game (new-game)) (print-gam

Re: How to add a new type of collection?

2012-01-27 Thread Walter van der Laan
Are you somehow required to use the Java library? Otherwise you could also use a Clojure map as a sparse matrix. This will be much easier to implement. Walter -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to cloju

Re: [lein] Depending on tools.jar

2011-11-28 Thread Walter van der Laan
You can add something like this to project.clj: :resources-path "/usr/lib/jvm/java-6-sun/lib/tools.jar" Walter -- 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 memb

Re: Map eats println output?

2011-10-17 Thread Walter van der Laan
That's a big relieve. Thanks for the answer! -- 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 un

Map eats println output?

2011-10-17 Thread Walter van der Laan
Hi, When I run this expression: (map (fn [x] (println x) x) (range 5)) I expect to get (0 1 2 3 4) but instead I get (0 1 2 3 4 0 1 2 3 4) It seems like the println output is included in the result list. Am I missing something? -- You received this message because you are subscribed to the G

Re: Sum on a list of maps

2011-10-14 Thread Walter van der Laan
You could first turn the Values from String into Double like this: (defn step1 [coll] (map (fn [m] (assoc m "Value" (Double/parseDouble (m "Value" coll)) Next, you can use reduce to calculate the sum per Value: (defn step2 [coll] (reduce (fn [res m] (let [k (m "

Re: I/O

2011-08-25 Thread Walter van der Laan
This gives several I/O examples: http://nakkaya.com/2010/06/15/clojure-io-cookbook/ -- 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 b

Re: finding a key which does not exist in the map

2011-05-26 Thread Walter van der Laan
You could use this: (defn non-existing-key [mp] (inc (reduce max (keys mp For example: (non-existing-key {1 "a" 2 "b"}) => 3 -- 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 p

Re: Screencast of the Emacs front end to the Clojure Debugging Toolkit:

2010-10-12 Thread Walter van der Laan
t; and see if that gives you any hints.  if not, send me the output of > that command, and the full path and namespace of one of your source > files, I'll see if I can see anything you are missing. > > g > > On Oct 5, 6:40 am, Walter van der Laan > wrote: > > > &g

Re: Screencast of the Emacs front end to the Clojure Debugging Toolkit:

2010-10-05 Thread Walter van der Laan
Thanks George, this is great. I tried the screencast instructions and it all works, but I can't get it to work with my own source. I tried several settings for (set-source-path) but I must be doing something wrong. Can you perhaps give an example? On Oct 1, 10:32 pm, George Jahad wrote: > For you

Re: Documentation and examples (and where is the documentation on reduce)?

2010-07-02 Thread Walter van der Laan
You can find a lot of examples using http://github.com/defn/walton For example you can point your browser at http://getclojure.org:8080/examples/reduce for reduce examples. On Jun 30, 8:08 am, michele wrote: > Mother's invention is a lazy necessity, I think. > > On Jun 29, 9:46 pm, Meikel Brand