From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?utf-8?Q?Gerd_M=C3=B6llmann?= Newsgroups: gmane.emacs.devel Subject: Re: What's missing in ELisp that makes people want to use cl-lib? Date: Thu, 16 Nov 2023 21:09:50 +0100 Message-ID: References: <320999cc-6c83-2315-0044-cc0403400af3@gutov.dev> <9ab5d2bd-a648-cae0-a4a7-ae86be10af0f@gutov.dev> <87r0kuqxbf.fsf@gmail.com> <54e115a2-fc36-3056-a030-0dbf32416ddb@gutov.dev> <43f290b0-4119-597b-c89a-0fb4c7db1665@gutov.dev> <1e7fe1ef-af7d-3222-7b9e-b569b3c97ccf@gutov.dev> <22e4cb4d-a8f3-1530-881d-b8c59c5d969b@gutov.dev> <339b58d6-5a44-8393-c2cd-4c935147dde3@gutov.dev> <877cmhrcsf.fsf@gmail.com> 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="6276"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Dmitry Gutov , Eli Zaretskii , michael_heerdegen@web.de, emacs-devel@gnu.org To: =?utf-8?B?Sm/Do28gVMOhdm9yYQ==?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Nov 16 21:10:56 2023 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 1r3ihU-0001YK-6w for ged-emacs-devel@m.gmane-mx.org; Thu, 16 Nov 2023 21:10:56 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r3igY-0002QX-LW; Thu, 16 Nov 2023 15:09:58 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3igW-0002QH-Vr for emacs-devel@gnu.org; Thu, 16 Nov 2023 15:09:57 -0500 Original-Received: from mail-lf1-x12c.google.com ([2a00:1450:4864:20::12c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r3igV-0005T6-86; Thu, 16 Nov 2023 15:09:56 -0500 Original-Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-507be298d2aso1622290e87.1; Thu, 16 Nov 2023 12:09:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700165392; x=1700770192; darn=gnu.org; h=content-transfer-encoding:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mpkOTHz1WghuEr+0Ytbvxreys2yW5f3kZ47WJYbd5E8=; b=cCmLA05tYokDCNlzjduqwSKNybj+YBkztBdMnSH5rFGqTSZENFhOEpPfsWRbclPx9g hnpQrN2YvNy9y2G8N8Pux+clkCe/yYDOGQyt4GWyQHRU6ytf2IMX6t3rNlizLafXxcrz qDoTFlzoECc2ghVeU3vc2RsOypHmeCKUVCzutJ/u/ISxErtvWtv0u3vPlITfVW7lYCS1 UZQkaKOBhANzLMricSdO0u2Wlq9D+faj6bQ8EvFNAGHGeKU7Z7+MZ4TWWfbyHa3f4pcI B4Km7XqPj4td4WDKr0dmcuUttCMv+8S0160QO5tGtTn5ESDT4JkI9JUtxJUJOqpOEXr+ 0ZBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700165392; x=1700770192; h=content-transfer-encoding:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=mpkOTHz1WghuEr+0Ytbvxreys2yW5f3kZ47WJYbd5E8=; b=nDzj27Pd0StaBVtzIhcoCDu5d6vRSD3SV5d7026NpKe8XjYM95yKn5m15tUoDMLCLf Tq9LQfMEr2PjkXb/m4V0/RszPXjNq2S8C609krD4aKCD3if4SI++vV0nEsh4Urdyvf8n JheukbdoOe7/q0E16ymvSHCrdf9AiDLv6f/gY30siXSBfbYdttcZDlmMYhjtNvrSWN0s GzN6J7b/ktEH9frevKeV8YWqffwHSASI2KsG4KxSPeEmWPLju4HgJ/tUi8lEG1L7Y2hB apNVXpeFiH/QA9eLR7bVW26ljxJRvKCeCB4CFJISWcVvOR7SWLzSvkxzfpGnfwmuwBMd oH1g== X-Gm-Message-State: AOJu0YwZVMf95/J3vtuO7xRTX7EwSGQMfuyG0QUMQ0+PN69RWhUQKxK1 wVcpI8tkNG4uB6VBLkYhmWdMGK9qd1A= X-Google-Smtp-Source: AGHT+IG/LpdJ9Ts4z4CkiwVPHUaAOlEEbxAKCVgG4yeuYlLIKkJSZtS6XYaN1+/+fu+p2uM9yqA5xQ== X-Received: by 2002:ac2:5393:0:b0:505:6c99:bd7c with SMTP id g19-20020ac25393000000b005056c99bd7cmr11228626lfh.57.1700165392156; Thu, 16 Nov 2023 12:09:52 -0800 (PST) Original-Received: from Pro.fritz.box (pd9e3628d.dip0.t-ipconnect.de. [217.227.98.141]) by smtp.gmail.com with ESMTPSA id l3-20020a5d4bc3000000b003143c9beeaesm285196wrt.44.2023.11.16.12.09.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Nov 2023 12:09:51 -0800 (PST) In-Reply-To: ("Gerd =?utf-8?Q?M=C3=B6llmann?= =?utf-8?Q?=22's?= message of "Thu, 16 Nov 2023 18:44:56 +0100") Received-SPF: pass client-ip=2a00:1450:4864:20::12c; envelope-from=gerd.moellmann@gmail.com; helo=mail-lf1-x12c.google.com 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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 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-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:312835 Archived-At: Gerd M=C3=B6llmann writes: > Jo=C3=A3o T=C3=A1vora writes: > >> AFTER loading it >> >> ... > > The magnitude of the difference when additional methods are defined I > find surprising. I take it as a strong indicator that cl-generic.el > indeed works completely differently than PCL. Assuming it is not a bug > af some sort. That the manual nowhere uses the term "discriminating > function" might also be a hint. Looking a bit at cl-generics.el, at least the discriminating functions part is indeed like nothing in PCL. And discriminating functions are not in the manual, because there are none. Disclaimer: I do not know cl-generics.el, and I've just looked enough to get an impression. So: I would describe the difference between PCL and cl-generic something like static vs. dynamic, perhaps. PCL goes to great lengths computing applicable methods etc. constructing an as optimal as possible discriminating function. Once this has all been done, nothing more has to be done at runtime. When methods are changed, added etc. the whole thing is done from scratch again. Cl-generics, in contrast, I'd say relies on runtime computation of applicable methods and so on, plus memoization. If someone wants to see what a generic function looks like, see cl-generic-define -> cl--generic-make-function -> cl--generic-make-next-function -> cl--generic-get-dispatcher. There we see (funcall cl--generic-compiler `(lambda (generic dispatches-left methods) (let ((method-cache (make-hash-table :test #'eql))) (lambda (,@fixedargs &rest args) (let ,bindings (apply (with-memoization (gethash ,tag-exp method-cache) (cl--generic-cache-miss generic ',dispatch-arg dispatches-left methods ,(if (cdr typescodes) `(append ,@typescodes) (car typescodes)))) ,@fixedargs args))))))))) The hash-table is a cache, the inner lambda is the function definition of the gf, the apply is the execution of an effective method, AFAIU. If we hit an argument combination not in the cache, we compute applicable methods at runtime, I believe. A bit strange is that cl--generic-next-function seems to be called recursively in the process, which I think could create another such hash-table. Or I'm reading that simply wrong, as I mentioned I just wanted to see if cl-generic is so different, so I didn't spend much time on this. The question how that leads to such-and-such performance effects I can't answer. I haven't seen such an implementation before. And I'm not saying it's bad! There are very very very (did I say very enough?) good reasons to try and avoid the incredible complexity of something like PCL.