all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Function argument order of evaluation
@ 2019-02-11  9:53 Tadeus Prastowo
  2019-02-11 14:54 ` YUE Daian
  2019-02-11 14:58 ` tomas
  0 siblings, 2 replies; 5+ messages in thread
From: Tadeus Prastowo @ 2019-02-11  9:53 UTC (permalink / raw)
  To: help-gnu-emacs

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



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-02-11 15:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-02-11  9:53 Function argument order of evaluation Tadeus Prastowo
2019-02-11 14:54 ` YUE Daian
2019-02-11 15:15   ` Tadeus Prastowo
2019-02-11 14:58 ` tomas
2019-02-11 15:17   ` Tadeus Prastowo

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.