unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: YUE Daian <sheepduke@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Function argument order of evaluation
Date: Mon, 11 Feb 2019 22:54:31 +0800	[thread overview]
Message-ID: <87ftsuz87s.fsf@home.i-did-not-set--mail-host-address--so-tickle-me> (raw)
In-Reply-To: <CAN-HRFYkBeqX4wDxNDgm57Fo38vEqfwazsjRpTHKLYEN_+kTRg@mail.gmail.com>

On 2019-02-11 10:53, Tadeus Prastowo <tadeus.prastowo@unitn.it> wrote:
> Hello,
>
> In C/C++, the following code has an undefined behavior (UB):
>
> int my_var = 1;
> my_function((my_var = 10), 2 * my_var);
>
> It is because their respective standards do not specify that the
> assignment `(my_var = 10)' as the first argument must be evaluated
> before the second argument `2 * my_var' is evaluated.  So,
> `my_function' can see as its arguments either `10' and `20' or `10'
> and `2'.  Compiling the following code with GCC 5.5 that comes with
> Ubuntu 16.04 gives the latter:
>
> #include <stdio.h>
> void my_function(int a, int b) {
>   printf("%d, %d\n", a, b);
> }
> int main() {
>   int my_var = 1;
>   my_function((my_var = 10), 2 * my_var);
>   return 0;
> }
>
> Does Emacs Lisp behave the same or does it provide a guarantee that
> the function arguments are always evaluated from left to right?
>
> I have searched Emacs Lisp manual and the archive of this mailing list
> for the keyword "order of evaluation" but have not found the answer.
> So, I ask directly here.  Sorry if I might have missed the obvious.
>
> Thank you for your kind help.
>
> --
> Best regards,
> Tadeus

Hi Tadeus,

From the Emacs Lisp reference:
...then the forms in the function body are evaluated in order, and the
value of the last body form becomes the value of the function call.

You see, the forms in the function body are evaluated *in order*.

I think it can be treated as a guarantee? ;-)

Reference:
https://ftp.gnu.org/old-gnu/Manuals/elisp-manual-20-2.5/html_chapter/elisp_9.html#SEC114

Danny



  reply	other threads:[~2019-02-11 14:54 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-11  9:53 Function argument order of evaluation Tadeus Prastowo
2019-02-11 14:54 ` YUE Daian [this message]
2019-02-11 15:15   ` Tadeus Prastowo
2019-02-11 14:58 ` tomas
2019-02-11 15:17   ` Tadeus Prastowo

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=87ftsuz87s.fsf@home.i-did-not-set--mail-host-address--so-tickle-me \
    --to=sheepduke@gmail.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.
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).