unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "Colin Woodbury" <colin@fosskers.ca>
To: "Andreas Schwab" <schwab@linux-m68k.org>
Cc: emacs-devel@gnu.org
Subject: Re: [PATCH] lisp/files.el: Add `file-name-set-extension`
Date: Wed, 26 May 2021 09:31:38 -0700	[thread overview]
Message-ID: <9a92de1b-e313-468d-aa1f-7f969ed73688@www.fastmail.com> (raw)
In-Reply-To: <87czteeyoc.fsf@igel.home>

[-- Attachment #1: Type: text/plain, Size: 1479 bytes --]

Hi Andreas,

In this particular case, the `string-trim-*` family of functions panic with the rather unhelpful `Wrong type argument: stringp, nil` message when passed `nil`, so the initial `when` is guarding against that. Since `nil` exists as a "bottom" value to every type in Elisp (not unlike C's null pointers), we adopt the C approach of "don't trust what we're given, and expect the user to check what they're returned". Such scenarios are precisely what macros like `when-let` are for, as far as I can tell.

In general this approach is founded upon the ideas that:

1. `nil` is a good general signal for logical failure (for languages that lack generics, etc.).
2. Library code shouldn't crash/panic (but user code should feel free to).
3. It's okay to return `nil` if the docstrings are clear about when that happens.

Please let me know if I've overlooked something, I'm happy to revise the patch.

Cheers,
Colin

On Wed, 26 May 2021, at 00:34, Andreas Schwab wrote:
> On Mai 25 2021, Colin Woodbury wrote:
> 
> > +Returns nil if either of the FILENAME or EXTENSION are nil before
> > +dot consolidation, or empty afterwards."
> > +  (when (and filename extension)
> 
> I still don't see any reason to allow nil.  A file name is always a
> string.
> 
> Andreas.
> 
> -- 
> Andreas Schwab, schwab@linux-m68k.org <mailto:schwab%40linux-m68k.org>
> GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
> "And now for something completely different."
> 

[-- Attachment #2: Type: text/html, Size: 2146 bytes --]

  reply	other threads:[~2021-05-26 16:31 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-25 15:50 [PATCH] lisp/files.el: Add `file-name-set-extension` Colin Woodbury
2021-05-25 17:48 ` Andreas Schwab
2021-05-25 19:42   ` Colin Woodbury
2021-05-25 18:00 ` Basil L. Contovounesios
2021-05-25 19:45   ` Colin Woodbury
2021-05-25 20:25     ` Stefan Monnier
2021-05-25 21:21       ` Colin Woodbury
2021-05-25 21:29         ` Stefan Monnier
2021-05-25 21:44           ` Colin Woodbury
2021-05-26  7:34             ` Andreas Schwab
2021-05-26 16:31               ` Colin Woodbury [this message]
2021-05-26 17:39                 ` Andreas Schwab
2021-05-31  1:16                   ` Colin Woodbury
2021-06-04 13:08                     ` Philipp
     [not found]                       ` <26B660D9-AC76-4AFC-9FFD-2F5D4DCA16C1@acm.org>
2021-06-09 20:54                         ` Colin Woodbury
2021-06-09 23:05                           ` Stefan Monnier
2021-06-10  0:42                             ` Colin Woodbury
2021-06-10  2:45                               ` Colin Woodbury
2021-06-10  7:46                           ` Michael Albinus
2021-06-10 14:40                             ` Colin Woodbury
2021-06-16  1:15                               ` Colin Woodbury
2021-06-19  9:16                                 ` Michael Albinus

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=9a92de1b-e313-468d-aa1f-7f969ed73688@www.fastmail.com \
    --to=colin@fosskers.ca \
    --cc=emacs-devel@gnu.org \
    --cc=schwab@linux-m68k.org \
    /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).