Re: arity-3 `iterate`

2015-11-16 Thread Ben Wolfson
ncomp would be faster if it's implemented a la exponentiation by squaring.

On Mon, Nov 16, 2015 at 12:55 PM, Ben Wolfson <wolf...@gmail.com> wrote:

> If you rearrange the arguments of your proposed three-argument iterate:
>
> (defn iterate
>   ...
>   ([f n x]
>(if (zero? n)
>  x
>  (recur f (f x) (dec n
>
> it supports partial application of the multiply-composed function to
> different arguments more easily, which suggests redefinition as:
>
> (defn ncomp [f n]
>   (loop [g identity n n]
> (if (zero? n)
>g
>(recur (comp g f) (dec n)
>
> This seems to come closer to matching what's desired from the
> three-argument iterate without confusingly (as you note) overloading
> "iterate": you want f applied n times to x and the stream of intermediate
> values isn't really of interest.
>
> On Mon, Nov 16, 2015 at 12:37 PM, Jason Felice <jason.m.fel...@gmail.com>
> wrote:
>
>>
>> I *frequently* see:
>>
>> (nth (iterate foo bar) n)
>>
>> And:
>>
>> (->> (iterate foo bar)
>>(drop n)
>>first)
>>
>> I've also coded this in `avi` after being surprised no such thing exists:
>>
>> (defn n-times
>>   [thing n a-fn]
>>   (reduce
>> (fn [thing n]
>>   (a-fn thing))
>> thing
>> (range n)))
>>
>> (which is kind of a bad implementation, now that I think of it):
>>
>> Would it be useful to file a ticket for a new arity for iterate?:
>>
>> (defn iterate
>>   ...
>>   ([f x n]
>>(if (zero? n)
>>  x
>>  (recur f (f x) (dec n
>>
>> There's a little bit of weirdness - this returns a single value, while
>> the other arity returns a lazy sequence.  However, I think it's the correct
>> name (and the original arity might  have better been named "iterations" for
>> symmetry with "reduce" and "reductions").  But ah well.
>>
>> Thoughts?
>>
>> --
>> 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.
>>
>
>
>
> --
> Ben Wolfson
> "Human kind has used its intelligence to vary the flavour of drinks, which
> may be sweet, aromatic, fermented or spirit-based. ... Family and social
> life also offer numerous other occasions to consume drinks for pleasure."
> [Larousse, "Drink" entry]
>
>


-- 
Ben Wolfson
"Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure."
[Larousse, "Drink" entry]

-- 
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: arity-3 `iterate`

2015-11-16 Thread Ben Wolfson
If you rearrange the arguments of your proposed three-argument iterate:

(defn iterate
  ...
  ([f n x]
   (if (zero? n)
 x
 (recur f (f x) (dec n

it supports partial application of the multiply-composed function to
different arguments more easily, which suggests redefinition as:

(defn ncomp [f n]
  (loop [g identity n n]
(if (zero? n)
   g
   (recur (comp g f) (dec n)

This seems to come closer to matching what's desired from the
three-argument iterate without confusingly (as you note) overloading
"iterate": you want f applied n times to x and the stream of intermediate
values isn't really of interest.

On Mon, Nov 16, 2015 at 12:37 PM, Jason Felice <jason.m.fel...@gmail.com>
wrote:

>
> I *frequently* see:
>
> (nth (iterate foo bar) n)
>
> And:
>
> (->> (iterate foo bar)
>(drop n)
>first)
>
> I've also coded this in `avi` after being surprised no such thing exists:
>
> (defn n-times
>   [thing n a-fn]
>   (reduce
> (fn [thing n]
>   (a-fn thing))
> thing
> (range n)))
>
> (which is kind of a bad implementation, now that I think of it):
>
> Would it be useful to file a ticket for a new arity for iterate?:
>
> (defn iterate
>   ...
>   ([f x n]
>(if (zero? n)
>  x
>  (recur f (f x) (dec n
>
> There's a little bit of weirdness - this returns a single value, while the
> other arity returns a lazy sequence.  However, I think it's the correct
> name (and the original arity might  have better been named "iterations" for
> symmetry with "reduce" and "reductions").  But ah well.
>
> Thoughts?
>
> --
> 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.
>



-- 
Ben Wolfson
"Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure."
[Larousse, "Drink" entry]

-- 
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: A call for an idiomatic rendering of Clojure EDN in info/error messages

2015-11-13 Thread Ben Wolfson
 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.
>



-- 
Ben Wolfson
"Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure."
[Larousse, "Drink" entry]

-- 
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: Weird GenSyms behaviour across different quoted blocks in a macro

2015-08-26 Thread Ben Wolfson
unify-gensyms from potemkin will fix this:
https://github.com/ztellman/potemkin


On Wed, Aug 26, 2015 at 2:07 PM, Rafik NACCACHE rafik.nacca...@gmail.com
wrote:

 Suppose I have the following macro, which generates a function that does
 some repetitive generation, let's say:

 (defmacro a-macro
   [m]
   `(fn [f#]
  ~(for [i# m]
 `(*  (:val f#) ~i# 

 Note how I start with a quoted block in which I emit the fn header, and in
 which I use a gensym to capture its input, F#. I unquote to do my iterative
 processing, then I quote again to emit my macro output.

 If I macroexpand this:
 (clojure.pprint/pprint  (macroexpand '(a-macro (1 2 3

 I get :

 (fn*
  ([f__11552__auto__]
   ((clojure.core/* (:val f__11551__auto__) 1)
(clojure.core/* (:val f__11551__auto__) 2)
(clojure.core/* (:val f__11551__auto__) 3

 And I have a problem. The auto gensym for args declaration (...11522) is
 different from the gensyms applying this arg in my generated function body
 (...11551), so I cannot call my function.

 Any Idea why is that? And Can you please help me to sort this kind of
 situation?

 Thank you;

 Rafik

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




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
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] Clojure 1.8.0-alpha3

2015-07-31 Thread Ben Wolfson
On Fri, Jul 31, 2015 at 1:57 PM, Eduardo Aquiles Affonso Radanovitsck 
eduardoaquiles...@gmail.com wrote:

 Not sure if this is expected or not:

 (map (fn [v] {:k v}) #{1 2 3})
 = ({:k 1} {:k 3} {:k 2})
 (map #({:k %}) #{1 2 3})
 ArityException Wrong number of args (0) passed to: PersistentArrayMap
  clojure.lang.AFn.throwArity (AFn.java:429)


The same behavior is visible in earlier versions of clojure and has to do
with how the #(...) syntax is parsed. The workaround is #(do {:k %}).

Basically, whatever occurs between the #( and the ) is spliced into a list,
so if you have just one single expression, it turns into a function call:

user= (defmacro p [k] (println k))
#'user/p
user= (p #({:k %}))
(fn* [p1__7143#] ({:k p1__7143#}));;  attempting to invoke a map
with zero args
nil
user= (p #(do {:k %}))
(fn* [p1__7144#] (do {:k p1__7144#}))
nil

-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
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: #{:rant} Questions about contribution policy and clojure compiler source.

2015-07-18 Thread Ben Wolfson
On Sat, Jul 18, 2015 at 6:21 AM, Bozhidar Batsov bozhi...@batsov.com
wrote:

 On 18 July 2015 at 14:13, Andrey Antukh n...@niwi.nz wrote:

 Hi!

 I have some, maybe controversial, questions...

 A little bit of context:
 https://twitter.com/aphyr/status/621806683908542464

 Why this is like a normal approach for managing third party contributions
 to clojure core? This kind of things the only discourages the
 contributions. Maybe I don't have more context about this concrete case,
 but seems is not a unique.
 And in general, I have the perception that the clojure development
 process is a little bit opaque...


 Many people feel this way, but ultimately Clojure is Rich's project and I
 guess Cognitect's to some extent. If they don't want to run it like other
 more open  contribution-friendly OSS projects this is obviously their
 right.


This is a line of response I don't really understand; sure, it's within
Rich's/Cognitect's rights to run the project as they please, but I don't
think any of the aggrieved parties is claiming that Rich did something he
had no *right* to do. One can still suggest that the way the project's run
(or the way these specific issues were handled) is unwise or shabby or
otherwise capable of improvement. No one has to take the suggestion, but it
might be better if they did.

-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
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: transducer (+ closures) efficiency question

2015-06-24 Thread Ben Wolfson
On Wed, Jun 24, 2015 at 8:29 AM, Herwig Hochleitner hhochleit...@gmail.com
wrote:



 2015-06-24 1:25 GMT+02:00 Ben Wolfson wolf...@gmail.com:

 On Tue, Jun 23, 2015 at 4:17 PM, Ghadi Shayban gshay...@gmail.com
 wrote:


 Tangentially:
 (remove even?)
 Will be faster than
 (remove (fn [i] (even? i)))
 because in the first case the dereference of the var 'even?' happens
 only once and the value inside the var will be passed to `remove` at the
 outset.  In the second example the var dereference happens for every single
 item (though it's very cheap).  The second example is equivalent to writing 
 (remove
 #'even?)


 I can't seem to observe a difference between the two cases.


 A simple var reference like even? compiles to a fetch of its root val:
 @#'even?
 In the first case, that happens only once, passing the resulting fn object
 to remove. In the second case, the deref happens every time the fn is
 called, thus allowing for redefinition of even?.


I meant a difference in speed.

-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
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: transducer (+ closures) efficiency question

2015-06-23 Thread Ben Wolfson
On Tue, Jun 23, 2015 at 4:17 PM, Ghadi Shayban gshay...@gmail.com wrote:


 Tangentially:
 (remove even?)
 Will be faster than
 (remove (fn [i] (even? i)))
 because in the first case the dereference of the var 'even?' happens only
 once and the value inside the var will be passed to `remove` at the
 outset.  In the second example the var dereference happens for every single
 item (though it's very cheap).  The second example is equivalent to writing 
 (remove
 #'even?)


I can't seem to observe a difference between the two cases.

-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
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: A one line macro that looks right, but just won't work.

2015-06-05 Thread Ben Wolfson
On Fri, Jun 5, 2015 at 4:53 AM, Jordan Schatz jor...@noionlabs.com wrote:

 Hello!

 So here is a short example:


 -
 ;; Story:
 ;; I have an EDN data structure from an external API
 ;; I extract several patterns of records from it.
 ;; I would like to treat the patterns as data, pass them around, modify
 them etc.

 (def sample-data {:tracks {:items [1 2 3 4 5]}})
 (def pattern [:tracks :items count])

 ;; Thread first - should be what I need, but I need to apply it...
 (apply - (cons sample-data pattern)) ;; Can't take value of a macro:
 #'clojure.core/-

 ;; So make a new macro that reuses -
 (defmacro get- [data pattern]
   `(- ~data ~@pattern))


;; This raises an error
 (macroexpand-1 '(get- sample-data pattern))
 ;; Don't know how to create ISeq from: clojure.lang.Symbol


This raises an error because it's attempting to treat pattern as a
sequence for the purposes of splicing it.

If you put a println in your macro definition:

(defmacro get- [data pattern]
  (println pattern: pattern) ;; run at expansion time
  `(- ~data ~@pattern))

you'll be able to see what the macro is working with as it tries to do the
expansion. It gets the literal tokens you pass in, *not* what those values
evaluate to (which is why you can do control-flow manipulation in a macro),
so here it's getting just the symbol pattern.


 ;; But this works correctly
 (macroexpand-1 '(get- sample-data [:tracks :items count]))
 ;; As does
 (get- sample-data [:tracks :items count]) ; = 5


Here you're passing in a sequence, not a symbol, so the macro expansion can
splice correctly.

In this case, fwiw, you can just do this:

user= (def pattern [:tracks :items count])
#'user/pattern
user= (def sample-data {:tracks {:items [1 2 3 4 5]}})
#'user/sample-data
user= (defn get- [data fs]
  #_=   (reduce #(%2 %1) data fs))
#'user/get-
user= (get- sample-data pattern)
5

-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
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: Embedded systems and transpiling Clojure to Nim

2015-05-01 Thread Ben Wolfson
I'd assumed that pixie, like other projects using the RPython toolchain,
was itself compiled, but ran as an interpreter. Is that not the case?

On Fri, May 1, 2015 at 2:43 PM, Christopher Small metasoar...@gmail.com
wrote:

 Both Nim and Pixie ultimately compile to C, and would have just as many
 layers of indirection.

 On Fri, May 1, 2015 at 2:37 PM, Raoul Duke rao...@gmail.com wrote:

 all i'm trying to say is that the more layers of indirection you add,
 the more i won't give you any money on kickstarter.

 --
 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 a topic in the
 Google Groups Clojure group.
 To unsubscribe from this topic, visit
 https://groups.google.com/d/topic/clojure/VhemHGGCcVY/unsubscribe.
 To unsubscribe from this group and all its topics, 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.




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
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: flip in clojure

2015-04-30 Thread Ben Wolfson
- and - actually play nice with each other in this direction:

(- 4
  range
  (- (map inc))
  last)

results in 4, because we end up with (- (range 4) (- (map inc)) last)
-- (- (- (range 4) (map inc)) last) -- (last (- (range 4) (map
inc))) -- (last (map inc (range 4))). Though all this saves you is a
single function call, and flip is a useful thing to have around anyway.

btw, as far as flip, you don't need the into call; you can just do:

(defn flip [f] (fn [x y  args] (apply f y x args))

though I don't know how if this is actually significant.


On Thu, Apr 30, 2015 at 3:47 PM, Vagmi Mudumbai m...@vagmim.in wrote:

 Hi,

 I was introducing one of my colleagues to clojure[1] and we were
 trying to parse the reddit json as an exercise.

 (require '(clj-http.client :as client))
 (require '(clojure.data.json :as json))

 (def ^:const REDDIT-URL http://reddit.com/r/clojure.json?limit=100;)
 (def ^:const headers {:headers {User-Agent showoffclojure.core by
 vagmi}})

 (let [entries_ (- REDDIT-URL
(client/get headers)
(:body)
(json/read-str :key-fn keyword)
(:data)
(:children))]
   (map :data entries))

 It would have been nice if we were able to write the map as a part of
 the threading macro. So if there were a flip function like in haskell,
 we could flip the args to the function hand have the map in the
 threading macro. I could not find one so I wrote one.

 (defn flip [fn_]
   (fn [x y  args]
 (apply fn_ (into [y x] args

 Now I can bring in the map as a part of the - threading macro.

 (- REDDIT-URL
 (client/get headers)
 (:body)
 (json/read-str :key-fn keyword)
 (:data)
 (:children)
 ((flip map) :data))

 This seems to be rather easy and useful and gets rid of the let block.
 Are there any implications to performance or impact to laziness by
 using flip? This would be useful even on the transduced version of
 map like ((flip transduce) (map :data)) on the last expression.

 Regards,
 Vagmi


 [1]: (
 http://blog.tarkalabs.com/2015/04/30/experience-report-introducing-an-experienced-ruby-developer-to-clojure/
 )
 and

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




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
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: Deterministic macro expansion for Clojure?

2015-03-27 Thread Ben Wolfson
One way you can get what you want is to give up on the auto-gensym feature
of the #-terminated identifiers, and call gensym directly, enabling it to
be mocked out with with-redefs. E.g. instead of:

(defmacro m1
  [x f]
  `(let [x# ~x]
(~f x#)))

do

(defmacro m1 [x f]
   (let [x-sym (gensym)]
 `(let [~x-sym ~x] (~f ~x-sym

You can then do something like

(defn new-gensym []
   (let [counter (atom 0)]
  (fn [ [extra]] (symbol (str (or extra G_) (swap! counter inc))

(with-redefs [gensym (new-gensym)] (macroexpand-1 '(m1 1 inc)))

(not tested)

On Fri, Mar 27, 2015 at 5:50 PM, David James davidcja...@gmail.com wrote:

 I agree with this motivation behind this request, which I explain in more
 detail here:
 http://stackoverflow.com/questions/16745135/how-to-test-a-clojure-macro-that-uses-gensyms

 We should be able to test the behavior *and* the macroexpansion. (Most
 things in life are not simple either/or decisions. Don't believe people
 that tell you otherwise.)

 On Monday, March 23, 2015 at 12:58:49 PM UTC-4, Chris Ford wrote:

 I think it's useful to think of macros as an odd form of I/O. Just as you
 would separate out your templating from your domain functions, separate out
 your defmacro from regular functions that just happen to manipulate
 symbols. These functions will be easier to test.

 On 23 March 2015 at 16:23, Sean Corfield se...@corfield.org wrote:

 On Mar 22, 2015, at 7:52 PM, myguidingstar phuthuycuo...@gmail.com
 wrote:
  I wonder if there is any way to make macro expansion in Clojure
 deterministic. That would be useful in unit tests.

 I'd be very interested to understand your use case... Testing what the
 macro expands to seems like it is test the macro system itself, not your
 own code. Surely in a unit test you'd want to test the _behavior_ of the
 code instead?

 Sean Corfield -- (904) 302-SEAN
 An Architect's View -- http://corfield.org/

 Perfection is the enemy of the good.
 -- Gustave Flaubert, French realist novelist (1821-1880)



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




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
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: Given a list of maps, produce a sublist having distinct values for one key

2015-03-24 Thread Ben Wolfson
why not just accumulate the interested customers in a set rather than a seq
in the first place?

On Tue, Mar 24, 2015 at 2:50 PM, Simon Brooke still...@googlemail.com
wrote:

 I'm rewriting a very odd e-commerce website I first wrote in 1996, for a
 friend.

 The website features categories, which are supposed to be arranged into an
 acyclic directed graph (actually there are currently cycles in the graph,
 but there shouldn't be, and that is not the problem I'm trying to solve
 here; assume there are not). Customers can register interest in a category
 or in several categories. When an item is added to the site, we want to
 email every customer who may be interested in that item; which is to say

 customers who are interested in the category to which the item has been
 added, and
 customers who are interested in the parent of that category, and
 so on recursively to the root of the graph.

 Now, I can recurse up the graph asking each category in turn for the
 customers interested in it; and by concatenating the lists, arrive at one
 list of all the interested customers. The problem is that if one customer
 has registered interest in both a category and its parent, he will appear
 on the composite list twice. I need to construct from this a list of
 records in which each customer appears only once, otherwise they'll receive
 duplicate emails, which no-one likes.

 My solution, which I give below, is to recurse across the composite list
 constructing a map whose keys are email addresses and whose values are the
 customer records as maps; and then to take the values of that map. It
 works, but it doesn't feel like idiomatic clojure:

 (defn map-by-key
   From this `list-of-maps`, produce a map keyed on the values for this
 `key`
   [list-of-maps key]
   (if (empty? list-of-maps) {}
 (let [record (first list-of-maps)]
   (merge {(record key) record} (map-by-key (rest list-of-maps) key)


 (defn interested-customers
   Return a list of the customers interested in the category with this
`category-id`. Recurses up the tree of categories; `path` is passed to
protect against cycles in the tree (which shouldn't be there by are
not impossible)
   ([category-id]
(vals (map-by-key (interested-customers category-id #{}) :email)))
   ([category-id path]
(if (contains? path category-id) ()
 (let
   [id (if (integer? category-id) category-id
 (Integer/valueOf (str category-id)))
category (categories/fetch id)
parent (:parent category)
upstream (if (not (nil? parent)) (interested-customers parent (conj
 path id)) ())
interested (select schema/customer
   (with schema/category
 (where {:id id})))]
   (concat interested upstream)

 Can anyone re-express that in a more idiomatic form?

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




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
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: `(apply map vector ...)`, and passing `apply` a list vs. a vector

2015-03-18 Thread Ben Wolfson
Because symbols can only take one argument:

('vector :a) --- nil
('vector :a :i :x) --- the exception you saw.

On Wed, Mar 18, 2015 at 2:01 PM, John Gabriele jmg3...@gmail.com wrote:

 I see that you can pass extra args to `apply` --- between the func and the
 coll args --- and `apply` will prepend the extras to the coll before
 proceeding. For example, these all work:

 (apply + [1 2 3 4])
 (apply + 1 2 [3 4])
 (apply + 1 2 '(3 4))

 While thinking about how the following works:

 ~~~
 (apply map vector [[:a :b :c]
[:i :j :k]
[:x :y :z]])
 ~~~

 I found this:

 ~~~
 some-app.core= (apply map [vector [:a :b :c] [:i :j :k] [:x :y :z]])
 ([:a :i :x] [:b :j :y] [:c :k :z])

 some-app.core= (apply map '(vector [:a :b :c] [:i :j :k] [:x :y :z]))
 ArityException Wrong number of args (3) passed to: Symbol
 clojure.lang.AFn.throwArity (AFn.java:429)
 ~~~

 Why does it fail when I pass a list there instead of a vector?

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




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
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] Dunaj project, an alternative core API for Clojure

2015-03-05 Thread Ben Wolfson
Why? One of the purposes of PyPy, for instance, was to make it easier to
experiment with new features in possible Python interpreters, and that's a
separate project not undertaken in direct collaboration with CPython's
authors.

On Thu, Mar 5, 2015 at 1:45 PM, adrian.med...@mail.yu.edu wrote:

 Not sure exactly how to properly express my impression here, but it
 strikes me as odd that this project would not come out of direct
 collaboration with Clojure's core contributors. Proposed features should
 probably go through the official channels if you are serious about getting
 them included in the language.


 On Thursday, March 5, 2015 at 4:33:53 PM UTC-5, Jozef Wagner wrote:

 I'm happy to announce a project called Dunaj [1], which provides an
 alternative core API for Clojure. Its main aim is to experimentally test
 major additions to the language.

 Dunaj /ˈdunaɪ/ is a set of core language experiments aimed to improve
 Clojure language and its core API. It deals with language features that
 require changes across different parts of Clojure and which cannot be
 evaluated in isolation. Dunaj aims to bring Clojure even more towards
 simplicity, consistency and performance.
 It is intended to be used by regular Clojure developers, either for
 application or library development.

 Dunaj was created to test 10 experiments that bring significant changes
 to the Clojure language. As there is a substantial number of additions and
 changes, I want to try a bit unconventional approach here. Before I'll
 release the actual library, I will introduce Dunaj's experiments in a
 series of individual posts. Every part states the motivation behind the
 experiment, introduces changes and additions to the language and
 demonstrates its intended use. If you do not want to miss any of this, you
 may want to register for a mailing list at [1] or follow @dunajproject at
 Twitter.

 -- Jozef Wagner

 [1] http://www.dunaj.org/

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




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
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: Removing the 5th, 10th, 15th ... element of a list

2015-02-17 Thread Ben Wolfson
why not (mapcat next)?

On Tue, Feb 17, 2015 at 3:45 PM, Fluid Dynamics a2093...@trbvm.com wrote:

 On Tuesday, February 17, 2015 at 2:21:20 PM UTC-5, Cecil Westerhof wrote:

 What is the best way to remove all elements which position (counting from
 1) is a multiply of five out of a list?

 So the list:
 (1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21)
 becomes:
 (1 2 3 4 6 7 8 9 11 12 13 14 16 17 18 19 21)


 The correct answer, obviously, is

 (- s
   (cons ::sentinel)
   (partition n n nil)
   (map next)
   (mapcat identity))

 with, in this case, s = (range 1 22) and n = 5

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




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
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: Let bindings and immutability

2015-02-11 Thread Ben Wolfson
The multiple-binding form of let can be recursively transformed into nested
lets:

(let [name1 value1 name2 value2 ... name value] body)

(let [name1 value1] (let [name2 value2] ...  (let [name value] body)))

All you're doing with your let form is shadowing the name; there's no
mutation. If you had something like this:

(let [x 1]
   (let [x (inc x)]
 (println x))  ;; prints 2
   (println x)) ;; prints 1

it would be more obvious; it's less apparent in your case because there's
no room for the extra forms.


On Wed, Feb 11, 2015 at 5:49 PM, gvim gvi...@gmail.com wrote:

 On 12/02/2015 01:44, Laurens Van Houtven wrote:

 Hi,

 You're confusing mutation with single assignment. You're not mutating
 anything: 1 is still 1, 2 is still 2; you're just assigning the same name
 to different numbers. The numbers themselves are immutable.


 It's x that bothers me, not the values assigned to it. I don't quite get
 it as x seems to behave here like any old mutable variable in Ruby or
 Python even if it's not called mutation. I suppose I've just never really
 got this (big) one :(


 gvim

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




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
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: Extending the LispReader with embeded language lorms

2015-02-10 Thread Ben Wolfson
On Tue, Feb 10, 2015 at 11:29 AM, Alex Miller a...@puredanger.com wrote:

 Hi Henrik,

 There is a long-standing philosophical position in Clojure that it should
 not be possible to write programs that cannot be read by other users.


What does that mean?

-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
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: Testing macros that throw errors at compile time?

2015-01-22 Thread Ben Wolfson
(try (macroexpand-1 '(my-macro (ill-formed-arguments ...)))
  false ;; shouldn't get here
  (catch Exception _ true)) ;; whole expression should be true

As long as you know that the *right* exception is being thrown.

On Thu, Jan 22, 2015 at 4:41 PM, Scott Rabin scottra...@gmail.com wrote:

 We have a few macros in my employer's codebase that throw compile-time
 errors when you've given them invalid configurations, and have generally
 simply tested the result of these macros and not necessarily the direct
 expansion of said macros. What we would like to do is *test* that the
 macro blows up; but unfortunately, since this happens before tests are run,
 the result is that the compiler just complains at you instead of telling
 you that a specific test failed.

 Is there a decent way to test for thrown exceptions from macros other than
 writing a few cases and saying well, if the tests didn't even run, it's
 not right!?

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




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
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: How can I remove the nils in the result?

2014-12-22 Thread Ben Wolfson
This is a little more concise:

(- 00101110101110
   (map-indexed vector)
   (partition-by second)
   (filter #(= (second (first %)) \1))
   (map (comp (fn [[f  tail]]
  (if rest (str f - (last tail)) (str f)))
  (partial map first

On Mon, Dec 22, 2014 at 8:09 PM, Pauli pauli.mat...@gmail.com wrote:

 Hi, all:

 I'm tring to solve such a problem: Given a string consisting of 1 and
 0, find all the locations of 1, and print them in the format of
 intervals.

 For example: 00101110101110 = 3, 5-7, 9, 11-13

 Here is my solution:

 (defn bar [x]
   (letfn [(foo [mystr]
 (-
   (map-indexed vector mystr)
   (filter #(= (second %) \1))
   (map (comp inc first))
   (partition-all 2 1)
   (filter #(= 2 (count %)]
 (let [y (map #(if ( (- (second %) (first %)) 1) (print (first %) ,  
 (second %) -)) (foo x))]
   (print (ffirst y) - y (last (last (foo x)))


 With the code above, I got many nils in the result:

 (bar 00101110101110) = 3 , 5 -nil - (nil nil 7 , 9 -nil 9 , 11 -nil
 nil nil nil) 13

 How can I remove them?

 And, is there any way to make my code more concise?



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




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
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: How can I remove the nils in the result?

2014-12-22 Thread Ben Wolfson
(it's also zero-indexed, unlike yours, but that isn't a big change)

On Mon, Dec 22, 2014 at 9:17 PM, Ben Wolfson wolf...@gmail.com wrote:

 This is a little more concise:

 (- 00101110101110
(map-indexed vector)
(partition-by second)
(filter #(= (second (first %)) \1))
(map (comp (fn [[f  tail]]
   (if rest (str f - (last tail)) (str f)))
   (partial map first

 On Mon, Dec 22, 2014 at 8:09 PM, Pauli pauli.mat...@gmail.com wrote:

 Hi, all:

 I'm tring to solve such a problem: Given a string consisting of 1 and
 0, find all the locations of 1, and print them in the format of
 intervals.

 For example: 00101110101110 = 3, 5-7, 9, 11-13

 Here is my solution:

 (defn bar [x]
   (letfn [(foo [mystr]
 (-
   (map-indexed vector mystr)
   (filter #(= (second %) \1))
   (map (comp inc first))
   (partition-all 2 1)
   (filter #(= 2 (count %)]
 (let [y (map #(if ( (- (second %) (first %)) 1) (print (first %) ,  
 (second %) -)) (foo x))]
   (print (ffirst y) - y (last (last (foo x)))


 With the code above, I got many nils in the result:

 (bar 00101110101110) = 3 , 5 -nil - (nil nil 7 , 9 -nil 9 , 11 -nil
 nil nil nil) 13

 How can I remove them?

 And, is there any way to make my code more concise?



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




 --
 Ben Wolfson
 Human kind has used its intelligence to vary the flavour of drinks, which
 may be sweet, aromatic, fermented or spirit-based. ... Family and social
 life also offer numerous other occasions to consume drinks for pleasure.
 [Larousse, Drink entry]




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
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: a nicer way to write 1 - 2 + 3 - 4 ... +/- n

2014-11-15 Thread Ben Wolfson
or

(defn enumerate [xs] (map vector (range) xs))

(defn altsum [n] (reduce (fn [acc [i f]] (f acc (inc i)))
 0
(take n (enumerate (cycle [+ -])



On Fri, Nov 14, 2014 at 3:41 PM, Andrew Oberstar ajobers...@gmail.com
wrote:

 How about this?

 (defn cyclefn
   [ fs]
   (let [fcycle (cycle fs)
 rem-fs (atom fcycle)]
 (fn [ args]
   (let [f (first @rem-fs)]
 (swap! rem-fs rest)
 (apply f args)

 (reduce (cyclefn + -) (range 1 100))

 cyclefn could be used to cycle through any set of functions you want and
 the result used as if it was a normal function.


 Andy

 On Fri, Nov 14, 2014 at 7:16 AM, Henrik Lundahl henrik.lund...@gmail.com
 wrote:

 How about this?  :-)

 (defn altsum [n] (/ (if (odd? n) (+ 1 n) (- n)) 2))

 --
 Henrik


 On Fri, Nov 14, 2014 at 1:48 PM, Gary Verhaegen gary.verhae...@gmail.com
  wrote:

 What about cheating a bit?

 (interleave
   (iterate #(+ % 2) 1)
   (iterate #(- % 2) -2))

 Then take n, reduce +, or whatever else you might want to do with the
 series.

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


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




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
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: better way to group consecutive numbers in a vector?

2014-11-06 Thread Ben Wolfson
I don't know if this is *clearer* than the reduce version ...

user (def xs [1 3 4 5 7 9 10 11 12 ])
#'user/xs
user (defn consecutivizer []
(let [prev (atom nil)
  last-returned (atom (gensym))]
  (fn [cur]
(when-not (or (nil? @prev)
  (= (inc @prev) cur))
  (reset! last-returned (gensym)))
(reset! prev cur)
@last-returned)))
#'user/consecutivizer
user (partition-by (consecutivizer) xs)
((1) (3 4 5) (7) (9 10 11 12))




On Thu, Nov 6, 2014 at 5:10 PM, Gordon Stratton gordon.strat...@gmail.com
wrote:

 On Thu, Nov 6, 2014 at 10:22 PM, John Gabriele jmg3...@gmail.com wrote:
  Hi all,
 
  I've got this: `[1 3 4 5 7 9 10 11 12]`
  and I'd like to turn it into this: `[[1] [3 4 5] [7] [9 10 11 12]]`.
 
  That is, I'd like to group consecutive numbers together (the final goal
  being to produce something like `[1 3-5 7 9-12]`, but that's the
  easy part).
 
  I haven't found an easy way to do this. Here's what I've come up with in
  Clojure:
 
  ~~~clojure
  #!/usr/bin/env lein-exec
 
  (def v [1 3 4 5 7 9 10 11 12])
 
  (defn congeal-consecutives
[coll]
(reduce (fn [accum x]
  (if (= x (inc (last (last accum
(concat (butlast accum)
[(conj (last accum) x)])
(concat accum
[[x]])))
[[(first coll)]]
(rest coll)))
 
  (prn (congeal-consecutives v))
  ~~~
 
  Can anyone suggest a better / simpler / more easily-understandable way
 to do
  this in Clojure?

 Hey John,

 I think your approach is pretty good. I made some small modifications:

 (defn congeal-consecutives
   [xs]
   (if (empty? xs)
 []
 (reduce (fn [acc x]
   (let [l (last acc)]
 (if (= (inc (last l)) x)
   (conj (pop acc) (conj l x))
   (conj acc [x]
 [[(first xs)]]
 (rest xs

 I didn't see how to use `partition-by` in a way that made the function
 any clearer than the `reduce` version, but I'd be interested if you or
 others do.

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




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
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: CCW bug [SEVERE]

2014-10-31 Thread Ben Wolfson
On Fri, Oct 31, 2014 at 8:30 PM, Fluid Dynamics a2093...@trbvm.com wrote:


 It's not *my* fault the log file doesn't contain anything unusual between
 before the hang happened and after recovery. If CCW didn't log anything
 that helps indicate what was different or unusual on that occasion of
 saving, then there's simply not much I can do about it.


You could, theoretically, send it along anyway, per the developer's
request, and let him make the determination of whether or not there's
anything useful there.

-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
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: Why is my function faster with eval?

2014-10-10 Thread Ben Wolfson
I believe it's because the `mapper` function is just creating and returning
a map literal. The mapper function in the evaled version is something
like this:

user (def names '[n1 n2 n3 n4])
#'user/names
user (def headers '[h1 h2 h3 h4])
#'user/headers
user `(fn [[~@names]] ~(zipmap headers names))
(clojure.core/fn [[n1 n2 n3 n4]] {h4 n4, h3 n3, h2 n2, h1 n1})   ;; just a
map literal, whose keys are already known.

Whereas in the first version, zipmap has to be called, iterating over
headers and names each time.

On Fri, Oct 10, 2014 at 1:04 PM, Sean Corfield s...@corfield.org wrote:

 It may be more to do with the difference between `for` and `map`. How do
 these versions compare in your benchmark:

 (defn read-to-maps-partial [rows]
   (let [headers (-
   rows
   first
   (take-while (complement #{}))
   (map keyword))]
 (map (partial zipmap headers) (rest rows

 (defn read-to-maps-fn [rows]
   (let [headers (-
   rows
   first
   (take-while (complement #{}))
   (map keyword))
 mapper (fn [row] (zipmap headers row))]
 (map mapper (rest rows

 Sean

 On Oct 10, 2014, at 11:42 AM, Michael Blume blume.m...@gmail.com wrote:
  So I'm reading a bunch of rows from a huge csv file and marshalling
 those rows into maps using the first row as keys. I wrote the function two
 ways: https://gist.github.com/MichaelBlume/c67d22df0ff9c225d956 and the
 version with eval is twice as fast and I'm kind of curious about why.
 Presumably the eval'd function still implicitly contains a list of keys,
 it's still implicitly treating each row as a seq and walking it, so I'm
 wondering what the seq-destructuring and the map literal are doing under
 the hood that's faster.




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
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: Why is my function faster with eval?

2014-10-10 Thread Ben Wolfson
it's not quite at compile-time (since it's a dynamic call to eval, after
all, and names and headers aren't known at compile time), but it is
calling it eval-time, for lack of a better phrase.

On Fri, Oct 10, 2014 at 1:35 PM, Sean Corfield s...@corfield.org wrote:

 Ah, interesting... I hadn't considered it was running the zipmap at
 compile-time so it only runs it once as opposed to running it for each row!

 Sean

 On Oct 10, 2014, at 1:06 PM, Ben Wolfson wolf...@gmail.com wrote:
  I believe it's because the `mapper` function is just creating and
 returning a map literal. The mapper function in the evaled version is
 something like this:
 
  user (def names '[n1 n2 n3 n4])
  #'user/names
  user (def headers '[h1 h2 h3 h4])
  #'user/headers
  user `(fn [[~@names]] ~(zipmap headers names))
  (clojure.core/fn [[n1 n2 n3 n4]] {h4 n4, h3 n3, h2 n2, h1 n1})   ;; just
 a map literal, whose keys are already known.
 
  Whereas in the first version, zipmap has to be called, iterating over
 headers and names each time.





-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
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] rmap - define lazy, recursive maps

2014-10-08 Thread Ben Wolfson
This is pretty nifty:

user= (require '[rmap.core :as rmap])
nil
user= (def fibs (rmap/rmap FIBS {:a 0 :b 1 :next (- FIBS (update-in [:a]
(constantly (:b FIBS))) (update-in [:b] (constantly (+ (:b FIBS) (:a
FIBS)}))
#'user/fibs
user= (defn fib [n] (loop [fibs fibs n n] (if (zero? n) (:a fibs) (recur
(:next fibs) (dec n)
#'user/fib
user= (fib 40)
102334155



On Wed, Oct 8, 2014 at 1:37 PM, Arnout Roemers 
goo...@company.romeinszoon.nl wrote:

 Hi Zach,

 Thank you for checking out the library. You were right, some interfaces
 were missing and some methods had not been implemented. Though this was
 documented, they were limitations that could be fixed.

 *So, I'd like to announce version 0.2.0.*

 This version does implement all the necessary interfaces. Your source of
 def-map-type from Potemkin certainly helped here, although I did not
 use it directly. Nice work by the way. I have tested the current rmap
 implementation with the collection-check library, and it passes. Again,
 nice work, Zach.

 I still use a LinkedHashMap as the underlying data structure (as I want
 to keep track of the evaluation order), but I could not break that
 structure like the way you said. It seems to behave fine. Please let me
 know if you do know of a counter example.

 P.S. Zach, the README of the collection-check library is not updated
 with the dependency change to test.check.
 P.P.S. Still working on a post about the motivation and how it works.

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




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
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: ClojureScript 0.0-2341, Improved Analysis Transducers

2014-09-18 Thread Ben Wolfson
On Thu, Sep 18, 2014 at 6:25 PM, Timothy Baldridge tbaldri...@gmail.com
wrote:

 That'd probably require emails to be in HTML format (or have massive
 amounts of text in the email), that would most likely upset a whole other
 group of users.


the links seem pretty short: http://dev.clojure.org/jira/browse/CLJS-702,
e.g., and could easily follow the slug in this most recent announcement
without cluttering things up much.



 On Thu, Sep 18, 2014 at 7:09 PM, bob wee@gmail.com wrote:

 It would be better that the jira issues have links.


 On Thursday, September 18, 2014 8:23:45 PM UTC+8, David Nolen wrote:

 ClojureScript, the Clojure compiler that emits JavaScript source code.

 README and source code: https://github.com/clojure/clojurescript

 New release version: 0.0-2341

 Leiningen dependency information:

 [org.clojure/clojurescript 0.0-2341]

 This releases comes with considerably better analysis. Vars from other
 namespaces are finally also verified. Protocols previously saw very
 little analysis support. Protocol method implementations are now
 checked for validity against the declared protocol.

 Transducers are also now in sync with Clojure 1.7.0-alpha2

 Feedback welcome!

 ### Enhancements
 * transducers

 ### Fixes
 * CLJS-704: warn if protocol extended to type multiple times in
 extend-type
 * CLJS-702: warn if protocol doesn't match declared
 * CLJS-859: use https for the bootstrap script
 * CLJS-855: combinatorial code generation under advanced
 * CLJS-858: resolve-existing var does not check vars outside current ns
 * CLJS-852: same group-by as Clojure
 * CLJS-847: Safari toString fix
 * CLJS-846: preserve namespace metadata

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




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
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] data.int-map 0.1.0

2014-09-15 Thread Ben Wolfson
These maps support transient/persistent semantics, and also provide
special merge, merge-with, update, and update! methods that provide
significantly faster performance than their normal Clojure counterparts.
The keys must be in the range of [0, Long/MAX_VALUE].

On Mon, Sep 15, 2014 at 12:07 PM, Mark markaddle...@gmail.com wrote:

 This looks interesting because of how my app manipulates data from Datomic
 but it brings up the question, does int mean Java primitive 32-bit int or
 64-bit long?

 On Monday, September 15, 2014 11:51:47 AM UTC-7, Zach Tellman wrote:

 https://github.com/clojure/data.int-map

 This contrib library represents the union of two other libraries [1] [2],
 which are now both deprecated.  There's nothing too surprising here, but
 I'm happy to answer any questions.

 Zach

 [1] https://github.com/ztellman/immutable-int-map
 [2] https://github.com/ztellman/immutable-bitset

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




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
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: destructuring help: `(let [{:keys [...]} ...]` in a `defn` vs in a `let`

2014-08-27 Thread Ben Wolfson
The reason is that in the macroexpansion of let, map-based destructuring
has a seq? test which the list passes but the vector doesn't:

 (clojure.pprint/pprint (macroexpand-1 '(let [{:keys [a b]} [:a 1]] a)))
(let*
 [map__34214
  [:a 1]
  map__34214
  (if
   (clojure.core/seq? map__34214)
   (clojure.lang.PersistentHashMap/create
(clojure.core/seq map__34214))
   map__34214)
  b
  (clojure.core/get map__34214 :b)
  a
  (clojure.core/get map__34214 :a)]
 a)

Presumably this is because vectors can also be accessed with get, so you
can do something like this:

 (let [{a 0} [:a 1]] a)
:a

... confusing though it is.



On Wed, Aug 27, 2014 at 11:20 AM, John Gabriele jmg3...@gmail.com wrote:

 Why is it that although this works:

 ~~~clojure
 (defn foo [ args] (let [{:keys [a b]} args] (str a \~ b)))
 ;;= #'some-app.core/foo
 (foo :a 1 :b 2)
 ;;= 1~2
 ~~~

 this does not:

 ~~~clojure
 (let [{:keys [a b]} [:a 1 :b 2 :c 3]] (str a \~ b))
 ;;= ~
 ~~~

 ?

 And even stranger, *this* *does* work:

 ~~~clojure
 ;; Changed vector to a list.
 (let [{:keys [a b]} '(:a 1 :b 2 :c 3)] (str a \~ b))
 ;;= 1~2
 ~~~

 ?

 Incidentally, I see that the following `let` also does indeed work:

 ~~~clojure
 (let [ [ {:keys [a b]}] [:a 1 :b 2 :c 3] ] (str a \~ b))
 ;;= 1~2
 ~~~

 Thanks!

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




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
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: destructuring help: `(let [{:keys [...]} ...]` in a `defn` vs in a `let`

2014-08-27 Thread Ben Wolfson
... the other half of the answer being that when you have rest args with
(defn foo [ args] ...), args is bound to a seq.


On Wed, Aug 27, 2014 at 11:27 AM, Ben Wolfson wolf...@gmail.com wrote:

 The reason is that in the macroexpansion of let, map-based destructuring
 has a seq? test which the list passes but the vector doesn't:

  (clojure.pprint/pprint (macroexpand-1 '(let [{:keys [a b]} [:a 1]] a)))
 (let*
  [map__34214
   [:a 1]
   map__34214
   (if
(clojure.core/seq? map__34214)
(clojure.lang.PersistentHashMap/create
 (clojure.core/seq map__34214))
map__34214)
   b
   (clojure.core/get map__34214 :b)
   a
   (clojure.core/get map__34214 :a)]
  a)

 Presumably this is because vectors can also be accessed with get, so you
 can do something like this:

  (let [{a 0} [:a 1]] a)
 :a

 ... confusing though it is.



 On Wed, Aug 27, 2014 at 11:20 AM, John Gabriele jmg3...@gmail.com wrote:

 Why is it that although this works:

 ~~~clojure
 (defn foo [ args] (let [{:keys [a b]} args] (str a \~ b)))
 ;;= #'some-app.core/foo
 (foo :a 1 :b 2)
 ;;= 1~2
 ~~~

 this does not:

 ~~~clojure
 (let [{:keys [a b]} [:a 1 :b 2 :c 3]] (str a \~ b))
 ;;= ~
 ~~~

 ?

 And even stranger, *this* *does* work:

 ~~~clojure
 ;; Changed vector to a list.
 (let [{:keys [a b]} '(:a 1 :b 2 :c 3)] (str a \~ b))
 ;;= 1~2
 ~~~

 ?

 Incidentally, I see that the following `let` also does indeed work:

 ~~~clojure
 (let [ [ {:keys [a b]}] [:a 1 :b 2 :c 3] ] (str a \~ b))
 ;;= 1~2
 ~~~

 Thanks!

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




 --
 Ben Wolfson
 Human kind has used its intelligence to vary the flavour of drinks, which
 may be sweet, aromatic, fermented or spirit-based. ... Family and social
 life also offer numerous other occasions to consume drinks for pleasure.
 [Larousse, Drink entry]




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
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: Transducers are Coming

2014-08-06 Thread Ben Wolfson
if I'm reading the source correctly, ((partial map f) something) and ((map
f) something) are completely different, yes?


On Wed, Aug 6, 2014 at 1:13 PM, Alex Miller a...@puredanger.com wrote:



 On Wednesday, August 6, 2014 2:20:38 PM UTC-5, Robin Heggelund Hansen
 wrote:

 I just want to check that I understand this. Instead of returning and
 manipulating lazy-seqs, you compose functions


 yes


 (sort of like they way you would in Haskell?)



 which return reqular seqs (non-lazy).


 no - they return functions which you can choose to use eagerly, lazily, in
 a channel, or in other ways we haven't even thought of yet.


 So I guess the upside is more flexibility, but you get eager-evaluation.
 Or am I misunderstanding something?


 You get the choice eagerness (along with many other things).



 kl. 20:01:24 UTC+2 onsdag 6. august 2014 skrev Rich Hickey følgende:

 I pushed today the initial work on transducers. I describe transducers
 briefly in this blog post:

 http://blog.cognitect.com/blog/2014/8/6/transducers-are-coming

 This work builds on the work done for reducers, bringing
 context-independent mapping, filtering etc to other areas, such as
 core.async.

 This is work in progress. We will be cutting alpha releases to help make
 it easier to start using core's transducers together with core.async's new
 support for them.

 I am very excited about this powerful technique and how we all might use
 it.

 Please have a look.

 Feedback welcome,

 Rich

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




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
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: Could I get some feedback on this function?

2014-07-25 Thread Ben Wolfson
On Fri, Jul 25, 2014 at 3:09 PM, boz b...@cox.net wrote:

 I'm no Clojure guru, but why not just use set?
 http://grimoire.arrdem.com/1.6.0/clojure.core/set/

 But you want to get rid of the timestamp. Using map is probably right for
 that. So I think this is more idiomatic...

 (defn only-keep-unique-ids [ids]
   (set (map #(get-form-id-without-timestamp %) ids)))


That won't necessarily get the *first* one; also, it will return a set of
the prefixes, not a set of the ids that have the relevant prefixes.

-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
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: Could I get some feedback on this function?

2014-07-25 Thread Ben Wolfson
I'd probably write this like so, fwiw (parameterized by the transformation
function):

user (defn only-keep-unique-ids [id-transform ids]
(map first (vals (group-by id-transform ids
#'user/only-keep-unique-ids
user (only-keep-unique-ids (partial take 2) [aaa baa xsdf aa3
ba4 azx aa4 xsss])
(aaa baa xsdf azx)

it's not lazy, though.



On Fri, Jul 25, 2014 at 2:32 PM, Christopher Elwell 
elwell.christop...@gmail.com wrote:

 New to Clojure, how is this function that I wrote? Any suggestions for
 improvement; is it too complicated?

 It filters a sequence, leaving only the first occurrence of each item in
 the seq that has a matching prefix (get-form-id-without-timestamp gets
 just the id prefix).

 (defn only-keep-unique-ids [ids]
   (let [seen-ids (atom #{})
 filter-fn #(let [raw-form-id (get-form-id-without-timestamp %)
  is-unique (not (contains? @seen-ids raw-form-id))]
  (do (swap! seen-ids conj raw-form-id)
  is-unique))]
 (filter filter-fn ids)))



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




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
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] monads 0.2.2

2014-07-16 Thread Ben Wolfson
After a surprisingly long time I'm releasing a new version of my monads
library, focussed on expressivity and correctness:

https://github.com/bwo/monads

Leiningen:

[bwo/monads 0.2.2]


Improvements from 0.1.0 include:

- change from maps to protocols for monad implementations, which has
increased flexibility and speed (this library is once again a little faster
than morph)

- all monad implementations interoperate with algo.generic.functor

- monad transformers automatically lift operations from inner monads, if
they're supported

- a combined reader/writer/state monad (and transformer) was introduced,
and the (faulty) list-t monad transformer was removed

- improvements to call/cc, shift, and reset for the continuation monad

- an applicative functor protocol was introduced, and implementations
provided for several existing types and all monad implementations.

Also, the `mdo` syntax macro was abstracted out and can now accept an
arbitrary user-provided function for doing monadic binds, which should mean
that it can be used with other libraries, though I haven't actually tested
this.

-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
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: Strange update-in Behavior

2014-05-29 Thread Ben Wolfson
it is expected behavior, because update-in calls the supplied function with
the value it finds in the map as the first argument, so your first call
ends up being

(remove [1 2 3] #{2})

Since ([1 2 3] 2) = 3 and is truthy, the result is ().

In your second case you're using (partial remove #{2}), so the result is
'(1 3), which is then turned into a vector by vec.


On Thu, May 29, 2014 at 10:00 AM, Stuart Fehr stuart.f...@gmail.com wrote:

 I am not sure if this is considered a bug or if it is simply expected
 behavior, so I thought I would ask the list for clarification.

 I have this test which passes and shows the strange behavior that I am
 encountering:

 (deftest update-in-and-remove
   ;; The leaf value becomes and empty list instead of [1 3]
   (is (= {:mykey {:myotherkey '()}}
  (update-in {:mykey {:myotherkey [1 2 3]}} [:mykey :myotherkey]
 remove #{2})))
   ;; Forcing a vector results in the behavior that I would expect
   (is (= {:mykey {:myotherkey [1 3]}}
  (update-in {:mykey {:myotherkey [1 2 3]}} [:mykey :myotherkey]
 (comp vec (partial remove #{2}))

 I think this behavior is due to the use of apply in the definition of
 update-in and I think (but haven't tested) adding a partial to the
 non-recursive clause will fix this:

 https://github.com/clojure/clojure/blob/master/src/clj/clojure/core.clj#L5687

 However, I don't want to submit a fix if this is the expected behavior.
 Thoughts?

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




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
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: Count vowels in a string

2014-05-20 Thread Ben Wolfson
The naïve implementation does sometimes underestimate the total, though.


On Tue, May 20, 2014 at 4:13 PM, Mark Engelberg mark.engelb...@gmail.comwrote:

 You're seriously overthinking this if it's any more than a one-liner.

 (defn count-vowels [s] (count (filter #{\a \e \i \o \u \A \E \I \O \U}
 (seq s


 On Tue, May 20, 2014 at 4:03 PM, Brad Kurtz bkurtz@gmail.com wrote:

 I saw a rant online about interviewing developers that mentioned
 candidates not being able to count the number of vowels in a string. So
 naturally, I decided to see if I could do it in Clojure!

 I wanted to see others' opinions on other ways of doing it.

 *https://gist.github.com/bradkurtz/6ce500d0361ccdc08c8e
 https://gist.github.com/bradkurtz/6ce500d0361ccdc08c8e*

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




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
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: Count vowels in a string

2014-05-20 Thread Ben Wolfson
There are three vowels in naïve, not two.


On Tue, May 20, 2014 at 4:19 PM, Mark Engelberg mark.engelb...@gmail.comwrote:

 Why do you say that?



 On Tue, May 20, 2014 at 4:16 PM, Ben Wolfson wolf...@gmail.com wrote:

 The naïve implementation does sometimes underestimate the total, though.


 On Tue, May 20, 2014 at 4:13 PM, Mark Engelberg mark.engelb...@gmail.com
  wrote:

 You're seriously overthinking this if it's any more than a one-liner.

 (defn count-vowels [s] (count (filter #{\a \e \i \o \u \A \E \I \O \U}
 (seq s


 On Tue, May 20, 2014 at 4:03 PM, Brad Kurtz bkurtz@gmail.comwrote:

 I saw a rant online about interviewing developers that mentioned
 candidates not being able to count the number of vowels in a string. So
 naturally, I decided to see if I could do it in Clojure!

 I wanted to see others' opinions on other ways of doing it.

 *https://gist.github.com/bradkurtz/6ce500d0361ccdc08c8e
 https://gist.github.com/bradkurtz/6ce500d0361ccdc08c8e*

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




 --
 Ben Wolfson
 Human kind has used its intelligence to vary the flavour of drinks,
 which may be sweet, aromatic, fermented or spirit-based. ... Family and
 social life also offer numerous other occasions to consume drinks for
 pleasure. [Larousse, Drink entry]

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




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

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

Re: in Clojure I rarely find myself reaching for something like the state monad, as I would in Haskell

2014-05-19 Thread Ben Wolfson
I wouldn't say that I *often* find myself reaching for monads, or the state
monad in particular, but I certainly have found them useful on occasion
(and would have sometimes refrained from using them where I'd naturally
lean to doing so solely to avoid creating an dependency). For instance,
whenever there's a couple of functions that return either a success value
or an error message that have to be threaded together---an error monad to
do the plumbing makes this a lot nicer.

We've got a library at ReadyForZero for walking though json and xml
structures and doing transformations based on the values found there, or a
bit of configuration, using a combined reader-writer-state monad, and a
bunch of code that uses it. The state that's held is actually just a zipper
into the structure, the configuration at this point is only a keyword, and
the writer log holds reports of unexpected values. This could all be done
with other machinery---pass the zipper around directly (or hold it in an
atom), pass the log around directly (or hold it in an atom), use a dynamic
variable + binding for the configuration (since the reader monad amounts to
that anyway). However, I think the monadic code is easier to work with,
partly because nothing does need to be managed or passed around explicitly
(so it's easier to put together lots of little pieces), and partly because
it enables the use of generic tools. Also, traversing the the structures
has a fairly imperative feel---go here, go there, do this
transformation---with occasional variable binding, and the macro for
monadic computations the monad library we're using provides makes
expressing that fairly convenient. (Though I may be biased, since I wrote
it.)

It's true that there doesn't seem to be much need for introducing a monad
library and using the state monad if you *only* had the state monad, since
Clojure has other ways to deal with mutation (incidentally, I don't think
it's true to say that Haskell only has refs, not atoms; there are functions
to modify IORefs, which live outside the STM system, atomically).



On Fri, May 16, 2014 at 5:49 PM, Julian juliangam...@gmail.com wrote:

 A quick shoutout to the Clojure Community - thanks for the way you've all
 contributed to make my life (mentally) richer.

 James Reeves (author of Compojure and many other wonderful libraries) made
 this interesting comment on Hacker News:
  Clojure has libraries that implement monads, but these aren't often
 used for threading state. I can't quite place my finger on why, but in
 Clojure I rarely find myself reaching for something like the state monad,
 as I would in Haskell.

 Clojure tends to view mutability as a concurrency problem, and the tools
 it provides to deal with mutability, such as atoms, refs, agents, channels
 and so forth, are not mechanisms to avoid mutation, as to provide various
 guarantees that restrict it in some fashion.

 It might be that in the cases where I'd use a state monad in Haskell, in
 Clojure I might instead use an atom. They're in no way equivalent, but they
 have some overlapping use-cases.

 https://news.ycombinator.com/item?id=7751424

 My question is - have other Clojure/Haskell programmers had this
 experience? (ie I rarely find myself reaching for something like the
 state monad). I'm interested to hear if so, and why.

 JG

 PS If this post is unhelpful, could be worded better - please let me know.
 I'm asking out of curiosity, not with intent to troll.

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




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

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

Re: in Clojure I rarely find myself reaching for something like the state monad, as I would in Haskell

2014-05-19 Thread Ben Wolfson
On Mon, May 19, 2014 at 7:48 AM, Bob Hutchison hutch-li...@recursive.cawrote:


 Haskell's STM transactions can be thought of as a form of IO action (like
 reading a file is an IO action) that modify refs (there are no atoms in
 Haskell, only refs). A transaction must be started in the IO monad and
 then, like IO, the STM monad is 'carried' in type signatures through all
 intervening computations that could take part in the transaction. The STM
 type/monad 'blocks' the IO type/monad (you can't do other IO actions if you
 might take part in an STM transaction (IO action), this is an effect of,
 and enforced by, Haskell's type system (i.e. it's a compilation not a
 runtime error)). In Clojure the STM isn't part of the IO system, and you
 can start or take part in a transaction anywhere you want to, even nest
 dosyncs within a single transaction, and intermingle transactional code
 with IO (no matter how bad an idea that is).


You can use regular IO in an STM action with unsafeUItoSTM: 
http://hackage.haskell.org/package/base-4.7.0.0/docs/GHC-Conc-Sync.html#v:unsafeIOToSTM.
IMO it's advantageous that you have to explicitly say that you want to do
IO inside a transaction, given that (in general) you probably shouldn't be
doing it.

-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
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: in Clojure I rarely find myself reaching for something like the state monad, as I would in Haskell

2014-05-19 Thread Ben Wolfson
On Mon, May 19, 2014 at 11:28 AM, Bob Hutchison hutch-li...@recursive.cawrote:


 On May 19, 2014, at 1:44 PM, Ben Wolfson wolf...@gmail.com wrote:

 I wouldn't say that I *often* find myself reaching for monads, or the
 state monad in particular, but I certainly have found them useful on
 occasion (and would have sometimes refrained from using them where I'd
 naturally lean to doing so solely to avoid creating an dependency). For
 instance, whenever there's a couple of functions that return either a
 success value or an error message that have to be threaded together---an
 error monad to do the plumbing makes this a lot nicer.


 I badly miss the Maybe and Either monads, but would want the syntactic
 support Haskell provides (which I can't see will ever be available in
 Clojure)


I've been pretty happy with:
https://github.com/bwo/monads/blob/master/src/monads/core.clj#L65



 We've got a library at ReadyForZero for walking though json and xml
 structures and doing transformations based on the values found there, or a
 bit of configuration, using a combined reader-writer-state monad, and a
 bunch of code that uses it. The state that's held is actually just a zipper
 into the structure, the configuration at this point is only a keyword, and
 the writer log holds reports of unexpected values. This could all be done
 with other machinery---pass the zipper around directly (or hold it in an
 atom), pass the log around directly (or hold it in an atom), use a dynamic
 variable + binding for the configuration (since the reader monad amounts to
 that anyway). However, I think the monadic code is easier to work with,
 partly because nothing does need to be managed or passed around explicitly
 (so it's easier to put together lots of little pieces), and partly because
 it enables the use of generic tools. Also, traversing the the structures
 has a fairly imperative feel---go here, go there, do this
 transformation---with occasional variable binding, and the macro for
 monadic computations the monad library we're using provides makes
 expressing that fairly convenient. (Though I may be biased, since I wrote
 it.)

 It's true that there doesn't seem to be much need for introducing a monad
 library and using the state monad if you *only* had the state monad, since
 Clojure has other ways to deal with mutation (incidentally, I don't think
 it's true to say that Haskell only has refs, not atoms; there are functions
 to modify IORefs, which live outside the STM system, atomically).


 Which is why I didn't call them atoms :-) There's also a ref in the ST
 monad (which is a bells-and-whistles state monad that has fallen into a bit
 of disuse since the IO monad appeared)


Well, my point was that IORefs seem to provide in Haskell what atoms
provide in Clojure. The refs in ST don't do the the same work because the
existential type parameter keeps them from being shared across distinct
runST invocations.


-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
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: puzzled by RuntimeException

2014-04-25 Thread Ben Wolfson
On Fri, Apr 25, 2014 at 11:19 AM, Alex Miller a...@puredanger.com wrote:



 On Friday, April 25, 2014 9:48:10 AM UTC-5, Greg D wrote:

 Thanks Alex and Steve,

 I've based a ton of work on keywords where the second character is
 numeric.

 The http://clojure.org/readers page should be the normative reference.


 The work is based on *reliance* on the definitions in the readers page.
 I believe it is unambiguous in demanding a colon as the first character of
 a keyword, and allowing the second character to be numeric.


 Well I'll contend it is at least ambiguous because I read it differently.
 :) I think everyone can agree that keywords begin with a colon. My
 understanding is that symbols and keywords share naming rules as a result
 of Keywords are like symbols. I think the interpretation depends on
 whether you see the : as being part of the name;


Since the very next thing after Keywords are like symbols is except:
They can and must begin with a colon, e.g. :fred. and the rule for symbols
is that they begin with a non-numeric character, it seems pretty
forgivable to assume that the colon is part of the keyword (the fact that
it isn't stored is immaterial; if you know it's a keyword you also know it
starts with a colon) and that it can therefore contain numeric characters
immediately after the colon. Begin should mean begin in both bullet
points, right?

-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
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: citing Clojure and EDN?

2014-04-23 Thread Ben Wolfson
On Wed, Apr 23, 2014 at 9:44 AM, Phillip Lord
phillip.l...@newcastle.ac.ukwrote:


 The idea that you can't cite websites is a conceit that ensures that
 academics continue to spend a 1000s of pounds a paper on puplication
 costs, when you can achieve much the same with a blog, some metadata and
 archive.org.

 Ah, that was good, I feel better now!


The woes of academic publishing have nothing to do with the idea that you
can't cite websites; MLA and Chicago style both have provisions for citing
websites and I'm sure less widespread style guides do as well.

-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
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: Quotient *and* Remainder

2014-04-09 Thread Ben Wolfson
Many languages expose a quotrem or divmod function that returns both at
once, since they can both be calculated at once.


On Wed, Apr 9, 2014 at 10:05 AM, Sam Ritchie sritchi...@gmail.com wrote:

 So you DON'T mean:

 (juxt quot rem)

 ?

   Anthony Ortiz anthonypa...@gmail.com
  April 9, 2014 11:01 AM
 Hello everyone,

 I am able to get the quotient or remainder by doing the following :

 (quot 22 7)
 - 3

 (rem 22 7)
 - 1

 Is there a way to get back both the quotient and the remainder in one
 calculation rather than performing two separate calculations? And I don't
 mean writing a function that does both calculations behind the scenes and
 returning a list of both results.

 Cheers!

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


 --
 Sam Ritchie (@sritchie)
 Paddleguru Co-Founder
 703.863.8561
 www.paddleguru.com
 Twitter http://twitter.com/paddleguru // 
 Facebookhttp://facebook.com/paddleguru

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




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
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.
inline: compose-unknown-contact.jpg

Re: remove first?

2014-04-02 Thread Ben Wolfson
On Wed, Apr 2, 2014 at 1:36 PM, Chris Lappe chris.la...@gmail.com wrote:

 Wouldn't just calling rest on your collection do what you want?


(remove-first #(= % 3) [1 2 3 4 3 5]) should return [1 2 4 3 5].


-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
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: generators...?

2014-03-26 Thread Ben Wolfson
If you really want something that can be called repeatedly and returns
something different each time (rather than just iterating through an
infinite sequence, which seems like it would be the more functional-ish
approach):

user (defn cycle-gen [input]
(let [iter (atom (cycle input))]
  (fn [] (let [v (first @iter)]
   (swap! iter rest)
   v
#'user/cycle-gen
user (def colors (cycle-gen '(red green blue)))
#'user/colors
user (colors)
red
user (colors)
green
user (colors)
blue
user (colors)
red
user (colors)
green
user (colors)
blue



On Wed, Mar 26, 2014 at 12:59 PM, Christopher Howard
cmhowa...@alaska.eduwrote:

 Hi. I'm still fairly new to Clojure. I was wondering: What's the
 easiest way to make a generator (or something that would be as useful).
 In one application, I need something that will return a different color
 each time I call it - following a predefined list of colors, and
 starting over again at the beginning when colors are exhausted.

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




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
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: generators...?

2014-03-26 Thread Ben Wolfson
cycle isn't really the same thing, though, at least if the OP really does
require (for some reason) something that can be called repeatedly and get a
different answer each time.


On Wed, Mar 26, 2014 at 1:05 PM, Gary Trakhman gary.trakh...@gmail.comwrote:

 cycle - http://clojuredocs.org/clojure_core/clojure.core/cycle

 And generally, this class of functionality is called lazy-seqs.


 On Wed, Mar 26, 2014 at 3:59 PM, Christopher Howard 
 cmhowa...@alaska.eduwrote:

 Hi. I'm still fairly new to Clojure. I was wondering: What's the
 easiest way to make a generator (or something that would be as useful).
 In one application, I need something that will return a different color
 each time I call it - following a predefined list of colors, and
 starting over again at the beginning when colors are exhausted.

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




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
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: 'Reduced' and logic functions

2014-02-19 Thread Ben Wolfson
On Wed, Feb 19, 2014 at 10:02 AM, Niels van Klaveren 
niels.vanklave...@gmail.com wrote:

 Currently, *and* and *or *are implemented as macro's, and cannot be used
 in *apply *or as function parameters. Related functions like *every?* and
 *some* are implemented either on the basis of *or* or recursion over lazy
 sequences. These choices were made because they all need to be able to
 short-circuit, which could be hard in previous clojure versions.

 From 1.5 we have the *reduced* function though, which enables
 short-circuiting *reduce *functions. Since I couldn't find much examples
 of *reduced*, I started experimenting a bit to find out it's usages. One
 of the things I found was that it was pretty easy to create reduced based
 functions for the above, so they could be used with *apply *and as
 function parameters. I came up with the following:

 (defn alt-or
   ([] nil)
   ([ args] (reduce (fn [_ s] (if s s (reduced s))) nil args)))

 (defn alt-and
   ([] nil)
   ([ args] (reduce (fn [_ s] (if s (reduced s) s)) nil args)))

 (defn alt-every?
   [pred coll]
   (reduce (fn [_ s] (let [t (boolean (pred s))] (if t t (reduced t true 
 coll))

 (defn alt-some
   [pred coll]
   (reduce (fn [_ s] (let [t (pred s)] (if t (reduced t) t))) nil coll))



The definitions of alt-or and alt-and are swapped:

(alt-or false true) and (alt-or true false) both return false, (but (and)
is true, and both (alt-and) and (alt-or) are false).

(alt-and true false) and (alt-and false true) both return true.



 Another idea was that this way I could also make core.reducers based
 versions. Of course this would mean that sometimes you would evaluate too
 much tests, but since this would happen in parallel, in general the result
 would return faster. *Am I right in presuming that, or am I overlooking
 some very basic argument against them (I'm pretty good at that) ?*


The result wouldn't return faster if the input is an infinite list.

-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
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: weird bug with cljs.core.async + macros

2014-02-18 Thread Ben Wolfson
On Tue, Feb 18, 2014 at 11:18 AM, Thomas Heller th.hel...@gmail.com wrote:

 While I haven't tested the code, I can see one obvious mistake.

 https://github.com/txrev319/bug-report/blob/master/src/app.cljx#L20

 cat is undefined?


That isn't a mistake. `silly` expands into a case, which expects bare
symbols.

-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
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: clojure.core/reduce calls (f) if given a reducible coll and no init value

2014-01-24 Thread Ben Wolfson
On Fri, Jan 24, 2014 at 12:56 PM, Cedric Greevey cgree...@gmail.com wrote:

 An interesting question this raises is if there is any sensible way to
 define (intersection). It would need to behave as an identity element for
 intersection, so would need to behave as a set (so, (set? (intersection))
 = truthy) that contained everything (so, (contains? (intersection) foo) =
 foo no matter what foo is; (partial contains? (intersection)) = identity).
 The problem would be what to do with seq? Ideally an infinite seq that will
 produce any particular value after finite time would be produced, but
 there's no way to sensibly produce any particular value given the wide
 variety of constructor semantics, builders, factory methods, things not
 known to this particular runtime instance but that conceptually exist
 somewhere, etc.; of course, the seq return is a dummy of sorts anyway since
 you couldn't really use it sensibly to it might as well just return
 (range). Printing should likely be overridden to just print
 (intersection) rather than b0rk the REPL with a neverending stream of
 integers (or whatever).


Why should printing be overridden? If I print (range) I don't get (range).

Also, contains? returns true if the first argument contains the second, not
the second; (partial contains? (intersection)) = (constantly true).


 But then it also subtly violates another property of Clojure set objects:
 if (= a b), (not (identical? a b)), and (identical? (a-set a) a), then
 (identical? (a-set b) a) and thus (not (identical? (a-set b) b)). The
 latter is true under the hypothesis for every real set but would be false
 for (intersection).


Is this a real property of Clojure's sets or an artifact of their present
implementation? Is it something that anything impleneting IPersistentSet
has to promise to uphold?

-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
-- 
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: Eastwood lint tools - some Qs

2014-01-13 Thread Ben Wolfson
Actual arglists have a set structure and can be parsed automatically:
https://github.com/bwo/macroparser/blob/master/src/macroparser/bindings.clj

It's true that you couldn't reconstruct something as informative as the
:arglists metadata on defn from the actual declaration, of course.


On Mon, Jan 13, 2014 at 6:57 PM, Colin Fleming
colin.mailingl...@gmail.comwrote:

 This is an interesting discussion, I've been thinking about some of these
 problems as I move towards adding inspections in Cursive. arglist parsing
 is a real problem in Clojure. I'd like to be able to flag invocations of
 functions with bad arities in the editor, but it's very difficult. Even
 defn is complicated, given that its :arglists is:

 :arglists '([name doc-string? attr-map? [params*] prepost-map? body]
 [name doc-string? attr-map? ([params*] prepost-map? body)+
 attr-map?])

 and its actual args declaration is:

 [form env name  fdecl]

 There's really no way to parse either of them automatically well. Does
 Eastwood use the actual fn declaration or :arglists for linting? What would
 it do in the case above? It's impossible to tell if doc-string? is a
 boolean or if it's an optional arg.

 Oh, and I agree that invalid :arglists as documentation is probably a bad
 idea, since it'll inevitably make this sort of tooling more difficult than
 it already is.


 On 14 January 2014 14:03, Sean Corfield s...@corfield.org wrote:

 On Jan 13, 2014, at 3:09 PM, Nicola Mometto brobro...@gmail.com wrote:
  To be honest I don't like the idea of libraries attaching not-valid
  :arglists meta to Vars at all since the doc[1] for `def` says that
 :arglists
  will be a list of vector(s) of argument forms, as were supplied to
  defn and the clojure Compiler uses :arglists for type-hints handling.

 I agree with you in principle - and I'm happy to change java.jdbc to
 avoid the issue.

 Could Eastwood (or j.t.a) flag invalid :arglists? The example ones in
 both java.jdbc and congomongo are clearly invalid according the special
 forms page (but they silently work). Perhaps if Eastwood finds invalid /
 suspicious metadata in :arglists, it could use a different linter warning?

 Sean Corfield -- (904) 302-SEAN
 An Architect's View -- http://corfield.org/

 Perfection is the enemy of the good.
 -- Gustave Flaubert, French realist novelist (1821-1880)




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




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
-- 
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: How to go about 'proving' why dynamically typed languages are better.

2013-12-23 Thread Ben Wolfson
 for
 static typing, but it's hard to be a zealot after you've freely chosen,
 many times, to compromise on formerly rigid principles.)  Dynamical
 languages are above all oriented toward practical programming needs *in
 certain contexts*--in other contexts, static typing is more practical.
 Maybe some of the hard core static type advocates will see the potential
 benefits dynamic typing when they get more experience.  But you can't
 *prove*, mathematically, that dynamical typing is better sometimes.  Its
 advantage comes out in actual *practice* in real-world situations.
 (Real world doesn't mean business.  I'm an academic coding solely for
 research purposes (and fun!).)

 My 2c.

  --
 --
 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 a topic in the
 Google Groups Clojure group.
 To unsubscribe from this topic, visit
 https://groups.google.com/d/topic/clojure/0I7u5yn01qU/unsubscribe.
 To unsubscribe from this group and all its topics, 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.




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
-- 
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: How to go about 'proving' why dynamically typed languages are better.

2013-12-23 Thread Ben Wolfson
On Mon, Dec 23, 2013 at 2:34 PM, Chris Zheng z...@caudate.me wrote:

 However, the more i write lisp code, the more i realise that types has its
 drawbacks. I'm not sure of the answer here but I have my suspicions: Can
 typed clojure be written in typed clojure?


Why in the world couldn't it be? At the most boring level, if there were
some difficulty, one could just project everything into some universal
type, then do case analysis based on what sort of thing you had. (Which is
the nub of Bob Harper's claim that dynamically typed languages are just a
special case of statically typed languages, if I understand it.)

-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
-- 
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: Who is doing something worthwhile in Clojure?

2013-12-19 Thread Ben Wolfson
Why is a programming language---which one would think is in itself neutral,
being a tool that can be put to a variety of uses---more obviously
worthwhile (let alone the ultimate worthwhile thing!) than sellers of
insurance, who, after all, do, if they're honest, insulate people from what
would otherwise be inconvenient-to-catastrophic events (and thereby make
certain risks more feasible)?


On Thu, Dec 19, 2013 at 4:02 PM, Bruno Kim Medeiros Cesar 
brunokim...@gmail.com wrote:

 Being acquired by Monsanto does not invalidate The Climate Corporation's
 work, which I find extremely exciting and valuable. In fact, why would
 their work be worthwhile by your worthiness definition? They are just
 insurance sellers, after all.

 Clojure itself is the ultimate worthwhile project. Even if it fails, by
 some measure of failure, the world is better with a sufficiently-functional
 language, an inspiration for future Lisp users, and a target for future JVM
 languages to aim.

 On Thursday, December 19, 2013 2:49:37 AM UTC-2, Rich Morin wrote:

 I found Doug Selph's talk at Clojure/conj to be quite inspiring, in
 that he is clearly (IMHO) doing something that is of great potential
 value to humanity.  I used to have similar feelings about The Climate
 Corporation, but their recent acquisition by Monsanto troubles me.

 This makes me wonder about the number of Clojure-driven projects that
 meet Tim O'Reilly's notions of doing something worthwhile:

   “Pursue something so important that even if you fail,
the world is better off with you having tried.”

 Full disclojure: I'd love to find a Clojure-related position that meets
 this test.  More generally, however, I'd like to know about any projects
 that do so.  Suggestions, anyone?

 -r

  --
 http://www.cfcl.com/rdm   Rich Morin   r...@cfcl.com
 http://www.cfcl.com/rdm/resumeSan Bruno, CA, USA   +1 650-873-7841

 Software system design, development, and documentation


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




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
-- 
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: contains? and transient set

2013-12-04 Thread Ben Wolfson
This is not a good way to check whether an *arbitrary* element is in a set:

user= (contains? #{nil} nil)
true
user= (#{nil} nil)
nil



On Wed, Dec 4, 2013 at 3:35 AM, László Török ltoro...@gmail.com wrote:

 Hi,

 contains? is for checking whether a data structure contains the respective
 key.

 A more idiomatic way to check whether an element is in the set is

 (#{1 2 3} 1)  ;; = returns 1
 (#{1 2 3} 0)  ;; = returns nil

 works for (transient #{1 2 3}) too.

 Las



 2013/12/4 Burt burkhardt.r...@googlemail.com

 Does contains? and get not work with transient sets?

 Examples:
 (contains? #{1 2 3} 1)
 ; = true
 (contains? (transient #{1 2 3}) 1)
 ; = IllegalArgumentException contains? not supported on type:
 clojure.lang.PersistentHashSet$TransientHashSet
 (get #{1 2 3} 1)
 ; = 1
 (get (transient #{1 2 3}) 1)
 ; = nil

 How can I check whether an element is contained in a transient set?


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




 --
 László Török

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




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
-- 
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: Advice on choosing the right data structure

2013-12-04 Thread Ben Wolfson
it might be worthwhile to implement custom zippers for your trees, without
using clojure.zip. I've done this for navigating into json structures and
it was relatively painless (admittedly I only needed a smallish subset of
the functionality provided by clojure.zip).


On Wed, Dec 4, 2013 at 1:09 PM, dabd dario.reh...@gmail.com wrote:

 I didn't get there because I ran into problems with the zipper API.  When
 you call 'children' on a loc you get a seq of nodes instead of a seq of
 locs which causes me problems in a recursive algorithm operating on locs.

 On Wednesday, December 4, 2013 8:38:17 PM UTC, James Reeves wrote:

 On 4 December 2013 20:27, dabd dario@gmail.com wrote:


 I tried a purely functional approach with zippers but ran into some
 trouble with the zipper API. I also think I will would have performance
 problems too as there is a lot of bookkeeping in a zipper (paths, parents
 associated with a loc).


 You think you'll have performance problems? Have you benchmarked and
 checked? :)

 - James

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




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
-- 
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: Advice on choosing the right data structure

2013-12-04 Thread Ben Wolfson
oh, I meant custom from the bottom up, without using clojure.zip at all (so
your issue with the return value of children wouldn't come up). I realize
this doesn't answer your question about alternatives.


On Wed, Dec 4, 2013 at 1:15 PM, dabd dario.reh...@gmail.com wrote:

 I had to implement a custom tree zipper as none of the existing zippers
 worked for me.
 My question is are there better alternatives when you want the best
 performance in clojure?


 On Wednesday, December 4, 2013 9:12:16 PM UTC, Ben wrote:

 it might be worthwhile to implement custom zippers for your trees,
 without using clojure.zip. I've done this for navigating into json
 structures and it was relatively painless (admittedly I only needed a
 smallish subset of the functionality provided by clojure.zip).


 On Wed, Dec 4, 2013 at 1:09 PM, dabd dario@gmail.com wrote:

 I didn't get there because I ran into problems with the zipper API.
  When you call 'children' on a loc you get a seq of nodes instead of a seq
 of locs which causes me problems in a recursive algorithm operating on locs.

 On Wednesday, December 4, 2013 8:38:17 PM UTC, James Reeves wrote:

 On 4 December 2013 20:27, dabd dario@gmail.com wrote:


 I tried a purely functional approach with zippers but ran into some
 trouble with the zipper API. I also think I will would have performance
 problems too as there is a lot of bookkeeping in a zipper (paths, parents
 associated with a loc).


 You think you'll have performance problems? Have you benchmarked and
 checked? :)

 - James

  --
 --
 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/groups/opt_out.




 --
 Ben Wolfson
 Human kind has used its intelligence to vary the flavour of drinks,
 which may be sweet, aromatic, fermented or spirit-based. ... Family and
 social life also offer numerous other occasions to consume drinks for
 pleasure. [Larousse, Drink entry]

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




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
-- 
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: Any elegant solutions for this problem?

2013-12-01 Thread Ben Wolfson
user= (def v [foo 1 bar 2 3 baz 4])
#'user/v
user= (first (reduce (fn [[res s] e] (if (string? e) [res e] [(conj res [s
e]) s])) [[] nil] v))
[[foo 1] [bar 2] [bar 3] [baz 4]]

On Sun, Dec 1, 2013 at 10:57 AM, Ryan arekand...@gmail.com wrote:

 Hi all,

 I have a vector which contains an unknown number of repetitions of the
 following pattern:

 String, followed by 1 or more integers

 For example:

 String
 Integer
 String
 Integer
 Integer
 String
 Integer
 Integer
 Integer
 String
 Integer

 What I am trying to do is to create a vector of pairs which each pair will
 be the string and the integers followed.

 Real example:

 foo
 1
 bar
 10
 20
 clown
 5

 should convert to:

 [[foo 1] [bar 10] [bar 20] [clown 5]]

 I did try to play around with partition-by, partition and instance? but I
 couldn't get it quite right.

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




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
-- 
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: Do web apps need Clojure?

2013-11-18 Thread Ben Wolfson
 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 a topic in the
 Google Groups Clojure group.
 To unsubscribe from this topic, visit
 https://groups.google.com/d/topic/clojure/ZxUUBlYf1ck/unsubscribe.
 To unsubscribe from this group and all its topics, 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.


 marcus blankenship
 \\\ Partner, Problem Solver, Linear Thinker
 \\\ 541.805.2736 \ @justzeros \ skype:marcuscreo

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




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
-- 
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: How to convert this simple (and inefficient) fibonacci function to # format

2013-11-13 Thread Ben Wolfson
#(fn fib [x] ... ) creates a zero-arity function which, when called, will
return a one-arity function. Just get rid of the #.


On Wed, Nov 13, 2013 at 9:41 AM, Angus anguscom...@gmail.com wrote:

 I know this fibonacci function is not optimal but I want to learn one step
 at a time.  I want to be able to apply this approach to 4clojure which
 disallows a lot of things including defn.

 This is my implementation so far:

 (defn fib [x]
(cond
   (= x 0) 0
   (= x 1) 1
   :else
  (+ (fib (- x 1)) (fib (- x 2)


 So I thought about something like this:

 (#(fn fib [x]
(cond
   (= x 0) 0
   (= x 1) 1
   :else
  (+ (fib (- x 1)) (fib (- x 2)
   8)

 But trying that in a REPL I get error:

 clojure.lang.ArityException: Wrong number of args (1) passed to:
 sandbox28956$eval28971$fn

 So how can I call this as a one line REPL?

 I though using apply with a one element list might work, but no.

 (apply #(fn fib [x](cond (= x 0) 0 (= x 1) 1  :else  (+ (fib (- x 1)) (fib
 (- x 2) '(8))


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




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
-- 
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: assoc / dissoc consistency, maps and vectors

2013-11-02 Thread Ben Wolfson
On Sat, Nov 2, 2013 at 11:51 AM, vrak...@gmail.com wrote:




 (dissoc ['a 'b 'c] 1)

 ;= ['a 'c]


So then (get (dissoc some-vector i) i) would be equivalent to (get
some-vector (inc i))?

-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
-- 
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: problems with state-t monad transformer

2013-10-22 Thread Ben Wolfson
based on what you posted to stack overflow I would guess it's because the
side-effects (the prints) are coming too soon---you have a println as the
first line of check-k-v, so if the expression (mplus (check-k-v ...)
(check-k-v ...)) is evaluated, then, given that mplus is not a macro, both
arguments will be evaluated, and both prints will happen.

Since the state modifications aren't both happening, I assume that the
actual computation returned---the domonad block---is being correctly
treated.


On Tue, Oct 22, 2013 at 4:23 AM, Mark Fisher mark.j.fis...@gmail.comwrote:

 I originally posted this in Stack 
 Overflowhttp://stackoverflow.com/questions/19505334/clojure-algo-monad-strange-m-plus-behaviour-with-parser-m-why-is-second-m-plus,
 but realised I might get more response from the google group. Apologies for
 duplication.

 I'm seeing some issues using a parser monad created from the state monad
 transformer.

 I've written a full test case on the SO page outlining the issue, which is
 that when I use m-plus for the combined monad, it always evaluates the
 first 2 methods, even though it uses the return values from the first (if
 it is valid), and any state changes in the second occur but are discarded
 (however side effects do - like d/b updates etc).

 e.g.

 (def parser-m (state-t maybe-m))
 (def world-destroyer
   (domonad parser-m
[_ (fetch-state)
 result (m-plus
 (check-we-are-chilled)
 (destroy-planet))]
result))
 (world-destroyer {:chill-out true})

 In this implementation, destroy-planet is always evaluated.
 Both of these monadic functions can terminate by using a :when condition
 on the state.

 If I add a dummy method to the m-plus call list at the start (as first or
 as second method in list) that does nothing (using a :when nil predicate to
 stop its evaluation), the results are fine, no planet is destroyed because
 it's never called, and the dummy monadic function takes the hit of stopping
 m-plus spilling into the destroy-planet function.

 Interestingly, any state changes I make in the method erroneously called
 do not get reflected in the final return value (clearly due to immutability
 of the state map), but side effects are happening - and that's my issue.

 I've reverted to using a hand-crafted parser-m as given on Jim Duey's
 monad blog http://www.intensivesystems.net/tutorials/monads_101.html which
 doesn't exhibit this behaviour.

 I'm relatively inexperienced with clojure and monads (I was using this as
 an excuse to learn them both), so I thought i'd try and work out why it's
 happening.

 From looking at the definitions of state-t monad-m, the only thing i can
 see m-plus doing different to Jim's version is:

 state-t monad-m:
 (defn x [s]
   (apply (fn [ xs]
(first (drop-while nil? xs)))
  (map #(% s) flist)))

 jim's:
 (defn y [s]
   (first (drop-while nil?
  (map #(% s) flist

 for some list of functions flist, e.g.
 (def flist
   [(fn [x]
  (println f a :  x)
  (when-let [r (:a x)] r))
(fn [x]
  (println f b: x)
  (when-let [r (:b x)] r))
(fn [x]
  (println f nil :  x)
  nil)])

 (x {:b 2})
 (y {:b 2})

 and running either of these produces same result (2), however they both
 produce the println side effects of *all 3* functions in the list, so now
 i'm even more confused.

 I thought everything in y is lazy, so only the first two methods would be
 used from the array. I can't find anything saying apply is lazy, so thought
 I was getting closer.

 Anyone have any thoughts on this? Am I using m-plus in the right way
 inside a domonad call?

 Cheers,
 Mark

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




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

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

Re: is PG's imperative outside-in advice any good?

2013-10-15 Thread Ben Wolfson
On Tue, Oct 15, 2013 at 10:48 AM, Sean Corfield seancorfi...@gmail.comwrote:

 On Tue, Oct 15, 2013 at 10:19 AM, Jim - FooBar(); jimpil1...@gmail.com
 wrote:
  wasn't cond- designed exactly for that?
 
  (let [x (some-expression)]
  (cond- x
  (p x) f
  ((comlpement p) x) g)))

 That's uglier than the if :)


Also less efficient, since it may require evaluating (p x) twice.

If it were me, I'd use something like this:

(defn either
   Return a function that takes one argument, x, and returns (f x) if (p
x) is truthy and (g x) otherwise.
   [p f g]
   (fn [x] (if (p x) (f x) (g x

-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
-- 
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: Why is this Project Euler solution slow?

2013-10-01 Thread Ben Wolfson
You can actually solve this problem quite directly. I just looked up my
python solution and it's just print 9*16*5*7*11*13*17*19.


On Tue, Oct 1, 2013 at 11:22 AM, David Chambers david.chambers...@gmail.com
 wrote:

 Last night I attempted Project Euler #5http://projecteuler.net/problem=5in 
 Clojure. The problem is as follows:

  # Smallest multiple
 
  2520 is the smallest number that can be divided by each of the numbers
  from 1 to 10 without any remainder.
 
  What is the smallest positive number that is evenly divisible by all of
 the
  numbers from 1 to 20?

 Here's my solution:

 (defn divisible?
   [numer denom]
   (= 0 (mod numer denom)))

 (defn smallest-multiple
   Find the smallest positive number that is evenly divisible by all
   of the numbers from 1 to n.
   [n]
   (let [s (range 1 (inc n))]
 (first (filter (fn [x] (every? (partial divisible? x) s))
(rest (range))

 This gives the expected answer for *n* of 10, but takes a long time to
 solve *n* of 20. I'd like to understand what make this code slow. Am I
 doing something inefficiently? What steps might I take to rework this
 code to have it solve *n* of 20 within a minute?

 ---

 p.s. I'm new to Clojure. Don't hesitate to mention applicable Clojure
 idioms of which I may not be aware.

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




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
-- 
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: Safely flush old value out of an atom

2013-09-19 Thread Ben Wolfson
Is there some reason you can't use a ref for this?


On Thu, Sep 19, 2013 at 9:20 AM, Adam Clements adam.cleme...@gmail.comwrote:

 Hi,

 I have been working on a setup where I batch a number of updates in a
 queue, which I store in an atom with multiple threads potentially adding
 things to it. Periodically I want to flush that queue, leaving an empty
 list in the atom and passing the current batch of values on for further
 processing.

 I can't use swap! for this, because my further processing is side
 effecting and I wouldn't want to dispatch the same information twice, and I
 can't use reset! because that just throws away the old contents of the
 atom, and derefing it in the line before I am likely to lose data if
 another thread adds something at the last minute.

 I could change to an agent with append and flush actions which would get
 queued up and run only once each, and that would work. But it has quite a
 lot of thread overhead which I think is unnecessary.

 What I ended up doing was writing a version of reset! which returns the
 old value instead of the new value (why would I want the new value? I know
 that, I put it in!)

 (defn flush! [atom newval]
(let [val @atom]
   (if (compare-and-set! atom val newval)
  val
  (recur atom newval

 = (def a (atom [1 2 3 4]))
 #'user/a
 = (flush! a [])
 [1 2 3 4]
 = @a
 []

 Is there already a standard library fn I should be using for this? Is this
 a bad idea for some reason I don't fathom?

 Adam

 https://github.com/AdamClements

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




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
-- 
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: Building Trees

2013-09-09 Thread Ben Wolfson
There's an overview of several approaches to the problem here:
http://okmij.org/ftp/Scheme/parent-pointers.txt


On Mon, Sep 9, 2013 at 4:37 PM, Mark Engelberg mark.engelb...@gmail.comwrote:

 Let's assume for the moment that you do in fact absolutely need some sort
 of bidirectional querying of the data.  In other words, from a parent you
 need to get to the child, and from the child you need to get to the
 parent.  There's no way to accomplish this with immutable data structures
 without introducing some level of indirection.

 Option 1:
 Code it the way you'd code a pointer-based version, but use refs as your
 pointers.  Advantage over coding in Java with raw pointers is that you
 can use the STM to change a bunch of pointers in one transaction.

 Option 2:
 Store in your immutable data structure a mapping from unique names to
 nodes.  These names are your pointers.  Nodes refer to other parent and
 children nodes by their names.  For example, store the tree like so:
 {Node1 {:parent nil :children [Node2 Node3]}
  Node2 {:parent Node1 :children []}
  Node3 {:parent Node1 :children []}}
 Looking up a name in that map corresponds to the notion of dereferencing
 your pointer.

 In pointer-based code, you generally pass the pointers as arguments to
 functions.  Similarly, with this approach you'd tend to write your API to
 take and return names.

 The main downside versus a pointer or ref version of the code is that all
 queries to find a parent or child must take as parameters not only the name
 of the node in question, but the whole mapping of names to nodes.  Finding
 a parent, for example, is a two step process.  Lookup the name in the map,
 and then you have the actual structure you need to find the name of the
 parent.  You can encapsulate that, of course, in an api, for example:
 (get-parent name-to-node-map name) - returns name of parent.

 The advantage of this representation is that you have one immutable entity
 representing the whole tree, and it is therefore trivial to save different
 versions and states of the tree in its entirety.  This is the way I usually
 do it.

 Option 3:
 Rather than thinking of it as a tree, think of it as a directed graph.
 There is one type of link from parent to child, and another type of link
 from child to parent.  This way of thinking makes it easy to leverage
 existing graph technologies that can be easily accessed from Clojure, for
 example, http://titanium.clojurewerkz.org/.

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




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
-- 
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: [ANN] riddley: code-walking without caveats

2013-09-04 Thread Ben Wolfson
Postwalk expansion would break macros that inspect their argument forms for
e.g. writing special-purpose queries, if they *also* adopt the symbols
and and or for conjunction or disjunction. Korma's where, for
instance, does this; one can write

(select my-table (where (and (...) (...

And the where detects the and.

Arguably this is wrongheaded behavior from the get-go (it can be somewhat
confusing and makes it necessary to use something like clojure.core/and
within where if you want normal clojure-land and semantics), but it's a
style of non-anaphoric macro that relies on receiving an unexpanded form.


On Wed, Sep 4, 2013 at 9:27 AM, Zach Tellman ztell...@gmail.com wrote:

 So complete recursive expansion is postwalk macroexpansion?  It seems
 like that could break anaphoric macros, and likely others.  A macro has the
 option of calling macroexpand-all on its own contents if it wants only
 special forms, but it shouldn't be forced to take only special forms.

 Also, here's a sketch of how you could do symbol macros using Riddley:
 https://gist.github.com/ztellman/6439318.  Please let me know if I'm
 missing something w.r.t. how symbol macros are done in tools.macros.

 Zach


 On Wed, Sep 4, 2013 at 2:16 AM, Konrad Hinsen 
 googlegro...@khinsen.fastmail.net wrote:

 **
 On Wed, Sep 4, 2013, at 09:25 AM, Zach Tellman wrote:

 I'm not sure what you mean by complete recursive expansion.  Could
 you expand
 on that?

 Completely ;-)

 By complete recursive expansion I mean that you get a form that is fully
 reduced to
 the core language, i.e. it contains no more macro applications at any
 level.

 If you leave macro expansion to the compiler, it does it when it arrives
 at the
 macro during evaluation. Then it does a plain non-recursive macroexpand
 and goes on
 evaluating. Any macro thus has access to the unexpanded contents of its
 form, but
 not to what it eventually expands to. For many applications that's just
 fine, which
 is why this approach has been the default in the Lisp world for a long
 time.

 As for replicating the behavior of the compiler, I'd assert that
 unless env is
 precisely what it would be without ahead of time macroexpansion, the
 compiler's
 behavior isn't being replicated.

 I agree. tools.macro predates env, which is why it is not supported.
 Since I have
 never need env support and nobody ever asked for it (before now), it's
 not there.
 I don't see any reason why it couldn't be supported.

 Konrad.


 --
 --
 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 a topic in the
 Google Groups Clojure group.
 To unsubscribe from this topic, visit
 https://groups.google.com/d/topic/clojure/a68aThpvP4o/unsubscribe.
 To unsubscribe from this group and all its topics, 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.




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
-- 
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: A macro for writing defn-like macros?

2013-09-03 Thread Ben Wolfson
I've got something that helps with this stuff:
https://github.com/bwo/macroparser/blob/master/src/macroparser/functions.clj




On Tue, Sep 3, 2013 at 9:01 AM, Mark markaddle...@gmail.com wrote:

 I find the vast majority of the time I'm tempted to write a macro (yeah,
 yeah, I know the first rule of macro club), is to defn-like things.
 Writing a defn-like macro to handle all the stuff defn does is pretty tough
 so I end up writing a barebones thing that doesn't support doc-string,
 doesn't support multiple arities, and doesn't support metadata.  I'm
 wondering, has anyone written a defdefnmacro macro?

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




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
-- 
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: A macro for writing defn-like macros?

2013-09-03 Thread Ben Wolfson
used, for example, here:
https://github.com/bwo/monads/blob/master/src/monads/util.clj#L28-L43 and
here:
https://github.com/ReadyForZero/babbage/blob/1.1/src/babbage/graph.clj#L28-L79


On Tue, Sep 3, 2013 at 9:23 AM, Ben Wolfson wolf...@gmail.com wrote:

 I've got something that helps with this stuff:
 https://github.com/bwo/macroparser/blob/master/src/macroparser/functions.clj




 On Tue, Sep 3, 2013 at 9:01 AM, Mark markaddle...@gmail.com wrote:

 I find the vast majority of the time I'm tempted to write a macro (yeah,
 yeah, I know the first rule of macro club), is to defn-like things.
 Writing a defn-like macro to handle all the stuff defn does is pretty tough
 so I end up writing a barebones thing that doesn't support doc-string,
 doesn't support multiple arities, and doesn't support metadata.  I'm
 wondering, has anyone written a defdefnmacro macro?

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




 --
 Ben Wolfson
 Human kind has used its intelligence to vary the flavour of drinks, which
 may be sweet, aromatic, fermented or spirit-based. ... Family and social
 life also offer numerous other occasions to consume drinks for pleasure.
 [Larousse, Drink entry]




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
-- 
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: [ANN] riddley: code-walking without caveats

2013-09-03 Thread Ben Wolfson
On Tue, Sep 3, 2013 at 12:41 PM, Konrad Hinsen 
googlegro...@khinsen.fastmail.net wrote:


 Not quite. It expands only terms that are evaluated, using a built-in
 table of special forms, and it allows local macro definitions (macrolet).
 But most importantly, it tracks local bindings


Local binding tracking is at best inconsistent. mexpand-all produces the
same incorrect result that Proteus's previous code-walker did:

user= (require '[clojure.tools.macro :as m])
nil
user= (defmacro aif [test then else]
  #_=(let [it (first (filter #(not (contains? env %))
  #_=(cons 'it (map #(symbol (str
it- %)) (iterate inc 1)]
  #_=  `(let [~it ~test] (if ~it ~then ~else
#'user/aif
user= (m/mexpand-all '(aif (get {:x {:y 3}} :x) (aif (get it :y) [it it-1]
it) nil))
(let* [it (get {:x {:y 3}} :x)] (if it (let* [it (get it :y)] (if it [it
it-1] it)) nil))

The inner let* should be binding it-1.

-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
-- 
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: eval/macros with functions with metadata

2013-08-28 Thread Ben Wolfson
On Wed, Aug 28, 2013 at 2:46 AM, Gary Fredericks
fredericksg...@gmail.comwrote:

 what's the use case for evaling a function object?


This is just a minimal example that illustrates the difficulty, in the
actual code where I came across it, a new function with relatively complex
internals is created at runtime.

-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
-- 
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: eval/macros with functions with metadata

2013-08-28 Thread Ben Wolfson
On Wed, Aug 28, 2013 at 9:27 AM, Jamie Brandon ja...@scattered-thoughts.net
 wrote:


 If you aren't worried about leaking memory, a possible workaround is
 to intern the fn in some namespace and then put the symbol in the
 macro output.


Hrm, I hope it doesn't come to that---as long as I'm creating the functions
with their metadata, I can make things work, because I can add extra
information to the with-meta call or do extra things when making the call.
What I'd like, though, is for it to be possible to copy the metadata over
to a new function by client code, just using the regular (with-meta (fn
[blah] blah) (meta old-fn)) mechanism. But then the sneaky symbol, or
whatever extra thing, in the metadata, that's used in the form to be
eval-ed is pointing to the original function, not the one passed in. Maybe
just providing a utility for fixing up the metadata is the right move,
though it's kidn of dissatisfying.

-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
-- 
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: core.async - handling nils

2013-08-27 Thread Ben Wolfson
On Tue, Aug 27, 2013 at 7:51 AM, Mike Anderson mike.r.anderson...@gmail.com
 wrote:

 On 27 August 2013 20:45, Timothy Baldridge tbaldri...@gmail.com wrote:

 The reason for not allowing nils isn't a complex one, and basically boils
 down to the following:

 a) to avoid race conditions, we need a single value to signal the
 channel is closed. As mentioned, nil is the obvious choice for this as it
 matches lazy seqs and fits well with the rest of clojure:


 Agreed that you want a single sentinel value.

 It doesn't match lazy-seqs at all though: lazy seqs can contain nils just
 fine. There's a big difference between (next some-lazy-seq) [which could be
 nil, indicating an empty sequence] and the actual values in the seq [which
 could also be nil but don't indicate the end of the seq].


And the when-first macro correctly handles this! It's not just `(when-let
[~x (first ~xs)] ~@body). when-first nicely hides away what would otherwise
be much more ugly.



-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

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


eval/macros with functions with metadata

2013-08-27 Thread Ben Wolfson
or, the dreaded no matching ctor found exception.

Is there a way to write the function

(defn eval-at-one [f] (eval `(~f 1)))

such that it works when invoked like this:

(eval-at-one (fn [x] x))
 ;; -- 1

and like this

(eval-at-one (with-meta (fn [x] x) {}))
 ;; - IllegalArgumentException No matching ctor found for class
clojure.lang.AFunction$1  clojure.lang.Reflector.invokeConstructor
(Reflector.java:163)

?

I thought that the object returned by with-meta might be hanging onto the
original, metadata-less object, which could then be retrieved and used
without difficulty, but this appears not to be the case.

-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
-- 
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: ANN: clj-tuple, efficient small collections

2013-08-24 Thread Ben Wolfson
Are the element names .e0, .e1 etc. considered part of the public interface
of tuple objects?


On Sat, Aug 24, 2013 at 7:38 PM, Zach Tellman ztell...@gmail.com wrote:

 I just pulled some code I wrote while trying to optimize 'memoize' into
 its own library: https://github.com/ztellman/clj-tuple.  It only has the
 one function, so I assume no one will need too much explanation.  However,
 there may still be room for performance improvements, so if anyone wants to
 take a stab, pull requests are welcome.

 Zach

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




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
-- 
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: What's your preference, partial or closures?

2013-08-19 Thread Ben Wolfson
Counterpoint! He's not crazy:
https://github.com/bwo/monads/blob/master/src/monads/util.clj#L8-43


On Sun, Aug 18, 2013 at 9:20 PM, Sean Corfield seancorfi...@gmail.comwrote:

 You're crazy :)

 On Sun, Aug 18, 2013 at 9:04 PM, Chris Allen callen.2...@gmail.com
 wrote:
  Am I crazy or does this scream macro?
 
  On Saturday, August 17, 2013 6:02:03 PM UTC-7, Sean Corfield wrote:
 
  On Sat, Aug 17, 2013 at 5:43 PM, yair yair...@gmail.com wrote:
   What do you mean by currying in this context?  Is there a way to do
 this
   in
   clojure apart from using partial?
 
  (defn some-func
([a b c] (process a b c))
([a b]   (fn [c] (some-func a b c)))
([a] (fn ([b] (fn [c] (some-func a b c)))
 ([b c] (some-func a b c)
 
  (some-func 1 2 3)
  ((some-func 1 2) 3)
  (((some-func 1) 2) 3)
  ((some-func 1) 2 3)
  --
  Sean A Corfield -- (904) 302-SEAN
  An Architect's View -- http://corfield.org/
  World Singles, LLC. -- http://worldsingles.com/
 
  Perfection is the enemy of the good.
  -- Gustave Flaubert, French realist novelist (1821-1880)
 
  --
  --
  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.



 --
 Sean A Corfield -- (904) 302-SEAN
 An Architect's View -- http://corfield.org/
 World Singles, LLC. -- http://worldsingles.com/

 Perfection is the enemy of the good.
 -- Gustave Flaubert, French realist novelist (1821-1880)

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




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
-- 
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: core.async - handling nils

2013-08-17 Thread Ben Wolfson
A sentinel value also prevents channels from being able to send/receive 
arbitrary values, without further wrapping.

Sent from my iPhone

On Aug 17, 2013, at 5:48 PM, Mikera mike.r.anderson...@gmail.com wrote:

 My overall sense is that the convenience of using if-let directly in a few 
 use cases doesn't justify making channels fall short of being able to send 
 arbitrary values (nil specifically, and clearly boolean false can cause some 
 problems too). 
 
 I think it would be a much better design to have a sentinel value and a 
 couple of specialised functions or macros that can detect  / interact with it 
 appropriately. With a sentinel value the key part of your if-recv code could 
 just be something like:
 
 `(let [~name (! ~port)]
   (if (end-of-stream? ~name)
 ~else
 ~then
 
 I can see that wrappers for nil values could also work, but that seems to be 
 a more complex solution (and also potentially with more overhead) than a 
 sentinel value
 
 
 On Saturday, 17 August 2013 07:50:06 UTC+8, Brandon Bloom wrote:
 I ran into the other half of this problem: If you expect nils to signify 
 closed channels, then you can't leverage the logically false nature of nil 
 without excluding explicit boolean false values. Given the pleasant syntax 
 of if-let / ! pairs, I reworked my early experiments to use if-recv which 
 is defined as follows:
 
 (defmacro if-recv
   Reads from port, binding to name. Evaluates the then block if the
   read was successful. Evaluates the else block if the port was closed.
   ([[name port :as binding] then]
`(if-recv ~binding ~then nil))
   ([[name port] then else]
`(let [~name (! ~port)]
   (if (nil? ~name)
 ~else
 ~then
 
 I've considered some alternative core.async designs, such as an additional 
 done sentinel value, or a pair of quote/unquote operators (see reduced), 
 but nothing seems as simple as just avoiding booleans and nils, as annoying 
 as that is. I'd be curious to here what Rich  team considered and how 
 they're thinking about it. However, my expectation is that the nil approach 
 won't change, since it's pretty much good enough.
 
 On Thursday, August 15, 2013 10:44:48 PM UTC-4, Mikera wrote:
 
 Hi all,
 
 I'm experimenting with core.async. Most of it is exceptionally good, but 
 bit I'm finding it *very* inconvenient that nil can't be sent over 
 channels. In particular, you can't pipe arbitrary Clojure sequences through 
 channels (since sequences can contain nils). 
 
 I see this as a pretty big design flaw given the ubiquity of sequences in 
 Clojure code - it appears to imply that you can't easily compose channels 
 with generic sequence-handling code without some pretty ugly special-case 
 handling.
 
 Am I missing something? Is this a real problem for others too? 
 
 If it is a design flaw, can it be fixed before the API gets locked down?
 
 -- 
 -- 
 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.


Re: core.async - handling nils

2013-08-16 Thread Ben Wolfson
On Fri, Aug 16, 2013 at 4:50 PM, Brandon Bloom brandon.d.bl...@gmail.comwrote:

 I ran into the other half of this problem: If you expect nils to signify
 closed channels, then you can't leverage the logically false nature of nil
 without excluding explicit boolean false values. Given the pleasant syntax
 of if-let / ! pairs, I reworked my early experiments to use if-recv
 which is defined as follows:

 (defmacro if-recv
   Reads from port, binding to name. Evaluates the then block if the
   read was successful. Evaluates the else block if the port was closed.
   ([[name port :as binding] then]
`(if-recv ~binding ~then nil))
   ([[name port] then else]
`(let [~name (! ~port)]
   (if (nil? ~name)
 ~else
 ~then


 I've considered some alternative core.async designs, such as an additional
 done sentinel value, or a pair of quote/unquote operators (see
 reduced), but nothing seems as simple as just avoiding booleans and nils,
 as annoying as that is. I'd be curious to here what Rich  team
 considered and how they're thinking about it. However, my expectation is
 that the nil approach won't change, since it's pretty much good enough.


One possibility is to retain nil as closed and have every other value
come wrapped in a Just or Some-like constructor, which an if-recv macro
would unwrap transparently, something like:

(defmacro if-recv [[name port] then else]
   `(let [~name (! ~port)]
  (if (nil? ~name)
  ~else
(let [~name (unwrap ~name)]
  ~then

That would enable sending of nils, since on the far side they'd be wrapped.

-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
-- 
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: core.async - handling nils

2013-08-16 Thread Ben Wolfson
On Fri, Aug 16, 2013 at 5:07 PM, Brandon Bloom brandon.d.bl...@gmail.comwrote:

  have every other value come wrapped in a Just or Some-like constructor

 That's what I meant by a pair of quote/unquote operators


 ah, gotcha

-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
-- 
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: vec to map with consolidated vals

2013-08-16 Thread Ben Wolfson
I don't know if this is a *better* way, but I like it:

user= (require '[clojure.algo.generic.functor :as f])
nil
user= (def v [[:a 1] [:b 2] [:a 3] [:c 4] [:b 1]])
#'user/v
user= (defn consolidate [m]
  #_=   (f/fmap (partial apply +) (reduce (fn [acc [k v]] (update-in acc
[k] conj v)) {} m)))
#'user/consolidate
user= (consolidate v)
{:c 4, :b 3, :a 4}



On Fri, Aug 16, 2013 at 9:57 PM, David Chelimsky dchelim...@gmail.comwrote:

 I've got a vector of 2-element vectors e.g. [[:a 1] [:b 2]] where the
 first val of any vec might appear in another vec e.g. [[:a 1] [:b 2] [:a
 3]]. I need a fn that will consolidate this into a hash-map with the vals
 consolidated e.g.

 (to-consolidated-map [[:a 1] [:b 2] [:a 3]])
 ; {:a 4 :b 2}

 I've got two candidate implementations and I'm curious which you like
 better and why, or if I'm missing a better way:

 (defn to-consolidated-map [parts]
   (reduce (fn [h [k v]]
 (if (contains? h k)
   (assoc h k (+ (k h) v))
   (assoc h k v)))
   {} parts))

 (defn to-consolidated-map [parts]
 (- parts
(group-by first)
(map (fn [[k v]] [k (- v (map last) (reduce +))]

 TIA,
 David

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




-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

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


with-redefs vs. constant folding

2013-08-14 Thread Ben Wolfson
Is this a bug?

user (with-redefs [list +] (list 1 2)) ;; expected: 3
3 ;; huzzah

user (with-redefs [+ list] (+ 1 2)) ;; expected: (1 2)
3 ;; blast!



-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
-- 
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: [GSoC] CinC mid-term evaluation status

2013-07-31 Thread Ben Wolfson
This is very cool!


On Wed, Jul 31, 2013 at 9:41 AM, Nicola Mometto brobro...@gmail.com wrote:


 For the last month or so I've been working on completing Aaron Cohen's
 CinC.

 As planned, this first period has been spent working extensively on the
 analyzer improving it to the point where it's competitive with the
 analysis done in Compiler.java while keeping it clojurescript-like and
 extensible via small composable passes over the AST [1].

 There's some doc about the passes that are implemented and about the AST
 nodes produced at in the doc directory of the repository [2].

 Notably, the jvm analyzer is able to propagate the tag of expressions
 to infer the tag of more complex expressions avoiding the necessity
 of explicit tagging in order to avoid run-time reflection in some cases.

 There are two main namespaces: `cinc.analyzer` and
 `cinc.analyzer.jvm`; the first one should not be used directly but
 should rather be extended to platform-specific forms and passes as done
 by `cinc.analyzer.jvm`.

 Work on the jvm emitter will start soon.

 Thanks,
 Nicola.

 [1]
 https://github.com/Bronsa/CinC/tree/analyzer-WIP/src/cinc/analyzer/passes
 [2] https://github.com/Bronsa/CinC/tree/analyzer-WIP/doc

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





-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
-- 
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: clojure keyword spec

2013-07-31 Thread Ben Wolfson
what's really strange about this is that the double-colon trick does work
for integers:

user ::3
:user/3

You just can't write :user/3 directly.


On Wed, Jul 31, 2013 at 12:59 PM, Brent Millare brent.mill...@gmail.comwrote:

 I've been discovering in my code that namespaced identifiers are a
 wonderful thing. In particular, I am found of namespaced integers as an id.

 Keywords usually serve the role as identifiers, but currently, the spec
 does not allow namespaced integers, which is odd since integers are valid
 as keywords and you can namespace words.

 Again in table form:

 Keyword...
 name-starts-with | has-namespace | is-valid?
 letter, no, yes
 letter, yes, yes
 number, no, yes
 number, yes, no -- This is odd

 Can we change this so we don't get stack traces like so?

 clojure.lang.LispReader$ReaderException: java.lang.RuntimeException:
 Invalid token: :asdf/3a
LispReader.java:220
 clojure.lang.LispReader.read
  core.clj:3407 clojure.core/read
  core.clj:3405 clojure.core/read
  interruptible_eval.clj:52
 clojure.tools.nrepl.middleware.interruptible-eval/evaluate[fn]
   main.clj:257 clojure.main/repl[fn]
   main.clj:257 clojure.main/repl[fn]
   main.clj:277 clojure.main/repl[fn]
   main.clj:277 clojure.main/repl
   RestFn.java:1096
 clojure.lang.RestFn.invoke
  interruptible_eval.clj:56
 clojure.tools.nrepl.middleware.interruptible-eval/evaluate[fn]
   AFn.java:159
 clojure.lang.AFn.applyToHelper
   AFn.java:151 clojure.lang.AFn.applyTo
   core.clj:617 clojure.core/apply
  core.clj:1788
 clojure.core/with-bindings*
RestFn.java:425
 clojure.lang.RestFn.invoke
  interruptible_eval.clj:41
 clojure.tools.nrepl.middleware.interruptible-eval/evaluate
 interruptible_eval.clj:171
 clojure.tools.nrepl.middleware.interruptible-eval/interruptible-eval[fn]
  core.clj:2330 clojure.core/comp[fn]
 interruptible_eval.clj:138
 clojure.tools.nrepl.middleware.interruptible-eval/run-next[fn]
AFn.java:24 clojure.lang.AFn.run
   ThreadPoolExecutor.java:1145
 java.util.concurrent.ThreadPoolExecutor.runWorker
ThreadPoolExecutor.java:615
 java.util.concurrent.ThreadPoolExecutor$Worker.run
Thread.java:724 java.lang.Thread.run
 Caused by: java.lang.RuntimeException: Invalid token: :asdf/3a
  Util.java:219
 clojure.lang.Util.runtimeException
LispReader.java:326
 clojure.lang.LispReader.interpretToken
LispReader.java:211
 clojure.lang.LispReader.read

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






-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
-- 
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: is intellij idea a good ide for clojure development?

2013-07-28 Thread Ben Wolfson
On Sun, Jul 28, 2013 at 3:39 PM, Mark markhanif...@gmail.com wrote:


 So Stallman spins freeing code with freeing slaves.  Obviously the guy
 has some ethical problems of his own.


The claim that freeing something wrongly held isn't theft (in a moral
rather than legal sense), though the wrongful holder would call it theft,
isn't clearly problematic. You may think that Stallman is wrong that code
can be wrongly held, but that's independent of the analogies he draws.

-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
-- 
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: ANN: substantiation, An opinionated nested maps validations library

2013-07-27 Thread Ben Wolfson
Why not just use functions for the validations? string? instead of :String.
Then you get disjunction for free.


On Sat, Jul 27, 2013 at 12:22 PM, ronen nark...@gmail.com wrote:


 Thanks for the feedback!

 Hi,

 Some feedback and questions, as I've made something similar in the past.
 - allow normal fns and classes as a predicates.

 - having one global Var for predicates is an antipattern


 The Var is only for the built in ones and is internal and private,
 external ones are stored in an atom, if you have better alternative id be
 happy to hear.


 - can you compose predicates logically (AND/OR)?


 If you mean something along the lines of {:foo #{(or :String :Integer)}}
 then no, in that case I would suggest defining a new validation and use
 that:

 (validation :int-or-str (when-not-nil #(or (string? %) (number? %)))

 The predicates have implicit AND relation by default.


 - can you validate a contents of the vector?


 You can write a predicate that goes through a vector and asserts its
 values, there no special support for asserting special positions, do you
 have an example?

 As an inspiration, the validator I'm using allows for following rules,
 which IMHO looks a bit cleaner:


 Your using classes which is indeed useful for the basic types, however it
 complects description with implementation which is what I wanted to avoid,

 Nothing for example stops me from taking the description that I use and
 move it to clojurescript (which java classes prevents)

 Hope it makes sense


 (defn- uri?
   Checks if input is valid URI.
   [uri]
   (try
 (URI. uri)
 true
 (catch Exception e false)))

 (def location-rule {:name String :lat Number :long Number})

 (def contributor-rule {(required :id) uri? :gender #{m f}
 :birthDate String
:locales [String] :homeAddress location-rule})

 Best,
 Jozef


 On Saturday, July 27, 2013 5:50:14 AM UTC+2, ronen wrote:

 Substantiation is an opinionated simple nested map validation library:

- Predicates and description kept separate.
- Validation description map follows validated input structure.
- Pure data structures to describe validations.
- Composability of validations is trivial.
- Validation predicates scope is limited (can only access the
checked value).
- High level decisions such as when to activate a group of
validations should happen on upper layer.
- Non strict, only described items checked.

 Github: 
 https://github.com/narkisr/**substantiationhttps://github.com/narkisr/substantiation

 Feedback is welcome
 Ronen

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






-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
-- 
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: Does this abstraction have any existing name?

2013-07-26 Thread Ben Wolfson
If the map is a tree with values at the leaves, then it's a functor and
applying a function to the values is fmap.


On Fri, Jul 26, 2013 at 6:02 PM, Dave Sann daves...@gmail.com wrote:

 if you are thinking of the nested map as a sort of tree - which you seem
 to be doing - then map-leaves or something similar might convey the intent.

 On Saturday, 27 July 2013 04:30:30 UTC+10, Jay Fields wrote:

 I'm not sure I'd call this more readable, but it's another option - using
 clojure.walk

 (defn deep-update-vals
   [m f  args]
   (let [f (fn [[k v]] (if (map? v) [k v] [k (apply f v args)]))]
 (clojure.walk/postwalk (fn [x] (if (map? x) (into {} (map f x)) x))
 m)))


 On Fri, Jul 26, 2013 at 2:06 PM, Jay Fields j...@jayfields.com wrote:

 I defined update-vals in jry: https://github.com/**
 jaycfields/jry/blob/master/**src/clojure/jry.clj#L74-L75https://github.com/jaycfields/jry/blob/master/src/clojure/jry.clj#L74-L75

 It doesn't traverse nested maps, but I haven't ever needed that ability
 either.

 1) I've never seen a name for that.
 2) not in core. I'm sure it's been written 50 times in various helper
 libs.
 3) I'd probably write it like below, but I'm not convinced it's any
 better.

 (defn deep-update-vals
   [m f  args]
   (if (map? m)
 (reduce-kv #(assoc %1 %2 (apply deep-update-vals %3 f args)) {} m)
 (apply f m args)))


 On Fri, Jul 26, 2013 at 1:31 PM, Yoshinori Kohyama yyko...@gmail.comwrote:

 Thank you Gary.
 There's no reason why this need to be a macro.
 It has rewritten as a function.

 And I'd still like to hear any response about the same three questions.



 (require '[clojure.test :refer (with-test is run-tests)])



 (with-test
   (defn mapf [f m  args]


 ((fn g [n]
(if (map? n)


(into {} (map (fn [[k v]] [k (g v)]) n))


(apply f n args)))

  m))

   (is (= (mapf #(* % %) {:a {:b 3 :c 4} :d 5})


  {:a {:b 9 :c 16} :d 25}))


   (is (= (mapf #(+ (* %1 %1) %2) {:a {:b 3 :c 4} :d 5} 1)


  {:a {:b 10 :c 17} :d 26})))



  --
 --
 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=enhttp://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/**groups/opt_outhttps://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.






-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
-- 
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: Does this abstraction have any existing name?

2013-07-26 Thread Ben Wolfson
On Fri, Jul 26, 2013 at 9:27 PM, Yoshinori Kohyama yykohy...@gmail.comwrote:

 Thank you, Ben.

 If I think the map as a tree, then as a functor, what I do is 'fmap' (in
 Haskell or some languages),
 ,as you say.
 Thanks for saying that.

 Does Algo supply things around Functor, Applicative and Monad?
 I'm going to look at Algo.

 Or anybody knows any other libraries or implementations around these
 things in Clojure?


algo.generic has a functor implementation for regular maps which you could
already use, if your maps have uniform depth:

(fmap (partial fmap inc) {:a {:x 1} :b {:y 2}}) --- {:a {:x 2} :b {:y 3}}

if you want to use that fmap (or, I'd think, the fmaps provided by either
morph or fluokitten) with uneven depths, you'd have to wrap them in a
defrecord or deftype, I'd expect.

-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
-- 
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: Does this abstraction have any existing name?

2013-07-26 Thread Ben Wolfson
On Fri, Jul 26, 2013 at 9:31 PM, Ben Wolfson wolf...@gmail.com wrote:

 On Fri, Jul 26, 2013 at 9:27 PM, Yoshinori Kohyama yykohy...@gmail.comwrote:

 Thank you, Ben.

 If I think the map as a tree, then as a functor, what I do is 'fmap' (in
 Haskell or some languages),
 ,as you say.
 Thanks for saying that.

 Does Algo supply things around Functor, Applicative and Monad?
 I'm going to look at Algo.

 Or anybody knows any other libraries or implementations around these
 things in Clojure?


 algo.generic has a functor implementation for regular maps which you could
 already use, if your maps have uniform depth:

 (fmap (partial fmap inc) {:a {:x 1} :b {:y 2}}) --- {:a {:x 2} :b {:y 3}}

 if you want to use that fmap (or, I'd think, the fmaps provided by either
 morph or fluokitten) with uneven depths, you'd have to wrap them in a
 defrecord or deftype, I'd expect.


You could also engage in this underhanded trick:

user= (defmethod f/fmap Object [f v] (f v)) ;;; Identity functor
#MultiFn clojure.lang.MultiFn@5de33e
user= (defmethod f/fmap clojure.lang.IPersistentMap [f v] (into {} (map
(fn [[k v]] [k (f/fmap f v)]) v)))
#MultiFn clojure.lang.MultiFn@5de33e
user= (f/fmap inc {:a {:y 1} :b {:x 2 :z {:c [1 2 3]}}})
{:a {:y 2}, :b {:z {:c [2 3 4]}, :x 3}}

But I wouldn't recommend it.

-- 
-- 
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: querying a clojure data structure

2013-07-24 Thread Ben Wolfson
On Wed, Jul 24, 2013 at 5:16 AM, Phillip Lord
phillip.l...@newcastle.ac.ukwrote:



 So, with this case, say I want the Italian label, in the set which is the
 value of the annotation key, find any list with the first element 'label,
 and
 third element it, and return the second element. Of course, this can be
 done
 in Clojure, but the code gets complex very quickly.

 What I'd really want to be able to do is to use some sort of query; so I'd
 write a data structure like so:

 {:annotation
  #{(label ? it)}}

 and have this match and return

 {:annotation
  #{(label Ingredienti di Pizza it)}}

 which is the bit that matches.


This is considerably more complicated than the query given, but I have lib
which (when I push an update for better set, string, and map handling) will
allow you to do something not entirely unlike that:

macroparser.parsers (run (map (both (keyword
:annotation)

 (set (seq (parseq (symbol 'label)
(expression) (string
it))

  '({:annotation #{(label pizza it)}}))
{:annotation #{(label pizza it)}}
macroparser.parsers

i.e., match a map with one value whose key is :annotation and whose value
is a set containing a seq of 'label, anything, and it.

-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
-- 
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: Can we please deprecate the :use directive ?

2013-07-23 Thread Ben Wolfson
On Tue, Jul 23, 2013 at 1:50 PM, Stefan Kamphausen ska2...@gmail.comwrote:


 It complects require and refer ;-)


How so?

-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
-- 
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: Can we please deprecate the :use directive ?

2013-07-23 Thread Ben Wolfson
On Tue, Jul 23, 2013 at 1:55 PM, Sean Corfield seancorfi...@gmail.comwrote:

 On Tue, Jul 23, 2013 at 1:53 PM, Ben Wolfson wolf...@gmail.com wrote:
  On Tue, Jul 23, 2013 at 1:50 PM, Stefan Kamphausen ska2...@gmail.com
  wrote:
  It complects require and refer ;-)
  How so?

 Because use = require + refer (essentially).


If that's all that's required for one thing to complect two others,
clojure's rife with the stuff. if-let complects if and let. Destructuring
assignment complects assignment and getting values from a data structure
(as the macroexpansion of (let [[a b] x]) demonstrates. split-with
complects take-while and drop-while. let complects lambda abstraction and
function application. Etc. I had assumed that a complects b and c on the
one hand meant more than a can be expressed using b and c and on the
other was a criticism.

-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
-- 
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: State monad issue

2013-07-11 Thread Ben Wolfson
Is it not possible just to put another domonad block in the true branch of
the if? Alternately, it should be possible to do it with an explicit bind
operation.


On Thu, Jul 11, 2013 at 2:11 PM, JvJ kfjwhee...@gmail.com wrote:

 I'm trying to use a domonad block with the state monad, and I'm running
 into trouble chaining together multiple monadic instructions.

 Take this for example:

 ;; This block of code fetches the value from :a in the state,
 ;; and then associates a new value for :b if :a is set.
 (domonad state-m
  [a (fetch-val :a)
  _ (if a
(update-state #(assoc % :b 2))
(m-result nil))
  ]
  nil)

 My question is, what if I wanted to run two update functions, like
 (update-state #(assoc % :b 2)) and (update-state #(assoc % :c 3)),
 but within the if statement?

 (p.s.  I realize that assoc is variadic, and could easily deal with this,
 however I'm using
 it as a simple example of a more general case)

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






-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
-- 
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: [ANN] Proteus: local mutable variables for the masses

2013-07-11 Thread Ben Wolfson
Note:

proteus (defmacro aif [test then else]
   (let [it (first (filter #(not (contains? env %))
   (cons 'it (map #(symbol (str it- %))
(iterate inc 1)]
 `(let [~it ~test] (if ~it ~then ~else
#'proteus/aif
proteus (aif (get {:x {:y 3}} :x)
  (aif (get it :y)
   [it it-1]
   it)
  nil)
[{:y 3} 3]
proteus (let-mutable [x 1]
  (aif (get {:x {:y 3}} :x)
   (aif (get it :y)
(set! x [it it-1])
(set! x it))
   (set! x nil))
  x)
CompilerException java.lang.RuntimeException: Unable to resolve symbol:
it-1 in this context, compiling:(NO_SOURCE_PATH:1:1)
proteus




On Thu, Jul 11, 2013 at 6:16 PM, Zach Tellman ztell...@gmail.com wrote:

 There was some discussion a few days ago about how the lack of local
 mutable variables were harming performance, or possibly elegance, I'm not
 sure.  Regardless, I fixed it: https://github.com/ztellman/proteus

 Enjoy!

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






-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
-- 
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: [ANN] Proteus: local mutable variables for the masses

2013-07-11 Thread Ben Wolfson
On Thu, Jul 11, 2013 at 6:48 PM, Zach Tellman ztell...@gmail.com wrote:

 Yeah, for safety's sake I need to macroexpand everything, which wipes out
 the env for internal macros.  There might be a gentler way to do this, but
 it's not obvious to me.  If anyone has suggestions, I'd be interested in
 hearing them.


You can track the environment through expansion:

https://github.com/bwo/conditions/blob/master/test/conditions/free_test.clj#L19

The core.async internals do something similar (or did at the time of
release, that code has been rewritten, apparently).

You're also missing some binding forms:

proteus (clojure.pprint/pprint (macroexpand-1 '(let-mutable [x 1] (try (/
1 0) (catch Exception x (set! x 2) x)
(clojure.core/let
 [x (new proteus.Containers$L 1)]
 (do
  (try
   (. clojure.lang.Numbers (divide 1 0))
   (catch Exception (.x x) (do (.set x 2) nil) (.x x)


proteus (clojure.pprint/pprint (macroexpand-1 '(let-mutable [x 1] (letfn
[(x [] 4)] (set! x 4) x
(clojure.core/let
 [x (new proteus.Containers$L 1)]
 (do (letfn* [x (fn* x ([] 4))] (do (.set x 4) nil) (.x x





 Zach


 On Thursday, July 11, 2013 6:35:21 PM UTC-7, Ben wrote:

 Note:

 proteus (defmacro aif [test then else]
(let [it (first (filter #(not (contains? env %))
   ** (cons 'it (map #(symbol (str it-
 %)) (iterate inc 1)]
  `(let [~it ~test] (if ~it ~then ~else
 #'proteus/aif
 proteus (aif (get {:x {:y 3}} :x)
   (aif (get it :y)
[it it-1]
it)
   nil)
 [{:y 3} 3]
 proteus (let-mutable [x 1]
   (aif (get {:x {:y 3}} :x)
(aif (get it :y)
   **  (set! x [it it-1])
   **  (set! x it))
(set! x nil))
   x)
 CompilerException java.lang.RuntimeException: Unable to resolve symbol:
 it-1 in this context, compiling:(NO_SOURCE_PATH:1:1)
 proteus




 On Thu, Jul 11, 2013 at 6:16 PM, Zach Tellman ztel...@gmail.com wrote:

 There was some discussion a few days ago about how the lack of local
 mutable variables were harming performance, or possibly elegance, I'm not
 sure.  Regardless, I fixed it: 
 https://github.com/**ztellman/proteushttps://github.com/ztellman/proteus

 Enjoy!

 --
 --
 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=enhttp://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/**groups/opt_outhttps://groups.google.com/groups/opt_out
 .






 --
 Ben Wolfson
 Human kind has used its intelligence to vary the flavour of drinks,
 which may be sweet, aromatic, fermented or spirit-based. ... Family and
 social life also offer numerous other occasions to consume drinks for
 pleasure. [Larousse, Drink entry]

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






-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

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

Re: [ANN] Proteus: local mutable variables for the masses

2013-07-11 Thread Ben Wolfson
Sure, I was considering that anyway. I'm not sure, though, whether it
should be in its own library all by its lonesome or in one with at least a
fairly generic name, since I've got some other macro-related utilities
(specifically https://github.com/bwo/macroparser) that could all be
usefully (I think) grouped together.


On Thu, Jul 11, 2013 at 7:02 PM, Zach Tellman ztell...@gmail.com wrote:

 It looks like the macroexpansion code in conditions.free is fairly
 generic.  What would you say to putting it into its own library?


 On Thu, Jul 11, 2013 at 6:54 PM, Ben Wolfson wolf...@gmail.com wrote:

 On Thu, Jul 11, 2013 at 6:48 PM, Zach Tellman ztell...@gmail.com wrote:

 Yeah, for safety's sake I need to macroexpand everything, which wipes
 out the env for internal macros.  There might be a gentler way to do this,
 but it's not obvious to me.  If anyone has suggestions, I'd be interested
 in hearing them.


 You can track the environment through expansion:


 https://github.com/bwo/conditions/blob/master/test/conditions/free_test.clj#L19

 The core.async internals do something similar (or did at the time of
 release, that code has been rewritten, apparently).

 You're also missing some binding forms:

 proteus (clojure.pprint/pprint (macroexpand-1 '(let-mutable [x 1] (try
 (/ 1 0) (catch Exception x (set! x 2) x)
 (clojure.core/let
  [x (new proteus.Containers$L 1)]
  (do
   (try
(. clojure.lang.Numbers (divide 1 0))
(catch Exception (.x x) (do (.set x 2) nil) (.x x)


 proteus (clojure.pprint/pprint (macroexpand-1 '(let-mutable [x 1] (letfn
 [(x [] 4)] (set! x 4) x
 (clojure.core/let
  [x (new proteus.Containers$L 1)]
  (do (letfn* [x (fn* x ([] 4))] (do (.set x 4) nil) (.x x





 Zach


 On Thursday, July 11, 2013 6:35:21 PM UTC-7, Ben wrote:

 Note:

 proteus (defmacro aif [test then else]
(let [it (first (filter #(not (contains? env %))
   ** (cons 'it (map #(symbol (str
 it- %)) (iterate inc 1)]
  `(let [~it ~test] (if ~it ~then ~else
 #'proteus/aif
 proteus (aif (get {:x {:y 3}} :x)
   (aif (get it :y)
[it it-1]
it)
   nil)
 [{:y 3} 3]
 proteus (let-mutable [x 1]
   (aif (get {:x {:y 3}} :x)
(aif (get it :y)
   **  (set! x [it it-1])
   **  (set! x it))
(set! x nil))
   x)
 CompilerException java.lang.RuntimeException: Unable to resolve symbol:
 it-1 in this context, compiling:(NO_SOURCE_PATH:1:1)
 proteus




 On Thu, Jul 11, 2013 at 6:16 PM, Zach Tellman ztel...@gmail.comwrote:

 There was some discussion a few days ago about how the lack of local
 mutable variables were harming performance, or possibly elegance, I'm not
 sure.  Regardless, I fixed it: 
 https://github.com/**ztellman/proteushttps://github.com/ztellman/proteus

 Enjoy!

 --
 --
 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=enhttp://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/**groups/opt_outhttps://groups.google.com/groups/opt_out
 .






 --
 Ben Wolfson
 Human kind has used its intelligence to vary the flavour of drinks,
 which may be sweet, aromatic, fermented or spirit-based. ... Family and
 social life also offer numerous other occasions to consume drinks for
 pleasure. [Larousse, Drink entry]

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






 --
 Ben Wolfson
 Human kind has used its intelligence to vary the flavour of drinks,
 which may be sweet, aromatic, fermented or spirit-based. ... Family and
 social life also offer numerous other occasions to consume

Re: Clojure: Elegance vs. Performance?

2013-07-09 Thread Ben Wolfson
 by the REPL. Probably this would be a very intensive 
 process - I don't know. But maybe it's worth the trouble after all to save a 
 ton of programmer-hours by increasing readability.


 Thoughts?

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






-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
-- 
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: Clojure: Elegance vs. Performance?

2013-07-09 Thread Ben Wolfson
On Tue, Jul 9, 2013 at 10:28 AM, Mikera mike.r.anderson...@gmail.comwrote:


 A reasonably simple optimisation would be to automatically identify
 self-recursion in tail position and convert it directly to recur. I think
 that's possibly the kind of optimisation pass that the OP was suggesting.


One thing that would be neat, if feasible, would be to make it possible to
do tail call elimination in situations where you can't currently use
recur because there's already a target established---if you have
something like

(defn foo [...]
(loop [...]
  (if some-condition
 (recur ...)
 (foo ...

where you can't use recur for the call to foo, even though it's in tail
position, because the recur target is the loop expression.

-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
-- 
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: Clojure: Elegance vs. Performance?

2013-07-09 Thread Ben Wolfson
On Tue, Jul 9, 2013 at 10:46 AM, Gary Trakhman gary.trakh...@gmail.comwrote:

 The TCO macro already exists: https://github.com/cjfrisz/clojure-tco


That is super cool.

I feel compelled to observe that using a continuation monad run by a
trampoline also allows for tail call elimination:

user= (require '[monads.cont :as c] '[monads.core :refer [= return]])
nil
user= (declare od?)
#'user/od?
user= (defn evn? [x] (if (zero? x) (return true) (od? (dec x
#'user/evn?
user= (defn od? [x] (if (zero? x) (return false) (= (return nil) (fn [_]
(evn? (dec x))
#'user/od?
user= (c/run-cont (evn? 500))
true

But the result is about 2x slower than what the clojure-tco macro produces
(around 600ms vs around 300ms, for me).

-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

-- 
-- 
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: group-by replacement when an item has many groups?

2013-07-08 Thread Ben Wolfson
You could do something like this, which is just a generalization of
group-by to the multiple value case (except that group-by actually uses
transients):

user (defn groups-by [f coll]
(reduce (fn [acc x]
(let [ks (f x)]
  (reduce (fn [acc' k] (update-in acc' [k] #(conj (or %
[]) x))) acc ks)))
{} coll))
#'user/groups-by
user (groups-by #(range 1 (inc %)) [1 2 3])
{3 [3], 2 [2 3], 1 [1 2 3]}

(This isn't the return value you say you want, but it seems to be the right
return value, unless I've misunderstood the problem: 1, 2, and 3 all
include 1, but only 3 includes 3.)

You can define regular group-by in terms of this function as (defn group-by
[f coll] (groups-by (comp vector f) coll)).



On Mon, Jul 8, 2013 at 12:25 PM, Colin Yates colin.ya...@gmail.com wrote:

 Hi,

 I have a sequence of items and want to group them into categories, the
 value of which is a function of the item.  This sounds exactly what
 group-by is after.

 The kicker is that the function could return multiple values.  Imagine
 each item was a date range and I wanted to group them by the number of days
 in that date range.

 For example, (group-by #(range 1 (inc %)) [1 2 3] = {(1) [1] (1 2) [2] (1
 2 3) [3]}.  I want {1 [1] 2 [1 2] 3 [1 2 3]}.

 Any ideas?

 Thanks!

 Col

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






-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

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




ANN: conditions 0.1.0, a simple resumable exceptions library

2013-07-07 Thread Ben Wolfson
Hello all,

I'm releasing a small library for using resumable exceptions, aka
conditions, in Clojure. Resumable exceptions allow the decision about what
kind of response to take to an exception to be made in a separate place
(higher up the call stack) from where the actual response itself is taken
(generally right at the place where the exception was raised). To use in a
leiningen project:

[bwo/conditions 0.1.0]

Code:

https://github.com/bwo/conditions/

The test suite contains a translation of this example illustrating
conditions in CL http://c2.com/cgi/wiki?CommonLispConditionSystem:

(defn reciprocal-of [v]
  (c/rtry (if (== v 0) (slingshot/throw+ {:type :zerodivisionerror}) (/ 1 v))
  (c/resume-with [:type :return-zero] _ 0)
  (c/resume-with [:type :return-value] {v :value} v)
  (c/resume-with [:type :recalc-with] {v :value} (reciprocal-of v

(defn determine-infinity []
  (c/rtry (let [result (reciprocal-of 0)]
(println Value: result)
result)
(c/resume-with [:type :continue] _ -1)))

(defn restarter [n]
  (c/handle (determine-infinity)
(c/catch [:type :zerodivisionerror] _ (c/resume {:type
:recalc-with :value n}

(defn aborter []
  (c/handle (determine-infinity)
(c/catch [:type :zerodivisionerror] _ (c/abort 0


Evaluating (restarter 5) prints 1/5 and evaluates to 1/5; evaluating
(aborter) doesn't print anything (abort jumps to the handler) and
evaluates to 0.

The README and docstrings in core.clj are fairly extensive; comments on any
aspect are welcome.

-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure.
[Larousse, Drink entry]

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




  1   2   3   >