Re: if-let/when-let

2016-07-26 Thread Ertuğrul Çetin
Here is the if-let*: (defmacro if-let* ([bindings then] `(if-let* ~bindings ~then nil)) ([bindings then else] (if (seq bindings) `(if-let [~(first bindings) ~(second bindings)] (if-let* ~(drop 2 bindings) ~then ~else) ~(if-not (second bindings) else)) then))) And when-let*: (defmacro when-let

if-let and friends with multiple bindings

2015-11-09 Thread Karl Mikkelsen
If you have ever wished if-let and friends would allow multiple bindings wish no more. Check out... https://github.com/LockedOn/if-let -Karl -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email

Re: Where should 'if-let-all' macro go?

2015-06-10 Thread Mike Rodriguez
I'll chime in with my opinion on this topic. I think the existing if-let and similar forms that have a limitation of only allowing a single binding is a confusing restriction to place on the familiar binding vector construct. I've always been a little uneasy about repurposing bindi

Re: Where should 'if-let-all' macro go?

2015-06-09 Thread Isaac Zeng
this if-let-all do not support destructure, I writed a improved https://gist.github.com/gfZeng/8e8e18f148d5742b064c On Tuesday, June 9, 2015 at 8:00:53 PM UTC+8, crocket wrote: > > It evaluates true-case only if every local binding evaluates to true values. > false-case has no access

Re: Where should 'if-let-all' macro go?

2015-06-09 Thread Sean Corfield
nd the actual behavior of this sort of code (if it was allowed): (if-let [a (some-a-fn) b (some-b-fn) c (some-c-fn)] (some-t-fn) (some-f-fn)) Should it short-circuit as soon as one of `a`, `b`, or `c` is falsey? Should it evaluate all thr

Re: Where should 'if-let-all' macro go?

2015-06-09 Thread Leon Grapenthin
At least based on my uses, I agree that this would likely bring the most use of the now unused binding space in cores if-let. I can't think of any useful alternatives. Syntactically though, one could worry that the additional bindings would be read as regular let bindings and worry abou

Re: Where should 'if-let-all' macro go?

2015-06-09 Thread Fluid Dynamics
There's a variant of this in one of my projects as well. If this is in "several" utility libraries *and* half the world keeps Greenspunning versions of it in their own projects, then it might be something that belongs in core ... -- You received this message because you are subscribed to the G

Re: Where should 'if-let-all' macro go?

2015-06-09 Thread Andy Fingerhut
valuates true-case only if every local binding evaluates to true values. > false-case has no access to local bindings. > > (defmacro if-let-all > "if-let-all evaluates every local binding sequentially and evaluates > true-case only if every local binding is a truthy value. &g

Re: Where should 'if-let-all' macro go?

2015-06-09 Thread Jozef Wagner
Dunaj has support for multiple bindings in if-let since version 0.5. http://www.dunaj.org/dunaj.flow.api.html#if_let Related design page that discusses possible approaches is at https://github.com/dunaj-project/dunaj/wiki/Conditionals Jozef On Tuesday, June 9, 2015 at 4:00:35 PM UTC+2, Lars

Re: Where should 'if-let-all' macro go?

2015-06-09 Thread Lars Andersen
I actually wish this was how the if-let macro in core worked. Once in a blue moon I end up writing nested if-let statements or an if-let with a nested let. Both of these cases look so ridiculous I often re-write the the code just avoid it. On Tuesday, June 9, 2015 at 2:00:53 PM UTC+2

Where should 'if-let-all' macro go?

2015-06-09 Thread crocket
It evaluates true-case only if every local binding evaluates to true values. false-case has no access to local bindings. (defmacro if-let-all "if-let-all evaluates every local binding sequentially and evaluates true-case only if every local binding is a truthy value. true-case has acce

Re: I created a new macro "if-let-all"

2015-06-09 Thread crocket
Where does if-let-all serve people best? Can anyone help me find the right clojure project to contribute to? On Friday, June 5, 2015 at 2:44:22 PM UTC+9, crocket wrote: > > The macro below is called if-let-all. > > (defmacro if-let-all > "if-let-all evaluates every local

Re: I created a new macro "if-let-all"

2015-06-06 Thread crocket
Yes, if-and-let is similar to if-let-all. On Friday, June 5, 2015 at 10:47:24 PM UTC+9, Fluid Dynamics wrote: > > On Friday, June 5, 2015 at 1:53:07 AM UTC-4, crocket wrote: >> >> Ouch, I didn't write. Gary Fredericks wrote it. I simply modified his >> if-let-all

Re: I created a new macro "if-let-all"

2015-06-05 Thread Fluid Dynamics
On Friday, June 5, 2015 at 1:53:07 AM UTC-4, crocket wrote: > > Ouch, I didn't write. Gary Fredericks wrote it. I simply modified his > if-let-all macro a little bit. > > On Friday, June 5, 2015 at 2:44:22 PM UTC+9, crocket wrote: >> >> The macro below is called if

Re: I created a new macro "if-let-all"

2015-06-04 Thread crocket
Ouch, I didn't write. Gary Fredericks wrote it. I simply modified his if-let-all macro a little bit. On Friday, June 5, 2015 at 2:44:22 PM UTC+9, crocket wrote: > > The macro below is called if-let-all. > > (defmacro if-let-all > "if-let-all evaluates every local

I created a new macro "if-let-all"

2015-06-04 Thread crocket
The macro below is called if-let-all. (defmacro if-let-all "if-let-all evaluates every local binding sequentially and evaluates true-case only if every local binding is a truthy value. true-case has access to all local bindings, but false-case doesn't have access to loca

Re: Wouldn't it be nice if if-let allowed more bindings?

2014-11-27 Thread Fluid Dynamics
On Wednesday, November 26, 2014 10:06:41 PM UTC-5, Michael Blume wrote: > > Instead of the deshadowing logic, why not > > (defn if-and-let* > [bindings then-clause else-fn-name] > (if (empty? bindings) > then-clause > `(if-let ~(vec (take 2 bindings)) >

Re: Wouldn't it be nice if if-let allowed more bindings?

2014-11-26 Thread Sam Ritchie
s) then-clause `(if-let ~(vec (take 2 bindings)) ~(if-and-let* (drop 2 bindings) then-clause else-fn-name) (~else-fn-name (defmacro if-and-let [bindings then-clause else-clause] (let [efname (gensym)] `(let [~efname (fn [] ~else-clause)] ~(if-and-let* bi

Re: Wouldn't it be nice if if-let allowed more bindings?

2014-11-26 Thread Michael Blume
Instead of the deshadowing logic, why not (defn if-and-let* [bindings then-clause else-fn-name] (if (empty? bindings) then-clause `(if-let ~(vec (take 2 bindings)) ~(if-and-let* (drop 2 bindings) then-clause else-fn-name) (~else-fn-name (defmacro if-and-let

Wouldn't it be nice if if-let allowed more bindings?

2014-11-26 Thread Fluid Dynamics
Wouldn't it be nice if if-let allowed more bindings? Try this, which I hereby dedicate into the public domain so that anyone may use it freely in their code without restrictions: (defn if-and-let* [bindings then-clause else-clause deshadower] (if (empty? bindings) then-clause

Re: assert inside an if-let

2014-11-19 Thread Niels van Klaveren
ing form doesn't compile and I see no reason why it shouldn't: > > (if-let [a "a"] a (assert a)) > > IMHO it is a bug. > > If anyone is of a different opinion please share. > > Thanks, > > -- > László Török > > -- You received this messa

Re: assert inside an if-let

2014-11-19 Thread László Török
, and can't compile. > > > On Wednesday, November 19, 2014 3:34:13 PM UTC+1, Las wrote: >> >> Hi, >> >> the following form doesn't compile and I see no reason why it shouldn't: >> >> (if-let [a "a"] a (assert a)) >

assert inside an if-let

2014-11-19 Thread László Török
Hi, the following form doesn't compile and I see no reason why it shouldn't: (if-let [a "a"] a (assert a)) IMHO it is a bug. If anyone is of a different opinion please share. Thanks, -- László Török -- You received this message because you are subscribed to the Go

Re: the semantic of if-let macro

2013-01-31 Thread Stuart Halloway
The docs are clear that the test occurs before the bindings: (doc if-let) - clojure.core/if-let ([bindings then] [bindings then else & oldform]) Macro bindings => binding-form test If test is true, evaluates then with binding-form bound to the value of test,

Re: the semantic of if-let macro

2013-01-30 Thread Mimmo Cosenza
On Thursday, January 31, 2013 1:49:40 AM UTC+1, Sean Corfield wrote: > but now that you've posted this, I > can see some potential for confusion when folks first encounter > if-let... Presumably the same confusion could arise for when-let? > yes, this is the confusion that

Re: the semantic of if-let macro

2013-01-30 Thread Mimmo Cosenza
On Wednesday, January 30, 2013 8:51:47 PM UTC+1, Gary Verhaegen wrote: > For your particular use-case, what you want is more along the lines of > > (if-let [errors (:password (fn-returning-errors))] > ...) > yes, precisely! mimmo -- -- You received this message because you

Re: the semantic of if-let macro

2013-01-30 Thread Sean Corfield
Interesting to see this interpretation of if-let... I'd always read it as "if the condition is truthy then let the binding be the condition and evaluate the first expression else just evaluate the second expression". Since the binding could create multiple named values (in general

Re: the semantic of if-let macro

2013-01-30 Thread Mimmo Cosenza
Perhaps I've been a little bit rude with if-let, but I really do not see how (if-let [{erros :email} (function-returning-errors email password)] true false) is not misleading. I now that the tested value is the one returning from the function call and not the value assign

Re: the semantic of if-let macro

2013-01-30 Thread Gary Verhaegen
If-let does the right thing. What would your intuition expect for (if-let [{a :a b :b} {:a 1 :b nil}] true false) For your particular use-case, what you want is more along the lines of (if-let [errors (:password (fn-returning-errors))] ...) On Wednesday, January 30, 2013, Ben Smith

Re: the semantic of if-let macro

2013-01-30 Thread Ben Smith-Mannschott
I find it helpful to view if-let as a minor variation on if, with the only difference being that you choose to bind the results of the test-expression to some name(s). if-let doesn't care about the values bound to the variables named in binding-target (which might be an arbitrarily co

Re: the semantic of if-let macro

2013-01-30 Thread Mimmo Cosenza
that means never use if-let with sequential destructoring, which brings me to say: never use if-let, because I don't' like to remember such thing while coding and then become crazy to catch my error because of a misleading language feature. mimmo On Jan 30, 2013, at 10:32 AM

Re: the semantic of if-let macro

2013-01-30 Thread James Xu
Agree with you that it is very misleading when using map-destructure in if-let, the same applies to sequential-destructure: user=> (if-let [[_ x] [1 nil]] true false) true On 13-1-30 下午5:23, "Mimmo Cosenza" wrote: >Uhm, I do not agree. > >Suppose tha you have a funct

Re: the semantic of if-let macro

2013-01-30 Thread Mimmo Cosenza
ah, compare > (if-let [{errors :email} (function-returning-error email password)] >true >false) with (let [{errors :email) (function-returning-errros email password)] (if errors true false)) I'm not saying that if-let is wrong, I'm saying I would

Re: the semantic of if-let macro

2013-01-30 Thread Mimmo Cosenza
Uhm, I do not agree. Suppose tha you have a function returning a map of errors (a valip validator lib real case) like the following {:email ["Email can't be empty"] :password ["Password can't be empty"]} If I want to select just the email errors I would writ

Re: the semantic of if-let macro

2013-01-30 Thread James Xu
>From the expansion we can see that if-let determine the result based on the second param, in your case: {:key2 "a string"}, not the local binding you assumed(key1), and I think it is reasonable, for example, if we have the following code: (if-let [{key1 key2} {:key2 "a string&q

the semantic of if-let macro

2013-01-30 Thread Mimmo Cosenza
Hi all, I'm a little bit confused about the semantic of if-let macro. Suppose to call it as follows with map destructoring: (if-let [{key1 :key1} {:key2 "a string"}] true false)) It returns true. But, (let [{key1 :key1} {:key2 "a string"}] (if key1

Re: if-let/when-let

2013-01-04 Thread Mark Engelberg
On Fri, Jan 4, 2013 at 2:35 PM, Michał Marczyk wrote: > Note that if-let -- as it currently stands, I mean -- doesn't make the > binding available to the "else" branch (so there's no way of telling > if the init expression turned out to be false or nil). The above w

Re: if-let/when-let

2013-01-04 Thread Mark Engelberg
On Fri, Jan 4, 2013 at 11:59 AM, Marko Topolnik wrote: > I do this regurarly: > > (-> x (fun1 arg1) (#(fun2 arg2 %)) ...) > > It works, but I still don't like it, I find that extra hash and parens > distasteful. > > Thanks for that idea. Don't know why I never thought to do that. -- You receive

Re: if-let/when-let

2013-01-04 Thread Michał Marczyk
ms > weird. I would absolutely want if-let to use (and ..) on my bindings. All bindings in "then" clause, no bindings in "else" clause. Inside the bindings vector -- as in a regular let, that is, each init expression sees the bindings established earlier. Note that if-let -- as i

Re: if-let/when-let

2013-01-04 Thread Anthony Grimes
t it, it seemed that there > was actually very broad consensus about the desirability of multiple > bindings in when-let/if-let and about the behavior. Nearly everyone agreed > it was obvious that as soon as you hit a variable that is bound to nil, you > bail out of the express

Re: if-let/when-let

2013-01-04 Thread Marko Topolnik
os and on redundant indentation due to if-let-if combinations. > This wouldn't be such a limitation if you could use anonymous functions > among the chained functions (since then you could set up a function with > the "hole" anywhere you want), but this doesn

Re: if-let/when-let

2013-01-04 Thread Mark Engelberg
n when-let/if-let and about the behavior. Nearly everyone agreed it was obvious that as soon as you hit a variable that is bound to nil, you bail out of the expression, short-circuiting further evaluations and returning nil (for when-let) or the else clause (for if-let). There were a few quibbles

Re: if-let/when-let

2013-01-04 Thread David Brown
On Fri, Jan 04, 2013 at 08:58:40AM +0100, Tassilo Horn wrote: At least in my experience, it usually matters a lot which form actually evaluated to nil. But it's easy to write a macro `if-let-all' or so, which would expand into (let [x 1 y nil z 3] (if (and x y z) (+ x y

Re: if-let/when-let

2013-01-04 Thread David Brown
On Thu, Jan 03, 2013 at 11:14:30PM -0800, Evan Mezeske wrote: Wouldn't it be more accurately named "if-and-let" if it supported that? E.g. (if (and x y z) ...). I can see regular if-let being useful with more than one form, just using the last value for the conditional.

Re: if-let/when-let

2013-01-04 Thread Edward Tsech
in > Clojure > > or like "let*" in Scheme. > > > > I mean e.g.: > > (if-let* [x 1 y nil z (inc y)] > > (+ x y z) > > 0) ; => 0 > > ;; (inc y) shouldn't be evaluated here. > > > > Which means "and" doe

Re: if-let/when-let

2013-01-04 Thread Dave Ray
wrote: > Sorry guys, I forget to mention that it should behave like "let" in Clojure > or like "let*" in Scheme. > > I mean e.g.: > (if-let* [x 1 y nil z (inc y)] > (+ x y z) > 0) ; => 0 > ;; (inc y) shouldn't be evaluated here. > > Which mean

Re: if-let/when-let

2013-01-04 Thread Edward Tsech
Sorry guys, I forget to mention that it should behave like "let" in Clojure or like "let*" in Scheme. I mean e.g.: (if-let* [x 1 y nil z (inc y)] (+ x y z) 0) ; => 0 ;; (inc y) shouldn't be evaluated here. Which means "and" doesn't work there.

Re: if-let/when-let

2013-01-04 Thread Andy Fingerhut
ly reasonable choice. My main reason for responding is to let you know that if you really want such behavior, macros let you roll your own without much trouble. Andy On Jan 3, 2013, at 10:24 PM, Edward Tsech wrote: > Hey guys, > > if-let and when-let macros support only 2 forms i

Re: if-let/when-let

2013-01-03 Thread Tassilo Horn
Edward Tsech writes: > java.lang.IllegalArgumentExcepdtion: if-let requires exactly 2 forms > in binding vector(NO_SOURCE_FILE:1) > > Why doesn't "if-let" support any even amount of binding forms as "let" > does? > > e.g. > (if-let [x 1 y 2 z 3] &

Re: if-let/when-let

2013-01-03 Thread Evan Mezeske
Wouldn't it be more accurately named "if-and-let" if it supported that? E.g. (if (and x y z) ...). On Thursday, January 3, 2013 10:24:57 PM UTC-8, Edward Tsech wrote: > > Hey guys, > > if-let and when-let macros support only 2 forms in binding v

if-let/when-let

2013-01-03 Thread Edward Tsech
Hey guys, if-let and when-let macros support only 2 forms in binding vector: (if-let [x 1 y 2] ...) java.lang.IllegalArgumentExcepdtion: if-let requires exactly 2 forms in binding vector(NO_SOURCE_FILE:1) Why doesn't "if-let" support any even amount of binding forms as "

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

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]) j

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

2012-05-21 Thread Borkdude
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 >

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

2012-05-21 Thread Aaron Cohen
>> 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

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

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,

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

2012-05-16 Thread dgrnbrg
ural 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, "th

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

2012-05-16 Thread Jay Fields
ings > >> 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! > > > Wh

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

2012-05-16 Thread Dan Cross
ave 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

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 thei

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 wrote: > On Wed, May 16, 2012 at 3:16 PM, Aaron Cohen wrote: > > What should happen on the else branch of the if-let; which bindings

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

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

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

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 th

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 subscrib

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 t

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

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

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

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

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

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

2012-05-15 Thread Walter Tetzner
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-

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 wrote: > I tried using if-let with multiple binding in past as well. > Following least surprise principle, I would like to see suppo

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

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

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 wi

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

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

Re: if-let bug

2011-01-05 Thread David
Nevermind - it was late, and I found the error message cryptic. Sorry for throwing up a red herring. On Jan 5, 5:30 am, Alessio Stalla wrote: > On Wednesday, January 5, 2011 11:06:34 AM UTC+1, David wrote: > > java.lang.String cannot be cast to clojure.lang.IFn > >   [Thrown class java.lang.Cla

Re: if-let bug

2011-01-05 Thread Alessio Stalla
On Wednesday, January 5, 2011 11:06:34 AM UTC+1, David wrote: > > Consider the two definitions: > > (defn if-let-good [str] > (if-let [rest (seq (drop-while (partial = \a) str))] > (first rest) > "empty")) > > (defn if-let-bad [seq] > (if-

Re: if-let bug

2011-01-05 Thread Laurent PETIT
Hello David, what's the question ? 2011/1/5 David > Consider the two definitions: > > (defn if-let-good [str] > (if-let [rest (seq (drop-while (partial = \a) str))] >(first rest) > "empty")) > > (defn if-let-bad [seq] > (if-let [rest (seq (dr

if-let bug

2011-01-05 Thread David
Consider the two definitions: (defn if-let-good [str] (if-let [rest (seq (drop-while (partial = \a) str))] (first rest) "empty")) (defn if-let-bad [seq] (if-let [rest (seq (drop-while (partial = \a) seq))] (first rest) "empty")) The only difference betw

Re: Misleading error message on incorrect if-let use

2010-10-20 Thread David Jagoe
Looks like its already done: https://www.assembla.com/spaces/clojure/tickets/103-gc-issue-99--incorrect-error-with-if-let On 20 October 2010 22:20, David Jagoe wrote: > Hi all, > > I noticed today (clojure 1.2) that using if-let incorrectly thusly: > > (if-let [a 1] >  (printl

Misleading error message on incorrect if-let use

2010-10-20 Thread David Jagoe
Hi all, I noticed today (clojure 1.2) that using if-let incorrectly thusly: (if-let [a 1] (println "1") (println "2") (println "3")) Instead of e.g. (if-let [a 1] (println "1") (do (println "2") (println "3"))) Res

Re: studying core.clj, questions on read-lines, lazy-seq, and if-let

2010-06-07 Thread Joost
On Jun 7, 6:37 am, toddg wrote: > I'm attempting to read and understand core.clj, and I'm walking > through methods as I run into them, trying to understand them, line by > line. I' mostly understand read-lines (w/ the exception of the last > line), but I do not follo

studying core.clj, questions on read-lines, lazy-seq, and if-let

2010-06-07 Thread toddg
I'm attempting to read and understand core.clj, and I'm walking through methods as I run into them, trying to understand them, line by line. I' mostly understand read-lines (w/ the exception of the last line), but I do not follow lazy-seq or if-let. Could someone check my deconst

Re: if-let

2009-02-09 Thread jdz
> (let [basedir (if-let [bdir (:basedir *locs)] bdir ".")] >     ...) I'd personally write that as: (let [basedir (or (:basedir *locs*) ".")] ...) There is also when-let, which can be used to iterate over sequences: (loop [items some-sequence] (when-l

Re: if-let

2009-02-08 Thread Adrian Cuthbertson
, > > Am 08.02.2009 um 15:47 schrieb Adrian Cuthbertson: > >> Here's one, I'm setting basedir to either :basedir in a map in *locs >> (a thread-local var) or to "." if :basedir was not found in the map... >> >> (let [basedir (if-let [bdir (:basedir *loc

Re: if-let

2009-02-08 Thread Meikel Brandmeyer
Hi, Am 08.02.2009 um 15:47 schrieb Adrian Cuthbertson: Here's one, I'm setting basedir to either :basedir in a map in *locs (a thread-local var) or to "." if :basedir was not found in the map... (let [basedir (if-let [bdir (:basedir *locs)] bdir ".")] ...)

Re: if-let

2009-02-08 Thread Adrian Cuthbertson
Here's one, I'm setting basedir to either :basedir in a map in *locs (a thread-local var) or to "." if :basedir was not found in the map... (let [basedir (if-let [bdir (:basedir *locs)] bdir ".")] ...) i.e bdir assumes the value of the test and if that is

Re: if-let

2009-02-08 Thread Meikel Brandmeyer
Hi, Am 08.02.2009 um 15:25 schrieb Mark Volkmann: Can someone show me an example of a good use of if-let? One use: (defn some-function [& args] (if-let [fst (first args)] (do-something-with fst) (do-something-else))) Sincerely Meikel smime.p7s Description: S/

if-let

2009-02-08 Thread Mark Volkmann
Can someone show me an example of a good use of if-let? I find its doc string a little confusing. It says "If test is true, evaluates then with binding-form bound to the value of test, if not, yields else". However, it doesn't have a parameter named "test". I assume