From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Eric Abrahamsen <eric@ericabrahamsen.net>
Cc: emacs-devel@gnu.org
Subject: Re: Using funcall on inline functions
Date: Sat, 12 Dec 2020 18:28:59 -0500 [thread overview]
Message-ID: <jwvr1numx0l.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87bleyd4hz.fsf@ericabrahamsen.net> (Eric Abrahamsen's message of "Sat, 12 Dec 2020 14:49:28 -0800")
> (define-inline ebdb-add-to-list (list-var element)
> (inline-quote (when, element
> (cl-pushnew, element, list-var :test #'equal))))
This can't work: your argument is named "list-var" but the way you use
it in the body indicates that it's supposed to be a *list* not a *list
variable*.
It may happen to work in some cases when the function gets inlined, but
if so, it's actually showing a misfeature of the `define-inline`
implementation (result of some optimizations).
You can't have it both way: if `ebdb-add-to-list` is a function, then
`list-var` is a local variable and this argument uses the usual
pass-by-value semantics (and hence `cl-pushnew` will only affect that
local variable). If you want `list-var` to be the name of the *place*
passed by the caller then it has to be a macro.
There is a workaround, then, which is to use a reference:
(cl-defstruct ebdb-record-cache
(alt-names nil :type list))
(defclass ebdb-record ()
((cache :type ebdb-record-cache)))
(define-inline ebdb-record-alt-names (record)
(inline-quote (ebdb-record-cache-alt-names
(slot-value,record 'cache))))
(define-inline ebdb-add-to-list (list-ref element)
(inline-quote
(when ,element
(cl-pushnew ,element (gv-deref ,list-ref) :test #'equal))))
(let ((listfunc #'ebdb-add-to-list)
(name-string "Bob's new name"))
(funcall listfunc
(gv-ref (ebdb-record-alt-names <some-record>))
name-string))
[ BTW, your `ebdb-add-to-list` has a bug in that it will evaluate its
second argument before its first. ]
Stefan
next prev parent reply other threads:[~2020-12-12 23:28 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-12 22:49 Using funcall on inline functions Eric Abrahamsen
2020-12-12 23:28 ` Stefan Monnier [this message]
2020-12-13 17:48 ` Eric Abrahamsen
2020-12-13 18:12 ` Stefan Monnier
2020-12-13 18:27 ` Eric Abrahamsen
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwvr1numx0l.fsf-monnier+emacs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=emacs-devel@gnu.org \
--cc=eric@ericabrahamsen.net \
/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 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).