Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -0,0 +1,13 @@
#include
"share/atspre_staload.hats"
fun app_to_0 (f: (int) -> int): int = f (0)
implement
main0 () =
{
//
val () = assertloc (app_to_0(lam(x) => x+1) = 1)
val () = assertloc (app_to_0(lam(x) => 10*(x+1)) = 10)
//
} (* end of [main0] *)

View file

@ -0,0 +1,25 @@
-- This handler takes a script object (singer)
-- with another handler (call).
on sing about topic by singer
call of singer for "Of " & topic & " I sing"
end sing
-- Define a handler in a script object,
-- then pass the script object.
script cellos
on call for what
say what using "Cellos"
end call
end script
sing about "functional programming" by cellos
-- Pass a different handler. This one is a closure
-- that uses a variable (voice) from its context.
on hire for voice
script
on call for what
say what using voice
end call
end script
end hire
sing about "closures" by (hire for "Pipe Organ")

View file

@ -3,7 +3,7 @@ Higher Order Functions is a room.
To decide which number is (N - number) added to (M - number) (this is addition):
decide on N + M.
To decide which number is (N - number) multiplied by (M - number) (this is multiplication):
To decide which number is multiply (N - number) by (M - number) (this is multiplication):
decide on N * M.
To demonstrate (P - phrase (number, number) -> number) as (title - text):

View file

@ -0,0 +1,34 @@
MODULE HOFuns;
IMPORT
NPCT:Tools,
Out;
TYPE
Formatter = PROCEDURE (s: STRING; len: LONGINT): STRING;
VAR
words: ARRAY 8 OF STRING;
PROCEDURE PrintWords(w: ARRAY OF STRING; format: Formatter);
VAR
i: INTEGER;
BEGIN
i := 0;
WHILE (i < LEN(words)) DO
Out.Object(format(words[i],16));
INC(i)
END;
Out.Ln
END PrintWords;
BEGIN
words[0] := "Al-Andalus";
words[1] := "contributed";
words[2] := "significantly";
words[3] := "to";
words[4] := "the";
words[5] := "field";
words[6] := "of";
words[7] := "medicine";
PrintWords(words,Tools.AdjustLeft);
PrintWords(words,Tools.AdjustCenter);
PrintWords(words,Tools.AdjustRight)
END HOFuns.