Another update from ingydotnet^djgoku

This commit is contained in:
Ingy döt Net 2015-11-18 06:14:39 +00:00
parent 91df62d461
commit 948b86eafa
7604 changed files with 108452 additions and 22726 deletions

View file

@ -0,0 +1,14 @@
procedure booleanOperations( logical value a, b ) ;
begin
% algol W has the usual "and", "or" and "not" operators %
write( a, " and ", b, ": ", a and b );
write( a, " or ", b, ": ", a or b );
write( " not ", a, ": ", not a );
% logical values can be compared with the = and not = operators %
% a not = b can be used for a xor b %
write( a, " xor ", b, ": ", a not = b );
write( a, " equ ", b, ": ", a = b );
end booleanOperations ;

View file

@ -0,0 +1,6 @@
iex(1)> true and false
false
iex(2)> false or true
true
iex(3)> not false
true

View file

@ -0,0 +1,14 @@
(28)> nil || 23
23
iex(29)> [] || false
[]
iex(30)> nil && true
nil
iex(31)> 0 && 15
15
iex(32)> ! true
false
iex(33)> ! nil
true
iex(34)> ! 3.14
false

View file

@ -0,0 +1,14 @@
function exerciselogic(a::Bool, b::Bool)
st = @sprintf " %5s" a
st *= @sprintf " %5s" b
st *= @sprintf " %5s" ~a
st *= @sprintf " %5s" a | b
st *= @sprintf " %5s" a & b
st *= @sprintf " %5s" a $ b
end
println("Julia's logical operations on Bool:")
println(" a b not or and xor")
for a in [true, false], b in [true, false]
println(exerciselogic(a, b))
end

View file

@ -0,0 +1,13 @@
fn boolean_ops(a: bool, b: bool) {
println!("{} and {} -> {}", a, b, a && b);
println!("{} or {} -> {}", a, b, a || b);
println!("{} xor {} -> {}", a, b, a ^ b);
println!("not {} -> {}\n", a, !a);
}
fn main() {
boolean_ops(true, true);
boolean_ops(true, false);
boolean_ops(false, true);
boolean_ops(false, false)
}

View file

@ -0,0 +1,4 @@
true not = false.
( true && false ) = false.
( true ^^ false ) = true. "xor"
( true || false ) = true. "or"