I started playing with Clojure again. I made the following three functions:
(defn get-percentage [place total-count]
(int (Math/round (double (/ (* place 100) total-count)
(defn get-percentage-low [place total-count]
(int (Math/floor (/ (* place 100) total-count
2014-11-24 14:48 GMT+01:00 Plínio Balduino pbaldu...@gmail.com:
Because java.lang.Math#round supports only two types: float and double.
Java won't find the equivalent signature with Ratio or Number.
But ceil and floor only have double and they work. In my opinion those
should go wrong then
I've recently been serialising some data using Edn, and to date this has
caused no problems. During some tests today, I serialised a string
representing a file path that originated on a windows machine \My
Documents\somedoc.txt. Edn throws a runtime exception when reading this
back claiming:
Hi Andy,
If I stick with Edn are there any other gotchas that should be sanitised ?
The specs of String literals is a bit implicit :
https://github.com/edn-format/edn#strings refers to
https://docs.oracle.com/javase/specs/jls/se7/html/jls-3.html#jls-3.10.6 .
I think there are no ways to
Add an arity 3 version which takes a symbol and dispatches on it. You can
choose the position that you like best; to keep in line with your current
scheme:
(defn get-percentage
([place total-count] (get-percentage :normal place total-count))
([mode place total-count]
(condp = mode
Hi Cecil,
I think the issue doesn't occur for ceil and floor because there's only one
overload, so Clojure can infer which method you intended to call (since it
can convert a Ratio into a double). Because round has two overloads, which
both take a type that can be converted from Ratio (float
On 25 November 2014 at 12:23, Andy Dwelly andydwe...@gmail.com wrote:
I've recently been serialising some data using Edn, and to date this has
caused no problems. During some tests today, I serialised a string
representing a file path that originated on a windows machine \My
On Tuesday, November 25, 2014 8:54:35 AM UTC-5, Michael Griffiths wrote:
Hi Cecil,
I think the issue doesn't occur for ceil and floor because there's only
one overload, so Clojure can infer which method you intended to call (since
it can convert a Ratio into a double). Because round has
On Tuesday, November 25, 2014 8:32:14 AM UTC-5, Gary Verhaegen wrote:
Add an arity 3 version which takes a symbol and dispatches on it. You can
choose the position that you like best; to keep in line with your current
scheme:
(defn get-percentage
([place total-count] (get-percentage
Also, you can use multi-methods:
(defmulti get-percentage (fn [x mode] mode))
(defmethod get-percentage :default
[x _]
(get-percentage x :high))
(defmethod get-percentage :high
[x _]
...)
(defmethod get-percentage :low
[x _]
...)
This has the advantage to not only having a clear
While I think the latter two solutions show off Clojures ease of extensibility,
I personally believe the first technique is more appropriate for the current
wxample.
I mean, how many different ways of calculating and rounding a percentage are
there?
--
You received this message because
If you specify a main namespace to lein, it is evaluated at startup of lein
repl, and the repl starts within it. It also needs to have a -main method
by default, as that will be executed by lein run.
This might be what you want.
On Saturday, 22 November 2014, Aleksandr
I'm trying to build a string output system with functions that later have a
state passed to it, so that I can write something like (output The result
of this example is: (get :result)) and have it passed to a parsing
function that takes a state and calls the functions in the list, something
Short answer:
Use a string generator that is much more likely to have collisions, and
thus provoke your failure. Here's an example:
(def small-strings (gen/sized (fn [s] (gen/resize (min s 2) (gen/not-empty
gen/string-ascii)
Longer answer:
When using gen/bind, you create a nested shrink
2014-11-25 14:31 GMT+01:00 Gary Verhaegen gary.verhae...@gmail.com:
Add an arity 3 version which takes a symbol and dispatches on it. You can
choose the position that you like best; to keep in line with your current
scheme:
(defn get-percentage
([place total-count] (get-percentage :normal
2014-11-25 18:30 GMT+01:00 David Pidcock eraz0rh...@gmail.com:
While I think the latter two solutions show off Clojures ease of
extensibility, I personally believe the first technique is more appropriate
for the current wxample.
I mean, how many different ways of calculating and rounding a
Do you know about closures? So something like:
(defn foo [arg1 arg2]
(fn [state] (do-something-with state arg1 arg2)))
- James
On 25 November 2014 at 18:55, Isaac Karth isaacka...@gmail.com wrote:
I'm trying to build a string output system with functions that later have
a state passed to
Can you elaborate on what makes String.format not a good fit here?
On Tuesday, 25 November 2014, James Reeves ja...@booleanknot.com wrote:
Do you know about closures? So something like:
(defn foo [arg1 arg2]
(fn [state] (do-something-with state arg1 arg2)))
- James
On 25 November 2014
It is our pleasure to announce a new ring middleware for CORS support.
https://github.com/unbounce/encors
Features include:
* Add multiple CORS Policy to an app (can classify them via ring request
info)
* Preflight CORS requests are supported
* Thoroughly tested (around 276 different
String.format could work; I would prefer to have an inline syntax for the
string formatting rather than appending it at the end, but that's the major
objection. The main goal was to have the strings be easy to write and to
make it easy to have variations. I'm also trying to avoid eval-ing a
I mentioned this on r/clojure, but don't understand why you have a
map-CorsPolicy function, as it doesn't appear to serve any purpose. You
seem to be using it as a map, but in Clojure it's more idiomatic to use
maps as maps.
- James
On 25 November 2014 at 23:40, ro...@unbounce.com wrote:
It is
Thanks for both suggestions guys, and yes - I'm using prn-str - apparently
the wrong one. It's a trivial change so I will start there.
Thanks again, appreciate it.
Andy
On Tuesday, November 25, 2014 2:00:44 PM UTC, James Reeves wrote:
On 25 November 2014 at 12:23, Andy Dwelly
22 matches
Mail list logo