Discussions related to Visual Prolog
Michel
Posts: 8
Joined: 8 Nov 2025 17:17

Need help about custom langage (C).

Post by Michel »

First of all, I wish you an Happy 2026 year.

I get some issues interfacing C and prolog. Here is the codes I try to let communicate with each other. Of course, it is just a test before extending my project to something more serious.

My very basic prolog file :

Code: Select all

implement taskWindow inherits applicationWindow     open core, stdio, vpiDomains   constants     mdiProperty : boolean = true.   class predicates     myRoutine : (integer) -> integer language c as "ExternCalc".   resolve     myRoutine externally   clauses     new() :-         applicationWindow::new(),         generatedInitialize().   % etc...   class predicates     onHelpAbout : window::menuItemListener. clauses     onHelpAbout(TaskWin, _MenuTag) :-         Result = myRoutine(2), // <---- extern C routine         write(Result),         _AboutDialog = aboutDialog::display(TaskWin).   % etc...
Compiler MVS 2026 gives a correct Sources.o from Sources.c

Here is the very very basic test "C" routine :
int ExternCalc(int input)
{
return(input * 3);
}
--------------------------------------

Visual Prolog 11 (personal edition) compilation return this error !

error lnk2525 : : 'obj64\taskWindow.B668E84D.obj' - undefined name 'ExternCalc'

Using 'stdcal' or 'cdecl' gives the same issue...

Is there somme steps I missed ? Have I to "add" object code from the "Menu-File" or something else ? Where must be located the object file(s) ?

Warm Regards, Michel
User avatar
drspro2
VIP Member
Posts: 122
Joined: 28 Apr 2006 12:03

Re: Need help about custom langage (C).

Post by drspro2 »

in the VPsamples section of this forum there is the Subject: VPcURL . In there a Visual Prolog program connects there to a C -Dll , there is a lot of sample code of how to declare things . Also there are sample projects in the Visual prolog examples in: DLL directory
User avatar
drspro2
VIP Member
Posts: 122
Joined: 28 Apr 2006 12:03

Re: Need help about custom langage (C).

Post by drspro2 »

as far as i know you cant simply include C - obj files in VP , but maybe i am wrong here . you would have to export / compile the C-code to a DLL with this code:

int ExternCalc(int input)
{
return(input * 3);
}

If you post the resulting C -dll in a zip file i could try to connect to it by a VP project
Michel
Posts: 8
Joined: 8 Nov 2025 17:17

Re: Need help about custom langage (C).

Post by Michel »

Thanks for such an answer.
I am working hard in VP I but love "C"/UNIX and VP vs C language are two worlds, especially about syntax.
I love CLIPS but CLIPS but it is very hard to port to Windows. I am not new with Prolog ( Delphia P., Turbo P. ) but I am very very new to OOP.

Thanks one more time,
Regards, Michel
User avatar
drspro2
VIP Member
Posts: 122
Joined: 28 Apr 2006 12:03

Re: Need help about custom langage (C).

Post by drspro2 »

Quote:
**I love CLIPS but CLIPS but it is very hard to port to Windows. ""
this is clips? : https://en.wikipedia.org/wiki/CLIPS

---------------
as far as i understand CLIPS is an expert system language implemented in the language C
and this CLIPS language has a LISP -alike syntax

- since CLIPS is written in C it should be very easy to compile it on ms Windows,
with MS Visual C or with GNU C compiler?

So you have an existing Expert System with very large Source in CLIPS?

Visual prolog programs should always have the possibility of connecting to C - dlls ( on windows )
and that opens Many possibilities.

Another option could be to Parse all the CLIPS code ( prolog is very good at parsing )
and then rewrite / transpile it to (visual) prolog code, you could write a program that does this
instead of manually editing all the CLIPS code to prolog

in my opinion OOP is just a term whereby it is very often claimed that programmers cant understand
what it is. in the new visual prolog syntax the OOP is this ( VP example code ) :
1.
<object>:name_of_predicate( ARg1, Arg2 , Arg3 )
2.
<object>::name_of_predicate( ARg1, Arg2 , Arg3 )

so you have 1 colon or you have 2 colons ;;
in case of 1 colon you use in general a variabel as the Object.
in case of 2 colons you refer to another VPclass where everything is implemented
User avatar
Thomas Linder Puls
VIP Member
Posts: 1492
Joined: 28 Feb 2000 0:01

Re: Need help about custom langage (C).

Post by Thomas Linder Puls »

Hi Michel.

I suggest you read Foreign Language Code.

As mentioned above we recommend that you place your C/C++ code in a DLL. Linking directly with object files can be more problematic.
Regards Thomas Linder Puls
PDC
User avatar
drspro2
VIP Member
Posts: 122
Joined: 28 Apr 2006 12:03

Re: Need help about custom langage (C).

Post by drspro2 »

thankyou for the information, i wasnt aware yet that there was also a wiki-page about the foreign language code subject.

With also the examples of the VPcurl -project i can find how to manage things.
In case of debugging, if you pass incorrect domains to the C-dll , or pass incorrect number of arguments, will you always receive the same error level

what i do not see in the wiki, and what is see in the examples code of VPcurl is

* Result = uncheckedConvert( pointer , <some_domain> )
to be able to pass arguments to the C dll, can we uncheckedConvert all possible VP domains
to pointers

* and also i see:

memory::allocHeap(

string8::mapToString(

does there exist a mappings list of the C-domains to VP domains , for example :

"wchar_t *" means Unicode

or as mentioned in the wiki: everything is integer , real Or string and that is everything you need