Re: unexpected behavior of clojure.core/empty

2014-07-18 Thread Brian Craft
hm, looks even more broken in the context of these examples.

On Friday, July 18, 2014 5:04:34 AM UTC-7, Mike Fikes wrote:
>
> My guess: Perhaps this is a bug, or alternatively, a known issue that 
> won't be addressed because to do so would be a breaking change.
>
> There is an old demo of Clojure given by Rich where MapEntry's were 
> printed using some sort of un-readable notation #<:foo 5>. But clearly 
> MapEntry's have been revised to act a lot like 2-element vectors.
>
> user=> (rseq (first (mapv identity {:foo 5})))
>
> (5 :foo)
>
> user=> (conj (first (mapv identity {:foo 5})) :x)
>
> [:foo 5 :x]
>
> user=> (assoc (first (mapv identity {:foo 5})) 1 7)
>
> [:foo 7]
>
> user=> (subvec (first (mapv identity {:foo 5})) 0 1)
>
> [:foo]
>
>
> FWIW, ClojureScript behaves in your expected way:
>
>
> (empty (first (mapv identity {:foo 5})))
>
> => []
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Rxtx Serial Dependency issues with ARM processor

2014-07-18 Thread Jozef Wagner
Hi,

AFAIK RXTX is obsolete, you may have more luck with JSSC [1]. Including it
in your Clojure project is easy, just add [org.scream3r/jssc "2.8.0"]

While it's not perfect, its pretty solid from my experience. There is a
support for ARM, but I've been using it only in x86-64 Linux.

[1] https://github.com/scream3r/java-simple-serial-connector

JW


On Fri, Jul 18, 2014 at 6:22 PM, Samuel Nelson  wrote:

> We are trying to include a serial port handler package in our project.
>
> We tried to use the rxtx22 1.0.6 clojar... this works on laptops but not
> on the smaller computer with an ARM processor.
>
> we tried following the instructions here:  (except we are using the
> localrepo plugin for lein to manage the project.clj dependency)
> http://nakkaya.com/2010/04/05/managing-native-dependencies-with-leiningen/
>
> Does anyone know how we can include a rxtx project to handle the ARM's
> serial ports.?
>
> This information is intended solely for the use of the individual to whom it 
> is addressed.
> Any review, disclosure, copying, distribution or use of this e-mail 
> communication by
> others is strictly prohibited.  If you are  not the intended recipient, 
> please notify us
> immediately by returning  this message to the sender and delete all copies.
>
>  --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Rxtx Serial Dependency issues with ARM processor

2014-07-18 Thread Samuel Nelson
We are trying to include a serial port handler package in our project.

We tried to use the rxtx22 1.0.6 clojar... this works on laptops but not on 
the smaller computer with an ARM processor.

we tried following the instructions here:  (except we are using the 
localrepo plugin for lein to manage the project.clj dependency)
http://nakkaya.com/2010/04/05/managing-native-dependencies-with-leiningen/

Does anyone know how we can include a rxtx project to handle the ARM's 
serial ports.?

-- 


This information is intended solely for the use of the individual to whom it is 
addressed. 
Any review, disclosure, copying, distribution or use of this e-mail 
communication by 
others is strictly prohibited.  If you are  not the intended recipient, please 
notify us 
immediately by returning  this message to the sender and delete all copies.

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Calculating the number of timestamps logged within a specific time period

2014-07-18 Thread Mike Fikes
You could use frequencies:

user=> (frequencies (map #(quot % 1000) epochs))

{1405060202 1, 1405060201 8, 1405060200 1, 1405060205 1}

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Calculating the number of timestamps logged within a specific time period

2014-07-18 Thread John Gabriele
On Thursday, July 17, 2014 8:49:12 AM UTC-4, empt...@gmail.com wrote:
>
> Hi, 
>
> I have a list of epoch times which map to HTTP requests. 
>
> '(1405060202611
> 1405060201157
> 1405060201361
> 1405060201261
> 1405060200391
> 1405060201458
> 1405060201705
> 1405060201058
> 1405060205062
> 1405060201558
> 1405060201761
> )
>
> I am trying to find out how many HTTP requests I have in a specified time 
> period, so I can graph requests per second.
>
>  
Hi Aidy,

It sounds like you're looking to create a histogram.

There are probably a number of libraries around to do that, but here's 
something I whipped up:

~~~clojure
#!/usr/bin/env lein-exec

(def min-val 0)
(def max-val 100)

(def raw-data (sort (for [i (range 20)]
  (+ (rand (- max-val min-val))
 min-val

(println "raw data:" raw-data)
(newline)

(def interval-size 10)
;; e.g.: ((0 10) (10 20) (20 30) ... (90 100))
(def intervals (partition 2
  1
  (range min-val
 (+ max-val interval-size)
 interval-size)))

(defn interval-for
  "Finds you which interval `x` lands in."
  [x]
  (first (drop-while (fn [i] (not (and (>= x (first i))
   (<  x (second i)
 intervals)))


(let [histo-data (loop [accum (zipmap (map vec intervals)
  (repeat []))
d raw-data]
   (if (empty? d)
 accum
 (recur (update-in accum
   [(interval-for (first d))]
   conj
   (first d))
(rest d]
  (doseq [d (sort histo-data)]
(println d)))
~~~

Hm... my crystal ball tells me that in few minutes someone will point out 
how I can replace that `loop` with a `reduce`...

-- 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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: unexpected behavior of clojure.core/empty

2014-07-18 Thread Neel Upadhyaya
While MapEntry is displayed as a vector it isn't actually a collection 
(which is a mistake I sometimes make also), so empty behaves as expected.

On Friday, 18 July 2014 10:45:19 UTC+1, Brian Craft wrote:
>
> => (empty [:foo 5])
> []
> => (first (mapv identity {:foo 5}))
> [:foo 5]
> => (empty (first (mapv identity {:foo 5})))
> nil
>
> What just happened there? Is this expected? In the second and third cases 
> the type of the vector is clojure.lang.MapEntry, which I expect is the root 
> of the behavior, but this seems very inconsistent. Is there a way to get 
> the behavior one would expect? Should clojure.core/empty be avoided?
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: unexpected behavior of clojure.core/empty

2014-07-18 Thread Mike Fikes
My guess: Perhaps this is a bug, or alternatively, a known issue that won't 
be addressed because to do so would be a breaking change.

There is an old demo of Clojure given by Rich where MapEntry's were printed 
using some sort of un-readable notation #<:foo 5>. But clearly MapEntry's 
have been revised to act a lot like 2-element vectors.

user=> (rseq (first (mapv identity {:foo 5})))

(5 :foo)

user=> (conj (first (mapv identity {:foo 5})) :x)

[:foo 5 :x]

user=> (assoc (first (mapv identity {:foo 5})) 1 7)

[:foo 7]

user=> (subvec (first (mapv identity {:foo 5})) 0 1)

[:foo]


FWIW, ClojureScript behaves in your expected way:


(empty (first (mapv identity {:foo 5})))

=> []

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: unexpected behavior of clojure.core/empty

2014-07-18 Thread Bob Hutchison

On Jul 18, 2014, at 5:45 AM, Brian Craft  wrote:

> => (empty [:foo 5])
> []
> => (first (mapv identity {:foo 5}))
> [:foo 5]
> => (empty (first (mapv identity {:foo 5})))
> nil

=> (class (first (mapv identity {:foo 5})))
clojure.lang.MapEntry
=> (class (first (mapv (fn [[k v]] [k v]) {:foo 5})))
clojure.lang.PersistentVector
=> (empty (first (mapv (fn [[k v]] [k v]) {:foo 5})))
[]

by mapping identity over the map you're returning a vector of MapEntries (which 
print/deconstruct like a two element array).

Cheers,
Bob

> 
> What just happened there? Is this expected? In the second and third cases the 
> type of the vector is clojure.lang.MapEntry, which I expect is the root of 
> the behavior, but this seems very inconsistent. Is there a way to get the 
> behavior one would expect? Should clojure.core/empty be avoided?
> 
> -- 
> 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 unsubscribe from this group and stop receiving emails from it, send an 
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


unexpected behavior of clojure.core/empty

2014-07-18 Thread Brian Craft
=> (empty [:foo 5])
[]
=> (first (mapv identity {:foo 5}))
[:foo 5]
=> (empty (first (mapv identity {:foo 5})))
nil

What just happened there? Is this expected? In the second and third cases 
the type of the vector is clojure.lang.MapEntry, which I expect is the root 
of the behavior, but this seems very inconsistent. Is there a way to get 
the behavior one would expect? Should clojure.core/empty be avoided?

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Critiques of "my-flatten" which uses CPS

2014-07-18 Thread Mark Phillips
Thanks - useful idioms to know about!

On Friday, 18 July 2014 16:18:33 UTC+9:30, puzzler wrote:
>
> Yeah, you've answered your own question.  In practice, I doubt the 
> difference is measurable.
>
> Another common idiom you see in Clojure code is:
> (defn f [xs]
>   (if-let [s (seq xs)]
> ...do something with (first s) and (f (rest s))...
> ...base case...))
>
> This ensures that you seq-ify the input (rather than assuming it has been 
> seq'ed before passed in), gives you the fast test against nil, and uses 
> rest rather than next because next would have the effect of causing an 
> extra unnecessary call to seq.
>
> In a loop-recur situation, it is more common to do the seq once in the 
> initialization of the loop and then use next which calls seq:
>
> (defn f [xs]
>   (loop [s (seq xs)]
> (if s
>... (recur (next s))...
>... base case ...)))
>
>
> Out of habit, I prefer to see the base case first so I don't usually do 
> either of these, but these two patterns are a very popular style, and very 
> fast execution.  If you don't have a pre-existing preference, these would 
> be good choices.
>  

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.