unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* noob question on cl-flet.
@ 2016-04-20 14:50 Shiyao Ma
  2016-04-20 15:50 ` Drew Adams
  0 siblings, 1 reply; 3+ messages in thread
From: Shiyao Ma @ 2016-04-20 14:50 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,

for this code:

(cl-flet ((myfunc nil
                  (message "i am in")))
  (myfunc)
  (princ (symbol-function 'myfunc)))


Why symbol-function gives nil? My expectation is the function.


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

* RE: noob question on cl-flet.
  2016-04-20 14:50 noob question on cl-flet Shiyao Ma
@ 2016-04-20 15:50 ` Drew Adams
  2016-04-20 16:08   ` Michael Heerdegen
  0 siblings, 1 reply; 3+ messages in thread
From: Drew Adams @ 2016-04-20 15:50 UTC (permalink / raw)
  To: Shiyao Ma, help-gnu-emacs

> (cl-flet ((myfunc nil
>                   (message "i am in")))
>   (myfunc)
>   (princ (symbol-function 'myfunc)))
> 
> Why symbol-function gives nil? My expectation is the function.

It returns nil because the symbol `myfunc' has an undefined function slot - it is not defined as a global function.

The binding created by `cl-flet' is not a binding of a Lisp (global) symbol.  It is a local (let-like) lexical binding.



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

* Re: noob question on cl-flet.
  2016-04-20 15:50 ` Drew Adams
@ 2016-04-20 16:08   ` Michael Heerdegen
  0 siblings, 0 replies; 3+ messages in thread
From: Michael Heerdegen @ 2016-04-20 16:08 UTC (permalink / raw)
  To: help-gnu-emacs

Drew Adams <drew.adams@oracle.com> writes:

> The binding created by `cl-flet' is not a binding of a Lisp (global)
> symbol.  It is a local (let-like) lexical binding.

@Shiyao (sorry if this is impolite and @Ma would have been correct): A
very related question has been discussed just some days ago, see
<87pototkq5.fsf@mbork.pl> in thread

   `pp-eval-expression' behaves strangely under lexical binding

This is an equivalent issue, just that we are here speaking of named
functions defined in lexical scope vs. the function cell of a symbol.


Michael.




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

end of thread, other threads:[~2016-04-20 16:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-20 14:50 noob question on cl-flet Shiyao Ma
2016-04-20 15:50 ` Drew Adams
2016-04-20 16:08   ` Michael Heerdegen

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).