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: Noob question: why sequences, lists in particular start at index 0 in Elisp? Date: Sun, 08 Nov 2020 17:04:44 +0100 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3325"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Nov 08 17:05:58 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 1kbnCX-0000kK-Sm for ged-emacs-devel@m.gmane-mx.org; Sun, 08 Nov 2020 17:05:57 +0100 Original-Received: from localhost ([::1]:48020 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kbnCW-0003Yh-Vt for ged-emacs-devel@m.gmane-mx.org; Sun, 08 Nov 2020 11:05:57 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:40188) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kbnBT-0002yM-T0 for emacs-devel@gnu.org; Sun, 08 Nov 2020 11:04:51 -0500 Original-Received: from mail-am6eur05olkn2097.outbound.protection.outlook.com ([40.92.91.97]:2401 helo=EUR05-AM6-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 1kbnBQ-00062P-OB for emacs-devel@gnu.org; Sun, 08 Nov 2020 11:04:51 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Z5vzvKVp0DORi7xtEp/7mClyGdLOK89X80oMuisJEqkiiExBRzFwjgpxJmUSZuCBkv5ulS/F+Rc/qRiN3n+tXQDoqAZbamhmDjMh3lqHTNeKCJYtSGnABzIqfTROk72rf0XhW7rH/2UMU7J4l4w8Ou6LuQ/PR5asBD3kTrKImPVznF9Q8/9SjykxB6fSvR20cR+uD+Zti7pnLKwfa9X17bm/jabPd76DdaNb4/HFRWB+kztnqg9t+i3mjZit1fZQ7TtvPqYRLSctUwqlGCb2x3biFwH1aBlrkpoXFulNhhhn3arEkmcuZVPc1DZeLjU0LajMQU8E19043nRjFDPTvg== 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=M5lmhZmLToDBT8LEG1QoOR03EFmivFtCpgXnLil7OKM=; b=GJTCWSNV65KbQ1auLFpkJUWVGUHm/Q5reeheeG+noV/H6mxano6xijkYIO+Wfrg/NL0Lcvx86aAWO0VasaaBNJndHOKOjrZWWcUY5FP8MGuIiuos+v13/8crgfBbKy54ZOlcn0j/AeRSeaAb2HppD7gTRNONIdOpbKFQSAYlvlOuW6lAEzkOAGtg6NUhD0I5BHmXZ29mj0r1KasF4+13TUTbonikHPS/LVY72KWP0bfWb2Oss2x1f85tRjgj5soCfxQUlcaBDGWJcieh30StB9uDa3s/KkyDfPP1zVwraje9g7IKKvP19qJygz5Tmoj+kgbTAKK5RrQeXWCJy33EwQ== 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=M5lmhZmLToDBT8LEG1QoOR03EFmivFtCpgXnLil7OKM=; b=JdoPnK9TtzqFxal3LMlkcVgehECv3oPzW1j7NZkrAvIgOTIVmpR97i7wJLWD6x7Y/DDpxYmZImdnZv72rHmZ7qPygqvDUoTm0beGxlJJUbcxdO4FyBak6N4YZaL3jV5AiVsk0f+ypstYhAK0lzYrvE7NzCbm77h62Whfm0V6npl/7Aln4RuP9ZV1YEqssDw6/WGuE9Z9X2+Ys7d6+R5pHSy82kEey3xg2wLE/xz8m5CteUW/vH6Ujf2IBv+d0PfcrUhv+Uh6oNVuYQQP7/NqpiCY497nkbL6ScPPUVGSa8b5On0RPvS1++WBOWpj8i6uUQLX8QLfURq0E7cFbN747A== Original-Received: from DB8EUR05FT054.eop-eur05.prod.protection.outlook.com (2a01:111:e400:fc0f::51) by DB8EUR05HT102.eop-eur05.prod.protection.outlook.com (2a01:111:e400:fc0f::265) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3541.17; Sun, 8 Nov 2020 16:04:46 +0000 Original-Received: from VI1PR06MB4526.eurprd06.prod.outlook.com (2a01:111:e400:fc0f::4e) by DB8EUR05FT054.mail.protection.outlook.com (2a01:111:e400:fc0f::111) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3541.17 via Frontend Transport; Sun, 8 Nov 2020 16:04:46 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:D2FF9D0AA9BA02613BD24D87E9ADA5F6D4FE27CF00E72BE917C906A7424574A6; UpperCasedChecksum:624C00E24B9C6A07A925B77E1C99648EEE208E63C2D3B0BD6C03214AB2D050DA; SizeAsReceived:7519; 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.3499.032; Sun, 8 Nov 2020 16:04:46 +0000 In-Reply-To: (Stefan Monnier's message of "Sun, 08 Nov 2020 09:42:42 -0500") X-TMN: [qkWNk22p/P1Ll7VUpy9VyLgZ30R2wICz] X-ClientProxiedBy: AM6PR04CA0011.eurprd04.prod.outlook.com (2603:10a6:20b:92::24) To VI1PR06MB4526.eurprd06.prod.outlook.com (2603:10a6:803:ac::17) X-Microsoft-Original-Message-ID: <87mtzrbzs3.fsf@live.com> X-MS-Exchange-MessageSentRepresentingType: 1 Original-Received: from pascal.homepc (90.230.29.56) by AM6PR04CA0011.eurprd04.prod.outlook.com (2603:10a6:20b:92::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3541.21 via Frontend Transport; Sun, 8 Nov 2020 16:04:45 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 46 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: cb6cfdc9-f33d-4a17-f443-08d8840002ea X-MS-TrafficTypeDiagnostic: DB8EUR05HT102: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4ct4rVAL6WHCEiZaR+VfCbSk7H0gNald+BVQ5BnsN6vQl3Ff+fBMxFDhCV5xchmMhmsh/+PQmNTPZAIZjVCMWwin+IG6iRrvf1ilmkZlt6B49QwLk2rRX6FoGgdSecb0kdgUyiaOtJfQDW4tpUxCGI9BkGtNCvv7pg4f9Z6iV+J8YD5D3WYW7MxS9NowEOxu7MtnK/5p4pMhWGcBFcu/jg== X-MS-Exchange-AntiSpam-MessageData: 11t6k7gzo/rYtVu4j80lQCBIPAJhHXZgnU0fNJSdXnirTjujJ1mIS/N2e6fUrOFLhSgE9xoIdnsnorcvCad8AtE8NGpdlrxQppUFys/8XcWKVs5MetmLgouRyl7wZv51jlqCMDT9zNOjBwwsL+BjEg== X-OriginatorOrg: live.com X-MS-Exchange-CrossTenant-Network-Message-Id: cb6cfdc9-f33d-4a17-f443-08d8840002ea X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Nov 2020 16:04:46.2800 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: DB8EUR05FT054.eop-eur05.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: DB8EUR05HT102 Received-SPF: pass client-ip=40.92.91.97; envelope-from=arthur.miller@live.com; helo=EUR05-AM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/08 11:04:46 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:258908 Archived-At: Stefan Monnier writes: >> I understand why they do so in C; but why in Elisp? > > Why should it be different in ELisp? Because ELisp is not designed to be machine-close language easily implemented in almost a one-pass compiler that translates it's references to memory addresses directly? I am not sure it even makes sence for C; what does it save? An extra addition? Is it worth? But more because we humans thing in terms of first, second, etc. Algorithms look much nicer when we can write [1,length] instead of [0,length-1]. I could even find Pascal indexing to be useful sometimes. Numerical Recipes had nice practice for their code; they would type pointer-- on base pointer so they could write algorithms as in [1,length] (and yes I know they abandoned the practice in C++ edition). I have red Dijkstra's paper on the issue from 1982, and I am not sure I agree. He writes: "the subscript range ( ... ); starting with 0, however, gives the nicer range 0<= i < N". Well, yes; but only when iterating so we can write i < N, instead of i <= N, or i != N. Yes he derives it from the mathematical notion of smallest natural number; but then is 0 a number? More important does it really matter? When accessing the element in subscript one has to write array[N-1]; so I am not sure that is so much nicer then to type i <= N. As I understand, that is his main argument, and I don't think it is strong enough. Actually I think it is more practical to use [1,N] then [0,N-1] in a higher level language. Yes, we can also just define something like "first" and "last" in our program; but then it is just our "local" convention, which opens for missunderstanding and misstakes. If it is supported on the language level, then users of that language should have it as a rule, rather then just a package convention (opposite what Dijkstra argues in his paper). > AFAIK, indexing should always be 0-based, so we don't get into silly "is > 1900 in the 19th century or the 20th century". I am sure we can construct examples that support both arguments, since bot versions make sense in different scenarios. > And indeed computer > science got this mostly right, I dunno what to say; I am probably too pragmatic to support statements of kind that there is always one right way. I find it a bit dogmatic to say computer science got it right. > except for Fortran arrays and > Emacs buffers. Njah, I prefer moving to first line, not 0th line. I would refer to Monnier's first paper, not 0th paper, I would probably direct someone to first street to the right, not the 0th street. No? Please, forgive me if I am annoying; I am just trying to understand it better. Personally I think that higher level languages should probably be closer to natural language and human reasoning, while assemblers or maybe a language like C, very close to machine should probably be closer to the machine.