Is it possible to set a symbol that is the value of target symbol within the let bind form? because I am not setting a target symbol, I am not sure how to use let.
I am doing this because I am passing in a string that represents a library's name to generate a function for the library. look at the following link to see how I am using it https://github.com/natask/sexp-string/blob/6b748c133da51a129a465a426ae43b06c3a1331d/sexp-string.el#L189.
starting point, The following is a valid let form
(setq boolean 'dynamic-value)
(print boolean) ;; prints 'dynamic-value
(let ((boolean 'lexical-value))
(print boolean)) ;; prints 'lexical-value
I am looking to modify lexically the variable boolean from a variable boolean-variable that contains the symbol boolean. boolean-variable is like a pointer to the pointer boolean.
(setq boolean 'first-value)
(setq boolean-variable 'boolean)
(print (symbol-value boolean-variable)) ;; prints 'first-value
(set boolean-variable 'second-value)
(print boolean) ;; prints 'second-value
what I have,
(setq boolean 'dynamic-value)
(setq boolean-variable (intern-soft "boolean"))
(print boolean-variable) ;; prints 'boolean
(print (symbol-value boolean-variable)) ;; prints 'dynamic-value
(let ((old-boolean-variable (symbol-value boolean-variable)))
(set boolean-variable 'lexical-value)
;; use boolean-variable in a function
(print (symbol-value boolean-variable)) ;; prints 'lexical-value
;; set the value of variable back to previous value
(set boolean-variable old-boolean-variable))
(print (symbol-value boolean-variable)) ;; prints 'dynamic-value
what I am looking for ,
(setq boolean 'dynamic-value)
(setq boolean-variable (intern-soft "boolean"))
(print boolean-variable) ;; prints 'boolean
(print (symbol-value boolean-variable)) ;; prints 'dynamic-value
(let (((symbol-content boolean-variable) 'lexical-value))) ;; creates a lexical binding to symbol 'boolean
(print (access-symbol-lexically boolean-variable)) ;; prints 'lexical-value
)
(print (symbol-value boolean-variable)) ;; prints 'dynamic-value
I am not using the variable boolean directly but through a symbol because I am passing in a string something like the following.
(setq boolean-1 'dynamic-value)
(setq boolean-2 'dynamic-value)
(defun my-fun (library)
(setq boolean-variable1 (intern-soft (concat library "-1")))
(setq boolean-variable2 (intern-soft (concat library "-2")))
;;utilize variables
)
(my-fun "boolean")
symbol-value
is explicitly for dynamically scoped variables. SeeC-h f symbol-value
and (elisp) Accessing Variables.let
form is strange/confusing. The whole "save the current value, do a thing, restore the original value" process is robustly taken care of bylet
-- you don't need to manually save and restore the value; it will be restored once the let-binding ends. Following(let ((foo newvalue)) do-a-thing)
the symbolfoo
will have its original value again.