Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,37 +0,0 @@
|
|||
with Ada.Text_Io;
|
||||
with Ada.Integer_text_IO;
|
||||
|
||||
procedure Call_Back_Example is
|
||||
-- Purpose: Apply a callback to an array
|
||||
-- Output: Prints the squares of an integer array to the console
|
||||
|
||||
-- Define the callback procedure
|
||||
procedure Display(Location : Positive; Value : Integer) is
|
||||
begin
|
||||
Ada.Text_Io.Put("array(");
|
||||
Ada.Integer_Text_Io.Put(Item => Location, Width => 1);
|
||||
Ada.Text_Io.Put(") = ");
|
||||
Ada.Integer_Text_Io.Put(Item => Value * Value, Width => 1);
|
||||
Ada.Text_Io.New_Line;
|
||||
end Display;
|
||||
|
||||
-- Define an access type matching the signature of the callback procedure
|
||||
type Call_Back_Access is access procedure(L : Positive; V : Integer);
|
||||
|
||||
-- Define an unconstrained array type
|
||||
type Value_Array is array(Positive range <>) of Integer;
|
||||
|
||||
-- Define the procedure performing the callback
|
||||
procedure Map(Values : Value_Array; Worker : Call_Back_Access) is
|
||||
begin
|
||||
for I in Values'range loop
|
||||
Worker(I, Values(I));
|
||||
end loop;
|
||||
end Map;
|
||||
|
||||
-- Define and initialize the actual array
|
||||
Sample : Value_Array := (5,4,3,2,1);
|
||||
|
||||
begin
|
||||
Map(Sample, Display'access);
|
||||
end Call_Back_Example;
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
( ( callbackFunction1
|
||||
= location value
|
||||
. !arg:(?location,?value)
|
||||
& out$(str$(array[ !location "] = " !!value))
|
||||
)
|
||||
& ( callbackFunction2
|
||||
= location value
|
||||
. !arg:(?location,?value)
|
||||
& !!value^2:?!value
|
||||
)
|
||||
& ( mapar
|
||||
= arr len callback i
|
||||
. !arg:(?arr,?len,?callback)
|
||||
& 0:?i
|
||||
& whl
|
||||
' ( !i:<!len
|
||||
& !callback$(!i,!i$!arr)
|
||||
& 1+!i:?i
|
||||
)
|
||||
)
|
||||
& tbl$(array,4)
|
||||
& 1:?(0$array)
|
||||
& 2:?(1$array)
|
||||
& 3:?(2$array)
|
||||
& 4:?(3$array)
|
||||
& mapar$(array,4,callbackFunction1)
|
||||
& mapar$(array,4,callbackFunction2)
|
||||
& mapar$(array,4,callbackFunction1)
|
||||
);
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
>>SOURCE FORMAT IS FREE
|
||||
IDENTIFICATION DIVISION.
|
||||
PROGRAM-ID. map.
|
||||
|
||||
DATA DIVISION.
|
||||
LOCAL-STORAGE SECTION.
|
||||
01 i USAGE IS INDEX.
|
||||
01 table-size CONSTANT AS 30.
|
||||
LINKAGE SECTION.
|
||||
01 table-param.
|
||||
03 table-values USAGE IS FLOAT-LONG, OCCURS table-size TIMES.
|
||||
01 func-ptr USAGE IS PROGRAM-POINTER.
|
||||
|
||||
PROCEDURE DIVISION USING BY REFERENCE table-param, BY VALUE func-ptr.
|
||||
PERFORM VARYING i FROM 1 BY 1 UNTIL i IS GREATER THAN table-size
|
||||
CALL func-ptr USING BY REFERENCE table-values(i)
|
||||
END-PERFORM
|
||||
GOBACK.
|
||||
|
||||
END PROGRAM map.
|
||||
|
|
@ -2,7 +2,7 @@ import system'routines;
|
|||
|
||||
PrintSecondPower(n){ console.writeLine(n * n) }
|
||||
|
||||
public program()
|
||||
public Program()
|
||||
{
|
||||
new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}.forEach(PrintSecondPower)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +0,0 @@
|
|||
function apply_to_all(sequence s, integer f)
|
||||
-- apply a function to all elements of a sequence
|
||||
sequence result
|
||||
result = {}
|
||||
for i = 1 to length(s) do
|
||||
-- we can call add1() here although it comes later in the program
|
||||
result = append(result, call_func(f, {s[i]}))
|
||||
end for
|
||||
return result
|
||||
end function
|
||||
|
||||
function add1(atom x)
|
||||
return x + 1
|
||||
end function
|
||||
|
||||
-- add1() is visible here, so we can ask for its routine id
|
||||
? apply_to_all({1, 2, 3}, routine_id("add1"))
|
||||
-- displays {2,3,4}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
class Main {
|
||||
static function main() {
|
||||
var numbers = [1, 2, 3, 4, 5];
|
||||
|
||||
var squared = (i) -> i * i;
|
||||
|
||||
trace(numbers);
|
||||
trace(numbers.map(squared));
|
||||
}
|
||||
}
|
||||
|
|
@ -1 +0,0 @@
|
|||
1..5 | ForEach-Object { $_ * $_ }
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
function map ([array] $a, [scriptblock] $s) {
|
||||
$a | ForEach-Object $s
|
||||
}
|
||||
map (1..5) { $_ * $_ }
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
REBOL [
|
||||
Title: "Array Callback"
|
||||
URL: http://rosettacode.org/wiki/Apply_a_callback_to_an_Array
|
||||
]
|
||||
|
||||
map: func [
|
||||
"Apply a function across an array."
|
||||
f [native! function!] "Function to apply to each element of array."
|
||||
a [block!] "Array to process."
|
||||
/local x
|
||||
][x: copy [] forall a [append x do [f a/1]] x]
|
||||
|
||||
square: func [x][x * x]
|
||||
|
||||
; Tests:
|
||||
|
||||
assert: func [code][print [either do code [" ok"]["FAIL"] mold code]]
|
||||
|
||||
print "Simple loop, modify in place:"
|
||||
assert [[1 100 81] = (a: [1 10 9] forall a [a/1: square a/1] a)]
|
||||
|
||||
print [crlf "Functional style with 'map':"]
|
||||
assert [[4 16 36] = map :square [2 4 6]]
|
||||
|
||||
print [crlf "Applying native function with 'map':"]
|
||||
assert [[2 4 6] = map :square-root [4 16 36]]
|
||||
|
|
@ -1,23 +1,52 @@
|
|||
/*REXX program applies a callback to an array (using factorials for a demonstration).*/
|
||||
numeric digits 100 /*be able to display some huge numbers.*/
|
||||
parse arg # . /*obtain an optional value from the CL.*/
|
||||
a.= /*initialize the array A to all nulls*/
|
||||
if #=='' | #=="," then #= 12 /*Not assigned? Then use default value*/
|
||||
do j=0 to #; a.j= j /*assign the integer J ───► A.j */
|
||||
end /*j*/ /*array A will have N values: 0 ──► #*/
|
||||
-- 8 Sep 2025
|
||||
include Setting
|
||||
|
||||
call listA 'before callback' /*display A array before the callback*/
|
||||
say /*display a blank line for readability.*/
|
||||
say ' ··· applying callback to array A ···' /*display what is about to happen to B.*/
|
||||
say /*display a blank line for readability.*/
|
||||
call bangit 'a' /*factorialize (the values) of A array.*/
|
||||
/* store the results ───► array B.*/
|
||||
call listA ' after callback' /*display A array after the callback.*/
|
||||
exit 0 /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
bangit: do v=0; $= value(arg(1)'.'v); if $=='' then return /*No value? Then return*/
|
||||
call value arg(1)'.'v, fact($) /*assign a value (a factorial) to array*/
|
||||
end /*i*/
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
fact: procedure; arg x; != 1; do f=2 to x; != !*f; end; /*f*/; return !
|
||||
listA: do k=0 while a.k\==''; say arg(1) 'a.'k"=" a.k; end /*k*/; return
|
||||
say 'APPLY A CALLBACK TO AN ARRAY'
|
||||
say version
|
||||
say
|
||||
call Task 'x'
|
||||
call Task ''
|
||||
call Task 'Sqrt(x)'
|
||||
call Task 'Sin(x)'
|
||||
call Task 'Exp(x)'
|
||||
exit
|
||||
|
||||
Task:
|
||||
-- Get function to apply
|
||||
parse arg function
|
||||
-- Example array with x-values
|
||||
array.=0; n=10
|
||||
do i = 1 to n
|
||||
array.i=i
|
||||
end
|
||||
array.0 = n
|
||||
if function = '' then do
|
||||
-- Apply fixed function to each element
|
||||
do i = 1 to array.0
|
||||
array.i=Square(array.i)
|
||||
end
|
||||
function='Square(x)'
|
||||
end
|
||||
else do
|
||||
-- Apply dynamic function to each element
|
||||
do i = 1 to array.0
|
||||
array.i=Std(Eval(function,array.i)/1)
|
||||
end
|
||||
end
|
||||
-- Show after callback
|
||||
call Show
|
||||
return
|
||||
|
||||
Show:
|
||||
say ' x' function
|
||||
do i = 1 to n
|
||||
say Right(i,2) array.i
|
||||
end
|
||||
say
|
||||
return
|
||||
|
||||
Square:
|
||||
arg xx
|
||||
return xx**2
|
||||
|
||||
include Math
|
||||
|
|
|
|||
|
|
@ -1,16 +0,0 @@
|
|||
class callback
|
||||
dim sRule
|
||||
|
||||
public property let rule( x )
|
||||
sRule = x
|
||||
end property
|
||||
|
||||
public default function applyTo(a)
|
||||
dim p1
|
||||
for i = lbound( a ) to ubound( a )
|
||||
p1 = a( i )
|
||||
a( i ) = eval( sRule )
|
||||
next
|
||||
applyTo = a
|
||||
end function
|
||||
end class
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
dim a1
|
||||
dim cb
|
||||
set cb = new callback
|
||||
|
||||
cb.rule = "ucase(p1)"
|
||||
a1 = split("my dog has fleas", " " )
|
||||
cb.applyTo a1
|
||||
wscript.echo join( a1, " " )
|
||||
|
||||
cb.rule = "p1 ^ p1"
|
||||
a1 = array(1,2,3,4,5,6,7,8,9,10)
|
||||
cb.applyto a1
|
||||
wscript.echo join( a1, ", " )
|
||||
Loading…
Add table
Add a link
Reference in a new issue