Questions regarding do form

2012-09-27 Thread arekanderu
Hello all,

I am new to clojure and I have two questions about do and the way it should 
be used.

*Question 1: Which of the following two functions is more idiomatic and 
why? Both functions produce the same result.*


(defn my-fn [java-object]
  (. java-object firstFunc)
  (. java-object secondFunc)
  (. java-object thirdFunc)
  java-object)



(defn my-fn [java-object]
  (do (. java-object firstFunc)
(. java-object secondFunc )
(. java-object thirdFunc )
java-object))


*Question 2: Again, which one is more idiomatic and why? Both functions 
produce the same result.*
*
*

(defn my-fn [java-object bar]
  (let [bar-bar (. java-object getSomething)
_   (if (not (is-bar? bar))
  (. java-object (setSomething bar-bar)))]
java-object))



(defn my-fn [java-object bar]
  (let [bar-bar (. java-object getSomething)]
(do 
  (if (not (is-bar? bar))
(. java-object (setSomething bar-bar)))
 java-object)))



-- 
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: Questions regarding do form

2012-09-27 Thread arekanderu
Thank you Meikel for your so helpful replies.

On Thursday, September 27, 2012 4:19:44 PM UTC+3, Meikel Brandmeyer 
(kotarak) wrote:
>
> Hi,
>
> Am Donnerstag, 27. September 2012 12:16:41 UTC+2 schrieb arekanderu:
>
> I am new to clojure and I have two questions about do and the way it 
>> should be used.
>>
>> *Question 1: Which of the following two functions is more idiomatic and 
>> why? Both functions produce the same result.*
>>
>> 
>> (defn my-fn [java-object]
>>   (. java-object firstFunc)
>>   (. java-object secondFunc)
>>   (. java-object thirdFunc)
>>   java-object)
>> 
>>
>
> The first because defn includes an implicit do. So the second example is 
> actually (do (do ...)).
>
> In this case you could also use doto:
>
> (defn my-fn
>   [pojo]
>   (doto pojo
> .firstFunc
> .secondFunc
> .thirdFunc))
>
>  
>
>> *Question 2: Again, which one is more idiomatic and why? Both functions 
>> produce the same result.*
>> *
>> *
>> 
>> (defn my-fn [java-object bar]
>>   (let [bar-bar (. java-object getSomething)
>> _   (if (not (is-bar? bar))
>>   (. java-object (setSomething bar-bar)))]
>> java-object))
>> 
>>
>> 
>> (defn my-fn [java-object bar]
>>   (let [bar-bar (. java-object getSomething)]
>> (do 
>>   (if (not (is-bar? bar))
>> (. java-object (setSomething bar-bar)))
>>  java-object)))
>> 
>>
>
> The third:
>
> (defn my-fn
>   [pojo bar]
>   (let [bar-bar (.getSomething pojo)]
> (when-not (is-bar? bar)
>   (.setSomething pojo bar-bar))
> pojo)))
>
> let also (just like defn) includes an implicit do for the body.
>
> Hope this helps.
>
> Kind regards
> Meikel
>  
>

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

Transforming an ugly nested loop into clojure code

2012-09-30 Thread arekanderu
Hello,

I am trying to port an ugly piece of code from Ruby to clojure. So far I 
have only ported it to clojure by keeping the same way it was written in 
Ruby and i am trying to re-write it the clojure way because...wellits 
very ugly.
I have a complex hash map which it's structure is always the same and the 
keys always known and by using the values in those keys, i make some 
function calls with those values as parameters. You can find a simplified 
version of the map and the function which steps into the map below.

The map structure:

(def my-map 
>
>   [{:a-key "foo" :items-a 
>
>   [{:another-key "bar" :items-b 
>
>   [{:items-c 
>
> [{:name "bar-bar" :items-d 
>
>   [{:items-e 
>
> [{:name "foo-foo"}]
>
>}]
>
>  }]
>
>}]
>
> }]
>
>   }])
>
>  
And the function:

(defn my-func []
>
>(map (fn [a-hash]
>
>(map (fn [item-a]
>
>   (map (fn [item-b]
>
>  (map (fn [item-c]
>
> (when-not (empty? (:items-e item-c))
>
>   (map (fn [item]
>
>  (doSomething (:a-key item-a) 
>> (:name item))
>
>   (:items-e items-c))
>
>  (doSomethingElse (:a-key item-a) 
>> (:another-key item-b) (:name item-c
>
>   (:items-c item-b)))
>
>(:items-b item-a)))
>
> (:items-a a-hash)))
>
>  my-map))) 
>
>
I would really appreciate it if someone could propose an alternative way of 
writing the above function or at least to point me where can I look for 
some useful clojure functions that will help me do what I want but in a 
cleaner way.

Thank you for your 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: Transforming an ugly nested loop into clojure code

2012-09-30 Thread arekanderu
Thank you for your prompt reply Grant.

*> May you share the original code? *
*
*
I will post the original function very soon*
*

*> Why does my-map have vectors storing maps inside instead of a map with 
> maps inside? *
*
*
Because each vector will have more than one hash-map and each hash map will 
have multiple keys. I only posted a simplified version of the map for 
readability, unless I am missing something here...
I think of vector as the equivalent of the "array of" and that's why I used 
it. If i should have done it in some other way please let me know.

*> May you write some tests to demonstrate what you want to accomplish 
> with the ugly map and share them here? *
*
*
I am basically trying to destruct my deep map with a better way than a 
4-nested loop. 

I will post a better code snippet in order to clean things even more.

Thanks again

On Monday, October 1, 2012 12:41:52 AM UTC+3, Grant Rettke wrote:
>
> On Sun, Sep 30, 2012 at 2:59 PM, arekanderu > 
> wrote: 
> > I am trying to port an ugly piece of code from Ruby to clojure. 
>
> May you share the original code? 
>
> > So far I 
> > have only ported it to clojure by keeping the same way it was written in 
> > Ruby and i am trying to re-write it the clojure way 
> because...wellits 
> > very ugly. 
>
> Why does my-map have vectors storing maps inside instead of a map with 
> maps inside? 
>
> > I have a complex hash map which it's structure is always the same and 
> the 
> > keys always known and by using the values in those keys, i make some 
> > function calls with those values as parameters. You can find a 
> simplified 
> > version of the map and the function which steps into the map below. 
>
> May you write some tests to demonstrate what you want to accomplish 
> with the ugly map and share them here? 
>
> > I would really appreciate it if someone could propose an alternative way 
> > of writing the above function or at least to point me where can I look 
> for 
> > some useful clojure functions that will help me do what I want but in a 
> > cleaner way. 
>
> Once you provide tests then we have a better chance at helping. 
>
> -- 
> ((λ (x) (x x)) (λ (x) (x x))) 
> http://www.wisdomandwonder.com/ 
> ACM, AMA, COG, IEEE 
>

-- 
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: Transforming an ugly nested loop into clojure code

2012-10-01 Thread arekanderu
I wrote a much better example in order to show what am I trying to do. Of 
course, the following is a simplified version of the actual code in order 
to make things easier for everybody.

(def my-data [{:area "Somewhere" :warehouses
>
>[{:warehouse "W54321" :containers
>
> [{:container "C12345" :boxes
>
>   [{:box "B12345" :items
>
> [{:item "I12345"}]}]}]}]}
>
>   {:area "SomewhereElse" :warehouses
>
>[{:warehouse "W54321" :containers
>
> [{:container "C54321" :boxes
>
>   [{:box "B54321" :items
>
> [{:item "I54321"}]}]}]}]}])
>
>
>> (defn my-func [data]
>
>   (map (fn [area]
>
>  (map (fn [warehouse]
>
> (map (fn [container]
>
>(map (fn [box]
>
>   (if (not (empty? (:items box)))
>
> (map (fn [item]
>
>(doSomething (:box box) (:item 
>> item)))
>
>  (:items box))
>
> (doSomethingElse (:warehouse warehouse) 
>> (:container container) (:box box
>
>   (:boxes container)))
>
>  (:containers warehouse)))
>
>   (:warehouses area)))
>
>data))
>
>
My question is, how can I get rid of the nested loops and replace it with 
something more elegant in clojure.

Thank you for any replies.

On Monday, October 1, 2012 1:16:25 AM UTC+3, arekanderu wrote:
>
> Thank you for your prompt reply Grant.
>
> *> May you share the original code? *
> *
> *
> I will post the original function very soon*
> *
>
> *> Why does my-map have vectors storing maps inside instead of a map with 
> > maps inside? *
> *
> *
> Because each vector will have more than one hash-map and each hash map 
> will have multiple keys. I only posted a simplified version of the map for 
> readability, unless I am missing something here...
> I think of vector as the equivalent of the "array of" and that's why I 
> used it. If i should have done it in some other way please let me know.
>
> *> May you write some tests to demonstrate what you want to accomplish 
> > with the ugly map and share them here? *
> *
> *
> I am basically trying to destruct my deep map with a better way than a 
> 4-nested loop. 
>
> I will post a better code snippet in order to clean things even more.
>
> Thanks again
>
> On Monday, October 1, 2012 12:41:52 AM UTC+3, Grant Rettke wrote:
>>
>> On Sun, Sep 30, 2012 at 2:59 PM, arekanderu  wrote: 
>> > I am trying to port an ugly piece of code from Ruby to clojure. 
>>
>> May you share the original code? 
>>
>> > So far I 
>> > have only ported it to clojure by keeping the same way it was written 
>> in 
>> > Ruby and i am trying to re-write it the clojure way 
>> because...wellits 
>> > very ugly. 
>>
>> Why does my-map have vectors storing maps inside instead of a map with 
>> maps inside? 
>>
>> > I have a complex hash map which it's structure is always the same and 
>> the 
>> > keys always known and by using the values in those keys, i make some 
>> > function calls with those values as parameters. You can find a 
>> simplified 
>> > version of the map and the function which steps into the map below. 
>>
>> May you write some tests to demonstrate what you want to accomplish 
>> with the ugly map and share them here? 
>>
>> > I would really appreciate it if someone could propose an alternative 
>> way 
>> > of writing the above function or at least to point me where can I look 
>> for 
>> > some useful clojure functions that will help me do what I want but in a 
>> > cleaner way. 
>>
>> Once you provide tests then we have a better chance at helping. 
>>
>> -- 
>> ((λ (x) (x x)) (λ (x) (x x))) 
>> http://www.wisdomandwonder.com/ 
>> ACM, AMA, COG, IEEE 
>>
>

-- 
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: Transforming an ugly nested loop into clojure code

2012-10-01 Thread arekanderu
Thank you Gaz for your reply. You are correct about the side effects.

I will go through your example more carefully and give it a go. It 
definitely looks more promising than what I got :)

On Tuesday, October 2, 2012 1:22:44 AM UTC+3, Gaz wrote:
>
> You appear to be running over the map purely for side-effects, 
> therefore off the top of my head something like: 
>
> (defn my-func 
>   [data] 
>   (doseq [area data 
>   warehouse (:warehouses area) 
>   container (:containers warehouse) 
>   box (:boxes container)] 
> (if-not (empty? (:items box)) 
>   (doseq [item (:items box)] (do-something (:box box) (:item item))) 
>   (do-something-else (:warehouse warehouse) 
>  (:container container) 
>  (:box box) 
>
> Might be more appropriate... 
>
>
> On Mon, Oct 1, 2012 at 5:07 PM, arekanderu > 
> wrote: 
> >> (def my-data [{:area "Somewhere" :warehouses 
> >> 
> >>[{:warehouse "W54321" :containers 
> >> 
> >> [{:container "C12345" :boxes 
> >> 
> >>   [{:box "B12345" :items 
> >> 
> >> [{:item "I12345"}]}]}]}]} 
> >> 
> >>   {:area "SomewhereElse" :warehouses 
> >> 
> >>[{:warehouse "W54321" :containers 
> >> 
> >> [{:container "C54321" :boxes 
> >> 
> >>   [{:box "B54321" :items 
> >> 
> >> [{:item "I54321"}]}]}]}]}]) 
> >> 
> >> 
> >> (defn my-func [data] 
> >> 
> >>   (map (fn [area] 
> >> 
> >>  (map (fn [warehouse] 
> >> 
> >> (map (fn [container] 
> >> 
> >>(map (fn [box] 
> >> 
> >>   (if (not (empty? (:items box))) 
> >> 
> >> (map (fn [item] 
> >> 
> >>(doSomething (:box box) (:item 
> >> item))) 
> >> 
> >>  (:items box)) 
> >> 
> >> (doSomethingElse (:warehouse warehouse) 
> >> (:container container) (:box box 
> >> 
> >>   (:boxes container))) 
> >> 
> >>  (:containers warehouse))) 
> >> 
> >>   (:warehouses area))) 
> >> 
> >>data)) 
>

-- 
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: Transforming an ugly nested loop into clojure code

2012-10-02 Thread arekanderu
Thank you for your input Stathis, I will have a look at them as well.

On Sunday, September 30, 2012 10:59:05 PM UTC+3, arekanderu wrote:
>
> Hello,
>
> I am trying to port an ugly piece of code from Ruby to clojure. So far I 
> have only ported it to clojure by keeping the same way it was written in 
> Ruby and i am trying to re-write it the clojure way because...wellits 
> very ugly.
> I have a complex hash map which it's structure is always the same and the 
> keys always known and by using the values in those keys, i make some 
> function calls with those values as parameters. You can find a simplified 
> version of the map and the function which steps into the map below.
>
> The map structure:
>
> (def my-map 
>>
>>   [{:a-key "foo" :items-a 
>>
>>   [{:another-key "bar" :items-b 
>>
>>   [{:items-c 
>>
>> [{:name "bar-bar" :items-d 
>>
>>   [{:items-e 
>>
>> [{:name "foo-foo"}]
>>
>>}]
>>
>>  }]
>>
>>}]
>>
>> }]
>>
>>   }])
>>
>>  
> And the function:
>
> (defn my-func []
>>
>>(map (fn [a-hash]
>>
>>(map (fn [item-a]
>>
>>   (map (fn [item-b]
>>
>>  (map (fn [item-c]
>>
>> (when-not (empty? (:items-e item-c))
>>
>>   (map (fn [item]
>>
>>  (doSomething (:a-key item-a) 
>>> (:name item))
>>
>>   (:items-e items-c))
>>
>>  (doSomethingElse (:a-key item-a) 
>>> (:another-key item-b) (:name item-c
>>
>>   (:items-c item-b)))
>>
>>(:items-b item-a)))
>>
>> (:items-a a-hash)))
>>
>>  my-map))) 
>>
>>
> I would really appreciate it if someone could propose an alternative way 
> of writing the above function or at least to point me where can I look for 
> some useful clojure functions that will help me do what I want but in a 
> cleaner way.
>
> Thank you for your 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: Clojure web framework

2012-10-03 Thread arekanderu
Hello,

I had a similar question as the OP so I thought i should post it in this 
thread instead of starting a new one.

I am trying to build a web services api which will only respond in json 
format. I had a look at everything suggested in this topic and I am leaning 
towards noir. Do you think this would be a good option for a web services 
api or should i go with ring + compojure, or something else?? In addition, 
I will be needing to add authentication and authorization at the api and I 
haven't found a noir middleware to be able to handle this. Do I need to 
roll out something of my own with the use of noir pre-route and maybe a 
middleware or is there something in existence which I am not aware of?

Thank you for any replies.

On Friday, September 28, 2012 10:36:20 AM UTC+3, Yakovlev Roman wrote:
>
> Hi
> So i'd like to point to the problem here. Clojure web framework in google 
> get these results, at least for me
> 1. noir
> 2. stackoverflow question 2008 year
> 3. stackoverflow question 2010 year
> 4. joodo ( outdated thing developed by one person)
> 5. Compojure ( routing dsl)
> So there is no popular framework these days for clojure.
> Noir is mostly Chris Granger thing. As he make Lighttable today Noir 
> developed by some other people ( or may be on person not sure). Main site 
> instructions are nice but already outdated ( lein2). No news, no blog, no 
> new features, no examples, no infrastructure. Lein new project, insert noir 
> in dependencies and you don't have working app, you must add :main and 
> stuff to work. What about testing ? no info, no structure, decide on your 
> own. 
> It's no secret that web development today is biggest and popular trend. If 
> language and it's community have good web framework that language will gain 
> more popularity. 
> Take Ruby on rails it has over 30 core contributers, huuuge community, 
> active development, industry standart web development framework. Good 
> testing, development infrastracture, easy start, sprockets for js css 
> managment and so on. Also it has some books about testing and framework 
> itself which is good start point for newbies. 
> I like Clojure, for simplicity mostly. It has amazing power and i believe 
> it can be very good platform for web development. 
> So what i suggest :
> Take 1 platform for web development in Clojure (for example noir as most 
> mature framework) .
> Form working core group from 5-6 people.
> Decide about name of the project ( or take Noir)
> Make good site about it
> Make a plan for development ( what core features should have first version)
> Make first version
> Make couple good examples
> Make good documentation and maybe a book ( community book for example on 
> github that will be online and updated frequently).
> --
> http://www.playframework.org/ good example what site could be
> Alternative to online book can be guides, as for ruby on rails 
> http://guides.rubyonrails.org/index.html
> Another good news that there is nice web IDE for Clojure by Bodil Stokke 
> https://github.com/bodil/catnip. Super easy install, very nice 
> insterface, reactive interface ( no need for browser refresh, autorecompile 
> when you save ) web based ! and under active development, just perfect 
> place for newbies to start. So this project also can be added to Clojure 
> Web framework project.
> Also we have ClojureScript so Clojure web framework would be perfect place 
> where this thing can shine.
> Let's discuss.
>

-- 
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: Clojure web framework

2012-10-03 Thread arekanderu
Thanks a lot Gaz :)

I am pretty new to clojure but I like it a lot so far. Good to know that 
there are a lot of things going fast in the clojure community!

On Wednesday, October 3, 2012 9:39:21 PM UTC+3, Gaz wrote:
>
> You do not need noir to create a simple json api, just use compojure. 
> I find the Cheshire json library to also be useful: 
> https://github.com/dakrone/cheshire. Authentication and authorization 
> libs were pretty much up to you until 
> https://github.com/cemerick/friend was released fairly recently, so 
> you could look at that (I haven't used it myself). I would also 
> recommend starting the server with embedded jetty rather than mess 
> around with app containers, it's far simpler (look at 
> ring.adapter.jetty). 
>
> We have many json apis written in clojure in production where I work, 
> and they have worked out great for us. 
>
> On Wed, Oct 3, 2012 at 1:01 PM, arekanderu > 
> wrote: 
> > Hello, 
> > 
> > I had a similar question as the OP so I thought i should post it in this 
> > thread instead of starting a new one. 
> > 
> > I am trying to build a web services api which will only respond in json 
> > format. I had a look at everything suggested in this topic and I am 
> leaning 
> > towards noir. Do you think this would be a good option for a web 
> services 
> > api or should i go with ring + compojure, or something else?? In 
> addition, I 
> > will be needing to add authentication and authorization at the api and I 
> > haven't found a noir middleware to be able to handle this. Do I need to 
> roll 
> > out something of my own with the use of noir pre-route and maybe a 
> > middleware or is there something in existence which I am not aware of? 
> > 
> > Thank you for any replies. 
> > 
> > 
> > On Friday, September 28, 2012 10:36:20 AM UTC+3, Yakovlev Roman wrote: 
> >> 
> >> Hi 
> >> So i'd like to point to the problem here. Clojure web framework in 
> google 
> >> get these results, at least for me 
> >> 1. noir 
> >> 2. stackoverflow question 2008 year 
> >> 3. stackoverflow question 2010 year 
> >> 4. joodo ( outdated thing developed by one person) 
> >> 5. Compojure ( routing dsl) 
> >> So there is no popular framework these days for clojure. 
> >> Noir is mostly Chris Granger thing. As he make Lighttable today Noir 
> >> developed by some other people ( or may be on person not sure). Main 
> site 
> >> instructions are nice but already outdated ( lein2). No news, no blog, 
> no 
> >> new features, no examples, no infrastructure. Lein new project, insert 
> noir 
> >> in dependencies and you don't have working app, you must add :main and 
> stuff 
> >> to work. What about testing ? no info, no structure, decide on your 
> own. 
> >> It's no secret that web development today is biggest and popular trend. 
> If 
> >> language and it's community have good web framework that language will 
> gain 
> >> more popularity. 
> >> Take Ruby on rails it has over 30 core contributers, huuuge community, 
> >> active development, industry standart web development framework. Good 
> >> testing, development infrastracture, easy start, sprockets for js css 
> >> managment and so on. Also it has some books about testing and framework 
> >> itself which is good start point for newbies. 
> >> I like Clojure, for simplicity mostly. It has amazing power and i 
> believe 
> >> it can be very good platform for web development. 
> >> So what i suggest : 
> >> Take 1 platform for web development in Clojure (for example noir as 
> most 
> >> mature framework) . 
> >> Form working core group from 5-6 people. 
> >> Decide about name of the project ( or take Noir) 
> >> Make good site about it 
> >> Make a plan for development ( what core features should have first 
> >> version) 
> >> Make first version 
> >> Make couple good examples 
> >> Make good documentation and maybe a book ( community book for example 
> on 
> >> github that will be online and updated frequently). 
> >> -- 
> >> http://www.playframework.org/ good example what site could be 
> >> Alternative to online book can be guides, as for ruby on rails 
> >> http://guides.rubyonrails.org/index.html 
> >> Another good news that there is nice web IDE for Clojure by Bodil 
> Stokke 
> >> https://github.com/bodil/catnip. Super easy install, very nice 
> insterface, 
> >> reactive

Noir.response and custom java object

2012-10-04 Thread arekanderu
Hello,

I am not sure if i am supposed to ask a noir-related question in the group 
but the noir issues at github  is closed 
so i thought someone here might know. I am trying to use a custom 
encoderwith
 noir.response but i am failing to understand how.  

This is what I am trying to do which at the moment fails of course:

(ns my-app.views.my-page
>
>   (:require [noir.response :as resp]))
>
>
>> (defpage "/my-page" []
>
>   (let [java-object (do-something)]
>
>   (resp/json java-object)))
>
>
The error message

Cannot JSON encode object of class: class-name-here - (class 
> org.codehaus.jackson.JsonGenerationException) 

 
It does work however if i use gson  on 
my java-object before i pass it to *resp/json *but i prefer to do it 
without gson. I am pretty sure its possible :)
*
*
Thank you for any replies
 

-- 
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: Noir.response and custom java object

2012-10-04 Thread arekanderu
Hi Gaz

That's exactly the part that I can't figure out. Where exactly am I 
supposed to do that? Inside the clj where I am going to use noir.response? 
My apologies if my question seems silly but I am a bit brain-blocked with 
this.

On Thursday, October 4, 2012 8:26:29 PM UTC+3, Gaz wrote:
>
> It seems to be using cheshire under the covers, did you add an encoder 
> for your class? e.g: 
>
> (add-encoder java.awt.Color 
> (fn [c jsonGenerator] 
> (.writeString jsonGenerator (str c 
>
> On Thu, Oct 4, 2012 at 12:04 PM, arekanderu > 
> wrote: 
> > Hello, 
> > 
> > I am not sure if i am supposed to ask a noir-related question in the 
> group 
> > but the noir issues at github is closed so i thought someone here might 
> > know. I am trying to use a custom encoder with noir.response but i am 
> > failing to understand how. 
> > 
> > This is what I am trying to do which at the moment fails of course: 
> > 
> >>> (ns my-app.views.my-page 
> >>> 
> >>>   (:require [noir.response :as resp])) 
> >>> 
> >>> 
> >>> (defpage "/my-page" [] 
> >>> 
> >>>   (let [java-object (do-something)] 
> >>> 
> >>>   (resp/json java-object))) 
> > 
> > 
> > The error message 
> > 
> >> Cannot JSON encode object of class: class-name-here - (class 
> >> org.codehaus.jackson.JsonGenerationException) 
> > 
> > 
> > It does work however if i use gson on my java-object before i pass it to 
> > resp/json but i prefer to do it without gson. I am pretty sure its 
> possible 
> > :) 
> > 
> > Thank you for any replies 
> > 
> > 
> > -- 
> > 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 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: Noir.response and custom java object

2012-10-04 Thread arekanderu
In fact, on the latest commit, 
response.clj<https://github.com/bitwalker/noir/blob/master/src/noir/response.clj>does
 not seem to use chesire.custom anymore even though this 
commit<https://github.com/bitwalker/noir/commit/6408d7028cae00937588b599b7c3305bb48e32fd>indicates
 otherwise.

On Thursday, October 4, 2012 8:32:25 PM UTC+3, arekanderu wrote:
>
> Hi Gaz
>
> That's exactly the part that I can't figure out. Where exactly am I 
> supposed to do that? Inside the clj where I am going to use noir.response? 
> My apologies if my question seems silly but I am a bit brain-blocked with 
> this.
>
> On Thursday, October 4, 2012 8:26:29 PM UTC+3, Gaz wrote:
>>
>> It seems to be using cheshire under the covers, did you add an encoder 
>> for your class? e.g: 
>>
>> (add-encoder java.awt.Color 
>> (fn [c jsonGenerator] 
>>     (.writeString jsonGenerator (str c 
>>
>> On Thu, Oct 4, 2012 at 12:04 PM, arekanderu  wrote: 
>> > Hello, 
>> > 
>> > I am not sure if i am supposed to ask a noir-related question in the 
>> group 
>> > but the noir issues at github is closed so i thought someone here might 
>> > know. I am trying to use a custom encoder with noir.response but i am 
>> > failing to understand how. 
>> > 
>> > This is what I am trying to do which at the moment fails of course: 
>> > 
>> >>> (ns my-app.views.my-page 
>> >>> 
>> >>>   (:require [noir.response :as resp])) 
>> >>> 
>> >>> 
>> >>> (defpage "/my-page" [] 
>> >>> 
>> >>>   (let [java-object (do-something)] 
>> >>> 
>> >>>   (resp/json java-object))) 
>> > 
>> > 
>> > The error message 
>> > 
>> >> Cannot JSON encode object of class: class-name-here - (class 
>> >> org.codehaus.jackson.JsonGenerationException) 
>> > 
>> > 
>> > It does work however if i use gson on my java-object before i pass it 
>> to 
>> > resp/json but i prefer to do it without gson. I am pretty sure its 
>> possible 
>> > :) 
>> > 
>> > Thank you for any replies 
>> > 
>> > 
>> > -- 
>> > 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 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: Noir.response and custom java object

2012-10-04 Thread arekanderu
OK, the problem is that the custom encoders isn't merged with the master 
tree yet so, you need to download this 
branch<https://github.com/bitwalker/noir/tree/custom-json-encoding>, 
run *lein jar *at the root directory of the project and then use that jar 
file in your project dependencies. I did that by having a local maven 
repo<http://www.pgrs.net/2011/10/30/using-local-jars-with-leiningen/>in my 
project

...unfortunately though a bunch of deps are required though or else lein 
run blows up. I am still working on it to see what can i do. What a mess

On Thursday, October 4, 2012 8:54:17 PM UTC+3, arekanderu wrote:
>
> In fact, on the latest commit, 
> response.clj<https://github.com/bitwalker/noir/blob/master/src/noir/response.clj>does
>  not seem to use chesire.custom anymore even though this 
> commit<https://github.com/bitwalker/noir/commit/6408d7028cae00937588b599b7c3305bb48e32fd>indicates
>  otherwise.
>
> On Thursday, October 4, 2012 8:32:25 PM UTC+3, arekanderu wrote:
>>
>> Hi Gaz
>>
>> That's exactly the part that I can't figure out. Where exactly am I 
>> supposed to do that? Inside the clj where I am going to use noir.response? 
>> My apologies if my question seems silly but I am a bit brain-blocked with 
>> this.
>>
>> On Thursday, October 4, 2012 8:26:29 PM UTC+3, Gaz wrote:
>>>
>>> It seems to be using cheshire under the covers, did you add an encoder 
>>> for your class? e.g: 
>>>
>>> (add-encoder java.awt.Color 
>>> (fn [c jsonGenerator] 
>>> (.writeString jsonGenerator (str c 
>>>
>>> On Thu, Oct 4, 2012 at 12:04 PM, arekanderu  wrote: 
>>> > Hello, 
>>> > 
>>> > I am not sure if i am supposed to ask a noir-related question in the 
>>> group 
>>> > but the noir issues at github is closed so i thought someone here 
>>> might 
>>> > know. I am trying to use a custom encoder with noir.response but i am 
>>> > failing to understand how. 
>>> > 
>>> > This is what I am trying to do which at the moment fails of course: 
>>> > 
>>> >>> (ns my-app.views.my-page 
>>> >>> 
>>> >>>   (:require [noir.response :as resp])) 
>>> >>> 
>>> >>> 
>>> >>> (defpage "/my-page" [] 
>>> >>> 
>>> >>>   (let [java-object (do-something)] 
>>> >>> 
>>> >>>   (resp/json java-object))) 
>>> > 
>>> > 
>>> > The error message 
>>> > 
>>> >> Cannot JSON encode object of class: class-name-here - (class 
>>> >> org.codehaus.jackson.JsonGenerationException) 
>>> > 
>>> > 
>>> > It does work however if i use gson on my java-object before i pass it 
>>> to 
>>> > resp/json but i prefer to do it without gson. I am pretty sure its 
>>> possible 
>>> > :) 
>>> > 
>>> > Thank you for any replies 
>>> > 
>>> > 
>>> > -- 
>>> > 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 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: Noir.response and custom java object

2012-10-04 Thread arekanderu
After adding the dependencies of noir to my own project.clj, everything 
worked fine :)

I hope that noir developers will make it a bit easier soon...

On Thursday, October 4, 2012 9:26:56 PM UTC+3, arekanderu wrote:
>
> OK, the problem is that the custom encoders isn't merged with the master 
> tree yet so, you need to download this 
> branch<https://github.com/bitwalker/noir/tree/custom-json-encoding>, 
> run *lein jar *at the root directory of the project and then use that jar 
> file in your project dependencies. I did that by having a local maven 
> repo<http://www.pgrs.net/2011/10/30/using-local-jars-with-leiningen/>in my 
> project
>
> ...unfortunately though a bunch of deps are required though or else lein 
> run blows up. I am still working on it to see what can i do. What a mess
>
> On Thursday, October 4, 2012 8:54:17 PM UTC+3, arekanderu wrote:
>>
>> In fact, on the latest commit, 
>> response.clj<https://github.com/bitwalker/noir/blob/master/src/noir/response.clj>does
>>  not seem to use chesire.custom anymore even though this 
>> commit<https://github.com/bitwalker/noir/commit/6408d7028cae00937588b599b7c3305bb48e32fd>indicates
>>  otherwise.
>>
>> On Thursday, October 4, 2012 8:32:25 PM UTC+3, arekanderu wrote:
>>>
>>> Hi Gaz
>>>
>>> That's exactly the part that I can't figure out. Where exactly am I 
>>> supposed to do that? Inside the clj where I am going to use noir.response? 
>>> My apologies if my question seems silly but I am a bit brain-blocked 
>>> with this.
>>>
>>> On Thursday, October 4, 2012 8:26:29 PM UTC+3, Gaz wrote:
>>>>
>>>> It seems to be using cheshire under the covers, did you add an encoder 
>>>> for your class? e.g: 
>>>>
>>>> (add-encoder java.awt.Color 
>>>> (fn [c jsonGenerator] 
>>>> (.writeString jsonGenerator (str c 
>>>>
>>>> On Thu, Oct 4, 2012 at 12:04 PM, arekanderu  
>>>> wrote: 
>>>> > Hello, 
>>>> > 
>>>> > I am not sure if i am supposed to ask a noir-related question in the 
>>>> group 
>>>> > but the noir issues at github is closed so i thought someone here 
>>>> might 
>>>> > know. I am trying to use a custom encoder with noir.response but i am 
>>>> > failing to understand how. 
>>>> > 
>>>> > This is what I am trying to do which at the moment fails of course: 
>>>> > 
>>>> >>> (ns my-app.views.my-page 
>>>> >>> 
>>>> >>>   (:require [noir.response :as resp])) 
>>>> >>> 
>>>> >>> 
>>>> >>> (defpage "/my-page" [] 
>>>> >>> 
>>>> >>>   (let [java-object (do-something)] 
>>>> >>> 
>>>> >>>   (resp/json java-object))) 
>>>> > 
>>>> > 
>>>> > The error message 
>>>> > 
>>>> >> Cannot JSON encode object of class: class-name-here - (class 
>>>> >> org.codehaus.jackson.JsonGenerationException) 
>>>> > 
>>>> > 
>>>> > It does work however if i use gson on my java-object before i pass it 
>>>> to 
>>>> > resp/json but i prefer to do it without gson. I am pretty sure its 
>>>> possible 
>>>> > :) 
>>>> > 
>>>> > Thank you for any replies 
>>>> > 
>>>> > 
>>>> > -- 
>>>> > 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 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: Is game development Clojure(functional in general) friendly?

2012-10-30 Thread arekanderu
I also happened to read an interesting 
articlerecently
 about functional programming by John 
Carmack . 

On Tuesday, October 30, 2012 9:00:07 AM UTC+2, titon barua wrote:
>
> Hi,
> I am very new to Clojure and functional programming in general. I am game 
> development enthusiast(although did nothing more than a tetris clone in 
> python and C). As far as i've seen OpenGL, it's mostly state manipulation 
> and seems to me like completely against Clojure's philosophy. Could there 
> exist some kind of magic that makes all the state manipulations disappear?
>
> By the way, I think Clojure's concurrency capabilities can upsurge a new 
> era for game development as "GigaHertz war" have pretty much stopped and 
> game developers are  still reluctant to use full capabilities of multi-core 
> hardware. Perhaps they didn't discover clojure yet? (:
>
> I for one would like some good and maintained wrappers for input and 
> graphics in Clojure - like SDL and OpenGL.
>
> Disclaimer: I am a wannabe game dev chained to internet/web paradigm for 
> financial reasons ... :(
>

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

Question about doseq

2012-10-30 Thread arekanderu
Hello all,

I have the following code:

(def my-hash {"1" {:a-key {:value "a value"} :another-key "another value" 
>> :a-third-key []}
>
>  "2" {:a-key {:value "a value"} :another-key "another 
>> value" :a-third-key []}}
>
>
In the following example i get the following result: 

user=> (doseq [[id item] my-hash] (println item))

{:a-key {:value a value}, :another-key another value, :a-third-key []}

{:a-key {:value a value}, :another-key another value, :a-third-key []}

nil


On the above example, it looks *almost* normal to me. For instance, why 
*{:value 
a value}* is not returned as *{:value "a value"} *? Same goes for *:another 
key*
It still looks like a hashmap though. Isn't it?

The behavior however which confused me even more is the following:

user=> (doseq [[id item] my-hash
>   key (:a-key item)]
> (println key)) 
> [:value a value]
> [:value a value]
> nil


I was expecting the above to return:

{:value "a value"} 
> {:value "a value"}
> nil


Can someone explain to me why vector is being returned and how can I 
achieve the result I was expecting? What am I missing here? Am i misusing 
the doseq bindings? 

Thank you for your 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