unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: tomas@tuxteam.de
To: pietru@caramail.com
Cc: Help Gnu Emacs <help-gnu-emacs@gnu.org>
Subject: Re: Optional Arguments
Date: Mon, 7 Dec 2020 16:51:08 +0100	[thread overview]
Message-ID: <20201207155108.GC15617@tuxteam.de> (raw)
In-Reply-To: <trinity-618dfe72-51a6-4a77-b21c-4bac81d8b409-1607353573951@3c-app-mailcom-bs11>

[-- Attachment #1: Type: text/plain, Size: 973 bytes --]

On Mon, Dec 07, 2020 at 04:06:13PM +0100, pietru@caramail.com wrote:

[...]

> How can one get computed values from a function then?

Either you return it (in your case, e.g. by returning a pair)

  (cons ma mb)

or (less preferable) by modifying variables "outside" of the
function. You have to take carefully into account what kind
of binding the program runs under, or to use "global" (in
the sense of program scope: buffer-local variables count as
global here) variables, and you have a very good Petri dish
for all sort of nasty bugs ;-)

Under lexical binding, this, for example, would do:

  (let ((ma 0)
        (mb 0))
  
    (defun foo ()
      (setq ma 5)
      (setq mb 7))
  
    (foo)
    (message "ma: %d mb: %d" ma mb))

(the function `foo' "sees" the variables `ma', `mb' set up in
the enclosing scope). Only recommended for small, tightly knit
snippets: the (human) reader should be able to "see" that too.

Cheers
 - t

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

  reply	other threads:[~2020-12-07 15:51 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-07  3:17 Optional Arguments pietru
2020-12-07  8:16 ` Alexis Roda
2020-12-07 12:37   ` pietru
2020-12-07 13:06     ` tomas
2020-12-07 13:35       ` Anders Dalskov
2020-12-07 14:24       ` pietru
2020-12-07 15:38         ` tomas
2020-12-07 18:13           ` pietru
2020-12-07 19:01             ` Arthur Miller
2020-12-07 19:42               ` pietru
2020-12-07 19:54                 ` Michael Heerdegen
2020-12-07 20:21                   ` pietru
2020-12-07 20:52                   ` Arthur Miller
2020-12-07 21:21                     ` pietru
2020-12-07 19:51             ` Alexis Roda
2020-12-07 15:06       ` pietru
2020-12-07 15:51         ` tomas [this message]
2020-12-07 17:51           ` pietru
2020-12-07 18:33             ` Arthur Miller
2020-12-07 18:49               ` pietru
2020-12-07 20:13             ` Stefan Monnier
2020-12-07 20:25               ` pietru
2020-12-07 20:39                 ` Christopher Dimech

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=20201207155108.GC15617@tuxteam.de \
    --to=tomas@tuxteam.de \
    --cc=help-gnu-emacs@gnu.org \
    --cc=pietru@caramail.com \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).