Re: Decision Tables
- From: "Bartc" <bc@xxxxxxxxxx>
- Date: Tue, 29 Jan 2008 23:45:56 GMT
kwikius wrote:
On Jan 28, 5:20 pm, Ben Bacarisse <ben.use...@xxxxxxxxx> wrote:....
Another way to go about this (when you don't have closures) is to
encode the actions that match into a stack machine. One simple
encoding is as function pointers (invented language):
void match_first_name(rM, cM) { push(rM.FirstName == cM.FirstName); }
void match_last_name(rM, cM) { push(rM.LastName == cM.LastName); }
void match_country(rM, cM) { push(rM.Country == cM.Country); }
void match_and(rM, cM) { push(pop() & pop()); }
void match_or(rM, cM) { push(pop() | pop()); }
void match_not(rM, cM) { push(!pop()); }
Your complex matches then become short NULL terminated arrays for
these:
complex_match[] = { match_contry, match_not, match_first_name,
match_or, NULL };
FWIW heres a C++ variant, which seems to work...
Some quite elaborate and advanced ideas have been proposed.
But, if the OP can use an appropriate language then the code given below
will do pretty much what he requested. (This is in my own 'toy' language,
but I doubt this code has anything that Python, Perl etc cannot do. The code
actually works)
The business part is the half-dozen lines of Match(), which I'd imagine
would not be impossible in C, depending on the actual types of the fields
being tested.
/--
Bart
/--------------------------------------------------------------------
Type testrec = Record (var firstname, lastname, address, country)
Proc Start=
A := testrec( "John", "Smith", "London", "UK")
B := testrec( "John", "Brown", "Manchester", "UK")
Map := (1,4)
if Match (A,B, Map) then
println A," and ",B, " MATCH on fields ",Map
else
println A," and ",B, " DON'T MATCH on fields ",Map
fi
End
Function Match(A, B, map)=
forall i in map do
if A.[i]<>B.[I] then return 0 fi
end
return 1
End
.
- Follow-Ups:
- Re: Decision Tables
- From: Ben Bacarisse
- Re: Decision Tables
- References:
- Decision Tables
- From: Leslie Sanford
- Re: Decision Tables
- From: Ben Bacarisse
- Re: Decision Tables
- From: kwikius
- Decision Tables
- Prev by Date: Re: General tree assignment in C
- Next by Date: Re: Decision Tables
- Previous by thread: Re: Decision Tables
- Next by thread: Re: Decision Tables
- Index(es):
Relevant Pages
|