langs a-z

This commit is contained in:
Ingy döt Net 2013-04-10 22:43:41 -07:00
parent db842d013d
commit d066446780
11389 changed files with 98361 additions and 1020 deletions

View 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)}
}

View 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

View file

@ -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)))

View 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)

View 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);
}
}
}

View 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);

View file

@ -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.

View file

@ -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.

View 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

View file

@ -0,0 +1,5 @@
logic(a,b)={
print(a&b); \\ && is the same
print(a|b); \\ || is the same
print(!a);
};

View 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;

View 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;

View 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);

View 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

View 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;

View file

@ -0,0 +1 @@
print_logic(true, false);

View file

@ -0,0 +1,7 @@
/logical{
/a exch def
/b exch def
a b and =
a b or =
a not =
}def

View file

@ -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)
}

View file

@ -0,0 +1,6 @@
Procedure LogicDebug(a,b)
Debug a And b
Debug a Or b
Debug Not a
Debug a XOr b
EndProcedure

View 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]]
]

View file

@ -0,0 +1,10 @@
>> x = 5
5
>> y = 0
0
>> !x
0
>> !y
1
>> x && y
0

View file

@ -0,0 +1,10 @@
>> x = int(5)
5
>> y = int(0)
0
>> !x
-6
>> !y
-1
>> x && y
0

View file

@ -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>");
}

View file

@ -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

View 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 ;

View 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;

View 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]]
].

View 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

View file

@ -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")
)

View 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

View file

@ -0,0 +1,7 @@
[mylogic
[get2 [dup] dip swap [dup] dip].
get2 and puts
get2 or puts
swap not puts
pop
].

View file

@ -0,0 +1,7 @@
[mylogic
[get2 [a b : a b a b] view].
get2 and puts
get2 or puts
swap not puts
pop
].

View file

@ -0,0 +1,5 @@
[mylogic [a b] let
a b and puts
a b or puts
a not puts
].

View file

@ -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

View 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);
]

View 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>