Re: Determine object passed as argument

Jean Louis <[email protected]>
Newsgroups gmane.emacs.help
Organization GNU Support
Message-ID <[email protected]>
On 2026-04-11 15:14, Heime wrote:
> ----------------------------------------------------------------
> Can a function determine the object being passed as argument and
> print its name.  For instance that I passed if I pass fpln when
> calling (lana-du-fpln 'fpln).
> 
> (defun lana-du-fpln (datenstruk &optional bname)

In Emacs Lisp, you cannot directly get the variable name that was passed 
to a function, because arguments are evaluated before being passed. By 
the time datenstruk receives the value, the original variable name is 
lost.

(defun lana-du-fpln (datenstruk-symbol &optional bname)
   "Print the name of the symbol passed, then access its value."
   (message "Processing variable: %s" datenstruk-symbol)
   (let ((datenstruk (symbol-value datenstruk-symbol)))
     ;; Now work with datenstruk's value
     (message "Value: %S" datenstruk)))

Call it with quoted symbol: (lana-du-fpln 'fpln)

(defun lana-du-fpln (datenstruk-symbol &optional bname)
   "Print the name of the symbol passed, then access its value if bound."
   (message "Processing variable: %s" datenstruk-symbol)
   (if (boundp datenstruk-symbol)
       (let ((datenstruk (symbol-value datenstruk-symbol)))
         (message "Value: %S" datenstruk)
         ;; Your logic here
         )
     (message "Warning: %s is unbound (void variable)" 
datenstruk-symbol)))

"Warning: fpln is unbound (void variable)"
-- 
Jean Louis
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.