all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Pascal J. Bourguignon" <pjb@informatimago.com>
To: emacs-devel@gnu.org
Subject: Re: problems with flet on last emacs
Date: Wed, 27 Jun 2012 14:49:48 +0200	[thread overview]
Message-ID: <87zk7oq5qr.fsf@kuiper.lan.informatimago.com> (raw)
In-Reply-To: 87pq8lnd7v.fsf@gmail.com

Thierry Volpiatto <thierry.volpiatto@gmail.com> 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))))

(let*
    ((#1=#:--cl-letf-bound--
      (fboundp #2='f))
     (#3=#:--cl-letf-save--
      (and #1#
           (symbol-function #2#))))
  (unwind-protect
       (progn
         (fset #2#
               (function*
                (lambda
                    (x)
                 (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	other threads:[~2012-06-27 12:49 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-27 12:36 problems with flet on last emacs Thierry Volpiatto
2012-06-27 12:49 ` Pascal J. Bourguignon [this message]
2012-06-27 15:29   ` Stefan Monnier
2012-06-27 16:38     ` Thierry Volpiatto
2012-06-28  6:53     ` Ivan Kanis
2012-06-28  7:31       ` Thierry Volpiatto
2012-06-29  5:42         ` Ivan Kanis
2012-06-29  6:17           ` Thierry Volpiatto
2012-07-12  8:22             ` Ivan Kanis
2012-07-12 14:40               ` Stefan Monnier
2012-07-12 16:44                 ` Ivan Kanis
2012-11-09 17:41                   ` João Távora
2012-11-09 19:23                     ` Stefan Monnier
2012-11-10 14:12                       ` João Távora
2012-11-10 22:46                         ` Stefan Monnier
2012-11-10 23:07                           ` João Távora
2012-11-10 23:38                             ` Stefan Monnier
2012-11-12  8:02                               ` Andreas Röhler
2012-06-27 13:24 ` Tassilo Horn
2012-06-27 13:43   ` Thierry Volpiatto
2012-06-27 14:27   ` Thierry Volpiatto
2012-06-27 14:42   ` Pascal J. Bourguignon
2012-06-27 15:55     ` Tassilo Horn
2012-06-27 16:29       ` Pascal J. Bourguignon
2012-06-27 19:42         ` Tassilo Horn
2012-06-27 19:46           ` Pascal J. Bourguignon
2012-06-27 15:01   ` Andreas Schwab
2012-06-27 16:03     ` Tassilo Horn
2012-06-27 16:22 ` Glenn Morris

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=87zk7oq5qr.fsf@kuiper.lan.informatimago.com \
    --to=pjb@informatimago.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.