help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Qs on obarrays


From: Kevin Rodgers
Subject: Re: Qs on obarrays
Date: Wed, 12 Oct 2005 10:17:47 -0600
User-agent: Mozilla Thunderbird 0.9 (X11/20041105)

Pascal Bourguignon wrote:
> "Drew Adams" <drew.adams@oracle.com> writes:
>>However, this does not seem to work for me:
>>
>>(let ((my-obarray (make-vector 7 0)))
>>  (dolist (name my-names) (intern name my-obarray))
>>  (all-completions "" my-obarray 'commandp))
>>
>>Even if all of my-names are symbol-names of commands, this always returns
>>nil. Any idea why?
>
> Because symbols are objects, they have their own identity.  When a
> symbol is used to name a function or command, it's the symbol identity
> that's used, not its name (otherwise we would use strings to name
> functions!).
>
> Try this:
>
> (defmacro defun-with-symbol (name args &rest body)
>    `(defun ,(eval name) ,args ,@body))
>
> (let ((my-obarray (make-vector 7 0)))
>   (defun-with-symbol (intern "insert-hello" my-obarray) ()
>      (interactive)
>      (insert "Hello "))
>   (defun-with-symbol (intern "insert-world" my-obarray) ()
>      (interactive)
>      (insert "World! "))
>   (funcall (intern "insert-hello" my-obarray))
>   (funcall (intern "insert-world" my-obarray))
>   (all-completions "" my-obarray 'commandp))

An alternative is to change just the predicate to check the standard
obarray:

(let ((my-obarray (make-vector 7 0)))
  (dolist (name my-names) (intern name my-obarray))
  (all-completions "" my-obarray
                   (lambda (symbol)
                     (commandp (intern (symbol-name symbol))))))

--
Kevin





reply via email to

[Prev in Thread] Current Thread [Next in Thread]