in reply to surprising backwards evaluation order

This strikes me as an odd choice

In a stack machine, it's easier to calculate last what you will need first. The arguments are only needed once the function is called, so it's convenient to calculate the address of the function last.

It's not purely a Perl oddity. Visual Studio .NET 2003's C++ compiler does things in the same order with respect to function pointer vs function argument order:

#include <stdio.h> typedef void (*fp)(int); void f(int) { printf("f()\n"); } fp a() { printf("a()\n"); return &f; } int b() { printf("b()\n"); return 0; } int main() { ((fp)(a()))(b()); // (a())->(b()) return 0; }

outputs

b() a() m()

Replies are listed 'Best First'.
Re^2: surprising backwards evaluation order
by TimToady (Parson) on Mar 18, 2006 at 02:39 UTC
    Consider also that in an MMD implementation, it's a requirement that the call destination be calculated on the basis of the run-time types of the arguments. Even for a single dispatch system like Perl 5, you have to at least figure out what the object is before you find out where you're going to call.

    Also, some of the bias is just coming from seeing the verb out in front. A speaker of a language such as Japanese might not have that bias, since the verb comes after the object there. Even in English, you have to reserve judgement on the meaning of a verb until you've seen the object. You don't know what "screw the X" means until you know whether X is a light bulb or a Californian.