all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Zhu Zihao <all_but_last@163.com>
Cc: emacs-devel@gnu.org
Subject: Re: Any convenient way for cl-generic to dispatch on a callable Lisp Object?
Date: Mon, 20 Apr 2020 09:44:23 -0400	[thread overview]
Message-ID: <jwv8siq2snj.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87r1wia64r.wl-all_but_last@163.com> (Zhu Zihao's message of "Mon, 20 Apr 2020 16:55:16 +0800")

> 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




  reply	other threads:[~2020-04-20 13:44 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-20  8:55 Any convenient way for cl-generic to dispatch on a callable Lisp Object? Zhu Zihao
2020-04-20 13:44 ` Stefan Monnier [this message]
2020-04-20 15:32   ` Zhu Zihao
2020-04-20 15:39   ` Zhu Zihao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwv8siq2snj.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=all_but_last@163.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.