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

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

Re: [External] : Re: Lexical vs. dynamic: small examples?


From: Emanuel Berg
Subject: Re: [External] : Re: Lexical vs. dynamic: small examples?
Date: Thu, 26 Aug 2021 02:10:59 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

> Now the byte-compiler instead warns about a reference to
> a free variable. Maybe it shouldn't do that and instead warn
> when one uses `defvar'?

The byte-compiler also warns about the assignment to the same
variable, this is the `setq' line.

  geh.el: 
  In toplevel form:
  geh.el:15:7: Warning: assignment to free variable ‘b’

  In fun:
  geh.el:18:3: Warning: reference to free variable ‘b’

Other byte-compiler questions are, why does it stop warning
after a second compilation? Because there is no change to the
source file, so no compilation happens? But doesn't that mean
you can just compile away the shortcomings of the code?

Also, why does the warnings appear so many times? The file
(geh.el) isn't `require'd or anything from any other file.
Just `load'ed, once. Yet both warnings appear 6 times!

And all the cl warnings, from slime ... slime stuff is
required from two files, `slime' but also
`slime-presentations', `slime-autoloads', `slime-banner', and
`slime-reply'. (I use a/the MELPA version, 2.26.1.)

Anyway, that warning appear 12 times! See output after geh.el,
and last the Makefile.

;;; -*- lexical-binding: t -*-
;;;
;;; this file:
;;;   http://user.it.uu.se/~embe8573/emacs-init/geh.el
;;;   https://dataswamp.org/~incal/emacs-init/geh.el

(defmacro slet (bindings &rest body)
  (unless lexical-binding
    (error "`slet' requires `lexical-binding' to be enabled") )
  `(funcall
    (lambda ,(mapcar #'car bindings)
      ,@body)
    ,@(mapcar #'cadr bindings) ))

(setq b 200)

(defun fun ()
  b) ; geh.el:18:3: Warning: reference to free variable ‘b’

(slet ((b 1))
      (list b (fun)) ) ; (1 200)

(let ((b 2))
  (list b (fun))) ; (2 200)

(how-many "Warning: assignment to free variable ‘b’" (point) (point-max)) ;  6
(how-many "Warning: reference to free variable ‘b’"  (point) (point-max)) ;  6
(how-many "Warning: Package cl is deprecated"        (point) (point-max)) ; 12

erc/erc-kill.el:
erc/erc-iterate.el:
In toplevel form:
geh.el:15:7: Warning: assignment to free variable ‘b’

In fun:
geh.el:18:3: Warning: reference to free variable ‘b’

In toplevel form:
geh.el:15:7: Warning: assignment to free variable ‘b’

In fun:
geh.el:18:3: Warning: reference to free variable ‘b’

frame-size.el:
erc/erc-spell.el:
In toplevel form:
geh.el:15:7: Warning: assignment to free variable ‘b’

In fun:
geh.el:18:3: Warning: reference to free variable ‘b’

geh.el:
get-search-string.el:
In toplevel form:
geh.el:15:7: Warning: assignment to free variable ‘b’

In fun:
geh.el:18:3: Warning: reference to free variable ‘b’

In toplevel form:
geh.el:15:7: Warning: assignment to free variable ‘b’

In fun:
geh.el:18:3: Warning: reference to free variable ‘b’

In toplevel form:
geh.el:15:7: Warning: assignment to free variable ‘b’

In fun:
geh.el:18:3: Warning: reference to free variable ‘b’

gnus/mail.el:
In toplevel form:
ide/slime-incal.el:33:1: Warning: Package cl is deprecated

ide/slime-incal.el:
In toplevel form:
ide/slime-incal.el:33:1: Warning: Package cl is deprecated

global-keys.el:
In toplevel form:
ide/slime-incal.el:33:1: Warning: Package cl is deprecated

face.el:
ide/ide.el:
In toplevel form:
face.el:15:1: Warning: Package cl is deprecated

In toplevel form:
face.el:15:1: Warning: Package cl is deprecated

sort-incal.el:
street.el:
In toplevel form:
face.el:15:1: Warning: Package cl is deprecated

In toplevel form:
face.el:15:1: Warning: Package cl is deprecated

string.el:
In toplevel form:
face.el:15:1: Warning: Package cl is deprecated

navigate-fs-keys.el:
In toplevel form:
face.el:15:1: Warning: Package cl is deprecated

super.el:
scroll.el:
In toplevel form:
face.el:15:1: Warning: Package cl is deprecated

In toplevel form:
face.el:15:1: Warning: Package cl is deprecated

string-minibuffer.el:
In toplevel form:
face.el:15:1: Warning: Package cl is deprecated

# this file:
#   http://user.it.uu.se/~embe8573/emacs-init/Makefile
#   https://dataswamp.org/~incal/emacs-init/Makefile

emacs=/usr/local/bin/emacs

ema-path=~/.emacs.d/emacs-init

ema-erc=\"${ema-path}/erc\"
ema-gnus=\"${ema-path}/gnus\"
ema-ide=\"${ema-path}/ide\"
ema-init=\"${ema-path}\"
ema-w3m=\"${ema-path}/w3m\"
ema=${ema-erc} ${ema-gnus} ${ema-ide} ${ema-init} ${ema-w3m}

elpa-path=~/.emacs.d/elpa

markdown-mode=\"${elpa-path}/markdown-mode-20201220.253\"
w3m=\"${elpa-path}/w3m-20210615.103\"

elpa=${markdown-mode} ${w3m}

slime=\"/usr/share/emacs/site-lisp/elpa-src/slime-2.26.1/\"

packs=${ema} ${elpa} ${slime}

byte-compile=$(emacs)                                       \
        --batch                                                  \
        --eval "(setq load-path (append load-path '(${packs})))" \
        -f batch-byte-compile

sed-filter=2>&1 | sed '/^\(Loading\|Wrote\)/d' # errors and warnings only

error-file=error.txt

INIT_FILE=~/.emacs
INIT_FILE_BC=$(INIT_FILE).elc

ELS = $(shell zsh -c "ls -1 **/*.el")
ELCS= $(ELS:.el=.elc)

all: $(ELCS) $(INIT_FILE_BC)
        rm -f $(error-file)

$(INIT_FILE_BC): $(INIT_FILE)
        $(byte-compile) $< $(sed-filter)

%.elc: %.el
        $(byte-compile) $< $(sed-filter) > $(error-file)
        if [ -s $(error-file) ]; then echo -n "\n$<: "; cat $(error-file); fi
        rm -f $<~

clean:
        $(shell zsh -c "rm -rf **/*.elc(N)")
        rm -f $(INIT_FILE_BC) $(error-file)

again:
        ${MAKE} clean
        ${MAKE}

new:
        ${MAKE} again

-- 
underground experts united
https://dataswamp.org/~incal




reply via email to

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