Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a closure around a private function in elisp

In elisp I have the following

(setq lexical-binding t)



 (fset 'boom (cl-flet*
               ((tickle ()
                        (message "hi"))
                (pickle ()
                        (tickle)))
             (lambda ()
               (pickle))))
(boom)

When I run the boom function I get the error

Symbol's value as variable is void: --cl-pickle--

What's going on here?

My intent is I would like to wrap private/helper functions and variables in a closure so I can better organize my code than everything being global.

like image 207
jacob Avatar asked Nov 21 '25 20:11

jacob


1 Answers

Don't (setq lexical-binding t). You don't want to execute a command that sets this variable. Instead you want to describe to Emacs that the code you write uses lexical binding, and for that you need to add:

-*- lexical-binding:t -*-

somewhere on the first line of the file.

like image 57
Stefan Avatar answered Nov 23 '25 12:11

Stefan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!