langs a-z
This commit is contained in:
parent
db842d013d
commit
d066446780
11389 changed files with 98361 additions and 1020 deletions
|
|
@ -0,0 +1,12 @@
|
|||
// point of interest: the when keyword and && operator inside the macro definition are macros themselves
|
||||
|
||||
macro if2 (cond1, cond2, bodyTT, bodyTF, bodyFT, bodyFF)
|
||||
syntax ("if2", "(", cond1, ")", "(", cond2, ")", bodyTT, "elseTF", bodyTF, "elseFT", bodyFT, "else", bodyFF)
|
||||
{
|
||||
<[
|
||||
when($cond1 && $cond2) {$bodyTT};
|
||||
when($cond1 && !($cond2)) {$bodyTF};
|
||||
when(!($cond1) && $cond2) {$bodyFT};
|
||||
when(!($cond1) && !($cond2)) {$bodyFF};
|
||||
]>
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
using System;
|
||||
using System.Console;
|
||||
|
||||
module UseIf2
|
||||
{
|
||||
Main() : void
|
||||
{
|
||||
def happy = true;
|
||||
def knowit = false;
|
||||
|
||||
if2 (happy) (knowit)
|
||||
Write("Clap hands")
|
||||
elseTF
|
||||
Write("You're happy")
|
||||
elseFT
|
||||
Write("Cheer up")
|
||||
else
|
||||
Write("You're unhappy, cheer up");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
(context 'if2)
|
||||
|
||||
(define-macro (if2:if2 cond1 cond2 both-true first-true second-true neither)
|
||||
(cond
|
||||
((eval cond1)
|
||||
(if (eval cond2)
|
||||
(eval both-true)
|
||||
(eval first-true)))
|
||||
((eval cond2)
|
||||
(eval second-true))
|
||||
(true
|
||||
(eval neither))))
|
||||
|
||||
(context MAIN)
|
||||
|
||||
> (if2 true true 'bothTrue 'firstTrue 'secondTrue 'else)
|
||||
bothTrue
|
||||
> (if2 true false 'bothTrue 'firstTrue 'secondTrue 'else)
|
||||
firstTrue
|
||||
> (if2 false true 'bothTrue 'firstTrue 'secondTrue 'else)
|
||||
secondTrue
|
||||
> (if2 false false 'bothTrue 'firstTrue 'secondTrue 'else)
|
||||
else
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
if2(c1,c2,tt,tf,ft,ff)={
|
||||
if(c1,
|
||||
if(c2,tt,tf)
|
||||
,
|
||||
if(c2,ft,ff)
|
||||
)
|
||||
};
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
GEN
|
||||
if2(GEN c1, GEN c2, GEN tt, GEN tf, GEN ft, GEN ff)
|
||||
{
|
||||
if (gequal0(c1))
|
||||
if (gequal0(c2))
|
||||
return ff ? closure_evalgen(ff) : gnil;
|
||||
else
|
||||
return ft ? closure_evalgen(ft) : gnil;
|
||||
else
|
||||
if (gequal0(c2))
|
||||
return tf ? closure_evalgen(tf) : gnil;
|
||||
else
|
||||
return tt ? closure_evalgen(tt) : gnil;
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
install("if2","GGDEDEDEDE","if2","./if2.gp.so");
|
||||
addhelp(if2, "if2(a,b,{seq1},{seq2},{seq3},{seq4}): if a is nonzero and b is nonzero, seq1 is evaluated; if a is nonzero and b is zero, seq2 is evaluated; if a is zero and b is nonzero, seq3 is evaluated; otherwise seq4. seq1 through seq4 are optional.");
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
/*
|
||||
GP;install("if2","GGDEDEDEDE","if2","./if2.gp.so");
|
||||
GP;addhelp(if2, "if2(a,b,{seq1},{seq2},{seq3},{seq4}): if a is nonzero and b is nonzero, seq1 is evaluated; if a is nonzero and b is zero, seq2 is evaluated; if a is zero and b is nonzero, seq3 is evaluated; otherwise seq4. seq1 through seq4 are optional.");
|
||||
*/
|
||||
24
Task/Extend-your-language/Perl-6/extend-your-language.pl6
Normal file
24
Task/Extend-your-language/Perl-6/extend-your-language.pl6
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
my &if2 = -> \a, \b, &x { my @*IF2 = ?a,?b; x }
|
||||
|
||||
my &if-both = -> &x { x if @*IF2 ~~ (True,True) }
|
||||
my &if-first = -> &x { x if @*IF2 ~~ (True,False) }
|
||||
my &if-second = -> &x { x if @*IF2 ~~ (False,True) }
|
||||
my &if-neither = -> &x { x if @*IF2 ~~ (False,False)}
|
||||
|
||||
sub test ($a,$b) {
|
||||
$_ = "G"; # Demo correct scoping of topic.
|
||||
my $got = "o"; # Demo correct scoping of lexicals.
|
||||
my $*got = "t"; # Demo correct scoping of dynamics.
|
||||
|
||||
if2 $a, $b, {
|
||||
if-both { say "$_$got$*got both" }
|
||||
if-first { say "$_$got$*got first" }
|
||||
if-second { say "$_$got$*got second" }
|
||||
if-neither { say "$_$got$*got neither" }
|
||||
}
|
||||
}
|
||||
|
||||
test 1,1;
|
||||
test 1,0;
|
||||
test 0,1;
|
||||
test 0,0;
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
: 4wayIf ( flag flag both neither first second )
|
||||
heap [ cons &cons dip [ [ cons ] dip ] dip rot ] preserve
|
||||
[ do [ -1 = ] bi@ and ] [ 2drop do drop do ] when
|
||||
[ do [ 0 = ] bi@ and ] [ 2drop do nip do ] when
|
||||
[ do 0 = swap -1 = and ] [ drop nip do drop do ] when
|
||||
[ do -1 = swap 0 = and ] [ drop nip do nip do ] when
|
||||
drop 2drop ;
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
: test
|
||||
-1 -1 [ 1 ] [ 2 ] [ 3 ] [ 4 ] 4wayIf .s drop
|
||||
0 0 [ 1 ] [ 2 ] [ 3 ] [ 4 ] 4wayIf .s drop
|
||||
-1 0 [ 1 ] [ 2 ] [ 3 ] [ 4 ] 4wayIf .s drop
|
||||
0 -1 [ 1 ] [ 2 ] [ 3 ] [ 4 ] 4wayIf .s drop ;
|
||||
39
Task/Extend-your-language/Seed7/extend-your-language.seed7
Normal file
39
Task/Extend-your-language/Seed7/extend-your-language.seed7
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
$ include "seed7_05.s7i";
|
||||
|
||||
$ syntax expr: .if.().().then.().else1.().else2.().else3.().end.if is -> 25;
|
||||
|
||||
const proc: if (in boolean: cond1) (in boolean: cond2) then
|
||||
(in proc: statements1)
|
||||
else1
|
||||
(in proc: statements2)
|
||||
else2
|
||||
(in proc: statements3)
|
||||
else3
|
||||
(in proc: statements4)
|
||||
end if is func
|
||||
begin
|
||||
if cond1 then
|
||||
if cond2 then
|
||||
statements1;
|
||||
else
|
||||
statements2;
|
||||
end if;
|
||||
elsif cond2 then
|
||||
statements3;
|
||||
else
|
||||
statements4;
|
||||
end if;
|
||||
end func;
|
||||
|
||||
const proc: main is func
|
||||
begin
|
||||
if TRUE FALSE then
|
||||
writeln("error TRUE TRUE");
|
||||
else1
|
||||
writeln("TRUE FALSE");
|
||||
else2
|
||||
writeln("error FALSE TRUE");
|
||||
else3
|
||||
writeln("error FALSE FALSE");
|
||||
end if;
|
||||
end func;
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
if2() {
|
||||
if eval "$1"; then
|
||||
if eval "$2"; then eval "$3"; else eval "$4"; fi
|
||||
else
|
||||
if eval "$2"; then eval "$5"; else eval "$6"; fi
|
||||
fi
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
if2 'test 7 -lt 9' 'test 7 -gt 9' '
|
||||
echo both 1 and 2
|
||||
' '
|
||||
echo 1 but not 2
|
||||
' '
|
||||
echo 2 but not 1
|
||||
' '
|
||||
echo neither 1 nor 2
|
||||
'
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
fn if2 cond1 cond2 body11 body10 body01 body00 {
|
||||
# Must evaluate both conditions, and should do so in order.
|
||||
# Negation ensures a boolean result: a true condition becomes
|
||||
# 1 for false; a false condition becomes 0 for true.
|
||||
let (c1 = <={! $cond1}; c2 = <={! $cond2}) {
|
||||
# Use those values to pick the body to evaluate.
|
||||
$(body$c1$c2)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
if2 {test 1 -gt 0} {~ grill foo bar boo} {
|
||||
echo 1 and 2
|
||||
} {
|
||||
echo 1 but not 2
|
||||
} {
|
||||
echo 2 but not 1
|
||||
} {
|
||||
echo neither 1 nor 2
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
iftwo("p","q") <"both","justp","justq","neither"> =
|
||||
|
||||
"p"?(
|
||||
"q"?("both","justp"),
|
||||
"q"?("justq","neither"))
|
||||
Loading…
Add table
Add a link
Reference in a new issue