What is the scope of a defaulted parameter in Python? [duplicate]

The scope is as you would expect. The perhaps surprising thing is that the default value is only calculated once and reused, so each time you call the function you get the same list, not a new list initialized to []. The list is stored in f.__defaults__ (or f.func_defaults in Python 2.) def f(a, L=[]): … Read more

System call vs Function call

A system call is a call into kernel code, typically performed by executing an interrupt. The interrupt causes the kernel to take over and perform the requested action, then hands control back to the application. This mode switching is the reason that system calls are slower to execute than an equivalent application-level function. fopen is … Read more

php: determine where function was called from

You can use debug_backtrace(). Example: <?php function epic( $a, $b ) { fail( $a . ‘ ‘ . $b ); } function fail( $string ) { $backtrace = debug_backtrace(); print_r( $backtrace ); } epic( ‘Hello’, ‘World’ ); Output: Array ( [0] => Array ( [file] => /Users/romac/Desktop/test.php [line] => 5 [function] => fail [args] => … Read more

Calling a function from a string in C#

Yes. You can use reflection. Something like this: Type thisType = this.GetType(); MethodInfo theMethod = thisType.GetMethod(TheCommandString); theMethod.Invoke(this, userParameters); With the above code, the method which is invoked must have access modifier public. If calling a non-public method, one needs to use the BindingFlags parameter, e.g. BindingFlags.NonPublic | BindingFlags.Instance: Type thisType = this.GetType(); MethodInfo theMethod = … Read more

Function overloading by return type?

Contrary to what others are saying, overloading by return type is possible and is done by some modern languages. The usual objection is that in code like int func(); string func(); int main() { func(); } you can’t tell which func() is being called. This can be resolved in a few ways: Have a predictable … Read more