From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuri Khan Newsgroups: gmane.emacs.help Subject: Re: avoid narrow-to-region (was: Re: replace-regexp) Date: Sun, 9 May 2021 12:48:29 +0700 Message-ID: References: <87tunf1mz5.fsf@zoho.eu> <87v97v6mxg.fsf@gnu.org> <87wnsaz9df.fsf@zoho.eu> <877dkaytwu.fsf@zoho.eu> <87eeegx25w.fsf_-_@zoho.eu> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34998"; mail-complaints-to="usenet@ciao.gmane.io" To: Emanuel Berg , help-gnu-emacs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sun May 09 07:49:23 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lfcJe-0008wE-OQ for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 09 May 2021 07:49:22 +0200 Original-Received: from localhost ([::1]:51422 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lfcJd-0001EO-8s for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 09 May 2021 01:49:21 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:51768) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lfcJ8-0001EG-Me for help-gnu-emacs@gnu.org; Sun, 09 May 2021 01:48:50 -0400 Original-Received: from mail-ua1-x934.google.com ([2607:f8b0:4864:20::934]:40740) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lfcJ5-0002i3-OL for help-gnu-emacs@gnu.org; Sun, 09 May 2021 01:48:50 -0400 Original-Received: by mail-ua1-x934.google.com with SMTP id 33so4192672uaa.7 for ; Sat, 08 May 2021 22:48:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :content-transfer-encoding; bh=hmg+K3PU6BawJ/nOBq1yR4NH4Mlp7W8s9ALPXxZl1Tc=; b=dKpZVpvk7LmSFVupMnyG0FKzz7Won2Forxu6x8XBPUt2xdWbQLhK1eQoTr8q59OfrR wRTFEfRSSiu9VraJP43x0nPyLWikqg9z7w/2cPWeakjiU2eR7vZlFwwkTAGIWyG79qTg rZS5OxobM1JzjALP7Sk3rGlIDTFwqWsizd0+ANgIO+OF0zFX3+VjTrwxLW2dpMupR1Py BXVHq+OEa0I9fbrg4Ci2H63SyRzEnkHLMwkttVz14DDEWZx/XUgpaMoHQSDXmMschJ7L XGDiK5QNHo7NB5Ug0EK5vmZ+vqkXYiJBtBRxEe8sNTqWY1jzQWZNBSqq0QtGCdBcaN+5 D4Iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:content-transfer-encoding; bh=hmg+K3PU6BawJ/nOBq1yR4NH4Mlp7W8s9ALPXxZl1Tc=; b=Xie1nUHRER+7lUUfzgOaZkJ40Wv7PJxxXJTcgWS9cLmj5VoTsDoGGaiGQk4wx2TeT+ zpRkwrzLo6rZNfOg/3EKByIA2eDYjMBND1xapgEVYDa2BxPvmDUePi66VtL4R2EvCBE+ gIaJ+Chaia34Ly9n9YbrJovkj/2XE2/iS3yrV9fNCC3MQXuPLDtGbQAy4gjZvDPJO/Jn Xg82ncZQIxnzv6ID4GMes8NmBnyxwzGGKniOycI+sCb9Iort1hMs66Rw7NIf9aW7F3nb c/jGsuigsAOC/m2xwyg8RroO6MxgKXA4vXmVjyogS7E+XGucMtUMhdWigIvI8Ry+mKmi ZJIw== X-Gm-Message-State: AOAM531dB9IVrM2LadwtkWfT9lX48U3Jd+zRu2KejXEU+MmKAS6xPIkR H6OlsNDv0XJboMRKOCVfvcrEeeP93OFJj8+xD/w= X-Google-Smtp-Source: ABdhPJwyl11dA7DYOdlk3V9NAjkiMPouly8YXPUf/ULg5/NexJbLl+5X2cTgVDPRWzAgvpaltA2wf0LdbW1+i1xaleQ= X-Received: by 2002:ab0:2b15:: with SMTP id e21mr3024458uar.102.1620539321126; Sat, 08 May 2021 22:48:41 -0700 (PDT) In-Reply-To: <87eeegx25w.fsf_-_@zoho.eu> Received-SPF: pass client-ip=2607:f8b0:4864:20::934; envelope-from=yurivkhan@gmail.com; helo=mail-ua1-x934.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:129598 Archived-At: On Sun, 9 May 2021 at 06:00, Emanuel Berg via Users list for the GNU Emacs text editor wrote: > (sort-subr nil > #'forward-line > #'end-of-line > nil nil > (lambda (_ __) (zerop (random 2)) ))))) Note that this is not a suitable sorting predicate. It violates all axioms of a strict weak ordering: * Consistency: If (f a b) returns t once, it must return t when called again with the same arguments. * Irreflexivity: (f a a) must return nil. Your predicate returns nil or t randomly. * Antisymmetry: of (f a b) and (f b a), no more than one may return t. In your case, both can return t. * Transitivity: If (f a b) and (f b c) both return t, (f a c) must also return t. * Transitivity of equivalence: if (f a b), (f b a), (f b c), (f c b) all return nil, then (f a c) and (f c a) must also return nil. Generic sorting algorithms typically require the predicate to conform to all of the above; otherwise, they may signal an error or enter an endless loop. I have not analyzed whether =E2=80=98sort-subr=E2=80=99 has any issues with inconsistent orderings, and its docstring does not mention these requirements, but it would be a good idea to avoid that anyway. Also, using a sorting algorithm to randomize an ordered sequence is a bit of an overkill. Sorting has an asymptotic complexity of O(n log n), but the Fisher=E2=80=93Yates=E2=80=93Durstenfeld shuffle algorithm is O= (n). https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle