B
This commit is contained in:
parent
e5e8880e41
commit
518da4a923
1019 changed files with 15877 additions and 0 deletions
4
Task/Boolean-values/0DESCRIPTION
Normal file
4
Task/Boolean-values/0DESCRIPTION
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
Show how to represent the boolean states "true" and "false" in a language. If other objects represent "true" or "false" in conditionals, note it.
|
||||
|
||||
;Cf.
|
||||
* [[Logical operations]]
|
||||
2
Task/Boolean-values/1META.yaml
Normal file
2
Task/Boolean-values/1META.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
note: Basic language learning
|
||||
30
Task/Boolean-values/ALGOL-68/boolean-values.alg
Normal file
30
Task/Boolean-values/ALGOL-68/boolean-values.alg
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
BOOL f = FALSE, t = TRUE;
|
||||
[]BOOL ft = (f, t);
|
||||
STRING or = " or ";
|
||||
FOR key TO UPB ft DO
|
||||
BOOL val = ft[key];
|
||||
UNION(VOID, INT) void = (val|666|EMPTY);
|
||||
REF STRING ref = (val|HEAP STRING|NIL);
|
||||
INT int = ABS val;
|
||||
REAL real = ABS val;
|
||||
COMPL compl = ABS val;
|
||||
BITS bits = BIN ABS val; # or bitspack(val); #
|
||||
BYTES bytes = bytes pack((val|"?"|null char)*bytes width);
|
||||
CHAR char = (val|"?"|null char);
|
||||
STRING string = (val|"?"|"");
|
||||
|
||||
print((((val | "TRUE" | "FALSE" ), ": ", val, or, (val|flip|flop), new line)));
|
||||
print((" void: ", " => ", (void|(VOID):FALSE|TRUE), new line));
|
||||
print((" ref: ", " => ", ref ISNT REF STRING(NIL), new line));
|
||||
print((" int: ", int , " => ", int /= 0, new line));
|
||||
print((" real: ", real , " => ", real /= 0, new line));
|
||||
print((" compl: ", compl , " => ", compl /= 0, new line));
|
||||
print((" bits: ", bits , " => ", ABS bits /= 0, or, bits /= 2r0, or,
|
||||
bits width ELEM bits, or, []BOOL(bits)[bits width], new line));
|
||||
print((" bytes: """, STRING(bytes) , """ => ", 1 ELEM bytes /= null char, or,
|
||||
STRING(bytes) /= null char*bytes width, or,
|
||||
STRING(bytes)[1] /= null char, new line));
|
||||
print((" char: """, char , """ => ", ABS char /= 0 , or, char /= null char, new line));
|
||||
print(("string: """, string , """ => ", string /= "", or, UPB string /= 0, new line));
|
||||
print((new line))
|
||||
OD
|
||||
18
Task/Boolean-values/AWK/boolean-values.awk
Normal file
18
Task/Boolean-values/AWK/boolean-values.awk
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
BEGIN {
|
||||
# Do not put quotes round the numeric values, or the tests will fail
|
||||
a = 1 # True
|
||||
b = 0 # False
|
||||
|
||||
# Boolean evaluations
|
||||
if (a) { print "first test a is true" } # This should print
|
||||
if (b) { print "second test b is true" } # This should not print
|
||||
if (!a) { print "third test a is false" } # This should not print
|
||||
if (!b) { print "forth test b is false" } # This should print
|
||||
|
||||
# Boolean evaluation using comparison against zero
|
||||
if (a == 0) { print "fifth test a is false" } # This should not print
|
||||
if (b == 0) { print "sixth test b is false" } # This should print
|
||||
if (a != 0) { print "seventh test a is true" } # This should print
|
||||
if (b != 0) { print "eighth test b is true" } # This should not print
|
||||
|
||||
}
|
||||
1
Task/Boolean-values/Ada/boolean-values.ada
Normal file
1
Task/Boolean-values/Ada/boolean-values.ada
Normal file
|
|
@ -0,0 +1 @@
|
|||
type Boolean is (False, True);
|
||||
11
Task/Boolean-values/BASIC/boolean-values.bas
Normal file
11
Task/Boolean-values/BASIC/boolean-values.bas
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
10 LET A%=0
|
||||
20 LET B%=NOT(A%)
|
||||
30 PRINT "THIS VERSION OF BASIC USES"
|
||||
40 PRINT B%; " AS ITS TRUE VALUE"
|
||||
50 IF A% THEN PRINT "TEST ONE DOES NOT PRINT"
|
||||
60 IF B% THEN PRINT "TEST TWO DOES PRINT"
|
||||
70 IF A%=0 THEN PRINT "TEST THREE (FALSE BY COMPARISON) DOES PRINT"
|
||||
80 IF B%=0 THEN PRINT "TEST FOUR (FALSE BY COMPARISON) DOES NOT PRINT"
|
||||
90 IF A%<>0 THEN PRINT "TEST FIVE (TRUE BY COMPARISON) DOES NOT PRINT"
|
||||
100 IF B%<>0 THEN PRINT "TEST SIX (TRUE BY COMPARISON) DOES PRINT"
|
||||
110 END
|
||||
7
Task/Boolean-values/BASIC256/boolean-values.basic256
Normal file
7
Task/Boolean-values/BASIC256/boolean-values.basic256
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
' BASIC256 used numbers to represent true and false
|
||||
' values. Zero is false and anything else is true.
|
||||
' The built in constants true and false exist
|
||||
' and represent one and zero respectively.
|
||||
|
||||
print false
|
||||
print true
|
||||
5
Task/Boolean-values/BBC-BASIC/boolean-values.bbc
Normal file
5
Task/Boolean-values/BBC-BASIC/boolean-values.bbc
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
REM BBC BASIC uses integers to represent Booleans; the keywords
|
||||
REM FALSE and TRUE equate to 0 and -1 (&FFFFFFFF) respectively:
|
||||
|
||||
PRINT FALSE
|
||||
PRINT TRUE
|
||||
28
Task/Boolean-values/CoffeeScript/boolean-values.coffee
Normal file
28
Task/Boolean-values/CoffeeScript/boolean-values.coffee
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
h1 = {foo: "bar"}
|
||||
h2 = {foo: "bar"}
|
||||
|
||||
true_expressions = [
|
||||
true
|
||||
1
|
||||
h1? # because h1 is defined above
|
||||
not false
|
||||
!false
|
||||
[]
|
||||
{}
|
||||
1 + 1 == 2
|
||||
1 == 1 # simple value equality
|
||||
true or false
|
||||
]
|
||||
|
||||
false_expressions = [
|
||||
false
|
||||
not true
|
||||
undeclared_variable?
|
||||
0
|
||||
''
|
||||
null
|
||||
undefined
|
||||
h1 == h2 # despite having same key/values
|
||||
1 == "1" # different types
|
||||
false and true
|
||||
]
|
||||
6
Task/Boolean-values/Erlang/boolean-values.erl
Normal file
6
Task/Boolean-values/Erlang/boolean-values.erl
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
1> 1 < 2.
|
||||
true
|
||||
2> 1 < 1.
|
||||
false
|
||||
3> 0 == false.
|
||||
false
|
||||
2
Task/Boolean-values/Forth/boolean-values.fth
Normal file
2
Task/Boolean-values/Forth/boolean-values.fth
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
TRUE . \ -1
|
||||
FALSE . \ 0
|
||||
1
Task/Boolean-values/Haskell/boolean-values.hs
Normal file
1
Task/Boolean-values/Haskell/boolean-values.hs
Normal file
|
|
@ -0,0 +1 @@
|
|||
data Bool = False | True deriving (Eq, Ord, Enum, Read, Show, Bounded)
|
||||
6
Task/Boolean-values/Lua/boolean-values.lua
Normal file
6
Task/Boolean-values/Lua/boolean-values.lua
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
if 0 then print "0" end -- This prints
|
||||
if "" then print"empty string" end -- This prints
|
||||
if {} then print"empty table" end -- This prints
|
||||
if nil then print"this won't print" end
|
||||
if true then print"true" end
|
||||
if false then print"false" end -- This does not print
|
||||
35
Task/Boolean-values/MATLAB/boolean-values.m
Normal file
35
Task/Boolean-values/MATLAB/boolean-values.m
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
>> islogical(true)
|
||||
|
||||
ans =
|
||||
|
||||
1
|
||||
|
||||
>> islogical(false)
|
||||
|
||||
ans =
|
||||
|
||||
1
|
||||
|
||||
>> islogical(logical(1))
|
||||
|
||||
ans =
|
||||
|
||||
1
|
||||
|
||||
>> islogical(logical(0))
|
||||
|
||||
ans =
|
||||
|
||||
1
|
||||
|
||||
>> islogical(1)
|
||||
|
||||
ans =
|
||||
|
||||
0
|
||||
|
||||
>> islogical(0)
|
||||
|
||||
ans =
|
||||
|
||||
0
|
||||
2
Task/Boolean-values/Perl/boolean-values-1.pl
Normal file
2
Task/Boolean-values/Perl/boolean-values-1.pl
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
my $x = 0.0;
|
||||
my $true_or_false = $x ? 'true' : 'false'; # false
|
||||
10
Task/Boolean-values/Perl/boolean-values-2.pl
Normal file
10
Task/Boolean-values/Perl/boolean-values-2.pl
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
my $x = 1; # true
|
||||
|
||||
my $true_or_false;
|
||||
|
||||
if ($x) {
|
||||
$true_or_false = 'true';
|
||||
}
|
||||
else {
|
||||
$true_or_false = 'false';
|
||||
}
|
||||
5
Task/Boolean-values/Perl/boolean-values-3.pl
Normal file
5
Task/Boolean-values/Perl/boolean-values-3.pl
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
print (7 && 2); # 2, rather than 1(true)
|
||||
print (2 && 7); # 7, rather than 1(true)
|
||||
print (7 xor 2); # empty string, rather than 0(false)
|
||||
print ('apples' && 'pears'); # pears, rather than 1(true)
|
||||
print ('apples' xor 'pears'); # empty string, rather than 0(false)
|
||||
5
Task/Boolean-values/Perl/boolean-values-4.pl
Normal file
5
Task/Boolean-values/Perl/boolean-values-4.pl
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# This does not work
|
||||
# true and false are not special so will be treated as bareword strings
|
||||
if (true) { print "true is true\n" }; # This prints
|
||||
if (false) { print "false is true\n" }; # So does this
|
||||
if (spongebob) { print "spongebob is true\n" }; # A bareword string
|
||||
39
Task/Boolean-values/Python/boolean-values.py
Normal file
39
Task/Boolean-values/Python/boolean-values.py
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
>>> True
|
||||
True
|
||||
>>> not True
|
||||
False
|
||||
>>> # As numbers
|
||||
>>> False + 0
|
||||
0
|
||||
>>> True + 0
|
||||
1
|
||||
>>> False + 0j
|
||||
0j
|
||||
>>> True * 3.141
|
||||
3.141
|
||||
>>> # Numbers as booleans
|
||||
>>> not 0
|
||||
True
|
||||
>>> not not 0
|
||||
False
|
||||
>>> not 1234
|
||||
False
|
||||
>>> bool(0.0)
|
||||
False
|
||||
>>> bool(0j)
|
||||
False
|
||||
>>> bool(1+2j)
|
||||
True
|
||||
>>> # Collections as booleans
|
||||
>>> bool([])
|
||||
False
|
||||
>>> bool([None])
|
||||
True
|
||||
>>> 'I contain something' if (None,) else 'I am empty'
|
||||
'I contain something'
|
||||
>>> bool({})
|
||||
False
|
||||
>>> bool("")
|
||||
False
|
||||
>>> bool("False")
|
||||
True
|
||||
2
Task/Boolean-values/REXX/boolean-values-1.rexx
Normal file
2
Task/Boolean-values/REXX/boolean-values-1.rexx
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
true = 1
|
||||
false = 0
|
||||
2
Task/Boolean-values/REXX/boolean-values-2.rexx
Normal file
2
Task/Boolean-values/REXX/boolean-values-2.rexx
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
true = (1=1)
|
||||
false = (1=0)
|
||||
2
Task/Boolean-values/REXX/boolean-values-3.rexx
Normal file
2
Task/Boolean-values/REXX/boolean-values-3.rexx
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
true = (1==1)
|
||||
false = (1==0)
|
||||
2
Task/Boolean-values/REXX/boolean-values-4.rexx
Normal file
2
Task/Boolean-values/REXX/boolean-values-4.rexx
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
true = (1==1)
|
||||
false = \true
|
||||
1
Task/Boolean-values/REXX/boolean-values-5.rexx
Normal file
1
Task/Boolean-values/REXX/boolean-values-5.rexx
Normal file
|
|
@ -0,0 +1 @@
|
|||
false = ¬true
|
||||
4
Task/Boolean-values/REXX/boolean-values-6.rexx
Normal file
4
Task/Boolean-values/REXX/boolean-values-6.rexx
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
true = 1984 = 1984
|
||||
false = 'war' = 'peace'
|
||||
false = 'freedom' = 'slavery'
|
||||
false = 'ignorance' = 'strength'
|
||||
3
Task/Boolean-values/Racket/boolean-values.rkt
Normal file
3
Task/Boolean-values/Racket/boolean-values.rkt
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
(cond ([(< 4 3) 'apple]
|
||||
['bloggle 'pear]
|
||||
[else 'nectarine])
|
||||
2
Task/Boolean-values/SNUSP/boolean-values.snusp
Normal file
2
Task/Boolean-values/SNUSP/boolean-values.snusp
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
$!/?\=false= + =true=#
|
||||
\-/
|
||||
7
Task/Boolean-values/Sather/boolean-values.sa
Normal file
7
Task/Boolean-values/Sather/boolean-values.sa
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
v:BOOL := true; -- ok
|
||||
i:INT := 1;
|
||||
v := 1; -- wrong
|
||||
if i then ... end; -- wrong: if requires a bool!
|
||||
-- BUT
|
||||
v := 1.bool; -- ok
|
||||
if i.bool then ... end; -- ok
|
||||
2
Task/Boolean-values/Tcl/boolean-values-1.tcl
Normal file
2
Task/Boolean-values/Tcl/boolean-values-1.tcl
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
% if {""} then {puts true} else {puts false}
|
||||
expected boolean value but got ""
|
||||
1
Task/Boolean-values/Tcl/boolean-values-2.tcl
Normal file
1
Task/Boolean-values/Tcl/boolean-values-2.tcl
Normal file
|
|
@ -0,0 +1 @@
|
|||
if {[string is false -strict $string]} ...
|
||||
Loading…
Add table
Add a link
Reference in a new issue