Re: Decision Tables



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



.



Relevant Pages

  • Re: Decision Tables
    ... encoding is as function pointers: ... if the OP can use an appropriate language then the code given below ... if Match (A,B, Map) then ... pointers to member functions. ...
    (comp.programming)
  • Re: Macro Question: Paraphrasing
    ... why not use keywords for everything? ... which is the language used by the human reader to map symbols to ... It's the basic building block of the Lisp language. ...
    (comp.lang.lisp)
  • Re: Macro Question: Paraphrasing
    ... why not use keywords for everything? ... that keywords can distort the meaning of a symbol on the surface level, ... which is the language used by the human reader to map symbols to ... language is by convention read right to left. ...
    (comp.lang.lisp)
  • Re: casts
    ... int compbigramfreq(const void *vp1, const void *vp2) ... That's how qsort works. ... because the children who designed this language never even thought ... tool because of its apparent lack of safety and use of void pointers, ...
    (comp.lang.c)
  • Re: Cheap tricks for map data structure
    ... Is C++ a slow, high-level language? ... So it's not exactly a "map square object" anti-pattern that ... same coordinates for various arrays in the Map class? ... The fast language lets you get away with bad programming practices. ...
    (rec.games.roguelike.development)