PROLOG UNDER THE HOOD - New Prolog Engine!

G

Graham Cooper

Guest
BEHOLD!

$sql2="SELECT HEADS.id AS 'HID', QUERY.buds AS 'QB'
FROM QUERY INNER JOIN HEADS
ON QUERY.ref=HEADS.ref AND QUERY.term=HEADS.term
GROUP BY HID HAVING COUNT(HID)=$qc-SUM(QB)"

This is what makes PROLOG DATABASES possible: the flux capacitor! It's
taken me nearly thirty years and my entire family fortune to realize
the vision of that day. My God, has it been that long?

Native PROLOG has 0 COMMANDS! You can morph your code to use 4GL or
3GL, make it look like Forth, C, ASSEMBLER or possibly ENGLISH!

YOU DESIGN THE COMMANDS!

unify [ [ the [ hungry FOX ]] [ ate hungrily ] [ the hamburger] ]
[ [ the [ hungry animal ]] [ ate HOW ] [ the FOOD ]]

PROLOG>
FOX = animal
HOW = hungrily
FOOD = hamburger

How about a FOR LOOP?

casea( A ) :-
less( A , 2 ) ,
write( concat( final , A )) .

casea( A ) :-
less( 1 , A ) ,
write( concat( looping , A )) ,
minus( A , 1 , B ) ,
casea( B ) .

------------------
The Output (in PROLOG) for
casea(5)

looping5
looping4
looping3
looping2
final1


----------------------

Just like C right?

NOTICE THE 2 *IDENTICAL* FUNCTION DEFINITIONS!

tryDoingThisinC( X ) { write('a'); }
tryDoingThisinC( X ) { write('b'); }

PROLOG just picks and chooses what programs to run, if it doesn't get
the right result, it tries another program.

PROLOG actually checks out the 1st CASEA briefly each iteration of the
loop, then decides to fully run the 2nd definition!

---------------------

By using BTREE indexing on every KEYWORD Prolog's Speed barely slows
down for 1.21 GIGA-TUPLE DATABASES!

1.21 GIGA-TUPLE!!!

Because BLOCKPROLOG is the 1st Language to be based on SQL (4GL)

BLOCKPROLOG is the 1st Real 5TH GENERATION LANGUAGE (5GL)

Compare that to Traditional RECURSIVE DESCENT Prolog Parsers...

VT-PROLOG written in TURBO PASCAL take 100s of lines of code to do the
work of the 1 SQL STATEMENT and only matches TERM BY TERM!

...


VT PROLOG DATA STRUCTURE

tag - which kind of node this is.
cons_node - cons_nodes consist of two pointers,
one to the head (first item)
the other to the rest of the list. They are the
"glue" which
holds the list together. The list (A B C) would be
stored as
------- -------- --------
| .| . |-----> | .| . |------> | .| . |---> NIL
--|----- --|------ --|-----
| | |
V V V
A B C

The boxes are the cons nodes, the first part of the
box
holds the head pointer, then second contains the
tail.
constant - holds string values, we don't actually use the entire
80
characters in most cases.
variable - also conatins a string value, these nodes will be
treated as
PROLOG variables rather than constants.

...
...


VT PROLOG MATCHING ENGINE

(+ 100s of lines of subroutines )




FUNCTION unify(list1,list2,environ : node_ptr ; VAR new_environ :
node_ptr) :
boolean ;
(* Unify two lists and return any new bindings at the front of
the
environment list. Returns true if the lists could be unified.
Unify checks to see if both lists are NIL, this is a
successful
unification. Otherwise check what kind on node the head of
list1
is and call the appropriate routine to perform the
unification.
Variables are unified by looking up the binding of the
variable.
If none is found, make a binding for the variable, otherwise
try to
unify the binding with list2. *)
VAR
var_ptr : node_ptr ;

PROCEDURE make_binding(l1,l2 : node_ptr) ;
(* Bind a variable to the environment. Anonymous variables are
not bound.
l1 points to the variable and l2 points to its binding. *)
BEGIN
IF copy(string_val(l1),1,1) <> '_'
THEN new_environ := cons(cons(l1,l2),environ)
ELSE new_environ := environ ;
unify := true ;
END ; (* make_binding *)

PROCEDURE fail ;
(* Unification failed. *)
BEGIN
unify := false ;
new_environ := environ ;
END ; (* fail *)

PROCEDURE unify_constant ;
(* List1 contains a constant. Try to unify it with list2. The 4
cases
are:
list2 contains
constant - unify if constants match
variable - look up binding, if no current binding bind the
constant to the variable, otherwise unify list1
with the binding.
cons_node,
func - these can't be unified with a constant. A
cons_node
indicates an expression. *)

PROCEDURE nil_constant ;
BEGIN
IF string_val(list1) = '[]'
THEN
BEGIN
unify := true ;
new_environ := environ ;
END
ELSE fail ;
END ; (* nil_constant *)

BEGIN
IF list2 = NIL
THEN nil_constant
ELSE
CASE tag_value(list2) OF
constant : IF string_val(list1) = string_val(list2)
THEN
BEGIN
unify := true ;
new_environ := environ ;
END
ELSE fail ;
variable : BEGIN
var_ptr := look_up(string_val(list2),environ) ;
IF var_ptr = NIL
THEN make_binding(list2,list1)
ELSE unify :=
unify(list1,var_ptr,environ,new_environ) ;
END ;
cons_node,
func : fail ;
ELSE fail ;
END ;
END ; (* unify_constant *)

PROCEDURE unify_variable ;
(* The first list contained a variable, now try to unify that
variable
with list2. If list2 is NIL, unify the varaible with '[]'.
This
is for printing purposes only. *)
BEGIN
var_ptr := look_up(string_val(list1),environ) ;
IF var_ptr <> NIL
THEN unify := unify(var_ptr,list2,environ,new_environ)
ELSE IF list2 = NIL
THEN make_binding(list1,alloc_str(constant,'[]'))
ELSE IF tag_value(list2) IN [constant,variable,func,cons_node]
THEN make_binding(list1,list2)
ELSE fail ;
END ; (* unify_variable *)

PROCEDURE unify_func ;
(* List1 contains a functor. Try to unify it with list2. The 4
cases
are:
list2 contains
constant - can't be unified.
variable - look up binding, if no current binding bind the
functor to the variable, otherwise unify list1
with the binding.
cons_node - fail
func - if the functors match, then true to unify the
component
lists (tail of the list) term by term. *)
BEGIN
CASE tag_value(list2) OF
constant : fail ;
variable : BEGIN
var_ptr := look_up(string_val(list2),environ) ;
IF var_ptr = NIL
THEN make_binding(list2,list1)
ELSE unify :=
unify(list1,var_ptr,environ,new_environ) ;
END ;
func : IF string_val(list1) = string_val(list2)
THEN
BEGIN
unify := true ;
new_environ := environ ;
END
ELSE fail ;
cons_node : fail ;
ELSE fail ;
END ;
END ; (* unify_func *)




--------------

NEXT WEEK : Assuming I can debug at 88MPH!

A SPEED TEST!

BLOCKPROLOG -Vs- VT-PROLOG

SAME PROLOG CODE! SAME PROLOG QUERY!

This is it! This is the answer! It says here that a bolt of lightning
is going to strike the clock tower at precisely 10:04 PM next Saturday
Night! If we could somehow... harness this lightning; channel it into
the Flux Capacitor, it just might work.



Herc
--
www.BLoCKPROLOG.com (b)eta
 

Welcome to EDABoard.com

Sponsor

Back
Top