March 2014 update
This commit is contained in:
parent
09687c4926
commit
a25938f123
1846 changed files with 21876 additions and 5203 deletions
|
|
@ -0,0 +1,18 @@
|
|||
10 F$ = "SIN"
|
||||
20 DEF FN A(P) = ATN(P/SQR(-P*P+1))
|
||||
30 G$ = "FN A"
|
||||
40 GOSUB 100"COMPOSE
|
||||
50 SA$ = E$
|
||||
|
||||
60 X = .5 : E$ = SA$
|
||||
70 GOSUB 200"EXEC
|
||||
80 PRINT R
|
||||
90 END
|
||||
|
||||
100 E$ = F$ + "(" + G$ + "(X))" : RETURN : REMCOMPOSE F$ G$
|
||||
|
||||
200 D$ = CHR$(4) : FI$ = "TEMPORARY.EX" : M$ = CHR$(13)
|
||||
210 PRINT D$"OPEN"FI$M$D$"CLOSE"FI$M$D$"DELETE"FI$
|
||||
220 PRINT D$"OPEN"FI$M$D$"WRITE"FI$
|
||||
230 PRINT "CALL-998:CALL-958:R="E$":CONT"
|
||||
240 PRINT D$"CLOSE"FI$M$D$"EXEC"FI$:CALL-998:END:RETURN
|
||||
42
Task/Function-composition/Objective-C/function-composition.m
Normal file
42
Task/Function-composition/Objective-C/function-composition.m
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
#include <Foundation/Foundation.h>
|
||||
|
||||
typedef id (^Function)(id);
|
||||
|
||||
// a commodity for "encapsulating" double f(double)
|
||||
typedef double (*func_t)(double);
|
||||
Function encapsulate(func_t f) {
|
||||
return ^(id x) { return @(f([x doubleValue])); };
|
||||
}
|
||||
|
||||
Function compose(Function a, Function b) {
|
||||
return ^(id x) { return a(b(x)); };
|
||||
}
|
||||
|
||||
// functions outside...
|
||||
double my_f(double x)
|
||||
{
|
||||
return x+1.0;
|
||||
}
|
||||
|
||||
double my_g(double x)
|
||||
{
|
||||
return x*x;
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
@autoreleasepool {
|
||||
|
||||
Function f = encapsulate(my_f);
|
||||
Function g = encapsulate(my_g);
|
||||
|
||||
Function composed = compose(f, g);
|
||||
|
||||
printf("g(2.0) = %lf\n", [g(@2.0) doubleValue]);
|
||||
printf("f(2.0) = %lf\n", [f(@2.0) doubleValue]);
|
||||
printf("f(g(2.0)) = %lf\n", [composed(@2.0) doubleValue]);
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,3 +1,3 @@
|
|||
sub infix:<∘> (&f, &g --> Block) {
|
||||
-> $args { f g |$args }
|
||||
-> |args { f g |args }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue