all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: Michael Heerdegen <michael_heerdegen@web.de>, emacs-devel@gnu.org
Subject: RE: Human-readable file sorting
Date: Sat, 20 Feb 2016 10:25:50 -0800 (PST)	[thread overview]
Message-ID: <7652fd6b-aa2e-4ffc-a594-1256f467da5d@default> (raw)
In-Reply-To: <87oabbe1by.fsf@web.de>

> > (defun file-string-lessp (s1 s2)
> >   (pcase file-sorting-method
> >     (,unicode
> >      (string-lessp s1 s2))
> >     (,human
> >      (human-string-lessp s1 s2)))
> >     ..)
> >
> > (Hey!  Did I get the pcase syntax right?  Bonus points!)
> 
> These patterns are invalid.  I think the patterns you want are
> 'unicode and 'human.

`eql' tests of the value of a symbol are exactly what Common Lisp
`case' is for (`cl-case' in Elisp).

 (cl-case file-sorting-method
   (unicode    (string-lessp s1 s2))
   (human      (human-string-lessp s1 s2))
   (otherwise  (my-default-string-less-p s1 s2)))

Use `pcase' when you need to do something fancier - that makes the
fancy need clear to a human reader.  If Lars's "..)" requires fancy
stuff then `pcase' can make sense here.  Otherwise, it is overkill.

----

FWIW:

That should be `human-string-less-p', not `human-string-lessp'.

`string-lessp' (and `smie-rule-bolp') are (AFAICT) the only exceptions
(found in the Emacs manuals, at least) to the rule stated in (elisp)
`Coding Conventions' that a predicate name that uses multiple words
should end in `-p' (not just `p'):

  If the purpose of a function is to tell you whether a certain
  condition is true or false, give the function a name that ends in
  'p' (which stands for "predicate").  If the name is one word, add
  just 'p'; if the name is multiple words, add '-p'.  Examples are
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  'framep' and 'frame-live-p'.

Both of the names `string-lessp' and `smie-rule-bolp' could claim to
reuse well known names `lessp' and `bolp', but that claim is lame.
`time-less-p' is correct; `string-lessp' not so much.
 
`string-lessp' was perhaps named before the naming rule was adopted.
`smie-rule-bolp' presumably has no such excuse.  (And `string-lessp'
at least has an alias: `string<'.)



  reply	other threads:[~2016-02-20 18:25 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-20  1:15 Human-readable file sorting Lars Ingebrigtsen
2016-02-20  1:58 ` John Wiegley
2016-02-20  2:26   ` Lars Ingebrigtsen
2016-02-20  2:33     ` John Wiegley
2016-02-20  6:00       ` Lars Ingebrigtsen
2016-02-20  6:12         ` Marcin Borkowski
2016-02-20  7:15           ` Lars Ingebrigtsen
2016-02-20  8:14             ` Marcin Borkowski
2016-02-22 18:09             ` Nikolaus Rath
2016-02-22 21:31               ` Marcin Borkowski
2016-02-23  6:13                 ` Yuri Khan
2016-02-23  8:32                   ` Andreas Schwab
2016-02-24  5:39                     ` Marcin Borkowski
2016-02-20  6:17         ` John Wiegley
2016-02-20  7:11           ` Lars Ingebrigtsen
2016-02-20  9:28         ` Eli Zaretskii
2016-02-20 10:24           ` martin rudalics
2016-02-20 10:53             ` Eli Zaretskii
2016-02-20 17:30         ` Michael Heerdegen
2016-02-20 18:25           ` Drew Adams [this message]
2016-02-20  6:16       ` dired and ls (was: Human-readable file sorting) Lars Ingebrigtsen
2016-02-20  6:19         ` dired and ls John Wiegley
2016-02-20  7:25           ` Lars Ingebrigtsen
2016-02-20  8:01             ` John Wiegley
2016-02-23  7:15               ` Thierry Volpiatto
2016-02-23 16:34                 ` John Wiegley
2016-02-20  9:57         ` dired and ls (was: Human-readable file sorting) Eli Zaretskii
2016-02-20 19:21           ` dired and ls John Wiegley
2016-02-20 21:02             ` Eli Zaretskii
2016-02-20 21:24               ` John Wiegley
2016-02-21  2:10           ` Lars Ingebrigtsen
2016-02-20  8:53     ` Human-readable file sorting Eli Zaretskii
2016-02-20 11:32       ` Lars Ingebrigtsen
2016-02-20 11:36         ` Eli Zaretskii
2016-02-20 11:45           ` Lars Ingebrigtsen
2016-02-20 12:35             ` Eli Zaretskii
2016-02-21  2:14               ` Lars Ingebrigtsen
2016-02-21 23:36                 ` Richard Stallman
2016-02-22  2:58                   ` Lars Ingebrigtsen
2016-02-22 18:01                     ` Richard Stallman
2016-02-22 18:13                       ` Pierpaolo Bernardi
2016-02-22 19:00                       ` Eli Zaretskii
2016-02-23 17:43                         ` Richard Stallman
2016-02-23 18:00                           ` Eli Zaretskii
2016-02-24  1:51                             ` Lars Ingebrigtsen
2016-02-24 13:43                               ` Richard Stallman
2016-02-24 13:41                             ` Richard Stallman
2016-02-20 14:23             ` Alexis
2016-02-20 14:43               ` Eli Zaretskii
2016-02-21  2:18               ` Lars Ingebrigtsen
2016-02-21  9:30                 ` Alexis
2016-02-21 10:07                   ` Lars Ingebrigtsen
2016-02-21 19:27                   ` Yuri Khan
2016-02-21 20:21                     ` Eli Zaretskii
2016-02-20 15:35       ` Pierpaolo Bernardi
2016-02-20 15:52         ` Eli Zaretskii
2016-02-21 12:45           ` Richard Stallman
2016-02-20 16:03         ` Herring, Davis
2016-02-20 16:23           ` Paul Eggert
2016-02-21  2:20         ` Lars Ingebrigtsen
2016-02-21 12:45         ` Richard Stallman
2016-02-21  2:38     ` Stefan Monnier
2016-02-20 14:32 ` Richard Stallman

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

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

  git send-email \
    --in-reply-to=7652fd6b-aa2e-4ffc-a594-1256f467da5d@default \
    --to=drew.adams@oracle.com \
    --cc=emacs-devel@gnu.org \
    --cc=michael_heerdegen@web.de \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.