Commune · Savoirs
Elvis operator
Opérateur binaire en programmation informatique
Dans certains langages de programmation informatique, l'opérateur Elvis, souvent noté ?:, est un opérateur binaire qui renvoie son premier opérande si sa valeur est logiquement vraie (selon une convention propre à chaque langage, autrement dit une valeur dite truthy) ou renvoie son second opérande si le premier n'est pas vrai. Il s'agit donc d'un OU à court-circuit, qui renvoie son premier opérande véridique.
Traduit automatiquement de l'anglais · Voir l'original
In certain computer programming languages, the Elvis operator, often written ?:, is a binary operator that returns the first operand if its value is logically true (according to a language-dependent convention, in other words, a truthy value) or returns its second operand if the first operand is not true. That is, it is a short-circuit OR, which returns its first truthy operand.
Lire la suite
La syntaxe de l'opérateur Elvis s'inspire de l'opérateur conditionnel ternaire ? :, puisque l'expression A ?: B est approximativement équivalente à l'expression conditionnelle ternaire A ? A : B.
Traduit automatiquement depuis l'article en anglais
Texte : Wikipédia en anglais, traduction automatique, CC BY-SA 4.0. · Image : Tzali (CC0) ·