langs a-z
This commit is contained in:
parent
db842d013d
commit
d066446780
11389 changed files with 98361 additions and 1020 deletions
14
Task/Logical-operations/Nemerle/logical-operations.nemerle
Normal file
14
Task/Logical-operations/Nemerle/logical-operations.nemerle
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
using System;
|
||||
using System.Console;
|
||||
|
||||
module Logical
|
||||
{
|
||||
WriteLogical(a : bool, b : bool) : void
|
||||
{
|
||||
WriteLine("{0} and {1} is {2}", a, b, a && b);
|
||||
WriteLine("{0} or {1} is {2}", a, b, a || b);
|
||||
WriteLine("not {0} is {1}", a, !a);
|
||||
}
|
||||
|
||||
Main() : void {WriteLogical(true, false)}
|
||||
}
|
||||
37
Task/Logical-operations/NetRexx/logical-operations.netrexx
Normal file
37
Task/Logical-operations/NetRexx/logical-operations.netrexx
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/* NetRexx */
|
||||
options replace format comments java crossref symbols binary
|
||||
|
||||
runSample(arg)
|
||||
return
|
||||
|
||||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
method logicalOperation(xL = boolean, xR = boolean) public static
|
||||
say showBool(xL) 'AND' showBool(xR) '=' showBool(xL & xR) -- AND
|
||||
say showBool(xL) 'OR ' showBool(xR) '=' showBool(xL | xR) -- OR
|
||||
say showBool(xL) 'XOR' showBool(xR) '=' showBool(xL && xR) -- XOR
|
||||
say ' ' 'NOT' showBool(xL) '=' showBool(\xL) -- NOT
|
||||
say
|
||||
return
|
||||
|
||||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
method showBool(bb = boolean) public static
|
||||
if bb then bt = 'true '
|
||||
else bt = 'false'
|
||||
return bt
|
||||
|
||||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
method runSample(arg) private static
|
||||
TRUE_ = (1 == 1)
|
||||
FALSE_ = \TRUE_
|
||||
lpairs = [ -
|
||||
[TRUE_, TRUE_ ], -
|
||||
[TRUE_, FALSE_], -
|
||||
[FALSE_, TRUE_ ], -
|
||||
[FALSE_, FALSE_] -
|
||||
]
|
||||
loop lx = 0 to lpairs.length - 1
|
||||
lpair = lpairs[lx]
|
||||
--say showBool(lpair[0]) showBool(lpair[1])
|
||||
logicalOperation(lpair[0], lpair[1])
|
||||
end lx
|
||||
return
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
(define (logic a b)
|
||||
(print "a and b is: " (and a b) "\n a or b is: " (or a b))
|
||||
(print "\n not a is: " (not a)))
|
||||
4
Task/Logical-operations/OCaml/logical-operations.ocaml
Normal file
4
Task/Logical-operations/OCaml/logical-operations.ocaml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
let print_logic a b =
|
||||
Printf.printf "a and b is %B\n" (a && b);
|
||||
Printf.printf "a or b is %B\n" (a || b);
|
||||
Printf.printf "not a is %B\n" (not a)
|
||||
11
Task/Logical-operations/Objeck/logical-operations.objeck
Normal file
11
Task/Logical-operations/Objeck/logical-operations.objeck
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
bundle Default {
|
||||
class Logic {
|
||||
function : Main(args : String[]) ~ Nil {
|
||||
a := true;
|
||||
b := false;
|
||||
IO.Console->GetInstance()->Print("a and b is: ")->PrintLine(a & b);
|
||||
IO.Console->GetInstance()->Print("a or b is: ")->PrintLine(a | b);
|
||||
IO.Console->GetInstance()->Print("not a is: ")->PrintLine(a <> true);
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Task/Logical-operations/Octave/logical-operations.octave
Normal file
13
Task/Logical-operations/Octave/logical-operations.octave
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
function test(a, b)
|
||||
s1 = num2str(a);
|
||||
s2 = num2str(b);
|
||||
disp(strcat(s1, " and ", s2, " = ", num2str(a&&b)));
|
||||
disp(strcat(s1, " or ", s2, " = ", num2str(a||b)));
|
||||
disp(strcat("not ", s1, " = ", num2str(!a)));
|
||||
endfunction
|
||||
|
||||
% constant true is 1, false is 0
|
||||
test(true, true);
|
||||
test(false, false);
|
||||
test(true, false);
|
||||
test(false, true);
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
FUNCTION testLogical RETURNS CHAR (
|
||||
i_l1 AS LOGICAL,
|
||||
i_l2 AS LOGICAL
|
||||
):
|
||||
|
||||
RETURN
|
||||
SUBSTITUTE( '&1 and &2: &3', i_l1, i_l2, i_l1 AND i_l2 ) + '~n' +
|
||||
SUBSTITUTE( '&1 or &2: &3', i_l1, i_l2, i_l1 OR i_l2 ) + '~n' +
|
||||
SUBSTITUTE( 'not &1: &2', i_l1, NOT i_l1 )
|
||||
.
|
||||
|
||||
END FUNCTION.
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
MESSAGE
|
||||
testLogical( FALSE, FALSE ) SKIP(1)
|
||||
testLogical( FALSE, TRUE ) SKIP(1)
|
||||
testLogical( TRUE, FALSE ) SKIP(1)
|
||||
testLogical( TRUE, TRUE ) SKIP(2)
|
||||
|
||||
testLogical( ?, ? ) SKIP(1)
|
||||
testLogical( ?, FALSE ) SKIP(1)
|
||||
testLogical( ?, TRUE ) SKIP(1)
|
||||
VIEW-AS ALERT-BOX.
|
||||
10
Task/Logical-operations/Oz/logical-operations.oz
Normal file
10
Task/Logical-operations/Oz/logical-operations.oz
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
proc {PrintLogic A B}
|
||||
%% using not short-circuiting standard library functions
|
||||
{Show {And A B}}
|
||||
{Show {Or A B}}
|
||||
{Show {Not A}}
|
||||
|
||||
%% using short-circuiting keywords
|
||||
{Show A andthen B}
|
||||
{Show A orelse B}
|
||||
end
|
||||
5
Task/Logical-operations/PARI-GP/logical-operations.pari
Normal file
5
Task/Logical-operations/PARI-GP/logical-operations.pari
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
logic(a,b)={
|
||||
print(a&b); \\ && is the same
|
||||
print(a|b); \\ || is the same
|
||||
print(!a);
|
||||
};
|
||||
8
Task/Logical-operations/PL-I/logical-operations.pli
Normal file
8
Task/Logical-operations/PL-I/logical-operations.pli
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
logical_ops: procedure (t, u);
|
||||
declare (t, u) bit (1);
|
||||
|
||||
put skip list (t & u);
|
||||
put skip list (t | u); /* logical or */
|
||||
put skip list (^t); /* logical not */
|
||||
put skip list (t ^ u); /* exclusive or */
|
||||
end logical_ops;
|
||||
6
Task/Logical-operations/Pascal/logical-operations.pascal
Normal file
6
Task/Logical-operations/Pascal/logical-operations.pascal
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
procedure printlogic(a, b: boolean);
|
||||
begin
|
||||
writeln('a and b is ', a and b);
|
||||
writeln('a or b is ', a or b);
|
||||
writeln('not a is', not a);
|
||||
end;
|
||||
29
Task/Logical-operations/Perl-6/logical-operations-1.pl6
Normal file
29
Task/Logical-operations/Perl-6/logical-operations-1.pl6
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
sub logic($a,$b) {
|
||||
say "$a && $b is ", $a && $b; # short-circuiting
|
||||
say "$a || $b is ", $a || $b; # short-circuiting
|
||||
say "$a ^^ $b is ", $a ^^ $b;
|
||||
say "!$a is ", !$a;
|
||||
|
||||
say "$a ?& $b is ", $a ?& $b; # non-short-circuiting
|
||||
say "$a ?| $b is ", $a ?| $b; # non-short-circuiting
|
||||
say "$a ?^ $b is ", $a ?^ $b; # non-short-circuiting
|
||||
|
||||
say "$a +& $b is ", $a +& $b; # numeric bitwise
|
||||
say "$a +| $b is ", $a +| $b; # numeric bitwise
|
||||
say "$a +^ $b is ", $a +^ $b; # numeric bitwise
|
||||
|
||||
say "$a ~& $b is ", $a ~& $b; # buffer bitwise
|
||||
say "$a ~| $b is ", $a ~| $b; # buffer bitwise
|
||||
say "$a ~^ $b is ", $a ~| $b; # buffer bitwise
|
||||
|
||||
say "$a & $b is ", $a & $b; # junctional/autothreading
|
||||
say "$a | $b is ", $a | $b; # junctional/autothreading
|
||||
say "$a ^ $b is ", $a ^ $b; # junctional/autothreading
|
||||
|
||||
say "$a and $b is ", ($a and $b); # loose short-circuiting
|
||||
say "$a or $b is ", ($a or $b); # loose short-circuiting
|
||||
say "$a xor $b is ", ($a xor $b);
|
||||
say "not $a is ", (not $a);
|
||||
}
|
||||
|
||||
logic(3,10);
|
||||
20
Task/Logical-operations/Perl-6/logical-operations-2.pl6
Normal file
20
Task/Logical-operations/Perl-6/logical-operations-2.pl6
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
3 && 10 is 10
|
||||
3 || 10 is 3
|
||||
3 ^^ 10 is
|
||||
!3 is 0
|
||||
3 ?& 10 is 1
|
||||
3 ?| 10 is 1
|
||||
3 ?^ 10 is 0
|
||||
3 +& 10 is 2
|
||||
3 +| 10 is 11
|
||||
3 +^ 10 is 9
|
||||
3 ~& 10 is 1
|
||||
3 ~| 10 is 30
|
||||
3 ~^ 10 is 30
|
||||
3 & 10 is all(3, 10)
|
||||
3 | 10 is any(3, 10)
|
||||
3 ^ 10 is one(3, 10)
|
||||
3 and 10 is 10
|
||||
3 or 10 is 3
|
||||
3 xor 10 is
|
||||
not 3 is 0
|
||||
5
Task/Logical-operations/Pop11/logical-operations-1.pop11
Normal file
5
Task/Logical-operations/Pop11/logical-operations-1.pop11
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
define print_logic(a, b);
|
||||
printf(a and b, 'a and b is %p\n');
|
||||
printf(a or b, 'a or b is %p\n');
|
||||
printf(not(a), 'not a is %p\n');
|
||||
enddefine;
|
||||
1
Task/Logical-operations/Pop11/logical-operations-2.pop11
Normal file
1
Task/Logical-operations/Pop11/logical-operations-2.pop11
Normal file
|
|
@ -0,0 +1 @@
|
|||
print_logic(true, false);
|
||||
7
Task/Logical-operations/PostScript/logical-operations.ps
Normal file
7
Task/Logical-operations/PostScript/logical-operations.ps
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
/logical{
|
||||
/a exch def
|
||||
/b exch def
|
||||
a b and =
|
||||
a b or =
|
||||
a not =
|
||||
}def
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
function Test-Boolean ([bool] $a, [bool] $b) {
|
||||
Write-Host "A and B: " ($a -and $b)
|
||||
Write-Host "A or B: " ($a -or $b)
|
||||
Write-Host "not A: " (-not $a)
|
||||
Write-Host "not A: " (!$a)
|
||||
Write-Host "A xor B: " ($a -xor $b)
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
Procedure LogicDebug(a,b)
|
||||
Debug a And b
|
||||
Debug a Or b
|
||||
Debug Not a
|
||||
Debug a XOr b
|
||||
EndProcedure
|
||||
13
Task/Logical-operations/REBOL/logical-operations.rebol
Normal file
13
Task/Logical-operations/REBOL/logical-operations.rebol
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
logics: func [a [logic!] b [logic!]] [
|
||||
print ['and tab a and b]
|
||||
print ['or tab a or b]
|
||||
print ['not tab not a]
|
||||
print ['xor tab a xor b]
|
||||
|
||||
print ['and~ tab and~ a b]
|
||||
print ['or~ tab or~ a b]
|
||||
print ['xor~ tab xor~ a b]
|
||||
|
||||
print ['any tab any [a b]]
|
||||
print ['all tab all [a b]]
|
||||
]
|
||||
10
Task/Logical-operations/RLaB/logical-operations-1.rlab
Normal file
10
Task/Logical-operations/RLaB/logical-operations-1.rlab
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
>> x = 5
|
||||
5
|
||||
>> y = 0
|
||||
0
|
||||
>> !x
|
||||
0
|
||||
>> !y
|
||||
1
|
||||
>> x && y
|
||||
0
|
||||
10
Task/Logical-operations/RLaB/logical-operations-2.rlab
Normal file
10
Task/Logical-operations/RLaB/logical-operations-2.rlab
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
>> x = int(5)
|
||||
5
|
||||
>> y = int(0)
|
||||
0
|
||||
>> !x
|
||||
-6
|
||||
>> !y
|
||||
-1
|
||||
>> x && y
|
||||
0
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
import IO;
|
||||
|
||||
public void logic(bool a, bool b){
|
||||
println("a and b, is <a && b>");
|
||||
println("a or b, is <a || b>");
|
||||
println("a equivalent to b, is <a <==> b>");
|
||||
println("a implies b, is <a ==> b>");
|
||||
println("not a", <!a>");
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
rascal>logic(false, false);
|
||||
|
||||
a and b, is false
|
||||
a or b, is false
|
||||
a equivalent to b, is true
|
||||
a implies b, is true
|
||||
not a, true
|
||||
ok
|
||||
6
Task/Logical-operations/Retro/logical-operations.retro
Normal file
6
Task/Logical-operations/Retro/logical-operations.retro
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
: .bool ( f- ) [ "true" ] [ "false" ] if puts cr ;
|
||||
: logic ( ab- )
|
||||
"\na = " puts over .bool "b = " puts dup .bool
|
||||
"\na and b = " puts 2dup and .bool
|
||||
"\na or b = " puts over or .bool
|
||||
"\nnot a = " puts not .bool ;
|
||||
6
Task/Logical-operations/Seed7/logical-operations.seed7
Normal file
6
Task/Logical-operations/Seed7/logical-operations.seed7
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
const proc: writeLogic (in boolean: a, in boolean: b) is func
|
||||
begin
|
||||
writeln("a and b is " <& a and b);
|
||||
writeln("a or b is " <& a or b);
|
||||
writeln("not a is " <& not a);
|
||||
end func;
|
||||
9
Task/Logical-operations/Slate/logical-operations-1.slate
Normal file
9
Task/Logical-operations/Slate/logical-operations-1.slate
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
{#/\. #\/. #not} do: [ |:func|
|
||||
func arity = 1 ifTrue: [inform: 'True ' ; (func as: String) ; ' = ' ; (func sendTo: {True}) printString.
|
||||
inform: 'False ' ; (func as: String) ; ' = ' ; (func sendTo: {False}) printString.].
|
||||
|
||||
func arity = 2
|
||||
ifTrue: [{{True. True}. {True. False}. {False. True}. {False. False}} do:
|
||||
[ |:each| inform: each first printString ; (func as: String) ; each second printString ; ' = ' ; (func sendTo: each) printString]]
|
||||
|
||||
].
|
||||
10
Task/Logical-operations/Slate/logical-operations-2.slate
Normal file
10
Task/Logical-operations/Slate/logical-operations-2.slate
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
True/\True = True
|
||||
True/\False = False
|
||||
False/\True = False
|
||||
False/\False = False
|
||||
True\/True = True
|
||||
True\/False = True
|
||||
False\/True = True
|
||||
False\/False = False
|
||||
True not = False
|
||||
False not = True
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
fun print_logic (a, b) = (
|
||||
print ("a and b is " ^ Bool.toString (a andalso b) ^ "\n");
|
||||
print ("a or b is " ^ Bool.toString (a orelse b) ^ "\n");
|
||||
print ("not a is " ^ Bool.toString (not a) ^ "\n")
|
||||
)
|
||||
7
Task/Logical-operations/Toka/logical-operations.toka
Normal file
7
Task/Logical-operations/Toka/logical-operations.toka
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
[ 0 <> [ ." true" ] [ ." false"] ifTrueFalse ] is .bool
|
||||
[ ( a b -- )
|
||||
cr ." a = " over .bool ." b = " dup .bool
|
||||
cr ." a and b = " 2dup and .bool
|
||||
cr ." a or b = " over or .bool
|
||||
cr ." not a = " 0 = .bool
|
||||
] is logic
|
||||
7
Task/Logical-operations/V/logical-operations-1.v
Normal file
7
Task/Logical-operations/V/logical-operations-1.v
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
[mylogic
|
||||
[get2 [dup] dip swap [dup] dip].
|
||||
get2 and puts
|
||||
get2 or puts
|
||||
swap not puts
|
||||
pop
|
||||
].
|
||||
7
Task/Logical-operations/V/logical-operations-2.v
Normal file
7
Task/Logical-operations/V/logical-operations-2.v
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
[mylogic
|
||||
[get2 [a b : a b a b] view].
|
||||
get2 and puts
|
||||
get2 or puts
|
||||
swap not puts
|
||||
pop
|
||||
].
|
||||
5
Task/Logical-operations/V/logical-operations-3.v
Normal file
5
Task/Logical-operations/V/logical-operations-3.v
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
[mylogic [a b] let
|
||||
a b and puts
|
||||
a b or puts
|
||||
a not puts
|
||||
].
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
Function Test(ByVal a As Boolean, ByVal b As Boolean)
|
||||
Console.WriteLine("And " & a And b)
|
||||
Console.WriteLine("Or " & a Or b)
|
||||
Console.WriteLine("Not " & Not a)
|
||||
Console.WriteLine("Xor " & a Xor b)
|
||||
Console.WriteLine("And, short-circuited " & a AndAlso b)
|
||||
Console.WriteLine("Or, short-circuited " & a OrElse b)
|
||||
End Function
|
||||
16
Task/Logical-operations/XPL0/logical-operations.xpl0
Normal file
16
Task/Logical-operations/XPL0/logical-operations.xpl0
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
include c:\cxpl\codes; \intrinsic 'code' declarations
|
||||
|
||||
func Logic(A, B);
|
||||
int A, B;
|
||||
[HexOut(0, A and B); ChOut(0, ^ );
|
||||
HexOut(0, A or B); ChOut(0, ^ );
|
||||
HexOut(0, not A); ChOut(0, ^ );
|
||||
HexOut(0, A xor B);
|
||||
]; \Logic
|
||||
|
||||
[Logic(false, false); CrLf(0);
|
||||
Logic(true, false); CrLf(0);
|
||||
Logic(true, true); CrLf(0);
|
||||
Logic(1, 1); CrLf(0);
|
||||
Logic(1, 2); CrLf(0);
|
||||
]
|
||||
6
Task/Logical-operations/XSLT/logical-operations.xslt
Normal file
6
Task/Logical-operations/XSLT/logical-operations.xslt
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<xsl:template name="logic">
|
||||
<xsl:param name="a" select="true()"/>
|
||||
<xsl:param name="b" select="false()"/>
|
||||
<fo:block>a and b = <xsl:value-of select="$a and $b"/></fo:block>
|
||||
<fo:block>a or b = <xsl:value-of select="$a or $b"/></fo:block>
|
||||
<fo:block>not a = <xsl:value-of select="not($a)"/></fo:block>
|
||||
Loading…
Add table
Add a link
Reference in a new issue