unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Should vtable-goto-object use 'equal instead of 'eq?
@ 2024-11-16 21:48 Kristoffer Balintona
  2024-11-16 22:57 ` Adam Porter
  0 siblings, 1 reply; 2+ messages in thread
From: Kristoffer Balintona @ 2024-11-16 21:48 UTC (permalink / raw)
  To: emacs-devel

Hello,

I have been using vtable.el for a project of mine and have come across a
bit of an undesirable design choice in vtable, namely, in
vtable-goto-object. Its definition on master is as follows:

        (defun vtable-goto-object (object)
          "Go to OBJECT in the current table.
        Return the position of the object if found, and nil if not."
          (let ((start (point)))
            (vtable-beginning-of-table)
            (save-restriction
              (narrow-to-region (point) (save-excursion (vtable-end-of-table)))
              (if (text-property-search-forward 'vtable-object object #'eq)
                  (progn
                    (forward-line -1)
                    (point))
                (goto-char start)
                nil))))

The relevant line is the one calling text-property-search-forward. I am
wondering whether using equal instead of eq as the predicate is
preferable.

Take the following example. The objects in a given vtable are strings.
For whatever reason, I would like to go to the vtable object
corresponding to the string "foo." I call (vtable-goto-object "foo") but
it returns nil (does nothing). The reason is because vtable-goto-object
uses eq instead of equal. This same situation occurs regardless of what
kind of objec the vtable uses.

As far as I can think of, the only way to productively use
vtable-goto-object is if the objects are stored in e.g. a variable and
referenced within that variable somehow, which is a significant
constraint.

The only case where eq would be desirable is if the vtable contains
duplicate objects, that is, objects which return t on equal but nil on
eq. With these cases in mind, would it be best for vtable-goto-object to
have as a parameter the predicate used by text-property-search-forward
(the default being eq)?

-- 
Best,
Kristoffer



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-11-16 22:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-16 21:48 Should vtable-goto-object use 'equal instead of 'eq? Kristoffer Balintona
2024-11-16 22:57 ` Adam Porter

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).