Re: Delphi can do map/reduce?

Dan Downs escribió:
I don't think Delphi can't, I know I can pass a function but I don't understand this concept enough to solve it myself...

I can think of a couple ways to go about it, but I'm not sure its as eligant as functional languages.

The only real limitation I see is having to hard set your function types and parameter lists and matching your map functions to those so everything matches up correctly. There's a couple ways I can think of to make it a more flexible and dynamic, but I'm not sure its worth the added complexity and unless you were scaling it out to several cpus/systems the extra overhead would probably limit any gain.

If I converted the sample code correctly I think you'd end up with something like the following in delphi.

type
TMapableIntFunc = function( a, b : Integer) : Integer;
TMapableIntFunc = function( a, b : String) : String;

TIntegerArray = array of Integer;
TStringArray = array of String;

function IntReduce(fn : TMapableIntFunc; a : TIntegerArray; init : Integer) : Integer;
var
s, i : Integer;
begin
s := init;
for i := 0 to Length(a)-1 do
s := fn( s, a[i] );
Result := s;
end;

function sumInts(a : TIntegerArray) : Integer;
begin
Result := IntReduce( SumIntFunc, a, 0 );
end;

function StrReduce(fn : TMapableStrFunc; a : TStringArray; init : String) : String;
var
i : Integer;
s : String;
begin
s := init;
for i := 0 to Length(a)-1 do
s := fn( s, a[i] );
Result := s;
end;

function joinStrings(a : TStringArray) : String;
begin
Result := StrReduce( JoinStrFunc, a, "" );
end;

function SumIntFunc(a, b : Integer) : Integer;
begin
Result := a + b;
end;

function JoinStrFunc(a, b : String) : String;
begin
Result := a + b;
end;

By itself this doesn't really do much, but rewritting the IntReduce and StrReduce function to a multithreaded or message disbatching to server farm approach, would make this alot more interesting.

DD

Thanks to both...

Now I have a starting pont...

Also, other thing I think is embed python and do the map/reduce function on this and passing to delphi???

In the other side, what things are best/cool to have using this?
.

Relevant Pages

• Re: Delphi can do map/reduce?
... TStringArray = array of String; ... s:= init; ... Result:= IntReduce(SumIntFunc, a, 0); ...
(borland.public.delphi.non-technical)
• Re: Xilinx/Synplicity LUT Placement
... it accepted a boolean equation as a string for input and returned the hex string for the LUT init as the output. ... If you can't get the xc_map to work out for verilog, then perhaps you can use a boolean equation to INIT string parser function to do that conversion. ... instantiating LUTs and using the INITs directly is not a fun way to do any design. ... localparam I0 = 16'haaaa; ...
(comp.arch.fpga)
• Modem init sequence in KPPP
... and my modem won't connect at more than 28 KB. ... The init string in KPPP is not right. ...
(Debian-User)
• Re: string initilization WHY?
... (I've argued before that all casts should be ... The variable str is a pointer to char; ... string whose value is "Awesome" ... init() function. ...
(comp.lang.c)
• __setattr__ and __getattr__ with derived classes
... print 'No Init yet' ... def init: ... __getattr__ python is giving me a different dictionary!!! ...
(comp.lang.python)