ForNext
Only Do What Only You Can Do
141. default value
Hyperpolyglot Interpreted Languages: PHP, Perl, Python, Ruby より (2012.05.08)
VBScript
JScript
Perl
sub my_log { my $x = shift; my $base = shift // 10; log($x)/log($base); } my_log(42); my_log(42, exp(1));
PHP
function my_log($x, $base=10) { return log($x)/log($base); } my_log(42); my_log(42, M_E);
Python
import math def my_log(x, base=10): return math.log(x)/math.log(base) my_log(42) my_log(42, math.e)
Ruby
def my_log(x, base=10) Math.log(x)/Math.log(base) end my_log(42) my_log(42, Math::E)