- ALGOL 68
- ANSI C
- AWK
- bit
- byte
- C++
- C99
- Church booleans
- Common Lisp
- comparison operator
- computer science
- data type
- Emacs Lisp
- Englewood Cliffs, NJ
- enumerated type
- Fortran
- George Boole
- if-then-else
- JavaScript
- lambda calculus
- list (computing)
- logic
- logical conjunction
- logical disjunction
- logical equivalence
- Microsoft Press
- Modula
- NaN
- negation
- Null (SQL)
- Objective-C
- Perl
- PHP
- Postgresql
- Prentice Hall
- primitive data type
- programming language
- s-expression
- scripting language
- set (computing)
- Shannon's expansion
- shell scripting
- Smalltalk
- SQL
- Stdbool.h
- truth value
- type coercion
- type-checked
- Visual Basic
- while loop
- −0
- Order: Reorder
- Duration: 5:53
- Published: 12 Apr 2011
- Uploaded: 26 Sep 2011
- Author: lecturesnippets
- Order: Reorder
- Duration: 8:21
- Published: 30 Aug 2009
- Uploaded: 24 Nov 2011
- Author: SchoolFreeware
- Order: Reorder
- Duration: 4:01
- Published: 04 Aug 2011
- Uploaded: 11 Sep 2011
- Author: EducatorVids
- Order: Reorder
- Duration: 4:01
- Published: 17 Aug 2011
- Uploaded: 07 Sep 2011
- Author: EducatorVids2
- Order: Reorder
- Duration: 5:27
- Published: 24 May 2011
- Uploaded: 26 Oct 2011
- Author: supereasytuts
- Order: Reorder
- Duration: 1:49
- Published: 10 Feb 2011
- Uploaded: 11 Oct 2011
- Author: programmingindepth
- Order: Reorder
- Duration: 4:50
- Published: 15 Jun 2009
- Uploaded: 15 Nov 2011
- Author: GaStateULibrary
- Order: Reorder
- Duration: 5:56
- Published: 14 Apr 2008
- Uploaded: 05 Nov 2011
- Author: TruthBeautyGoodness
- Order: Reorder
- Duration: 9:29
- Published: 02 Oct 2009
- Uploaded: 13 Jun 2011
- Author: davidranum
- Order: Reorder
- Duration: 5:57
- Published: 07 May 2011
- Uploaded: 03 Nov 2011
- Author: SchoolFreeware
- Order: Reorder
- Duration: 5:21
- Published: 22 Dec 2008
- Uploaded: 04 Dec 2011
- Author: NoNeedSkill
- Order: Reorder
- Duration: 11:02
- Published: 10 Jun 2011
- Uploaded: 16 Aug 2011
- Author: SkyeShatter
- Order: Reorder
- Duration: 5:54
- Published: 09 Nov 2011
- Uploaded: 29 Nov 2011
- Author: mybringback
- Order: Reorder
- Duration: 6:30
- Published: 02 Jul 2009
- Uploaded: 14 Jun 2011
- Author: javaprogrammer345
-
Iran files complaint over purported US drone
Al Jazeera
-
Forget Embassy Wars, the Real War Is Over Memory
WorldNews.com
-
Russians stage mass protests against Putin, polls
The Star
-
Defense Authorization Act Will Destroy The Bill Of Rights
WorldNews.com
-
Euro crisis summit: The night Europe changed
BBC News
- ALGOL 60
- ALGOL 68
- ANSI C
- AWK
- bit
- byte
- C++
- C99
- Church booleans
- Common Lisp
- comparison operator
- computer science
- data type
- Emacs Lisp
- Englewood Cliffs, NJ
- enumerated type
- Fortran
- George Boole
- if-then-else
- JavaScript
- lambda calculus
- list (computing)
- logic
- logical conjunction
- logical disjunction
- logical equivalence
- Microsoft Press
- Modula
- NaN
- negation
- Null (SQL)
- Objective-C
- Perl
- PHP
- Postgresql
- Prentice Hall
- primitive data type
- programming language
- s-expression
- scripting language
- set (computing)
- Shannon's expansion
- shell scripting
- Smalltalk
- SQL
- Stdbool.h
- truth value
- type coercion
- type-checked
- Visual Basic
- while loop
- −0
size: 1.8Kb
size: 8.6Kb
size: 7.6Kb
size: 5.1Kb
size: 2.0Kb
size: 5.9Kb
size: 6.3Kb
size: 3.2Kb
Implementations
In programming languages that have a built-in Boolean data type, such as Pascal and Java, the comparison operators such as '>' and '≠' are usually defined to return a Boolean value. Also, conditional and iterative commands may be defined to test Boolean-valued expressions.
Languages without an explicit Boolean data type, like C90 and Lisp, may still represent truth values by some other data type. Lisp uses an empty list for false, and any other value for true. C uses an integer type, where relational expressions like i > j
and logical expressions connected by &&
and ||
are defined to have value 1 if true and 0 if false, whereas the test parts of if
, while
, for
, etc., treat any non-zero value as true. Indeed, a Boolean variable may be regarded (and be implemented) as a numerical variable with a single binary digit (bit), which can store only two values.
Most programming languages, even those that do not have an explicit Boolean type, have support for Boolean algebraic operations such as conjunction (AND
, &
, *
), disjunction (OR
, |
, +
), equivalence (EQV
, =
, ==
), exclusive or/non-equivalence (XOR
, NEQV
, ^
, !=
), and not (NOT
, ~
, !
).
In some languages, like Ruby and Smalltalk, the "true" and "false" values belong to separate classes -- e.g. "True" and "False", respective -- so there is no single Boolean "type".
In some languages, the Boolean data type is defined to include more than two truth values. For instance the ISO SQL 1999 standard defined a Boolean value as being either true, false, or unknown (SQL null). Although this convention defies the law of excluded middle, it is often useful in programming.
In the lambda calculus model of computing, Boolean values can be represented as Church booleans.
History
One of the earliest languages to provide an explicit Boolean data type was ALGOL 60 (1960) with values true and false and logical operators denoted by symbols '' (and), '' (or), '' (implies), '' (equivalence), and '' (not). Due to input device limitations of the time, however, most compilers used alternative representations for the latter, such asAND
or 'AND'
. This approach ("Boolean is a separate built-in primitive data type") was adopted by many later languages, such as ALGOL 68 (1970), Java, and C#.
The first version of FORTRAN (1957) and its successor FORTRAN II (1958) did not have logical values or operations; even the conditional IF
statement took an arithmetic expression and branched to one of three locations according to its sign. FORTRAN IV (1962), however, followed the ALGOL 60 example by providing a Boolean data type (LOGICAL
), truth literals (.TRUE.
and .FALSE.
), Boolean-valued numeric comparison operators (.EQ.
, .GT.
, etc.), and logical operators (.NOT.
, .AND.
, .OR.
). In FORMAT
statements, a specific control character ('L
') was provided for the parsing or formatting of logical values.
The Lisp language (1958) never had a built-in Boolean data type. Instead, conditional constructs like cond
assume that the logical value "false" is represented by the empty list ()
, which is defined to be the same as the special atom nil
or NIL
; whereas any other s-expression is interpreted as "true". For convenience, most modern dialects of Lisp predefine the atom t
to have value t
, so that one can use t
as a mnemonic notation for "true". This approach ("any value can be used as a Boolean value") was retained in most Lisp dialects (Common Lisp, Scheme, Emacs Lisp), and similar models were adopted by many scripting languages, even ones that do have a distinct Boolean type or Boolean values; although which values are interpreted as "false" and which are "true" vary from language to language. In Scheme, for example, the "false" value is an atom distinct from the empty list, so the latter is interpreted as "true". In Python, a numeric value of zero (integer or fractional), the null value (None
), the empty string, and empty containers (i.e. lists, sets, etc.) are considered Boolean false; all other values are considered Boolean true by default. In Ruby, on the other hand, only the null object and a special false
object are "false", everything else (including the integer 0 and empty arrays) is "true". In JavaScript, the empty string (""
), null
, undefined
, NaN
, +0, −0 and false
are sometimes called "falsy", and their complement, "truthy", to distinguish between strictly type-checked and coerced Booleans. Languages such as PHP also use this approach.
The initial standards for the C language (1972) provided no Boolean type; and, to this day, Boolean values are commonly represented by integers (int
s) in C programs. The comparison operators ('>
', '==
', etc.) are defined to return a signed integer (int
) result, either zero (for false) or 1 (for true). The same convention is assumed by the logical operators ('&&
', '||
', '!
', etc.) and condition-testing statements ('if
', 'while
'). Thus logical values can be stored in integer variables, and used anywhere integers would be valid, including in indexing, arithmetic, parsing, and formatting. This approach ("Boolean values are just integers") was retained in all later versions of C. Some of its dialects, like C99 and Objective-C, provide standard definitions of a Boolean type as an integer type and macros for "false" and "true" as 0 and 1, respectively. Visual Basic uses a similar approach. C++ has a separate Boolean data type ('bool'
), but with automatic conversions from scalar and pointer values that are very similar to those of C. This approach was adopted also by many later languages, especially by some scripting ones such as AWK and Perl. One problem with this approach is that the tests if(t==TRUE){...}
and if(t)
are not equivalent. Python has a related situation, where the Boolean type, bool
is a subtype of the integer type, int
, and Booleans False and True act as 0 and 1, respectively, in arithmetic contexts.
The Pascal language (1978) introduced the concept of programmer-defined enumerated types. A built-in Boolean
data type was then provided as a predefined enumerated type with values FALSE
and TRUE
. By definition, all comparisons, logical operations, and conditional statements applied to and/or yielded Boolean
values. Otherwise, the Boolean
type had all the facilities which were available for enumerated types in general — such as ordering and use as indices. On the other hand, the conversion between Boolean
s and integers (or any other types) still required explicit tests or function calls, as in ALGOL 60. This approach ("Boolean is an enumerated type") was adopted by most later languages which had enumerated types, such as Modula, Ada and Haskell.
After enumerated types (enum
s) were added to the ANSI version of C (1989), many C programmers got used to defining their own Boolean types as such, for readability reasons. However, enumerated types are equivalent to integers according to the language standards; so the effective identity between Booleans and integers is still valid for C programs.
Special approaches
In recent versions of Python, user-defined objects may specify their truth value by providing a__bool__
method.
As of the 1999 standard, SQL specified a Boolean data type with four possible values: true, false, unknown or null. However, vendors could choose to equate the last two values. Because of this inconsistency most SQL implementations (with the notable exception of Postgresql) use other data types (like bit, byte, and character) to simulate Boolean values.
See also
References
Category:Boolean algebra Category:Data types Category:Primitive types Category:Articles with example ALGOL 68 code
cs:Boolean de:Boolesche Variable et:Tõeväärtus (andmetüüp) es:Tipo de dato lógico fr:Booléen ko:불린 자료형 it:Variabile booleana ms:Boolean ja:ブーリアン型 no:Boolsk variabel mhr:Логик тип pl:Logiczny typ danych pt:Booleano ro:Boolean (tip de date) ru:Логический тип sv:Boolesk datatyp th:ชนิดข้อมูลแบบบูล tr:Boole'ca uk:Логічний тип даних zh:布尔型This text is licensed under the Creative Commons CC-BY-SA License. This text was originally published on Wikipedia and was developed by the Wikipedia community.