From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] * src/eval.c: Stop checking for nvars, and use only CONSP Date: Tue, 02 Mar 2021 18:48:12 -0500 Message-ID: References: <20210302.111043.609653289571449353.conao3@gmail.com> <20210302.120929.1656994339284323372.conao3@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25262"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: Naoya Yamashita , emacs-devel@gnu.org To: Pip Cet Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Mar 03 00:49:10 2021 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 1lHElK-0006U1-GH for ged-emacs-devel@m.gmane-mx.org; Wed, 03 Mar 2021 00:49:10 +0100 Original-Received: from localhost ([::1]:52146 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lHElJ-0000vY-DH for ged-emacs-devel@m.gmane-mx.org; Tue, 02 Mar 2021 18:49:09 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52322) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lHEka-0000UT-73 for emacs-devel@gnu.org; Tue, 02 Mar 2021 18:48:24 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:47371) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lHEkX-0006fW-OV for emacs-devel@gnu.org; Tue, 02 Mar 2021 18:48:23 -0500 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 72E5A80533; Tue, 2 Mar 2021 18:48:19 -0500 (EST) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 99C2880712; Tue, 2 Mar 2021 18:48:13 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1614728893; bh=fMBT/s+d6Ed37xwt2mDHfPn+swmtbHQY4nz1xb5Jci0=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=GyIA0lZt7zSg/k4mZJ1Xv2tpbkGyPlXcWhTMnFCEuDIIy3PbQfOKQSMEGAcqN3/uw /dwyohLj7OgD0MYSK5HHOSPCKZTrJZ/1znbOyBDmgN2kqgmoT1lzY4E17Vvwpip1/5 HbLrZYX2AKRg9ah8bEGlrgMoJdd5uwx/dm6JcM3mXl5/dOKGoXkHkaMKtqPJTqA7ZX YmQJWvoOE0MfmbYYBcD1spkdIbphlc++alM34ufPZF3Dn66Xl+TxwkMxDW7r+gGdV0 vCZ1T/BzVvLKzwWivo9Ky5W5UyQR6livvrvMYCB+kRTwVJdo/Vlvq9tQB7uCNbMYIx Px/0TTY1vGx8g== Original-Received: from alfajor (unknown [216.154.41.47]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 2B052120310; Tue, 2 Mar 2021 18:48:13 -0500 (EST) In-Reply-To: (Pip Cet's message of "Tue, 2 Mar 2021 19:50:23 +0000") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=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:265848 Archived-At: >> That would mean just replacing the `Flet` in C with another in ELisp, so >> it would largely just move the question (which is about diagnosing >> invalid code). > Two advantages: A macro can be redefined and have its redefinition > apply to compiled code; and, if let were implemented as a macro, other > letlikes would have a starting point. I'd be happy to have a "low-level" `let` and then macros on top, yes. But some kind of let-like thingy at the lowest level is largely unavoidable for practical reasons (falling back on funcall+lambda is cute for the theory, but to get acceptable performance you need to treat that combination specially). > For example, I'd love > > (traced-let ((a 1) (b 2) (c (throw 'out nil)) (d 3)) ...) > > to work (and print "a = 1 b = 2 c = "), but every time I > need it it seems more effort to write than just to debug things the > old-fashioned way (did I mention it's my non-integral birthday?)... I can't see any trouble defining such a macro nor in which way it's influenced by whether `let` itself is a macro or a special form. > I think this applies to debugging invalid code, too. What do you mean by "debugging invalid code"? > I do wonder why other languages have moved to the equivalent of > > (defun f (a) (letq x 1) (+ x a)) > > or > > (defun f (a) (+ (letq x 1) a x)) I find this horrible, like Scheme's `define`. The semantics of such things tends to be quite intricate. I think what I find ugly about it is that it means an expression affects the set of variables bound in the surrounding context. > What seems particularly problematic to me is that other languages can > emulate "let" easily, but implementing "letq" in ELisp is...an > interesting exercise (i.e. I tried and failed). You can emulate it with a new macro `progn-with-lets` which looks for `letq` in its body. It's an interesting exercise, indeed, and its complexity is a good part of why I dislike such features. > So those are the emacs-devel-relevant questions: Can you implement > letq in ELisp? You can, but by its very nature it can't be implemented "as is": it has to be done within the context of some other element (like `progn-with-lets`). > And why does it feel so wrong in ELisp when it's how > most other languages do this? Basically those other languages define their functions (and other forms) to take bodies implicitly wrapped in `progn-with-lets`. > For bonus points, make > > (defun f () > (letq g (lambda () (letq-in g g-counter 0) (letq-in f f-counter 0) > (incf g-counter) (incf f-counter))) > (cons g (lambda () f-counter)) I'm afraid I have no idea what this code means. [ I must admit, I'm not familiar with your "most other languages" ;-) ] Stefan