unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Kevin Rodgers <ihs_4664@yahoo.com>
Subject: Re: Qs on obarrays
Date: Wed, 12 Oct 2005 10:17:47 -0600	[thread overview]
Message-ID: <dijcvd$jlp$1@sea.gmane.org> (raw)
In-Reply-To: <87zmpfy0y0.fsf@thalassa.informatimago.com>

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

  parent reply	other threads:[~2005-10-12 16:17 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.10964.1129078391.20277.help-gnu-emacs@gnu.org>
2005-10-12  1:32 ` Qs on obarrays Pascal Bourguignon
2005-10-12  2:02   ` Drew Adams
2005-10-12 16:17   ` Kevin Rodgers [this message]
2005-10-12 17:14     ` Drew Adams
2005-10-12 18:23       ` Kevin Rodgers
2005-10-12 20:24         ` Drew Adams
2005-10-12 15:53 ` Stefan Monnier
2005-10-12  0:52 Drew Adams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='dijcvd$jlp$1@sea.gmane.org' \
    --to=ihs_4664@yahoo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).