Jump to content

Higher-order functions: Difference between revisions

m (→‎{{header|Phix}}: added get_routine_info() comment, Phix/basics libheader, syntax coloured)
Line 2,471:
INTERFACE
 
USES
Math,
SysUtils,
variants;
Variants;
{$WARN 6058 off : Call to subroutine "$1" marked as inline is not inlined} // Use for variants
 
Line 2,535:
result := Ar ;
 
FOR k := Low ( xAr ) TO High ( xAr ) DO
Ar [ k ] := f ( x [ k ] ) ;
 
Line 2,565:
BEGIN
SetLength ( Ar, min ( length ( x ) , length ( y ) ) ) ;
result := Ar ;
 
FOR k := Low ( xAr ) TO High ( xAr ) DO
Ar [ k ] := f ( x [ k ] , y [ k ] ) ;
 
Line 2,586 ⟶ 2,585:
BEGIN
SetLength ( Ar, min ( length ( x ) , length ( y ) ) ) ;
result := Ar ;
 
FOR k := Low ( xAr ) TO High ( xAr ) DO
Ar [ k ] := f ( x [ k ] , y [ k ] ) ;
 
Line 2,643 ⟶ 2,641:
BEGIN
result := ordx ([ fLow ( 0, x [ 0) ] ) = 0 ) ;
 
FOR k := Low ( x ) TO High ( x ) DO
Line 2,660 ⟶ 2,658:
BEGIN
result := ordx ([ fLow ( 0, x [ 0) ] ) = 0 ) ;
 
FOR k := Low ( x ) TO High ( x ) DO
Line 2,686 ⟶ 2,684:
BEGIN
 
result := ordx ([ fHigh ( 0, x [ 0) ] ) = 0 ) ;
FOR k := High ( x ) DOWNTO Low ( x ) DO
Line 2,704 ⟶ 2,702:
BEGIN
result := ord ( f ( 0, x [ 0 ] ) = 0 ) ;
 
FOR kresult := High ( x )[ DOWNTO LowHigh ( x ) DO];
 
resultFOR k := ordHigh ( f ( 0, x [) 0 ]DOWNTO )Low =( 0x ) ;DO
result := f ( result , x [ k ] ) ;
 
Line 2,847 ⟶ 2,846:
END ;
END.
 
 
(*) === How to use in a program === (*)
Line 2,854:
{$mode Delphi} {$H+} {$J-} {$R+} (*) https://www.freepascal.org/docs-html/prog/progch1.html (*)
USES
MRF,
Math,
SysUtils,
Line 2,870:
Randomize ;
 
setlength ( a, 74 ) ;
setlength ( b, 74 ) ;
setlength ( c, 74 ) ;
a := Map ( RandFillInt RandFillReal , a ) ;
Map ( show , a ) ;
writeln ;
Line 2,889:
 
b := Map ( RandFillInt , b ) ;
WriteLn ( 'b :');
Map ( show , b ) ;
writeln ;
Line 2,894 ⟶ 2,895:
Accu := avg ( a ) ;
WriteLn ( 'avg = ' ,Accu Accu ) ;
writeln ;
writeln ;
c := Filter ( Is_Odd , ab ) ;
writeln ( 'Odd : ' , length ( c ) ) ;
Map ( show , c ) ;
result := Ar writeln ;
result := Ar writeln ;
 
Accu := FoldL ( min , c ) ;
WriteLn ( 'min = ' , Accu );
writeln ;
writeln ;
 
Accu := FoldL ( max , c ) ;
WriteLn ( 'max = ' , Accu );
writeln ;
writeln ;
Line 2,927 ⟶ 2,939:
 
 
 
</lang>JPD 2021/07/0809
 
Output:
122

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.