Data update

This commit is contained in:
Ingy döt Net 2026-02-01 16:33:20 -08:00
parent 5150844a7d
commit 4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions

View file

@ -1,50 +0,0 @@
with Ada.Text_IO;
procedure Partial_Function_Application is
type Sequence is array(Positive range <>) of Integer;
-- declare a function FS with a generic parameter F and a normal parameter S
generic
with function F(I: Integer) return Integer; -- generic parameter
function FS (S: Sequence) return Sequence;
-- define FS
function FS (S: Sequence) return Sequence is
Result: Sequence(S'First .. S'Last);
begin
for Idx in S'Range loop
Result(Idx) := F(S(Idx));
end loop;
return Result;
end FS;
-- define functions F1 and F2
function F1(I: Integer) return Integer is
begin
return 2*I;
end F1;
function F2(I: Integer) return Integer is
begin
return I**2;
end F2;
-- instantiate the function FS by F1 and F2 (partially apply F1 and F2 to FS)
function FSF1 is new FS(F1);
function FSF2 is new FS(F2);
procedure Print(S: Sequence) is
begin
for Idx in S'Range loop
Ada.Text_IO.Put(Integer'Image(S(Idx)));
end loop;
Ada.Text_IO.New_Line;
end Print;
begin
Print(FSF1((0,1,2,3)));
Print(FSF2((0,1,2,3)));
Print(FSF1((2,4,6,8)));
Print(FSF2((2,4,6,8)));
end Partial_Function_Application;

View file

@ -2,7 +2,7 @@ import system'collections;
import system'routines;
import extensions;
public program()
public Program()
{
var partial := (afs,af => (s => afs(af, s)));
@ -13,6 +13,6 @@ public program()
var fsf1 := partial(fs, f1);
var fsf2 := partial(fs, f2);
console.printLine(fsf1(new int[]{2,4,6,8}).toString());
console.printLine(fsf2(new int[]{2,4,6,8}).toString())
Console.printLine(fsf1(new int[]{2,4,6,8}).toString());
Console.printLine(fsf2(new int[]{2,4,6,8}).toString())
}

View file

@ -1,20 +0,0 @@
var f1 = function (x) { return x * 2; },
f2 = function (x) { return x * x; },
fs = function (f, s) {
return function (s) {
return s.map(f);
}
},
fsf1 = fs(f1),
fsf2 = fs(f2);
// Test
[
fsf1([0, 1, 2, 3]),
fsf2([0, 1, 2, 3]),
fsf1([2, 4, 6, 8]),
fsf2([2, 4, 6, 8])
]

View file

@ -1,21 +0,0 @@
var f1 = function (x) { return x * 2; },
f2 = function (x) { return x * x; },
fs = function (f) {
return function () {
return Array.prototype.slice.call(
arguments
).map(f);
}
},
fsf1 = fs(f1),
fsf2 = fs(f2);
// Test alternative approach, with arbitrary numbers of arguments
[
fsf1(0, 1, 2, 3, 4),
fsf2(0, 1, 2),
fsf1(2, 4, 6, 8, 10, 12),
fsf2(2, 4, 6, 8)
]

View file

@ -1,32 +0,0 @@
(() => {
'use strict';
// GENERIC FUNCTIONS ------------------------------------------------------
// curry :: ((a, b) -> c) -> a -> b -> c
const curry = f => a => b => f(a, b);
// map :: (a -> b) -> [a] -> [b]
const map = curry((f, xs) => xs.map(f));
// PARTIAL APPLICATION ----------------------------------------------------
const
f1 = x => x * 2,
f2 = x => x * x,
fs = map,
fsf1 = fs(f1),
fsf2 = fs(f2);
// TEST -------------------------------------------------------------------
return [
fsf1([0, 1, 2, 3]),
fsf2([0, 1, 2, 3]),
fsf1([2, 4, 6, 8]),
fsf2([2, 4, 6, 8])
];
})();

View file

@ -1,37 +0,0 @@
(() => {
'use strict';
// GENERIC FUNCTIONS ------------------------------------------------------
// 2 or more arguments
// curry :: Function -> Function
const curry = (f, ...args) => {
const go = xs => xs.length >= f.length ? (f.apply(null, xs)) :
function () {
return go(xs.concat(Array.from(arguments)));
};
return go([].slice.call(args, 1));
};
// map :: (a -> b) -> [a] -> [b]
const map = curry((f, xs) => xs.map(f));
// PARTIAL APPLICATION ----------------------------------------------------
const
f1 = x => x * 2,
f2 = x => x * x,
fs = map,
fsf1 = fs(f1),
fsf2 = fs(f2);
// TEST -------------------------------------------------------------------
return [
fsf1([0, 1, 2, 3]),
fsf2([0, 1, 2, 3]),
fsf1([2, 4, 6, 8]),
fsf2([2, 4, 6, 8])
];
})();

View file

@ -1,23 +1,50 @@
/*REXX program demonstrates a method of a partial function application. */
s=; do a=0 to 3 /*build 1st series of some low integers*/
s=strip(s a) /*append to the integer to the S list*/
end /*a*/
-- 11 Sep 2025
include Setting
call fs 'f1',s; say 'for f1: series=' s", result=" result
call fs 'f2',s; say 'for f2: series=' s", result=" result
say 'PARTIAL FUNCTION APPLICATION'
say version
say 'F1 doubles, F2 squares'
say
-- List of low integers
list=''
do i = 0 to 3
list=Strip(list i)
end i
-- Apply F1 and F2
call Fs 'F1',list
say 'For F1: Sequence =' list', Result =' result
call Fs 'F2',list
say 'For F2: Sequence =' list', Result =' result
-- List of low even integers
list=''
do i = 2 by 2 to 8
list=Strip(list i)
end i
-- Apply F1 and F2
call Fs 'F1',list
say 'For F1: Sequence =' list', Result =' result
call Fs 'F2',list
say 'For F2: Sequence =' list', Result =' result
exit
s=; do b=2 to 8 by 2 /*build 2nd series, low even integers. */
s=strip(s b) /*append to the integer to the S list*/
end /*b*/
Fs:
-- Partial function application
-- Mimics 'map' operation
procedure expose Memo.
arg function,list
dd=''
do w = 1 for Words(list)
z=Word(list,w)
interpret 'dd=dd' function'('z')'
end w
return Strip(dd)
call fs 'f1',s; say 'for f1: series=' s", result=" result
call fs 'f2',s; say 'for f2: series=' s", result=" result
exit /*stick a fork in it, we're all done. */
/*────────────────────────────────────────────────────────────────────────────*/
f1: return arg(1)* 2
f2: return arg(1)**2
/*────────────────────────────────────────────────────────────────────────────*/
fs: procedure; arg f,s; $=; do j=1 for words(s); z=word(s,j)
interpret '$=$' f"("z')'
end /*j*/
return strip($)
F1:
-- Double
return arg(1)*2
F2:
-- Square
return arg(1)**2
include Math