词条 | Fat comma |
释义 |
=> " operator present in some programming languages. It is primarily associated with PHP, Ruby and Perl programming languages, which use it to declare hashes. Using a fat comma to bind key-value pairs in a hash, instead of using a comma, is considered an example of good idiomatic Perl.[1] In CoffeeScript and TypeScript, the fat comma is used to declare a function that is bound to this .[2][3]SubtletiesPerlThe "fat comma" forces the word to its left to be interpreted as a string.[4] Thus, where this would produce a run-time error under strict (barewords are not allowed): the following use of the fat comma would be legal and idiomatic: This is because the token The result is easier-to-read code, with a stronger emphasis on the name-value pairing of associative arrays. PHPIn 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: RubyIn Ruby, the fat comma is the token to create hashes. Ruby 1.9 introduced a special syntax to use symbols as barewords.[5][6] In Ruby, the fat comma is called a hash rocket.[6] Use as Lambda FunctionsThe fat arrow is used to declare single expression anonymous functions in JavaScript[7], and C sharp[8]. References1. ^{{Cite book|last=Conway|first=Damian|authorlink=Damian Conway|editor=Allison Randal and Tatiana Appandi|title=Perl Best Practices|year=2005|publisher=O'Reilly Media, Inc.|isbn=0-596-00173-8|chapter=4: Values and Expressions|pages=66|quote=Whenever you are creating a list of key/value or name/value pairs, use the "fat comma" (=>) to connect the keys to their corresponding values.}} {{compu-prog-stub}}2. ^{{cite web|last=Ashkenas|first=Jeremy|title=Coffeescript Documentation: grammar.coffee|url=http://coffeescript.org/documentation/docs/grammar.html}} 3. ^http://www.typescriptlang.org/docs/handbook/functions.html 4. ^perldoc.perl.org – perlop – Comma Operator 5. ^{{cite web|last=Galero|first=Michael|title=Ruby 1.9 Hash in Ruby 1.8|url=http://devblog.michaelgalero.com/2008/04/03/ruby-19-hash-in-ruby-18/|accessdate=3 April 2008}} 6. ^1 {{cite web |last=Nash |first=Phil |title=I don’t like the Ruby 1.9 hash syntax |url=http://logicalfriday.com/2011/06/20/i-dont-like-the-ruby-1-9-hash-syntax/ |work=Logical Friday |accessdate=13 July 2011 |deadurl=yes |archiveurl=https://web.archive.org/web/20110625034400/http://logicalfriday.com/2011/06/20/i-dont-like-the-ruby-1-9-hash-syntax/ |archivedate=25 June 2011 |df=dmy }} 7. ^{{cite web|url=https://dzone.com/articles/javascript-fat-city|title=Fat arrows in javascript}} 8. ^{{cite web|url=https://joelholder.com/2013/07/19/hacking-cs-lambda-expressions-into-hash-rockets/|title=Hacking Sharp Lambda Expressions into Hash Rockets}} 4 : Perl|Ruby (programming language)|Articles with example Ruby code|Programming constructs |
随便看 |
|
开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。