emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why (substring "abc" 0 4) does not return "abc" instead of an error?


From: Thien-Thi Nguyen
Subject: Re: Why (substring "abc" 0 4) does not return "abc" instead of an error?
Date: Mon, 16 Jul 2012 21:49:17 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1 (gnu/linux)

() Bastien <address@hidden>
() Mon, 16 Jul 2012 17:49:49 +0200

   Bastien <address@hidden> 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 via email to

[Prev in Thread] Current Thread [Next in Thread]