Generalizing -> and ->> forms

2015-08-28 Thread Akhil Wali
I've been trying to refactor the -> and ->> forms to use a common macro 
form.
Ended up with this.

(defmacro threading [a b x forms]
  (loop [x x
 forms forms]
(if forms
  (let [form (first forms)
f (first form)
r (rest form)
threaded (if (seq? form)
   (with-meta
 `(~f ~`(~a ~`(list ~x ~@r))
  ~`(~b ~`(list ~x ~@r)))
 (meta form))
   (list form x))]
(recur threaded (next forms)))
  x)))

(defmacro -> [x & forms]
  `(threading ~'first ~'second
  ~x ~forms))

(defmacro ->> [x & forms]
  `(threading ~'second ~'first
  ~x ~forms))


This does work, but it's a bit of whammy.
Anyone with suggestions for improvement?

-- 
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: Generalizing -> and ->> forms

2015-08-28 Thread Moe Aboulkheir
On Fri, Aug 28, 2015 at 12:37 PM, Akhil Wali  wrote:

> This does work, but it's a bit of whammy.
> Anyone with suggestions for improvement?

It doesn't appear to work for simple cases (where the expressions
aren't function calls w/ additional arguments), e.g. (-> 1 inc)

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: Generalizing -> and ->> forms

2015-08-28 Thread Atamert Ölçgen
Hi,

threading doesn't need to be a macro. In fact it would be easier to test if
it's just a function.

Also, you know about as->, don't you?


On Fri, Aug 28, 2015 at 2:37 PM, Akhil Wali 
wrote:

> I've been trying to refactor the -> and ->> forms to use a common macro
> form.
> Ended up with this.
>
> (defmacro threading [a b x forms]
>   (loop [x x
>  forms forms]
> (if forms
>   (let [form (first forms)
> f (first form)
> r (rest form)
> threaded (if (seq? form)
>(with-meta
>  `(~f ~`(~a ~`(list ~x ~@r))
>   ~`(~b ~`(list ~x ~@r)))
>  (meta form))
>(list form x))]
> (recur threaded (next forms)))
>   x)))
>
> (defmacro -> [x & forms]
>   `(threading ~'first ~'second
>   ~x ~forms))
>
> (defmacro ->> [x & forms]
>   `(threading ~'second ~'first
>   ~x ~forms))
>
>
> This does work, but it's a bit of whammy.
> Anyone with suggestions for improvement?
>
> --
> 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.
>



-- 
Kind Regards,
Atamert Ölçgen

◻◼◻
◻◻◼
◼◼◼

www.muhuk.com

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


Re: Generalizing -> and ->> forms

2015-08-28 Thread Akhil Wali
​On Fri, Aug 28, 2015 at 5:33 PM, Atamert Ölçgen  wrote:

> Also, you know about as->, don't you?


​Well, I'm aware of all other threading forms like some->, as->, etc.
This is just something I'm trying ​with -> and ->>, and thought I'd discuss.

Perhaps the definition of  as-> can be used as a better premise.
But, as-> is entirely different and simpler shape that uses interleave. 


On Friday, August 28, 2015 at 5:34:24 PM UTC+5:30, Atamert Ölçgen wrote:
>
> Hi,
>
> threading doesn't need to be a macro. In fact it would be easier to test 
> if it's just a function.
>
> Also, you know about as->, don't you?
>
>
> On Fri, Aug 28, 2015 at 2:37 PM, Akhil Wali  > wrote:
>
>> I've been trying to refactor the -> and ->> forms to use a common macro 
>> form.
>> Ended up with this.
>>
>> (defmacro threading [a b x forms]
>>   (loop [x x
>>  forms forms]
>> (if forms
>>   (let [form (first forms)
>> f (first form)
>> r (rest form)
>> threaded (if (seq? form)
>>(with-meta
>>  `(~f ~`(~a ~`(list ~x ~@r))
>>   ~`(~b ~`(list ~x ~@r)))
>>  (meta form))
>>(list form x))]
>> (recur threaded (next forms)))
>>   x)))
>>
>> (defmacro -> [x & forms]
>>   `(threading ~'first ~'second
>>   ~x ~forms))
>>
>> (defmacro ->> [x & forms]
>>   `(threading ~'second ~'first
>>   ~x ~forms))
>>
>>
>> This does work, but it's a bit of whammy.
>> Anyone with suggestions for improvement?
>>
>> -- 
>> 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.
>>
>
>
>
> -- 
> Kind Regards,
> Atamert Ölçgen
>
> ◻◼◻
> ◻◻◼
> ◼◼◼
>
> www.muhuk.com
>

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


Re: Generalizing -> and ->> forms

2015-08-28 Thread Akhil Wali

>
> It doesn't appear to work for simple cases (where the expressions 
> aren't function calls w/ additional arguments), e.g. (-> 1 inc) 


Thanks for that one. How silly of me :P
Here's a better version of threading.

(defmacro threading [a b x forms]
  (loop [x x
 forms forms]
(if forms
  (let [form (first forms)
threaded (if (seq? form)
   (with-meta
 `(~(first form)
   ~`(~a ~`(list ~x ~@(next form)))
   ~`(~b ~`(list ~x ~@(next form
 (meta form))
   (list form x))]
(recur threaded (next forms)))
  x)))



On Friday, August 28, 2015 at 5:30:44 PM UTC+5:30, Moe Aboulkheir wrote:
>
> On Fri, Aug 28, 2015 at 12:37 PM, Akhil Wali  > wrote: 
>
> > This does work, but it's a bit of whammy. 
> > Anyone with suggestions for improvement? 
>
> It doesn't appear to work for simple cases (where the expressions 
> aren't function calls w/ additional arguments), e.g. (-> 1 inc) 
>
> 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: Generalizing -> and ->> forms

2015-08-28 Thread Moe Aboulkheir
On Fri, Aug 28, 2015 at 12:37 PM, Akhil Wali 
wrote:

>
> This does work, but it's a bit of whammy.
> Anyone with suggestions for improvement?
>

I went over this quickly, though it seems to work OK:

(defn threading [x first? forms]
  (reduce
   (fn [x form]
 (if (seq? form)
   (let [[op & args] form
 args (conj (cond-> args (not first?) vec) x)]
 (apply list op args))
   (list form x)))
   x forms))

(defmacro -> [x & forms]
  (threading x true forms))

(defmacro ->> [x & forms]
  (threading x false forms))

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: Generalizing -> and ->> forms

2015-08-28 Thread Akhil Wali
That's pretty neat!
But then -> will be implemented using cond->, which is slightly off.

On Friday, August 28, 2015 at 6:07:46 PM UTC+5:30, Moe Aboulkheir wrote:
>
> On Fri, Aug 28, 2015 at 12:37 PM, Akhil Wali  > wrote:
>
>>
>> This does work, but it's a bit of whammy.
>> Anyone with suggestions for improvement?
>>
>
> I went over this quickly, though it seems to work OK:
>
> (defn threading [x first? forms]
>   (reduce
>(fn [x form]
>  (if (seq? form)
>(let [[op & args] form
>  args (conj (cond-> args (not first?) vec) x)]
>  (apply list op args))
>(list form x)))
>x forms))
>
> (defmacro -> [x & forms]
>   (threading x true forms))
>
> (defmacro ->> [x & forms]
>   (threading x false forms))
>
> 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: Generalizing -> and ->> forms

2015-08-28 Thread Moe Aboulkheir
The function is actually shorter without cond->: (conj (if first? args (vec
args)) x)

Take care,
Moe

On Fri, Aug 28, 2015 at 1:59 PM, Akhil Wali 
wrote:

> That's pretty neat!
> But then -> will be implemented using cond->, which is slightly off.
>
> On Friday, August 28, 2015 at 6:07:46 PM UTC+5:30, Moe Aboulkheir wrote:
>>
>> On Fri, Aug 28, 2015 at 12:37 PM, Akhil Wali 
>> wrote:
>>
>>>
>>> This does work, but it's a bit of whammy.
>>> Anyone with suggestions for improvement?
>>>
>>
>> I went over this quickly, though it seems to work OK:
>>
>> (defn threading [x first? forms]
>>   (reduce
>>(fn [x form]
>>  (if (seq? form)
>>(let [[op & args] form
>>  args (conj (cond-> args (not first?) vec) x)]
>>  (apply list op args))
>>(list form x)))
>>x forms))
>>
>> (defmacro -> [x & forms]
>>   (threading x true forms))
>>
>> (defmacro ->> [x & forms]
>>   (threading x false forms))
>>
>> 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.
>

-- 
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: Generalizing -> and ->> forms

2015-08-28 Thread Akhil Wali
​Good one!

On Fri, Aug 28, 2015 at 6:34 PM, Moe Aboulkheir  wrote:

> The function is actually shorter without cond->: (conj (if first? args
> (vec args)) x)





-- 
Akhil Wali

# https://github.com/darth10
# https://darth10.github.io

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


Strange eval behavior making Java types more generic

2015-08-28 Thread psfblair
I'm pretty new to Clojure, so please bear with me if this is obvious for 
some reason. Maybe the answer is out there and I've been looking in the 
wrong place.

I'm seeing some strange behavior losing type information when using eval in 
certain circumstances. Here is an example:

Eval-ing a Timestamp is still a Timestamp:

(def my-timestamp (clj-time.coerce/to-timestamp (java.util.Date.)))
=> #'user/my-timestamp
(type my-timestamp)
=> java.sql.Timestamp
(eval my-timestamp)
=> #inst "2015-08-28T15:03:10.55700-00:00"
(type (eval my-timestamp))
=> java.sql.Timestamp

Using the Timestamp as a hash value also works as expected:

(def timestamp-holder {:a my-timestamp})
=> #'user/timestamp-holder
(type (:a timestamp-holder))
=> java.sql.Timestamp
(eval (:a timestamp-holder))
=> #inst "2015-08-28T15:03:10.55700-00:00"
(type (eval (:a timestamp-holder)))
=> java.sql.Timestamp


But now instead eval the hash map and its type gets more generic:

(eval timestamp-holder)
=> {:a #inst "2015-08-28T15:03:10.557-00:00"}
(type (:a (eval timestamp-holder)))
=> java.util.Date

Is this expected behavior?

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


[ANN] Yagni 0.1.4 released

2015-08-28 Thread W. David Jarvis
Happy to announce the long-delayed release of Yagni 0.1.4!

This release includes the following major changes: 

 * Fixed a ClassNotFound exception when Yagni encountered a function with a 
name like a class constructor (e.g. `->Something`)
 * Removed the log4j dependency entirely.
 * Cleaned up the main `run-yagni` function to expose a cleaner, more 
functional interface.

Planned changes in Yagni 0.1.5 are support for reader literals, which most 
of the groundwork has been laid for.

As always, feedback/issues/comments welcome :)

 - V

-- 
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] Yagni 0.1.4 released

2015-08-28 Thread W. David Jarvis
A link to the project page might not have been a bad 
idea: https://github.com/venantius/yagni

On Friday, August 28, 2015 at 9:59:25 AM UTC-7, W. David Jarvis wrote:
>
> Happy to announce the long-delayed release of Yagni 0.1.4!
>
> This release includes the following major changes: 
>
>  * Fixed a ClassNotFound exception when Yagni encountered a function with 
> a name like a class constructor (e.g. `->Something`)
>  * Removed the log4j dependency entirely.
>  * Cleaned up the main `run-yagni` function to expose a cleaner, more 
> functional interface.
>
> Planned changes in Yagni 0.1.5 are support for reader literals, which most 
> of the groundwork has been laid for.
>
> As always, feedback/issues/comments welcome :)
>
>  - V
>

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


Interest in a book on Nathan Marz's Specter?

2015-08-28 Thread Brian Marick
Specter https://github.com/nathanmarz/specter is a library for querying 
and "updating" data structures. For most things, I prefer it to zippers 
or hand-written descent functions. Specter's approach is similar to 
lenses, but I find it easier to understand and more featureful.


When starting out, I would have liked a short, exercise- and 
example-filled book on Specter. I'm thinking of writing that book.


Leanpub lets people indicate their interest on a book's webpage, which 
is here: https://leanpub.com/specter If you are, please do.


Brian Marick

--
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: Generalizing -> and ->> forms

2015-08-28 Thread Alan Thompson
I have become very partial to a simple adaptation of as-> from the Tupelo
Core  library.  I almost always like to
be explicit about the location the previous value, since either -> or ->>
can sometimes be difficult if the threading forms don't always want the arg
as the first or last parameter.  Copying the pattern of Groovy/Ruby, I
almost always name the threading placeholder "it".  Since I don't like
repetition (& I would argue that the as-> form has its params backwards!) I
created the simple it-> form:

(defmacro it->
  "A threading macro like as-> that always uses the symbol 'it' as the
placeholder for the next threaded value:
  (it-> 1
(inc it)
(+ it 3)
(/ 10 it))
  ;=> 2
   "
  [expr & forms]
  `(let [~'it ~expr
 ~@(interleave (repeat 'it) forms)
   ]
 ~'it ))


Alan


On Fri, Aug 28, 2015 at 6:14 AM, Akhil Wali  wrote:

> ​Good one!
>
> On Fri, Aug 28, 2015 at 6:34 PM, Moe Aboulkheir  wrote:
>
>> The function is actually shorter without cond->: (conj (if first? args
>> (vec args)) x)
>
>
>
>
>
> --
> Akhil Wali
>
> # https://github.com/darth10
> # https://darth10.github.io
>
> --
> 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: Generalizing -> and ->> forms

2015-08-28 Thread Matching Socks

The parameter order of as-> makes it convenient to use *inside *-> so you 
can name the threaded parameter only where it needs naming:

(-> "UFOT"
(reverse)
(->> (apply str))
(string/lower-case)
(as-> x (string/replace "slip on a tofu" x "banana peel")))






On Friday, August 28, 2015 at 6:51:44 PM UTC-4, Alan Thompson wrote:
>
> I have become very partial to a simple adaptation of as-> from the Tupelo 
> Core  library.  I almost always like 
> to be explicit about the location the previous value, since either -> or 
> ->> can sometimes be difficult if the threading forms don't always want the 
> arg as the first or last parameter.  Copying the pattern of Groovy/Ruby, I 
> almost always name the threading placeholder "it".  Since I don't like 
> repetition (& I would argue that the as-> form has its params backwards!) I 
> created the simple it-> form:
>
> (defmacro it->
>   "A threading macro like as-> that always uses the symbol 'it' as the 
> placeholder for the next threaded value:
>   (it-> 1
> (inc it)
> (+ it 3)
> (/ 10 it))
>   ;=> 2
>"
>   [expr & forms]
>   `(let [~'it ~expr
>  ~@(interleave (repeat 'it) forms)
>]
>  ~'it ))
>
>
> Alan
>
>
> On Fri, Aug 28, 2015 at 6:14 AM, Akhil Wali  > wrote:
>
>> ​Good one!
>>
>> On Fri, Aug 28, 2015 at 6:34 PM, Moe Aboulkheir > > wrote:
>>
>>> The function is actually shorter without cond->: (conj (if first? args 
>>> (vec args)) x)
>>
>>
>>
>>
>>
>> -- 
>> Akhil Wali 
>>
>> # https://github.com/darth10
>> # https://darth10.github.io
>>
>> -- 
>> 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: Generalizing -> and ->> forms

2015-08-28 Thread Moe Aboulkheir
On Fri, Aug 28, 2015 at 11:51 PM, Alan Thompson  wrote:

> I have become very partial to a simple adaptation of as-> from the Tupelo
> Core  library.  I almost always like
> to be explicit about the location the previous value, since either -> or
> ->> can sometimes be difficult if the threading forms don't always want the
> arg as the first or last parameter.
>

You've likely seen it, but https://github.com/rplevy/swiss-arrows has -<>
and -<>>, which capture "<>" for placement, and default to either the first
or last position when not present in an expression.  IIRC they don't
require wrapping all expressions in lists, a difference from it-> - e.g.
(-<> 1 inc (* 5) (/ 4 <> 3)).  I haven't used the library, but would expect
readability to be improved by allowing the placeholder to be omitted except
when needed.  I was/am an enthusiast of the "cut" macro from SRFI-26 (which
uses <>) - I think cut-> and cut->> scan much better than -<>>.


>   Copying the pattern of Groovy/Ruby, I almost always name the threading
> placeholder "it".  Since I don't like repetition (& I would argue that the
> as-> form has its params backwards!)
>

The parameter ordering seems awkward, but enables embedding within
thread-first.  The example above becomes (-> 1 inc (* 5) (as-> it (/ 4 it
3)))

(2/15, in case you were curious)

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.