[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: problems with flet on last emacs

From: Pascal J. Bourguignon
Subject: Re: problems with flet on last emacs
Date: Wed, 27 Jun 2012 14:49:48 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux)

Thierry Volpiatto <address@hidden> writes:

> Hi,
> stranges things happen with recent Emacs.
> All functions that use flet don't work anymore.
> The anonymous function defined by the flet is not read.
> (i.e void function foo)
> I could make it working by restarting my computer, recompiling
> some libraries, (helm, slime) and it worked.
> When I recompile files, restart Emacs, the problem occur again.
> I have not this problem on 24.1.
> Any ideas?
> If not I will send a bug report.

flet is a macro in cl-macs.el
in emacs-version "23.4.2":

(pp (macroexpand '(flet ((f (x) (+ x x)))
                      (f 42))))

      (fboundp #2='f))
      (and #1#
           (symbol-function #2#))))
         (fset #2#
                 (block f
                   (+ x x)))))
         (f 42))
    (if #1#
        (fset #2# #3#)
        (fmakunbound #2#))))

This is spooky, because it rebinds the function slot of the symbol
(globally).  In Common Lisp, flet is a lexical binding.

An alternative (and more correct) implementation of flet would use a
code walker to substitute any call to (f 42) by something like:
(--cl-letf-function-- 42).

To avoid problem with the current version of flet, you should use a
function name that is not the name of a global function.

For example:

    (defun pjb--do-something ()
      (flet ((pjb--do-something--inner-fun (x) (+ x x)))
        (pjb--do-something--inner-fun 42)))

If you use a simple name, such as string-compare, (there's no
string-compare function in this emacs 23.4.2 instance), then it may
break when you load some library that define that function, or when you
switch to another version of emacs that define that function.

__Pascal Bourguignon__                     http://www.informatimago.com/
A bad day in () is better than a good day in {}.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]