all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Pascal J. Bourguignon" <pjb@informatimago.com>
To: help-gnu-emacs@gnu.org
Subject: Re: elisp: can a function/defun return two strings..? prompt for two strings??
Date: Sun, 27 Feb 2011 12:07:48 +0100	[thread overview]
Message-ID: <87hbbp20sb.fsf@kuiper.lan.informatimago.com> (raw)
In-Reply-To: mailman.2.1298798656.16925.help-gnu-emacs@gnu.org

ken <gebser@mousecar.com> writes:

> 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:

(defun pseudo-code ()

> ;; search buffer for line of interest.

   (let ((line-of-interest  (search-buffer-for-it)))

> ;; if the line exists

     (if (line-exists-p line-of-interest)

       (list    

>   ;; does it specify str1?

         (if (line-specify-str1-p line-of-interest)

>   ;; if it does, grab that str1, hold it for eventual return

             (grab-str1 line-of-interest)

>   ;; if it doesn't, prompt user for it, and hold it for eventual
>   return.
             (read-from-minibuffer "prompt for str1"))

>   ;; does the same line specify str2?

         (if (line-specify-str2-p line-of-interest)

>   ;; if it does, grab that str2, hold it for eventual return

              (grab-str2 line-of-interest)

>   ;; if it doesn't, prompt user for it, and hold it for eventual
>   return.

              (read-from-minibuffer "prompt for str2")))

> ;; if the line doesn't exist,
>   ;; prompt user for str1 and str2

       (let ((str1 (read-from-minibuffer "prompt for str1"))
             (str2 (read-from-minibuffer "prompt for str2")))
          (insert "%s %s\n" str1 str2)
          (list str1 str2)))))

>      ;; create/insert new line in buffer, inserting str1 & str2 into it.
> ;; return str1 and str2 to calling function


Now you just need to implement the missing functions used above...


> Most of the coding for the above will busy itself with finding the line
> of interest-- or determining that it doesn't exist.  

I doubt so.  Clearly, the coding above busies itself with something
else, as the pseudo code clearly indicates.


> So why should I do
> that twice, once for each string?  Sure, I could save to a variable the
> location of the line of interest to avoid having to search for it again,
> but then I'm back to working with two variables, the location and just
> one string.  So that's a non-solution.

What are you talking about???


> So how to "return" two variables to a calling function, possibly have to
> prompt for one or both of them?  (I can think of a half dozen ways to do
> this in C, but this is elisp.)

You cannot return variables, only values, resulting from the evaluation
of expressions.

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
A bad day in () is better than a good day in {}.


  parent reply	other threads:[~2011-02-27 11:07 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.2.1298798656.16925.help-gnu-emacs@gnu.org>
2011-02-27 10:31 ` elisp: can a function/defun return two strings..? prompt for two strings?? Harald Hanche-Olsen
2011-02-27 11:07 ` Pascal J. Bourguignon [this message]
2011-02-27 21:10 ` Tim X
2011-02-27  9:24 ken
2011-02-27 10:39 ` Andrea Crotti

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87hbbp20sb.fsf@kuiper.lan.informatimago.com \
    --to=pjb@informatimago.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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.