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: Matt Price
Subject: RE: syntax: anonymous vs. named functions
Date: Sun, 16 Nov 2008 10:48:13 -0500

On Sun, 2008-11-16 at 00:01 -0800, Drew Adams wrote:
> > I have working code for my tab-completion problem (again thanks to
> > everyone for answering my painfully stupid questions).  i don't
> > understand, though, why attempts to write my function as an unnamed
> > lambda fails, but the same function succeeds when named.  the "lambda"
> > line commented out in tab-complete-from-function below 
> > returns an error
> > "test-completion: Invalid function", while the uncommented call to a
> > different, trivial function is successful.  cna anyone advise me why?
> > thanks much!
> > 
> > (defun tab-complete-from-function (stub)
> > "very simple tab completion function"
> >   (interactive (list (completing-read "Name: "
> > ;;                               (lambda (string)  
> > (split-string (shell-command-to-string (concat 
> > "/home/matt/mutt-eds-query "  string)) "\n" t)) 
> >                                   (do-completion (string)) 
> >                                   nil t)))
> >   (message stub))
> > 
> > 
> > (defun do-completion (stub)
> > "minimal function"
> >    (split-string (shell-command-to-string (concat 
> > "/home/matt/mutt-eds-query "  stub)) "\n" t))
> 
> (do-completion string) is not a function. It is a function application, and 
> its
> value is a list of strings. The lambda form is a function.
> 
> To use a function as the `completing-read' COLLECTION argument, the function
> must take the right (three) arguments and return the right values. See the doc
> for a description of the kind of function that is needed.
> 

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

ps, does the collection function really need to accept all three
arguments (string, predicate and t/nil/lambda)?  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)?  


> 
-- 
Matt Price
matt.price@utoronto.ca




reply via email to

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