Fat comma
The fat comma is a syntactic construction that appears in a position in a function call letters
:;
Subtleties
ALGOL 60
The ALGOL "fat comma" is semantically identical to the comma. In particular, whether letter strings are used, and what their contents are, need not match between the definition of a function and its uses. The following are equivalent:
S
S t: p:
S Temperature: Pressure:
Perl
The "fat comma" forces the word to its left to be interpreted as a string.
Thus, where this would produce a run-time error under strict :
%bad_example = ;
the following use of the fat comma would be legal and idiomatic:
%good_example = ;
This is because the token converted_to_string would be converted to the string literal "converted_to_string" which is a legal argument in a hash key assignment.
The result is easier-to-read code, with a stronger emphasis on the name-value pairing of associative arrays.
PHP
In PHP, the fat comma is termed a double arrow, and is used to specify key/value relationships when declaring an array. Unlike in Perl, the double arrow does not treat what comes before it as a bare word, but rather evaluates it. Hence, constants used with the double arrow will be evaluated:
$array = array;
Ruby
In Ruby, the fat comma is the token to create hashes. Ruby 1.9 introduced a special syntax to use symbols as barewords. In Ruby, the fat comma is called a hash rocket.
- Old syntax
old_hash =
- New syntax
new_hash =
Use as lambda functions
The fat arrow is used to declare single expression anonymous functions in JavaScript, and C sharp.