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.