Ar an deichiú lá de mí Meitheamh, scríobh Didier Verna:
[...] In general, the problem occurs when you can't control the
time at
which cl-macroexpand-all performs. In such situations, the lexically let
symbols translation may miss some cases occuring in already byte-compiled
forms.
Right. And it can’t avoid that without inspecting the constant vectors and
working out if a given symbol is being used for its function or for its
value slot, which is a ridiculous amount of work, and fragile, too.
I can't quite figure out a way around this right now. Any ideas ?
In specific instances you can often construct an appropriate compiled
function object at runtime, cf. this in modeline.el, which as it happens
could equally be implemented as a function:
(defmacro make-modeline-command-wrapper (command)
"Return a function object wrapping COMMAND, for use with the modeline.
The function (itself a command, with \"e\" as its interactive spec) calls
COMMAND with the appropriate window selected, and is suitable as a binding
in the keymaps associated with the modeline."
(cond
((and-fboundp 'cl-const-expr-p (cl-const-expr-p command))
`#'(lambda (event)
(interactive "e")
(save-selected-window
(select-window (event-window event))
(call-interactively ,command))))
((eval-when-compile (cl-compiling-file))
(let ((compiled
(eval-when-compile
(byte-compile-sexp
#'(lambda (event)
(interactive "e")
(save-selected-window
(select-window (event-window event))
(call-interactively 'placeholder)))))))
`(make-byte-code ',(compiled-function-arglist compiled)
,(compiled-function-instructions compiled)
(vector ,@(subst command ''placeholder
(mapcar 'quote-maybe
(compiled-function-constants compiled))
:test 'equal))
,(compiled-function-stack-depth compiled)
,(compiled-function-doc-string compiled)
,(quote-maybe (second (compiled-function-interactive compiled))))))
(t
`(lexical-let ((command ,command))
#'(lambda (event)
(interactive "e")
(save-selected-window
(select-window (event-window event))
(call-interactively command)))))))
But I suspect you’re looking for a more general solution in the context of
implementing CLOS; we don’t have one at the moment. Were we to add lexical
scope support to the byte code instructions and the byte compiler, this
would be a natural part of that.
--
‘Iodine deficiency was endemic in parts of the UK until, through what has been
described as “an unplanned and accidental public health triumph”, iodine was
added to cattle feed to improve milk production in the 1930s.’
(EN Pearce, Lancet, June 2011)
_______________________________________________
XEmacs-Beta mailing list
XEmacs-Beta(a)xemacs.org
http://lists.xemacs.org/mailman/listinfo/xemacs-beta