unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Thien-Thi Nguyen <ttn@gnuvola.org>
To: Bastien <bzg@gnu.org>
Cc: "Pascal J. Bourguignon" <pjb@informatimago.com>, emacs-devel@gnu.org
Subject: Re: Why (substring "abc" 0 4) does not return "abc" instead of an error?
Date: Mon, 16 Jul 2012 21:49:17 +0200	[thread overview]
Message-ID: <87zk6z8p1e.fsf@zigzag.favinet> (raw)
In-Reply-To: <87629nd7tu.fsf@gnu.org> (Bastien's message of "Mon, 16 Jul 2012 17:49:49 +0200")

() Bastien <bzg@gnu.org>
() Mon, 16 Jul 2012 17:49:49 +0200

   Bastien <bzg@gnu.org> writes:

   > I'm not interested in doing crazy stuff, I'm interested in
   >
   > (substring "abc" 0 4 t)
   >   => "abc"
   >
   > where `t' is the value of an option third NOERROR argument.
                                         ^^^^^

   Fourth, actually.

If you prefer this slackful ‘substring’ and would like to use it
everywhere, then in practice "extending" ‘substring’ has the same
cost as writing a personalized version.

How's that?

Imagine if ‘substring’ were to indeed be changed to support this
NOERROR argument.  Since you want to use it everywhere, you would
start converting all the callsites to include NOERROR ‘t’.  After
a bit, you'd look askance at this extra verbosity, and decide to
abstract it w/ a personalized function, say "subs".

  (defun subs (string beg end)
    (substring string beg end t))

"Ah, much better!" you think.  Well i would agree.  But now that
you have ‘subs’ (and use it everywhere), why precisely do you need
the extended ‘substring’ anymore?  You could have saved the effort
of going north 1 then east 1 by going northeast 1.414...

  (defun subs (string beg end)
    (substring string beg (and (< end (length string))
                               end)))

...in the first place.  Overall, the design principle is that you
want the platform to be firm and the performer flexible, not the
other way around.  The audience may be pleased either way, but as
producer, you want the roadies to sleep better lest they revolt...



  reply	other threads:[~2012-07-16 19:49 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-16  3:45 Why (substring "abc" 0 4) does not return "abc" instead of an error? Dmitry Gutov
2012-07-16  7:32 ` Bastien
2012-07-16  7:52   ` Thierry Volpiatto
2012-07-16  8:38     ` Bastien
2012-07-16 13:03   ` Dmitry Gutov
2012-07-16 14:32     ` Bastien
2012-07-16 13:10 ` Pascal J. Bourguignon
2012-07-16 14:40   ` Bastien
2012-07-16 15:00     ` Pascal J. Bourguignon
2012-07-16 15:07       ` Lennart Borgman
2012-07-16 15:19         ` Pascal J. Bourguignon
2012-07-16 15:22         ` Bastien
2012-07-16 15:46       ` Bastien
2012-07-16 15:49         ` Bastien
2012-07-16 19:49           ` Thien-Thi Nguyen [this message]
2012-07-16 22:32             ` Bastien
2012-07-16 15:56         ` Pascal J. Bourguignon
2012-07-16 16:13           ` Bastien
  -- strict thread matches above, loose matches on Subject: below --
2012-07-16 19:00 Dmitry Gutov
2012-07-16 19:51 ` Tassilo Horn
2012-07-15 23:15 Bastien
2012-07-15 23:29 ` Juanma Barranquero
2012-07-15 23:59   ` Bastien
2012-07-16  0:10     ` Juanma Barranquero
2012-07-16  7:14       ` Bastien
2012-07-16 16:15         ` Stefan Monnier
2012-07-16 16:22           ` Bastien
2012-07-16 16:46           ` Bastien
2012-07-16 17:57             ` Tassilo Horn
2012-07-16 18:51               ` Lars Magne Ingebrigtsen
2012-07-16 19:30                 ` Bastien
2012-07-16 19:30                 ` Tassilo Horn
2012-07-16 20:20                 ` Pascal J. Bourguignon
2012-07-16 19:25               ` Bastien
2012-07-16 19:43                 ` Bastien
2012-07-16 20:19             ` Pascal J. Bourguignon
2012-07-16 20:30             ` Stefan Monnier
2012-07-16 22:28               ` Lennart Borgman
2012-07-16 22:48                 ` Bastien
2012-07-16 22:53                   ` Lennart Borgman
2012-07-16  7:38       ` Andreas Schwab
2012-07-16  9:40         ` Juanma Barranquero

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=87zk6z8p1e.fsf@zigzag.favinet \
    --to=ttn@gnuvola.org \
    --cc=bzg@gnu.org \
    --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).