Named Parameters

From splike.com
Jump to: navigation, search

Named parameters (or the closest you can get) in many programming languages

Groovy

parseInt(number: 'afy', radix: 36, foo: false)

C# 4.0

parseInt(number: 'afy', radix: 36, foo: false)

Python

parseInt(number = 'afy', radix = 36, foo = False)

http://docs.python.org/tutorial/controlflow.html#keyword-arguments

Scala 2.8

parseInt(number = 'afy', radix = 36, foo = false)

Perl 6

parseInt( :number('afy'), :radix(36), :foo(0) ); # no false keyword

JavaScript

parseInt( { number: 'afy', radix: 36, foo: false } );

Use JSON, an object literal

Perl

parseInt( number => 'afy', radix => 36, foo => 0 ); # no false keyword

=> does same as ",". Looks like hash (associative array), though. See http://www.cs.cf.ac.uk/Dave/PERL/node126.html

Ruby

parseInt( :number => 'afy', :radix => 30, :foo => false );

associative array

parseInt( {'number' => 'afy', 'radix' => 30, 'foo' => false } );

PHP

parseInt( array( 'number' => 'afy', 'radix' => 36, 'foo' => false ));

associative array

Java

parseInt( new HashMap() {­{ put( "number", "afy" ); put( "radix", 36 ); put( "foo", false ); }} );

map (associative array)