Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: surprising backwards evaluation order

by ikegami (Patriarch)
on Mar 17, 2006 at 23:10 UTC ( [id://537609]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://537609]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-19 14:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found