{"id":3017,"date":"2023-02-16T15:16:20","date_gmt":"2023-02-16T09:46:20","guid":{"rendered":"https:\/\/www.rangakrish.com\/?p=3017"},"modified":"2023-02-16T15:16:20","modified_gmt":"2023-02-16T09:46:20","slug":"calling-external-dll-functions-from-julia","status":"publish","type":"post","link":"https:\/\/www.rangakrish.com\/index.php\/2023\/02\/16\/calling-external-dll-functions-from-julia\/","title":{"rendered":"Calling External DLL Functions from Julia"},"content":{"rendered":"<p><a href=\"https:\/\/julialang.org\/\" target=\"_blank\" rel=\"noopener\"><em><strong>Julia<\/strong><\/em><\/a> supports calling external functions, especially those written in <em><strong>\u201cC\u201d<\/strong><\/em> language. As <em><strong>Julia<\/strong> <a href=\"http:\/\/web.mit.edu\/julia_v0.6.2\/julia\/share\/doc\/julia\/html\/en\/manual\/calling-c-and-fortran-code.html\" target=\"_blank\" rel=\"noopener\"><strong>documentation<\/strong><\/a><\/em> says, such calls do not involve any <em><strong>\u201cboilerplate\u201d<\/strong><\/em> code and hence are efficient. In today\u2019s article, I am going to show how to call functions defined in a <em><strong>DLL<\/strong><\/em> (Windows 64 bit). Instead of using direct <em><strong>\u201cC\u201d<\/strong><\/em> functions, I will discuss how to compile <a href=\"http:\/\/www.lispworks.com\/\" target=\"_blank\" rel=\"noopener\"><em><strong>LispWorks<\/strong><\/em><\/a> <em><strong>Lisp<\/strong><\/em> code into a <em><strong>DLL<\/strong><\/em> and then interface it with <em><strong>Julia<\/strong><\/em>.<\/p>\n<p><span style=\"text-decoration: underline;\"><strong>My environment:<\/strong><\/span><\/p>\n<p style=\"padding-left: 40px;\">1) Windows 10 (64 bit)<br \/>\n2) LispWorks Enterprise Edition 8.0.1 (64 bit, for Windows)<\/p>\n<p>Let us start with the <em><strong>Lisp<\/strong><\/em> code first. I have written a function <em><strong>\u201clispEval\u201d<\/strong><\/em> that takes a string, evaluates it as a sequence of <em><strong>S-Expressions<\/strong><\/em> and returns the result as a string. It uses <em><strong>LispWorks<\/strong> <strong>\u201cFLI\u201d<\/strong><\/em> package. Here is the code:<\/p>\n<figure id=\"attachment_3018\" aria-describedby=\"caption-attachment-3018\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/code.jpg?ssl=1\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" data-attachment-id=\"3018\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2023\/02\/16\/calling-external-dll-functions-from-julia\/code-21\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/code.jpg\" data-orig-size=\"1005,391\" 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;1676387685&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 &amp;#8220;lispEval&amp;#8221; Function\" data-image-description=\"&lt;p&gt;The &amp;#8220;lispEval&amp;#8221; Function&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;The &amp;#8220;lispEval&amp;#8221; Function&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/code.jpg\" class=\"wp-image-3018\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/code.jpg?resize=600%2C233&#038;ssl=1\" alt=\"The &quot;lispEval&quot; Function\" width=\"600\" height=\"233\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/code.jpg?resize=300%2C117&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/code.jpg?resize=768%2C299&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/code.jpg?w=1005&amp;ssl=1 1005w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><figcaption id=\"caption-attachment-3018\" class=\"wp-caption-text\"><strong>The &#8220;lispEval&#8221; Function<\/strong><\/figcaption><\/figure>\n<p>To make the <em><strong>Julia<\/strong><\/em> interaction more interesting, I have defined another <em><strong>Lisp<\/strong><\/em> function <em><strong>\u201cjuliaCallBack\u201d<\/strong><\/em>, which takes a <em><strong>\u201cpointer\u201d<\/strong><\/em> to a <em><strong>Julia<\/strong><\/em> function and then calls it with two integer arguments. The <em><strong>Julia<\/strong><\/em> function is expected to return an integer, which is then returned as it is from the <em><strong>Lisp<\/strong><\/em> function. Nothing fancy here, except that this allows 2-way communication between <em><strong>Lisp<\/strong><\/em> and <em><strong>Julia<\/strong><\/em>. Here is the second function:<\/p>\n<figure id=\"attachment_3019\" aria-describedby=\"caption-attachment-3019\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/code2.jpg?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"3019\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2023\/02\/16\/calling-external-dll-functions-from-julia\/code2-10\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/code2.jpg\" data-orig-size=\"1084,472\" 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;1676487219&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 &amp;#8220;juliaCallBack&amp;#8221; Function\" data-image-description=\"&lt;p&gt;The &amp;#8220;juliaCallBack&amp;#8221; Function&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;The &amp;#8220;juliaCallBack&amp;#8221; Function&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/code2-1024x446.jpg\" class=\"wp-image-3019\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/code2.jpg?resize=600%2C261&#038;ssl=1\" alt=\"The &quot;juliaCallBack&quot; Function\" width=\"600\" height=\"261\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/code2.jpg?resize=300%2C131&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/code2.jpg?resize=1024%2C446&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/code2.jpg?resize=768%2C334&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/code2.jpg?w=1084&amp;ssl=1 1084w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><figcaption id=\"caption-attachment-3019\" class=\"wp-caption-text\"><strong>The &#8220;juliaCallBack&#8221; Function<\/strong><\/figcaption><\/figure>\n<p>Both the functions are exported from the <em><strong>Lisp<\/strong><\/em> code.<\/p>\n<figure id=\"attachment_3020\" aria-describedby=\"caption-attachment-3020\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/exporting-the-functions.jpg?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"3020\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2023\/02\/16\/calling-external-dll-functions-from-julia\/exporting-the-functions\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/exporting-the-functions.jpg\" data-orig-size=\"708,220\" 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;1676539376&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=\"Exporting the Functions from Lisp DLL\" data-image-description=\"&lt;p&gt;Exporting the Functions from Lisp DLL&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Exporting the Functions from Lisp DLL&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/exporting-the-functions.jpg\" class=\"wp-image-3020\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/exporting-the-functions.jpg?resize=500%2C155&#038;ssl=1\" alt=\"Exporting the Functions from Lisp DLL\" width=\"500\" height=\"155\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/exporting-the-functions.jpg?resize=300%2C93&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/exporting-the-functions.jpg?w=708&amp;ssl=1 708w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-3020\" class=\"wp-caption-text\"><strong>Exporting the Functions from Lisp DLL<\/strong><\/figcaption><\/figure>\n<p>Now, to compile this <em><strong>Lisp<\/strong><\/em> code and generate the <em><strong>DLL<\/strong><\/em>, we execute the following command on Windows prompt:<\/p>\n<p style=\"padding-left: 40px;\"><em><strong>CMD&gt;&#8221;G:\\Program Files\\LispWorks8\\lispworks-8-0-0-x64-windows.exe&#8221; -build lisp-call.lisp<\/strong><\/em><\/p>\n<p>This completes the <em><strong>DLL<\/strong><\/em> creation. Next, we copy the <em><strong>DLL<\/strong><\/em> to the <em><strong>Julia<\/strong><\/em> project directory so that it is accessible from our <em><strong>Julia<\/strong><\/em> environment.<\/p>\n<p>I have already installed <em><strong>Julia 1.8.5<\/strong><\/em> on my Windows machine. It includes <em><strong>\u201cIJulia\u201d<\/strong><\/em> package that allows me to work conveniently with <em><strong>JupyterLab<\/strong><\/em> IDE. Here is how I launch it:<\/p>\n<figure id=\"attachment_3022\" aria-describedby=\"caption-attachment-3022\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/launching-jupyterlab.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3022\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2023\/02\/16\/calling-external-dll-functions-from-julia\/launching-jupyterlab\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/launching-jupyterlab.jpg\" data-orig-size=\"810,319\" 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;1676387840&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=\"Launching JupyterLab IDE\" data-image-description=\"&lt;p&gt;Launching JupyterLab IDE&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Launching JupyterLab IDE&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/launching-jupyterlab.jpg\" class=\"wp-image-3022\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/launching-jupyterlab.jpg?resize=500%2C197&#038;ssl=1\" alt=\"Launching JupyterLab IDE\" width=\"500\" height=\"197\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/launching-jupyterlab.jpg?resize=300%2C118&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/launching-jupyterlab.jpg?resize=768%2C302&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/launching-jupyterlab.jpg?w=810&amp;ssl=1 810w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-3022\" class=\"wp-caption-text\"><strong>Launching JupyterLab IDE<\/strong><\/figcaption><\/figure>\n<p>The notebook interface provides an interactive session with <em><strong>Julia<\/strong><\/em>. First we need to open the <em><strong>Lisp DLL<\/strong><\/em> and bind a variable to the <em><strong>\u201clispEval\u201d<\/strong><\/em> function in the <em><strong>DLL<\/strong><\/em>. The <em><strong>Julia<\/strong><\/em> function by the same name, defined in <em><strong>cell [5]<\/strong><\/em>, acts as a wrapper by allocating the required buffer and passing it to Lisp.<\/p>\n<figure id=\"attachment_3023\" aria-describedby=\"caption-attachment-3023\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/Session.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3023\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2023\/02\/16\/calling-external-dll-functions-from-julia\/session-10\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/Session.jpg\" data-orig-size=\"834,809\" 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;1676387634&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=\"Calling the Lisp Function\" data-image-description=\"&lt;p&gt;Calling the Lisp Function&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Calling the Lisp Function&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/Session.jpg\" class=\"wp-image-3023\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/Session.jpg?resize=600%2C582&#038;ssl=1\" alt=\"Calling the Lisp Function\" width=\"600\" height=\"582\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/Session.jpg?resize=300%2C291&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/Session.jpg?resize=768%2C745&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/Session.jpg?w=834&amp;ssl=1 834w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><figcaption id=\"caption-attachment-3023\" class=\"wp-caption-text\"><strong>Calling the Lisp Function\u00a0<\/strong><\/figcaption><\/figure>\n<p><em><strong>Cells [6] <\/strong><\/em>and<em><strong> [7]<\/strong><\/em> show that when the <em><strong>DLL<\/strong><\/em> function <em><strong>\u201clispEval\u201d<\/strong><\/em> is called with a string representing an S-Expression, we get the corresponding answer as a string.<\/p>\n<p>The second example shows the other <em><strong>Lisp<\/strong><\/em> function <em><strong>\u201cjuliaCallBack\u201d<\/strong><\/em> in action.<\/p>\n<figure id=\"attachment_3024\" aria-describedby=\"caption-attachment-3024\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/Session2.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3024\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2023\/02\/16\/calling-external-dll-functions-from-julia\/session2-5\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/Session2.jpg\" data-orig-size=\"1074,750\" 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;1676530930&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=\"Testing the &amp;#8220;juliaCallBack&amp;#8221; Function\" data-image-description=\"&lt;p&gt;Testing the &amp;#8220;juliaCallBack&amp;#8221; Function&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Testing the &amp;#8220;juliaCallBack&amp;#8221; Function&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/Session2-1024x715.jpg\" class=\"wp-image-3024\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/Session2.jpg?resize=600%2C419&#038;ssl=1\" alt=\"Testing the &quot;juliaCallBack&quot; Function\" width=\"600\" height=\"419\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/Session2.jpg?resize=300%2C209&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/Session2.jpg?resize=1024%2C715&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/Session2.jpg?resize=768%2C536&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/Session2.jpg?w=1074&amp;ssl=1 1074w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><figcaption id=\"caption-attachment-3024\" class=\"wp-caption-text\"><strong>Testing the &#8220;juliaCallBack&#8221; Function<\/strong><\/figcaption><\/figure>\n<p>As before, we need to bind the <em><strong>DLL<\/strong><\/em> function to a <em><strong>Julia<\/strong><\/em> variable. Then we define a <em><strong>Julia<\/strong><\/em> function <em><strong>\u201cfooBar\u201d<\/strong><\/em> whose pointer will be passed to the <em><strong>Lisp<\/strong><\/em> function. We need to use the <em><strong>&#8220;@cfunction&#8221;<\/strong><\/em> macro to generate a c-callable function pointer from a <em><strong>Julia<\/strong><\/em> function. The <em><strong>\u201ctestCallBack\u201d<\/strong> <\/em>function is a simple wrapper around the underlying <em><strong>\u201cccall\u201d<\/strong><\/em>. <em><strong>Cells [12] <\/strong><\/em>and<em><strong> [13]<\/strong><\/em> show that the call works correctly.<\/p>\n<p>Just to make sure that the <em><strong>Lisp<\/strong><\/em> call back is general enough, let us define another <em><strong>Julia<\/strong><\/em> function <em><strong>\u201cfindMax\u201d<\/strong><\/em>, whose pointer will be passed to the <em><strong>Lisp<\/strong><\/em> function.<\/p>\n<figure id=\"attachment_3027\" aria-describedby=\"caption-attachment-3027\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/Session3.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3027\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2023\/02\/16\/calling-external-dll-functions-from-julia\/session3-3\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/Session3.jpg\" data-orig-size=\"855,484\" 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;1676530957&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=\"Another Callback Function\" data-image-description=\"&lt;p&gt;Another Callback Function&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Another Callback Function&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/Session3.jpg\" class=\"wp-image-3027\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/Session3.jpg?resize=600%2C340&#038;ssl=1\" alt=\"Another Callback Function\" width=\"600\" height=\"340\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/Session3.jpg?resize=300%2C170&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/Session3.jpg?resize=768%2C435&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/Session3.jpg?resize=352%2C198&amp;ssl=1 352w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/Session3.jpg?w=855&amp;ssl=1 855w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><figcaption id=\"caption-attachment-3027\" class=\"wp-caption-text\"><strong>Another Callback Function<\/strong><\/figcaption><\/figure>\n<p>The <em><strong>cells [16] <\/strong><\/em>and<em><strong> [17]<\/strong><\/em> show that this also works as expected.<\/p>\n<p>As the above examples demonstrate, calling external functions available in shared libraries is straightforward. You can download the <em><strong>Lisp<\/strong><\/em> code from <a href=\"http:\/\/www.rangakrish.com\/downloads\/lisp-call.lisp\" target=\"_blank\" rel=\"noopener\"><em><strong>here<\/strong><\/em><\/a>. The <em><strong>&#8220;Jupyterlab&#8221;<\/strong><\/em> notebook is available <a href=\"http:\/\/www.rangakrish.com\/downloads\/lisp-call-example.ipynb\" target=\"_blank\" rel=\"noopener\"><em><strong>here<\/strong><\/em><\/a>.<\/p>\n<p>Have a nice day and a great weekend!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Julia supports calling external functions, especially those written in \u201cC\u201d language. As Julia documentation says, such calls do not involve any \u201cboilerplate\u201d code and hence are efficient. In today\u2019s article, I am going to show how to call functions defined in a DLL (Windows 64 bit). Instead of using direct \u201cC\u201d functions, I will discuss [&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":[63,18,17],"tags":[149,64,352,268],"class_list":["post-3017","post","type-post","status-publish","format-standard","hentry","category-julia","category-lisp","category-programming","tag-dll","tag-julia","tag-jupyterlab","tag-lispworks-lisp"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9OLnF-MF","jetpack-related-posts":[{"id":944,"url":"https:\/\/www.rangakrish.com\/index.php\/2018\/06\/10\/calling-lisp-functions-from-go-language\/","url_meta":{"origin":3017,"position":0},"title":"Calling Lisp Functions from Go Language","author":"admin","date":"June 10, 2018","format":false,"excerpt":"In the previous post, we saw how to invoke a Go function from Lisp. In today's post, I would like to explain how to go in the other direction, namely, how to call Lisp functins from Go. There are two ways to do this. The first approach is to load\u2026","rel":"","context":"In &quot;Golang&quot;","block_context":{"text":"Golang","link":"https:\/\/www.rangakrish.com\/index.php\/category\/golang\/"},"img":{"alt_text":"Direct DLL Call","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/06\/LispCall.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/06\/LispCall.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/06\/LispCall.png?resize=525%2C300 1.5x"},"classes":[]},{"id":2057,"url":"https:\/\/www.rangakrish.com\/index.php\/2020\/07\/19\/calling-lisp-functions-from-elixir\/","url_meta":{"origin":3017,"position":1},"title":"Calling Lisp Functions from Elixir","author":"admin","date":"July 19, 2020","format":false,"excerpt":"In the last article\u00a0I showed how we can simulate the idea of Lisp's \"closure\" in Elixir. Today, I would like to demonstrate how we can call Lisp functions from Elixir using the NIF interface. What is the need to integrate Elixir with another language? I can think of two reasons:\u2026","rel":"","context":"In &quot;Elixir&quot;","block_context":{"text":"Elixir","link":"https:\/\/www.rangakrish.com\/index.php\/category\/elixir\/"},"img":{"alt_text":"Using the Lisp Functions","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/07\/Session.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/07\/Session.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/07\/Session.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/07\/Session.jpg?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":963,"url":"https:\/\/www.rangakrish.com\/index.php\/2018\/06\/24\/calling-go-functions-from-lisp-part-2\/","url_meta":{"origin":3017,"position":2},"title":"Calling Go Functions from Lisp &#8211; Part 2","author":"admin","date":"June 24, 2018","format":false,"excerpt":"In my earlier article Calling Go Functions from Lisp, I explained the steps for making calls to Go functions from another language, specifically LispWorks Lisp. Today, I want to give a slightly more\u00a0 interesting example showing the use of Go channels\u00a0through exported functions. Go is widely admired for its native\u2026","rel":"","context":"In &quot;Golang&quot;","block_context":{"text":"Golang","link":"https:\/\/www.rangakrish.com\/index.php\/category\/golang\/"},"img":{"alt_text":"Go Functions","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/06\/Go-Functions.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":2645,"url":"https:\/\/www.rangakrish.com\/index.php\/2021\/12\/25\/calling-lisp-functions-from-d-language\/","url_meta":{"origin":3017,"position":3},"title":"Calling Lisp Functions from D Language","author":"admin","date":"December 25, 2021","format":false,"excerpt":"After exploring \"newLisp\" in the past few posts, I would like to start looking at the \"D Programming Language\"\u00a0(DLang). DLang\u00a0has been around since 2001. It was originally created by Walter Bright and later Andrei Alexandrescu joined the team in 2007. The main inspiration for DLang was C++, although it uses\u2026","rel":"","context":"In &quot;D Language&quot;","block_context":{"text":"D Language","link":"https:\/\/www.rangakrish.com\/index.php\/category\/d-language\/"},"img":{"alt_text":"Lisp Function Called from D","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/12\/Lisp-300x107.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/12\/Lisp-300x107.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/12\/Lisp-300x107.jpg?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":928,"url":"https:\/\/www.rangakrish.com\/index.php\/2018\/05\/27\/calling-go-functions-from-lisp\/","url_meta":{"origin":3017,"position":4},"title":"Calling Go Functions from Lisp","author":"admin","date":"May 27, 2018","format":false,"excerpt":"For the past few weeks I was travelling in the USA and had the pleasure of meeting several friends, some of whom are senior developers and architects. It was interesting to learn that many of them were either using Go language in their daily work, or were passionately endorsing the\u2026","rel":"","context":"In &quot;Golang&quot;","block_context":{"text":"Golang","link":"https:\/\/www.rangakrish.com\/index.php\/category\/golang\/"},"img":{"alt_text":"Part of Header File","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/05\/Header-file.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/05\/Header-file.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/05\/Header-file.png?resize=525%2C300 1.5x"},"classes":[]},{"id":2765,"url":"https:\/\/www.rangakrish.com\/index.php\/2022\/04\/17\/calling-lisp-functions-from-xojo\/","url_meta":{"origin":3017,"position":5},"title":"Calling Lisp Functions from Xojo","author":"admin","date":"April 17, 2022","format":false,"excerpt":"A few days ago, I purchased Xojo Pro commercial license. In case you haven't heard about the product, Xojo\u00a0is a popular cross-platform development tool targeting Desktop, Web and iOS (Android is expected in the near future). It supports an Object-Oriented Basic language. It has been around for over 25 years\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"The Lisp Code","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/04\/LispCode-300x168.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/04\/LispCode-300x168.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/04\/LispCode-300x168.jpg?resize=525%2C300&ssl=1 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/3017","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=3017"}],"version-history":[{"count":0,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/3017\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/media?parent=3017"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/categories?post=3017"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/tags?post=3017"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}