unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Heime <heimeborgia@protonmail.com>
To: Heime <heimeborgia@protonmail.com>
Cc: Drew Adams <drew.adams@oracle.com>,
	Heime via Users list for the GNU Emacs text editor
	<help-gnu-emacs@gnu.org>
Subject: RE: [External] : Use of an associated list with completing-read
Date: Fri, 19 Apr 2024 03:10:26 +0000	[thread overview]
Message-ID: <1ZznhcKDmGMQcjaA3pyQaBOnYG81YwX4pE1YSoGxi_Vj_UFqz_DzTcdhZ50XnL3lEDivoq5THtGr-ShAq1PMbkmNHxajYrXWeRmti6_BSD4=@protonmail.com> (raw)
In-Reply-To: <W6kyQi0KEzTUToft2XlMS-_kjEKVV9BBKmMWWdNH1Ddk9UqyzE-S2SpOWmOm9Ly8NwF2kGT0fyvIDv7SS-bMzyTdCBMFivZaNxFvEblWXHQ=@protonmail.com>

On Friday, April 19th, 2024 at 2:59 PM, Heime <heimeborgia@protonmail.com> wrote:

> On Friday, April 19th, 2024 at 2:14 PM, Drew Adams drew.adams@oracle.com wrote:
> 
> > > Haw can I have an interactive function that
> > > displays a list of elements from an associated
> > > list using completing-read ?
> > 
> > The elements of an alist are conses. Assuming
> > that you really meant that you want to see and
> > choose among the elements, then use this:
> > 
> > (completing-read
> > "Choose an alist element: "
> > (mapcar #'prin1-to-string my-alist)
> > nil
> > t)
> > 
> > That "displays" elements that match your
> > input. Is that what you meant by "displays
> > a list of elements"?
> > 
> > It returns a string such as "(a . 42)" for
> > the alist element (a . 42). Then you can
> > use (read "(a . 42)") to get a new cons
> > that's `equal' to the cons in your alist. ___
> 
> > But if you don't really want to see the elements of the alist as completions,
> > but instead you want to see their keys, then just do this:
> 
> > (completing-read "Choose an alist key: " my-alist nil t)
> 
> 
> Yes, I wanted to see the keys as completing entries. Right, looking
> at the documentation COLLECTION can be an alist and will print the keys.
> 
> I had the cons cells the other way round, with the actual key as the cdr,
> making completing-read display the wrong entry.
> 
> > If the alist keys are symbols then apply`intern' to the chosen string, to get the symbol key. Then use this to get the element with that key (the exact same cons, i.e.,`eq', not just` equal):
> > 
> > (car (assq THE-SYMBOL my-alist)
> > 
> > I had to do a lot of guessing as to what
> > you're really requesting. As usual, you
> > don't make clear what you're after. And
> > you don't show any code that you've tried
> > so far.

How can I get the value associated with a key.  The following does not get me the 
value associated with my-key. 

(let ( (lnum (cdr (rassoc my-key my-alist))))
  (when lnum (goto-line lnum))))) )




  reply	other threads:[~2024-04-19  3:10 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-18 23:48 Use of an associated list with completing-read Heime
2024-04-19  2:14 ` [External] : " Drew Adams
2024-04-19  2:59   ` Heime
2024-04-19  3:10     ` Heime [this message]
2024-04-19 15:10       ` Drew Adams
2024-04-19 19:09         ` Heime
2024-04-19 23:32           ` Stefan Monnier via Users list for the GNU Emacs text editor
2024-04-20  1:13             ` Drew Adams
2024-04-20  1:52               ` Stefan Monnier via Users list for the GNU Emacs text editor
2024-04-20  1:59                 ` Emanuel Berg
2024-04-20  6:14                 ` Heime
2024-04-20  6:37                   ` Heime
2024-04-23  4:44 ` Jean Louis

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='1ZznhcKDmGMQcjaA3pyQaBOnYG81YwX4pE1YSoGxi_Vj_UFqz_DzTcdhZ50XnL3lEDivoq5THtGr-ShAq1PMbkmNHxajYrXWeRmti6_BSD4=@protonmail.com' \
    --to=heimeborgia@protonmail.com \
    --cc=drew.adams@oracle.com \
    --cc=help-gnu-emacs@gnu.org \
    /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).