Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.
|
|
|
|
Re: adding SQL QUERIES to PROLOG!
Posted:
Aug 9, 2012 6:42 PM
|
|
On Aug 8, 7:17 pm, Graham Cooper <grahamcoop...@gmail.com> wrote: > *LOGIC, A.I. groups added since this is > > COMPUTER *PROGRAMMING-LOGIC* LANGUAGE DESIGN.* > > ** > > 2 rules can be added to *PRO-LOG* to have nested queries like SQL! > > FIELD NAMES can be assigned to PREDICATE ARGUMENTS > > so PROLOG is compatible with standard SQL STATEMENTS. > > SQL: > SELECT PERSON FROM T-CLIENTS > WHERE "surname = smith". > > Prolog doesn't recorgnize the term 'surname' even if the predicate > PERSON is defined, so SQL has a STRUCTURED WHERE statement whereas > Prolog refers to fields via ARGUMENT position. > > ***microPROLOG*** > > [bigger 2 1]. > [bigger 3 2]. > [bigger 10 5]. > [bigger tom sally]. > > ***PROLOG*** > > bigger(2, 1). > bigger(3, 2). > bigger(10, 5). > bigger(tom, sally). > > ?- bigger(X,Y). > > X=2, Y=1 > X=3, Y=2 > X=10, Y=5 > X=tom, Y=sally > > **** > > This complicated FORMAT of output > - the binding results of UNIFY(query, db-facts) > > is probably the reason PROLOG was ditched in favour of SQL. > > (Structured Query Language). > > ************************************** > ENHNANCED PROLOG GRAMMAR > ************************************** > > LINE ! -> NEWTABLE TABLEDEF ! > LINE ! -> NEWQUERY QUERYDEF ! > > TABLEDEF --> [term FIELDTAIL] > FIELDTAIL --> FIELD FIELD ... FIELD > > QUERYDEF --> TABLEDEF IS TABLEDEF IF TAIL > > ***ORIGINAL microPROLOG GRAMMAR*** > > LINE . --> FACT . > LINE . --> RULE . > ?- LINE . --> ?- QUERY . > > RULE --> FACT IF TAIL > QUERY --> TAIL > > FACT --> term > FACT --> VAR > FACT --> [term TAIL] > > TAIL --> FACT FACT ... FACT > > ******************************** > END ENHANCED GRAMMAR > ******************************** > > ****ENHANCED PROLOG**** > > NEWTABLE [bigger BIG SMALL] ! > > [bigger X Y] ? > > [bigger] > ============== > BIG SMALL > -------------- > 2 1 > 3 2 > 10 5 > tom sally > > NEWQUERY [smaller SMALL BIG] IS [bigger BIG SMALL] ! > > [smaller SMALL BIG] ? > > [smaller] > ============== > SMALL BIG > -------------- > 1 2 > 2 3 > 5 10 > sally tom > > This is not using the RULE (filter) so it's just an equivalent table > with different field orders. > > QUERYDEF --> TABLEDEF IS TABLEDEF IF TAIL > > where TAIL could restrict results or even JOIN two previous tables and > nested queries. > > G. Cooper (BInfTech) > --http://www.microprolog.com/LowMoon-Sun-12Stars.jpg
A constructive suggestion:
Join the discussion groups at www.mersenneforum.org
You may find a more favorable reception there.
|
|
|
|