Re: docstrings of if-let and when-let incorrect

2012-05-21 Thread Borkdude
Wow, the discussion continued! 

I agree on what most people have said: AND-combined and none of the 
bindings available in the else.

On Friday, May 18, 2012 7:20:06 AM UTC+2, FrankS wrote:

 Christophe Grand was experimenting with some extensions to if-let and 
 when-let that had implicit ANDs for the let-forms: 


 https://github.com/cgrand/parsley/blob/master/src/net/cgrand/parsley/util.clj 

 It feels intuitive to me to allow multiple if-let-forms like cgrand 
 implements, and I can certainly remember situations where I could have used 
 such a feature. 

 -FrankS. 



 On May 16, 2012, at 11:26 AM, dgrnbrg wrote: 

  I too assumed that if/when-let would support multiple bindings, short- 
  circuiting if one failed, when I started learning Clojure. It seems 
  that short-circuiting multiple bindings isn't surprising. 
  
  On May 16, 10:56 am, Jay Fields j...@jayfields.com wrote: 
  I've also attempted to use if/when-let with multiple bindings in the 
 past. 
  I assumed that it would behave as 'AND' and that no bindings would be 
  available in 'else' 
  
  Cheers, Jay 
  
  
  
  
  
  
  
  On Wed, May 16, 2012 at 10:29 AM, Dan Cross cro...@gmail.com wrote: 
  On Wed, May 16, 2012 at 9:16 AM, Aaron Cohen aa...@assonance.org 
 wrote: 
  On Wed, May 16, 2012 at 9:10 AM, Walter Tetzner  
  robot.ninja.saus...@gmail.com wrote: 
  To make the bindings work like let, where later bindings can see 
  previous 
  bindings, I think the most natural way to do it is to have the 
 bindings 
  behave like the maybe monad. 
  [...] 
  
  Saying something is obvious and then using the word monad a paragraph 
  later 
  is contradictory. ;) 
  
  Hypothetically, this is obvious, unlike most monads.  Zing! 
  
  What should happen on the else branch of the if-let; which bindings 
 are 
  in 
  scope and what would be their values? 
  
  None of the bindings should be in scope. 
  
 - Dan C. 
  
  -- 
  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 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 


On Friday, May 18, 2012 7:20:06 AM UTC+2, FrankS wrote:

 Christophe Grand was experimenting with some extensions to if-let and 
 when-let that had implicit ANDs for the let-forms: 


 https://github.com/cgrand/parsley/blob/master/src/net/cgrand/parsley/util.clj 

 It feels intuitive to me to allow multiple if-let-forms like cgrand 
 implements, and I can certainly remember situations where I could have used 
 such a feature. 

 -FrankS. 



 On May 16, 2012, at 11:26 AM, dgrnbrg wrote: 

  I too assumed that if/when-let would support multiple bindings, short- 
  circuiting if one failed, when I started learning Clojure. It seems 
  that short-circuiting multiple bindings isn't surprising. 
  
  On May 16, 10:56 am, Jay Fields j...@jayfields.com wrote: 
  I've also attempted to use if/when-let with multiple bindings in the 
 past. 
  I assumed that it would behave as 'AND' and that no bindings would be 
  available in 'else' 
  
  Cheers, Jay 
  
  
  
  
  
  
  
  On Wed, May 16, 2012 at 10:29 AM, Dan Cross cro...@gmail.com wrote: 
  On Wed, May 16, 2012 at 9:16 AM, Aaron Cohen aa...@assonance.org 
 wrote: 
  On Wed, May 16, 2012 at 9:10 AM, Walter Tetzner  
  robot.ninja.saus...@gmail.com wrote: 
  To make the bindings work like let, where later bindings can see 
  previous 
  bindings, I think the most natural way to do it is to have the 
 bindings 
  behave like the maybe monad. 
  [...] 
  
  Saying something is obvious and then using the word monad a paragraph 
  later 
  is contradictory. ;) 
  
  Hypothetically, this is obvious, unlike most monads.  Zing! 
  
  What should happen on the else branch of the if-let; which bindings 
 are 
  in 
  scope and what would be their values? 
  
  None of the bindings should be in scope. 
  
 - Dan C. 
  
  -- 
  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 
  

Re: docstrings of if-let and when-let incorrect

2012-05-21 Thread Aaron Cohen
On Wed, May 16, 2012 at 9:53 AM, Walter Tetzner 
robot.ninja.saus...@gmail.com wrote:

 On Wednesday, May 16, 2012 9:16:29 AM UTC-4, Aaron Cohen wrote:

 Saying something is obvious and then using the word monad a paragraph
 later is contradictory. ;)

 What should happen on the else branch of the if-let; which bindings are
 in scope and what would be their values?


 None of the bindings should be available in the else branch, since there
 would be no way to know which will succeed before run-time.


I actually think that having all the bindings available and just nil for
everything past the first failure would be more useful, and also matches
the intuition that it expands out to nested if-lets

(if-let [a 1 b 2 c nil] [a b c])


(if-let [a 1]
   (if-let [b 2]
  (if-let [c nil]
  [a b c]
  [a b c])
  [a b c])
   [a b c])

= [1 2 nil]

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

Re: docstrings of if-let and when-let incorrect

2012-05-21 Thread Borkdude
I guess it wouldn't hurt having them available in the else, even if people 
won't use them often.

On Monday, May 21, 2012 7:11:05 PM UTC+2, Aaron Cohen wrote:

 On Wed, May 16, 2012 at 9:53 AM, Walter Tetzner 
 robot.ninja.saus...@gmail.com wrote:

 On Wednesday, May 16, 2012 9:16:29 AM UTC-4, Aaron Cohen wrote:

 Saying something is obvious and then using the word monad a paragraph 
 later is contradictory. ;)

 What should happen on the else branch of the if-let; which bindings are 
 in scope and what would be their values?


 None of the bindings should be available in the else branch, since there 
 would be no way to know which will succeed before run-time.


 I actually think that having all the bindings available and just nil for 
 everything past the first failure would be more useful, and also matches 
 the intuition that it expands out to nested if-lets

 (if-let [a 1 b 2 c nil] [a b c])


 (if-let [a 1]
(if-let [b 2]
   (if-let [c nil]
   [a b c]
   [a b c])
   [a b c])
[a b c])

 = [1 2 nil] 


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

Re: docstrings of if-let and when-let incorrect

2012-05-21 Thread Jay Fields
There's a few issues there, first of which is that the code doesn't
evaluate to what's shown:
REPL started; server listening on localhost port 21867
user=
(if-let [a 1]
   (if-let [b 2]
  (if-let [c nil]
  [a b c]
  [a b c])
  [a b c])
   [a b c])
java.lang.Exception: Unable to resolve symbol: c in this context
(NO_SOURCE_FILE:3)

The c isn't nil in the else form, it's unbound. The same would be true if
it failed at any of the other levels, if the original if fails, a, b,  c
are all unbound. So, setting them to nil isn't consistent. It might be a
good option, but it's not consistent with the code above. I can't imagine
that you'd want the else statement to have a bunch of possibly nil vars for
any reason other than printing - otherwise you'd end up putting a bunch of
conditional logic in the else to know which vars are nil, in which case
you're better off using nested if-lets anyway. But, maybe the printing
(i.e. logging) scenario is reason enough to bind these variables. I'd
probably lean towards keeping them all unbound, as it's clear that each var
would be bound (if form) or unbound (else form), versus each var being
possibly truthy or nil in the else form.

But, I don't feel strongly either way.

On Mon, May 21, 2012 at 1:32 PM, Borkdude michielbork...@gmail.com wrote:

 I guess it wouldn't hurt having them available in the else, even if people
 won't use them often.

 On Monday, May 21, 2012 7:11:05 PM UTC+2, Aaron Cohen wrote:

 On Wed, May 16, 2012 at 9:53 AM, Walter Tetzner 
 robot.ninja.saus...@gmail.com** wrote:

 On Wednesday, May 16, 2012 9:16:29 AM UTC-4, Aaron Cohen wrote:

 Saying something is obvious and then using the word monad a paragraph
 later is contradictory. ;)

 What should happen on the else branch of the if-let; which bindings are
 in scope and what would be their values?


 None of the bindings should be available in the else branch, since there
 would be no way to know which will succeed before run-time.


 I actually think that having all the bindings available and just nil for
 everything past the first failure would be more useful, and also matches
 the intuition that it expands out to nested if-lets

 (if-let [a 1 b 2 c nil] [a b c])


 (if-let [a 1]
(if-let [b 2]
   (if-let [c nil]
   [a b c]
   [a b c])
   [a b c])
[a b c])

 = [1 2 nil]

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

Re: docstrings of if-let and when-let incorrect

2012-05-21 Thread Aaron Cohen
On Mon, May 21, 2012 at 1:43 PM, Jay Fields j...@jayfields.com wrote:

 There's a few issues there, first of which is that the code doesn't
 evaluate to what's shown:
 REPL started; server listening on localhost port 21867
 user=
 (if-let [a 1]
(if-let [b 2]
   (if-let [c nil]
   [a b c]
   [a b c])
   [a b c])
[a b c])
 java.lang.Exception: Unable to resolve symbol: c in this context
 (NO_SOURCE_FILE:3)

 The c isn't nil in the else form, it's unbound. The same would be true if
 it failed at any of the other levels, if the original if fails, a, b,  c
 are all unbound. So, setting them to nil isn't consistent. It might be a
 good option, but it's not consistent with the code above. I can't imagine
 that you'd want the else statement to have a bunch of possibly nil vars for
 any reason other than printing - otherwise you'd end up putting a bunch of
 conditional logic in the else to know which vars are nil, in which case
 you're better off using nested if-lets anyway. But, maybe the printing
 (i.e. logging) scenario is reason enough to bind these variables. I'd
 probably lean towards keeping them all unbound, as it's clear that each var
 would be bound (if form) or unbound (else form), versus each var being
 possibly truthy or nil in the else form.


Yeah, I was typing theory code. However, none defined in the else doesn't
fully match the nested if-lets behavior either. In the second if-let
stanza, a would be bound in the else case.

In any event, this is all just bike-shedding and illustrating that what
appears obvious isn't necessarily.

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

Re: docstrings of if-let and when-let incorrect

2012-05-17 Thread Frank Siebenlist
Christophe Grand was experimenting with some extensions to if-let and 
when-let that had implicit ANDs for the let-forms:

https://github.com/cgrand/parsley/blob/master/src/net/cgrand/parsley/util.clj

It feels intuitive to me to allow multiple if-let-forms like cgrand implements, 
and I can certainly remember situations where I could have used such a feature.

-FrankS.



On May 16, 2012, at 11:26 AM, dgrnbrg wrote:

 I too assumed that if/when-let would support multiple bindings, short-
 circuiting if one failed, when I started learning Clojure. It seems
 that short-circuiting multiple bindings isn't surprising.
 
 On May 16, 10:56 am, Jay Fields j...@jayfields.com wrote:
 I've also attempted to use if/when-let with multiple bindings in the past.
 I assumed that it would behave as 'AND' and that no bindings would be
 available in 'else'
 
 Cheers, Jay
 
 
 
 
 
 
 
 On Wed, May 16, 2012 at 10:29 AM, Dan Cross cro...@gmail.com wrote:
 On Wed, May 16, 2012 at 9:16 AM, Aaron Cohen aa...@assonance.org wrote:
 On Wed, May 16, 2012 at 9:10 AM, Walter Tetzner 
 robot.ninja.saus...@gmail.com wrote:
 To make the bindings work like let, where later bindings can see
 previous
 bindings, I think the most natural way to do it is to have the bindings
 behave like the maybe monad.
 [...]
 
 Saying something is obvious and then using the word monad a paragraph
 later
 is contradictory. ;)
 
 Hypothetically, this is obvious, unlike most monads.  Zing!
 
 What should happen on the else branch of the if-let; which bindings are
 in
 scope and what would be their values?
 
 None of the bindings should be in scope.
 
- Dan C.
 
 --
 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 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 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


Re: docstrings of if-let and when-let incorrect

2012-05-16 Thread Vinzent


 As the logical AND of all of the multiple forms?  The OR?  Only use the 
 first expression?  Only the last?


It should be 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

Re: docstrings of if-let and when-let incorrect

2012-05-16 Thread Stuart Sierra
How would multiple bindings for if-let or when-let work? Should every 
binding be testedd? Should they be and-ed together? Should it short-circuit 
if the first is false?

I don't think there are obvious answers to those questions.
-S

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

Re: docstrings of if-let and when-let incorrect

2012-05-16 Thread Walter Tetzner


 On Wednesday, May 16, 2012 9:01:49 AM UTC-4, Stuart Sierra wrote:How would 
 multiple bindings for if-let or when-let work? Should every binding be 
 testedd? Should they be and-ed together? Should it short-circuit if the 
 first is false?

 I don't think there are obvious answers to those questions.


Well, considering everyone on here that's answered that question said 
'AND', it seems to be obvious.

To make the bindings work like let, where later bindings can see previous 
bindings, I think the most natural way to do it is to have the bindings 
behave like the maybe monad. The first time you encounter a false value, it 
fails. This way, you are using 'AND', but you don't run the risk of a 
NullPointerException in later bindings if a previous one fails.

-Walter

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

Re: docstrings of if-let and when-let incorrect

2012-05-16 Thread Aaron Cohen
On Wed, May 16, 2012 at 9:10 AM, Walter Tetzner 
robot.ninja.saus...@gmail.com wrote:

 On Wednesday, May 16, 2012 9:01:49 AM UTC-4, Stuart Sierra wrote:How would
 multiple bindings for if-let or when-let work? Should every binding be
 testedd? Should they be and-ed together? Should it short-circuit if the
 first is false?


 I don't think there are obvious answers to those questions.


 Well, considering everyone on here that's answered that question said
 'AND', it seems to be obvious.

 To make the bindings work like let, where later bindings can see previous
 bindings, I think the most natural way to do it is to have the bindings
 behave like the maybe monad. The first time you encounter a false value, it
 fails. This way, you are using 'AND', but you don't run the risk of a
 NullPointerException in later bindings if a previous one fails.


Saying something is obvious and then using the word monad a paragraph later
is contradictory. ;)

What should happen on the else branch of the if-let; which bindings are in
scope and what would be their values?

--Aaron

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

Re: docstrings of if-let and when-let incorrect

2012-05-16 Thread Moritz Ulrich
On Wed, May 16, 2012 at 3:16 PM, Aaron Cohen aa...@assonance.org wrote:
 What should happen on the else branch of the if-let; which bindings are in
 scope and what would be their values?

This is kind of tricky. My opinion tends to all bindings, but then
it's difficult to handle lazy evaluation like in (or
(cheap-computation) (long-computation)).
One solution for this would be evaluating all arguments 'til the first
fails, then nil-ing the rest. The problem with this is, that it throws
away values which could be useful.

-- 
Moritz Ulrich

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


Re: docstrings of if-let and when-let incorrect

2012-05-16 Thread Michael Gardner
On May 16, 2012, at 8:16 AM, Aaron Cohen wrote:

 Saying something is obvious and then using the word monad a paragraph later 
 is contradictory. ;)

If the word monad is scary, just pretend he said it should short-circuit 
instead. ;)

 What should happen on the else branch of the if-let; which bindings are in 
 scope and what would be their values?

That's an interesting question. For consistency with the current behavior of 
single-binding if-let, the binding whose value was false should be left unbound 
(as well as successive bindings, given short-circuiting); but I could see going 
either way for the bindings that succeeded. I don't think it matters as much 
that this behavior would be non-obvious, though, because I'd predict the common 
case in the else-branch of a multi-binding if-let would be to not care about 
any of the bindings. That's just my guess, though.

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


Re: docstrings of if-let and when-let incorrect

2012-05-16 Thread Chris Ford
Personally, I would intuitively assume that none of the bindings from
if-let would be available in the else branch.

On 16 May 2012 14:36, Moritz Ulrich ulrich.mor...@googlemail.com wrote:

 On Wed, May 16, 2012 at 3:16 PM, Aaron Cohen aa...@assonance.org wrote:
  What should happen on the else branch of the if-let; which bindings are
 in
  scope and what would be their values?

 This is kind of tricky. My opinion tends to all bindings, but then
 it's difficult to handle lazy evaluation like in (or
 (cheap-computation) (long-computation)).
 One solution for this would be evaluating all arguments 'til the first
 fails, then nil-ing the rest. The problem with this is, that it throws
 away values which could be useful.

 --
 Moritz Ulrich

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

Re: docstrings of if-let and when-let incorrect

2012-05-16 Thread Walter Tetzner
On Wednesday, May 16, 2012 9:16:29 AM UTC-4, Aaron Cohen wrote:

 Saying something is obvious and then using the word monad a paragraph 
 later is contradictory. ;)

 What should happen on the else branch of the if-let; which bindings are in 
 scope and what would be their values?


None of the bindings should be available in the else branch, since there 
would be no way to know which will succeed before run-time.

-Walter

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

Re: docstrings of if-let and when-let incorrect

2012-05-16 Thread Dan Cross
On Wed, May 16, 2012 at 9:16 AM, Aaron Cohen aa...@assonance.org wrote:
 On Wed, May 16, 2012 at 9:10 AM, Walter Tetzner 
 robot.ninja.saus...@gmail.com wrote:
 To make the bindings work like let, where later bindings can see previous
 bindings, I think the most natural way to do it is to have the bindings
 behave like the maybe monad.
 [...]

 Saying something is obvious and then using the word monad a paragraph later
 is contradictory. ;)

Hypothetically, this is obvious, unlike most monads.  Zing!

 What should happen on the else branch of the if-let; which bindings are in
 scope and what would be their values?

None of the bindings should be in scope.

- Dan C.

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


Re: docstrings of if-let and when-let incorrect

2012-05-16 Thread Jay Fields
I've also attempted to use if/when-let with multiple bindings in the past.
I assumed that it would behave as 'AND' and that no bindings would be
available in 'else'

Cheers, Jay

On Wed, May 16, 2012 at 10:29 AM, Dan Cross cro...@gmail.com wrote:

 On Wed, May 16, 2012 at 9:16 AM, Aaron Cohen aa...@assonance.org wrote:
  On Wed, May 16, 2012 at 9:10 AM, Walter Tetzner 
 robot.ninja.saus...@gmail.com wrote:
  To make the bindings work like let, where later bindings can see
 previous
  bindings, I think the most natural way to do it is to have the bindings
  behave like the maybe monad.
  [...]
 
  Saying something is obvious and then using the word monad a paragraph
 later
  is contradictory. ;)

 Hypothetically, this is obvious, unlike most monads.  Zing!

  What should happen on the else branch of the if-let; which bindings are
 in
  scope and what would be their values?

 None of the bindings should be in scope.

- Dan C.

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

Re: docstrings of if-let and when-let incorrect

2012-05-16 Thread dgrnbrg
I too assumed that if/when-let would support multiple bindings, short-
circuiting if one failed, when I started learning Clojure. It seems
that short-circuiting multiple bindings isn't surprising.

On May 16, 10:56 am, Jay Fields j...@jayfields.com wrote:
 I've also attempted to use if/when-let with multiple bindings in the past.
 I assumed that it would behave as 'AND' and that no bindings would be
 available in 'else'

 Cheers, Jay







 On Wed, May 16, 2012 at 10:29 AM, Dan Cross cro...@gmail.com wrote:
  On Wed, May 16, 2012 at 9:16 AM, Aaron Cohen aa...@assonance.org wrote:
   On Wed, May 16, 2012 at 9:10 AM, Walter Tetzner 
  robot.ninja.saus...@gmail.com wrote:
   To make the bindings work like let, where later bindings can see
  previous
   bindings, I think the most natural way to do it is to have the bindings
   behave like the maybe monad.
   [...]

   Saying something is obvious and then using the word monad a paragraph
  later
   is contradictory. ;)

  Hypothetically, this is obvious, unlike most monads.  Zing!

   What should happen on the else branch of the if-let; which bindings are
  in
   scope and what would be their values?

  None of the bindings should be in scope.

         - Dan C.

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


Re: docstrings of if-let and when-let incorrect

2012-05-15 Thread Stuart Sierra
Reasonable enough. Patch welcome.
-S

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

Re: docstrings of if-let and when-let incorrect

2012-05-15 Thread Vinzent
Or maybe if-let and when-let should support multiple bindings, like the doc 
states.

воскресенье, 13 мая 2012 г., 4:55:40 UTC+6 пользователь Borkdude написал:

 The docstring of if-let is as follows:

 bindings = binding-form test

 If test is true, evaluates then with binding-form bound to the value of 
 test, if not, yields else

 I think it should be mentioned in the docs that if-let and when-let 
 support only *one binding*, not multiple bindings (like for example 
 https://www.refheap.com/paste/2700).
  
 Kind regards,

 Michiel


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

Re: docstrings of if-let and when-let incorrect

2012-05-15 Thread Hubert Iwaniuk

I tried using if-let with multiple binding in past as well.
Following least surprise principle, I would like to see support for 
multiple bindings.


Cheers,
Hubert.

Vinzent mailto:ru.vinz...@gmail.com
May 15, 2012 5:47 PM
Or maybe if-let and when-let should support multiple bindings, like 
the doc states.


воскресенье, 13 мая 2012 г., 4:55:40 UTC+6 пользователь Borkdude 
написал: --

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
Borkdude mailto:michielbork...@gmail.com
May 13, 2012 12:55 AM
The docstring of if-let is as follows:

bindings = binding-form test

If test is true, evaluates then with binding-form bound to the value of
test, if not, yields else

I think it should be mentioned in the docs that if-let and when-let 
support only /one binding/, not multiple bindings (like for 
example https://www.refheap.com/paste/2700).


Kind regards,

Michiel
--
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 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=eninline: compose-unknown-contact.jpginline: postbox-contact.jpg

Re: docstrings of if-let and when-let incorrect

2012-05-15 Thread Evan Gamble
If if-let and when-let don't get support for multiple bindings, you could 
try https://github.com/egamble/let-else .

On Tuesday, May 15, 2012 12:09:08 PM UTC-7, Hubert Iwaniuk wrote:

 I tried using if-let with multiple binding in past as well.
 Following least surprise principle, I would like to see support for 
 multiple bindings.

 Cheers,
 Hubert
  

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

Re: docstrings of if-let and when-let incorrect

2012-05-15 Thread Aaron Cohen
Does the principle of least surprise suggest that multiple bindings be
combined with AND or OR?

--Aaron

On Tue, May 15, 2012 at 3:09 PM, Hubert Iwaniuk neo...@kungfoo.pl wrote:

 I tried using if-let with multiple binding in past as well.
 Following least surprise principle, I would like to see support for
 multiple bindings.

 Cheers,
 Hubert.

   Vinzent ru.vinz...@gmail.com
  May 15, 2012 5:47 PM
 Or maybe if-let and when-let should support multiple bindings, like the
 doc states.

 воскресенье, 13 мая 2012 г., 4:55:40 UTC+6 пользователь Borkdude написал:
 --
 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
   Borkdude michielbork...@gmail.com
  May 13, 2012 12:55 AM
 The docstring of if-let is as follows:

 bindings = binding-form test

 If test is true, evaluates then with binding-form bound to the value of
 test, if not, yields else

 I think it should be mentioned in the docs that if-let and when-let
 support only *one binding*, not multiple bindings (like for example
 https://www.refheap.com/paste/2700).

 Kind regards,

 Michiel
 --
 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 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 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=encompose-unknown-contact.jpgpostbox-contact.jpg

Re: docstrings of if-let and when-let incorrect

2012-05-15 Thread Walter Tetzner
On Tuesday, May 15, 2012 3:26:52 PM UTC-4, Aaron Cohen wrote:

 Does the principle of least surprise suggest that multiple bindings be 
 combined with AND or OR?

  
For `when-let', I would expect it to work like nested when-lets:

(when-let [x (exp-1)
   y (exp-2 x)
   z (exp-3 y)]
  [x y z])

would be the same as

(when-let [x (exp-1)]
  (when-let [y (exp-2 x)]
(when-let [z (exp-3 y)]
  [x y z])))

For the behavior of `if-let' to not be suprising given this definition
of `when-let', I think it would have to behave similarily:

(if-let [x (exp-1)
 y (exp-2 x)
 z (exp-3 y)]
  [x y z]
  'failed)

would be the same as

(if-let [x (exp-1)]
  (if-let [y (exp-2 x)]
(if-let [z (exp-3 y)]
  [x y z]
  'failed)
'failed)
  'failed)

So, AND I guess. But later expressions can refer to earlier ones, just
like in `let'.

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

Re: docstrings of if-let and when-let incorrect

2012-05-15 Thread Dan Cross
On Tue, May 15, 2012 at 3:26 PM, Aaron Cohen aa...@assonance.org wrote:

 Does the principle of least surprise suggest that multiple bindings be
 combined with AND or OR?


My own personal opinion is that it makes sense in combination with 'and',
but others may feel differently.  E.g.,

(when-let [a (allocate-thing) b (read-into-thing a) c
(extract-something-from-thing b)]
  (do-something-with c))

makes intuitive sense to me.  If, at any stage of the execution, any of a,
b or c was nil, the evaluation would stop and the (when-let) form would
return nil.

- Dan C.

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

Re: docstrings of if-let and when-let incorrect

2012-05-15 Thread Walter Tetzner
On Tuesday, May 15, 2012 3:41:58 PM UTC-4, Dan Cross wrote:

 My own personal opinion is that it makes sense in combination with 'and', 
 but others may feel differently.  E.g.,

 (when-let [a (allocate-thing) b (read-into-thing a) c 
 (extract-something-from-thing b)]
   (do-something-with c))

 makes intuitive sense to me.  If, at any stage of the execution, any of a, 
 b or c was nil, the evaluation would stop and the (when-let) form would 
 return nil.


So judging by both your response and my response, it should behave like the 
maybe monad.

-Walter

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

Re: docstrings of if-let and when-let incorrect

2012-05-15 Thread Andy Fingerhut
If if-let/when-let had multiple bindings, how would you propose to define the 
condition of whether to do the then branch?

As the logical AND of all of the multiple forms?  The OR?  Only use the first 
expression?  Only the last?

I don't see that any of those is any more clear or least surprising than any 
of the others.  Permitting only one makes that part of the behavior clear, at 
least.

Andy

On May 15, 2012, at 12:09 PM, Hubert Iwaniuk wrote:

 I tried using if-let with multiple binding in past as well.
 Following least surprise principle, I would like to see support for multiple 
 bindings.
 
 Cheers,
 Hubert.
  Vinzent May 15, 2012 5:47 PM
 Or maybe if-let and when-let should support multiple bindings, like the doc 
 states.

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

Re: docstrings of if-let and when-let incorrect

2012-05-15 Thread Michael Gardner
On May 15, 2012, at 3:15 PM, Andy Fingerhut wrote:

 If if-let/when-let had multiple bindings, how would you propose to define the 
 condition of whether to do the then branch?
 
 As the logical AND of all of the multiple forms?  The OR?  Only use the first 
 expression?  Only the last?
 
 I don't see that any of those is any more clear or least surprising than 
 any of the others.  Permitting only one makes that part of the behavior 
 clear, at least.

AND is the obvious choice, IMO. People will probably still have to look up what 
happens with multiple bindings from time to time, but that doesn't seem worse 
than having to look up whether if-let and when-let even support multiple 
bindings.

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


Re: docstrings of if-let and when-let incorrect

2012-05-15 Thread Dan Cross
On Tue, May 15, 2012 at 3:47 PM, Walter Tetzner
robot.ninja.saus...@gmail.com wrote:
 On Tuesday, May 15, 2012 3:41:58 PM UTC-4, Dan Cross wrote:
 My own personal opinion is that it makes sense in combination with 'and',
 but others may feel differently.  E.g.,

     (when-let [a (allocate-thing) b (read-into-thing a) c
 (extract-something-from-thing b)]
       (do-something-with c))

 makes intuitive sense to me.  If, at any stage of the execution, any of a,
 b or c was nil, the evaluation would stop and the (when-let) form would
 return nil.

 So judging by both your response and my response, it should behave like the
 maybe monad.

Yes, that's a very good characterization.

- Dan C.

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


docstrings of if-let and when-let incorrect

2012-05-14 Thread Borkdude
The docstring of if-let is as follows:

bindings = binding-form test

If test is true, evaluates then with binding-form bound to the value of 
test, if not, yields else

I think it should be mentioned in the docs that if-let and when-let support 
only *one binding*, not multiple bindings (like for 
example https://www.refheap.com/paste/2700).
 
Kind regards,

Michiel

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