{"id":2433,"date":"2021-06-06T13:58:42","date_gmt":"2021-06-06T08:28:42","guid":{"rendered":"https:\/\/www.rangakrish.com\/?p=2433"},"modified":"2021-06-06T14:01:30","modified_gmt":"2021-06-06T08:31:30","slug":"getting-to-know-visual-prolog-10","status":"publish","type":"post","link":"https:\/\/www.rangakrish.com\/index.php\/2021\/06\/06\/getting-to-know-visual-prolog-10\/","title":{"rendered":"Getting to Know Visual Prolog 10"},"content":{"rendered":"<p><a href=\"https:\/\/www.visual-prolog.com\" target=\"_blank\" rel=\"noopener\"><em><strong>Visual Prolog<\/strong><\/em><\/a>\u00a0has its roots in <em><strong>Turbo Prolog<\/strong><\/em>, which was popularized by <em><strong>Borland<\/strong><\/em> in the mid 1980s. It is developed and supported by <a href=\"https:\/\/www.pdc.com\" target=\"_blank\" rel=\"noopener\"><em><strong>PDC A\/S<\/strong><\/em>, <em><strong>Denmark<\/strong><\/em><\/a>.<\/p>\n<p>So how is <em><strong>Visual Prolog<\/strong><\/em> different from other <em><strong>Prolog<\/strong><\/em> implementations out there, for example, <a href=\"https:\/\/www.swi-prolog.org\" target=\"_blank\" rel=\"noopener\"><em><strong>SWI-Prolog<\/strong><\/em><\/a> or <a href=\"https:\/\/sicstus.sics.se\" target=\"_blank\" rel=\"noopener\"><em><strong>Sicstus Prolog<\/strong><\/em><\/a>?<\/p>\n<p>Here are the key differences:<\/p>\n<p style=\"padding-left: 40px;\">1) It is not an <strong><em>ISO<\/em><\/strong> Prolog<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<p style=\"padding-left: 40px;\">2) It is strongly-typed and is object-oriented<\/p>\n<p style=\"padding-left: 40px;\">3) It is a compiled environment, not interpreted<\/p>\n<p><em><strong>Visual Prolog<\/strong><\/em> is quite rich in functionality. We can quickly build <em><strong>Console<\/strong><\/em> mode or <em><strong>GUI<\/strong><\/em>-based applications, <em><strong>DLLs<\/strong><\/em>, and even <em><strong>Windows Service<\/strong><\/em> using the platform. Because of strong typing and compile-only strategy, the efficiency of generated code is likely to be superior compared to other interpreted environments. So, if you don&#8217;t need a <em><strong>&#8220;Standard&#8221;<\/strong> <strong>Prolog<\/strong><\/em>, then <em><strong>Visual Prolog<\/strong><\/em> has a lot to offer.<\/p>\n<p>Although I purchased the Commercial Edition of <em><strong>Visual Prolog<\/strong><\/em> a few years ago, I never got around to using it. One reason is that it seems to have a steeper learning curve and there are not many video tutorials to explain the language and the environment. There are a couple of PDF books but they cover an older version (ver 7.x or earlier).<\/p>\n<p>I upgraded to the latest version (ver 10) a couple of weeks ago and decided to spend some time understanding the language and the environment.<\/p>\n<p>Instead of writing the canonical\u00a0<em><strong>&#8220;Hello, world!<\/strong><strong>&#8220;<\/strong><\/em> program, I wanted to start by implementing a <em><strong>DLL<\/strong><\/em> that I can call from <em><strong>C\/C++<\/strong><\/em>. I do this usually with other languages too, see for example <a href=\"https:\/\/www.rangakrish.com\/index.php\/2018\/08\/05\/sicstus-prolog-building-a-windows-dll\/\" target=\"_blank\" rel=\"noopener\"><em><strong>this<\/strong><\/em><\/a> and <a href=\"https:\/\/www.rangakrish.com\/index.php\/2018\/05\/27\/calling-go-functions-from-lisp\/\" target=\"_blank\" rel=\"noopener\"><em><strong>this<\/strong><\/em><\/a>. The capability to use <em><strong>DLLs<\/strong><\/em> (in Windows environment) written in one language can come in handy if we want to exploit the language&#8217;s special features for implementing specific functionalities, even though the main application is written in another language say, <em><strong>Erlang<\/strong><\/em>, <em><strong>Go<\/strong><\/em>, etc. In that sense, since <em><strong>Prolog<\/strong><\/em> is a <em><strong>declarative<\/strong><\/em> language and is good at <em><strong>logical inferencing<\/strong><\/em>, we might consider using it to implement an application such as a <em><strong>Medical Diagnosis<\/strong><\/em> system that has an <em><strong>Expert System<\/strong><\/em> subcomponent.<\/p>\n<h3>Creating the DLL:<\/h3>\n<p>Getting back to our main topic, I decided to create a <em><strong>DLL<\/strong><\/em> in <em><strong>Visual Prolog. <\/strong><\/em>The<em><strong> DLL<\/strong><\/em>\u00a0provides the following:<\/p>\n<p style=\"padding-left: 40px;\">1) A <em><strong>function<\/strong><\/em> called <em><strong>&#8220;factorial&#8221;<\/strong><\/em> that takes an integer argument and returns the corresponding factorial of the argument.<\/p>\n<p style=\"padding-left: 40px;\">2) A <em><strong>procedure<\/strong><\/em> called <em><strong>&#8220;lookup&#8221;<\/strong><\/em> that takes two arguments: an integer, which acts as a <em><strong>&#8220;key&#8221;<\/strong><\/em> for lookup and and an <em><strong>&#8220;out&#8221;<\/strong><\/em> parameter that corresponds to the looked up value.<span class=\"Apple-converted-space\">\u00a0 <\/span>In case the integer <em><strong>&#8220;key&#8221;<\/strong><\/em> is not present, it will assign <em><strong>&#8220;-999999&#8221;<\/strong><\/em> to the output argument.<\/p>\n<p>As you can see, <em><strong>Visual Prolog<\/strong><\/em> supports functions and procedures too, in addition to the regular non-deterministic\u00a0<em><strong>&#8220;Horn Clauses&#8221;<\/strong><\/em>\u00a0.<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<p>Since Visual Prolog is <em><strong>&#8220;object oriented&#8221;<\/strong><\/em>, functionality is implemented in classes, whose code is distributed in three files:<\/p>\n<p style=\"padding-left: 40px;\">&#8211; <em><strong>&#8220;Interface&#8221;<\/strong><\/em> file, which defines the interface\/behaviour provided by the <em><strong>&#8220;objects&#8221;<\/strong><\/em> of a class<\/p>\n<p style=\"padding-left: 40px;\">&#8211; <em><strong>&#8220;Class&#8221;<\/strong><\/em> file, that declares the class-specific interface<\/p>\n<p style=\"padding-left: 40px;\">&#8211; <em><strong>&#8220;Implementation&#8221;<\/strong><\/em> file that implements the clauses, etc. declared in the above<span class=\"Apple-converted-space\">\u00a0two files<\/span><\/p>\n<p>In some cases, the <em><strong>&#8220;interface&#8221;<\/strong><\/em> is not required (if we are not going to create class instances), but the other two are must.<\/p>\n<p>I created a <em><strong>&#8220;New Project&#8221;<\/strong><\/em> with the type as <em><strong>&#8220;DLL&#8221;<\/strong><\/em>:<\/p>\n<figure id=\"attachment_2435\" aria-describedby=\"caption-attachment-2435\" style=\"width: 550px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/06\/Project.jpg?ssl=1\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" data-attachment-id=\"2435\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/06\/06\/getting-to-know-visual-prolog-10\/project\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/06\/Project.jpg\" data-orig-size=\"1041,634\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1622903324&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Visual Prolog Project\" data-image-description=\"&lt;p&gt;Visual Prolog Project&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Visual Prolog Project&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/06\/Project-1024x624.jpg\" class=\"wp-image-2435\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/06\/Project.jpg?resize=550%2C335&#038;ssl=1\" alt=\"Visual Prolog Project\" width=\"550\" height=\"335\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/06\/Project.jpg?resize=300%2C183&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/06\/Project.jpg?resize=1024%2C624&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/06\/Project.jpg?resize=768%2C468&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/06\/Project.jpg?w=1041&amp;ssl=1 1041w\" sizes=\"(max-width: 550px) 100vw, 550px\" \/><\/a><figcaption id=\"caption-attachment-2435\" class=\"wp-caption-text\"><em><strong>Visual Prolog Project<\/strong><\/em><\/figcaption><\/figure>\n<p>When I click &#8220;Finish&#8221;, the IDE generates the necessary files in the selected directory.<\/p>\n<p>Here are the two predicates that I export from the <em><strong>DLL<\/strong><\/em> (they are declared in the <em><strong>&#8220;class&#8221;<\/strong><\/em> file):<\/p>\n<figure id=\"attachment_2436\" aria-describedby=\"caption-attachment-2436\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/06\/export-cl.jpg?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"2436\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/06\/06\/getting-to-know-visual-prolog-10\/export-cl\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/06\/export-cl.jpg\" data-orig-size=\"651,196\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1622891851&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"The Class File\" data-image-description=\"&lt;p&gt;The Class File&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;The Class File&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/06\/export-cl.jpg\" class=\"wp-image-2436\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/06\/export-cl.jpg?resize=500%2C151&#038;ssl=1\" alt=\"The Class File\" width=\"500\" height=\"151\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/06\/export-cl.jpg?resize=300%2C90&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/06\/export-cl.jpg?w=651&amp;ssl=1 651w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2436\" class=\"wp-caption-text\"><strong>The Class File<\/strong><\/figcaption><\/figure>\n<p>Here is the corresponding implementation:<\/p>\n<figure id=\"attachment_2437\" aria-describedby=\"caption-attachment-2437\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/06\/export-pro.jpg?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"2437\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/06\/06\/getting-to-know-visual-prolog-10\/export-pro\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/06\/export-pro.jpg\" data-orig-size=\"570,507\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1622891980&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"The Implementation File\" data-image-description=\"&lt;p&gt;The Implementation File&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;The Implementation File&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/06\/export-pro.jpg\" class=\"wp-image-2437\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/06\/export-pro.jpg?resize=500%2C445&#038;ssl=1\" alt=\"The Implementation File\" width=\"500\" height=\"445\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/06\/export-pro.jpg?resize=300%2C267&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/06\/export-pro.jpg?w=570&amp;ssl=1 570w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2437\" class=\"wp-caption-text\"><strong>The Implementation File<\/strong><\/figcaption><\/figure>\n<p>When I create the <em><strong>DLL<\/strong><\/em> project, the IDE automatically generates the <em><strong>&#8220;main&#8221;<\/strong><\/em> module that takes care of creating and initializing the <em><strong>DLL<\/strong><\/em>. Here is the generated code:<\/p>\n<figure id=\"attachment_2438\" aria-describedby=\"caption-attachment-2438\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/06\/main-pro.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2438\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/06\/06\/getting-to-know-visual-prolog-10\/main-pro\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/06\/main-pro.jpg\" data-orig-size=\"513,495\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1622892068&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"DLL Initilization\" data-image-description=\"&lt;p&gt;DLL Initilization&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;DLL Initilization&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/06\/main-pro.jpg\" class=\"wp-image-2438\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/06\/main-pro.jpg?resize=500%2C482&#038;ssl=1\" alt=\"DLL Initilization\" width=\"500\" height=\"482\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/06\/main-pro.jpg?resize=300%2C289&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/06\/main-pro.jpg?w=513&amp;ssl=1 513w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2438\" class=\"wp-caption-text\"><strong>DLL Initilization<\/strong><\/figcaption><\/figure>\n<p>The <em><strong>&#8220;Build&#8221;<\/strong><\/em> command (Control + Shift + B) causes the IDE to compile the project and emit the <em><strong>DLL<\/strong><\/em> as well as the <em><strong>LIB<\/strong><\/em> file. The <em><strong>DLL<\/strong><\/em> is saved in the <em><strong>&#8220;exe64&#8221;<\/strong><\/em> subdirectory and the LIB file in the <em><strong>&#8220;Lib64&#8221;<\/strong><\/em> directory inside the Project directory <em><strong>&#8220;DllTest&#8221;<\/strong><\/em>.<\/p>\n<h3>Using the DLL from a C++ Program:<\/h3>\n<p>I decided to load the <em><strong>DLL<\/strong><\/em> dynamically in my <em><strong>C++<\/strong><\/em> program, so there was no need for the <em><strong>LIB<\/strong><\/em> file. I wrote a simple <em><strong>wrapper<\/strong><\/em> to interface with the <em><strong>Visual Prolog<\/strong><\/em> code:<\/p>\n<figure id=\"attachment_2439\" aria-describedby=\"caption-attachment-2439\" style=\"width: 550px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/06\/VipWrapper-cpp.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2439\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/06\/06\/getting-to-know-visual-prolog-10\/vipwrapper-cpp\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/06\/VipWrapper-cpp.jpg\" data-orig-size=\"1021,994\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1622892200&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"The Wrapper Class\" data-image-description=\"&lt;p&gt;The Wrapper Class&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;The Wrapper Class&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/06\/VipWrapper-cpp.jpg\" class=\"wp-image-2439\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/06\/VipWrapper-cpp.jpg?resize=550%2C535&#038;ssl=1\" alt=\"The Wrapper Class\" width=\"550\" height=\"535\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/06\/VipWrapper-cpp.jpg?resize=300%2C292&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/06\/VipWrapper-cpp.jpg?resize=768%2C748&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/06\/VipWrapper-cpp.jpg?w=1021&amp;ssl=1 1021w\" sizes=\"(max-width: 550px) 100vw, 550px\" \/><\/a><figcaption id=\"caption-attachment-2439\" class=\"wp-caption-text\"><strong>The Wrapper Class<\/strong><\/figcaption><\/figure>\n<p>Take a look at <em><strong>line 40<\/strong><\/em>. Since the Prolog <em><strong>&#8220;lookup&#8221;<\/strong><\/em> procedure retuns the result via <em><strong>&#8220;out&#8221;<\/strong><\/em> parameter, I need to pass the <em><strong>address<\/strong><\/em> of the <em><strong>&#8220;result&#8221;<\/strong><\/em> variable. <em><strong>Visual Prolog<\/strong><\/em> will store the looked up value in this address.<\/p>\n<p>And here is the <em><strong>&#8220;main&#8221;<\/strong> <\/em>function:<\/p>\n<figure id=\"attachment_2440\" aria-describedby=\"caption-attachment-2440\" style=\"width: 550px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/06\/main-cpp.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2440\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/06\/06\/getting-to-know-visual-prolog-10\/main-cpp\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/06\/main-cpp.jpg\" data-orig-size=\"889,458\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1622892242&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"C++ Main Entry Point\" data-image-description=\"&lt;p&gt;C++ Main Entry Point&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;C++ Main Entry Point&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/06\/main-cpp.jpg\" class=\"wp-image-2440\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/06\/main-cpp.jpg?resize=550%2C283&#038;ssl=1\" alt=\"C++ Main Entry Point\" width=\"550\" height=\"283\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/06\/main-cpp.jpg?resize=300%2C155&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/06\/main-cpp.jpg?resize=768%2C396&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/06\/main-cpp.jpg?w=889&amp;ssl=1 889w\" sizes=\"(max-width: 550px) 100vw, 550px\" \/><\/a><figcaption id=\"caption-attachment-2440\" class=\"wp-caption-text\"><em><strong>C++ Main Entry Point<\/strong><\/em><\/figcaption><\/figure>\n<p>First, I have to create an instance of the <em><strong>&#8220;wrapper&#8221;<\/strong><\/em> class, initializing it with the correct <em><strong>path<\/strong><\/em> of the <em><strong>DLL<\/strong><\/em> to be used. The prolog calls are then routed through this object. Nothing fancy here.<\/p>\n<p>I used <em><strong>Embarcadero&#8217;s <a href=\"https:\/\/www.embarcadero.com\/products\/rad-studio\" target=\"_blank\" rel=\"noopener\">RAD Studio<\/a> ver 10.4.2<\/strong><\/em> to build the <em><strong>C++<\/strong><\/em> application (64-bits).<\/p>\n<p>Here is the output from the program:<\/p>\n<figure id=\"attachment_2441\" aria-describedby=\"caption-attachment-2441\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/06\/Session.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2441\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/06\/06\/getting-to-know-visual-prolog-10\/session-8\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/06\/Session.jpg\" data-orig-size=\"734,157\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1622891258&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Program Output\" data-image-description=\"&lt;p&gt;Program Output&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Program Output&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/06\/Session.jpg\" class=\"wp-image-2441\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/06\/Session.jpg?resize=500%2C107&#038;ssl=1\" alt=\"Program Output\" width=\"500\" height=\"107\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/06\/Session.jpg?resize=300%2C64&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/06\/Session.jpg?w=734&amp;ssl=1 734w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2441\" class=\"wp-caption-text\"><strong>Program Output<\/strong><\/figcaption><\/figure>\n<p>The program works as expected. When time permits, I intend to check out the other interesting features that <em><strong>Visual Prolog<\/strong> <\/em>has to offer.<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<p>You can download the <em><strong>Visual Prolog\u00a0<\/strong><\/em>project <a href=\"http:\/\/www.rangakrish.com\/downloads\/PrologDLLTest.zip\" target=\"_blank\" rel=\"noopener\"><em><strong>here<\/strong><\/em><\/a>. The <em><strong>C++ <\/strong><\/em>source file is <a href=\"http:\/\/www.rangakrish.com\/downloads\/TestPrologDLL.cpp\" target=\"_blank\" rel=\"noopener\"><em><strong>here<\/strong><\/em><\/a>.<\/p>\n<p>Have a nice weekend!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Visual Prolog\u00a0has its roots in Turbo Prolog, which was popularized by Borland in the mid 1980s. It is developed and supported by PDC A\/S, Denmark. So how is Visual Prolog different from other Prolog implementations out there, for example, SWI-Prolog or Sicstus Prolog? Here are the key differences: 1) It is not an ISO Prolog\u00a0 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[49,17,147],"tags":[149,283],"class_list":["post-2433","post","type-post","status-publish","format-standard","hentry","category-c","category-programming","category-prolog","tag-dll","tag-visual-prolog"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9OLnF-Df","jetpack-related-posts":[{"id":1770,"url":"https:\/\/www.rangakrish.com\/index.php\/2019\/11\/10\/calling-c-methods-from-sicstus-prolog-through-com-interface\/","url_meta":{"origin":2433,"position":0},"title":"Calling C# Methods from Sicstus Prolog through COM Interface","author":"admin","date":"November 10, 2019","format":false,"excerpt":"Recently\u00a0I needed to make use of a C# library (which I had implemented a few years ago) from Sicstus Prolog. Calling C\/C++ functions from Sicstus Prolog is fairly well documented. When it comes to C#\/.NET, the official documentation recommends the PrologBeans library. After going through the documentation, I felt that\u2026","rel":"","context":"In &quot;Programming&quot;","block_context":{"text":"Programming","link":"https:\/\/www.rangakrish.com\/index.php\/category\/programming\/"},"img":{"alt_text":"Prolog Client Code","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/11\/Prolog-Code.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/11\/Prolog-Code.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/11\/Prolog-Code.jpg?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":1025,"url":"https:\/\/www.rangakrish.com\/index.php\/2018\/08\/19\/sicstus-prolog-building-a-windows-executable\/","url_meta":{"origin":2433,"position":1},"title":"Sicstus Prolog &#8211; Building a Windows Executable","author":"admin","date":"August 19, 2018","format":false,"excerpt":"In my previous post, I showed how to build a C-based Windows DLL to execute Prolog predicates in the Sicstus Prolog\u00a0engine. Today, I want to show how to build an executable (on Windows) from a C\/C++ program that uses Sicstus prolog engine. The process is quite simple. In order to\u2026","rel":"","context":"In &quot;Natural Language Processing&quot;","block_context":{"text":"Natural Language Processing","link":"https:\/\/www.rangakrish.com\/index.php\/category\/natural-language-processing\/"},"img":{"alt_text":"Creating WordNet Prolog Image","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/08\/Creating-image.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/08\/Creating-image.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/08\/Creating-image.png?resize=525%2C300 1.5x"},"classes":[]},{"id":1004,"url":"https:\/\/www.rangakrish.com\/index.php\/2018\/08\/05\/sicstus-prolog-building-a-windows-dll\/","url_meta":{"origin":2433,"position":2},"title":"Sicstus Prolog &#8211; Building a Windows DLL","author":"admin","date":"August 5, 2018","format":false,"excerpt":"Last week I upgraded to the latest version (4.4.1) of Sicstus Prolog\u00a0for Windows.\u00a0Since the Prolog engine can be embedded (royalty free) in other applications, it is useful to understand how to create a DLL (on Windows) for this purpose. In today's article, I would like to outline this process in\u2026","rel":"","context":"In &quot;C++&quot;","block_context":{"text":"C++","link":"https:\/\/www.rangakrish.com\/index.php\/category\/c\/"},"img":{"alt_text":"Creating Prolog Program Image","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/08\/Saving-Prolog-Image.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/08\/Saving-Prolog-Image.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/08\/Saving-Prolog-Image.png?resize=525%2C300 1.5x"},"classes":[]},{"id":3555,"url":"https:\/\/www.rangakrish.com\/index.php\/2024\/11\/22\/multiobjective-optimization-moo-in-lisp-and-prolog\/","url_meta":{"origin":2433,"position":3},"title":"Multiobjective Optimization (MOO) in Lisp and Prolog","author":"admin","date":"November 22, 2024","format":false,"excerpt":"Recently I came across a nice article\u00a0by Jose Crespo, where the author stresses that the future of programming revolves around the application of math concepts such as Functor, Monads, Folds, etc. In addition, he argues that familiarity with C\/C++ is essential in this modern AI age. The author goes through\u2026","rel":"","context":"In &quot;C++&quot;","block_context":{"text":"C++","link":"https:\/\/www.rangakrish.com\/index.php\/category\/c\/"},"img":{"alt_text":"Lisp Code for Pareto Front","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/11\/lisp-code-249x300.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":2366,"url":"https:\/\/www.rangakrish.com\/index.php\/2021\/03\/28\/implementing-ilexicon-using-litedb\/","url_meta":{"origin":2433,"position":4},"title":"Implementing iLexicon using LiteDB","author":"admin","date":"March 28, 2021","format":false,"excerpt":"iLexicon is an \"intelligent\" dictionary that can be used to build Natural Language applications. I have two implementations, one in Lisp and another in Prolog. Both implementations are memory-based, in order to speed up performance. I have written several articles referencing it, for example see this. \u00a0 LiteDB is a\u2026","rel":"","context":"In &quot;Natural Language Processing&quot;","block_context":{"text":"Natural Language Processing","link":"https:\/\/www.rangakrish.com\/index.php\/category\/natural-language-processing\/"},"img":{"alt_text":"Sample Commands","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/03\/Session1.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":2922,"url":"https:\/\/www.rangakrish.com\/index.php\/2022\/10\/06\/why-learn-prolog\/","url_meta":{"origin":2433,"position":5},"title":"Why Learn Prolog?","author":"admin","date":"October 6, 2022","format":false,"excerpt":"There are several programming languages in use today and a simple google search will throw up interesting recommendations of a subset of these languages to learn, usually based on popularity ranking. As is expected, the popularity of a programming language varies over time and hence a language that was in\u2026","rel":"","context":"In &quot;Programming&quot;","block_context":{"text":"Programming","link":"https:\/\/www.rangakrish.com\/index.php\/category\/programming\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/2433","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/comments?post=2433"}],"version-history":[{"count":0,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/2433\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/media?parent=2433"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/categories?post=2433"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/tags?post=2433"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}