unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Lars Magne Ingebrigtsen <larsi@gnus.org>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: Re: if-let and when-let: parallel or sequential
Date: Tue, 12 Aug 2014 04:43:34 +0200	[thread overview]
Message-ID: <m361hye8bt.fsf@stories.gnus.org> (raw)
In-Reply-To: <jwvr40nt7j1.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Mon, 11 Aug 2014 10:42:19 -0400")

Stefan Monnier <monnier@iro.umontreal.ca> writes:

> Why do you think so?  If they only work for a single binding, the
> benefit is really minor.  It's only when you use several bindings that
> the benefit becomes more significant (the alternative being either
> a very deeply nested code, or separating the var's declarations from
> their initialization).

I use lw:when-let all the time in Common Lisp.  It only takes a single
binding.  I find it very clear and nice -- mostly used as a kinda "early
return" thing, but without the return.

(defun foo (zot)
  (when-let (bar (compute-something zot))
    ...))

I grepped through a random directory in our code base, and out of 146
uses of when-let, 6 had nested when-lets.

There's lw:when-let*, though, which is like Emacs' when-let (i.e.,
several bindings), which is used two times.

Anyway, I think Emacs' when-let is a good addition as it is now.  Even
if the multiple-let-binding version doesn't get used much, it's nice
when you need it.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



  parent reply	other threads:[~2014-08-12  2:43 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-10  2:44 if-let and when-let: parallel or sequential John Mastro
2014-08-10 15:22 ` Stefan Monnier
2014-08-11 12:01   ` Bozhidar Batsov
2014-08-11 14:42     ` Stefan Monnier
2014-08-11 16:40       ` Harald Hanche-Olsen
2014-08-11 17:49       ` Bozhidar Batsov
2014-08-11 20:55         ` Harald Hanche-Olsen
2014-08-12  2:43       ` Lars Magne Ingebrigtsen [this message]
2014-08-12  3:15       ` Richard Stallman
2014-08-12  3:30         ` John Mastro
2014-08-12 14:32           ` Elias Mårtenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m361hye8bt.fsf@stories.gnus.org \
    --to=larsi@gnus.org \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).