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: Why is defun not executed during load-file? Date: Mon, 31 May 2021 23:41:16 +0000 Message-ID: References: <87k0nfesns.fsf@zoho.eu> <87mtsbd31w.fsf@zoho.eu> <87a6oad81r.fsf@zoho.eu> 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="8840"; mail-complaints-to="usenet@ciao.gmane.io" Cc: "Help-Gnu-Emacs \(help-gnu-emacs@gnu.org\)" To: Emanuel Berg Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Tue Jun 01 01:42:09 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 1lnrXs-00028p-CA for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 01 Jun 2021 01:42:08 +0200 Original-Received: from localhost ([::1]:39948 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lnrXr-0004GP-E9 for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 31 May 2021 19:42:07 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37720) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lnrXA-0004GH-CU for help-gnu-emacs@gnu.org; Mon, 31 May 2021 19:41:24 -0400 Original-Received: from userp2120.oracle.com ([156.151.31.85]:38654) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lnrX7-0002OZ-PB for help-gnu-emacs@gnu.org; Mon, 31 May 2021 19:41:23 -0400 Original-Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 14VNdlfj174133; Mon, 31 May 2021 23:41:19 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-2020-01-29; bh=F3M9NBNa+AAMqCqcGaxIIgzbkpk2Q0vELRg8HQYfMtY=; b=di3RjikmaPzX78YbOrEC9KUC/IcKq8Ji8fi4wot0u220O1ITQUtwLkZIMjeq2WZcXBOl qFZ3QhDYZchOWacNwZI7be82p9HigrkRIdMzjktS5Gsm0GtXM18K4GYEm8FmEPP3Gs/z q0TnFQDQbBGpu2fgEJ/8ZE884QXoK2Ds92T6ICr6UVinYwawSPYVU7TsAXoE0AIkcU3w Pc+Ogj9DjIci8PgMkPwcUFCEFdleVaiY8EJJRlcqJuQh5SPkEA5CohZKzeQ0rVhPmkJJ WXlJ497d6xw1PvDTPRQFXM6H9Fssi9h0tV7nt8UAA5Jx3+p0U38R41NYtjXy/4LDAfhW NQ== Original-Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2120.oracle.com with ESMTP id 38ue8pbwv7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 31 May 2021 23:41:19 +0000 Original-Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 14VNeZvA062497; Mon, 31 May 2021 23:41:18 GMT Original-Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2176.outbound.protection.outlook.com [104.47.55.176]) by aserp3030.oracle.com with ESMTP id 38ubncqa05-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 31 May 2021 23:41:18 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UHjYpfBQpEfUx3cdvPl6kv500JEHP97C78S3475z71pRnLaJpegSW3pXwFhcBWFceBUG1Qu5vFt3Pvd94ArzxkFl5sTfS5rtNhUgBsRfybuoBIw46V2QbxaMIOpYAaWuFm5O0j9zHrdbC6NNUITt9HgHDyBcSJcS+EJA2f1KWvEUOm7QLII9nlZCrBOCnZSygM/4nJGNy50JjtOUw9nCo+ykZHfFcw0jBRHXo+znHqlGQ/nB8rsJdPtx4VWIU5skcS+mdRu7AN+b4C3DGiYUe/LFqH3gkBBCddkPyDEsmx8Yc+TVoQbGjXV+1KsNFQgVhPoazivb03iCZKJHKLInVA== 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=F3M9NBNa+AAMqCqcGaxIIgzbkpk2Q0vELRg8HQYfMtY=; b=LC2ct0wxunZfTtemgAOs1bUTD4dph5SosDhIjziLkEajlNM+rMDkw3mwVGtCKS3DBWif7S29WWrDnxuMTPIPO7f860wE5WgyAbZn8Umk4vm3W29UcCramobuRN9dSfTsPewPw4CA6spw4hOHuVTm/EpPaFz9PqABHWXf1G45JYO45Lh/8kV/BAQ620p7eHBMfwLIuBVHhJ4jhUfi1AsFbvJUGCISW8p8h4u/t+iu1PdIAcEosc5eEtOkmKNm+W72yiT3o00ECku+m6cjuq14xavhX5wTUZ70rUdSeChL+qFopqpoGA8hz3a+hSQlKeVWhSgHK/Wh/80vFxGNbokprQ== 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=F3M9NBNa+AAMqCqcGaxIIgzbkpk2Q0vELRg8HQYfMtY=; b=B/K2K9a2zaoWt9w8OMx96CmgxdI2t02M3wc+f/mltkAHS/xiY1QQX+efHA5jp9v/WEcWlOXZIXq2hysXA70CKeUjmqDaM7duq/fiQV0u+JH2qkp9RK2+7rFcLlDeJ2suscGWdqoRyTJKAD+q9Tpvd7F3f+clRiTf60PLVcp/lXM= Original-Received: from SA2PR10MB4474.namprd10.prod.outlook.com (2603:10b6:806:11b::15) by SA2PR10MB4507.namprd10.prod.outlook.com (2603:10b6:806:119::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.24; Mon, 31 May 2021 23:41:16 +0000 Original-Received: from SA2PR10MB4474.namprd10.prod.outlook.com ([fe80::2109:9725:fd4a:6494]) by SA2PR10MB4474.namprd10.prod.outlook.com ([fe80::2109:9725:fd4a:6494%6]) with mapi id 15.20.4173.030; Mon, 31 May 2021 23:41:16 +0000 Thread-Topic: [External] : Re: Why is defun not executed during load-file? Thread-Index: AQHXVlIWFl3QGKJTnU+Y8Tcf4ITJ7ar+KsEA In-Reply-To: <87a6oad81r.fsf@zoho.eu> Accept-Language: en-US Content-Language: en-US authentication-results: zoho.eu; dkim=none (message not signed) header.d=none;zoho.eu; dmarc=none action=none header.from=oracle.com; x-originating-ip: [73.170.83.28] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 624947c5-b370-440f-3261-08d9248d959a x-ms-traffictypediagnostic: SA2PR10MB4507: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:6108; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: LD/VkLUkrZVEK6WdP6FqV1PqV5XLU/jqpeaaQynN7Ag3xYWUtnBEBaw6P0I5nG23RUFO089umaEmzyQtm6pb3qOMuriOx8cKLoK0A6PoFyxvenbs0jESIPn2kGR65goE0A7bREyAKITMndey9vRXydjrHyl01z5v/KgS5EOiGjiXo96rrOdbRV2ZRv55K6F8ZQeRG4nrAdN6Q2zI0e8yNl+GE0cKWlSurd5LTmrRLCHjKYvVKKACCH6wlIQZ0TPtoi6jZtaiUlBrodK8ODOOXxVRY4rmbWdzxfkSj2R4ysUM1izfQc1ip58PvYztABFVM3N9nX+PrTFstUjjRX1n3JjwNcdsyVGAqLdk8Xl5Uk+3UJelt3hJx2O927iXQlwzlZD6tPIu9AwG6PNAx1gZAZQgeC04eY/ZEYO/d4KUH+S3CpvShO9sOmpMC/dCNWmp4isTL2ricB2qILzyonaFnJjCypLLNiEQKWinEsDT7An+xVh71vMPX2xuIW0NLLXyIvgf5mpNpqslcVhEyte5Dw+TnkJVcUtsnTrbEAskNEhvsGweSqsMcRNfJk7Cbkf39e3hJMjpYsIiSSMeiQpevAFNaUBYJzyz7yDEd0GXJ4fyMzFYbUVGznRV7Of0OAlT9gfUCKOMdGMfTg2hqa/ZIE0Suu6DPXLFa86t092/p+5tHwsoryBYNmbcX/WS9PJIYtLzhP06sGnggww8Uhw/kMpW4pa9P/38Nzb56z1mHns= x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SA2PR10MB4474.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(396003)(39860400002)(136003)(376002)(366004)(346002)(122000001)(966005)(9686003)(83380400001)(33656002)(86362001)(66946007)(8676002)(71200400001)(2906002)(55016002)(8936002)(478600001)(38100700002)(6916009)(66446008)(64756008)(26005)(66556008)(44832011)(5660300002)(52536014)(66476007)(4326008)(76116006)(6506007)(7696005)(316002)(186003); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata: =?us-ascii?Q?0UAyO8XtaHDr1BlAoLGUYXKFprtHZhDr79MXyLIxyjOmYD43wlXLHTFaHctN?= =?us-ascii?Q?u1nGKwEPTeXWlQxJ4a5oyvagYOJwuJNTMBFK9jew8DYWJ1JaIEaL9Iao5SKJ?= =?us-ascii?Q?ENa0OzJ2rh40+0j8Y7n1TC16kVTJShVd7RZrKgIAQxHalxNUlf/zznAGI0YK?= =?us-ascii?Q?oQ6NePd8dJ04iEa6poaeZM8718iF/2RbYmJf8cTEM02+/bUPRoyak1X3MIrx?= =?us-ascii?Q?NB2/7VArXyoElZGoNIZavJcc0px+JLkKmTGpJxm4+8CiUEZ+B48l3X3NZl+v?= =?us-ascii?Q?9hXRvdJNKVfM3q3UXNv73DSwIzzXiZrAC0INEzy5j8XQynEEYxes1Y4euaFh?= =?us-ascii?Q?/uvVoPSfwp5IZwL2LSqzk98grEMJlKqwPOYImPgZbFkEXZtabv4wP5brbMO1?= =?us-ascii?Q?WikkyVfQpiJLoklYa+e6BXSpYFUytU2Q3fNeFBykq93zaQjyMfOujmr//j3C?= =?us-ascii?Q?vkdohAUZIa2VCprTadum+9LwzDH/9SUOd53MQOxP9YhFta3tWYpeCvU3/1fj?= =?us-ascii?Q?a/C1nqBs4aYUgqZTC5copc07muqF1bHrXupyGhcTHHnkFlzjpGc80pwWPtNJ?= =?us-ascii?Q?X5gy0hZWhgmQfnK8WR8mvKcg0a2cykhL9sDxVSF9RnMLpcdQDFoMPQWeqWdg?= =?us-ascii?Q?DDHX x-ms-exchange-transport-forked: True X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: SA2PR10MB4474.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 624947c5-b370-440f-3261-08d9248d959a X-MS-Exchange-CrossTenant-originalarrivaltime: 31 May 2021 23:41:16.7479 (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: Gn0/HmPiEl2ctDGEw62OPe5NBTIYwmil3t2Y1AflPo5v57rI+fMIHo2M4y+7Hu2jFlj80dHHyYfu+QCWZ9ZC1Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA2PR10MB4507 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=10001 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 bulkscore=0 phishscore=0 spamscore=0 malwarescore=0 mlxscore=0 mlxlogscore=936 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105310178 X-Proofpoint-GUID: GsKsqT2enOAcMfitxN35bMQFUhSxXrf5 X-Proofpoint-ORIG-GUID: GsKsqT2enOAcMfitxN35bMQFUhSxXrf5 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=10001 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 impostorscore=0 malwarescore=0 adultscore=0 suspectscore=0 lowpriorityscore=0 spamscore=0 bulkscore=0 phishscore=0 priorityscore=1501 clxscore=1015 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105310177 Received-SPF: pass client-ip=156.151.31.85; envelope-from=drew.adams@oracle.com; helo=userp2120.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, 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_BL=0.001, RCVD_IN_MSPIKE_L3=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:130406 Archived-At: > Hm ... interesting. Yeah, maybe we should start do that more? Dunno what you mean by "do that more". If you mean use `defmacro' more or something, then let me be clear that I'm NOT suggesting that. I'm not suggesting that people should define more Lisp macros. In general, don't define a macro if a function will do what you want. I just wanted to point out that I think the supposed difficulty or bugginess of defining macros is due partly (largely?) to the fact that we (all of us) write macros much less often than we write functions. > But I'm unsure even what is the entry point... I'm guessing that here you're asking about how to use a macro to just translate one Lisp sexp to another (where the first is a list with symbol car). If so, the answer is to use function `macroexpand'. (or `macroexpand-1' or `macroexpand-all'). That just does the first step: it expands an input sexp to its expansion. `eval', on the other hand, does both steps: it expands the input sexp and then it evaluates the resulting sexp. (defun bar (x y z) (format "%s, %s! Is the answer really %s?" y x z))=20 (defmacro foo (a b) `(bar ,b ,a 42)) (macroexpand '(foo "Hello" 'alpha)) ; =3D=3D> (bar 'alpha "Hello" 42) (eval '(foo "Hello" 'alpha))) ; =3D=3D> "Hello, alpha! Is the answer really 42?" > What kind of things or problems could or should you solve > with macros? Sexp translation. One common use is to define control structures (conditionals etc.), since a macro need not evaluate all (or any) of its arguments. Emacs Lisp (like most Lisps) is not lazy - functions evaluate all of their args before the function body is invoked. So you can't define a conditional such as `my-if' as a Lisp function. But you can define it as a macro. Another common use is to define access functions, e.g., provide recognizable, domain-specific names. E.g.: (defmacro antenna-frobulator (satellite) `(caddr (caar (cddr (cdaar satellite))))) Defining a domain-specific language is a major use case for Lisp macros. Of course, with Emacs Lisp the resulting language still has Lisp-like syntax to a large extent. But with Common Lisp you also have reader macros, which means you can end up with pretty much any syntax you want for your DSL. Most uses of macros are something like these. Paul Graham describes what Lisp macros are all about, what they're used for, and how to use them, in several of his essays, and in his book "On Lisp". Here's one such short essay - search for "macro": http://www.paulgraham.com/avg.html ___ What's a use case of just macro-expanding, i.e., just translating Lisp sexps, without evaluating the result? This is not common. Let me be clear about that. But as one example, the first non-trivial Lisp program I wrote did just that. It essentially used `macrolet' to define a zillion macros that translated all of the predefined forms (functions, special forms, macros) of Franz Lisp to Common Lisp (this was before Franz Inc. went Common). (Another part of the code translation translated predefined global variables.) The program was used to make a first, automatic, pass at translating lots of Franz-Lisp code to Common Lisp for a Lisp/Prolog machine we built. (This was back when there were few CL implementations. A preliminary implementation of Kyoto CL was all we had. We were writing a CL implementation for the Lisp machine.) Franz then was only dynamically scoped, and CL is lexically scoped, so exact translation is ultimately impossible. But a given sexp translation (e.g. `(apply #+ foobar)' could sometimes be relatively straightforward. (Actually, even `+' was not straightforward, as the type systems were different etc.) In a simple case, a sexp translation might only mean changing the order of some arguments. The two Lisps had a lot in common, even though they were also very different. There were plenty of "faux amis" and such. More generally, the output would be a sexp with lambda forms that had doc strings describing correspondences for functions/macros etc. (the closest correspondences to be found), args, limitations, etc. The result of translating a short program could thus be a large program of approximate code. The point was to serve as an aid to humans who had to produce a CL version of the code. We translated tons of code this way. The translation tool was only that - a tool that helped people translate code. You could also use the tool interactively to evaluate the translation result. That is, it gave us a way to to interpret Franz code on the fly using CL, in a first-pass way. That helped with testing & debugging. =20