all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* common data defined once for several functions without making it global with lexical-let and fset
@ 2014-07-25 15:05 Emanuel Berg
  0 siblings, 0 replies; only message in thread
From: Emanuel Berg @ 2014-07-25 15:05 UTC (permalink / raw)
  To: help-gnu-emacs

If `defun' isn't used, it can be solved with
`lexical-let'.

(lexical-let ((msg "shared inside"))
  (fset 'func-a (lambda (arg) "Number one." (message "1: %s" msg)))
  (fset 'func-b (lambda (arg) "Number two." (message "2: %s" msg))) )

(func-a 1)
(func-b 2)

The code gets less pleasant to write and read and it
seems to confuse the help system:

    func-a is a Lisp function.
    
    (func-a &rest --CL-REST--)
    
    Number one.

And, the byte-compiler doesn't like this solution any
more than the `setq' one:

    In toplevel form:
    funs.el:1:1:Warning: `(msg "shared inside")' is a malformed function
    funs.el:2:45:Warning: reference to free variable `msg'

    In end of data:
    funs.el:7:1:Warning: the following functions are not known to be defined:
        lexical-let, func-1, func-2
    Wrote /home/incal/funs.elc

-- 
underground experts united


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-07-25 15:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-25 15:05 common data defined once for several functions without making it global with lexical-let and fset Emanuel Berg

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.