emacs-devel
[Top][All Lists]
Advanced

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

RE: Human-readable file sorting


From: Drew Adams
Subject: RE: Human-readable file sorting
Date: Sat, 20 Feb 2016 10:25:50 -0800 (PST)

> > (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 via email to

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