my Modulo Inverse in clojure Seems to give wrong answer

2014-10-13 Thread Ashish Negi



Hi I am programming in clojure and though the problem of modulo inverse has 
nothing to do with language i am stuck at this code -

(defn EulerDiv [x p]
  (let [ToMod (+ p 2)]
(loop [num 1 toPow (int p) numDouble x]
  (if (= 0 toPow) 
num
(let [numDouble2 (rem (* numDouble numDouble) ToMod)
  halfToPow (int (/ toPow 2))]
  (if (odd? toPow)
(recur (rem (* num numDouble) ToMod)
   halfToPow
   numDouble2)
(recur num halfToPow numDouble2))

  
  )

It seems to give me right answers for small Primes but when i am using it 
in a problem with Bigger primes i am getting answers other than result like 
:

(= 2 (mod (* 4 (EulerDiv 2 (- 3 2))) 3))

This prints true

(def ToMod (+ 10e8 7))( = 1 (int (mod (* 2 (EulerDiv 2 (- ToMod 2))) ToMod)) )

This prints false.

Also there is rem and mod in clojure. mod makes the output positive and 
hence i can not use it in between the calculations.
The problem is that of programming calculator grammar for evaluating 
evpressions like  "4/-2/(2 + 8)"

Thanks

-- 
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: my Modulo Inverse in clojure Seems to give wrong answer

2014-10-13 Thread Laurens Van Houtven
Hi Ashish,


At first sight, this looks like a numerical precision problem. 1e80 is a 
floating point type, not an integer type. You may want to try with e.g. 
1000N (note the N; that makes it a bigint). I don’t know of any 
nice syntax for describing extremely large bigints; e.g exponent notation.


hth
lvh



On 13 Oct 2014, at 10:20, Ashish Negi  wrote:

> 
> 
> Hi I am programming in clojure and though the problem of modulo inverse has 
> nothing to do with language i am stuck at this code -
> 
> (defn EulerDiv [x p]
> 
>   
> (let [ToMod (+ p 2)]
> 
> 
> (loop [num 1 toPow (int p) numDouble x]
> 
>   
> (if (= 0 toPow)
>  
> num
> 
> (let [numDouble2 (rem (* numDouble numDouble) ToMod)
> 
>   halfToPow 
> (int (/ toPow 2))]
> 
>   
> (if (odd? toPow)
> 
> 
> (recur (rem (* num numDouble) ToMod)
> 
>halfToPow
>numDouble2
> )
> 
> 
> (recur num halfToPow numDouble2))
> 
> 
>   
> 
> 
>   
> )
> It seems to give me right answers for small Primes but when i am using it in 
> a problem with Bigger primes i am getting answers other than result like :
> 
> (= 2 (mod (* 4 (EulerDiv 2 (- 3 2))) 3))
> This prints true
> 
> (def ToMod (+ 10e8 7))
> ( = 1 (int (mod (* 2 (EulerDiv 2 (- ToMod 2))) ToMod)) )
> This prints false.
> 
> Also there is rem and mod in clojure. mod makes the output positive and hence 
> i can not use it in between the calculations.
> 
> The problem is that of programming calculator grammar for evaluating 
> evpressions like  "4/-2/(2 + 8)"
> 
> Thanks
> 
> 
> -- 
> 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.



signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: my Modulo Inverse in clojure Seems to give wrong answer

2014-10-13 Thread Ashish Negi
Thanks Laurens 

 That solved it. :)

On Monday, 13 October 2014 14:04:16 UTC+5:30, Laurens Van Houtven wrote:
>
> Hi Ashish, 
>
>
> At first sight, this looks like a numerical precision problem. 1e80 is a 
> floating point type, not an integer type. You may want to try with e.g. 
> 1000N (note the N; that makes it a bigint). I don’t know of any 
> nice syntax for describing extremely large bigints; e.g exponent notation. 
>
>
> hth 
> lvh 
>
>
>
> On 13 Oct 2014, at 10:20, Ashish Negi > 
> wrote: 
>
> > 
> > 
> > Hi I am programming in clojure and though the problem of modulo inverse 
> has nothing to do with language i am stuck at this code - 
> > 
> > (defn EulerDiv [x p] 
> > 
> >   
> > (let [ToMod (+ p 2)] 
> > 
> > 
> > (loop [num 1 toPow (int p) numDouble x] 
> > 
> >   
> > (if (= 0 toPow) 
> >   
> > num 
> > 
> > (let [numDouble2 (rem (* numDouble numDouble) ToMod) 
> > 
> >   halfToPow 
> > (int (/ toPow 2))] 
> > 
> >   
> > (if (odd? toPow) 
> > 
> > 
> > (recur (rem (* num numDouble) ToMod) 
> > 
> >halfToPow 
> >numDouble2 
> > ) 
> > 
> > 
> > (recur num halfToPow numDouble2)) 
> > 
> > 
> >   
> >  
> > 
> >   
> > ) 
> > It seems to give me right answers for small Primes but when i am using 
> it in a problem with Bigger primes i am getting answers other than result 
> like : 
> > 
> > (= 2 (mod (* 4 (EulerDiv 2 (- 3 2))) 3)) 
> > This prints true 
> > 
> > (def ToMod (+ 10e8 7)) 
> > ( = 1 (int (mod (* 2 (EulerDiv 2 (- ToMod 2))) ToMod)) ) 
> > This prints false. 
> > 
> > Also there is rem and mod in clojure. mod makes the output positive and 
> hence i can not use it in between the calculations. 
> > 
> > The problem is that of programming calculator grammar for evaluating 
> evpressions like  "4/-2/(2 + 8)" 
> > 
> > Thanks 
> > 
> > 
> > -- 
> > 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 unsubscribe from this group and stop receiving emails from it, send 
> an email to clojure+u...@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.


Re: [ANN] rete4frames, v. 5.2.0 - CLIPS-like expert system shell

2014-10-13 Thread ru
Hi Shantanu,

1. I am waiting for bug reports from you, guys :)
2. Does this create some problems?

-- ru


суббота, 11 октября 2014 г., 20:59:43 UTC+4 пользователь ru написал:
>
> Hello all,
>
> New version 5.2.0 of rete4frames CLIPS-like expert system shell published 
> on https://github.com/rururu/rete4frames.
>
> News:
>
> 1. Tests can be used in negative condition
> 2. Because of this CLIPS examples reducted to canonical form
> 3. Several bug fixes including logical
> 4. Lot of code optimizations
>
> Enjoy!
>
> Sincerely,
>   Ru
>

-- 
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.


core.async thread behaviour

2014-10-13 Thread Nico Swart
 I am experimenting with core.async and I am using some code from a Tim 
Baldridge presentation:

; Logging Handler ;

(def log-chan (chan))

(thread
 (loop []
   (when-let [v (!! log-chan msg))

(log "foo")

If one executes (log "foo") a number of times the thread count of the 
process increases every time this function is called. My expectation
was that only one extra thread will be created in this code. Watching the 
number of threads in Windows task manager, the threads of the process
was 28, but after calling this function a number of times, the count was up 
to 93. Is this expected behaviour ?


-- 
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: [ANN] rete4frames, v. 5.2.0 - CLIPS-like expert system shell

2014-10-13 Thread Shantanu Kumar
OK, I understand now - will report bugs if I find any, am at a newbie level 
now. I was confused whether it's an Alpha release, because the subject 
didn't mention that.

Shantanu

On Monday, 13 October 2014 17:46:30 UTC+5:30, ru wrote:
>
> Hi Shantanu,
>
> 1. I am waiting for bug reports from you, guys :)
> 2. Does this create some problems?
>
> -- ru
>
>
> суббота, 11 октября 2014 г., 20:59:43 UTC+4 пользователь ru написал:
>>
>> Hello all,
>>
>> New version 5.2.0 of rete4frames CLIPS-like expert system shell published 
>> on https://github.com/rururu/rete4frames.
>>
>> News:
>>
>> 1. Tests can be used in negative condition
>> 2. Because of this CLIPS examples reducted to canonical form
>> 3. Several bug fixes including logical
>> 4. Lot of code optimizations
>>
>> Enjoy!
>>
>> Sincerely,
>>   Ru
>>
>

-- 
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: core.async thread behaviour

2014-10-13 Thread Laurens Van Houtven
Hi Nico,


Just to rule out the obvious: you’re not recompiling that namespace ever time, 
right? Because if you call (thread …) a bunch of times, you’re gonna get a 
bunch of threads :-)


cheers
lvh



On 13 Oct 2014, at 14:21, Nico Swart  wrote:

>  I am experimenting with core.async and I am using some code from a Tim 
> Baldridge presentation:
> 
> ; Logging Handler ;
> 
> (def log-chan (chan))
> 
> (thread
>  (loop []
>(when-let [v (  (println v)
>  (recur)))
>  (println "Log Closed"))
> 
> 
> (close! log-chan)
> 
> (defn log [msg]
>   (>!! log-chan msg))
> 
> (log "foo")
> 
> If one executes (log "foo") a number of times the thread count of the process 
> increases every time this function is called. My expectation
> was that only one extra thread will be created in this code. Watching the 
> number of threads in Windows task manager, the threads of the process
> was 28, but after calling this function a number of times, the count was up 
> to 93. Is this expected behaviour ?
> 
> 
> 
> -- 
> 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.



signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: core.async thread behaviour

2014-10-13 Thread Nico Swart
Hi Laurens,

I am pretty sure (thread ...) only executes once. To check this I evaluated 

(dotimes [i 100] (log "foo")) 

in the REPL and the thread count goes from 23 to 80. On subsequent 
evaluations of (dotimes [i 100] (log "foo")), the count stays at 78. 


Thanks
Nico.


On Monday, October 13, 2014 8:43:51 AM UTC-4, Laurens Van Houtven wrote:
>
> Hi Nico, 
>
>
> Just to rule out the obvious: you’re not recompiling that namespace ever 
> time, right? Because if you call (thread …) a bunch of times, you’re gonna 
> get a bunch of threads :-) 
>
>
> cheers 
> lvh 
>
>
>
> On 13 Oct 2014, at 14:21, Nico Swart > 
> wrote: 
>
> >  I am experimenting with core.async and I am using some code from a Tim 
> Baldridge presentation: 
> > 
> > ; Logging Handler ; 
> > 
> > (def log-chan (chan)) 
> > 
> > (thread 
> >  (loop [] 
> >(when-let [v ( >  (println v) 
> >  (recur))) 
> >  (println "Log Closed")) 
> > 
> > 
> > (close! log-chan) 
> > 
> > (defn log [msg] 
> >   (>!! log-chan msg)) 
> > 
> > (log "foo") 
> > 
> > If one executes (log "foo") a number of times the thread count of the 
> process increases every time this function is called. My expectation 
> > was that only one extra thread will be created in this code. Watching 
> the number of threads in Windows task manager, the threads of the process 
> > was 28, but after calling this function a number of times, the count was 
> up to 93. Is this expected behaviour ? 
> > 
> > 
> > 
> > -- 
> > 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 unsubscribe from this group and stop receiving emails from it, send 
> an email to clojure+u...@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.


Optimizing code : Fun but now paining me

2014-10-13 Thread Ashish Negi
I am competing in an online competition and the scenario is like this :
I coded with my basic knowledge of clojure and got 11 out of 20 testcases 
and others being timed out and one being runtime error..

I started optimizing my code and read 
https://groups.google.com/forum/#!searchin/clojure/performance/clojure/SxT2MaOsip8/xoMkDVHeOqMJ
and other google articles for performance.. but after that i just managed 
to solve only one more problem and i am stuck at 12 solved.. ( the time for 
each case is 8 seconds max)
The last 12th was completed in 7.05 secs :) .. just on the border huh... :)

The problem is about that of Solving calculataor expressions like 
"2+3/2/2/(2+8)" mod 10^8+7  gives answer 10^8+3..
Nevertheless it is the concern but optimizing code is :)

This is current condition of my code :

(ns fpcontest.expression)

(def Term)
(def Factor)

(def ToMod (int (+ 10 7)))

;; (int ToMod)

(def toPrint false)

(defn myprintln [& args]
  ;; (if toPrint
  ;;   (apply println args))
)

(defn EulerDivNonMemo [^long x ^long p]
  (let [ToMod (+ p 2)]
(loop [num (long 1) toPow p numDouble x]
  (if (= 0 toPow) 
;;(do (myprintln " EulerDiv : " num " for " x p)) 
num
(let [numDouble2 (rem (* numDouble numDouble) ToMod)
  halfToPow (bit-shift-right toPow 1)]
  (if (odd? toPow)
(recur (rem (* num numDouble) ToMod)
   halfToPow
   numDouble2)
(recur num halfToPow numDouble2))
  
  
  )

(def EulerDiv (memoize EulerDivNonMemo)
)

;; (EulerDiv 2 2)
;; (defn TestEulerDiv []
;;   (and
;;(= 2 (mod (* 4 (EulerDiv 2 (- 3 2))) 3))
;;(= 1 (mod (* 2 (EulerDiv 2 (- 3 2))) 3))
;;(= 1 (int (mod (* 2 (EulerDiv 2 (- ToMod 2))) ToMod
;;   )

;; (= true (TestEulerDiv))

(defn Expression [lst]
  (let [term (Term lst)
;; p (myprintln term " term for exp " lst)
sizeTerm (count term)
evaluateExpr 
(fn [opr lst]
  (let [expr (Expression (drop 2 lst))
;; p (myprintln expr " expr for Expr " lst " and " opr)
intLst (first lst)]
(cons (rem (opr intLst
(first expr)) 
   ToMod) (drop 1 expr]
(if (> sizeTerm 2)
  (if (= (second term) "+")
(evaluateExpr + term)
(if (= (second term) "-")
  (evaluateExpr - term)
  term)
)
  ;; first of term is the answer
  term
  )
))


(defn Term [lst]
  (let [factor (Factor lst)
;; p (myprintln factor " factor for term " lst)
sizeFactor (count factor)
evaluateExpr
(fn [opr lst]
  (let [expr (Term (drop 2 lst))
;;p (myprintln expr " term for expr " 
lst " and " opr)
intLst (first lst)]
(cons (rem (opr intLst
(first expr)) 
   ToMod) (drop 1 expr) )))]
(if (> sizeFactor 2)
  (if (= (second factor) "*")
(evaluateExpr * factor)
(if (= (second factor) "/")
  (let [expr (Term (drop 2 factor))
fExpr (first expr)] 
(cons (rem (* (first factor) (EulerDiv fExpr (- ToMod 2)))
   ToMod) (drop 1 expr))
)
  ;;(evaluateExpr / factor)
  factor)
)
  factor
  )
))

(defn Factor [lst]
  (let [fFactor (first lst)
;;p (myprintln " Factor has : " lst)
]
(if (= fFactor "+")
  (cons (int (Integer. (second lst))) (rest lst))
  (if (= fFactor "-")
(cons (- (int (Integer. (second lst (rest (rest lst)))
(if (= fFactor "(")
  ;; remove the '(' and ')'
  (let [expr (Expression (rest lst))]
(cons (first expr) (drop 2 expr))
)
  ;; (if (= (count lst) 1))
  (cons  (int (Integer. (first lst))) (rest lst))
  ;;(myprintln "I do not know where i am... " lst)
  
)
  ))
  )

(defn split-with-delim [d s]
  (clojure.string/split 
   s (re-pattern (str "(?=" d 
")|(?<=" d
")"

(defn make-calulator-list [s]
  (->> s
   (split-with-delim #"[\/\+\-\*\(\) ]")
   (filter #(not (or (= "" %) (= " " %
   doall
   ))

(defn StartRun [FuncToCall inputParse outputParse]
  (let [lines (line-seq (java.io.BufferedReader. *in*))]
(outputParse (FuncToCall (inputParse (first lines)
)  


and this is how i am testing my code  
** Test 




(defn RunTests []
  (and 
   (= 1717 (int (first (Expression (make-calulator-list " 22 * 79 - 21")
   
   (= 12 (int (first (Expression (make-calulator-list " 4/2/2 + 8")
   
   (= 4  (int (first (Expression (make-calulator-list "4/-2/2 + 8")

   (= 98605 (int (mod  (first (Expression (make-calulator-list 
"55+3

Re: Optimizing code : Fun but now paining me

2014-10-13 Thread Ashish Negi
It would be great if you people could help me with the optimization .. just 
few tricks and it may work.. or guide me towards the resources..

On Monday, 13 October 2014 18:40:15 UTC+5:30, Ashish Negi wrote:
>
> I am competing in an online competition and the scenario is like this :
> I coded with my basic knowledge of clojure and got 11 out of 20 testcases 
> and others being timed out and one being runtime error..
>
> I started optimizing my code and read 
> https://groups.google.com/forum/#!searchin/clojure/performance/clojure/SxT2MaOsip8/xoMkDVHeOqMJ
> and other google articles for performance.. but after that i just managed 
> to solve only one more problem and i am stuck at 12 solved.. ( the time for 
> each case is 8 seconds max)
> The last 12th was completed in 7.05 secs :) .. just on the border huh... :)
>
> The problem is about that of Solving calculataor expressions like 
> "2+3/2/2/(2+8)" mod 10^8+7  gives answer 10^8+3..
> Nevertheless it is the concern but optimizing code is :)
>
> This is current condition of my code :
>
> (ns fpcontest.expression)
>
> (def Term)
> (def Factor)
>
> (def ToMod (int (+ 10 7)))
>
> ;; (int ToMod)
>
> (def toPrint false)
>
> (defn myprintln [& args]
>   ;; (if toPrint
>   ;;   (apply println args))
> )
>
> (defn EulerDivNonMemo [^long x ^long p]
>   (let [ToMod (+ p 2)]
> (loop [num (long 1) toPow p numDouble x]
>   (if (= 0 toPow) 
> ;;(do (myprintln " EulerDiv : " num " for " x p)) 
> num
> (let [numDouble2 (rem (* numDouble numDouble) ToMod)
>   halfToPow (bit-shift-right toPow 1)]
>   (if (odd? toPow)
> (recur (rem (* num numDouble) ToMod)
>halfToPow
>numDouble2)
> (recur num halfToPow numDouble2))
>   
>   
>   )
>
> (def EulerDiv (memoize EulerDivNonMemo)
> )
>
> ;; (EulerDiv 2 2)
> ;; (defn TestEulerDiv []
> ;;   (and
> ;;(= 2 (mod (* 4 (EulerDiv 2 (- 3 2))) 3))
> ;;(= 1 (mod (* 2 (EulerDiv 2 (- 3 2))) 3))
> ;;(= 1 (int (mod (* 2 (EulerDiv 2 (- ToMod 2))) ToMod
> ;;   )
>
> ;; (= true (TestEulerDiv))
>
> (defn Expression [lst]
>   (let [term (Term lst)
> ;; p (myprintln term " term for exp " lst)
> sizeTerm (count term)
> evaluateExpr 
> (fn [opr lst]
>   (let [expr (Expression (drop 2 lst))
> ;; p (myprintln expr " expr for Expr " lst " and " opr)
> intLst (first lst)]
> (cons (rem (opr intLst
> (first expr)) 
>ToMod) (drop 1 expr]
> (if (> sizeTerm 2)
>   (if (= (second term) "+")
> (evaluateExpr + term)
> (if (= (second term) "-")
>   (evaluateExpr - term)
>   term)
> )
>   ;; first of term is the answer
>   term
>   )
> ))
>
>
> (defn Term [lst]
>   (let [factor (Factor lst)
> ;; p (myprintln factor " factor for term " lst)
> sizeFactor (count factor)
> evaluateExpr
> (fn [opr lst]
>   (let [expr (Term (drop 2 lst))
> ;;p (myprintln expr " term for expr " 
> lst " and " opr)
> intLst (first lst)]
> (cons (rem (opr intLst
> (first expr)) 
>ToMod) (drop 1 expr) )))]
> (if (> sizeFactor 2)
>   (if (= (second factor) "*")
> (evaluateExpr * factor)
> (if (= (second factor) "/")
>   (let [expr (Term (drop 2 factor))
> fExpr (first expr)] 
> (cons (rem (* (first factor) (EulerDiv fExpr (- ToMod 2)))
>ToMod) (drop 1 expr))
> )
>   ;;(evaluateExpr / factor)
>   factor)
> )
>   factor
>   )
> ))
>
> (defn Factor [lst]
>   (let [fFactor (first lst)
> ;;p (myprintln " Factor has : " lst)
> ]
> (if (= fFactor "+")
>   (cons (int (Integer. (second lst))) (rest lst))
>   (if (= fFactor "-")
> (cons (- (int (Integer. (second lst (rest (rest lst)))
> (if (= fFactor "(")
>   ;; remove the '(' and ')'
>   (let [expr (Expression (rest lst))]
> (cons (first expr) (drop 2 expr))
> )
>   ;; (if (= (count lst) 1))
>   (cons  (int (Integer. (first lst))) (rest lst))
>   ;;(myprintln "I do not know where i am... " lst)
>   
> )
>   ))
>   )
>
> (defn split-with-delim [d s]
>   (clojure.string/split 
>s (re-pattern (str "(?=" d 
> ")|(?<=" d
> ")"
>
> (defn make-calulator-list [s]
>   (->> s
>(split-with-delim #"[\/\+\-\*\(\) ]")
>(filter #(not (or (= "" %) (= " " %
>doall
>))
>
> (defn StartRun [FuncToCall inputParse outputParse]
>   (let [lines (line-seq (java.io.BufferedReader. *in*))]
> (outputParse (FuncToCall

Re: Optimizing code : Fun but now paining me

2014-10-13 Thread Ashish Negi
It would be great if you people can help me with the optimization and it 
may work..
or can just guide me towards resources.. :)

Thanks 

-- 
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: uniqueness of hash if computed on different jvms across different machines.

2014-10-13 Thread Andy Fingerhut
For immutable values (including hash-maps containing only immutable
values), I believe the answer is yes, if you are using the same version of
Clojure on the different jvms (at least, I cannot think of any
counterexamples in a few minutes of thinking about it, and I have looked at
the hash function implementations in Clojure in some detail before because
of [1]).  For mutable values (or hash-maps containing mutable values),
there are whatever guarantees Java makes for its .hashCode method.

Most of the hash values computed changed between Clojure 1.5.1 and Clojure
1.6.0 [1] to avoid hash collisions that were common for collections.

There is no guarantee I know of that future versions of Clojure will not
change hash functions again.

These facts prompt me to wonder: Why do you want to know if there is such a
guarantee?  Saving such hash values on disk, for example, will expose you
to possible changes to those values in future versions of Clojure.  Using
them to communicate between different JVMs will limit the application to
running versions of Clojure on those multiple JVMs with the same hash
functions (either the same version of Clojure, or 'hash compatible'
versions of Clojure).

Andy


[1] https://github.com/clojure/clojure/blob/master/changes.md#24-hashing

On Sun, Oct 12, 2014 at 11:04 PM, Sunil S Nandihalli <
sunil.nandiha...@gmail.com> wrote:

> Hi,
> Is the clojure hash function guaranteed to produce the same hash on
> different jvms running on different jvms for the same "data-structure"
> which would satisfy "equality" if checked on a single jvm. The data
> structure is simply a hash-map.
> Thanks,
> Sunil.
>
> --
> 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.


Re: Why is my function faster with eval?

2014-10-13 Thread Mathias De Wachter
Very interesting thread!

I'm having a similar problem and Michaels approach got me a small speedup 
(around 15%). When trying Mike's approach on my real data, if fails with
IllegalArgumentException Too many arguments to struct constructor  clojure.
lang.PersistentStructMap.construct (PersistentStructMap.java:77)

Op zondag 12 oktober 2014 03:51:46 UTC+2 schreef Mike Fikes:
>
> Hey Michael,
>
> Since your eval solution essentially "cookie-cutters" out maps, each with 
> the same keys, as fast as it can, I was playing around with what would 
> happen if you used records, and I cobbled together something that appears 
> to run twice as fast as the eval approach:
>
> (defn read-to-structs [rows]
>   (let [headers (->>
>   rows
>   first
>   (take-while (complement #{""}))
>   (map keyword))
> s (apply create-struct headers)]
> (for [row (rest rows)]
>   (apply struct s row
>
>
> Here are comparative timings:
>
> (time-fn read-to-maps)
> "Elapsed time: 4871.02175 msecs"
> => nil
> (time-fn read-to-maps-partial)
> "Elapsed time: 4814.730643 msecs"
> => nil
> (time-fn read-to-maps-fn)
> "Elapsed time: 4815.230087 msecs"
> => nil
> (time-fn read-to-maps-eval)
> "Elapsed time: 2466.048578 msecs"
> => nil
> (time-fn read-to-structs)
> "Elapsed time: 1273.462618 msecs"
>
> I didn't test it too much, but it passed this:
>
> (= (read-to-maps csv-fix) (read-to-structs csv-fix))
> => true
>
> On Friday, October 10, 2014 4:21:01 PM UTC-4, Michael Blume wrote:
>>
>> https://github.com/MichaelBlume/eval-speed
>>
>> eval-speed.core=> (time-fn read-to-maps)
>> "Elapsed time: 5551.011069 msecs"
>> nil
>> eval-speed.core=> (time-fn read-to-maps-fn)
>> "Elapsed time: 5587.256991 msecs"
>> nil
>> eval-speed.core=> (time-fn read-to-maps-partial)
>> "Elapsed time: 5606.649172 msecs"
>> nil
>> eval-speed.core=> (time-fn read-to-maps-eval)
>> "Elapsed time: 2627.521592 msecs"
>> nil
>>
>> Ben, I'd still like to understand exactly what work the CPU is doing in 
>> the uneval'd version that it's skipping in the eval'd version. It seems 
>> like in the generated bytecode there's going to be *some* concept of 
>> iterating through the row in either case, if only as part of the 
>> destructuring process.
>>
>>
>> On Friday, October 10, 2014 1:07:08 PM UTC-7, Ben wrote:
>>>
>>> I believe it's because the `mapper` function is just creating and 
>>> returning a map literal. The "mapper" function in the evaled version is 
>>> something like this:
>>>
>>> user> (def names '[n1 n2 n3 n4])
>>> #'user/names
>>> user> (def headers '[h1 h2 h3 h4])
>>> #'user/headers
>>> user> `(fn [[~@names]] ~(zipmap headers names))
>>> (clojure.core/fn [[n1 n2 n3 n4]] {h4 n4, h3 n3, h2 n2, h1 n1})   ;; just 
>>> a map literal, whose keys are already known.
>>>
>>> Whereas in the first version, zipmap has to be called, iterating over 
>>> headers and names each time.
>>>
>>> On Fri, Oct 10, 2014 at 1:04 PM, Sean Corfield  
>>> wrote:
>>>
 It may be more to do with the difference between `for` and `map`. How 
 do these versions compare in your benchmark:

 (defn read-to-maps-partial [rows]
   (let [headers (->>
   rows
   first
   (take-while (complement #{""}))
   (map keyword))]
 (map (partial zipmap headers) (rest rows

 (defn read-to-maps-fn [rows]
   (let [headers (->>
   rows
   first
   (take-while (complement #{""}))
   (map keyword))
 mapper (fn [row] (zipmap headers row))]
 (map mapper (rest rows

 Sean

 On Oct 10, 2014, at 11:42 AM, Michael Blume  wrote:
 > So I'm reading a bunch of rows from a huge csv file and marshalling 
 those rows into maps using the first row as keys. I wrote the function two 
 ways: https://gist.github.com/MichaelBlume/c67d22df0ff9c225d956 and 
 the version with eval is twice as fast and I'm kind of curious about why. 
 Presumably the eval'd function still implicitly contains a list of keys, 
 it's still implicitly treating each row as a seq and walking it, so I'm 
 wondering what the seq-destructuring and the map literal are doing under 
 the hood that's faster.


>>>
>>>
>>> -- 
>>> 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+un

Re: uniqueness of hash if computed on different jvms across different machines.

2014-10-13 Thread Mike Fikes
In addition to Andy's caveats, remember that hash code equality doesn't 
imply object equality.

In concrete terms,

   a = b implies h(a) = h(b),

with the useful bit being

  h(a) ≠ h(b) implies a ≠ b.

On Monday, October 13, 2014 2:04:57 AM UTC-4, Sunil Nandihalli wrote:
>
> Hi,
> Is the clojure hash function guaranteed to produce the same hash on 
> different jvms running on different jvms for the same "data-structure" 
> which would satisfy "equality" if checked on a single jvm. The data 
> structure is simply a hash-map.
> Thanks,
> Sunil.
>

-- 
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.


New Functional Programming Job Opportunities

2014-10-13 Thread Functional Jobs
Here are some functional programming job opportunities that were posted

recently:



Software Engineer / Developer at Clutch Analytics/ Windhaven Insurance

http://functionaljobs.com/jobs/8753-software-engineer-developer-at-clutch-analytics-windhaven-insurance



Cheers,

Sean Murphy

FunctionalJobs.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
--- 
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.


Chestnut memory usage

2014-10-13 Thread gvim

I've just setup a `lein new chestnut` project and after:

$ lein repl
   (run)
   (browser-repl)

 Activity Monitor shows 3 Java processes:

main: 953Mb
main: 747Mb
java: 634Mb

Over 2.3Gb RAM just to get a CLJS browser repl? I haven't even added 
Lighttable into the mix or IntelliJ :(


gvim


--
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: Chestnut memory usage

2014-10-13 Thread Andy Fingerhut
You may want to be more explicit about dependencies you've added to your
project.clj file, or what the contents of your ~/.lein/profiles.clj file
is.  (run) an (browser-repl) throw exceptions as being undefined if your
~/.lein/profiles.clj is empty, and project.clj has its default contents.

Andy

On Mon, Oct 13, 2014 at 11:19 AM, gvim  wrote:

> I've just setup a `lein new chestnut` project and after:
>
> $ lein repl
>(run)
>(browser-repl)
>
>  Activity Monitor shows 3 Java processes:
>
> main: 953Mb
> main: 747Mb
> java: 634Mb
>
> Over 2.3Gb RAM just to get a CLJS browser repl? I haven't even added
> Lighttable into the mix or IntelliJ :(
>
> gvim
>
>
> --
> 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.


Re: [ANN] rete4frames, v. 5.2.0 - CLIPS-like expert system shell

2014-10-13 Thread kovas boguta
This looks like a cool project.

One comment: I don't know what CLIPS or frames are (I've heard of rete
once or twice), so its hard for me to understand what rete4frames is
or what problem it might solve for me. Might be help to have some very
basic explanation of the use cases / advantages of this system to
orient simple Clojure programmers like myself.





On Mon, Oct 13, 2014 at 8:36 AM, Shantanu Kumar
 wrote:
> OK, I understand now - will report bugs if I find any, am at a newbie level
> now. I was confused whether it's an Alpha release, because the subject
> didn't mention that.
>
> Shantanu
>
>
> On Monday, 13 October 2014 17:46:30 UTC+5:30, ru wrote:
>>
>> Hi Shantanu,
>>
>> 1. I am waiting for bug reports from you, guys :)
>> 2. Does this create some problems?
>>
>> -- ru
>>
>>
>> суббота, 11 октября 2014 г., 20:59:43 UTC+4 пользователь ru написал:
>>>
>>> Hello all,
>>>
>>> New version 5.2.0 of rete4frames CLIPS-like expert system shell published
>>> on https://github.com/rururu/rete4frames.
>>>
>>> News:
>>>
>>> 1. Tests can be used in negative condition
>>> 2. Because of this CLIPS examples reducted to canonical form
>>> 3. Several bug fixes including logical
>>> 4. Lot of code optimizations
>>>
>>> Enjoy!
>>>
>>> Sincerely,
>>>   Ru
>
> --
> 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.


Re: Chestnut memory usage

2014-10-13 Thread David Nolen
You can set explicit JVM memory settings. I'm also not convinced that
Chestnut's strategy of triggering CLJS compilation on (run) is a good
one. In anycase Chestnut's Github Issues is the right place to bring
this up.

David

On Mon, Oct 13, 2014 at 2:19 PM, gvim  wrote:
> I've just setup a `lein new chestnut` project and after:
>
> $ lein repl
>(run)
>(browser-repl)
>
>  Activity Monitor shows 3 Java processes:
>
> main: 953Mb
> main: 747Mb
> java: 634Mb
>
> Over 2.3Gb RAM just to get a CLJS browser repl? I haven't even added
> Lighttable into the mix or IntelliJ :(
>
> gvim
>
>
> --
> 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.


Re: [ANN] rete4frames, v. 5.2.0 - CLIPS-like expert system shell

2014-10-13 Thread ru
Hello kovasb,

I recommend you to have a quick look on this 3 pages:

1. http://en.wikipedia.org/wiki/CLIPS
2. http://en.wikipedia.org/wiki/Expert_system
3. http://clipsrules.sourceforge.net/

Rete4frames allows to embed this functionallity into Clojure programs.

Hope this helps.
Sincerely,
  Ru

понедельник, 13 октября 2014 г., 22:30:26 UTC+4 пользователь kovasb написал:
>
> This looks like a cool project. 
>
> One comment: I don't know what CLIPS or frames are (I've heard of rete 
> once or twice), so its hard for me to understand what rete4frames is 
> or what problem it might solve for me. Might be help to have some very 
> basic explanation of the use cases / advantages of this system to 
> orient simple Clojure programmers like myself. 
>
>
>
>
>
> On Mon, Oct 13, 2014 at 8:36 AM, Shantanu Kumar 
> > wrote: 
> > OK, I understand now - will report bugs if I find any, am at a newbie 
> level 
> > now. I was confused whether it's an Alpha release, because the subject 
> > didn't mention that. 
> > 
> > Shantanu 
> > 
> > 
> > On Monday, 13 October 2014 17:46:30 UTC+5:30, ru wrote: 
> >> 
> >> Hi Shantanu, 
> >> 
> >> 1. I am waiting for bug reports from you, guys :) 
> >> 2. Does this create some problems? 
> >> 
> >> -- ru 
> >> 
> >> 
> >> суббота, 11 октября 2014 г., 20:59:43 UTC+4 пользователь ru написал: 
> >>> 
> >>> Hello all, 
> >>> 
> >>> New version 5.2.0 of rete4frames CLIPS-like expert system shell 
> published 
> >>> on https://github.com/rururu/rete4frames. 
> >>> 
> >>> News: 
> >>> 
> >>> 1. Tests can be used in negative condition 
> >>> 2. Because of this CLIPS examples reducted to canonical form 
> >>> 3. Several bug fixes including logical 
> >>> 4. Lot of code optimizations 
> >>> 
> >>> Enjoy! 
> >>> 
> >>> Sincerely, 
> >>>   Ru 
> > 
> > -- 
> > 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 unsubscribe from this group and stop receiving emails from it, send 
> an 
> > email to clojure+u...@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.


Re: ANN: State of Clojure 2014 Survey - please contribute!!

2014-10-13 Thread Zack Maril
Next year, I would appreciate questions that measure the demographics of 
Clojure users be included. Out of the hundreds of people I've heard and 
seen talking about using Clojure, the vast majority of them have been white 
men. I've thought about it for a few days now and I can only think of three 
or four women who I know use Clojure and only a few non white men. I'd like 
to know if selecting Clojure as my default/main programming language means 
that I'll be forced to select from a fairly homogeneous group of potential 
coworkers and miss out on the benefits of a diverse working environment. 
-Zack 


On Friday, October 10, 2014 5:27:50 PM UTC-5, Jony Hudson wrote:
>
> If this is the unofficial survey post of academics using Clojure then I'd 
> better add myself to the list :-)
>
> @Bruce do you know what course they're going to be teaching Clojure on at 
> Birkbeck?
>
>
> Jony
>
>
> On Friday, 10 October 2014 08:08:28 UTC+1, Bruce Durling wrote:
>>
>> I also know that Birkbeck College University of London is going to be 
>> teaching Clojure this year. 
>> On Oct 10, 2014 12:01 AM, "Lee Spector"  wrote:
>>
>>>
>>> FWIW I'm another person using Clojure mostly for academic research. And 
>>> for computer science education, e.g. I'm currently teaching a Clojure-based 
>>> AI course. I'd be curious to know how many others of us are out there. And 
>>> BTW I think that attention to users in these categories could help to grow 
>>> the community.
>>>
>>>  -Lee
>>>
>>> On Oct 9, 2014, at 12:32 AM, Mars0i  wrote:
>>>
>>> > Thanks for the survey!
>>> >
>>> > I have a couple of suggestions/questions:
>>> >
>>> > For domains, there are no categories for scientific or other research 
>>> applications.  For example, I mainly use Clojure for writing agent-based 
>>> models for academic research.  Would a set of categories in this area be 
>>> usedful?
>>> >
>>>
>>> --
>>> 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 unsubscribe from this group and stop receiving emails from it, send 
>>> an email to clojure+u...@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.


Re: my Modulo Inverse in clojure Seems to give wrong answer

2014-10-13 Thread Fluid Dynamics


On Monday, October 13, 2014 4:34:16 AM UTC-4, Laurens Van Houtven wrote:
>
> Hi Ashish, 
>
>
> At first sight, this looks like a numerical precision problem. 1e80 is a 
> floating point type, not an integer type. You may want to try with e.g. 
> 1000N (note the N; that makes it a bigint). I don’t know of any 
> nice syntax for describing extremely large bigints; e.g exponent notation. 
>

1e80N doesn't work, but 1e80M does, and so does 1E400M so it's not going 
through a double on the way (or it would turn into an infinity at that 
stage). That's a BigDecimal but then, (bigint 1E400M) works just fine. 
Though it prints rather inefficiently. :)

-- 
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: Optimizing code : Fun but now paining me

2014-10-13 Thread juan.facorro
That is a whole lot of code to check and test for optimizations :P

How are you identifying the problems in your code that need optimization? 
Are you doing some kind of profiling or just trying stuff out? If you are 
not doing it already, I would recommend using VisualVM [1] to get a clearer 
picture on what is taking so long to execute so then you can attack the 
specific problem. If you have a specific question then on how to improve 
your code's performance, I think a lot people in the list would be glad to 
help.   

Hope it helps!

Juan

[1]: http://visualvm.java.net/

On Monday, October 13, 2014 10:12:31 AM UTC-3, Ashish Negi wrote:
>
> It would be great if you people can help me with the optimization and it 
> may work..
> or can just guide me towards resources.. :)
>
> Thanks 
>

-- 
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: uniqueness of hash if computed on different jvms across different machines.

2014-10-13 Thread Alex Miller
I would expect that right now the same version of Clojure would typically 
give you the same hash for the same data structure across different JVM 
instances. HOWEVER, I would consider this accidental, not a guarantee. 
Certainly the hash values may change across Clojure or JDK versions. 
Additionally the JVM (specifically in some JDK 1.7 versions and settings) 
and other languages seed hash calculation with an instance-specific value 
to foil hash-based DDOS attacks. Clojure may employ such a strategy in the 
future. I would not state any guarantee beyond this:  "In a particular JVM 
instance, two Clojure data structures that are =, will have the same hasheq 
value."

If you want a hash computation you can rely on across JVM and Clojure 
versions and instances, you should compute it with your own code.


On Monday, October 13, 2014 9:55:09 AM UTC-5, Andy Fingerhut wrote:
>
> For immutable values (including hash-maps containing only immutable 
> values), I believe the answer is yes, if you are using the same version of 
> Clojure on the different jvms (at least, I cannot think of any 
> counterexamples in a few minutes of thinking about it, and I have looked at 
> the hash function implementations in Clojure in some detail before because 
> of [1]).  For mutable values (or hash-maps containing mutable values), 
> there are whatever guarantees Java makes for its .hashCode method.
>
> Most of the hash values computed changed between Clojure 1.5.1 and Clojure 
> 1.6.0 [1] to avoid hash collisions that were common for collections.
>
> There is no guarantee I know of that future versions of Clojure will not 
> change hash functions again.
>
> These facts prompt me to wonder: Why do you want to know if there is such 
> a guarantee?  Saving such hash values on disk, for example, will expose you 
> to possible changes to those values in future versions of Clojure.  Using 
> them to communicate between different JVMs will limit the application to 
> running versions of Clojure on those multiple JVMs with the same hash 
> functions (either the same version of Clojure, or 'hash compatible' 
> versions of Clojure).
>
> Andy
>
>
> [1] https://github.com/clojure/clojure/blob/master/changes.md#24-hashing
>
> On Sun, Oct 12, 2014 at 11:04 PM, Sunil S Nandihalli <
> sunil.na...@gmail.com > wrote:
>
>> Hi,
>> Is the clojure hash function guaranteed to produce the same hash on 
>> different jvms running on different jvms for the same "data-structure" 
>> which would satisfy "equality" if checked on a single jvm. The data 
>> structure is simply a hash-map.
>> Thanks,
>> Sunil.
>>
>> -- 
>> 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 unsubscribe from this group and stop receiving emails from it, send an 
>> email to clojure+u...@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.


Re: Keyword comparison performance

2014-10-13 Thread Alex Miller
Not really chiming in directly on this, but one thing I wanted to note is 
that getting meaningful performance numbers for keyword-related code is 
somewhat tricky due to caching and interning.

Keywords are cached so new keyword construction is much slower than 
existing keyword construction (and there are GC and concurrency-related 
consequences). Keywords hold symbols that hold strings for namespace and 
name. Those strings are (until Clojure 1.7) interned in the JVM. That has 
its own consequences for string construction (interning itself is slow) 
however hash codes are cached on Strings. As of 1.7, the strings in Symbols 
are not interned (which is faster for construction, but uses more memory). 

It is challenging to account for all of these factors when benchmarking in 
ways that actually represent real applications. Testing your own actual 
application performance with different strategies and versions is of 
course, the best way to understand how it actually affects you. 


On Saturday, October 11, 2014 8:28:22 PM UTC-5, Mike Rodriguez wrote:
>
> Thanks for taking the time for the (detailed) clarification. I understand 
>  what you were saying now. 
> :)

-- 
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: ANN: State of Clojure 2014 Survey - please contribute!!

2014-10-13 Thread Alex Miller
I'd be happy to include these for consideration next year. I think on the 
dev env we have removed some like this because they were not well 
represented in the results. The landscape for dev envs changes 
significantly year to year.

On Wednesday, October 8, 2014 11:32:53 PM UTC-5, Mars0i wrote:
>
> Thanks for the survey!
>
> I have a couple of suggestions/questions:
>
> For domains, there are no categories for scientific or other research 
> applications.  For example, I mainly use Clojure for writing agent-based 
> models for academic research.  Would a set of categories in this area be 
> usedful?
>
> The development environment options leave out more basic, simple methods.  
> For example, I generally use vim and a repl run from the command line, 
> which works well for me.  I guess I should chose "other", but that means I 
> don't get counted among the vim users.  Maybe the number of people like me 
> is so small as to be ignorable?
>

-- 
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: ANN: State of Clojure 2014 Survey - please contribute!!

2014-10-13 Thread Alex Miller
Hey Zack,

I don't know that we will include demographic questions in this survey in 
the future, something to think about. 

I do not need a poll to see that Clojure developers are predominantly white 
men, although that's also true of most programming languages and a 
consequence of larger pervasive issues in the industry. However, I think 
the Clojure community has been making progress on increasing diversity 
through efforts like ClojureBridge http://www.clojurebridge.org/ and the 
Clojure/conj opportunity grants http://clojure-conj.org/grants/. 

You might also find this project's data 
interesting: http://alyssafrazee.com/gender-and-github-code.html

I would humbly submit that you should choose your language based on the 
best tool for the job and then work to hire, train, and improve diversity 
of the community regardless of what that tool may be. 

Alex



On Monday, October 13, 2014 1:50:13 PM UTC-5, Zack Maril wrote:
>
> Next year, I would appreciate questions that measure the demographics of 
> Clojure users be included. Out of the hundreds of people I've heard and 
> seen talking about using Clojure, the vast majority of them have been white 
> men. I've thought about it for a few days now and I can only think of three 
> or four women who I know use Clojure and only a few non white men. I'd like 
> to know if selecting Clojure as my default/main programming language means 
> that I'll be forced to select from a fairly homogeneous group of potential 
> coworkers and miss out on the benefits of a diverse working environment. 
> -Zack 
>
>
> On Friday, October 10, 2014 5:27:50 PM UTC-5, Jony Hudson wrote:
>>
>> If this is the unofficial survey post of academics using Clojure then I'd 
>> better add myself to the list :-)
>>
>> @Bruce do you know what course they're going to be teaching Clojure on at 
>> Birkbeck?
>>
>>
>> Jony
>>
>>
>> On Friday, 10 October 2014 08:08:28 UTC+1, Bruce Durling wrote:
>>>
>>> I also know that Birkbeck College University of London is going to be 
>>> teaching Clojure this year. 
>>> On Oct 10, 2014 12:01 AM, "Lee Spector"  wrote:
>>>

 FWIW I'm another person using Clojure mostly for academic research. And 
 for computer science education, e.g. I'm currently teaching a 
 Clojure-based 
 AI course. I'd be curious to know how many others of us are out there. And 
 BTW I think that attention to users in these categories could help to grow 
 the community.

  -Lee

 On Oct 9, 2014, at 12:32 AM, Mars0i  wrote:

 > Thanks for the survey!
 >
 > I have a couple of suggestions/questions:
 >
 > For domains, there are no categories for scientific or other research 
 applications.  For example, I mainly use Clojure for writing agent-based 
 models for academic research.  Would a set of categories in this area be 
 usedful?
 >

 --
 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 unsubscribe from this group and stop receiving emails from it, send 
 an email to clojure+u...@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.


Re: ANN: State of Clojure 2014 Survey - please contribute!!

2014-10-13 Thread Mars0i
On Monday, October 13, 2014 1:50:13 PM UTC-5, Zack Maril wrote:
>
> Next year, I would appreciate questions that measure the demographics of 
> Clojure users be included. Out of the hundreds of people I've heard and 
> seen talking about using Clojure, the vast majority of them have been white 
> men. I've thought about it for a few days now and I can only think of three 
> or four women who I know use Clojure and only a few non white men. I'd like 
> to know if selecting Clojure as my default/main programming language means 
> that I'll be forced to select from a fairly homogeneous group of potential 
> coworkers and miss out on the benefits of a diverse working environment. 
> -Zack 
>

I agree that including demographic questions would be a nice addition.

In the U.S.,   the distribution of sexes and racial/ethnic groups among IT 
people 

 
is pretty skewed toward white males, as I'm sure you would imagine.  Even 
if the percentages of groups among Clojure programmers were the same as 
they are for, say, Java programmers, there would in theory be a lot more 
women and non-white Java programmers to choose from if you wanted to build 
a diverse shop.  That is, in general if you're in a smaller community 
(Clojure), your flexibility is more limited.

(Also, although I think the State of Clojure survey is valuable, no one 
would claim that it uses a reliable sampling method.  That's not a 
criticism at all.  Coming up with a reliable sample would be difficult, in 
practice, The point is that sampling problems can be worse when you're 
dealing with small numbers.  So for example, if one group of people is a 
small but significant minority of all programmers, survey on their 
percentages in a relatively small community, such as the Clojure could be 
wildly inaccurate, even if their percentages were higher among Clojure 
programmers than in the general programming community.

-- 
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.


Diversity (was: State of Clojure 2014 Survey - please contribute!!

2014-10-13 Thread Sean Corfield
On Oct 13, 2014, at 11:50 AM, Zack Maril  wrote:
> I'd like to know if selecting Clojure as my default/main programming language 
> means that I'll be forced to select from a fairly homogeneous group of 
> potential coworkers and miss out on the benefits of a diverse working 
> environment.

One of the reasons I started ClojureBridge - http://clojurebridge.org - was 
because of the lack of diversity in the visible Clojure community and I wanted 
to see if we could do for Clojure what RailsBridge did for the Ruby on Rails 
community. We have been running workshops successfully around the globe now for 
over six months. I've been very pleased with the amount of support 
ClojureBridge has received from the community, and that a strong team has 
emerged to run the organization (so my involvement is now fairly minimal). It 
will take time but I believe we can change the demographics of our community if 
we all want to do so.

In particular, the demographics of your work environment depend almost entirely 
on your hiring process and willingness to train your employees so that's 
definitely an area where you can effect change if you have the will.

Sean Corfield -- http://clojurebridge.org

"ClojureBridge aims to increase diversity within the Clojure community by
 offering free, beginner-friendly Clojure programming workshops for women."



signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: ANN: State of Clojure 2014 Survey - please contribute!!

2014-10-13 Thread Ashton Kemerling
It would've been nice to have back-stats to tell if efforts like Clojure bridge 
are having a statistical impact on the communities makeup.


That being said, I'm sure the clojure bridge folk have their own internal 
metrics to guide their actions and measure outcomes, but it would've been nice 
to see overall.

On Mon, Oct 13, 2014 at 5:10 PM, Mars0i  wrote:

> On Monday, October 13, 2014 1:50:13 PM UTC-5, Zack Maril wrote:
>>
>> Next year, I would appreciate questions that measure the demographics of 
>> Clojure users be included. Out of the hundreds of people I've heard and 
>> seen talking about using Clojure, the vast majority of them have been white 
>> men. I've thought about it for a few days now and I can only think of three 
>> or four women who I know use Clojure and only a few non white men. I'd like 
>> to know if selecting Clojure as my default/main programming language means 
>> that I'll be forced to select from a fairly homogeneous group of potential 
>> coworkers and miss out on the benefits of a diverse working environment. 
>> -Zack 
>>
> I agree that including demographic questions would be a nice addition.
> In the U.S.,   the distribution of sexes and racial/ethnic groups among IT 
> people 
> 
>  
> is pretty skewed toward white males, as I'm sure you would imagine.  Even 
> if the percentages of groups among Clojure programmers were the same as 
> they are for, say, Java programmers, there would in theory be a lot more 
> women and non-white Java programmers to choose from if you wanted to build 
> a diverse shop.  That is, in general if you're in a smaller community 
> (Clojure), your flexibility is more limited.
> (Also, although I think the State of Clojure survey is valuable, no one 
> would claim that it uses a reliable sampling method.  That's not a 
> criticism at all.  Coming up with a reliable sample would be difficult, in 
> practice, The point is that sampling problems can be worse when you're 
> dealing with small numbers.  So for example, if one group of people is a 
> small but significant minority of all programmers, survey on their 
> percentages in a relatively small community, such as the Clojure could be 
> wildly inaccurate, even if their percentages were higher among Clojure 
> programmers than in the general programming community.
> -- 
> 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.


Re: Diversity (was: State of Clojure 2014 Survey - please contribute!!

2014-10-13 Thread Ashton Kemerling
I'm always very proud to tell other people how much effort the clojure 
community is putting into this, especially compared to its size. Keep up the 
good work!


--

Ashton

On Mon, Oct 13, 2014 at 5:41 PM, Sean Corfield  wrote:

> On Oct 13, 2014, at 11:50 AM, Zack Maril  wrote:
>> I'd like to know if selecting Clojure as my default/main programming 
>> language means that I'll be forced to select from a fairly homogeneous group 
>> of potential coworkers and miss out on the benefits of a diverse working 
>> environment.
> One of the reasons I started ClojureBridge - http://clojurebridge.org - was 
> because of the lack of diversity in the visible Clojure community and I 
> wanted to see if we could do for Clojure what RailsBridge did for the Ruby on 
> Rails community. We have been running workshops successfully around the globe 
> now for over six months. I've been very pleased with the amount of support 
> ClojureBridge has received from the community, and that a strong team has 
> emerged to run the organization (so my involvement is now fairly minimal). It 
> will take time but I believe we can change the demographics of our community 
> if we all want to do so.
> In particular, the demographics of your work environment depend almost 
> entirely on your hiring process and willingness to train your employees so 
> that's definitely an area where you can effect change if you have the will.
> Sean Corfield -- http://clojurebridge.org
> "ClojureBridge aims to increase diversity within the Clojure community by
>  offering free, beginner-friendly Clojure programming workshops for women."

-- 
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.


Programmable drones with Clojure/Java support?

2014-10-13 Thread JPH
I watched Carin Meier's great talk last year at OSCon on "The Joy of
flying robots with Clojure"
(http://www.youtube.com/watch?v=Ty9QDqV-_Ak&html5=1), and seen her work
on clj-drone (https://github.com/gigasquid), and have wanted a hackable
drone ever since.

I'm now in a position to purchase one, and was wondering what the
options were if I wanted a programmable drone (ideally with Clojure).

The Google namespace for "clojure drone" is dominated by clj-drone,
which is designed for AR Parrot (http://ardrone2.parrot.com/), but my
searches haven't found much else. Are there any / many alternatives to
AR Parrot if I want to program one in Clojure/Java?

JPH

-- 
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: Programmable drones with Clojure/Java support?

2014-10-13 Thread John Wiseman
Hi, JPH.  I'm interested in clojure + drones too.  I'll try to describe the
relevant parts of the current landscape as I see it.

Unless you're writing your own firmware, at the moment most higher level
drone programming is done with libraries that communicate with a remote
drone, over a comms link:

   - clj-drone . The Clojure
   library by Carin Meier/gigasquid that speaks the AR.Drone protocol.
   Includes some computer vision (with OpenCV) and belief-oriented programming.
   - turboshrimp .  My fork of
   clj-drone.  Fewer dependencies (OpenCV is not required) and can run on
   Android.  Focuses more on drone control/protocol without mixing in higher
   level concepts like belief-oriented programming.  Supports receiving
   telemetry data from AR.Drone, like altitude, speed, heading, GPS location,
   onboard vision capabilities (marker identification), etc.
   - mavjava
   .  A
   Java library that implements the MAVLink protocol, which is the currently
   the leader in the "open drone communications protocol" category.  MAVLink
   is spoken by a lot of different drone systems including APM
   Autopilot/Arducopter/Arduplane  by 3D Robotics
   and PIXHAWK/PX4  by ETH.  The AR.Drone
   supports a subset of MAVLink.
   - Drone API .  This is
   a Python library that speaks MAVLink but provides higher-level
   functionality for management of waypoints, etc.  It's Python, but is
   relevant because MAVLink is a rather low-level, somewhat annoying protocol
   and this code will be useful to look at if you want to build higher level
   abstractions on top of MAVLink.

The AR.Drone is a fun platform because the API is easy, the drone itself
has a lot of functionality (video, wifi, GPS) and can be flown indoors.  It
usually just works. It has an ARM CPU running Linux and has USB, which
makes it easy to cross-compile your own code, run it on-board, and
interface to other hardware.  E.g. see these experiments with connecting a
software defined radio to the drone so it can pick up aircraft
transponders: Augmented Reality Display of Air Traffic for Drones

and Cheap ADS-B on Amateur Drones
.
The AR.Drone is limited by wifi range and payload capability, and it is
closed software and hardware.

APM Autopilot is the current leader of open source drone hacking.  It runs
on lots of different drone platforms (including the AR.Drone) and is open
hardware and software.  The comms links are typically 1 km/line of sight,
and there are a variety of payloads available.  The software is very
capable, though it's not always stable.  The development process is
maturing, but it still has a way to go (today's announcement of the
creation of the Dronecode foundation  is a
good sign).  It uses the NuttX OS on really limited hardware (168 MHz
Cortex M4F CPU w/ 256 KB RAM, compared to the AR.Drone's 1 GHz ARM Cortex
A8  w/ 1 GB RAM), which is annoying, though they have just started
experimenting with a port to Linux on a Beaglebone Black.  An example of
some awesome hacking using APM is the search & rescue work done by
CanberraUAV .

The PX4FMU autopilot is by the same group that came up with the PX4
hardware that APM Autopilot currently uses, and while it's probably not as
mature as APM it seems to have a lot of potential.

My current project is porting this demo I did last year of voice control of
an AR.Drone, using Python running on a laptop, to clojure running on an
Android phone: https://www.youtube.com/watch?v=uhBa11gdbeU


John





On Mon, Oct 13, 2014 at 8:20 PM, JPH  wrote:

> I watched Carin Meier's great talk last year at OSCon on "The Joy of
> flying robots with Clojure"
> (http://www.youtube.com/watch?v=Ty9QDqV-_Ak&html5=1), and seen her work
> on clj-drone (https://github.com/gigasquid), and have wanted a hackable
> drone ever since.
>
> I'm now in a position to purchase one, and was wondering what the
> options were if I wanted a programmable drone (ideally with Clojure).
>
> The Google namespace for "clojure drone" is dominated by clj-drone,
> which is designed for AR Parrot (http://ardrone2.parrot.com/), but my
> searches haven't found much else. Are there any / many alternatives to
> AR Parrot if I want to program one in Clojure/Java?
>
> JPH
>
> --
> 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,

Re: Optimizing code : Fun but now paining me

2014-10-13 Thread Ashish Negi
Thanks juan

I thought that people would prefer the code.. and just wanted to have them 
glanced at it.. and tell if i am missing something basic.

But here is a little list of things i tried :

The problem is that of evaluation calculator expressions containig *,/,+,- 
and (, )
and the grammar for this is right associative for operators and precendence 
is as we know : ->unaray, () > */  > +-

So i think i have implemented recursive descend parser for this ;
This is the general thing about the problem 

And from optimization point of view :

The length of the input string would be 10^5 which means that worst case it 
would take 10^4 numbers
and doing this in repl shows :

user> (time (dotimes [_ 10]
((fn [times]
   (reduce (fn [x y] (rem (* x y) 17))
   1 (map inc (range times)))
   )
 1)
))


"Elapsed time: 35.591417 msecs"

so i think that computing numbers would not be a pain point for me..
so then another problem i think may be is..
with regex that is used for splitting the input string :

(defn split-with-delim [d s]
  (clojure.string/split 
   s (re-pattern (str "(?=" d 
")|(?<=" d
")"

(defn make-calulator-list [s]
  (->> s
   (split-with-delim #"[\/\+\-\*\(\) ]")
   (filter #(not (or (= "" %) (= " " %
   doall
   ))

Doing in REPL :

(time (dotimes [_ 10] (println (count (time (make-calulator-list (time 
(GenerateCalculatorTests 2000))
))

** Input Format : first line - time taken in generating the string , second 
line - regex splitting and third line length of list returned after 
splitting..

"Elapsed time: 289.126875 msecs"
"Elapsed time: 294.026862 msecs"
4121
"Elapsed time: 369.041191 msecs"
"Elapsed time: 372.199697 msecs"
4121
"Elapsed time: 365.559413 msecs"
"Elapsed time: 368.797257 msecs"
4205
"Elapsed time: 289.313576 msecs"
"Elapsed time: 292.487476 msecs"
4157
"Elapsed time: 310.207399 msecs"
"Elapsed time: 313.748384 msecs"
4277
"Elapsed time: 295.76637 msecs"
"Elapsed time: 300.253091 msecs"
4109
"Elapsed time: 302.364814 msecs"
"Elapsed time: 307.980419 msecs"
4145
"Elapsed time: 299.220518 msecs"
"Elapsed time: 302.353367 msecs"
4085
"Elapsed time: 292.046185 msecs"
"Elapsed time: 295.306528 msecs"
4181
"Elapsed time: 289.706317 msecs"
"Elapsed time: 292.845481 msecs"
4133
"Elapsed time: 3149.529342 msecs"


Which shows that since input string is given to me : ( I am generating it 
randomly here ) , so time is around 3 msecs which can also not be a 
bottleneck..

and then their is EulerDivMod which is

(time (dotimes [_ 1000]
  (EulerDivNonMemo 2 (- ToMod 2
"Elapsed time: 21.902319 msecs"

which is also not a bottleneck..

So now i have only My recursive descend parser which is in Function 
Expression, Term and Factor which are not doing computationally big things 
like * or / but what are they doing may be wrong like
-->> I take the list and it flows back and forth between the Expression -> 
Term <-> Factor <-> Expression and so on..
In each function call of above i change the incoming list (creating new one 
cons) and return that..

but 

(time (dotimes [_ 10]
(time (Expression (make-calulator-list
 (time (GenerateCalculatorTests 2000)))

"Elapsed time: 296.071484 msecs"
"Elapsed time: 706.866377 msecs"
"Elapsed time: 286.394266 msecs"
"Elapsed time: 681.03349 msecs"
"Elapsed time: 284.475953 msecs"
"Elapsed time: 676.624133 msecs"
"Elapsed time: 280.001073 msecs"
"Elapsed time: 666.90468 msecs"
"Elapsed time: 283.980191 msecs"
"Elapsed time: 676.609133 msecs"
"Elapsed time: 284.706861 msecs"
"Elapsed time: 684.848012 msecs"
"Elapsed time: 281.24995 msecs"
"Elapsed time: 666.264847 msecs"
"Elapsed time: 297.805466 msecs"
"Elapsed time: 691.719993 msecs"
"Elapsed time: 281.54125 msecs"
"Elapsed time: 684.12371 msecs"
"Elapsed time: 281.470597 msecs"
"Elapsed time: 672.724747 msecs"
"Elapsed time: 6811.717182 msecs"

so it seems it is also taking 400 msecs around for input of size 2000 
whereas maximum can be of 1 like 5 times..
but for that input i go StackOverflow..
however the online judge is showing Timeout for some problems and Runtime 
for 1 problem so i guess i am getting input within my range.. 

but what can be the problem then ?

I also tried adding "doall" in my make-calulator-list ..

Also, I tried using transients in Expression, Term and Factor..
however, i could not find transients for lists... I found for vector ?

Should i use vector ? would that make it faster ? and then use transients.. 
?

-- 
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://gro

Re: Optimizing code : Fun but now paining me

2014-10-13 Thread Baishampayan Ghose
No offence, Ashish, but this code is unreadable, this is horrible.
It'll be better if you first learn Clojure before you look for
optimizations. ~BG

On Mon, Oct 13, 2014 at 6:40 PM, Ashish Negi  wrote:
> I am competing in an online competition and the scenario is like this :
> I coded with my basic knowledge of clojure and got 11 out of 20 testcases
> and others being timed out and one being runtime error..
>
> I started optimizing my code and read
> https://groups.google.com/forum/#!searchin/clojure/performance/clojure/SxT2MaOsip8/xoMkDVHeOqMJ
> and other google articles for performance.. but after that i just managed to
> solve only one more problem and i am stuck at 12 solved.. ( the time for
> each case is 8 seconds max)
> The last 12th was completed in 7.05 secs :) .. just on the border huh... :)
>
> The problem is about that of Solving calculataor expressions like
> "2+3/2/2/(2+8)" mod 10^8+7  gives answer 10^8+3..
> Nevertheless it is the concern but optimizing code is :)
>
> This is current condition of my code :
>
> (ns fpcontest.expression)
>
> (def Term)
> (def Factor)
>
> (def ToMod (int (+ 10 7)))
>
> ;; (int ToMod)
>
> (def toPrint false)
>
> (defn myprintln [& args]
>   ;; (if toPrint
>   ;;   (apply println args))
> )
>
> (defn EulerDivNonMemo [^long x ^long p]
>   (let [ToMod (+ p 2)]
> (loop [num (long 1) toPow p numDouble x]
>   (if (= 0 toPow)
> ;;(do (myprintln " EulerDiv : " num " for " x p))
> num
> (let [numDouble2 (rem (* numDouble numDouble) ToMod)
>   halfToPow (bit-shift-right toPow 1)]
>   (if (odd? toPow)
> (recur (rem (* num numDouble) ToMod)
>halfToPow
>numDouble2)
> (recur num halfToPow numDouble2))
>
>   
>   )
>
> (def EulerDiv (memoize EulerDivNonMemo)
> )
>
> ;; (EulerDiv 2 2)
> ;; (defn TestEulerDiv []
> ;;   (and
> ;;(= 2 (mod (* 4 (EulerDiv 2 (- 3 2))) 3))
> ;;(= 1 (mod (* 2 (EulerDiv 2 (- 3 2))) 3))
> ;;(= 1 (int (mod (* 2 (EulerDiv 2 (- ToMod 2))) ToMod
> ;;   )
>
> ;; (= true (TestEulerDiv))
>
> (defn Expression [lst]
>   (let [term (Term lst)
> ;; p (myprintln term " term for exp " lst)
> sizeTerm (count term)
> evaluateExpr
> (fn [opr lst]
>   (let [expr (Expression (drop 2 lst))
> ;; p (myprintln expr " expr for Expr " lst " and " opr)
> intLst (first lst)]
> (cons (rem (opr intLst
> (first expr))
>ToMod) (drop 1 expr]
> (if (> sizeTerm 2)
>   (if (= (second term) "+")
> (evaluateExpr + term)
> (if (= (second term) "-")
>   (evaluateExpr - term)
>   term)
> )
>   ;; first of term is the answer
>   term
>   )
> ))
>
>
> (defn Term [lst]
>   (let [factor (Factor lst)
> ;; p (myprintln factor " factor for term " lst)
> sizeFactor (count factor)
> evaluateExpr
> (fn [opr lst]
>   (let [expr (Term (drop 2 lst))
> ;;p (myprintln expr " term for expr " lst
> " and " opr)
> intLst (first lst)]
> (cons (rem (opr intLst
> (first expr))
>ToMod) (drop 1 expr) )))]
> (if (> sizeFactor 2)
>   (if (= (second factor) "*")
> (evaluateExpr * factor)
> (if (= (second factor) "/")
>   (let [expr (Term (drop 2 factor))
> fExpr (first expr)]
> (cons (rem (* (first factor) (EulerDiv fExpr (- ToMod 2)))
>ToMod) (drop 1 expr))
> )
>   ;;(evaluateExpr / factor)
>   factor)
> )
>   factor
>   )
> ))
>
> (defn Factor [lst]
>   (let [fFactor (first lst)
> ;;p (myprintln " Factor has : " lst)
> ]
> (if (= fFactor "+")
>   (cons (int (Integer. (second lst))) (rest lst))
>   (if (= fFactor "-")
> (cons (- (int (Integer. (second lst (rest (rest lst)))
> (if (= fFactor "(")
>   ;; remove the '(' and ')'
>   (let [expr (Expression (rest lst))]
> (cons (first expr) (drop 2 expr))
> )
>   ;; (if (= (count lst) 1))
>   (cons  (int (Integer. (first lst))) (rest lst))
>   ;;(myprintln "I do not know where i am... " lst)
>
> )
>   ))
>   )
>
> (defn split-with-delim [d s]
>   (clojure.string/split
>s (re-pattern (str "(?=" d
> ")|(?<=" d
> ")"
>
> (defn make-calulator-list [s]
>   (->> s
>(split-with-delim #"[\/\+\-\*\(\) ]")
>(filter #(not (or (= "" %) (= " " %
>doall
>))
>
> (defn StartRun [FuncToCall inputParse outputParse]
>   (let [lines (line-seq (java.io.BufferedReader. *in*))]
> (outputParse (FuncToCall (inputParse (first lines)
> )
>
>
> and this is how i am testing m