Re: Looking for an equivalent of reductions for reduce for ->

2015-03-01 Thread Thomas Hicks
I'm not quite sure what you want to do here in the general case but.a 
few thoughts:

-> is implemented as a macro, whereas reduce and reductions are functions. 
Depending on what you really want you may need a macro over a function.

Note that reduce is picky about the reducing function it takes: it must be 
function of two arguments. This is very different from the operation of the 
threading macro (->).

If you want to implement this as a function, you might look at the 
implementation of juxt or comp for ideas since they are HOFs (functions 
taking other functions as arguments).

If functions f, g, and h all take one argument you can implement the 
specific example you show as: ((juxt f (comp g f) (comp h g f)) 1)
For functions of one argument this could be generalized to take multiple 
arguments and return vectors of composed applications:

(defn intermediates [fns]
  (let [f (fn [x] ((apply juxt (map #(apply comp (reverse (take %1 fns))) 
(range 1 (inc (count fns) x)) ]
(fn [& xs] (map f xs)) ))

(def f inc)
(defn g [x] (* x 2))
(defn h [n] (+ n 5))

((intermediates [f g]) 5)
;=> ([6] [12])

((intermediates [f g h]) 5)
;=> ([6 12 17])

((intermediates [f g h]) 5 7 9)  ; each vector is [(f x) (g (f x)) (h 
(g (f x)))]
;=> ([6 12 17] [8 16 21] [10 20 25])

cheers,
-tom


On Sunday, March 1, 2015 at 2:16:06 PM UTC-7, Bill Allen wrote:
>
> Hopefully that makes sense. Let me illustrate.
>
> (reduce + [1 2 3 4])
> ;=> 10
> (reductions + [1 2 3 4)
> ;=> (1 3 6 10)
>
> (-> 1 f g h)
> ;=> (h (g (f 1)))
>
> I'm hoping to get a function that behaves like:
> (--> 1 f g h)
> ;=> ((f 1) (g (f 1) (h (g (f 1
>
> Any ideas?
>
> Regards,
> Bill
>
>

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


Re: clojure.core/Format Bug?

2014-04-07 Thread Thomas Hicks
If I copy and paste your format s-exp into LT, I see the correct result, 
displayed correctly. Same for a plain lein repl using Clojure 1.6.0.
I'm using LightTable 0.6.5, binary 0.8.4. (On OSX 10.8.5 using 
Java 1.7.0_60-ea-b12).
   HTH,
  -tom


On Sunday, April 6, 2014 2:00:55 PM UTC-7, Paul Umbers wrote:
>
> Andy, thanks for your help.
>
> I've checked and the displayed result is different only in LightTable. 
> When I execute the format functions from a CLI REPL I get the correct 
> number of characters displayed. I've checked the LT issues and can't see 
> anything that matches, so I'll probably raise it as a Clojure plugin bug.
>

-- 
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: Questions about using error-kit

2012-09-30 Thread Thomas Hicks
Thanks Luc and Mayank. I will chuck the monolithic contrib lib and check 
out Slingshot as an error-kit replacement.
-t

On Sunday, September 30, 2012 1:52:08 PM UTC-7, Luc wrote:
>
> Contrib has been separated into separate libs since 1.3 
>
> http://dev.clojure.org/display/design/Where+Did+Clojure.Contrib+Go 
>
> Suggests to use slingshot. 
>
> The are 1.3 compliant monolithic contrib versions out there but it's 
> better to move to 
> the new implementations. 
>
> Luc P. 
>

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

Questions about using error-kit

2012-09-30 Thread Thomas Hicks
I'm trying to learn something about error-kit and encountering some 
unexpected responses, as follows:

Clojure 1.3.0
user=> (use 'clojure.contrib.error-kit)
Warning: *handler-stack* not declared dynamic and thus is not dynamically 
rebindable, but its name suggests otherwise. Please either indicate 
^:dynamic *handler-stack* or change the name.
Warning: *continues* not declared dynamic and thus is not dynamically 
rebindable, but its name suggests otherwise. Please either indicate 
^:dynamic *continues* or change the name.
nil
user=> (def tm (throw-msg java.lang.IllegalArgumentException))
#'user/tm
user=> (tm "hi")
IllegalArgumentException   
sun.reflect.NativeConstructorAccessorImpl.newInstance0 
(NativeConstructorAccessorImpl.java:-2)

First, note the dynamic variable warnings upon use...(might this possibly 
indicate an out-of-date version of error-kit (I'm using using 
clojure-contrib.jar from 1.2.0)?).

I'm just starting with error-kit but I would have expected that the last 
call (involving a previous throw-msg function) would have returned 
something like this:

-> java.lang.IllegalArgumentException: hi

and would not have included the additional junk from 
'sun.reflect.NativeConstructor'. Is this some OSX Java bug or does this 
also happen on other JDKs?
Any help or suggestions appreciated.
-t


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