Re: Deref Nil

2016-09-12 Thread Deon Moolman
Hi Tim,

Thanks for your feedback, I appreciate it! :)

Ye, I've been tempted and bitten by atoms-in-atoms before, and that's no
fun - My case here is slightly different though, I have a single atom and
construct cursors to paths within, which are swappable and deref'able like
normal atoms, but they modify the value of the original atom (just their
allocated slice inside though).

I'll give a bit of detail on one very specific usecase I have, my structure
looks like so:

My atom (and its value) looks like so:

(atom
  {:product
   [{:product/id 1 :product/name "Cooker"}
{:product/id 2 :product/name "Pan"}]
   :image
   [{:image/id 1 :image/url "..." :image/product 1}]})

And I have a function (reverse-lookup) that will take a product id and
return a list of cursors that point to the individual images for a product,
so:

(reverse-lookup :image/product 1) => [(cursor {:image/id :image/url "..."
:image/product 1})]
(reverse-lookup :image/product 2) => []

If I'm only interested in, say, rendering the first image, I can call
(render-image
@(first product-image-list)) - without nil-punning, I have to do add an if
to every usage, where I'd rather just handle nil to a default image
placeholder inside render-image.

I also have a function will literally return the first (and likely only)
element in the lookup, which will also return a cursor or nil if not found.
One could argue that the data needs integrity checking in that case before
getting into the atom, but in my case I'd rather just nil-pun all the
things since it's not exactly a big deal.

Anyhow - back to the original question - I'm wondering if there's anything
I'm missing about the decision to not nil-pun deref - If it's simply a
matter of 'didn't really think of it', that's fine, I'm quite content to
work around it, but if there's a deeper philosophical reason, then I'm keen
to add it to my understanding of the underlying foundation of clojure.

Thanks again for all the feedback, I really do appreciate your time!

Cheers,
 - Deon

On Sat, Sep 10, 2016 at 9:08 PM, Timothy Baldridge 
wrote:

> I've worked with a model much like this, and as an experience report: it
> resulted in a lot of pain. Atoms inside atoms, or really more than one atom
> for the entire state of your app results in to many sources of mutability.
> On top of that, you have the problem of async updates: some part of your
> state may or may not exist depending if some async call to the server has
> completed yet. I can't say much more without seeing your code, but I would
> use this as an opprotunity to re-think the design of the app a bit.
>
> If you are getting nils in unexpected places you can either nil-prune
> (what you're asking for here), or you can ask "why am I getting a nil here
> when I didn't expect it...how can I keep from doing this in the future?".
> Perhaps the answer is as simple as never calling the render function of a
> component until all its state exists (Om.Next takes an approach somewhat
> like this).
>
> On Sat, Sep 10, 2016 at 11:12 AM, Deon Moolman  wrote:
>
>> Hi Sean,
>>
>> Good point - as you have noticed, my use case is in ClojureScript - I'm
>> using reagent cursors (hence the deref) fairly heavily to chop my main atom
>> up and send only the relevant bits to components, but still allow them to
>> locally modify their state.
>>
>> In my specific case, I do lookups for parts of the tree that may not
>> exist, and in that case 'nil' is the obvious return value.
>>
>> Cheers,
>>  - Deon
>>
>> On Fri, Sep 9, 2016 at 6:55 PM, Sean Corfield  wrote:
>>
>>> Like Stuart, I don’t encounter atom-or-nil as a common pattern – could
>>> you explain why you have functions that might return an atom or might
>>> return nil?
>>>
>>>
>>>
>>> FYI, We have about 40,000 lines of Clojure at World Singles and just a
>>> handful of atoms (and most of those are going away as we refactor the code
>>> to use Component more extensively).
>>>
>>>
>>>
>>> Sean Corfield -- (970) FOR-SEAN -- (904) 302-SEAN
>>> An Architect's View -- http://corfield.org/
>>>
>>> "If you're not annoying somebody, you're not really alive."
>>> -- Margaret Atwood
>>>
>>>
>>>
>>> On 9/9/16, 1:10 AM, "Deon Moolman" >> of cmdrd...@gmail.com> wrote:
>>>
>>>
>>>
>>> Hey all,
>>>
>>>
>>>
>>> I'm having some pain with atoms and dereferencing nil - mostly around my
>>> functions sometimes returning an atom and other times nil - I don't really
>>> want to create a special 'nil' atom and do the bits for returning that and
>>> I don't want to be checking nils absolutely everywhere when nil-punning
>>> works perfectly otherwise, so I was wondering what the pitfalls of this
>>> approach would be?
>>>
>>>
>>>
>>> (extend-type nil IDeref
>>>
>>>   (-deref [_] nil))
>>>
>>>
>>>
>>> Effectively, make @nil nil-pun to nil. makes sense to me?
>>>
>>>
>>>
>>> Cheers,
>>>
>>>  - Deon
>>>
>>>
>>>
>>>
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Clojure" group.
>>> To post to thi

KLIPSE (repl + plugin) just hit the 400 stars on github!

2016-09-12 Thread Yehonathan Sharvit
KLIPSE (https://github.com/viebel/klipse) is both clojure[script] web repl
and a plugin.

The repl is at: http://app.klipse.tech

The klipse plugin is a javascript tag that transforms static code snippets
of an html page into live and interactive snippets:

   1. Live: The code is executed in your browser
   2. Interactive: You can modify the code and it is evaluated as you type

The code evaluation is done in the browser with bootstraped clojurescript.

The code editing is done with CodeMirror .

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ANN] defn Podcast Episode #9 Onyx

2016-09-12 Thread Bradley Pitts
hi vijay

i've been trying to get in touch to finally finish the website and get the 
project in an a manageable state. please get back to me so we can make a 
plan.

best,
bradley



On Wednesday, September 7, 2016 at 2:24:31 AM UTC-4, Vijay Kiran wrote:
>
> Hello Everyone,
>
> The new episode of defn podcast is now available, Onyx with Michael 
> Drogalis and Lucas Bradstreet! You can listen to it on SoundCloud[1] or via 
> itunes[1]
>
> We'd really appreciate your comments or feedback :)
>
> Enjoy,
> Ray & Vijay
>
>
> [1] https://defn.audio/2016/09/06/episode-9-onyx-with-mike-and-lucas/
> [2] https://itunes.apple.com/us/podcast/defn/id1114899563?mt=2
>

-- 
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: idiomatic way of counting loop iteration

2016-09-12 Thread Gary Johnson
Almost right. The iterate function is an infinite sequence generator, so 
(count (iterate f x)) will never return.

If you want the iteration to terminate when cond is false (as in your 
original example), you're looking for this:

(count (take-while cond (iterate (fn [[a b]] ... [new-a new-b]) [init-a init
-b])))

Happy hacking!

-- 
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: idiomatic way of counting loop iteration

2016-09-12 Thread Timothy Baldridge
Also consider map-indexed if you just need to count how many things go
through a lazy seq. It works like map, but takes a (fn [idx itm] ...) where
idx is the index of the item in the overall seq.

On Mon, Sep 12, 2016 at 3:10 PM, Gary Johnson 
wrote:

> Almost right. The iterate function is an infinite sequence generator, so
> (count (iterate f x)) will never return.
>
> If you want the iteration to terminate when cond is false (as in your
> original example), you're looking for this:
>
> (count (take-while cond (iterate (fn [[a b]] ... [new-a new-b]) [init-a
> init-b])))
>
> Happy hacking!
>
> --
> 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.
>



-- 
“One of the main causes of the fall of the Roman Empire was that–lacking
zero–they had no way to indicate successful termination of their C
programs.”
(Robert Firth)

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


Read the code of clj_http ,then I have one questions,#' that mean ?

2016-09-12 Thread 章亮
Hi
   Recently Read the code of clj_http, then I have one questions.
  In the clj_http/client.clj 
(def ^:dynamic request
  (wrap-request #'core/request))
#‘ is very strange.I don't understand #'  that mean after I searched some 
the books of clojure.
And I test for eample :
(defn test1 [x]
   (+ x 2))
(defn test2 [client]
   (client 3))
(defn test3 []
   (test2 #'test1))
(defn test4 []
   (test2 test1))
exec  test3  test4   the result is same,so I think I need 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.


Read the code of clj_http ,then I have one questions,#' that mean ?

2016-09-12 Thread Tienson Qin
It means var quote, I think you can find more in clojure.org reader literals. 
http://clojure.org/reference/reader

-- 
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: Read the code of clj_http ,then I have one questions,#' that mean ?

2016-09-12 Thread Erik Assum
In addition, 
https://yobriefca.se/blog/2014/05/19/the-weird-and-wonderful-characters-of-clojure/
 is a good read. 

Erik. 
-- 
i farta

> Den 13. sep. 2016 kl. 06.59 skrev Tienson Qin :
> 
> It means var quote, I think you can find more in clojure.org reader literals. 
> http://clojure.org/reference/reader
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> --- 
> You received this message because you are subscribed to the Google Groups 
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Read the code of clj_http ,then I have one questions,#' that mean ?

2016-09-12 Thread 章亮
I read http://clojure.org/reference/reader and 
 
https://yobriefca.se/blog/2014/05/19/the-weird-and-wonderful-characters-of-clojure/
thank you 
#' - Var macro

#' is the var quote. It is the same a the var method,

user=> (def nine 9)#'user/nineuser=> nine9user=> (var nine)#'user/nineuser=> 
#'nine#'user/nine

When used it will attempt to return the referenced var. This is useful when 
you want to talk about the reference/declaration instead of the value it 
represents. See the use of meta in the metadata (^) discussion.


在 2016年9月13日星期二 UTC+8上午10:13:50,章亮写道:
>
> Hi
>Recently Read the code of clj_http, then I have one questions.
>   In the clj_http/client.clj 
> (def ^:dynamic request
>   (wrap-request #'core/request))
> #‘ is very strange.I don't understand #'  that mean after I searched some 
> the books of clojure.
> And I test for eample :
> (defn test1 [x]
>(+ x 2))
> (defn test2 [client]
>(client 3))
> (defn test3 []
>(test2 #'test1))
> (defn test4 []
>(test2 test1))
> exec  test3  test4   the result is same,so I think I need 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.