Re: Determine object passed as argument

[email protected]
Newsgroups gmane.emacs.help
Message-ID <[email protected]>
Heime <[email protected]> writes:

> On Sunday, April 12th, 2026 at 2:38 AM, [email protected] <[email protected]> wrote:
>
>> [email protected] writes:
>> 
>> ...
>> Or,
>> 
>>   (defun lana-du-fpln (datenstruk &optional bname)
>>     (if (cl-typep datenstruk 'symbol)
>>       (symbol-name datenstruk)
>>       ;; Else
>>       "Not a symbol"))
>> 
>>   (lana-du-fpln 'fpln)
>>   => "fpln"
>>   (lana-du-fpln '(a b c))
>>   => "Not a symbol"
>>   (lana-du-fpln "abc")
>>   => "Not a symbol"
>
> No need for boundp as outlines by Jean?
>

1. ‘boundp’ is not needed within the function definition.
The parameter ‘datenstruk’ is definitely bound to the value
that was determined when the function *call* was evaluated:

   a. (lana-du-fpln <some-expression>)
      <some-expression> is evaluated to determine a value.
   b. (lana-du-fpln <its value>)
      The function ‘lana-du-fpln’ is called with the
      argument <its value>.
   c. Within ‘lana-du-fpln’, <its value> is bound to
      ‘datenstruk’.

Where it would be a problem (that is, need to check using
‘boundp’) is if you were using one level of indirection --
if <its value> was itself a symbol from which you wanted
*indirectly* to retrieve its value.

2. In step a, above, if <some-expression> was the name of a
variable which you had not yet bound to some value, then you
might need to use ‘boundp’ there.

   ;; No guard
   (lana-du-fpln needs-a-value)
   => Debugger entered--Lisp error: (void-variable needs-a-value)

   ;; Add a guard
   (when (boundp 'needs-a-value)
     (lana-du-fpln needs-a-value))
   => nil

   ;; No guard needed
   (let (needs-a-value)
     ;; ‘let’ binds ‘needs-a-value’ to nil, by default
     (lana-du-fpln needs-a-value))
   => "nil"
   (symbolp nil)
   => t

For more explanation, see David S. Touretzky’s textbook
(with exercises and answers) "COMMON LISP: A Gentle
Introduction to Symbolic Computation", Chapter 3, where he
introduces his "evaltrace diagram".  Although this is a book
on Common Lisp, almost all of the book applies as well to
Emacs Lisp (although you may need to use Emacs’s ‘cl-lib’
for some expressions).

   https://www.cs.cmu.edu/~dst/LispBook/book.pdf

-- 
The lyf so short, the craft so long to lerne.
- Geoffrey Chaucer, The Parliament of Birds.
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.