[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Optional Arguments
From: |
pietru |
Subject: |
Re: Optional Arguments |
Date: |
Mon, 7 Dec 2020 18:51:34 +0100 |
> Sent: Monday, December 07, 2020 at 4:51 PM
> From: tomas@tuxteam.de
> To: pietru@caramail.com
> Cc: "Help Gnu Emacs" <help-gnu-emacs@gnu.org>
> Subject: Re: Optional Arguments
>
> 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)
Because by default, a function returns the value of the last expression
evaluated as the return value. Correct?
> 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
>
- Re: Optional Arguments, (continued)
- Re: Optional Arguments, pietru, 2020/12/07
- Re: Optional Arguments, Arthur Miller, 2020/12/07
- Re: Optional Arguments, pietru, 2020/12/07
- Re: Optional Arguments, Michael Heerdegen, 2020/12/07
- Re: Optional Arguments, pietru, 2020/12/07
- Re: Optional Arguments, Arthur Miller, 2020/12/07
- Re: Optional Arguments, pietru, 2020/12/07
- Re: Optional Arguments, Alexis Roda, 2020/12/07
- Re: Optional Arguments, pietru, 2020/12/07
- Re: Optional Arguments, tomas, 2020/12/07
- Re: Optional Arguments,
pietru <=
- Re: Optional Arguments, Arthur Miller, 2020/12/07
- Re: Optional Arguments, pietru, 2020/12/07
- Re: Optional Arguments, Stefan Monnier, 2020/12/07
- Re: Optional Arguments, pietru, 2020/12/07
- Re: Optional Arguments, Christopher Dimech, 2020/12/07