From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.help Subject: RE: [External] : Re: Lexical vs. dynamic: small examples? Date: Sun, 15 Aug 2021 00:29:50 +0000 Message-ID: References: <4a9bddb9ec57299b3b0c@heytings.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15492"; mail-complaints-to="usenet@ciao.gmane.io" Cc: help-gnu-emacs To: Gregory Heytings , Eduardo Ochs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sun Aug 15 02:30:47 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 1mF435-0003od-O9 for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 15 Aug 2021 02:30:47 +0200 Original-Received: from localhost ([::1]:37716 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mF434-0005aU-2p for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 14 Aug 2021 20:30:46 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:59304) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mF42L-0005Zj-Vc for help-gnu-emacs@gnu.org; Sat, 14 Aug 2021 20:30:02 -0400 Original-Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:34128) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mF42J-0006f5-HY for help-gnu-emacs@gnu.org; Sat, 14 Aug 2021 20:30:01 -0400 Original-Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 17F0HasO001122; Sun, 15 Aug 2021 00:29:57 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=corp-2021-07-09; bh=jrBLcwoj3ixVAIbYZZ4timWtK24UCyXimlTh3+bhuXM=; b=nxpnHxJ4Y3wIs2RCR5Y1GqHVSbEG7uml/QFARqWr2/HpOxMsBUeU0HluaD1IZBF6IAw1 5tk03OTp4uqjGZ1Ae8WpfVYrz7ivlEDVXwmTrzRL0HvEaY9tzGWfsfYGbUTYgJpzQnpi JnDSPy8aV1KPpTP/wZuDca6a9thlqGlVdl/ovlFvj1IOSJP2kwQfe2DyH80WjBSSP0VF bamxkTABIk43dYXp5XhvyoxJ5R74Q3gkJKgSsFmIhGw/fMDyK3GslGLv89zIGQ9XpjWH XqpJ+3seh4cte3fncK4YoC6J1pq96vIzByk5LFPMBQY4n1vVOA2iJDKvcsYg64LLnvXJ sw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=corp-2020-01-29; bh=jrBLcwoj3ixVAIbYZZ4timWtK24UCyXimlTh3+bhuXM=; b=G9KL/NqTkW+/rb9e8S3JgEPw7A5mmsmqfWzMHlmjBue70tQiCVlJruSliL+EPAKjpMBt 0SmYqZfIqJuVvembU3QMnWkvek+qlLiCACAZnRxUXLs8YV6hJnIzRyvIU6UeJBQvFH0i BYXsj+sweE5nr5ZhYCXz03rtW4Jg7NtFP/LChxqjsx4zyXszAKICiDinsFGGKzutIQAR lOdvmlQVm4lQhZqpnGzbrFAYh3DAYk9NiY5KJ614RwYASnzGvpS1sPInitq9z0iGQj3K +5oeMBKyNMHfZuwRdTkZCv7n9PMwBh2FtlCHst+sylsI4RRGRKEAlnS+y70+PM4PZ617 3g== Original-Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by mx0b-00069f02.pphosted.com with ESMTP id 3ae5es9gyq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 15 Aug 2021 00:29:57 +0000 Original-Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 17F0GMCv151679; Sun, 15 Aug 2021 00:29:56 GMT Original-Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2174.outbound.protection.outlook.com [104.47.57.174]) by userp3030.oracle.com with ESMTP id 3ae2xusrka-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 15 Aug 2021 00:29:55 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TvPlz2pUPNqdZPF2mS5CXLTokKg7MUal6dwqLxTOjviMg7Y+o5CfuruPf2a8YMTGX6fpQ6Be9szuFXHeqX0CPLyoRirBlfhJloM0ZJnXPMQVECo5Sw2maNhykl92UkxnOR4nHGY6MeRQAnbEHSLw4EmypstzU0ir7bs/Uru7g56hJ7MQW55cnDG6ZaiSa7bRXhBrPDuRyLqv4YC0vAkOFemiL5kPA+vx75LkHpVJ2uRiuZG+4ldhXyWh3K7M3pBC5BUCmkw6Vaw3ZgcSDfLeIftVUVJSVgDjR16Yl7L6NUUsP819Nk81Xn0D/XeYfQwB5VD2lh+tRrC4W2CBWrtyRg== 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=jrBLcwoj3ixVAIbYZZ4timWtK24UCyXimlTh3+bhuXM=; b=NuDO96MYEXnDd0vSl2nMGYiYXGLaROOo2/sPxOrlNbEIllFIxdWWQ/CGV0Rz7zU2bxkaeUHCZLXf6iO8/rRAVh6vo+ocDK4UlkAZRnqm+CNjWHHyh/6N463gSn90wLPWY5ghUGUw7YtfQkJJuPfNZqZtaHHX4OC2yqksbE+jZj92ajRzPUFYM+yXaJqcBnw1hK+y0AEFU5VnZ8H+giUql7Ox7D3+0aBBJwfpLzcSrNt/LdV5nC4b8cx7TI6Bb3Bad+ttR2Evkzk27cmSMZiESHE56V6IRJYLy9ATPmdD81Vi/LpdVMQonHLF4e8tAq5vpALAM+5g81MBSvbnpO4Y1Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jrBLcwoj3ixVAIbYZZ4timWtK24UCyXimlTh3+bhuXM=; b=iYLdNRwl+05zaBmhdsa02Y6mtgzpQO9Ux4vfRvyhuUmR4aztR+Gbi85OKxhmHWDPp87UKdP5g8zl13wBP+EAmXI5pCpV72eRWJl3dgVbBlVv2YMil56HXrhmG2fVw2FMiVc/DDNik6V8aPdv9VOskbkzSxdumHc+TXhqWA0a2UM= Original-Received: from SJ0PR10MB5488.namprd10.prod.outlook.com (2603:10b6:a03:37e::19) by BY5PR10MB4209.namprd10.prod.outlook.com (2603:10b6:a03:207::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4415.14; Sun, 15 Aug 2021 00:29:50 +0000 Original-Received: from SJ0PR10MB5488.namprd10.prod.outlook.com ([fe80::a59e:fa26:ffe4:615b]) by SJ0PR10MB5488.namprd10.prod.outlook.com ([fe80::a59e:fa26:ffe4:615b%3]) with mapi id 15.20.4415.022; Sun, 15 Aug 2021 00:29:50 +0000 Thread-Topic: [External] : Re: Lexical vs. dynamic: small examples? Thread-Index: AQHXkT6xRQieoA3LxUyKw5hTggVFjKtzrLog In-Reply-To: <4a9bddb9ec57299b3b0c@heytings.org> Accept-Language: en-US Content-Language: en-US authentication-results: heytings.org; dkim=none (message not signed) header.d=none;heytings.org; dmarc=none action=none header.from=oracle.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 09b459bf-2555-4c8c-cb71-08d95f83cb48 x-ms-traffictypediagnostic: BY5PR10MB4209: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:10000; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: gYaF0FSKd7sZpWaCbFvH2SYsyvu85BinWXIwwaFrWpNATi3maLTQWyVQBM02PsIFRhLkXss2io3oIDXG0p0MLjZcrglDkd0mOerQNjjimo0E03wMIl0j75U/d3MX+J9v6WmiNnY4DOcp30bXEJCqlrtVZukq4knz7/7XjkQGOy2DX6/Ap00eLq4gIyhNr994VyUqvE8+uOfTYbVyEPuvT4vzijkpjjunZB4gIy6DOoO9s9zF7CFCBiOkPFcDJqp+1qczvVp1DzPb7FHCmuUp8MocFt2zVU3IOL0IquxjDufJue7CzReexnvJF+OF6IOwktw755CC416kY3fWL1JGLJTfELwutqi1T/cSO066W3ps9Y6k8bsH+oFpkgbVPpxTI3ePN/af25yGj1mz0rB3gM5HSmtEIgZHIGLPb4guVSV3ujzhIf6Ssg4FpcLyBjv5cg+Si2xokG3o2EWINf+24iRjOvEVtrNxZe3kn9sMRG6LOw6NJpifTkcY3KX2Dvos9+16/aKQqoFyJpVdKUhjFEir9358yfEO/1MzqpXZh2Lo/i600BXs/9EJ52T0/JmTohx/8wpjicAqY/H8j5hbvIpu993hEK6XaZm5pgw/z1wT8SBmpJwRd3Pjk9UTVRsX1Epa9ihu/r6oZSLqS+nGnV4KjApsZxKiKO6AhnXOq747qZg3darAazOFf1lGpqrwCnJBOt71ZJnpA0SRpSTWer9q3XrJaY5Y0o7XC2wQCVsalHN1QnS1GWpsYyRoQ bIHM1FS1wpW01+eRh52Urkgm/L2tww2ehhOLqcbV1ogyoo= x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SJ0PR10MB5488.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(376002)(136003)(346002)(396003)(366004)(39860400002)(83380400001)(6506007)(26005)(186003)(7696005)(55016002)(71200400001)(66556008)(76116006)(66946007)(66476007)(64756008)(66446008)(316002)(8676002)(8936002)(4326008)(2906002)(52536014)(110136005)(33656002)(38100700002)(122000001)(478600001)(5660300002)(9686003)(38070700005)(966005)(44832011)(86362001); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?3ehcKalyWJvAXhHcTHIG+41PLXXeqwjR4HFVV1Y2hP1PGSjpIeU2ZSibNCja?= =?us-ascii?Q?sjn3/+jPdv29OE2eLrRgE3ZjGdaTTYPpZjQJrLB3/t2Hscw9HP8CxrOcZ7NJ?= =?us-ascii?Q?1ncWLSBSn6FPmCz+AAHMzvnFVeibMinW7rtZ6NDBla1DTkGQEBpkZWNukLbw?= =?us-ascii?Q?OfDEOiexT1d4fbDs+tnHxXKmA+BjY7Fq2+q/RsjiCqCioIEjYBr0ZFefGEjk?= =?us-ascii?Q?UCtgBYdAbLJFNHEmVXzeri7mU/ydjzclf0IDZS8TnrxyQtYZJbBnrcg61WJi?= =?us-ascii?Q?D+A3qjKbjMVtnKmMqMpJ6EOGHrBubENiZ5K49RzNZmcD3HQCZfVZZrMkdNKT?= =?us-ascii?Q?p3xH70Qemq76axgKf/JM4RMDX5576ns2ix8nB7UihjuqGIziVAQowkKs0Mcs?= =?us-ascii?Q?ra/GkD58PPXpQHrU9AzAaN2uuagJvHvaDFLk0IjerOR3mQL3OwuwNNdyqdW2?= =?us-ascii?Q?6yV7J5/IqmFM8csdR987CZe07nvRDb4Du99Q3CR/Eb8Pwd/Pqs5Kq7LZzkq2?= =?us-ascii?Q?BznvVlE0Obu1k368vefNdQ2qd34G+gYr/mMETdY7smUBJ+6/gXMrc7f5wSaP?= =?us-ascii?Q?PAy3H1UaK6SXnTSqVcRaa4jAqAAplcQBb2qYMvN9PD0lkXcJ0asc8Zvf7OHo?= =?us-ascii?Q?vr x-ms-exchange-transport-forked: True X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB5488.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 09b459bf-2555-4c8c-cb71-08d95f83cb48 X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Aug 2021 00:29:50.4719 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: M81yo9w2UTKIIUY7EpQee6H5J3QsSXeV+ozog0aBey7dyKfUhl3t3JfhOOVjIjCnhKfeQO2CAkXsw3zBnUBBSg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR10MB4209 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=10076 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 spamscore=0 adultscore=0 suspectscore=0 phishscore=0 mlxlogscore=999 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108150000 X-Proofpoint-ORIG-GUID: QIIcehRz4Gq91pbXKDzvwour0MaA3FMz X-Proofpoint-GUID: QIIcehRz4Gq91pbXKDzvwour0MaA3FMz Received-SPF: pass client-ip=205.220.177.32; envelope-from=drew.adams@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -7 X-Spam_score: -0.8 X-Spam_bar: / X-Spam_report: (-0.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URI_DOTEDU=1.999 autolearn=no 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:132558 Archived-At: > Now if you M-x trim-whitespaces-at-eol in a read-only buffer, you'll get = a > "Buffer is read-only" error. Suppose you want to make that function work > for read-only buffers. If Emacs Lisp only had lexical binding, you would > have to alter the global "buffer-read-only" variable, that is, to do > something like: >=20 > (defvar saved-buffer-read-only) > (defun delete-whitespace-at-eol () > (interactive) > (setq saved-buffer-read-only buffer-read-only) > (setq buffer-read-only nil) > ... > (setq buffer-read-only saved-buffer-read-only)) `buffer-read-only' is a dynamically scoped, set, and bound variable. (It's also buffer-local.) What you did there was change the value for the dynamic extent of the function call. It's not defined by the scope of the function definition. All variables defined using defvar and defcustom are dynamically scoped. Same with top-level `setq', i.e., variables that are not explicitly defined in any scope, other that the top level. Same with frame parameters, faces, etc. - all essentially dynamically-scoped variables. Their values have indefinite scope and dynamic extent. "Dynamic scope" is a misnomer, BTW; it means only that - no particular scope and dynamic extent. See the very good explanation in CLTL: https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node43.html#SECTION007000000= 00000000000 Common Lisp calls such variables "special" variables. Wrt usefulness: if you've ever used user options or defvar variables, or frame parameters, or faces,... then you recognize their utility. Now try to imagine Emacs, as a flexible, dynamic user-interaction environment/lab _without_ dynamic binding... > This becomes much simpler with dynamic binding: > (defun delete-whitespace-at-eol () > (interactive) > (let ((buffer-read-only nil)) > ...)) That's just a simpler way to do the same thing. In both cases, it is the globally visible (buffer-local) variable whose value is changed for the _duration_ of the function call (unless something else changes it in the meantime). `let' binds the global variable (which, again, happens to be buffer-local). That's how `let' behaves with a "special" var. Otherwise, i.e., for vars that are not "special", `let' provides a lexical binding - the scope ends where the `let' ends, lexically. Dynamic scope/binding means variable name capture is always an inherent, potential problem. >From the CLTL chapter on Scope and Extent cited above, remember this: "A reference by name to an entity with dynamic extent will always refer to the entity of that name that has been most recently established that has not yet been disestablished."