Re: Determine object passed as argument
Heime <[email protected]>
| Newsgroups | gmane.emacs.help |
|---|---|
| Message-ID | <bY4Vtvvue4ZwhEN7zJlH1u6wtUL5cPqYZ6DopSzDuLPVPhlZuo9i7H8BZMY5DXv3beTXo4lsm0q4aSxOlpRgizSyztYbHv1JUW5i8pXun7E=@protonmail.com> |
On Sunday, April 12th, 2026 at 12:57 AM, Jean Louis <[email protected]> wrote: > 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) The above gives "Warning: lana-fpln is unbound (void variable)" > (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)" The above gives "Processing variable: fpln" followed by its value. Why does the condition (if (boundp datenstruk-symbol) make things work out? > -- > Jean Louis > >