I am reading SICP to learn Lisp, the book uses Scheme dialect. I want accommodate it to emacs lisp, I find something weird in 3.1.1 and cannot figure it out, say I have a test.el
file:
(defun make-account ()
(defun withdraw (amount)
(print "in withdraw"))
(lambda () 'withdraw))
(setq a (make-account))
(withdraw 10)
Execute this file with command emacs -batch -l test.el
yields "in withdraw"
. Why is not function withdraw
local in make-account
?
And if I comment out (setq a (make-account))
, it complains about Symbol’s function definition is void: withdraw
.
What am I missing here? Thanks for any help!
withdraw
is global, but only declared whenmake-account
has been run.define
in Scheme? then as a returned value which can be called outside?my--helper-function
ormy-helper-function-1
pattern.