I have a favorite function that contains several levels of set-process-sentinel
and lambda
sentinels. I have been using lexical-let
, but would like to see if it is possible to use dynamically bound variables using a backtick / comma to penetrate several levels deep. In my testing, I see that a variable dynamically bound using a backtick / comma only pentetrates a couple of levels before the variable becomes void
. Is there a way to increase the levels of penetration when using the backtick?
Example with lexical-let
:
(defun example-lexical-fn ()
"Doc-string"
(interactive)
(lexical-let* ((test-variable "Hello-world!"))
(set-process-sentinel
(start-process "process-one" "*one*" "echo" test-variable)
(lambda (p e) (when (= 0 (process-exit-status p))
(set-process-sentinel
(start-process "process-two" "*two*" "echo" test-variable)
(lambda (p e) (when (= 0 (process-exit-status p))
(start-process "process-three" "*three*" "echo" test-variable)
(set-process-sentinel
(start-process "process-four" "*four*" "echo" test-variable)
(lambda (p e) (when (= 0 (process-exit-status p))
(set-process-sentinel
(start-process "process-five" "*five*" "echo" test-variable)
(lambda (p e) (when (= 0 (process-exit-status p))
(message "test-variable: %s" test-variable)))))))))))))))
The dynamic binding putters-out and the test-variable
becomes a void-variable
at the section labeled "process-three".
(defun example-dynamic-fn ()
"Doc-string"
(interactive)
(let* ((test-variable "Hello-world!"))
(set-process-sentinel
(start-process "process-one" "*one*" "echo" test-variable)
`(lambda (p e) (when (= 0 (process-exit-status p))
(set-process-sentinel
(start-process "process-two" "*two*" "echo" ,test-variable)
`(lambda (p e) (when (= 0 (process-exit-status p))
(start-process "process-three" "*three*" "echo" ,test-variable)
(set-process-sentinel
(start-process "process-four" "*four*" "echo" ,test-variable)
`(lambda (p e) (when (= 0 (process-exit-status p))
(set-process-sentinel
(start-process "process-five" "*five*" "echo" ,test-variable)
`(lambda (p e) (when (= 0 (process-exit-status p))
(message "test-variable: %s" ,test-variable)))))))))))))))
Here is the working example based on the helpful answer of zk_phi: "Change all backticks to quote (') except for the first one . . . ."
(defun example-dynamic-fn ()
"Doc-string"
(interactive)
(let ((test-variable "Hello-world!"))
(set-process-sentinel
(start-process "process-one" "*one*" "echo" test-variable)
`(lambda (p e) (when (= 0 (process-exit-status p))
(set-process-sentinel
(start-process "process-two" "*two*" "echo" ,test-variable)
'(lambda (p e) (when (= 0 (process-exit-status p))
(start-process "process-three" "*three*" "echo" ,test-variable)
(set-process-sentinel
(start-process "process-four" "*four*" "echo" ,test-variable)
'(lambda (p e) (when (= 0 (process-exit-status p))
(set-process-sentinel
(start-process "process-five" "*five*" "echo" ,test-variable)
'(lambda (p e) (when (= 0 (process-exit-status p))
(message "test-variable: %s" ,test-variable)))))))))))))))