- macro and accessing context

2013-07-02 Thread pmf
Hi,

I sometimes (in fact quite often) want to use the - macro like this:

(- {}
  (assoc :a a)
  (assoc :b (some-fn CTX)))


where CTX should be the current value of the threaded element. Currently, 
I'm forced to write a helper function

(defn add-some-fn [ctx]
  (assoc ctx :b (some-fn ctx)))

and rewrite my usage of - to

(- {}
  (assoc :a a)
  (add-some-fn))

This works, of course, but somehow feels awkward (it destroys the 
uniformity of my assoc chaining). Is there a more idiomatic way to do this?

-- 
-- 
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: - macro and accessing context

2013-07-02 Thread Meikel Brandmeyer (kotarak)
Hi,

since 1.5 there is 
as-http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/as-
:

(as- {} ctx
  (assoc ctx :a a)
  (assoc ctx :b (some-fn ctx)))

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
--- 
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: - macro and accessing context

2013-07-02 Thread pmf
That looks like it can do the job; thanks!

On Tuesday, July 2, 2013 8:12:04 AM UTC+2, Meikel Brandmeyer (kotarak) 
wrote:

 Hi,

 since 1.5 there is 
 as-http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/as-%3E
 :

 (as- {} ctx
   (assoc ctx :a a)
   (assoc ctx :b (some-fn ctx)))

 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
--- 
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: - macro and accessing context

2013-07-02 Thread John D. Hume
I believe the intended idiom for as- (and the reason it doesn't take a
binding vector, like other forms that create locals) is

(- {}
  (assoc :a a)
  (as- ctx
(assoc ctx :b (some-fn ctx
On Jul 2, 2013 1:12 AM, Meikel Brandmeyer (kotarak) m...@kotka.de wrote:

 Hi,

 since 1.5 there is 
 as-http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/as-%3E
 :

 (as- {} ctx
   (assoc ctx :a a)
   (assoc ctx :b (some-fn ctx)))

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




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