Heime <[email protected]> writes:
> On Sunday, April 12th, 2026 at 3:27 AM, Heime <[email protected]> wrote:
>
>>
>> >
>> > 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?
>
> Can I use (symbolp datenstruk)
>
> If the test fails and is not a symbol, then what is the
> argument? Anonymous?
>
If the condition ‘(cl-typep datenstruk 'symbol)’ evaluates
to nil, then ‘datenstruk’ is not a symbol.
> Can I determine whether the input is a hash-table, plist,
> alist or something else?
>
In that case, you do not have a simple conditional
expression:
(if my-condition
then-expression
else-expression)
Instead, you have a multi-branch conditional. Because your
conditional is to branch based on the type of the parameter,
you can use ‘cl-typecase’:
(defun report-a-type (obj)
(cl-typecase obj
(symbol "It’s a symbol")
(hash-table "It’s a hash table")
(plist "it’s a plist")
;; Need to define the predicate ‘alistp’:
(list (if (alistp obj)
"It’s an assoc. list"
"It’s a list"))
(t "Some other type")))
(report-a-type 'k1)
=> "It’s a symbol"
(report-a-type (make-hash-table))
=> "It’s a hash table"
(report-a-type '(k1 v1 k2 v2 k3 v3))
=> "it’s a plist"
(report-a-type '(key1 val1 key2))
=> "It’s a list"
(report-a-type '((k1 v1) (k2 v2) (k3 v3)))
=> "It’s an assoc. list"
(report-a-type '(() () ()))
=> "It’s a list"
(report-a-type '((nil) (nil) (nil)))
=> "It’s an assoc. list"
Someone may have written a library/package that I am unaware
of that defines the equivalent of ‘alistp’ or an
association-list type.
See:
(info "(cl) Type Predicates")
(info "(elisp) Association List Type")
--
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.