0

I was expecting a compilation error for the snippet below... unfortunately compilation goes through without any errors, but it errors during runtime.

Run-time error is expected, so no surprise there. The surprise is in not getting a compilation error


;;; foo.el --- foo -*- lexical-binding: t; coding: utf-8-emacs; -*-

(defun foo ()
  ;; (cl-labels ((msg (s)
  ;;        (message "%s" s)))
  ;;   (msg
  ;;    ;; "Hello World!"
  ;;    ))

  (cl-flet ((msg (s)
          (message "%s" s)))
    (msg 
     ;; "Hello World!"
     )))

(foo)


Initially I went with


;;; foo.el --- foo -*- lexical-binding: t; coding: utf-8-emacs; -*-

(defun foo ()
  (let* ((msg (lambda (s)
        (message "%s" s))))
    (funcall msg
         ;; "Hello World!"
         )))

(foo)

and then switched to cl-labels and cl-flet hoping that it will produce compilation errors.

If I am not getting any compile-time errors, I could as well stay with lambda form. This way I don't have to be mentally bothered with cl-labels or cl-flet indenting the forms too much to the right.

Drew
  • 75,699
  • 9
  • 109
  • 225
  • Elisp is not a static language. – shynur Jul 31 '23 at 12:31
  • I just added `(require 'cl-macs)` ---- it is `cl-macs` and not `cl-lib`---as per your suggestion. I still don't get byte compiler errors. –  Jul 31 '23 at 12:33
  • 1
    Could you please layout each step in the reasoning from `Elisp is not a static language` to `This is why you don't get compilation errors`. –  Jul 31 '23 at 12:35
  • `cl-flet` expands to a `let*` form which binds a lambda to a symbol. Lisp is so dynamic that it is difficult for the compiler to apply static program analysis. You of course know that it will signal an error, because you are intellectual enough, but the compiler is not. – shynur Jul 31 '23 at 16:08

0 Answers0