Re: What I'm missing in my Instaparse rules?

2016-06-13 Thread Hussein B.
Oh my ...

You saved my hair! :)

Thanks a lot for your help and time.

On Monday, June 13, 2016 at 12:03:54 PM UTC+2, puzzler wrote:
>
> Looks like you left off a + in your regular expression for String.
>
> On Mon, Jun 13, 2016 at 2:59 AM, Hussein B. <hubag...@gmail.com 
> > wrote:
>
>> Thanks for your help.
>>
>> I tried this new grammar to match characters only:
>>
>> "
>>
>> TEST = OBJECT
>>
>>  = <#'\\s+'>
>>
>> OBJECT = CURLY_OPEN WHITESPACE* STRING WHITESPACE* (WHITESPACE* OBJECT 
>> WHITESPACE*)* CURLY_CLOSE
>>
>>  = <'{'>
>>
>>  = <'}'>
>>
>> STRING = #'[a-zA-Z]'
>>
>> "
>>
>>
>> (parse "{harden {James}}")
>>
>>
>> Parse error at line 1, column 3:
>>
>> {harden {James}}
>>
>>   ^
>>
>> Expected one of:
>>
>> "}" (followed by end-of-string)
>>
>> "{"
>>
>> #"\s+"
>>
>> On Sunday, June 12, 2016 at 10:07:01 PM UTC+2, puzzler wrote:
>>>
>>> Regular expressions are treated with their ordinary Java/Clojure, greedy 
>>> semantics.
>>>
>>> Your regular expression for ITEM doesn't exclude whitespace or } 
>>> characters, so ITEM is matching "Harden }" which leaves no characters left 
>>> to match your grammar's right curly brace requirement.
>>>
>>> => (re-seq #"[^\"]+" "Harden }")
>>> ("Harden }")
>>>
>>> A solution would be to make the regex for ITEM more restrictive.
>>>
>>> On Sun, Jun 12, 2016 at 12:52 PM, Hussein B. <hubag...@gmail.com> wrote:
>>>
>>>> Hello,
>>>>
>>>> I'm playing around Instaparse library, starting very simple.
>>>>
>>>> For input like :
>>>>
>>>> { player }
>>>>
>>>> I created the following parser:
>>>>
>>>> (def ast
>>>>   (ist/parser
>>>> "TEST = OBJECT
>>>>  = <#'\\s+'>
>>>>  = <'{'>
>>>>  = <'}'>
>>>> ITEM = #'[^\"]+'
>>>> OBJECT = CURLY_OPEN WHITESPACE* ITEM WHITESPACE* CURLY_CLOSE"))
>>>>
>>>>
>>>> In the REPL:
>>>>
>>>> user=> (ast "{ Harden } ")
>>>>
>>>> Parse error at line 1, column 12:
>>>>
>>>> { Harden } 
>>>>
>>>>^
>>>>
>>>> Expected one of:
>>>>
>>>> "}" (followed by end-of-string)
>>>>
>>>> #"\s+"
>>>>
>>>>
>>>> Any ideas what I'm doing wrong?
>>>>
>>>> Thanks for help.
>>>>
>>>> -- 
>>>> 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 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: What I'm missing in my Instaparse rules?

2016-06-13 Thread Hussein B.
Thanks for your help.

I tried this new grammar to match characters only:

"

TEST = OBJECT

 = <#'\\s+'>

OBJECT = CURLY_OPEN WHITESPACE* STRING WHITESPACE* (WHITESPACE* OBJECT 
WHITESPACE*)* CURLY_CLOSE

 = <'{'>

 = <'}'>

STRING = #'[a-zA-Z]'

"


(parse "{harden {James}}")


Parse error at line 1, column 3:

{harden {James}}

  ^

Expected one of:

"}" (followed by end-of-string)

"{"

#"\s+"

On Sunday, June 12, 2016 at 10:07:01 PM UTC+2, puzzler wrote:
>
> Regular expressions are treated with their ordinary Java/Clojure, greedy 
> semantics.
>
> Your regular expression for ITEM doesn't exclude whitespace or } 
> characters, so ITEM is matching "Harden }" which leaves no characters left 
> to match your grammar's right curly brace requirement.
>
> => (re-seq #"[^\"]+" "Harden }")
> ("Harden }")
>
> A solution would be to make the regex for ITEM more restrictive.
>
> On Sun, Jun 12, 2016 at 12:52 PM, Hussein B. <hubag...@gmail.com 
> > wrote:
>
>> Hello,
>>
>> I'm playing around Instaparse library, starting very simple.
>>
>> For input like :
>>
>> { player }
>>
>> I created the following parser:
>>
>> (def ast
>>   (ist/parser
>> "TEST = OBJECT
>>  = <#'\\s+'>
>>  = <'{'>
>>  = <'}'>
>> ITEM = #'[^\"]+'
>> OBJECT = CURLY_OPEN WHITESPACE* ITEM WHITESPACE* CURLY_CLOSE"))
>>
>>
>> In the REPL:
>>
>> user=> (ast "{ Harden } ")
>>
>> Parse error at line 1, column 12:
>>
>> { Harden } 
>>
>>^
>>
>> Expected one of:
>>
>> "}" (followed by end-of-string)
>>
>> #"\s+"
>>
>>
>> Any ideas what I'm doing wrong?
>>
>> Thanks for help.
>>
>> -- 
>> 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.


What I'm missing in my Instaparse rules?

2016-06-12 Thread Hussein B.
Hello,

I'm playing around Instaparse library, starting very simple.

For input like :

{ player }

I created the following parser:

(def ast
  (ist/parser
"TEST = OBJECT
 = <#'\\s+'>
 = <'{'>
 = <'}'>
ITEM = #'[^\"]+'
OBJECT = CURLY_OPEN WHITESPACE* ITEM WHITESPACE* CURLY_CLOSE"))


In the REPL:

user=> (ast "{ Harden } ")

Parse error at line 1, column 12:

{ Harden } 

   ^

Expected one of:

"}" (followed by end-of-string)

#"\s+"


Any ideas what I'm doing wrong?

Thanks for help.

-- 
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 Zipper isn't deleting what I thought is going to delete

2015-08-27 Thread Hussein B.
Thanks a lot Moe for your help. I always appreciate your patience and 
skills.

Would you explain why your zipper works in this case?

Thanks again.

On Thursday, August 27, 2015 at 12:11:14 PM UTC+2, Moe Aboulkheir wrote:

 Hussein, 

 Making this change to the zipper definition: 

 (z/zipper #(get % children) #(get % children) (fn [p c] (assoc p 
 children c)) {children z}) 

 looks like it'll do the right thing here. 

 Take care, 
 Moe 

 On Thu, Aug 27, 2015 at 11:03 AM, Hussein B. hubag...@gmail.com 
 javascript: wrote: 
  The modify function 
  
  (defn modify [loc] 
   (- loc z/remove)) 
  
  
  On Thursday, August 27, 2015 at 11:58:31 AM UTC+2, Hussein B. wrote: 
  
  Hi, 
  
  I'm trying to remove an element from nested data structure (nesting in 
  unknown, so I'm trying to come up with a generic solution: 
  
   (def z [ 
{a {b 1 c 2} 
 children [{a {b 3 c 4} 
  children []}]} 
{a {b 5 c 6} 
 children []} 
{a {b 7 c 8} 
 children [{a {b 9 c 10} 
  children []} 
 {a {b 11 c 12} 
  children [{a {b 13 c 14} children []} 
  {a {b 15 c 16} children []}]}]}]) 
  
  
  
  
  (def loz (z/zipper #(get % children) #(get % children) (fn [_ x ] 
 x) 
  {children z})) 
  
  
  
  (defn to-change? [loc] 
   (if (= 11 (get-in (z/node loc) [a b])) 
   true 
   false)) 
  
  
  (loop [loc loz] 
  (if (z/end? loc) 
(z/root loc) 
(recur (z/next 
(cond (to-change? loc) 
  (modify loc) 
  :else loc) 
  
  
  That gives a very wrong output: 
  
  ({a {b 1, c 2}, children [{a {b 3, c 4}, children []}]} 
  {a {b 5, c 6}, children []} ({a {b 9, c 10}, children 
 []})) 
  
  
  
  Parent {a {b 7 c 8} is getting deleted which is wrong. 
  
  What I'm doing wrong? 
  
  Thanks for help and time. 
  
  -- 
  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 
 javascript: 
  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 javascript: 
  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 javascript:. 
  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.


My Zipper isn't deleting what I thought is going to delete

2015-08-27 Thread Hussein B.
Hi,

I'm trying to remove an element from nested data structure (nesting in 
unknown, so I'm trying to come up with a generic solution:

 (def z [
  {a {b 1 c 2}
   children [{a {b 3 c 4}
children []}]}
  {a {b 5 c 6}
   children []}
  {a {b 7 c 8}
   children [{a {b 9 c 10}
children []}
   {a {b 11 c 12}
children [{a {b 13 c 14} children []} {a 
{b 15 c 16} children []}]}]}])




(def loz (z/zipper #(get % children) #(get % children) (fn [_ x ] x) 
{children z}))



(defn to-change? [loc]
 (if (= 11 (get-in (z/node loc) [a b]))
 true
 false))


(loop [loc loz]
(if (z/end? loc)
  (z/root loc)
  (recur (z/next
  (cond (to-change? loc)
(modify loc)
:else loc)


That gives a very wrong output:

({a {b 1, c 2}, children [{a {b 3, c 4}, children []}]} {a 
{b 5, c 6}, children []} ({a {b 9, c 10}, children []}))



Parent {a {b 7 c 8} is getting deleted which is wrong.

What I'm doing wrong?

Thanks for help and time.

-- 
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 Zipper isn't deleting what I thought is going to delete

2015-08-27 Thread Hussein B.
The modify function

(defn modify [loc]
 (- loc z/remove))


On Thursday, August 27, 2015 at 11:58:31 AM UTC+2, Hussein B. wrote:

 Hi,

 I'm trying to remove an element from nested data structure (nesting in 
 unknown, so I'm trying to come up with a generic solution:

  (def z [
   {a {b 1 c 2}
children [{a {b 3 c 4}
 children []}]}
   {a {b 5 c 6}
children []}
   {a {b 7 c 8}
children [{a {b 9 c 10}
 children []}
{a {b 11 c 12}
 children [{a {b 13 c 14} children []} {
 a {b 15 c 16} children []}]}]}])




 (def loz (z/zipper #(get % children) #(get % children) (fn [_ x ] x) 
 {children z}))



 (defn to-change? [loc]
  (if (= 11 (get-in (z/node loc) [a b]))
  true
  false))


 (loop [loc loz]
 (if (z/end? loc)
   (z/root loc)
   (recur (z/next
   (cond (to-change? loc)
 (modify loc)
 :else loc)


 That gives a very wrong output:

 ({a {b 1, c 2}, children [{a {b 3, c 4}, children []}]} {
 a {b 5, c 6}, children []} ({a {b 9, c 10}, children []}))



 Parent {a {b 7 c 8} is getting deleted which is wrong.

 What I'm doing wrong?

 Thanks for help and time.


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


How to move an element within a vector?

2015-08-25 Thread Hussein B.
Hi,

For a vector like [A B C D E], how to remove an element to a specific 
location? For example [A D B C E] ?

I thought about converting the vector into array but I would feel bad if I 
did that.

What would be the idiomatic way to do that in Clojure?

Thanks for help and time.

-- 
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 I'm getting NPE with zipper/next?

2015-08-24 Thread Hussein B.
Oh,

I defined my zipper as:

 (def loz (z/zipper #(contains? % children) #(get % children) (fn [_ x 
] x) {children z}))

But is throwing an exception.

This one works:

 (def loz (z/zipper #(get % children) #(get % children) (fn [_ x ] x) 
{children z}))



On Monday, August 24, 2015 at 4:08:17 PM UTC+2, Moe Aboulkheir wrote:

 Went off half-cocked there.  The remainder:

 (edit-parents
   #(= 10 (get-in % [a b]))
   #(update % children reverse),
   data-zipper)

 Would have the effect of reversing the order of the children in each node 
 which possesses a child having a b attribute set to 10.  You could 
 probably express this much better with a library which allows locations in 
 data structures to be described in an XPath-like way (and your data 
 actually looks a lot like it is the result of parsing markup - see 
 clojure.data.xml and xml-zip if so) -- or there's probably some better 
 zipper approach that somebody who's really into zippers could come up with.

 If you don't want to depend on an external library, and you lose your 
 enthusiasm for zippers, you could write a function which goes over the 
 structure and returns pairs of [[path] attributes], where path is a 
 sequence of keys/indices suitable for passing to update-in/assoc-in etc., 
 and attributes is the value of the a key at each level.  

 In general, if there aren't multiple keys similar to a in each map (i.e. 
 it's always some value pointing to some map, and the value is not always 
 a), this kind of layout may be easier (e.g. to destructure)

 {:tag a :attrs {:b 10} :children [...]}}

 Take care,
 Moe


-- 
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 I'm getting NPE with zipper/next?

2015-08-24 Thread Hussein B.
Hi Moi,

Thanks a lot for your patience and help.

I tried this so far:

 (defn edit-parents [editable? edit loc]
  (loop [loc loc]
(if (z/end? loc)
  (z/root loc)
  (if (editable? (z/node loc))
(recur (- loc z/up (z/edit edit) z/up z/next))
(recur (z/next loc))


(defn predicate [x]
  (and
  (vector? x)
  (some #(= 10 (get-in % [a b])) x)))


(defn operation [x] (update x children reverse))



(edit-parents predicate operation (z/seq-zip {children z}))



But I'm still getting the same data. What I'm doing wrong?

Thanks a lot.


On Monday, August 24, 2015 at 4:08:17 PM UTC+2, Moe Aboulkheir wrote:

 Went off half-cocked there.  The remainder:

 (edit-parents
   #(= 10 (get-in % [a b]))
   #(update % children reverse),
   data-zipper)

 Would have the effect of reversing the order of the children in each node 
 which possesses a child having a b attribute set to 10.  You could 
 probably express this much better with a library which allows locations in 
 data structures to be described in an XPath-like way (and your data 
 actually looks a lot like it is the result of parsing markup - see 
 clojure.data.xml and xml-zip if so) -- or there's probably some better 
 zipper approach that somebody who's really into zippers could come up with.

 If you don't want to depend on an external library, and you lose your 
 enthusiasm for zippers, you could write a function which goes over the 
 structure and returns pairs of [[path] attributes], where path is a 
 sequence of keys/indices suitable for passing to update-in/assoc-in etc., 
 and attributes is the value of the a key at each level.  

 In general, if there aren't multiple keys similar to a in each map (i.e. 
 it's always some value pointing to some map, and the value is not always 
 a), this kind of layout may be easier (e.g. to destructure)

 {:tag a :attrs {:b 10} :children [...]}}

 Take care,
 Moe


-- 
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 I'm getting NPE with zipper/next?

2015-08-24 Thread Hussein B.
The result now is as desired:

({a {b 1, c 2}, children [{a {b 3, c 4}, children []}]} 
{a {b 5, c 6}, children []} {a {b 7, c 8}, children ({a 
{b 10, c 10}, children []} {a {b 9, c 10}, children []})})

But now the updated children is using list notation, not vector. Is it ok 
or it is for displaying purposes?

Thanks a lot for your help. I was burning to know how to do that with 
Zippers. I want to understand zippers.

On Monday, August 24, 2015 at 4:08:17 PM UTC+2, Moe Aboulkheir wrote:

 Went off half-cocked there.  The remainder:

 (edit-parents
   #(= 10 (get-in % [a b]))
   #(update % children reverse),
   data-zipper)

 Would have the effect of reversing the order of the children in each node 
 which possesses a child having a b attribute set to 10.  You could 
 probably express this much better with a library which allows locations in 
 data structures to be described in an XPath-like way (and your data 
 actually looks a lot like it is the result of parsing markup - see 
 clojure.data.xml and xml-zip if so) -- or there's probably some better 
 zipper approach that somebody who's really into zippers could come up with.

 If you don't want to depend on an external library, and you lose your 
 enthusiasm for zippers, you could write a function which goes over the 
 structure and returns pairs of [[path] attributes], where path is a 
 sequence of keys/indices suitable for passing to update-in/assoc-in etc., 
 and attributes is the value of the a key at each level.  

 In general, if there aren't multiple keys similar to a in each map (i.e. 
 it's always some value pointing to some map, and the value is not always 
 a), this kind of layout may be easier (e.g. to destructure)

 {:tag a :attrs {:b 10} :children [...]}}

 Take care,
 Moe


-- 
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 I'm getting NPE with zipper/next?

2015-08-24 Thread Hussein B.
I see.

I tried to add more nested elements into my original structure but now the 
output isn't correct.

My question is:

Is it possible to implement a generic algorithm with Zippers that could 
traverse as long as needed and update an item? Maybe I'm doing zippers 
wrong in this case.

Thanks a lot for your time and your helpful answers. Now I started to 
understand zippers, thanks to you.


On Monday, August 24, 2015 at 7:36:17 PM UTC+2, Moe Aboulkheir wrote:

 Hussein, 


 On Mon, Aug 24, 2015 at 5:40 PM, Hussein B. hubag...@gmail.com 
 javascript: wrote: 

  But now the updated children is using list notation, not vector. Is it 
 ok or 
  it is for displaying purposes? 

 The collection type is now different, as the example I gave uses 
 reverse as the transform, which is a generic sequence function - it 
 doesn't care that it was passed a vector.  It may not matter - it 
 depends on how you're using the sequences.  In this specific case, 
 modifying the transform in the example to #(update % children (comp 
 vec reverse)) will result in a vector, though there are more general 
 ways of doing this without baking the collection type in everywhere 
 (into (empty x) (reverse x)). 

 Take care, 
 Moe 


-- 
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 I'm getting NPE with zipper/next?

2015-08-24 Thread Hussein B.
Hi Moe,

I have this structure:

[{a {b 1 c 2} 
   children [{a {b 3 c 4} children []}]}
  {a {b 5 c 6} children []}
  {a {b 7 c 8}
children [{a {b 9 c 10} children []} {a {b 10 c 10} 
children []}]}]

That is only a sample, the actual data is bigger is properly more one or 
two nesting in the children attribute.

I need to find a map by a criteria, say where b = 10 ({a {b 10 c 10} 
children []})

Once it is found, I need to change its position within its parent. The 
parent is {a {b 7 c 8} 

I know that zippers are for editing data structures but I'm not sure how to 
do it.

Thanks for help and time.

On Friday, August 21, 2015 at 7:14:13 PM UTC+2, Moe Aboulkheir wrote:

 Hussein, 

 I don't get an NPE passing that to traverse, but nothing much 
 interesting happens either.  The top-level data structure (and the 
 vectors within children) aren't associative, and so don't pass the 
 branch? test (contains? % children). 

 You could certainly extend the zipper to cover both cases, but there 
 may well be a more compact way to accomplish your goal.  What do you 
 want to do with the piece of data? 

 Take care, 
 Moe 

 On Fri, Aug 21, 2015 at 5:57 PM, Hussein B. hubag...@gmail.com 
 javascript: wrote: 
  Here is my zipper: 
  
   (z/zipper #(contains? % children) #(get % children)  (fn [_ c] c) 
 s) 
  
  On Friday, August 21, 2015 at 6:49:25 PM UTC+2, Moe Aboulkheir wrote: 
  
  Hussein, 
  
  How are you constructing your zipper, before passing it to traverse? 
  Note that clojure.zip doesn't work on arbitrary data structures 
  without being given some information about how to descend 
  into/construct nodes, etc. - i.e. z/next expects a zipper, and your 
  data structure isn't a zipper, but an input to a zipper.  Unless 
  you've written a zipper you omitted from your post, zipping over maps, 
  in particular, may not be as convenient as you're imagining. 
  https://clojuredocs.org/clojure.zip/zipper has helpful examples in it. 
  
  Take care, 
  Moe 
  
  On Fri, Aug 21, 2015 at 5:06 PM, Hussein B. hubag...@gmail.com 
 wrote: 
   Hi, 
   
   I changed println to z/node , this time I'm getting: 
   
   NullPointerException   clojure.zip/branch? (zip.clj:73) 
   
   On Friday, August 21, 2015 at 5:56:10 PM UTC+2, Moe Aboulkheir wrote: 
   
   Hussein, 
   
   The println inside (recur) will return nil. 
   
   Take care, 
   Moe 
   
   On Fri, Aug 21, 2015 at 4:35 PM, Hussein B. hubag...@gmail.com 
 wrote: 
Hi, 

I have this structure: 

(def s [{n {id a} d 2 children [{n {id c} d 4 
children 
[]}]} {n {id b} d 3 children []}]) 



And I wrote a function with zippers to traverse it: 

 (defn traverse [col] 
  (loop [z col] 
(if (= (z/next z) z) 
z 
(if (z/branch? z) 
  (recur (z/next z)) 
  (recur (- z println z/next)) 


But I'm getting: NullPointerException   clojure.zip/next 
(zip.clj:236) 

Any ideas? 

Thanks for help. 

-- 
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 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 clo...@googlegroups.com 
 javascript: 
  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 javascript: 
  For more options, visit this group at 
  http://groups.google.com/group

Why I'm getting NPE with zipper/next?

2015-08-21 Thread Hussein B.
Hi,

I have this structure:

(def s [{n {id a} d 2 children [{n {id c} d 4 children 
[]}]} {n {id b} d 3 children []}])



And I wrote a function with zippers to traverse it:

 (defn traverse [col]
  (loop [z col]
(if (= (z/next z) z)
z
(if (z/branch? z)
  (recur (z/next z))
  (recur (- z println z/next))


But I'm getting: NullPointerException   clojure.zip/next (zip.clj:236)

Any ideas?

Thanks for help.

-- 
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 I'm getting NPE with zipper/next?

2015-08-21 Thread Hussein B.
Hi,

I changed println to z/node , this time I'm getting:

NullPointerException   clojure.zip/branch? (zip.clj:73)

On Friday, August 21, 2015 at 5:56:10 PM UTC+2, Moe Aboulkheir wrote:

 Hussein, 

 The println inside (recur) will return nil. 

 Take care, 
 Moe 

 On Fri, Aug 21, 2015 at 4:35 PM, Hussein B. hubag...@gmail.com 
 javascript: wrote: 
  Hi, 
  
  I have this structure: 
  
  (def s [{n {id a} d 2 children [{n {id c} d 4 
 children 
  []}]} {n {id b} d 3 children []}]) 
  
  
  
  And I wrote a function with zippers to traverse it: 
  
   (defn traverse [col] 
(loop [z col] 
  (if (= (z/next z) z) 
  z 
  (if (z/branch? z) 
(recur (z/next z)) 
(recur (- z println z/next)) 
  
  
  But I'm getting: NullPointerException   clojure.zip/next (zip.clj:236) 
  
  Any ideas? 
  
  Thanks for help. 
  
  -- 
  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 
 javascript: 
  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 javascript: 
  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 javascript:. 
  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: How can find something inside heavily nested data structure ?

2015-08-21 Thread Hussein B.
Yes, that does the job. Thanks for your help and time.

On Thursday, August 20, 2015 at 12:21:47 AM UTC+2, Alan Forrester wrote:

 On 19 Aug 2015, at 18:08, Hussein B. hubag...@gmail.com javascript: 
 wrote: 

  Here is more concrete example 
  
  (def s [{n {id a} d 2 children [{n {id c} d 4 
 children nil}]} {n {id b} d 3 children nil}]) 
  
  
  I want to find the map that has value c for id. If found, I need to 
 return the map {n {id c} d 4 children nil} 

 One way to do this follows. First get all of the sub-maps, which you can 
 do with the following two functions: 

 (defn get-lower [x] (tree-seq coll? identity x)) 

 (defn get-maps-from-lower [x] (filter map? (get-lower x))). 

 The first function gets all of the lower level colls, the second picks the 
 maps out of those colls. 

 You then need a function that will rummage round in a coll x looking to 
 see if it has the relevant element r: 

 (defn rummager [x r] (some #(= r %) x)) 

 You then use rummager to get maps with the appropriate val 

 (defn get-map-with-val [v x] 
   (first (filter #(rummager (vals %) v) (get-maps-from-lower x. 

 Trying this out in the repl I get 

 = (get-map-with-val {id c} s) 

 {d 4, n {id c}, children nil} 

 which I believe is the result you wanted. 

 Alan

-- 
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 I'm getting NPE with zipper/next?

2015-08-21 Thread Hussein B.
Here is my zipper:

 (z/zipper #(contains? % children) #(get % children)  (fn [_ c] c) s)

On Friday, August 21, 2015 at 6:49:25 PM UTC+2, Moe Aboulkheir wrote:

 Hussein, 

 How are you constructing your zipper, before passing it to traverse? 
 Note that clojure.zip doesn't work on arbitrary data structures 
 without being given some information about how to descend 
 into/construct nodes, etc. - i.e. z/next expects a zipper, and your 
 data structure isn't a zipper, but an input to a zipper.  Unless 
 you've written a zipper you omitted from your post, zipping over maps, 
 in particular, may not be as convenient as you're imagining. 
 https://clojuredocs.org/clojure.zip/zipper has helpful examples in it. 

 Take care, 
 Moe 

 On Fri, Aug 21, 2015 at 5:06 PM, Hussein B. hubag...@gmail.com 
 javascript: wrote: 
  Hi, 
  
  I changed println to z/node , this time I'm getting: 
  
  NullPointerException   clojure.zip/branch? (zip.clj:73) 
  
  On Friday, August 21, 2015 at 5:56:10 PM UTC+2, Moe Aboulkheir wrote: 
  
  Hussein, 
  
  The println inside (recur) will return nil. 
  
  Take care, 
  Moe 
  
  On Fri, Aug 21, 2015 at 4:35 PM, Hussein B. hubag...@gmail.com 
 wrote: 
   Hi, 
   
   I have this structure: 
   
   (def s [{n {id a} d 2 children [{n {id c} d 4 
   children 
   []}]} {n {id b} d 3 children []}]) 
   
   
   
   And I wrote a function with zippers to traverse it: 
   
(defn traverse [col] 
 (loop [z col] 
   (if (= (z/next z) z) 
   z 
   (if (z/branch? z) 
 (recur (z/next z)) 
 (recur (- z println z/next)) 
   
   
   But I'm getting: NullPointerException   clojure.zip/next 
 (zip.clj:236) 
   
   Any ideas? 
   
   Thanks for help. 
   
   -- 
   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 clo...@googlegroups.com 
 javascript: 
  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 javascript: 
  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 javascript:. 
  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.


How can find something inside heavily nested data structure ?

2015-08-19 Thread Hussein B.
Hi,

I have transformed JSON response into the equivalent data structure using 
Cheshire library.

The result is a huge nested data structure , mostly vectors and maps. It is 
actually a tree.

How to find a property that is nested deep inside the tree ? For example 
I'm search for the node that has the value zyx for property uuid.

What I'm supposed to use? Something like zipper or walk? or something 
simpler is available?

Thanks for help.

-- 
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: How can find something inside heavily nested data structure ?

2015-08-19 Thread Hussein B.
Each node is represented as map:

{prop1 prop2 prop3 children}

children is a vector of nested nodes

[
prop1
prop2
children 
 [
 {prop1 prop2 children []}
 {prop1 prop2 children [{new-node} {new-node} ... {another-node}]
 ]
 [
 {prop1 prop2 children []}
 {prop1 prop2 children [{new-node} {new-node}]
 ]
]


I need to traverse the structure to find the node (the map data structure) 
that has a specific value, say for prop2.

I tried:

(defn is-it-node? [coll]
  (not (nil? (get coll children

(filter #(= 12345 (get % prop2)) (tree-seq #(is-it-node? %) identity 
navigation-tree))


But I'm getting nothing actually.


On Wednesday, August 19, 2015 at 5:36:42 PM UTC+2, Gary Verhaegen wrote:

 If you want more specific answers, you'll need to describe the 
 structure of your tree. In particular, what is the relationship 
 between your conceptual nodes and your data structures (vectors and 
 maps)? 

 On 19 August 2015 at 17:26, Andy- andre...@gmail.com javascript: 
 wrote: 
  I have yet to evaluate it myself but this might do help you: 
  
  https://github.com/nathanmarz/specter 
  
  
  On Wednesday, August 19, 2015 at 10:18:06 AM UTC-4, Hussein B. wrote: 
  
  Hi, 
  
  I have transformed JSON response into the equivalent data structure 
 using 
  Cheshire library. 
  
  The result is a huge nested data structure , mostly vectors and maps. 
 It 
  is actually a tree. 
  
  How to find a property that is nested deep inside the tree ? For 
 example 
  I'm search for the node that has the value zyx for property uuid. 
  
  What I'm supposed to use? Something like zipper or walk? or something 
  simpler is available? 
  
  Thanks for help. 
  
  -- 
  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 
 javascript: 
  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 javascript: 
  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 javascript:. 
  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: How can find something inside heavily nested data structure ?

2015-08-19 Thread Hussein B.
Here is more concrete example

(def s [{n {id a} d 2 children [{n {id c} d 4 children 
nil}]} {n {id b} d 3 children nil}])


I want to find the map that has value c for id. If found, I need to 
return the map {n {id c} d 4 children nil}

On Wednesday, August 19, 2015 at 5:36:42 PM UTC+2, Gary Verhaegen wrote:

 If you want more specific answers, you'll need to describe the 
 structure of your tree. In particular, what is the relationship 
 between your conceptual nodes and your data structures (vectors and 
 maps)? 

 On 19 August 2015 at 17:26, Andy- andre...@gmail.com javascript: 
 wrote: 
  I have yet to evaluate it myself but this might do help you: 
  
  https://github.com/nathanmarz/specter 
  
  
  On Wednesday, August 19, 2015 at 10:18:06 AM UTC-4, Hussein B. wrote: 
  
  Hi, 
  
  I have transformed JSON response into the equivalent data structure 
 using 
  Cheshire library. 
  
  The result is a huge nested data structure , mostly vectors and maps. 
 It 
  is actually a tree. 
  
  How to find a property that is nested deep inside the tree ? For 
 example 
  I'm search for the node that has the value zyx for property uuid. 
  
  What I'm supposed to use? Something like zipper or walk? or something 
  simpler is available? 
  
  Thanks for help. 
  
  -- 
  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 
 javascript: 
  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 javascript: 
  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 javascript:. 
  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.


How to transform this structure idiomaticlly in Clojure?

2015-08-18 Thread Hussein B.
Hi,

I have the following structure. Node has a string properly and a vector 
nodes and of course, each node has a string a property and a vector of 
nodes.

So I created the following record:

(defrecord Node [title childs])

And I have the following JSON response:

node
 string
 [
 node1 [
   nn1
   nn2
   ..
   nnn]
 node2 [
   nn1
   nn2
   ..
   nnn]
]

What I want to achieve is to transform that JSON response into the 
equivalent structure with Node recored type.

Thanks for help and time.

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


As framework creator, how would you get user defined specific functions/macros?

2014-11-20 Thread Hussein B.
Hi,

Lets say that you are framework creator and to use your framework, you 
defined a macro called defcontroller where the users of your framework add 
their logic.

You -as framework creator- how would you load user defined source code 
files and collect their defcontroller definitions?

Thanks for help.

-- 
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: Understanding how a collection reduce itself

2014-10-09 Thread Hussein B.
Thank you all and especially @James. That is exactly what I'm missing.
Thanks again for help.

On Wednesday, September 24, 2014 5:51:09 PM UTC+2, James Reeves wrote:

 Reducers primarily have two benefits:

 1. You don't need to create intermediate seqs
 2. You can use them to perform a parallel fold

 When you use clojure.core/map, it creates a lazy seq. When you use 
 clojure.core.reducers/map, it returns a small reified object that 
 implements CollReduce.

 Perhaps the best way to understand what's going on is to start with the 
 normal seq functions. For instance, consider this code:

 (let [ys (map inc xs)]
   (filter even? ys))

 In this example, an intermediate seq, ys, needs to be constructed.

 We can avoid this intermediate seq by using a reduce that combines both 
 steps:

 (reduce (fn [r x] (if (even? x) (conj r (inc x)) r) [] xs)

 The problem with this approach is that it's rather complected. What we 
 need is something that resolves to a reduce, but can be combined like map 
 and filter. This is where reducers come in.

 The main idea is to factor out that pesky conj, so we can separating the 
 reduction from the implementation details of the collection. So we can take 
 the inner reducing function:

 (fn [r x] (if (even? x) (conj r (inc x)) r)

 And then factor out conj:

 (fn [f] (fn [r x] (if (even? x) (f r (inc x)) r))

 We can then split out the filter and map to get two functions

 (fn [f] (fn [r x] (if (even? x) (f r x) r))
 (fn [f] (fn [r x] (f r (inc x)))

 And then take out even? and inc to get generic filter and map functions:

 (defn filterer [xf] (fn [f] (fn [r x] (if (xf x) (f r x) r))
 (defn mapper   [xf] (fn [f] (fn [r x] (f r (xf x)))

 So now we have the essence of map and filter, but we've removed the 
 implementation details of the collection. 

 Next we just need to figure out how to use these highly abstracted 
 functions. If we just want to use one of the functions, we can do so like 
 this:

 ((mapper inc) conj)

 This returns a function:

 (fn [r x] (conj r (inc x)))

 If we want to combine map and filter, we need an expression like:

 (fn [r x] (if (even? x) (conj r (inc x)) r))

 We can do this by passing the result of the mapping function into filterer 
 as f:

 ((filterer even?) ((mapper inc) conj))

 Or, we could use comp to compose the two functions, then apply conj, since 
 (f (g x)) is the same as ((comp f g) x):

 ((comp (filterer even?) (mapper inc)) conj))

 Now we can can finally create our efficient map/filter in a clean way:

 (let [f (comp (filterer even?)
   (mapper inc))]
   (reduce (f conj) [] xs))

 The reducer library goes one step further, and uses protocols to make it a 
 little nicer to use, but the mechanics are more or less the same.

 - James


 On 24 September 2014 15:30, Hussein B. hubag...@gmail.com javascript: 
 wrote:

 To elaborate more,
 I know that with reducers, map for example isn't going to create the 
 resulting sequence by using cons. That is clear to me.
 But, if the collections is going to call cons while reducing itself, then 
 I'm not sure what is the benefit of reducers (besides it makes sense and 
 makes a nice abstraction).

 Thanks.

 On Wednesday, September 24, 2014 2:58:18 PM UTC+2, Aleš Roubíček wrote:

 Resulting function is passed to reduction function as an recipe, how to 
 process the data. Collections implements CollReduce protocol. When you call 
 reduce function it will delegate the work to concrete implementation of the 
 protocol.

  -- 
 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 
 javascript:
 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 javascript:
 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 javascript:.
 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: Understanding how a collection reduce itself

2014-09-24 Thread Hussein B.
When the collection is reducing itself, it is going to create a sequence 
and call cons, conj or something like.
If this is true, then I'm not sure what reducers is bringing to the table.
Because according to what I read, by using reducers, map/filter functions 
aren't going to create and allocate cons.


On Wednesday, September 24, 2014 2:58:18 PM UTC+2, Aleš Roubíček wrote:

 Resulting function is passed to reduction function as an recipe, how to 
 process the data. Collections implements CollReduce protocol. When you call 
 reduce function it will delegate the work to concrete implementation of the 
 protocol.

-- 
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: Understanding how a collection reduce itself

2014-09-24 Thread Hussein B.
To elaborate more,
I know that with reducers, map for example isn't going to create the 
resulting sequence by using cons. That is clear to me.
But, if the collections is going to call cons while reducing itself, then 
I'm not sure what is the benefit of reducers (besides it makes sense and 
makes a nice abstraction).

Thanks.

On Wednesday, September 24, 2014 2:58:18 PM UTC+2, Aleš Roubíček wrote:

 Resulting function is passed to reduction function as an recipe, how to 
 process the data. Collections implements CollReduce protocol. When you call 
 reduce function it will delegate the work to concrete implementation of the 
 protocol.

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


Understanding how a collection reduce itself

2014-09-23 Thread Hussein B.
Hi,

I spent a considerable time trying to understand reducers. I got the 
concept of how the map/filter function will return a function and it is not 
going to iterate over a sequence and it is not going to create a new 
sequence.

The missing part though, who is creating the sequence?
They say a collection now knows how to reduce it self but I'm not getting 
that. I tried and I failed.

Would you please help with that?

Thanks for help and time.

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


How to know if an agent throw an exception?

2014-06-20 Thread Hussein B.
Hi,

When using send-off of an Agent, how to know if any exception is happened? 
Since AFAIK, agents are executed in different thread.

Currently, I'm calling (agent-error) but nothing is logged. Maybe nothing 
went wrong but some how I'm sure something went wrong.

Thank you.

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


How to tackle this concurrency problem?

2014-06-20 Thread Hussein B.
Hi,

I have a ref that saves the ID of last processed event.

Of course, I'm using Clojure STM facility. The problem now is I can't 
control the value of the ref. Due massive concurrency, it is updated and my 
logic is broken.

How to guard, and really guard the update of that ref?

Should I do (locking) ?

Thanks for help and time.

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


When to use (ensue) ?

2014-06-19 Thread Hussein B.
Hi,

When dealing with Clojure ref types, when to use (ensure) ?

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.


How to add elements to a vector that is the value of a map key?

2014-06-17 Thread Hussein B.
Hi,

This is a very basic question, so be patient please! :)

I have an empty map where key is an integer and the value is a vector.

How I can add an element to the vector of a specific key?

For example:

{1 [11]}

Then

{1 [ 11 22]}

Thanks for help and time.

-- 
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: How to add elements to a vector that is the value of a map key?

2014-06-17 Thread Hussein B.
Please keep in mind that I'm starting from an empty map. So, I'm looking 
for an idiomatic Clojure code to achieve my purpose where if the map 
doesn't has that specific key, it will create an entry of that key and add 
the value to the newly created vector. And if the key exists, then add the 
value to the existing vector.


On Tuesday, June 17, 2014 7:21:43 PM UTC+2, Hussein B. wrote:

 Hi,

 This is a very basic question, so be patient please! :)

 I have an empty map where key is an integer and the value is a vector.

 How I can add an element to the vector of a specific key?

 For example:

 {1 [11]}

 Then

 {1 [ 11 22]}

 Thanks for help and time.


-- 
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: How to add elements to a vector that is the value of a map key?

2014-06-17 Thread Hussein B.
Thanks, it works.

In case, my initial map is a ref type

(def m (ref { } ))

Why this isn't working?

(dosync 

   (alter m #(update-in @v [1] (fnil conj [ ])) 11))

On Tuesday, June 17, 2014 7:55:14 PM UTC+2, Mauricio Aldazosa wrote:

 For updating the value of a map given a key you can use update-in:

 user (update-in {1 [11]} [1] conj 22)
 {1 [11 22]}

 Now, to handle the case when the key is not present, you can use fnil:

 user (update-in {} [1] (fnil conj []) 22)
 {1 [22]}
 ​
 Cheers,
 Mauricio


-- 
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: How to add elements to a vector that is the value of a map key?

2014-06-17 Thread Hussein B.
Oh, this works

 (dosync (alter v #(update-in %1 [1] (fnil conj [ ]) %2) 33))

On Tuesday, June 17, 2014 8:05:10 PM UTC+2, Hussein B. wrote:

 Thanks, it works.

 In case, my initial map is a ref type

 (def m (ref { } ))

 Why this isn't working?

 (dosync 

(alter m #(update-in @v [1] (fnil conj [ ])) 11))

 On Tuesday, June 17, 2014 7:55:14 PM UTC+2, Mauricio Aldazosa wrote:

 For updating the value of a map given a key you can use update-in:

 user (update-in {1 [11]} [1] conj 22)
 {1 [11 22]}

 Now, to handle the case when the key is not present, you can use fnil:

 user (update-in {} [1] (fnil conj []) 22)
 {1 [22]}
 ​
 Cheers,
 Mauricio



-- 
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: How to add elements to a vector that is the value of a map key?

2014-06-17 Thread Hussein B.
Nice! :)

Thanks all for help.

On Tuesday, June 17, 2014 9:00:06 PM UTC+2, Thomas Heller wrote:



 On Tuesday, June 17, 2014 8:16:36 PM UTC+2, Hussein B. wrote:

 Oh, this works

  (dosync (alter v #(update-in %1 [1] (fnil conj [ ]) %2) 33))


 Not sure what %2 or 33 are doing there but you can skip the #() function, 
 alter (just like update-in) uses apply internally so you can just use:

 (def v (ref {}))

 (dosync (alter v update-in [1] (fnil conj []) 22)) 

 = {1 [22]}




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


Doing Socket IO inside STM transaction

2014-06-17 Thread Hussein B.
Hi,

I have a ServerSocket that stores the client ID and the client socket 
object into a ref type. And I also have a thread that is running in the 
background that checks if a specific condition is met, then it will start 
send notifications to the clients (it will use the client-id-ref and 
messages-ref).

Of course, since both are refs; any operation needs to be run under a STM 
transaction.

My question is, is it ok to do IO Socket operation inside a STM 
transaction? STM transaction might retry, this means that there are great 
chances that the clients will receive the notifications more than once.

For Socket IO operations inside STM transaction, is better/recommended to 
do it using Agents? Since, AFAIK, agents inside a transaction will be 
executed only if the transaction is successful.

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: Doing Socket IO inside STM transaction

2014-06-17 Thread Hussein B.
I think send-off is used for IO operations, or?

If an agent is started with messages [1 2 3] and then another agent started 
with messages [4 5] , is it guaranteed that messages [1 2 3] will be 
delivered before [4 5]?

I'm talking about production and really concurrent system.

On Tuesday, June 17, 2014 11:45:52 PM UTC+2, Gary Trakhman wrote:

 Agent send operations inside a transaction get queued up and don't 
 actually get sent until the transaction commits, that's probably what you 
 want, it's meant for side-effects.


 On Tue, Jun 17, 2014 at 5:43 PM, Hussein B. hubag...@gmail.com 
 javascript: wrote:

 Hi,

 I have a ServerSocket that stores the client ID and the client socket 
 object into a ref type. And I also have a thread that is running in the 
 background that checks if a specific condition is met, then it will start 
 send notifications to the clients (it will use the client-id-ref and 
 messages-ref).

 Of course, since both are refs; any operation needs to be run under a STM 
 transaction.

 My question is, is it ok to do IO Socket operation inside a STM 
 transaction? STM transaction might retry, this means that there are great 
 chances that the clients will receive the notifications more than once.

 For Socket IO operations inside STM transaction, is better/recommended to 
 do it using Agents? Since, AFAIK, agents inside a transaction will be 
 executed only if the transaction is successful.

 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 
 javascript:
 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 javascript:
 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 javascript:.
 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: Doing Socket IO inside STM transaction

2014-06-17 Thread Hussein B.
you mean one agent to deliver the notifications. true?

On Wednesday, June 18, 2014 12:01:42 AM UTC+2, Gary Trakhman wrote:

 Yea, send uses a fixed threadpool, and send-off uses a growing one, so 
 it's more suitable for IO-bound tasks.  I don't think there's any 
 difference in terms of how it looks from STM.

 2 agents will have 2 independent queues, even though they might share 
 threadpools, if you want to guarantee order, you need one queue.


 On Tue, Jun 17, 2014 at 5:54 PM, Hussein B. hubag...@gmail.com 
 javascript: wrote:

 I think send-off is used for IO operations, or?

 If an agent is started with messages [1 2 3] and then another agent 
 started with messages [4 5] , is it guaranteed that messages [1 2 3] will 
 be delivered before [4 5]?

 I'm talking about production and really concurrent system.


 On Tuesday, June 17, 2014 11:45:52 PM UTC+2, Gary Trakhman wrote:

 Agent send operations inside a transaction get queued up and don't 
 actually get sent until the transaction commits, that's probably what you 
 want, it's meant for side-effects.
  

 On Tue, Jun 17, 2014 at 5:43 PM, Hussein B. hubag...@gmail.com wrote:

  Hi,

 I have a ServerSocket that stores the client ID and the client socket 
 object into a ref type. And I also have a thread that is running in the 
 background that checks if a specific condition is met, then it will start 
 send notifications to the clients (it will use the client-id-ref and 
 messages-ref).

 Of course, since both are refs; any operation needs to be run under a 
 STM transaction.

 My question is, is it ok to do IO Socket operation inside a STM 
 transaction? STM transaction might retry, this means that there are great 
 chances that the clients will receive the notifications more than once.

 For Socket IO operations inside STM transaction, is better/recommended 
 to do it using Agents? Since, AFAIK, agents inside a transaction will be 
 executed only if the transaction is successful.

 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 clo...@googlegroups.com 
 javascript:
 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 javascript:
 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 javascript:.
 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.


How to unit test (defn-) functions?

2014-06-12 Thread Hussein B.
Hi,

I like to use (defn-) when it comes to internal implementation functions. 
But since they aren't exposed, how to unit test them?

Of course, I'm using Lein and clojure.test

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: Clojure:Lisp :: LSD:Meditation

2014-06-12 Thread Hussein B.
Thanks. Now, I have a clue how to skip some posts here.

On Thursday, June 12, 2014 3:41:13 PM UTC+2, Divyansh Prakash wrote:

 I compare Clojure to acid in this 
 http://pizzaforthought.blogspot.in/2014/06/clojurelisp-lsdmeditation.html 
 rant.


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


How to iterate over maps and drop one specific element each time?

2014-06-11 Thread Hussein B.
Hi,

I have a seq of maps:

[ {:op :e :v 1} {:op :n :b 2} {:op :m :z 2.3} ]

How to iterate over the sequence and extracting only the non-op entries?

Desired result is:

[ {:v 1} {:b 2} {:z 2.3} ]

Thanks for help and time.

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


What is going wrong in my code?

2014-05-11 Thread Hussein B.
Hi,

I'm trying to learn how to make  DSL in Clojure and Korma project is a 
really good place to learn from. I'm trying this very simple stuff 
(inspired by Korma, not Korma code):

(def predicates {'and :and
 'or  :or
 'not :not
 '   :gt
 '   :lt
 '=   :eq})


(defn parse-where 
  [form]
  (walk/postwalk-replace predicates form))


(defn condition-map [clause]
  (apply hash-map (conj clause :op)))


(defn clauses-vec [clauses]
  (reduce #(conj %1 (condition-map %2)) [ ] (rest clauses)))

(defn select* [ ] 
  {:type :select})

(defmacro select
  [ body]
  (make-query-then-execute #'select* body))

(defn- make-query-then-execute [fn-var body]
  `(let [query-map# (- (~fn-var) ~@body)]
query-map#))

(defn where-form [where-form* query form]
  `(let [q# ~query]
(~where-form* q# (clauses-vec ~(parse-where `~form)

(defmacro where [query form]
  (where-form #'where* query form))

(defn where* [query clause]
  (update-in query [:where] conj clause))


But when I'm trying in the REPL:

(select
  (where
(and (= :version 1.6) (= :name Clojure))

I'm getting:

ClassCastException java.lang.Character cannot be cast to 
clojure.lang.IPersistentCollection  clojure.core/conj (core.clj:83)

It is really hard to me to know what is going wrong. What is confusing me, 
if I'm trying the where macro alone, it is working as excepted but when 
integrating it with select macro, I got the exception.

I know it is not your problem but your help is greatly appreciated.

Thanks for help and time.

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


How to convert this list into map?

2014-05-10 Thread Hussein B.
Hi,

I have this list:

(:= :language Clojure)

And I want to convert it to the following map data structure:

{:op := , :language Clojure}

I can't really think of a clear way how to do it.

Would you please help?

Thanks for help and time.

-- 
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: How to convert this list into map?

2014-05-10 Thread Hussein B.
That is beautiful! Thanks a lot!

On Sunday, May 11, 2014 12:33:51 AM UTC+2, Mike Fikes wrote:

 Here is how you can derive that expression:

 {:op :=, :language Clojure}

 is the same as

 (hash-map :op := :language Clojure)


 which is the same as

 (apply hash-map '(:op := :language Clojure))


 So, all you need is

 '(:op := :language Clojure)

 which can be produced by prepending :op to your original list

 (conj '(:= :language Clojure) :op)


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


In Lein, is it possible to run a specific test suite?

2014-05-06 Thread Hussein B.
Hi,

I'm using clojure.test and Lein. Is it possible to run a specific test suit 
? I don't want to run the whole test each time.

Thanks for help and time.

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


Why this Clojure part is working in Korma and no exception is thrown?

2014-04-21 Thread Hussein B.
Hi,

I'm trying to study the source code of Korma project.

(insert users
  (values {:first john :last doe}))


This will resolve to (defmacro insert) 
https://github.com/korma/Korma/blob/master/src/korma/core.clj#L143


Will call (defn- make-query-then-execute) 
https://github.com/korma/Korma/blob/master/src/korma/core.clj#L109


What I don't get is the following:


`(let [query# (- (~query-fn-var ~@args)
~@body)]


(~query-fn-var ~@args) will generate a map that will be feed to (defn values) 
which accepts two arguments.

https://github.com/korma/Korma/blob/master/src/korma/core.clj#L280


I expected that part to throw:


CompilerException clojure.lang.ArityException: Wrong number of args (1) passed 
to: core/values

But it is not.

Any ideas why it is working?

Thanks for help and time.




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


Idiomatic Clojure for iterating all items of a map

2014-04-21 Thread Hussein B.
Hi,

For a data structure such as:

(def langs {:langs [ {:lang Clojure :version 1.6}
{:lang Erlang  :version 17} ] } )

How to iterate all the items of the maps?

I tried this but it is too imperative to me:

(doseq [lang (:langs langs)
  (doseq [k (keys lang)]
(str k(k lang

Thanks for help and time.

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


Dealing with edn for the first time

2014-04-20 Thread Hussein B.
Hi,

I want to save the configuration of my application in edn file.

Lein is used (of course). I want to pub my config.edn under /resources 
directory.

But honestly, I don't know the format of edn. I tried to google it, but I 
didn't get anything helpful. The format is in its early stages.

So, my questions:

1) What is the equivalent of the following in edn:

database.url=localhost
username=foo
password=bar

2) Since my edn file is under /resources . I need a way to read from the 
classpath.
How to do this?

Thanks for help and time.

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


Why (eval (list (quote (println Clojure)))) is throwing a Null Pointer Exception?

2013-08-24 Thread Hussein B.
Hi,

Why the following snippet:

(eval (list (quote (println Clojure 

is throwing a null pointer exception?

Thanks for help and time.

-- 
-- 
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/groups/opt_out.


Re: Entwined STM V1.0

2013-08-18 Thread Hussein B.
Great ! Congratulations!

How it does compare with Clojure's builtin STM?

Thanks.

On Sunday, August 18, 2013 10:24:48 AM UTC+2, Ivan Koblik wrote:

 Hi All,

 Almost 4 years ago I developed STM with semantic concurrency control for 
 my project at CERN. Main feature of this STM is the TransactionalMap that 
 lets you merge concurrent changes. Library is heavily tested and is very 
 stable. It has been used in production for the past 2 years.

 Recently I released it on GitHub:
 http://entwined.koblik.ch (will redirect to 
 https://github.com/CERN-BE/Entwined-STM)

 Since Entwined STM was designed to be used from Java I wrote a simple 
 facade for it in Clojure that you can load with 

 (require '[cern.entwined.core :as stm])

 Entwined STM operates on a memory with a fixed structure, meaning that you 
 have to define what and how many collections you want to have in your STM 
 and this can't be changed after construction. To construct memory with 1 
 transactional map and 1 transactional queue run this:

 (def memory (stm/create-memory :map (stm/create-map) :queue 
 (stm/create-queue)))

 It's impossible to access transactional entities outside of a transaction, 
 to run a transaction you can use intrans macro

 (stm/intrans memory data (- data :map (.put :key1 value1)) true)

 (stm/intrans memory data (- data :map (.get :key1))) ;- value1

 First line puts [:key1 value1] pair into the map. True at the end of the 
 body tells the memory to commit this transaction. intrans will initiate 
 commit if body returns truthy value. Second line just shows that the change 
 has been committed.

 A couple more words on the implementation: I used HashMap to implement the 
 TransactionalMap, I copy the backing map for every transaction which may be 
 expensive for some scenarios. Obvious solution would be to use Clojure's 
 persistent map. Commits are eventually serialized and protected with a 
 single lock. If you take a look at the Java source you'll see that 
 Transaction interface has a second method committed that is called when 
 commit is being done. I use this method to write to the hardware knowing 
 that execution order of committed callbacks is the same as the commit order.

 I would greatly appreciate any feedback and suggestions. If you have any 
 questions don't hesitate to ask here or email me directly. Documentation is 
 still somewhat lacking and I'd be interested to know which parts of it 
 should be improved first.

 Cheers,
 Ivan.
  

-- 
-- 
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/groups/opt_out.


Help to morph this imperative snippet into a functional one

2013-08-18 Thread Hussein B.
Hi!

Would you please help me transforming this imperative code into functional 
one?

The code is a typical snippet in imperative style. A lot of mutations that 
I don't even know how to start morphing it to Clojure.

class Container {
  MapString, Container children;
  String letter;
  ListString value;
}

void insert(Container container, String letters, String value) {
  
  for (int i = 0; i  letters.length; i++) {

String letter = new String(letters.chatAt[i]);

if (container.children.get(letter) != null) {
  container = container.children.get(letter);
} else {
  MapContainer childContainer = new HashMap();
  container.children.put(letter, childContainer);
  container = container.children.get(letter);
}

   if (i == letters.length() - 1) {
 container.values.add(value);
 break;
   }

} 


Thanks for help and time.

-- 
-- 
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/groups/opt_out.


Re: Help to morph this imperative snippet into a functional one

2013-08-18 Thread Hussein B.
It might be Huffman coding but I don't know Hoffman coding in depth, so I 
can't be precise. :)

But any way, it is a snippet written in an imperative style that I'm trying 
to transfer into a functional one.

The amount of mutation and the if statements are blocking me from doing it 
in Clojure.


On Sunday, August 18, 2013 4:27:43 PM UTC+2, Chris Ford wrote:

 Can you explain what the code is supposed to do in English? Java is a 
 little hard to read. :-)

 Are you doing Huffman coding or similar?


 On 18 August 2013 16:51, Hussein B. hubag...@gmail.com javascript:wrote:

 Hi!

 Would you please help me transforming this imperative code into 
 functional one?

 The code is a typical snippet in imperative style. A lot of mutations 
 that I don't even know how to start morphing it to Clojure.

 class Container {
   MapString, Container children;
   String letter;
   ListString value;
 }

 void insert(Container container, String letters, String value) {
   
   for (int i = 0; i  letters.length; i++) {

 String letter = new String(letters.chatAt[i]);

 if (container.children.get(letter) != null) {
   container = container.children.get(letter);
 } else {
   MapContainer childContainer = new HashMap();
   container.children.put(letter, childContainer);
   container = container.children.get(letter);
 }

if (i == letters.length() - 1) {
  container.values.add(value);
  break;
}

 } 


 Thanks for help and time.

 -- 
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clo...@googlegroups.comjavascript:
 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 javascript:
 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 javascript:.
 For more options, visit https://groups.google.com/groups/opt_out.




-- 
-- 
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/groups/opt_out.


Help to start creating this DSL in Clojure

2013-08-17 Thread Hussein B.
Hi, 

I'm trying to create this Domain Specific Language:

(query clojure
  (directory /usr/texts)
  (group-by :creation-date))

What it should do is to search for all files in a specific directory using 
a regexp and then group the result by some of files attributes.

The idea is the (query) created a RegExp object. (directory) to specify 
which directory to scan. (group-by) is to group the files names by 
creation-date of the files.

(query) will use Java RegExp library. (directory) will use java.io package. 

** I know that I can use Clojure functions for RegExp and IO but I want to 
try to create it using Java libraries **

Any starting points are really appreciated.

Thanks for help and time.

-- 
-- 
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/groups/opt_out.


Re: [ANN] Pedestal-app Tutorial has been released

2013-07-09 Thread Hussein B.
O, Yeah!
Thanks!

On Tuesday, July 9, 2013 6:03:58 PM UTC+2, Ryan Neufeld wrote:

 Hey there, Clojurians/Pedestallions! 

 I'm pleased to announce the release of a comprehensive tutorial for 
 pedestal-app: http://bit.ly/pedestal-app-tutorial. In this tutorial we 
 finally *dive deep* into the guts of pedestal-app and build a distributed 
 multiplayer game using pedestal-app. 

 Major kudos to @brentonashworth for all his hard work on the pedestal-app 
 tutorial. 

 Enjoy!

 -- Ryan Neufeld 


 -- Ryan Neufeld 



-- 
-- 
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/groups/opt_out.




How core.async compares to agents, future and promise?

2013-07-04 Thread Hussein B.
Hi,

How core.async compares to agents, future and promise?

When to use core.async and when to use agents, future and promise?

Thanks for help and time.

-- 
-- 
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/groups/opt_out.




How to implement a distributed and concurrent system in Clojure?

2013-07-03 Thread Hussein B.
Hi,

I read recently on the internet that Clojure concurrency tools make it easy 
to implement a highly concurrent system but on a single machine.

But how to implement a highly concurrent system that runs on a multiple 
machines?

Erlang, Elixir and Scala have the Actors model.

Please correct me if I'm wrong.

Thanks for help and time.

-- 
-- 
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/groups/opt_out.




Is it possible to parameterize proxy macro with defmacro?

2013-06-23 Thread Hussein B.
Hi,
After I got your help last week to get my Macro working :) I tried to 
expand it more:

I'm trying to parameterizing my object creation (I'm using 
clojure.core.match). Source class offers multiple constructors:

(defmacro source [source-name constructor-args  meths]
  (match [constructor-args]
[{}]
  `(def ~source-name (proxy [Source]
 []
 ~@(for [meth meths]
 (let [[method-name args  body] meth
   camel-case-method-name (hyphenated-camel-case method-name)]
   `(~camel-case-method-name ~args ~@body)
 [{:method _ :resource _}]
 (let [^Method meth (:method constructor-args)
  ^Reference reference (:resource constructor-args)]
   `(def ~source-name (proxy [Source]
 [^Method meth ^Reference reference]
   ~@(for [meth meths]
   (let [[method-name args  body] meth
  camel-case-method-name (hyphenated-camel-case 
method-name)]
 `(~camel-case-method-name ~args ~@body

But when macroexpand, I notice the called proxy is the one with the empty 
constructor, not the one that takes two parameters.

Am I missing something?

Thanks for help and time.

-- 
-- 
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/groups/opt_out.




Re: Clojure in production

2013-06-19 Thread Hussein B.
I mentioned that! :D

On Wednesday, June 19, 2013 9:40:57 AM UTC+2, Florian Over wrote:

 Hi,
 we at doo.net are using clojure and clojurescript for all our backend and 
 web development.
 We are also still in need for clojure developers. :)

 Florian


 2013/6/19 Nikita Prokopov prok...@gmail.com javascript:

 We're using Clojure for a year in one of our backend project (real-time 
 social feeds aggregation  processing) at AboutEcho.com (Novosibirsk  
 Ulyanovsk, Russia). 1.5.1 + a little bit of ClojureScript for internal 
 dashboard.

  -- 
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clo...@googlegroups.comjavascript:
 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 javascript:
 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 javascript:.
 For more options, visit https://groups.google.com/groups/opt_out.
  
  




-- 
-- 
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/groups/opt_out.




What the recommended way now to create an instance and override its methods?

2013-06-18 Thread Hussein B.
Hi,

I know we usually use 'proxy' macro when we want to create an instance of a 
concrete class and override some of its methods. But do we have now a 
recommended approach?  

AFAIK, reify only works with protocols and interfaces, can't be used to 
create an instance and override its methods.

I'm a little bit worry about 'proxy' macros since some devs are saying that 
it has a performance penalty.

Thanks for help and time.

-- 
-- 
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/groups/opt_out.




Re: First day with Macros

2013-06-18 Thread Hussein B.
I don't get why we have to use a second 'back tick'. I thought one backtick 
at the beginning and then we use ~ and ~@ when needed.

On Tuesday, June 18, 2013 2:09:44 AM UTC+2, Carlo wrote:

 I can't speak to the issues that Gary raised, but I can help you with your 
 macro.

 (defmacro servlet [servlet-name  meths]
   `(reify Servlet
  ~@(for [meth meths]
  (let [[method-name args  body] meth
method-name (hyphenated-camel-case method-name)]
`(~method-name ~args ~@body)

 The key here is to keep track of when things are run. The `for` must be 
 run at compile time in order to generate the code we want, so we have to 
 escape it with ~@. The code that the `for` creates (in the form of a list) 
 must then be (quasi-)quoted again by the backtick.

 Macros certainly take some getting used to.


 On Tue, Jun 18, 2013 at 8:12 AM, Hussein B. hubag...@gmail.comjavascript:
  wrote:

 Here is my fourth attempt:

 (defmacro servlet [servlet-name  meths]
   `(reify Servlet
  (for [meth ~meths]
(let [[method-name args  body] ~meth
   camel-case-method-name (hyphenated-camel-case 
 ~method-name)]
  (camel-case-method-name ~args ~@body)

 Still it is not working :(

 How to fix it?

 On Tuesday, June 18, 2013 12:04:50 AM UTC+2, Gary Trakhman wrote:

 Unquoting 'camel-case-method-name' is going to try and replace the 
 symbol with it's value during compile-time in the context of the macro 
 itself.

 also, reify isn't going to work if you need a named class to actually 
 wire up your servlet, for example with a web.xml. Also, consider that 
 you'll need some AOT compilation for the container to actually see the 
 servlet class.


 On Mon, Jun 17, 2013 at 4:38 PM, Hussein B. hubag...@gmail.com wrote:

 Hi,

 My target is to have something like this:

 (servlet ArticlesServlet
   (do-get [this request response]
 (println Get Request))
   (do-post [this request response]
 (println Post Request)))


 I started with this:

 (defmacro servlet [servlet-name meths]
   `(reify Servlet
  (for [meth ~@meths]
(let [[method-name params  body] meth
   camel-case-method-name (hyphenated-camel-case 
 method-name)]
  (~camel-case-method-name ~@body)

 But of course, it is not working :)

 I get:

 CompilerException java.lang.RuntimeException: Unable to resolve symbol: 
 camel-case-method-name in this context

 Why?

 And of course, feel super free to correct my Macro :)

 Thanks for help and time.

 -- 
 -- 
 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=enhttp://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/**groups/opt_outhttps://groups.google.com/groups/opt_out
 .
  
  


  -- 
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clo...@googlegroups.comjavascript:
 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 javascript:
 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 javascript:.
 For more options, visit https://groups.google.com/groups/opt_out.
  
  




-- 
-- 
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/groups/opt_out.




Re: What the recommended way now to create an instance and override its methods?

2013-06-18 Thread Hussein B.
Since reify allows us to override methods of an object, it is better to do:

(def meh-object (MehClass.))

(reify meh-object
  ;; override methods)

than:

(proxy MehClass[]
  ;; override methods)

Thanks.

On Tuesday, June 18, 2013 1:16:40 PM UTC+2, Jim foo.bar wrote:

 On 18/06/13 08:45, Hussein B. wrote: 
  I know we usually use 'proxy' macro when we want to create an instance 
  of a concrete class and override some of its methods. But do we have 
  now a recommended approach? 

 'proxy' is the recommended approach unless you have some weird 
 overriding requirements like providing an override based on the type of 
 the arguments rather than the arity, in which case you have to drop to 
 Java and manually construct your proxy... 

 yes, 'reify' will be slightly faster but as you say it only works with 
 abstractions and not concrete objects. 

 hope that helps, :) 

 Jim 


-- 
-- 
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/groups/opt_out.




Re: What the recommended way now to create an instance and override its methods?

2013-06-18 Thread Hussein B.
Hmm,
then why Clojure 
docs http://clojuredocs.org/clojure_core/clojure.core/reify mentions 
'object':

protocol-or-interface-or-Object
(methodName [args+] body)*

On Tuesday, June 18, 2013 1:41:57 PM UTC+2, Jim foo.bar wrote:

  On 18/06/13 12:34, Hussein B. wrote:
  
 Since reify allows us to override methods of an object, it is better to do:


 'reify' allows you to* implement*/*satisfy* interface-methods - not to 
 override concrete ones.

 user= (reify String 
   #_=  (length [this] (count this)))

 user= CompilerException java.lang.IllegalArgumentException: only 
 interfaces are supported, had: java.lang.String, 
 compiling:(NO_SOURCE_PATH:1:1)

 Jim
  

-- 
-- 
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/groups/opt_out.




Re: Clojure in production

2013-06-18 Thread Hussein B.
According to their Jobs page, Doo is using Clojure to implement their 
backend and web application:
https://doo.net/en/

On Monday, June 10, 2013 11:47:25 PM UTC+2, Plinio Balduino wrote:

 Hi there 

 I'm writing a talk about Clojure in the real world and I would like to 
 know, if possible, which companies are using Clojure for production or 
 to make internal tools. 

 Thank you 

 Plínio Balduino 


-- 
-- 
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/groups/opt_out.




First day with Macros

2013-06-17 Thread Hussein B.
Hi,

My target is to have something like this:

(servlet ArticlesServlet
  (do-get [this request response]
(println Get Request))
  (do-post [this request response]
(println Post Request)))


I started with this:

(defmacro servlet [servlet-name meths]
  `(reify Servlet
 (for [meth ~@meths]
   (let [[method-name params  body] meth
  camel-case-method-name (hyphenated-camel-case method-name)]
 (~camel-case-method-name ~@body)

But of course, it is not working :)

I get:

CompilerException java.lang.RuntimeException: Unable to resolve symbol: 
camel-case-method-name in this context

Why?

And of course, feel super free to correct my Macro :)

Thanks for help and time.

-- 
-- 
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/groups/opt_out.




Re: First day with Macros

2013-06-17 Thread Hussein B.
Here is my fourth attempt:

(defmacro servlet [servlet-name  meths]
  `(reify Servlet
 (for [meth ~meths]
   (let [[method-name args  body] ~meth
  camel-case-method-name (hyphenated-camel-case ~method-name)]
 (camel-case-method-name ~args ~@body)

Still it is not working :(

How to fix it?

On Tuesday, June 18, 2013 12:04:50 AM UTC+2, Gary Trakhman wrote:

 Unquoting 'camel-case-method-name' is going to try and replace the symbol 
 with it's value during compile-time in the context of the macro itself.

 also, reify isn't going to work if you need a named class to actually wire 
 up your servlet, for example with a web.xml. Also, consider that you'll 
 need some AOT compilation for the container to actually see the servlet 
 class.


 On Mon, Jun 17, 2013 at 4:38 PM, Hussein B. hubag...@gmail.comjavascript:
  wrote:

 Hi,

 My target is to have something like this:

 (servlet ArticlesServlet
   (do-get [this request response]
 (println Get Request))
   (do-post [this request response]
 (println Post Request)))


 I started with this:

 (defmacro servlet [servlet-name meths]
   `(reify Servlet
  (for [meth ~@meths]
(let [[method-name params  body] meth
   camel-case-method-name (hyphenated-camel-case method-name)]
  (~camel-case-method-name ~@body)

 But of course, it is not working :)

 I get:

 CompilerException java.lang.RuntimeException: Unable to resolve symbol: 
 camel-case-method-name in this context

 Why?

 And of course, feel super free to correct my Macro :)

 Thanks for help and time.

 -- 
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clo...@googlegroups.comjavascript:
 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 javascript:
 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 javascript:.
 For more options, visit https://groups.google.com/groups/opt_out.
  
  




-- 
-- 
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/groups/opt_out.




Re: How to write this in idiomatic Clojure code?

2012-11-16 Thread Hussein B.
Why the use of map? function ?
I don't get it.

On Friday, November 16, 2012 8:08:40 AM UTC+2, lpetit wrote:

 (map #(seq (process-some-class-instance %))
(tree-seq map? :children input))

 Sent from a smartphone, please excuse the brevity/typos.

 Le 16 nov. 2012 à 00:13, Hussein B. hubag...@gmail.com javascript: 
 a écrit :

 Yes true.

 If it is leaf , do process-some-class-instance

 If it is not, then it could hold a collection of nodes and leafs (a 
 mixture)

 Actually , I'm checking tree-seq but I don't know how to use it in my case.

 Any ideas ?

 On Friday, November 16, 2012 1:06:22 AM UTC+2, lpetit wrote:

 Am I right in guessing that your input is some kind of tree where 
 Someclass instances are leafs and non-leaf nodes are represented by maps 
 having a :children key?

 Sent from a smartphone, please excuse the brevity/typos.

 Le 15 nov. 2012 à 23:33, Hussein B. hubag...@gmail.com a écrit :

 Hi,

 Would you please help me to morph this to an idiomatic Clojure ?

 (defn crazy [input]
 (if (instance? SomeClass input)
 (seq (process-some-class-instance input))
 (map  crazy  (:children input


 Thanks for help and time.

 -- 
 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 post to this group, send email to clo...@googlegroups.com javascript:
 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 javascript:
 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 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

How to write this in idiomatic Clojure code?

2012-11-15 Thread Hussein B.
Hi,

Would you please help me to morph this to an idiomatic Clojure ?

(defn crazy [input]
(if (instance? SomeClass input)
(seq (process-some-class-instance input))
(map  crazy  (:children input


Thanks for help and time.

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

Re: How to write this in idiomatic Clojure code?

2012-11-15 Thread Hussein B.
The snippet I provided, is an idiomatic Clojure ?

On Friday, November 16, 2012 12:41:31 AM UTC+2, Jay Fields wrote:

 That code is clear enough that I wouldn't feel obligated to change it 
 if I encountered it. 

 You could also 

 (defmulti crazy class) 

 (defmethod crazy SomeClass [input] 
   (seq (process-some-class-instance input)) 

 (defmethod crazy :default [{:keys [children]}] 
   (map crazy children)) 

 On Thu, Nov 15, 2012 at 5:33 PM, Hussein B. hubag...@gmail.comjavascript: 
 wrote: 
  Hi, 
  
  Would you please help me to morph this to an idiomatic Clojure ? 
  
  (defn crazy [input] 
  (if (instance? SomeClass input) 
  (seq (process-some-class-instance input)) 
  (map  crazy  (:children input 
  
  
  Thanks for help and time. 
  
  -- 
  You received this message because you are subscribed to the Google 
  Groups Clojure group. 
  To post to this group, send email to clo...@googlegroups.comjavascript: 
  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 javascript: 
  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 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

Re: How to write this in idiomatic Clojure code?

2012-11-15 Thread Hussein B.
Yes true.

If it is leaf , do process-some-class-instance

If it is not, then it could hold a collection of nodes and leafs (a mixture)

Actually , I'm checking tree-seq but I don't know how to use it in my case.

Any ideas ?

On Friday, November 16, 2012 1:06:22 AM UTC+2, lpetit wrote:

 Am I right in guessing that your input is some kind of tree where 
 Someclass instances are leafs and non-leaf nodes are represented by maps 
 having a :children key?

 Sent from a smartphone, please excuse the brevity/typos.

 Le 15 nov. 2012 à 23:33, Hussein B. hubag...@gmail.com javascript: 
 a écrit :

 Hi,

 Would you please help me to morph this to an idiomatic Clojure ?

 (defn crazy [input]
 (if (instance? SomeClass input)
 (seq (process-some-class-instance input))
 (map  crazy  (:children input


 Thanks for help and time.

 -- 
 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 javascript:
 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 javascript:
 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 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

Re: Understanding clojure.core.cache TTL cache

2012-10-23 Thread Hussein B.
Just to push to the limit.

Lets say we saved/serializer the cache to a secondary storage (file or 
ZooKeeper).
What happen when the cache is restored? 
I mean TTL is still honored? expired data while been sleeping will be 
evicted upon an operation is performed after deserialization?

Thanks a lot!

On Tuesday, October 23, 2012 1:42:28 AM UTC+3, Sean Corfield wrote:

 On Mon, Oct 22, 2012 at 3:30 PM, Hussein B. hubag...@gmail.comjavascript: 
 wrote: 
  So we need to call evict explicitly if we want to remove an entry? no 
  automatic deletion after expiring? 

 The cache is immutable. 

 When you call hit / miss, you get a new instance of the cache with the 
 expired entries removed, and the hit entry updated (if appropriate) or 
 the miss entry added. 

 That new instance needs to be stored somewhere (or passed to future 
 code execution). 

 Entries will be automatically deleted after expiring in any new 
 instance of the cache - returned by hit / miss. 

 You can see that here: 

 user= (swap! c3 hit-or-miss :a 1) 
 {:a 1} 
 user= (swap! c3 hit-or-miss :b 2) 
 {:a 1, :b 2} 
 user= (swap! c3 hit-or-miss :c 3) 
 {:c 3, :b 2} 
 user= (swap! c3 hit-or-miss :d 4) 
 {:c 3, :d 4} 
 user= (swap! c3 hit-or-miss :e 5) 
 {:c 3, :d 4, :e 5} 

 We add :a, then :b. By the time we add :c, :a has expired (and been 
 removed). By the time we add :d, :b has expired (and been removed). 
 Then we add :e before any more expiries. If I wait awhile and add a 
 new value for :a... 

 user= (swap! c3 hit-or-miss :a 6) 
 {:a 6} 

 ...you'll see :c, :d and :e have expired. 
 -- 
 Sean A Corfield -- (904) 302-SEAN 
 An Architect's View -- http://corfield.org/ 
 World Singles, LLC. -- http://worldsingles.com/ 

 Perfection is the enemy of the good. 
 -- Gustave Flaubert, French realist novelist (1821-1880) 


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

Understanding clojure.core.cache TTL cache

2012-10-22 Thread Hussein B.
Hi,

I created this:

(def c3 (cache/ttl-cache-factory {:a 1} :ttl 2))
user= c3
{:a 1}
user= (cache/has? c3 :a)
true
user= (cache/has? c3 :a)
false
user= c3
{:a 1}
user= (cache/evict c3 :a)
{}
user= c3
{:a 1}

After TTL, cache doesn't has :a entry but printing the var shows the map 
contains :a
Then evicting :a shows {} but printing the c3 shows again the map contains 
:a

What I'm missing?

Thanks for help and time

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

Re: Understanding clojure.core.cache TTL cache

2012-10-22 Thread Hussein B.
Wow, What an honor to get a reply from my idol and mentor !!
Thanks a lot.
I really appreciate to hear your opinion regarding this:
http://stackoverflow.com/questions/13015906/is-it-safe-to-use-a-clojure-core-cache-guarded-by-ref-type
Every thing started with this issue.
Appreciate your precious time.

On Monday, October 22, 2012 10:05:25 PM UTC+3, Fogus wrote:

  What I'm missing? 

 First, thanks for trying c.c.cache! The answer to your question is 
 that the TTL cache implementation is non-destructive.  The `evict` 
 call returns the cache without the element, but does not remove it 
 from the original cache. 


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

Re: Understanding clojure.core.cache TTL cache

2012-10-22 Thread Hussein B.
I see.
But I didn't really grasp the whole concept firmly .
c3 holds a map containing {:a 1} that will lives for two minutes.
After two minutes, requesting :a is generating false since it reached its 
TTL but it will still live in map until it is removed explicitly by 
invoking evict.
Correct?

Also, would you please explain the recommended pattern to use core.cache 
for me?

(if (cache/has? C :c) ;; has? checks that the cache contains an item
  (cache/hit C :c);; hit returns a cache with any relevant internal 
information updated
  (cache/miss C :c 42))   ;; miss returns a new cache with the new item and 
without evicted entries


What I'm thinking of is a map that will remove an entry automatically 
(without calling evict) after TTL.

Thanks a lot!

On Monday, October 22, 2012 11:15:06 PM UTC+3, Sean Corfield wrote:

 On Mon, Oct 22, 2012 at 12:05 PM, Michael Fogus 
 mef...@gmail.comjavascript: 
 wrote: 
  First, thanks for trying c.c.cache! The answer to your question is 
  that the TTL cache implementation is non-destructive.  The `evict` 
  call returns the cache without the element, but does not remove it 
  from the original cache. 

 In other words you need something like this: 

 (def c3 (atom (cache/ttl-cache-factory {:a 1} :ttl 2))) 
 user= @c3 
 {:a 1} 
 user= (cache/has? @c3 :a) 
 true 
 user= (cache/has? @c3 :a) 
 false 
 user= @c3 
 {:a 1} 
 user= (swap! c3 cache/evict :a) 
 {} 
 user= @c3 
 {} 

 -- 
 Sean A Corfield -- (904) 302-SEAN 
 An Architect's View -- http://corfield.org/ 
 World Singles, LLC. -- http://worldsingles.com/ 

 Perfection is the enemy of the good. 
 -- Gustave Flaubert, French realist novelist (1821-1880) 


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

Re: Understanding clojure.core.cache TTL cache

2012-10-22 Thread Hussein B.
I tried this:

(defn hit-or-miss 
  [a k v] 
  (if (c/has? @a k) 
(c/hit @a k) 
(c/miss @a k v))) 

(def acu (atom (c/ttl-cache-factory {} :ttl 2))) 

(swap! acu hit-or-miss :e 55)

But I got:

ClassCastException clojure.core.cache.TTLCache cannot be cast to 
clojure.lang.IDeref  clojure.core/deref (core.clj:2080)

Any ideas?

On Tuesday, October 23, 2012 1:03:10 AM UTC+3, Sean Corfield wrote:

 Just to clarify, hit does nothing for TTL (since items timeout based 
 solely on when they were added, not when they were last touched), so 
 swap! on the hit really makes no difference here. It would, however, 
 be required for some of the other types of cache. 

 Also, exactly how you use has? / hit / miss is going to depend on how 
 you're interacting with the cache and what behavior you want. 

 For example, at World Singles, we use TTL caches and have three 
 operations: 
 * evict - this uses swap! and cache/evict to remove a cache entry 
 * fetch - this uses get to return an entry if present 
 * store - this uses swap! and cache/miss to add/update a cache entry 

 Since hit doesn't do anything on a TTL cache, we don't bother calling 
 it. If we switch to other types of cache, our fetch operation would 
 need to be updated to use cache/has?, swap! and cache/hit (as well as 
 get), or we'd need to change our API somewhat... 

 It's my understanding that you can use assoc / dissoc on a cache as 
 synonyms for miss / evict (that seemed to be true with the version of 
 core.cache that I initially used - I'm fairly confident it's still 
 true of assoc but not so confident that dissoc still works that way... 
 maybe Fogus can help me out there?). 

 Sean 

 On Mon, Oct 22, 2012 at 2:31 PM, Sean Corfield 
 seanco...@gmail.comjavascript: 
 wrote: 
  On Mon, Oct 22, 2012 at 1:50 PM, Hussein B. 
  hubag...@gmail.comjavascript: 
 wrote: 
  c3 holds a map containing {:a 1} that will lives for two minutes. 
  
  In the code I provided, c3 is an atom that holds a cache (which is the 
 map). 
  
  After two minutes, requesting :a is generating false since it reached 
 its 
  TTL but it will still live in map until it is removed explicitly by 
 invoking 
  evict. 
  
  Because the cache itself is immutable. That's why you need to store 
  the cache in an atom (so the atom can be updated to contain the 
  modified cache): 
  
  (defn hit-or-miss 
Given an atom containing a cache, a key, and a value, update the 
  cache and return... 
[a k v] 
(if (cache/has? @a k) 
  (cache/hit @a k) 
  (cache/miss @a k v))) 
  
  ... (swap! c3 hit-or-miss :c 42) ... 
  
  On Monday, October 22, 2012 11:15:06 PM UTC+3, Sean Corfield wrote: 
  In other words you need something like this: 
  
  (def c3 (atom (cache/ttl-cache-factory {:a 1} :ttl 2))) 
  user= @c3 
  {:a 1} 
  user= (cache/has? @c3 :a) 
  true 
  user= (cache/has? @c3 :a) 
  false 
  user= @c3 
  {:a 1} 
  user= (swap! c3 cache/evict :a) 
  {} 
  user= @c3 
  {} 



 -- 
 Sean A Corfield -- (904) 302-SEAN 
 An Architect's View -- http://corfield.org/ 
 World Singles, LLC. -- http://worldsingles.com/ 

 Perfection is the enemy of the good. 
 -- Gustave Flaubert, French realist novelist (1821-1880) 


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

Re: Understanding clojure.core.cache TTL cache

2012-10-22 Thread Hussein B.
I see, it works now.

So we need to call evict explicitly if we want to remove an entry? no 
automatic deletion after expiring?

On Tuesday, October 23, 2012 1:21:54 AM UTC+3, Sean Corfield wrote:

 On Mon, Oct 22, 2012 at 3:08 PM, Hussein B. hubag...@gmail.comjavascript: 
 wrote: 
  I tried this: 
  
  (defn hit-or-miss 
[a k v] 
(if (c/has? @a k) 
  (c/hit @a k) 
  (c/miss @a k v))) 

 My bad... got a bit carried away with the derefs based on code I was 
 playing around with in the REPL. Try this: 

 (defn hit-or-miss 
   [c k v] 
   (if (c/has? c k) 
 (c/hit c k) 
 (c/miss c k v))) 

 (swap! acu hit-or-miss :e 55) 

 That will update the atom to hold the new cache with {:e 55}. 
 -- 
 Sean A Corfield -- (904) 302-SEAN 
 An Architect's View -- http://corfield.org/ 
 World Singles, LLC. -- http://worldsingles.com/ 

 Perfection is the enemy of the good. 
 -- Gustave Flaubert, French realist novelist (1821-1880) 


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

Re: Understanding clojure.core.cache TTL cache

2012-10-22 Thread Hussein B.
Thank you, I understand it :)
And thank you Mr. Fogus. What a great pleasure!

On Tuesday, October 23, 2012 1:42:28 AM UTC+3, Sean Corfield wrote:

 On Mon, Oct 22, 2012 at 3:30 PM, Hussein B. hubag...@gmail.comjavascript: 
 wrote: 
  So we need to call evict explicitly if we want to remove an entry? no 
  automatic deletion after expiring? 

 The cache is immutable. 

 When you call hit / miss, you get a new instance of the cache with the 
 expired entries removed, and the hit entry updated (if appropriate) or 
 the miss entry added. 

 That new instance needs to be stored somewhere (or passed to future 
 code execution). 

 Entries will be automatically deleted after expiring in any new 
 instance of the cache - returned by hit / miss. 

 You can see that here: 

 user= (swap! c3 hit-or-miss :a 1) 
 {:a 1} 
 user= (swap! c3 hit-or-miss :b 2) 
 {:a 1, :b 2} 
 user= (swap! c3 hit-or-miss :c 3) 
 {:c 3, :b 2} 
 user= (swap! c3 hit-or-miss :d 4) 
 {:c 3, :d 4} 
 user= (swap! c3 hit-or-miss :e 5) 
 {:c 3, :d 4, :e 5} 

 We add :a, then :b. By the time we add :c, :a has expired (and been 
 removed). By the time we add :d, :b has expired (and been removed). 
 Then we add :e before any more expiries. If I wait awhile and add a 
 new value for :a... 

 user= (swap! c3 hit-or-miss :a 6) 
 {:a 6} 

 ...you'll see :c, :d and :e have expired. 
 -- 
 Sean A Corfield -- (904) 302-SEAN 
 An Architect's View -- http://corfield.org/ 
 World Singles, LLC. -- http://worldsingles.com/ 

 Perfection is the enemy of the good. 
 -- Gustave Flaubert, French realist novelist (1821-1880) 


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

Would you please help in migrating this code from Bishop to Liberator?

2012-09-19 Thread Hussein B.
Hi,

I want to migrate this code written in Bishop REST framework to Liberator 
REST framework:

(bishop/defresource ticket
  {
text/html
(fn [request]
  (let [request-method (:request-method request)]
(case request-method
  :get  (list-all-tickets request)
  :post (create-ticket-per-uploaded-file request
  }

  {
:allowed-methods (fn [request] [:get :post])
  })

I'm not really digesting the liberator approach.

Thanks for help and time.

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

Immutability rules when it comes to Ref type

2012-08-10 Thread Hussein B.
Hi,
I have a ref type that wraps a map, this map is going to embed many nested 
other maps.
According to immutability rules, what happens when:
A new nested map is updated (entry is removed or update) or even a new 
nested map is added to the master map that is wrapped by ref type? 
Thanks for help and time.

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

Re: Immutability rules when it comes to Ref type

2012-08-10 Thread Hussein B.
Crystal clear, thanks.

On Friday, August 10, 2012 10:16:19 PM UTC+3, Andy Fingerhut wrote:

 Hussein: 

 If you ignore the ref for the moment, making any change to a map, or a 
 map nested inside a map however many levels deep you wish, does not mutate 
 the original map.  Instead it creates a brand new map with the new set of 
 keys and values.  It is as if the original was copied, and the copy was 
 modified, but it is implemented much more efficiently than that.  For 
 efficiency, this new map will usually share a lot of memory with the 
 original one, but the original one and the new one are both in memory and 
 accessible simultaneously, until and unless one is garbage collected, which 
 would only happen after no other data structure references it any longer. 

 A ref effectively contains a pointer to one object at a time, and this 
 pointer can change over time.  If you want to be safe about concurrency, 
 the ref should only ever point at an immutable data structure.  Modifying 
 the map pointed to by the ref merely means that the pointer is changed from 
 pointing to one immutable map, to pointing at a different immutable map. 
  Neither of the two maps becomes mutable as a result of this. 

 Andy 

 On Aug 10, 2012, at 9:21 AM, Hussein B. wrote: 

  Hi, 
  I have a ref type that wraps a map, this map is going to embed many 
 nested other maps. 
  According to immutability rules, what happens when: 
  A new nested map is updated (entry is removed or update) or even a new 
 nested map is added to the master map that is wrapped by ref type? 
  Thanks for help and time. 


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

Better ideas how to collect analytics data

2012-08-10 Thread Hussein B.
Hi,
I'm collecting analytics data. I used a master map that holds many other 
nested maps.
Considering maps are immutable, many new maps are going to be allocated. 
(Yes, that is efficient in Clojure).
Basic operation that I'm using is update-in , very convenient.
Do you have a better idea how to collect these data more efficiently in 
Clojure? 
Thanks for help and time.

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

Why Clojure map literal creates an instance of array map?

2012-08-10 Thread Hussein B.
Hi,
Why Clojure map literal creates an instance of array map but not hash map?
What are the advantages of array map over hash map?
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

How to measure pieces of Clojure code?

2012-08-10 Thread Hussein B.
Hi,
I want to measure how much space an algorithm is taking and then trying to 
change some aspects to see how things are going to differ.
I also want to measure how much time it takes to complete an operation.

What tools can I use?

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

Re: Why Clojure map literal creates an instance of array map?

2012-08-10 Thread Hussein B.
Thanks, never knew about this hashtable threshold factor.

On Saturday, August 11, 2012 1:01:02 AM UTC+3, Tamreen Khan (Scriptor) 
wrote:

 It's not dependent on whether it's a literal but on the size of the map, 8 
 key-value pairs is the threshold.

 This results in a PersistentHashMap
 (class {1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9})  = 
 clojure.lang.PersistentHashMap

 This gets you a PersistentArrayMap
 (class {1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8})  = 
 clojure.lang.PersistentHashMap

 You can see where this happens in the source here: 
 https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/PersistentArrayMap.java#L115

 HASHTABLE_THRESHOLD is a constant set to 16, 8 keys and 8 values. So when 
 you assoc onto an arraymap with 8 key-value pairs it returns a hashmap.

 The reason for this, as far as I understand it, is that with small 
 hashmaps it's more efficient to do simple copy-on-write. In other words 
 when you assoc onto it, it copies the entire map, adds the new key-value 
 pair to the copy, and then returns the copy. With larger hashmaps, it 
 becomes more useful to do use a more complicated tree structure which uses 
 structural sharing so that assoc doesn't copy the entire map. Copying a 
 small 5 element map isn't a big deal, but copying one with several thousand 
 elements is.

 On Fri, Aug 10, 2012 at 5:43 PM, Hussein B. hubag...@gmail.comjavascript:
  wrote:

 Hi,
 Why Clojure map literal creates an instance of array map but not hash map?
 What are the advantages of array map over hash map?
 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.comjavascript:
 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 javascript:
 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 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