all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Bozhidar Batsov <bozhidar@batsov.com>
To: Eli Zaretskii <eliz@gnu.org>,
	Stefan Monnier <monnier@iro.umontreal.ca>,
	nandryshak@gmail.com,  Nicolas Petton <nicolas@petton.fr>,
	emacs-devel <emacs-devel@gnu.org>
Subject: Re: string> missing?
Date: Thu, 4 Jun 2015 09:02:05 +0200	[thread overview]
Message-ID: <CAM9Zgm2429mCXiJtzg=kD3rOjvLtgKgLNcz2icT9zLVcwH9RTA@mail.gmail.com> (raw)
In-Reply-To: <87vbf4dldj.fsf@gnu.org>

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

Way too much bikeshedding for something super trivial. Let's add the
function(s) and be done with it.

On 4 June 2015 at 08:43, Tassilo Horn <tsdh@gnu.org> wrote:

> Eli Zaretskii <eliz@gnu.org> writes:
>
> >> Emacs is inconsistent.  That's part of its inheritance.
> >> If someone wants to add string>, I'm perfectly OK with it.
> >
> > Why not _remove_ string< and use compare-strings for both jobs?
>
> Oh yes, please.  Everybody wants to use a function of 6-7 arguments! ;-)
>
> Fun aside: aside from the reason of symmertry/consistency, I can see at
> least two practical advantages of having `string>'.  Whenever it should
> be used as predicate of a higher-order function,
>
>   (sort coll #'string>)
>
> is more concise than
>
>   (sort coll (lambda (a b) (string< b a)))
>
> and it is also better to edebug because you are usually not
> interested in edebugging the lambda.  (What can possibly go wrong
> there?!?)
>
> However, this is true for any other simple predicate aside from number
> or string comparison.  So I'd suggest to have a `complement' function
> which simply returns a function negating the value of some predicate,
> e.g.,
>
> (defun complement (fn)
>   "Returns a function calling FN and returning FN's negated value."
>   (lambda (&rest args)
>     (not (apply fn args))))
>
> Then you can do
>
>   (sort coll (complement #'string<))
>
> which looks like a good compromise wrt conciseness and edebuggability.
> Of course, (complement #'string<) is string>= which will work fine for
> `sort' but probably not for other higer-order functions.
>
> Grepping the emacs source code, there are indeed at least three
> occurrences of (nreverse (sort coll predicate)) which could make use of
> that.  And I can also find occurrences of (lambda (a b) (string< b a)).
> However, when the number of definitions is what makes a function which
> is currently not provided by Elisp important, than it looks to me that
> there should be a function for
>
>   (lambda (a b) (string< (car a) (car b)))
>
> For that, `rgrep' delivers 40 matches in the elisp repositories I have
> on my disk, and I only searched for
>
>   "(lambda (. .) (string< (car .) (car .)))"
>
> so it has to occur on one line with the exact spacing and 1-char wide
> arguments.  So that suggests we want to have a
> `car-string-less-than-car' (or indeed want to have the numerical
> comparison functions work for strings, too, as Stefan suggested because
> there's already `car-less-than-car').
>
> Bye,
> Tassilo
>
>

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

  reply	other threads:[~2015-06-04  7:02 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-03  9:05 string> missing? Nicolas Petton
2015-06-03 14:51 ` Eli Zaretskii
2015-06-03 15:03   ` Nicolas Petton
2015-06-03 15:26     ` Tassilo Horn
2015-06-03 15:46       ` Nick Andryshak
2015-06-03 15:55         ` Eli Zaretskii
2015-06-03 16:10           ` Nick Andryshak
2015-06-03 16:42             ` Eli Zaretskii
2015-06-03 16:50               ` Nick Andryshak
2015-06-03 18:10                 ` Andreas Schwab
2015-06-03 19:13                 ` Alan Mackenzie
2015-06-03 19:13                 ` Eli Zaretskii
2015-06-03 19:34                   ` Nick Andryshak
2015-06-03 19:53                     ` Eli Zaretskii
2015-06-03 20:11                       ` Nick Andryshak
2015-06-03 20:37                         ` Jay Belanger
2015-06-03 20:53                           ` Nick Andryshak
2015-06-03 21:35                             ` Jay Belanger
2015-06-03 21:36                     ` Thibaut Verron
2015-06-03 22:25                       ` Stefan Monnier
2015-06-04  5:30                         ` Thibaut Verron
2015-06-04  7:44                           ` Nicolas Richard
2015-06-04  8:08                             ` Thibaut Verron
2015-06-04 15:33                           ` Stefan Monnier
2015-06-03 22:28                     ` Stefan Monnier
2015-06-04  2:50                       ` Eli Zaretskii
2015-06-04  6:43                         ` Tassilo Horn
2015-06-04  7:02                           ` Bozhidar Batsov [this message]
2015-06-04  7:53                           ` Gnus & Mail-Followup-To (was: string> missing?) Nicolas Richard
2015-06-04  9:04                             ` Gnus & Mail-Followup-To Tassilo Horn
2015-06-04 12:50                               ` Nicolas Richard
2015-06-05 17:07                                 ` Tassilo Horn
2015-06-06  8:48                                   ` Nicolas Richard
2015-06-04  4:20                       ` string> missing? Thierry Volpiatto
2015-06-04 15:52                       ` Nicolas Petton
2015-06-03 21:24                 ` Richard Stallman
2015-06-04 15:07                   ` Eli Zaretskii
2015-06-05 17:56                     ` Richard Stallman
2015-06-05 19:04                       ` Eli Zaretskii
2015-06-05 20:40                         ` Tassilo Horn
2015-06-05 21:35                           ` Ivan Shmakov
2015-06-05 21:53                             ` Tassilo Horn
2015-06-05 22:04                               ` Tassilo Horn
2015-06-06  6:40                           ` Eli Zaretskii
2015-06-06  8:53                             ` Tassilo Horn
2015-06-07  0:28                             ` Richard Stallman
2015-06-06  1:52                         ` Richard Stallman
2015-06-06  7:57                           ` Eli Zaretskii
2015-06-07  0:28                             ` 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='CAM9Zgm2429mCXiJtzg=kD3rOjvLtgKgLNcz2icT9zLVcwH9RTA@mail.gmail.com' \
    --to=bozhidar@batsov.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=nandryshak@gmail.com \
    --cc=nicolas@petton.fr \
    /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.