Taken from the spec documentation:
And additional args that control gen
> :gen-max - the maximum coll size to generate (default 20)
Q: Any plans to make the default value of :gen-max a dynamic var?
--
You received this message because you are subscribed to the Google
Groups "Clojur
eld posted this code to track memory use, so I have
> been using this to keep track of my app's memory usage:
>
> (defn- memory-bean
> "Return the MemoryMXBean."
> []
> (java.lang.management.ManagementFactory/getMemoryMXBean))
>
> (defn- heap-usage
> "
memory usage."
[^java.lang.management.MemoryMXBean bean]
(.getHeapMemoryUsage bean))
(defn- heap-used-max
"Given heap memory usage, return a pair of used/max values."
[^java.lang.management.MemoryUsage usage]
[(.getUsed usage) (.getMax usage)])
(defn memory-usage
&qu
Arguments to *max* should be supplied explicitly. If you want to use a
sequence you should use *apply* with *max*:
(apply max [1 2 0.5])
Regars,
Juan
On Wednesday, December 12, 2012 6:12:20 PM UTC-3, HamsterofDeath wrote:
>
> maybe i am blind, but why does max return the complete la
(doc max)
user=> (doc max)
-
clojure.core/max
([x] [x y] [x y & more])
Returns the greatest of the nums.
nil
max doesn't take a sequence, it takes one or more values and finds the max
of them. So use (apply max coll) to get what you want.
Timothy
On Wed,
maybe i am blind, but why does max return the complete lazy seq here
instead of the maximum number? if i just print as-products, i get a list
of numbers. (count solution) tells me there are 1000+
and yet max gives me the complete list?
(ns euler.Problem8)
(def digits
(def order-list [Tier5 Tier10 Tier20 Tier30 Tier40 Tier50])
(def rank (into {} (map-indexed (fn [i x] [x i]) orders)))
(apply max-key rank [Tier20 Tier10 Tier30])
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, sen
I need to apply a "max" operator to a list like this:
[Tier20 Tier10 Tier30]
It should give me "Tier30" as the max. My predefined order list (from low
to high) is:
[Tier5 Tier10 Tier20 Tier30 Tier40 Tier50]
What's the best way to achieve this in clojure?
--
You rece
Hi,
not sure if this is considered too frivolous somehow but I've thought many
times how nice it would be to modify a fileseq call by using a min-depth or
max-depth modifier rather constructing a filter.
Depth would refer to the levels of the underlying treeseq returned.
So min-depth=
> Another version I believe is more evident utilizes reductions to build a
> list over all the *max-ending-here*s. You can then just pick the maximal
> value in that list, giving you the maximal subarray:
>
> (defn max-subarray [A]
> (let [pos+ (fn [sum x] (if (neg? sum) x (
>
> Is there a more concise implementation, perhaps using `filter` or merely
> by making the `reduce` version more "idiomatic" somehow?
>
Another version I believe is more evident utilizes reductions to build a
list over all the *max-ending-here*s. You can then just pick
I've implemented the following two versions of the "Max Sub-Array" problem
(http://en.wikipedia.org/wiki/Maximum_subarray_problem) in Clojure, using
the Kadane algorithm.
First with `loop` / `recur`
(defn max-sub-array [A]
(loop [x (first A)
a (rest A)
See http://dev.clojure.org/jira/browse/CLJ-738 for clarity on this issue.
--
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
On Tue, Nov 1, 2011 at 21:00, Michael wrote:
>
>
> On Nov 1, 12:14 pm, Ben Smith-Mannschott
> wrote:
>> 3. Define that min and max will ignore any NaN arguments.
>
> What is:
>
> (min NaN NaN)
>
> in this situation; ()?
The part of the message you didn
On Nov 1, 12:14 pm, Ben Smith-Mannschott
wrote:
> 3. Define that min and max will ignore any NaN arguments.
What is:
(min NaN NaN)
in this situation; ()?
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group,
On Tue, Nov 1, 2011 at 12:14 PM, Ben Smith-Mannschott wrote:
>
> 2 Make NaN contagious
> -
>
> Define min and max to return NaN if and only if at least one of their
> arguments is NaN. This seems most in keeping with the (admittedly
> perverse) behavio
I've opened http://dev.clojure.org/jira/browse/CLJ-868
"The min and max functions in clojure.core behave unpredictably when
one or more of their arguments is Float/NaN or Double/NaN. This is
because the current implementation assumes that > provides a total
ordering, but this is not
On Oct 30, 4:02 am, bOR_ wrote:
> Hi all,
>
> Ran into something unexpected with "max".
>
> user> (sd-age-female 13)
>
> [10 NaN 0.746555245613119]
>
Why does Clojure have it's own naive implementation of max for doubles
instead of using max from java.lang.Math which has necessary checks for
NaN and the positive and negative zeros?
On Sun, 30 Oct 2011 15:36:23 +0100
Ben Smith-Mannschott wrote:
> On Sun, Oct 30, 2011 at 10:02, bOR
On Sun, Oct 30, 2011 at 10:02, bOR_ wrote:
> Hi all,
> Ran into something unexpected with "max".
> user> (sd-age-female 13)
>
>
> [10 NaN 0.746555245613119]
>
>
> user> (apply max (sd-age-female 13))
>
> 0.746555245613119
TL;DR: Don
Hi all,
Ran into something unexpected with "max".
user> (sd-age-female 13)
[10 NaN 0.74
On Fri, Nov 19, 2010 at 8:52 PM, Bob Shock wrote:
> I had a bug in my code where I meant to type:
>
> (get map key)
>
> and instead typed:
>
> (get max key)
>
> It seems that any function name I put in for "max" always returns nil.
>
> user=> (get
On Fri, 19 Nov 2010 17:52:03 -0800 (PST)
Bob Shock wrote:
> I had a bug in my code where I meant to type:
>
> (get map key)
>
> and instead typed:
>
> (get max key)
>
> It seems that any function name I put in for "max" always returns nil.
>
> u
I had a bug in my code where I meant to type:
(get map key)
and instead typed:
(get max key)
It seems that any function name I put in for "max" always returns nil.
user=> (get max 3)
nil
user=> (get min 3)
nil
user=> (get maxx 3)
java.lang.Exception: Unable to resolve s
>
> You should be able to use (apply max-key f someseq); apply takes a variable
> number of args, and only the last is expanded.
>
Thanks, thought there would be something like this!
--
You received this message because you are subscribed to the Google
Groups "Clojure"
On 15 November 2010 14:17, Tom Hall wrote:
> Hi,
>
> I think a better usage for max-key would be
> (max-key f someseq)
> rather than passing the values as args.
>
> I used
> (defn max-key-seq [f someseq]
> (apply max-key (into [f] someseq)))
> to make it do what
Hi,
I think a better usage for max-key would be
(max-key f someseq)
rather than passing the values as args.
I used
(defn max-key-seq [f someseq]
(apply max-key (into [f] someseq)))
to make it do what I wanted
Is there a better way?
Cheers,
Tom
--
You received this message because you are
On Fri, 30 Jul 2010 16:03:17 +0200, Base wrote:
Hi All
I have a vector in the following format:
[
["M" "3.4" "5.6"] ["L" "4.2" "6.6"] ["L" "4.9" "7.9"] ["L" "1.1"
"2.4
quot;4.2" "6.6"] ["L" "4.9" "7.9"] ["L" "1.1"
> > "2.4"]["L" "5.4" "4.5"]
> > ]
>
> > I would like to create a vector that contains the max values of each
> > of the
On 30 Jul 2010, at 15:03, Base wrote:
> Hi All
>
> I have a vector in the following format:
>
> [
>["M" "3.4" "5.6"] ["L" "4.2" "6.6"] ["L" "4.9" "7.9"] ["L" "1.1&q
Hi All
I have a vector in the following format:
[
["M" "3.4" "5.6"] ["L" "4.2" "6.6"] ["L" "4.9" "7.9"] ["L" "1.1"
"2.4"]["L" "5.4" "4.5"]
]
> Given that max only works on numbers, then why doesn't (max []) throw
> the same exception as (max [] [])? Or, for that matter, (max \a) throw
> the same exception as (max \a \b \c)?
Clojure tends not to guarantee any particular behavior for invalid
inputs. It might return a
On Fri, 9 Jul 2010 13:57:05 -0400
Stuart Halloway wrote:
> Once you walk down the path of "What should (max) return?" I think you won't
> want a default behavior.
>
> Stu
>
> P.S. Agreed that (max []) is a bad example.
Given that max only works on numbers, th
Once you walk down the path of "What should (max) return?" I think you won't
want a default behavior.
Stu
P.S. Agreed that (max []) is a bad example.
> I noticed that http://clojure-examples.appspot.com/clojure.core/max has both
> (apply max [1 2 3 4]) -> 4 and (max
I noticed that http://clojure-examples.appspot.com/clojure.core/max has both
(apply max [1 2 3 4]) -> 4 and (max []) -> [] (which I think is a poor
example).
However, when attempting to add another example for (apply max []) which I
expected to return nil, that instead it throws an excepti
Get Nike Shoes at Super Cheap Prices
Discount Nike air jordans (www.stylishdudes.com)
Discount Nike Air Max 90 Sneakers (www.stylishdudes.com)
Discount Nike Air Max 91 Supplier (www.stylishdudes.com)
Discount Nike Air Max 95 Shoes Supplier (www.stylishdudes.com)
Discount Nike Air Max 97
ompare-fn %1 %2)) %1 %2) args))
(defmacro generic-max [a b]
(if (or (and (instance? Number a)
(instance? Number b))
(and (= (:tag (meta a)) 'int)
(= (:tag (meta b)) 'int)))
(do (println "Using max")
`(max ~a ~b))
(do (p
er criteria)?
A macro gets its arguments unevaluated (necessarily, being called at
compile time). I don't see how it could know their types. Given
something like
(max a b)
how could you figure out the types of the values that will be bound
to a and b when the macro-gen
the type hint of its parameters (or some
other criteria)?
So a macro could expand to a call to some optimized version for
numeric types (max) if possible, but otherwise it would expand to a
version that uses Comparable or compare or something generic. Instead
of having to add this optimization directly
On Tue, Nov 4, 2008 at 10:00 AM, Christian Vest Hansen
<[EMAIL PROTECTED]> wrote:
>
> On Tue, Nov 4, 2008 at 3:12 PM, Rich Hickey <[EMAIL PROTECTED]> wrote:
>> On Nov 4, 9:00 am, "Christian Vest Hansen" <[EMAIL PROTECTED]>
>> wrote:
>>> "Generally" by custom but not required by contract of the Com
On Tue, Nov 4, 2008 at 3:12 PM, Rich Hickey <[EMAIL PROTECTED]> wrote:
> On Nov 4, 9:00 am, "Christian Vest Hansen" <[EMAIL PROTECTED]>
> wrote:
>> "Generally" by custom but not required by contract of the Comparable
>> interface. And those are all Numbers, right?
>>
>> Comparable imposes natural
and Date both
> > > implement Comparable. Comparable is supposed to impose a total
> > > ordering on a set, so in a finite set of objects of the same type, the
> > > max is always well defined.
> >
> > +1 on (min) and (max) operating on Comparables.
>
of the Comparable interface.
>
> >> > Ah, yes, this is true, I hadn't realized that String and Date both
> >> > implement Comparable. Comparable is supposed to impose a total
> >> > ordering on a set, so in a finite set of objects of the same type, the
> >
On Tue, Nov 4, 2008 at 7:45 AM, Rich Hickey <[EMAIL PROTECTED]> wrote:
> Hmm...
>
> Do you want:
>
> (max 1 2.1 4/5)
>
> to work?
>
> If so, you can't base it on Comparable, which generally only supports
> homogenous types.
>
> max, like >, is a
e both
>> > implement Comparable. Comparable is supposed to impose a total
>> > ordering on a set, so in a finite set of objects of the same type, the
>> > max is always well defined.
>>
>> +1 on (min) and (max) operating on Comparables.
>>
>
> H
ow objects of a type should be sorted is
> >> the point of the Comparable interface.
>
> > Ah, yes, this is true, I hadn't realized that String and Date both
> > implement Comparable. Comparable is supposed to impose a total
> > ordering on a set, so in a finite set
ction system based on the Collections interfaces, and
have max and min functions that only operate on numbers. It would seem
we should embrace the Comparable and Comparator interfaces as well.
Paul
On Tue, Nov 4, 2008 at 12:23 AM, Mark H. <[EMAIL PROTECTED]> wrote:
>
> On Nov 3
yes, this is true, I hadn't realized that String and Date both
> implement Comparable. Comparable is supposed to impose a total
> ordering on a set, so in a finite set of objects of the same type, the
> max is always well defined.
+1 on (min) and (max) operating on Comparables.
--
V
le is supposed to impose a total
ordering on a set, so in a finite set of objects of the same type, the
max is always well defined.
If I wanted the max of a set of strings representing dates, however,
I'd still comment the code to indicate what "max" means. I'd also
consider repl
On Nov 3, 2008, at 8:35 PM, Mark H. wrote:
>
> On Nov 3, 5:39 pm, "Paul Stadig" <[EMAIL PROTECTED]> wrote:
>> Could/Should the max function be modified to work against the
>> Comparable interface instead of expecting its arguments to be
>> numbers?
>
> The semantics of "max string" are unclear enough that it would be
> better to write out the operation explicitly so that all readers of
> the code know what you mean.
Agreed. For example, the semantics of "max string"
On Nov 3, 2008, at 9:35 PM, Mark H. wrote:
>
> On Nov 3, 5:39 pm, "Paul Stadig" <[EMAIL PROTECTED]> wrote:
>> Could/Should the max function be modified to work against the
>> Comparable interface instead of expecting its arguments to be
>> numbers?
>
On Nov 3, 5:39 pm, "Paul Stadig" <[EMAIL PROTECTED]> wrote:
> Could/Should the max function be modified to work against the
> Comparable interface instead of expecting its arguments to be numbers?
>
> I'm working with a sequence of strings that are dates in the
Could/Should the max function be modified to work against the
Comparable interface instead of expecting its arguments to be numbers?
I'm working with a sequence of strings that are dates in the
"-mm-dd" format, and I want to find the max. Calling max gives an
exception about
On 16 Okt., 22:01, "Stephen C. Gilardi" <[EMAIL PROTECTED]> wrote:
> #(identity %) is more compactly written as: identity.
>
> This works:
>
> user=> (apply max (filter identity '(1 2 nil 4)))
> 4
>
> In this case, number? i
On Oct 16, 1:45 pm, Stuart Halloway <[EMAIL PROTECTED]> wrote:
> Just to add to the confusion: I want compact to remove nil and
> false. :-)
They'll revoke your ruby license :)
irb(main):031:0> [1,2,3,4,false,nil,5,6].compact
=> [1, 2, 3, 4, false, 5, 6]
martin
--~--~-~--~~---
While were on the subject, wouldn't it make sense to rename max-key to
max-fn or something? I gather that it is called max-key because you can pass
a keyword as a way to index into a map, but since keywords implement IFn and
in this case they are actually being used as a function, and yo
Thanks, Rich. That's easier on the eyes.
Also, that set trick is pretty cool!
Paul
On Thu, Oct 16, 2008 at 5:20 PM, Rich Hickey <[EMAIL PROTECTED]> wrote:
> I've been meaning to add remove for a while. It's certainly more
> general than compact, and (filter (complement ...)) gets cumbersome
>
boolean values, but want to remove the nils (perhaps
> they're a sentinel for some other meaning).
>
> user> (compact [true false nil true true])
> (true false true true)
>
> I think it makes sense to have the number functions like max and min throw a
> NPE, and since fal
t;
> user> (compact [true false nil true true])
> (true false true true)
>
> I think it makes sense to have the number functions like max and min throw
> a NPE, and since false and nil are distinct, I think it makes sense to have
> a compact that removes nil, but leaves false.
>
true])
(true false true true)
I think it makes sense to have the number functions like max and min throw a
NPE, and since false and nil are distinct, I think it makes sense to have a
compact that removes nil, but leaves false.
Paul
On Thu, Oct 16, 2008 at 4:45 PM, Stuart Halloway
<[EMAIL PROTECTE
Just to add to the confusion: I want compact to remove nil and
false. :-)
> Perhaps another nudge for compact is that it's not as simple as
> (filter identity coll), to wit:
>
> user> (filter identity [1 2 nil false 4])
> (1 2 4)
>
> user> (filter #(not (nil? %)) [1 2 nil false 4])
> (1 2 fal
idiom will occur everywhere. It certainly does in the other
> languages I use.
>
> (2) Clojure needs compact *more* than these other languages, if
> functions like max are going to fall out with NPE. I like the idea of
> functions not being generally nil-safe where there is no obvious
> in
I am going to vote twice on this one. +2 for adding compact to
Clojure. :-)
(1) This idiom will occur everywhere. It certainly does in the other
languages I use.
(2) Clojure needs compact *more* than these other languages, if
functions like max are going to fall out with NPE. I like the
rks, but would it be
> possible
> > to add a 'squeeze or 'compact function so we could do something like
> (apply
> > max (compact coll))?
>
> I like how few functions clojure has built in (compared to say common
> lisp). It think this is partly achieved throug
On Thu, Oct 16, 2008 at 3:26 PM, Paul Stadig <[EMAIL PROTECTED]> wrote:
>
> Something like (filter #(identity %) coll) works, but would it be possible
> to add a 'squeeze or 'compact function so we could do something like (apply
> max (compact coll))?
I like how few
le to add a 'squeeze or 'compact function so we could do
> something like (apply max (compact coll))?
#(identity %) is more compactly written as: identity.
This works:
user=> (apply max (filter identity '(1 2 nil 4)))
4
In this case, number? is also a go
t be
> possible to add a 'squeeze or 'compact function so we could do
> something like (apply max (compact coll))?
>
>
> Paul
>
> On Thu, Oct 16, 2008 at 3:22 PM, Stuart Halloway <[EMAIL PROTECTED]
> > wrote:
>
> Hi Paul,
>
> I think the current b
OK. Then next question.
Is there some reason we don't have a "remove the nils" function in the
'clojure namespace?
Something like (filter #(identity %) coll) works, but would it be possible
to add a 'squeeze or 'compact function so we could do something like (app
Hi Paul,
I think the current behavior is reasonable. It is consistent across
all the numeric functions. And if the nil got into max by being a
sentinel value from some other function, I don't think there is a
right way to interpret it.
Stuart
> Currently, "(max 1 2 nil 4)&
Currently, "(max 1 2 nil 4)" throws a NPE. Would it be reasonable to expect
it to return "4"? Or is it right that it throws an NPE?
Paul
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"C
71 matches
Mail list logo