|
Copyright ® (1997-2013) EDMGROUP Pty Ltd - EZY Prolog Reference |
This sample program demonstrates how to use external DLL inside EZY Prolog code.
It simply passes string to Visual Prolog DLL which returns modified string.
/* EZY PROLOG. Copyright
(C) 1997-2013 EDMGROUP (Australia)
http://www.ezy-software.com
Written by: Serguei Penkov
email: ezy-soft@ezy-software.com
DLL Sources in:
SourceSamples\EZY_DLL_Test directory
EZY PROLOG PROGRAM calls external DLL, written in Visual Prolog 5.2
This DLL simply receives facts from EZY Prolog and asserts them into database,
declared inside DLL. To do so, EZY Prolog calls dll_assert function
EZY Prolog program can get all facts from dll by calling dll_findall
This function call returns list of facts inside a string.
Use term_str to convert string into list of facts
EZY Prolog program can retrieve facts non-deterministically by calling
dll_retract
Non-determinism is provided by EZY Prolog. DLL function simply returns
(0) to inform
EZY Prolog that all facts has been processed.
For Cucstom Control handling in DLL - please open EZY FORM:
Samples\ezy_dll_custom_control.ezy
*/
domains
my_complex_domain = complex(STRING NAME, SLIST PARAMS)
my_complex_domain_list = my_complex_domain*
predicates
prolog_main
dll_subsystem_test(STRING DLL_NAME)
clauses
prolog_main():-
write("Welcome
to EZY Prolog\nDLL Subsystem testing\n"),
DLL_NAME = "ezy_dll_test.dll",
syspath(EXEPATH,_),
format(DLL_FULL_NAME,"%s%s",EXEPATH,DLL_NAME),
STR_IN = "This is string
from EZY Prolog",
ezy_dll_call(DLL_FULL_NAME,"dll_function_test",STR_IN,STR_OUT),
write("Results
from DLL:\nSTR_IN=",STR_IN,"\nSTR_OUT=",STR_OUT),nl,
dll_subsystem_test(DLL_FULL_NAME),
!.
dll_subsystem_test(DLL_NAME):-
write("Start
of EZY DLL test. DLL_NAME=",DLL_NAME),nl,
fail.
dll_subsystem_test(DLL_NAME):-
% ASSET FACTS INSIDE DLL
% USER TERM_STR TO CREATE
INPUT PARAMETER FOR DLL
CALL_NAME = "dll_assert",
MY_FACT1 = complex("Bob",["Prolog","Java","Cobol"]),
term_str(my_complex_domain,MY_FACT1,MY_FACT_STR1),
ezy_dll_call(DLL_NAME,CALL_NAME,MY_FACT_STR1,RC1),
write("Asserting
First fact:\n\t",MY_FACT1,"\n\tRC=",RC1),nl,
MY_FACT2 = complex("Tony",["Beer","Wine","Visual Basic"]),
term_str(my_complex_domain,MY_FACT2,MY_FACT_STR2),
ezy_dll_call(DLL_NAME,CALL_NAME,MY_FACT_STR2,RC2),
write("Asserting
Second fact:\n\t",MY_FACT2,"\n\tRC=",RC2),nl,
fail.
dll_subsystem_test(DLL_NAME):-
write("Test
for findall in DLL - get list of facts:\n\tNote: list should have 2 facts,
asserted before\n"),
CALL_NAME = "dll_findall",
ezy_dll_call(DLL_NAME,CALL_NAME,"",RESULT_STR),
term_str(my_complex_domain_list,FACT_LIST,RESULT_STR),
% now we have LIST OF FACTS
write("findall
test\n\tstring to my_complex_domain_list conversion =\n\t",FACT_LIST),nl,
fail.
dll_subsystem_test(DLL_NAME):-
% NOW - SIMULATE NON-DETERMINISTIC
RETRIEVAL OF FACTS FROM DLL
% NOTE - ezy_dll_call will
fail when no facts found in the DLL
write("Retract
facts non-deterministically:\n"),
CALL_NAME = "dll_retract",
ezy_dll_call_nondeterm(DLL_NAME,CALL_NAME,"",RESULT_STR),
term_str(my_complex_domain_list,MY_FACT,RESULT_STR),
write("Fact
retracted\n\tstring to my_complex_domain_list conversion =\n\t",MY_FACT),nl,
fail.
dll_subsystem_test(DLL_NAME):-
write("End
of EZY DLL test. DLL_NAME=",DLL_NAME),nl.
goal
prolog_main().
/* PROGRAM OUTPUT */
EZY Prolog. Copyright (C) 1997-2006 EDMGROUP (Australia)
http://www.ezy-software.com
Check PDC Prolog compatibility
Program verification completed
Program compiled
Welcome to EZY Prolog
DLL Subsystem testing
Results from DLL:
STR_IN=This is string from EZY Prolog
STR_OUT=Updated string from DLL: This is string from
EZY Prolog
Start of EZY DLL test. DLL_NAME=C:Program\ FilesEZY\-SoftwareEZY_Prolog_Suite\ezy_dll_test\.dll
Asserting First fact:
complex("Bob",["Prolog","Java","Cobol"])
RC=OK
Asserting Second fact:
complex("Tony",["Beer","Wine","Visual
Basic"])
RC=OK
Test for findall in DLL - get list of facts
:
Note: list should have 2 facts , asserted before
findall test
string to my_complex_domain_list conversion =
[[complex("Bob","Prolog","Java","Cobol")],complex("Tony","Beer","Wine","Visual Basic")]
Retract facts non-deterministically:
Fact retracted
string to my_complex_domain_list conversion =
complex("Bob",["Prolog","Java","Cobol"])
Fact retracted
string to my_complex_domain_list conversion =
complex("Tony",["Beer","Wine","Visual
Basic"])
End of EZY DLL test.
DLL_NAME=C:Program\ FilesEZY\-SoftwareEZY_Prolog_Suite\ezy_dll_test\.dll