Re: [ANN] com.walmartlabs/cond-let 1.0.0

2018-10-05 Thread Howard Lewis Ship
: > > (cond > (odd? a) 1 >:let [a (quot a 2)] >:when-let [x (fn-which-may-return-nil a), > y (fn-which-may-return-nil (* 2 a))] >:when (seq x) >:do (println x) >(odd? (+ x y)) 2 >:else 3) > > The :do performs a side-effec

Re: [ANN] com.walmartlabs/cond-let 1.0.0

2018-10-04 Thread Mark Engelberg
Documentation for latest features in the 2.0.1 branch: https://github.com/Engelberg/better-cond/tree/v2.0.1 An example: (cond (odd? a) 1 :let [a (quot a 2)] :when-let [x (fn-which-may-return-nil a), y (fn-which-may-return-nil (* 2 a))] :when (seq x) :do (println x

Re: [ANN] com.walmartlabs/cond-let 1.0.0

2018-10-04 Thread Alan Thompson
How would the :when and :do forms work? Alan On Wed, Oct 3, 2018 at 7:22 PM Mark Engelberg wrote: > This looks like a case of "convergent evolution". > > Having the ability to do a :let in the middle of a cond feels like one of > those things that *should* be in the cor

Re: [ANN] com.walmartlabs/cond-let 1.0.0

2018-10-04 Thread Howard Lewis Ship
Yes, I wouldn't have bothered if I had known about better-cond, so there you go. I think I first wrote this code at Aviso at least five years ago. On Wed, Oct 3, 2018 at 7:22 PM Mark Engelberg wrote: > This looks like a case of "convergent evolution". > > Having the a

Re: [ANN] com.walmartlabs/cond-let 1.0.0

2018-10-04 Thread Gary Trakhman
a 'if-let' style nil-punning thing to a cond-let implementation but at that point I imagine it more appropriate to take a step back instead :-). I'm not convinced yet that it's worth thinking about it like this in a dynamically typed language, but brought it up because there's a named concept

Re: [ANN] com.walmartlabs/cond-let 1.0.0

2018-10-04 Thread lei Shulang
But a Maybe/Nothing will short-circuit the whole flow where cond-let won't? On Thursday, 4 October 2018 08:38:05 UTC-7, Moe Aboulkheir wrote: > > See https://funcool.github.io/cats/latest/#mlet for something closer to > home, in the monadic vein. > > > On Thu, Oct 4, 20

Re: [ANN] com.walmartlabs/cond-let 1.0.0

2018-10-04 Thread Moe Aboulkheir
//github.com/janestreet/ppx_let#syntactic-forms-and-actual-rewriting > > But it can be made to work for async or options or whatever, too. > > We can put the async helpers in the same bucket: > https://github.com/ztellman/manifold/blob/master/docs/deferred.md#let-flow > > The general ide

Re: [ANN] com.walmartlabs/cond-let 1.0.0

2018-10-04 Thread Gary Trakhman
bucket: https://github.com/ztellman/manifold/blob/master/docs/deferred.md#let-flow The general idea is turning function application into something that looks less nested. On Wed, Oct 3, 2018 at 10:22 PM Mark Engelberg wrote: > This looks like a case of "convergent evolution". > >

Re: [ANN] com.walmartlabs/cond-let 1.0.0

2018-10-03 Thread Mark Engelberg
This looks like a case of "convergent evolution". Having the ability to do a :let in the middle of a cond feels like one of those things that *should* be in the core language, so if it's not in there, a bunch of people are naturally going to arrive at the same solution and make

Re: [ANN] com.walmartlabs/cond-let 1.0.0

2018-10-03 Thread Matching Socks
Is this a refinement of Mark Engelberg's "better-cond", or an alternative approach? I have not used better-cond myself, but it starts here: https://dev.clojure.org/jira/browse/CLJ-200. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to

[ANN] com.walmartlabs/cond-let 1.0.0

2018-10-03 Thread Howard Lewis Ship
A micro library of a single macro, cond-let. cond-let acts like a cond, but adds :let terms that are followed by a binding form (like let). This allows conditional code to introduce new local symbols; the result is clearer, more linear code, that doesn't make a march for the right margin

Re: ANN: Parallel let macro!

2017-11-30 Thread Leif
his is small piece of code that is inspired by haxl, muse( > https://github.com/kachayev/muse), urania( > https://github.com/funcool/urania). Not a library. > > (defn remote-req [result] > (Thread/sleep 1000) > result) > > (defmacro plet [bindings & body] > (let [bents (partiti

Re: ANN: Parallel let macro!

2017-11-29 Thread Ambrose Bonnaire-Sergeant
. > > (defn remote-req [result] > (Thread/sleep 1000) > result) > > (defmacro plet [bindings & body] > (let [bents (partition 2 (destructure bindings)) > smap (into {} (map (fn [[b _]] > [b `(deref ~b)]) >

Re: ANN: Parallel let macro!

2017-11-28 Thread Henrik Eneroth
Very nice! Kudos. -- 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,

ANN: Parallel let macro!

2017-11-28 Thread Eunmin Kim
Hi, folks This is small piece of code that is inspired by haxl, muse(https://github.com/kachayev/muse), urania(https://github.com/funcool/urania). Not a library. (defn remote-req [result] (Thread/sleep 1000) result) (defmacro plet [bindings & body] (let [bents (partition 2 (destruc

Re: Got NullpointerException when using loop/recur/let together

2017-10-25 Thread Matching Socks
Also, have another look at '(ret (- time-now start-time)) It will yield a list containing the symbol 'ret and a nested list containing the symbol '- etc etc etc. I think what you expected was a vector of two numbers. -- You received this message because you are subscribed to the Google

Re: Got NullpointerException when using loop/recur/let together

2017-10-24 Thread Justin Smith
contexts where there isn't a do block implicitly, you can use do to sequence expressions On Tue, Oct 24, 2017 at 5:26 PM yihao yang <yangyihao1...@gmail.com> wrote: > Hi, all > > I want to do sth. like query until timeout. So I write a function below. > (defn wait-ls-ready >

Got NullpointerException when using loop/recur/let together

2017-10-24 Thread yihao yang
Hi, all I want to do sth. like query until timeout. So I write a function below. (defn wait-ls-ready [] (let [pair-fn (fn [] ( (Thread/sleep 1000) (let [ret (try (c/exec :ls

Re: How to try/catch Let bindings?

2017-10-08 Thread Gary Verhaegen
e, you can probably, as an intermediate solution, define a fairly simple macro that would get you almost all you want, something like: (defmacro mlet [bindings & body] (if (seq bindings) (let [[b expr & r] bindings] `(try (let [~b ~expr] (mlet ~r ~@body))

Re: How to try/catch Let bindings?

2017-10-07 Thread Nathan Fisher
rs handle this use case, which I feel should be pretty > common. > > Given you have a series of business process steps, where the flow is too > complex for the arrow macros, and you also like to name the step results > descriptively, so you use let: > > (let [a (do-a ...) >

Re: How to try/catch Let bindings?

2017-10-07 Thread Fabrizio Ferrai
, when it comes to handling Java exceptions in a monadic way, we can look at the Try monad in Scala, that is exactly what we are searching for. We have several libraries that implement monadic sugar in Clojure, and `cats` [1] implements the try monad [2]. Example usage with `mlet` (monadic let, aka

Re: How to try/catch Let bindings?

2017-10-06 Thread 'bertschi' via Clojure
On Monday, October 2, 2017 at 11:04:52 PM UTC+2, Didier wrote: > > > Even in an impure language such as Common Lisp we frown on such LET forms > > True, but as far as I know, in Common Lisp, the condition handler is > always in scope of where the error happened,

Re: How to try/catch Let bindings?

2017-10-02 Thread Didier
> Even in an impure language such as Common Lisp we frown on such LET forms True, but as far as I know, in Common Lisp, the condition handler is always in scope of where the error happened, so I wouldn't face this problem. I also struggle to split this up into functions without making it e

Re: How to try/catch Let bindings?

2017-10-02 Thread hiskennyness
also like to name the step results > descriptively, so you use let: > You are almost saying what I am thinking: this beast of a calculation has to be broken up (into separate functions)! :) > > (let [a (do-a ...) > b (do-b . a . .) > c (do-c . a . b)] > Even in

Re: How to try/catch Let bindings?

2017-10-02 Thread Luke Burton
> On Oct 1, 2017, at 9:21 PM, Didier wrote: > > I can't emphasize enough the utility of the interceptor chain pattern, as > employed heavily in pedestal. > > Interesting... Its almost like a workflow framework, but for simpler in code > workflows. I'm reluctant to have a

Re: How to try/catch Let bindings?

2017-10-02 Thread Duncan McGreggor
30, 2017, at 3:14 PM, Didier <did...@gmail.com> wrote: >> >> Is there another way to execute a set of complex steps which does not >> rely on let and can be try/catched in the manner I describe? >> >> >> I can't emphasize enough the utility of the interceptor c

Re: How to try/catch Let bindings?

2017-10-02 Thread Daniel Compton
t; >> Is there another way to execute a set of complex steps which does not >> rely on let and can be try/catched in the manner I describe? >> >> >> I can't emphasize enough the utility of the interceptor chain pattern, as >> employed heavily in pedestal. >&g

Re: How to try/catch Let bindings?

2017-10-01 Thread Didier
y, 1 October 2017 21:00:31 UTC-7, Luke Burton wrote: > > > On Sep 30, 2017, at 3:14 PM, Didier <did...@gmail.com > > wrote: > > Is there another way to execute a set of complex steps which does not rely > on let and can be try/catched in the manner I describe? >

Re: How to try/catch Let bindings?

2017-10-01 Thread Luke Burton
> On Sep 30, 2017, at 3:14 PM, Didier <didi...@gmail.com> wrote: > > Is there another way to execute a set of complex steps which does not rely on > let and can be try/catched in the manner I describe? I can't emphasize enough the utility of the interceptor chain pattern, as

Re: How to try/catch Let bindings?

2017-10-01 Thread Didier
I've seen this, I was still curious if the reason I was facing the issue was that let is simply the wrong tool for my use case or not. If let is the correct tool, I would propose that clojure.core should had a try/catch where the catch is in scope of the try. I feel the reason

How to try/catch Let bindings?

2017-09-30 Thread Marcus Magnusson
I've used try-let (link below) for this, it's worked great! https://github.com/rufoa/try-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

How to try/catch Let bindings?

2017-09-30 Thread Didier
I'm curious how others handle this use case, which I feel should be pretty common. Given you have a series of business process steps, where the flow is too complex for the arrow macros, and you also like to name the step results descriptively, so you use let: (let [a (do-a ...) b (do-b

Re: Beginner: let with Java object

2017-05-26 Thread Christopher Howard
christopher.how...@qlfiles.net <mailto:christopher.how...@qlfiles.net>> > wrote: > > When I run > > tutorial.core> (let [img (new-image 32 32)] (set-pixel img 10 10 cyan) > (show img)) > > from the REPL, this returns a javax.swing.JFrame object, a

Re: Beginner: let with Java object

2017-05-26 Thread Gary Trakhman
-expression. On Fri, May 26, 2017 at 11:54 AM Christopher Howard < christopher.how...@qlfiles.net> wrote: > When I run > > tutorial.core> (let [img (new-image 32 32)] (set-pixel img 10 10 cyan) > (show img)) > > from the REPL, this returns a javax.swing.JFrame objec

Beginner: let with Java object

2017-05-26 Thread Christopher Howard
When I run tutorial.core> (let [img (new-image 32 32)] (set-pixel img 10 10 cyan) (show img)) from the REPL, this returns a javax.swing.JFrame object, and displays the frame and image as expected. However, if put the same in (defn -main "Generates image." [& args] (let [

RE: Let and For Doesn't Execute - Where Is My Misunderstanding?

2017-05-17 Thread Phillip Lord
They are lazy -- change "for" to "doseq" From: clojure@googlegroups.com [clojure@googlegroups.com] on behalf of Kevin Kleinfelter [kleinfelter.gro...@gmail.com] Sent: 17 May 2017 19:14 To: Clojure Subject: Let and For Doesn't E

Re: Let and For Doesn't Execute - Where Is My Misunderstanding?

2017-05-17 Thread 'Alan Forrester' via Clojure
On 17 May 2017, at 19:14, Kevin Kleinfelter <kleinfelter.gro...@gmail.com> wrote: > I'm stumped by the behavior of the following code fragment. Can someone help > me understand what's happening? > > This code: > (println "Holding:" (:class holdin

Re: Let and For Doesn't Execute - Where Is My Misunderstanding?

2017-05-17 Thread Ralf Schmitt
Kevin Kleinfelter <kleinfelter.gro...@gmail.com> writes: > I'm stumped by the behavior of the following code fragment. Can someone > help me understand what's happening? > > *This code*: > (println "Holding:" (:class holding)) > (let [t (:class holding)] &g

Let and For Doesn't Execute - Where Is My Misunderstanding?

2017-05-17 Thread Kevin Kleinfelter
I'm stumped by the behavior of the following code fragment. Can someone help me understand what's happening? *This code*: (println "Holding:" (:class holding)) (let [t (:class holding)] (for [x t] (println "here" x)) (for [x t] (println "there"

Re: loop macro generates a wrapping let

2017-03-06 Thread juan.facorro
found curious. I'm probably missing something but here it > > goes. > > > > The expression generated by the *loop* macro includes a wrapping *let > > *when there is any de-structuring in the bindings. > > > > (require '[clojure.walk :as walk]) > > (w

Re: loop macro generates a wrapping let

2017-03-06 Thread Kevin Downey
On 03/06/2017 03:28 PM, juan.facorro wrote: > While I was debugging some code I found something related to the *loop > *macro that I found curious. I'm probably missing something but here it > goes. > > The expression generated by the *loop* macro includes a wrapping *let > *wh

loop macro generates a wrapping let

2017-03-06 Thread juan.facorro
While I was debugging some code I found something related to the *loop *macro that I found curious. I'm probably missing something but here it goes. The expression generated by the *loop* macro includes a wrapping *let *when there is any de-structuring in the bindings. (require '[clojure.walk

Re: recursive bindings not available in let form?

2016-12-04 Thread Timothy Baldridge
Let bindings map pretty much directly to Java style local variables: (let [x 42] (let [x 3] (+ x 3)) Becomes something like this when compiled to byte code: x_1 = 42 x_2 = 3 return x_2 +3 So let bindings with the same names are kept separate via modifying the stored name in the byte code

Re: recursive bindings not available in let form?

2016-12-03 Thread Paul Gowder
That's a really neat post. Thank you for writing it! How do bindings created by let fit into that picture? > The question of how vars work comes up enough that I recently wrote a blog > post on the subject. Maybe it will be useful to you. > http://blog.cognitect.com/blog/2016/9

Re: recursive bindings not available in let form?

2016-12-03 Thread Timothy Baldridge
gow...@gmail.com> wrote: > Thanks Bobby, Francis, Walter! Now trying to wrap my head around the idea > of def as a ref... > > On Friday, December 2, 2016 at 2:57:13 PM UTC-6, Francis Avila wrote: > > Let bindings are immutable bindings, not refs. They must act as if their >

Re: recursive bindings not available in let form?

2016-12-02 Thread Mark Engelberg
Your "y" could also be "fib". You are permitted to use the same name inside the fn. On Fri, Dec 2, 2016 at 12:59 PM, Walter van der Laan < waltervanderl...@gmail.com> wrote: > AFAIK there are two options. > > You can add a symbol after fn: > >

Re: recursive bindings not available in let form?

2016-12-02 Thread Paul Gowder
Thanks Bobby, Francis, Walter! Now trying to wrap my head around the idea of def as a ref... On Friday, December 2, 2016 at 2:57:13 PM UTC-6, Francis Avila wrote: > > Let bindings are immutable bindings, not refs. They must act as if their > value could be substituted at t

Re: recursive bindings not available in let form?

2016-12-02 Thread Walter van der Laan
AFAIK there are two options. You can add a symbol after fn: (let [fib (fn y [x] (cond (< x 2) x :else (+ (y (- x 2)) (y (- x 1)] (fib 5)) Or, as Bobby already suggested, you can use letfn: (letfn [(fib [x] (c

recursive bindings not available in let form?

2016-12-02 Thread Francis Avila
Let bindings are immutable bindings, not refs. They must act as if their value could be substituted at the moment they are referenced. Def (i.e. a ref) is a mutable container whose contents is examined when it is used (not when referenced), which is why your second example works. Why doesn't

Re: recursive bindings not available in let form?

2016-12-02 Thread Bobby Eickhoff
ecursive > fibonacci function interactively. So naturally, the first thing my fingers > went to was: > > (let [fib (fn [x] > (cond > (< x 2) x > :else (+ (fib (- x 2)) (fib (- x 1)] > (fib 5)) > > which threw an unable to resolve symbol error because i

recursive bindings not available in let form?

2016-12-02 Thread Paul Gowder
... So for obscure reasons, I found myself trying to use a naive recursive fibonacci function interactively. So naturally, the first thing my fingers went to was: (let [fib (fn [x] (cond (< x 2) x :else (+ (fib (- x 2)) (fib (- x 1)] (fib 5)) which threw an unable to reso

Re: def partial vs let partial

2016-12-01 Thread Timothy Baldridge
as different behavior > to the letted one? > This is especially confusing to me since the #() special form one works as > I expect. > > (def sum-partial-def (partial reduce +)) > > (let [sum-partial (partial reduce +) > sum-# #(reduce + %1) > nums [1 2 3 4]] > [

Re: def partial vs let partial

2016-12-01 Thread Gary Trakhman
n to me why the def-ed partial has different behavior > to the letted one? > This is especially confusing to me since the #() special form one works as > I expect. > > (def sum-partial-def (partial reduce +)) > > (let [sum-partial (partial reduce +) > sum-# #(reduce + %1)

def partial vs let partial

2016-12-01 Thread Matthew Hamrick
I'm confused by the following code. Could someone explain to me why the def-ed partial has different behavior to the letted one? This is especially confusing to me since the #() special form one works as I expect. (def sum-partial-def (partial reduce +)) (let [sum-partial (partial reduce

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

An elegant implementation of if-all-let

2015-07-11 Thread crocket
(defmacro if-all-let [bindings then else] (reduce (fn [subform binding] `(if-let [~@binding] ~subform ~else)) then (reverse (partition 2 bindings I quoted the function from p259 of Chas Emerick, Brian Carper, Christophe Grand-Clojure Programming-O'Reilly Media (2012

Re: An elegant implementation of if-all-let

2015-07-11 Thread Andy Fingerhut
Disclaimer: I do not make decisions on what gets into clojure.core. Here is a page that gives some reasons why most things don't get into clojure.core: http://dev.clojure.org/display/design/Why+Feature+X+Was+Declined More specifically on if-all-let and things like it, many people seem

Re: let vs. let*

2015-06-26 Thread Johannes
, then respond with this, otherwise I do not see a reason to post this. Thanks, Alex On Thursday, June 18, 2015 at 3:35:53 PM UTC-5, raould wrote: http://lmgtfy.com/?q=clojure+%22let+vs.+let*%22 -- You received this message because you are subscribed to the Google Groups Clojure group

Re: let vs. let*

2015-06-26 Thread Raoul Duke
My apologies (sincerely). Won't use that again. -- 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

Re: let vs. let*

2015-06-25 Thread Alex Miller
PM UTC-5, raould wrote: http://lmgtfy.com/?q=clojure+%22let+vs.+let*%22 -- 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

Re: let vs. let*

2015-06-25 Thread Luc Préfontaine
, then respond with this, otherwise I do not see a reason to post this. Thanks, Alex On Thursday, June 18, 2015 at 3:35:53 PM UTC-5, raould wrote: http://lmgtfy.com/?q=clojure+%22let+vs.+let*%22 -- You received this message because you are subscribed to the Google Groups Clojure

Re: let vs. let*

2015-06-20 Thread Mike Rodriguez
I don't think this is a let me google that for you question. Let vs let* in Clojure is not at all the same as the popular usages of these forms in popular lisp dialects like Common Lisp. I've thought it was confusing why let* existed in Clojure since let binding is only done in a sequential

Re: let vs. let*

2015-06-18 Thread Harley Waagmeester
In common lisp, 'let' didn't evaluate it's bindings in any guaranteed order (well, it is specified as being evaluated in parallel), however, 'let*' evaluated it's bindings in order from left to right. This enabled you to use the sequentially previous bindings in the evaluation of later

Re: let vs. let*

2015-06-18 Thread Fluid Dynamics
On Thursday, June 18, 2015 at 4:29:55 PM UTC-4, Johannes wrote: Hi! I cannot figure out, what the difference between let and let* is. Can anyone enlighten me? Let is a macro that wraps let* and adds destructuring. There's a similar relationship between fn and fn*, letfn and letfn

let vs. let*

2015-06-18 Thread Johannes
Hi! I cannot figure out, what the difference between let and let* is. Can anyone enlighten me? Johannes -- 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

Re: let vs. let*

2015-06-18 Thread Raoul Duke
http://lmgtfy.com/?q=clojure+%22let+vs.+let*%22 -- 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

Re: let vs. let*

2015-06-18 Thread Johannes
thanks Am Donnerstag, 18. Juni 2015 22:35:53 UTC+2 schrieb raould: http://lmgtfy.com/?q=clojure+%22let+vs.+let*%22 -- 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

Re: let vs. let*

2015-06-18 Thread Michael Blume
Basically you the user should not worry about the starred versions On Thu, Jun 18, 2015 at 1:40 PM Johannes bra...@nordakademie.de wrote: thanks Am Donnerstag, 18. Juni 2015 22:35:53 UTC+2 schrieb raould: http://lmgtfy.com/?q=clojure+%22let+vs.+let*%22 -- You received this message

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

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

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 access

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

2015-06-09 Thread Andy Fingerhut
: 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

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

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

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

2015-06-09 Thread Sean Corfield
On Jun 9, 2015, at 3:51 PM, Leon Grapenthin grapenthinl...@gmail.com wrote: Syntactically though, one could worry that the additional bindings would be read as regular let bindings and worry about the language clarity. One of the main points that I seem to recall from previous discussions has

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

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 to 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 macro a little bit. On Friday, June 5

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-let-all. (defmacro if-let-all

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

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 binding sequentially and evaluates

Re: Let bindings and immutability

2015-02-12 Thread Luc Préfontaine
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

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

Re: Let bindings and immutability

2015-02-11 Thread Ambrose Bonnaire-Sergeant
Local bindings are immutable. Your example demonstrates lexical shadowing of bindings. This is an equivalent program semantically. (let [x 1 x_1 (inc x) x_2 (inc x_1) x_3 (inc x_2)] x_3) By the rules of lexical scoping, you cannot access the first `x` but it is never

Re: Let bindings and immutability

2015-02-11 Thread Herwig Hochleitner
2015-02-12 3:06 GMT+01:00 gvim gvi...@gmail.com: That explains it but I think Clojure's syntax is misleading here. Without knowledge of this magic the mind doesn't readily translate: In some other lisps, clojure's let is called let* for this reason. Their let binds only in parallel, similar

Re: Let bindings and immutability

2015-02-11 Thread Justin Smith
(let [x 0 f #(println x) x 1 g #(println x) x 2] (f) (g) x) there is no mutation of x, only scope shadowing hiding the other binding. Most functional languages (all that I know) allow shadowing. -- You received this message because you are subscribed

Re: Let bindings and immutability

2015-02-11 Thread gvim
On 12/02/2015 01:53, Ben Wolfson wrote: 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

Re: Let bindings and immutability

2015-02-11 Thread Herwig Hochleitner
I think that, from a user perspective, the important difference from mutation to shadowing is, that outer x is available even in the inner context, if captured by a closure. Likewise, a second thread, that runs an outer closure, would see the original x. Observe: (let [x :outer f (fn [] x

Re: Let bindings and immutability

2015-02-11 Thread gvim
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

Let bindings and immutability

2015-02-11 Thread gvim
Why is this possible in a language based on immutability: (let [x 1 x (inc x) x (inc x) x (inc x)] x) ;;= 4 Maybe under the hood (ie. memory registers/pointers etc.) this isn't strictly mutation but as a relative newcomer to Clojure I find it goes against the grain

Re: Let bindings and immutability

2015-02-11 Thread Laurens Van Houtven
Hi, On Feb 11, 2015, at 5:42 PM, gvim gvi...@gmail.com wrote: Why is this possible in a language based on immutability: (let [x 1 x (inc x) x (inc x) x (inc x)] x) ;;= 4 Maybe under the hood (ie. memory registers/pointers etc.) this isn't strictly

Re: Let bindings and immutability

2015-02-11 Thread James Reeves
On 12 February 2015 at 02:06, gvim gvi...@gmail.com wrote: That explains it but I think Clojure's syntax is misleading here. Without knowledge of this magic the mind doesn't readily translate: (let [x 1 x (inc x) x (inc x) x (inc x)] x) into: (let [x 1

Re: try-let

2014-12-19 Thread Simon Stender Boisen
Old thread, but still works great, thanks! Den onsdag den 28. april 2010 03.25.26 UTC+2 skrev ataggart: Inspired from an earlier discussion, I've written a macro that allows let-style binding values to be try'd, and still available to catch/ finally clauses. E.g.: (try-let [from (API

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)) ~(if-and-let* (drop 2 bindings

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

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

2014-11-26 Thread Sam Ritchie
You've discovered the error (or Either) monad! https://brehaut.net/blog/2011/error_monads Michael Blume mailto:blume.m...@gmail.com November 26, 2014 at 8:06 PM Instead of the deshadowing logic, why not (defn if-and-let* [bindings then-clause else-fn-name] (if (empty? bindings

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 Google Groups Clojure group

  1   2   3   4   5   6   7   >