From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Arthur Miller Newsgroups: gmane.emacs.devel Subject: Re: empty-directory predicate, native implementation Date: Sun, 18 Oct 2020 00:06:08 +0200 Message-ID: References: <83blh60wgr.fsf@gnu.org> <87h7qxjh7g.fsf@gmx.de> <878sc8kgy8.fsf@gmx.de> <87imbcls71.fsf@gmx.de> <83eem0zt0b.fsf@gnu.org> <87k0vsrd6m.fsf@gmx.de> <83a6wozs7h.fsf@gnu.org> <87sgafq2e2.fsf@gmx.de> <87h7qvptm3.fsf@gmx.de> <871rhxp8we.fsf@gmx.de> <237bd21b-96c7-4433-a5bc-34b64a9f4250@default> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38826"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: Eli Zaretskii , Michael Albinus , emacs-devel@gnu.org To: Drew Adams Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Oct 18 00:07:22 2020 Return-path: Envelope-to: ged-emacs-devel@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 1kTuMD-000A2C-Rg for ged-emacs-devel@m.gmane-mx.org; Sun, 18 Oct 2020 00:07:21 +0200 Original-Received: from localhost ([::1]:48748 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kTuMC-0007aY-QP for ged-emacs-devel@m.gmane-mx.org; Sat, 17 Oct 2020 18:07:20 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45276) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kTuL9-00077D-3M for emacs-devel@gnu.org; Sat, 17 Oct 2020 18:06:15 -0400 Original-Received: from mail-vi1eur06olkn2096.outbound.protection.outlook.com ([40.92.17.96]:10848 helo=EUR06-VI1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kTuL6-0006Cp-O5; Sat, 17 Oct 2020 18:06:14 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ljT307x8OwDrpHhfgKrZimmi2yZR3Qn6dgYqlIBZIdTbHHZKiH3PXPoQH+5NkTVVvH8ovoZr0MxYYFBFTlViRw51V4znputjTDeVcFqPKDTtfBTOuD+qSRZ+tRRuj3Z4/FQ9jdGAp7Pp5MwJ8GMmXRjS6Jnm+KyWZzpws0EAdvnpy+CONvILzTjTI093kglf+sIDsN1VtepMHtlXBvd6bCncAThJg7+/dij/ds1OXn/MxjFd6NTiU+kLQ1Wnu1M9Vjrc1g0m+D9npoPjh/JjC8bZjeYOirUNToOs6RnZmUsmP0jv/g+oE43A1eTomSZjb6/+WnIltB0VVZe4h5xVJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KaOTmBYQsO4uh7z4BfUFkZbfMIDKdj67Ir+IM9yOLCI=; b=KM7/jTbf4Xpi2K7pE5g5cfge4ZxCG/nJdpMGsyKzequprLcH1Mo80Sk4UXl84PLzPfNOPkxbokDr0c3aUKlfAD/l2dASTA+OiaeEp3ggh7E/2yAQTLIiwpqsKWH9IT8IcXit9qMQhRrHYzYUaZwqmGOhWquE8NX9y7fa/C6jHv3w2TsSeKRy3rlV3RjmF2gMiE2srchd50mJEAV/Qpu3YpEgIZrs5qzUazKFL+3BDZQUuE1TV58dGPZ95anuquEhUugi9gFfMpnv+IAG+R4YoriF8y1Gb0SnPUyJ1bYQPfgrIhgX1ww8tI74kypWuSBR+1gEO9RfcKJCLa1WaCIzvw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=live.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KaOTmBYQsO4uh7z4BfUFkZbfMIDKdj67Ir+IM9yOLCI=; b=swG1IHa+FjR9dAeL6t7nQu6XB83ayPpXZMuqdKWGzYbcyG+Y7NOA8QnPEVE7+rUwfXTiIO12go+bZL/o+VvCyEU2u0F3YEnpy6bpqkb92EI5zK5J3+7Zx5v2SWUYJL4bfAK/wgKhQX2VQWWy9ZpVUCrVVHlc4JKMfAumYH5FO1XdwmDnXqvypkdJDKi4lgnF5tbtXbv5Qtn34UBBKW4H8ghZIeoaMYwpzhqsklroay12jMrJKpYMkj8CTG5kEfB6RQ8h2QUyem3piVWm47k51fYdf3tR8uuOcAbxVv5BjPAr5xvtk+35LKJmUw7YvWeob8a8OMoeqd/8Em2KQOaGhQ== Original-Received: from VI1EUR06FT034.eop-eur06.prod.protection.outlook.com (2a01:111:e400:fc37::49) by VI1EUR06HT181.eop-eur06.prod.protection.outlook.com (2a01:111:e400:fc37::197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.23; Sat, 17 Oct 2020 22:06:09 +0000 Original-Received: from VI1PR06MB4526.eurprd06.prod.outlook.com (2a01:111:e400:fc37::48) by VI1EUR06FT034.mail.protection.outlook.com (2a01:111:e400:fc37::148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.21 via Frontend Transport; Sat, 17 Oct 2020 22:06:09 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:62574B229D73E93D825EAB99D0CDC22D1B807060E13D21CF9E680D5ECD37192E; UpperCasedChecksum:161F16B2DD478518B9DF4909BF499489E1AF41FD3AAB3EC30CF0AFC2EBEABFAA; SizeAsReceived:8553; Count:46 Original-Received: from VI1PR06MB4526.eurprd06.prod.outlook.com ([fe80::187b:196a:cb2d:adf1]) by VI1PR06MB4526.eurprd06.prod.outlook.com ([fe80::187b:196a:cb2d:adf1%5]) with mapi id 15.20.3477.023; Sat, 17 Oct 2020 22:06:09 +0000 In-Reply-To: (Drew Adams's message of "Sat, 17 Oct 2020 14:18:19 -0700 (PDT)") X-TMN: [CemxA6LE2T1hA4F8GEi8N0C3XG8w/vmY] X-ClientProxiedBy: AM5PR0301CA0035.eurprd03.prod.outlook.com (2603:10a6:206:14::48) To VI1PR06MB4526.eurprd06.prod.outlook.com (2603:10a6:803:ac::17) X-Microsoft-Original-Message-ID: <87ft6c5wz3.fsf@live.com> X-MS-Exchange-MessageSentRepresentingType: 1 Original-Received: from pascal.homepc (90.230.29.56) by AM5PR0301CA0035.eurprd03.prod.outlook.com (2603:10a6:206:14::48) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.22 via Frontend Transport; Sat, 17 Oct 2020 22:06:09 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 46 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: b76fd628-d660-4510-ea6e-08d872e8da65 X-MS-TrafficTypeDiagnostic: VI1EUR06HT181: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GPI/YdVG3UQotQ6kLe6FxpqKqMLd0Z8ZuSn59K+V40ny5MhTN/5h8veaAXpaKZbi3tIPUVdoYb/KK/PG3/P20gZWyF3BpkxnX4emXdQ1Umr34hPevpXnxxwUGL4j9Ccx9hsNvbdO7s3TufEEeS/VTFjDL3ExjOOd9XntPIps2RXKYW56hRcxkYtasNMmQQmoCDFFmvT+bGNTxY1AqptFdg== X-MS-Exchange-AntiSpam-MessageData: WWmULFjM1Czk8PWGSDQnQzcimSNgzOhlIM2ZClkHdeiYbUb9hHRTQrunN6YqOHeK3gFaWJq9E2zvm9Yp8lbjVtrDnabNm+2EnnFKsiWWw/Gyd+GSwmdUxBb9gznzA3bES7+3kNc7sjdTgUrxoiOxSQ== X-OriginatorOrg: live.com X-MS-Exchange-CrossTenant-Network-Message-Id: b76fd628-d660-4510-ea6e-08d872e8da65 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Oct 2020 22:06:09.8394 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: VI1EUR06FT034.eop-eur06.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1EUR06HT181 Received-SPF: pass client-ip=40.92.17.96; envelope-from=arthur.miller@live.com; helo=EUR06-VI1-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/17 17:02:35 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] 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, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:257978 Archived-At: Drew Adams writes: >> > Sorry I'm coming to this late. It's a long thread, >> > and I've only checked your patch, not the messages. >> > >> > I don't understand why we would do this. Is the >> > real aim to be able to have an empty-directory >> > predicate, i.e., to be able to see if there are >> > no files in a directory? >> >> Yes. >> >> > If so, then why not do just that, without >> > bothering (changing the signature of) >> > `directory-files'? >> >> Because it is not possible to that efficiently with current elisp; how >> would you do that directly? OS does not have such call, one have to >> iterate through directories. At least I am not aware of such call. If >> you know, please tell me, I would be happy to use it, at least for myself. >> >> Fastest I am aware of is to get a buffered list with SYS_getdents and then >> check for first non-dot file. That changes complexity from linear in >> number of files in directory to constant (3 files at max). It works only >> on Linux kernel, and I don't know if there is nt version of such call, >> or what there is on macs. >> >> I suggested such predicate, but to not re-iterate entire discussion, pls >> check my first mail and followed 2 or 3 I think. > > I took a quick look at the first few messages etc. > > I see that Eli suggested not implementing an > empty-directory predicate directly but instead > adding a COUNT parameter to `directory-files' (Lisp). > > That's just what I questioned. If the aim is an > empty-directory pred then why not code it in C, like > we do `directory-files'? And instead of duplicating > code, if that would be the case, extend the C code > underlying `directory-files' to be usable also for > such a predicate, stopping as soon as it finds one > file. > > IOW, what you've done, but not expose the COUNT > parameter to Lisp. If its real purpose is just to > check for emptiness, then from Lisp I'd think we'd > have a separate predicate for that, and we wouldn't > change the signature of `directory-files'. > > UNLESS there really IS some use for a COUNT value > 1. > > That was my question. If there's some use case, in > Lisp, for COUNT, i.e., for returning the "first" N > files, then fine. But if not, I don't see why we > would add COUNT to `directory-files' (Lisp), as > opposed to just getting the emptiness check from C > (perhaps by adding a COUNT there, but not changing > the Lisp interface for `directory-files'). > > Not a big deal. Just a question; just something > that occurred to me when I saw this. I think a > Lisp user is likely to ask herself the same thing: > apart from passing 1 for COUNT, why would I ever > use COUNT? > > And if it were agreed that there's no use case for > COUNT > 1, but for some reason a separate predicate, > `directory-empty-p' isn't wanted, then change COUNT > to a Boolean parameter that just says you want an > emptiness check. > > If COUNT > 1 has no utility then, if you have to add > a parameter for Lisp, its name, doc, and behavior > should at least be more indicative of its purpose, no? > > Don't get me wrong. I'm generally in favor of Lisp > Boolean functions and such that return useful non-nil > truth values. I _really_ like that. But here I don't > see the usefulness of the non-nil return value, which > means the thing will confuse and mislead sometimes. > >> > Is there really some use case for getting only >> > the first N files in a directory? I can >> > understand wanting to test whether a dir is >> > empty. I can't see why someone would want the >> > first N files (however "first" might be defined). >> >> Probably not; it is just a result of having count parameter. > > Should be the other way round, no? We should have > a COUNT parameter only if it's useful. If we're > adding it just for implementation purposes, then why > not just do that under the covers in the C code? > > Anyway, I don't mean to belabor this. I've asked > my question and clarified why I asked. Yeah, sure; I completely buy your reasoning. When I think of, one user case for COUNT is maybe if a user have some kind of limited structure to fill and just wish to taken N number of files. I don't know if that is very common in Elisp, it's not directly a system programming lang, so I think it is an artifical example.