From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Any convenient way for cl-generic to dispatch on a callable Lisp Object? Date: Mon, 20 Apr 2020 09:44:23 -0400 Message-ID: References: <87r1wia64r.wl-all_but_last@163.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="40617"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: emacs-devel@gnu.org To: Zhu Zihao Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Apr 20 15:45:29 2020 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 1jQWjp-000AUi-CQ for ged-emacs-devel@m.gmane-mx.org; Mon, 20 Apr 2020 15:45:29 +0200 Original-Received: from localhost ([::1]:35998 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQWjo-0008V1-7F for ged-emacs-devel@m.gmane-mx.org; Mon, 20 Apr 2020 09:45:28 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34966 helo=eggs1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQWiq-0006wt-Kd for emacs-devel@gnu.org; Mon, 20 Apr 2020 09:44:28 -0400 Original-Received: from Debian-exim by eggs1p.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jQWip-0006c9-C9 for emacs-devel@gnu.org; Mon, 20 Apr 2020 09:44:27 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:7254) by eggs1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jQWio-0006Zr-UL for emacs-devel@gnu.org; Mon, 20 Apr 2020 09:44:27 -0400 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id D163B80055; Mon, 20 Apr 2020 09:44:25 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 2280D80D82; Mon, 20 Apr 2020 09:44:24 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1587390264; bh=smovdUu4vjrH8sEW3Ht/mHIE22q3DfV1zGJf7EEG/XQ=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=X5NxBwaaGNclF+y/PeS4TFCNgJF5TqHSEM+LKoLViM2g6WuJfZoGcg11b6i0nc150 XPy7aALjQU8KLpvcKea/GMGTuCBxq/p6GUvbuD8kIPgzXE2wxtmXWA45GsCzKfs68n +RJn+36YRrusjIgxXxgfcmjETQ7en4NGkDznyJA0py/i9/Q1DiQmWDtzK9s5qppNLV ZEo0efBLYYu5h/IRAUubp4nUO20h9MvJwYoQQgPPlQ8qfzSgxXZJbPyGa6JMMHJVg6 lUwNOPr05u3C1mNMDaeHrsOh+c+8BTmh4NhHsb2rUUO62h97EJ9VCIe4FymBLxEgTu 4nC84Es+ErleA== Original-Received: from alfajor (unknown [104.247.241.114]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id C0FA812024D; Mon, 20 Apr 2020 09:44:23 -0400 (EDT) In-Reply-To: <87r1wia64r.wl-all_but_last@163.com> (Zhu Zihao's message of "Mon, 20 Apr 2020 16:55:16 +0800") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-detected-operating-system: by eggs1p.gnu.org: First seen = 2020/04/20 09:09:43 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Received-From: 132.204.25.50 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:247381 Archived-At: > cl-generic can dispatch on builtin types, so subr and complied-function can be > dispatched. But looks that it lacks support of dispatching on funcall-able Lisp > Object(e.g. dynamic constructed lambda expression, closure, a symbol with > function slot set). Can we add this? The reason I haven't is that I felt that it would add too much extra cost to the dispatch. Currently the computation of the "tag" on which to dispatch for built-in types is (as you can see in `cl--generic-typeof-generalizer`): (if ,name (type-of ,name) 'null) We'd have to change this to distinguish generic `cons` from "cons cell with a `lambda` or `closure` in its `car`". I did implement it in Elisp locally, but I felt that it makes the computation of the tag a bit too expensive for my taste. I guess if we do it in C (by implementing a new `type-of-for-cl-generic` built-in function), it would be cheap enough. But next thing we know someone will want to dispatch on `face` or `keymap`, and then we'd need to distinguish symbol, symbol-and-function, symbol-and-function-and-face-and-keymap symbol-and-function-and-face-but-not-keymap, symbol-and-function-and-keymap-but-not-face, ... which will quickly become tiresome. Another way to make it cheaper is to rework the way generalizers work such that the code that builds the tag-computation can know which specializers we're interested in, so that we could use just `type-of` when there's no dispatch on `function` and use a more costly computation for those rare places where we do dispatch on `function`. Stefan