unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: "Pascal J. Bourguignon" <pjb@informatimago.com>, emacs-devel@gnu.org
Subject: RE: Sweeter Emacs Lisp
Date: Sat, 10 Aug 2013 09:27:14 -0700 (PDT)	[thread overview]
Message-ID: <56378161-1a38-40a2-bdd5-a13dc8de8d7e@default> (raw)
In-Reply-To: <8761vdoo3e.fsf@informatimago.com>

> >    > RMS suggested instead: (cond VAR (CONDITION [BODY...])...)
> >
> >    As I pointed out back then, a more general solution is a way to
> >    let-bind new variables in between cond clauses, as in
> >       (cond
> >        (<test1> <body1>)
> >        (let x <foo>)
> >        (<test2> <body2>))
> >
> >    which would be used in cases where we currently use
> >       (let (x)
> >         (cond
> >          (<test1> <body1>)
> >          ((progn (setq x <foo>) <test2>) <body2>))
> 
> I don't like it.  The general idiom in lisp, and including in emacs
> lisp, is to have a close correspondance between parentheses and lexical
> scope.
> 
> Whether x is in the englobing scope, or in a scope covering only the
> remaining clauses, in both cases it's bad because it's not reflected by
> the sexp structure of the form.

+1

> In this aspect, RMS' suggestion is better.

It's better, but it too is not a great idea, IMO.  Clearest of
all is what y'all *started* with - plain ol' lisp:

(let (x)
  (cond ((...x...)
         ...)
        ((progn (setq x ...) ...) 
         ...)))

or more likely:

(cond ((let ((x ...))...)
       ...)
      ((let ((x ...))...)
       ...))

or typically clearer, when possible (e.g., subforms refer to the
variable explicitly or do not evaluate code that refers to it):

(cond ((let ((x1 ...))...)
       ...)
      ((let ((x2 ...))...)
       ...)

depending on the need/context.

> I would advise a form rather like:
>      (letcond
>         ((f) 1)
>         (let* ((x (g))
>                (y (h x)))
>           ((= x y) 2)
>           ((< x y) 3)
>           (let ((z (p)))
>             ((< x z) 4))
>           (t 5))
>         ((q) 6)
>         (t 0))
>
> --> (cond ((f) 1)
>           ((let* ((x (g))
>                   (y (h x)))
>              (cond ((= x y) 2)
>                    ((< x y) 3)
>                    ((let ((z (p)))
>                      (cond ((< x z) 4))))
>                    (t 5))))
>           ((q) 6)
>           (t 0))

Quelle horreur ! The second (the macroexpansion of the first) is
more readable than the first.

And the second is but a mechanical expansion.  A human would write
something simpler, e.g. (and (< x z) 4) instead of (cond ((< x z) 4)).

And with average-length function and variable names the second form
is not much more verbose than the first.  Saving a few parens and
explicit conditionals at the expense of clarity wrt scope etc. is
usually an unwise trade-off.

YAGNI.



      reply	other threads:[~2013-08-10 16:27 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-14  2:22 Sweeter Emacs Lisp fgallina
2013-07-14 11:36 ` Dmitry Gutov
2013-07-14 11:53   ` Vitalie Spinu
2013-07-14 12:38     ` Aurélien Aptel
2013-07-14 13:25     ` Xue Fuqiao
2013-07-14 14:16     ` Pascal J. Bourguignon
2013-07-14 14:22 ` Lars Magne Ingebrigtsen
2013-07-14 16:27   ` Juanma Barranquero
2013-07-14 19:43     ` Lars Magne Ingebrigtsen
2013-07-15  3:20   ` Dmitry Gutov
2013-07-15  5:03     ` Stephen J. Turnbull
2013-07-16 20:23       ` Dmitry Gutov
2013-07-17 14:04         ` Lars Magne Ingebrigtsen
2013-07-17 15:07           ` Dmitry Gutov
2013-07-16  2:15   ` Miles Bader
2013-07-16  9:12     ` Stefan Monnier
2013-07-14 16:18 ` Josh
2013-07-14 16:30   ` Juanma Barranquero
2013-07-14 17:14     ` Josh
2013-07-14 17:18       ` Juanma Barranquero
2013-07-15  6:05         ` Lars Brinkhoff
2013-07-15  7:04   ` Stefan Monnier
2013-07-15 13:30     ` Bozhidar Batsov
2013-07-16  2:26       ` Miles Bader
2013-07-16  6:08         ` Thien-Thi Nguyen
2013-07-16 14:07           ` Drew Adams
2013-07-16  9:11       ` Stefan Monnier
2013-07-14 17:24 ` Andreas Schwab
2013-07-16  2:13 ` Miles Bader
2013-07-16  6:14   ` Stephen J. Turnbull
2013-07-16  9:07   ` Stefan Monnier
2013-07-16 11:09     ` Juanma Barranquero
2013-07-16 12:25       ` Andreas Schwab
2013-07-16 13:04         ` Thierry Volpiatto
2013-07-16 13:42         ` Juanma Barranquero
2013-07-16 14:38           ` Andreas Schwab
2013-07-16 14:42             ` Juanma Barranquero
2013-07-16 20:57       ` Stefan Monnier
2013-07-22 15:24 ` Stefan Monnier
2013-07-22 16:33   ` Thien-Thi Nguyen
2013-07-22 21:04     ` Stefan Monnier
2013-07-23  4:37       ` Thien-Thi Nguyen
2013-08-10  2:52         ` Stefan Monnier
2013-08-10 10:08         ` Pascal J. Bourguignon
2013-08-10 16:27           ` Drew Adams [this message]

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=56378161-1a38-40a2-bdd5-a13dc8de8d7e@default \
    --to=drew.adams@oracle.com \
    --cc=emacs-devel@gnu.org \
    --cc=pjb@informatimago.com \
    /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).