[comp.emacs] Why does completion require an alist?

bjaspan@ATHENA.MIT.EDU ("Barr3y Jaspan") (08/31/90)

Why does read-completion require an alist instead of an ordinary list
of strings?  Considering that only the car of each element of the
alist is used or returned, it doesn't seem to be a sensible
limitation.

Barr3y Jaspan, bjaspan@mit.edu

gaynor@sparky.rutgers.edu (Silver) (09/01/90)

bjaspan@ATHENA.MIT.EDU ("Barr3y Jaspan") writes:
> Why does read-completion require an alist instead of an ordinary list of
> strings?  Considering that only the car of each element of the alist is used
> or returned, it doesn't seem to be a sensible limitation.

Just the way things are.  Probably turned out that the predominating case was
one of using completing-read to grab an association from an alist, eg,

  (assoc (completing-read "Well, which one? " some-alist) some-alist)

I probably don't need to say this, but an easy way to use completing read with
a list of strings is to simply mapcar list on the list of strings, as in:

  (completing-read "Well, which one? " (mapcar 'list list-of-strings))

Regards, [Ag]

tale@turing.cs.rpi.edu (David C Lawrence) (09/01/90)

In <Sep.1.03.08.23.1990.10801@sparky.rutgers.edu> gaynor@sparky.rutgers.edu
(Silver) writes:

   I probably don't need to say this, but an easy way to use
   completing read with a list of strings is to simply mapcar list on
   the list of strings, as in:

     (completing-read "Well, which one? " (mapcar 'list list-of-strings))

Of course this conses up a lot more than it needs to in order to
perform the function.  That is, as completing-read is coded now it
certainly does need to be done but completing-read could easily be
modified to take either a simple list or an alist -- even a vector
(though a string vector would be a bit non-sensical).
--
   (setq mail '("tale@cs.rpi.edu" "tale@ai.mit.edu" "tale@rpitsmts.bitnet"))
 The most remarkable thing about looking at a picture of myself was the sudden
   realisation that my hair is in fact parted on the left and not the right.

steve@edm.isac.CA (Steve Hole) (09/04/90)

This is something that I asked some time ago and got no response on.  I
thought then that I might have been set up that way in anticipation of
using it to something more interesting.   I modified the original
function (just prototyped as a lisp function for now), that uses the
second element in each dotted pair as a documentation string.  I had to
modify the display algorithm for the possible completions to display the
second element in a nice way in the possible completions list, but
voila, instant non-obtrusive selection menu.  I often do this kind of
thing: 

 (let ((my-list '(("joe" "This is option joe")
		  ("fred" "This is option fred")
		  ("henry" "This is option henry")
		  ("sam" "This is option sam"))))
   (setq response (completing-read "Which guy?" my-list nil t)))
		  

This lets me select from a set of options with encoded or non-obvious
values by attaching supplementary information to them.  Makes for
interfaces for my programming tools and all I have to do is define new
sets of lists for the things I would like them to select.
-- 
Steve Hole  		         mail: steve@edm.isac.ca
ISA Corp.			 uucp: !{uunet, alberta}!ncc!isagate!steve
Edmonton, Alberta, Canada       phone: (403) 441-4121 

johnd@Stardent.COM (John R. Dennis @stardent) (09/07/90)

In article <1990Sep3.210627.19773@edm.isac.CA> steve@edm.isac.ca (Steve Hole) writes:
>This is something that I asked some time ago and got no response on.  I
>thought then that I might have been set up that way in anticipation of
>using it to something more interesting.   I modified the original
>function (just prototyped as a lisp function for now), that uses the
>second element in each dotted pair as a documentation string.  I had to
>modify the display algorithm for the possible completions to display the
>second element in a nice way in the possible completions list, but
>voila, instant non-obtrusive selection menu.  I often do this kind of
>thing: 

Would you care to share with us the modification you made to the display
algorithm that allows you to display the second element of the alist?

-- 
John Dennis
E     Mail: johnd@Stardent.COM | {uunet,convex,decvax}!stardent!johnd
Snail Mail: Stardent Computer, 85 Wells Avenue Newton, MA 02159
Voice Mail: <Work>(617) 964-6228 x243 <Home>(508)366-7976