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

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

Re: elisp: can a function/defun return two strings..? prompt for two str


From: Andrea Crotti
Subject: Re: elisp: can a function/defun return two strings..? prompt for two strings??
Date: Sun, 27 Feb 2011 11:39:57 +0100

Il giorno 27/feb/2011, alle ore 10.24, ken ha scritto:

> In one line of a file/buffer (which might exist or might not) will be
> two strings, both of which must be fetched and returned to the calling
> function.  I was going to write two separate functions, one for each
> string, but since both strings are in the same line, it seemed highly
> inefficient to search for the same line of text twice... made more sense
> to search for it once, and get both strings in the same function.
> 
> Here's pseudo-code:
> 
> ;; search buffer for line of interest.
> ;; if the line exists
>  ;; does it specify str1?
>  ;; if it does, grab that str1, hold it for eventual return
>  ;; if it doesn't, prompt user for it, and hold it for eventual return.
>  ;; does the same line specify str2?
>  ;; if it does, grab that str2, hold it for eventual return
>  ;; if it doesn't, prompt user for it, and hold it for eventual return.
> ;; if the line doesn't exist,
>  ;; prompt user for str1 and str2
>     ;; create/insert new line in buffer, inserting str1 & str2 into it.
> ;; return str1 and str2 to calling function

The easiest way in my opinion is just to return a list, and append to it what 
you get.
It looks quite long your procedure to look for strings anyway, I think that if 
you
use regular expressions it will be much much faster.
If you write exactly the input and output that you expect maybe it will be 
easier to help

;; pseudocode
(let ((result ()))
 (if .... (add-to-list ... result)
...
 result)


reply via email to

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