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: Making ielm behave like a shell (getting to previous commands using the up-arrow key) Date: Fri, 18 Dec 2020 09:14:10 -0800 (PST) Message-ID: <5f8911eb-b20c-400e-86c6-a6ea6ca3d437@default> References: <87im91ys4m.fsf@web.de> <874kklyqi2.fsf@web.de> <87im90dq2s.fsf@web.de> <87mtyb32ud.fsf@web.de> 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="2771"; mail-complaints-to="usenet@ciao.gmane.io" Cc: help-gnu-emacs@gnu.org To: Jean Louis , Michael Heerdegen Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Fri Dec 18 18:16:28 2020 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 1kqJMg-0000bI-PS for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 18 Dec 2020 18:16:26 +0100 Original-Received: from localhost ([::1]:46690 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqJMf-0000JU-RT for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 18 Dec 2020 12:16:25 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:57788) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqJKe-0007fQ-CZ for help-gnu-emacs@gnu.org; Fri, 18 Dec 2020 12:14:20 -0500 Original-Received: from aserp2120.oracle.com ([141.146.126.78]:42938) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqJKc-0000DZ-0g for help-gnu-emacs@gnu.org; Fri, 18 Dec 2020 12:14:19 -0500 Original-Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0BIHDo16028323; Fri, 18 Dec 2020 17:14:14 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=mime-version : message-id : date : from : sender : to : cc : subject : references : in-reply-to : content-type : content-transfer-encoding; s=corp-2020-01-29; bh=LYA2Y9klACSR+bh2d0nimwizm5masjkQvnM1zOifjus=; b=Wpmex1s8n9aLnpFRjC4idf4u9cFl0kC1MzamwvYqWeE7lia7T4b5SShmUi11fNZrI3ye T0/B0xlYQ+2gFWk2KXii5V5HGfkgUkAaoQgDP2oKwi8fdnyPlggfI3IQjmklIrhdf0yT AUHxiu1R6Xd8NWKvyFcGBA/4G16D2ma0yeCsuqOgD/Nmk3aup8XZCuNxxx+DGMHtNO4x He4pvNiHKAtKnHpSbOtW2m1/R4oVchObQdgXacbE/h2Z1oDbWBYJ/HxhxSuDO+CgtI3d zZER7FipETTMNe4x7+VgLCl3lpvxb5YlQaHwUn4XLgNUGZwCTrMISK+fGI8LX0y/MygX 4w== Original-Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2120.oracle.com with ESMTP id 35cntmk8kr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 18 Dec 2020 17:14:14 +0000 Original-Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0BIH5a7R143806; Fri, 18 Dec 2020 17:14:13 GMT Original-Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3020.oracle.com with ESMTP id 35g3rgdssg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 18 Dec 2020 17:14:13 +0000 Original-Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 0BIHEBJv011890; Fri, 18 Dec 2020 17:14:11 GMT In-Reply-To: X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9.1 (1003210) [OL 16.0.5071.0 (x86)] X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9839 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 malwarescore=0 spamscore=0 suspectscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012180116 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9839 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 phishscore=0 mlxscore=0 lowpriorityscore=0 spamscore=0 adultscore=0 malwarescore=0 suspectscore=0 mlxlogscore=999 impostorscore=0 priorityscore=1501 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012180117 Received-SPF: pass client-ip=141.146.126.78; envelope-from=drew.adams@oracle.com; helo=aserp2120.oracle.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: 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:126511 Archived-At: > First step: >=20 > (let* ((mailing-hash (rcd-db-table-id-hash "mailinglistoptions" option *c= f*)) > (mid (gethash 'mailinglistoptions_accounts mailing-hash)) > (mid-hash (rcd-db-table-id-hash "accounts" mid *cf*)) > (accounts-hash (rcd-db-table-id-hash "accounts" mid *cf*)) > (email-list (rcd-email-list mid)))) >=20 > Second step: >=20 > (let* ((setq mailing-hash (rcd-db-table-id-hash "mailinglistoptions" opti= on *cf*)) > (mid (gethash 'mailinglistoptions_accounts mailing-hash)) > (mid-hash (rcd-db-table-id-hash "accounts" mid *cf*)) > (accounts-hash (rcd-db-table-id-hash "accounts" mid *cf*)) > (email-list (rcd-email-list mid)))) Nope. That raises an error telling you "`let' bindings can have only one value-form". FYI, that `let' has an empty body - it has only bindings. That's not an error, but it might let you know that something might not be as you hope. More importantly, this "binding" is erroneous: (setq mailing-hash (rcd-db-table-id-hash ...)) A `let' binding is either just a symbol (implicit binding to `nil') or a two-element list of a symbol and a sexp. That "binding" looks at first like it's binding symbol `setq' to the value of variable `mailing-hash'. But the list doesn't end there - it's not a 2-element list (which is what the error message tells you). If you intend to use `setq' to assign a value to a variable, instead of let-binding it, then move the `setq' to the body of the `let'. CAN you use a `setq' or other procedural code inside a let-binding? Sure, if you want to. Just provide a variable to bind to it. (let* ((fred 42) (_IGNORED (setq fred 'nope-24)) (_NADA (message "FRED: %S" fred))) ;; Empty body, if you like ) (Nothing special about the variable names. But an underscore prefix is sometimes used conventionally to tell human readers that the thingy isn't really used or isn't used in some particular way. Here, I use it to tell myself that the variable is used only to be able to evaluate some sexp for its side effect. And I use uppercase just to make this weirdness more obvious to myself.) You can also bind the same variable multiple times, if you like: (let* ((fred 42) (alice (foo fred)) (fred (if (> fred 0) 24 'derf)) (fred '(nah dont-do-that at-all))) (message "FRED: %S" fred)) IOW: You can put any kind of procedural code in a `let' body or a `let' binding. If in a binding, it needs to be as a sexp to evaluate and bind to some variable. You can use multiple, sequential bindings for the same variable, if you use `let*'. You can also use the same variable name multiple times with plain `let', but that's typically useless and not what you intend. (let ((fred 42) ; Not used anywhere (fred '(nah dont-do-that at-all))) (message "FRED: %S" fred)) > Third step: >=20 > (let* ((mailing-hash (rcd-db-table-id-hash "mailinglistoptions" option *c= f*)) > (setq mid (gethash 'mailinglistoptions_accounts mailing-hash)) ^^^^^^^^^^^^^^^^^^^... Same problem as above. > How would you do message calls there? See above. Put any procedural code you want to use in the bindings part into a binding: provide a var that you use or don't use, binding it to the code you want to evaluate for its side effects. Is this kind of thing great style? Maybe not. But you can do it. Being able to add `message' calls wherever you want can be helpful. Whether to use multiple `let*' bindings for the same variable, versus the alternative of using multiple `let(*)' forms, is a question of style and how you want to work. Coding is not only about the final result; it can also be about intermediate forms that are easy to work with, that talk to you, or are otherwise convenient (for you) in some way. Another thing you can add, as an alternative to `message' calls, are calls to `debug'. Those are essentially breakpoints. They let you know which branch of code gets executed, opening the debugger when encountered. (let* ((fred 42) (_ZIP (setq fred 'nope-24)) (_NADA (when (toto) (debug nil fred)))) (unless (titi) (debug)) ;;... ) `C-h f debug'...