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

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

RE: syntax: anonymous vs. named functions


From: Drew Adams
Subject: RE: syntax: anonymous vs. named functions
Date: Sun, 16 Nov 2008 17:06:45 -0800

> thanks for the pointer -- i had looked at the docstrings but 
> not really read the programmed completion node of the info manual.
> i see this:
> ----------
>   It would be consistent and clean for completion functions to allow
> lambda expressions (lists that are functions) as well as function
> symbols as COLLECTION, but this is impossible.
> ----------
> not sure if that's exactly what you meant but it's enough to make me
> stop working in that direction...  thanks, matt

No, actually I had forgotten that a lambda form was not accepted as a function
here. ;-)

My point was that a lambda form is a function, whereas (do-completion (string))
is a list of strings - that is, it returns such a list.

`completing-read' lets you provide, as the COLLECTION argument, either (1) an
explicit set of completion candidates, as a list of strings, an alist, an
obarray, or a hash table or (2) an implicit set of candidates: a function of
three arguments that does everything.

(do-completion (string)) is case #1. A lambda form is case #2 (though, as you
pointed out, a lambda form is not accepted as the functional arg).

The reason that a lambda form is not allowed as a functional COLLECTION argument
is that although a lambda form can generally be used as a function, it
_evaluates_ to a list (whose car is `lambda' etc. - that is, to itself).

And since COLLECTION can also be an explicit list of candidates, it would be
problematic to distinguish the intention of passing an argument whose value is a
list that has the form (lambda (...) ...). This is a feature of Lisp's
program=data quality.

> ps, does the collection function really need to accept all three
> arguments (string, predicate and t/nil/lambda)?

Yes. It need not _use_ all three, or even any of them, to do its job, but it
must accept three arguments. The primitive Emacs completion functions depend on
it having such a signature.

> i know you say that
> (do-completion (string)) is a function application, but what would a
> function look like in this case?  just like this: do-completion (that
> is, a simple evaluated symbol)?  

Correct. You would pass the function `do-completion' this way:

 (completing-read "Name: " #'do-completion nil t)





reply via email to

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