help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

common data defined once for several functions without making it global


From: Emanuel Berg
Subject: common data defined once for several functions without making it global with lexical-let and fset
Date: Fri, 25 Jul 2014 17:05:13 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]