{"id":963,"date":"2018-06-24T14:24:09","date_gmt":"2018-06-24T08:54:09","guid":{"rendered":"http:\/\/www.rangakrish.com\/?p=963"},"modified":"2018-06-24T14:32:17","modified_gmt":"2018-06-24T09:02:17","slug":"calling-go-functions-from-lisp-part-2","status":"publish","type":"post","link":"https:\/\/www.rangakrish.com\/index.php\/2018\/06\/24\/calling-go-functions-from-lisp-part-2\/","title":{"rendered":"Calling Go Functions from Lisp &#8211; Part 2"},"content":{"rendered":"<p>In my earlier article <a href=\"http:\/\/www.rangakrish.com\/index.php\/2018\/05\/27\/calling-go-functions-from-lisp\/\" target=\"_blank\" rel=\"noopener\"><em><strong>Calling Go Functions from Lisp<\/strong><\/em><\/a>, I explained the steps for making calls to <em><strong>Go<\/strong><\/em> functions from another language, specifically <em><a href=\"http:\/\/www.lispworks.com\" target=\"_blank\" rel=\"noopener\"><strong>LispWorks<\/strong><\/a> <strong>Lisp<\/strong><\/em>. Today, I want to give a slightly more<span class=\"Apple-converted-space\">\u00a0 <\/span>interesting example showing the use of <em><strong>Go<\/strong> <a href=\"https:\/\/gobyexample.com\/channels\" target=\"_blank\" rel=\"noopener\"><strong>channels<\/strong><\/a><\/em>\u00a0through exported functions.<\/p>\n<p><em><strong>Go<\/strong><\/em> is widely admired for its native support for concurrency via <a href=\"https:\/\/www.golang-book.com\/books\/intro\/10\" target=\"_blank\" rel=\"noopener\"><em><strong>Goroutines<\/strong><\/em><\/a>. Synchronization without explcit locks or condition variables is facilitated by <a href=\"https:\/\/gobyexample.com\/channels\" target=\"_blank\" rel=\"noopener\"><em><strong>Channels<\/strong><\/em><\/a>. This greatly simplifies concurrent programming. So, why can&#8217;t we take advantage of this powerful feature of <em><strong>Go<\/strong><\/em> and use it in another language environment? I am not saying that this alone is sufficient reason for integrating <em><strong>Go<\/strong><\/em> runtime with another language program, but it is an appealing reason!<\/p>\n<p>Anyway, without getting into a debate on this topic, let me show you how easy it is to do this.<\/p>\n<p>The following figure shows three <em><strong>Go<\/strong><\/em> functions that I have defined for working with a <em><strong>Go<\/strong><\/em> Channel.<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<figure id=\"attachment_964\" aria-describedby=\"caption-attachment-964\" style=\"width: 433px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/06\/Go-Functions.png\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" data-attachment-id=\"964\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2018\/06\/24\/calling-go-functions-from-lisp-part-2\/go-functions\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2018\/06\/Go-Functions.png\" data-orig-size=\"433,569\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&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=\"Go Functions\" data-image-description=\"&lt;p&gt;Go Functions&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Go Functions&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2018\/06\/Go-Functions.png\" class=\"size-full wp-image-964\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/06\/Go-Functions.png?resize=433%2C569\" alt=\"Go Functions\" width=\"433\" height=\"569\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/06\/Go-Functions.png?w=433&amp;ssl=1 433w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/06\/Go-Functions.png?resize=228%2C300&amp;ssl=1 228w\" sizes=\"(max-width: 433px) 100vw, 433px\" \/><\/a><figcaption id=\"caption-attachment-964\" class=\"wp-caption-text\"><strong>Go Functions<\/strong><\/figcaption><\/figure>\n<p>For simplicity, I am using a single channel of type int. The function <em><strong>createChannel<\/strong><\/em> is used to initialize this<span class=\"Apple-converted-space\">\u00a0<\/span>global channel. The function <em><strong>writeToChannel<\/strong><\/em> writes an integer value to the channel and the third function <em><strong>readFromChannel<\/strong><\/em> reads an integer from the channel. All three functions are <em><strong>exported<\/strong><\/em>.<\/p>\n<p>The next step is to create a LIB file and Header file from the <em><strong>Go<\/strong><\/em> source.<\/p>\n<blockquote><p><span style=\"color: #0000ff;\">&gt; go build -o GoFunctions.lib -buildmode=c-shared GoFunctions.go<\/span><\/p><\/blockquote>\n<p>As discussed in the <a href=\"http:\/\/www.rangakrish.com\/index.php\/2018\/05\/27\/calling-go-functions-from-lisp\/\" target=\"_blank\" rel=\"noopener\">article<\/a>, we need to write appropriate <em><strong>C<\/strong><\/em> wrapper functions that get compiled into a <em><strong>DLL<\/strong><\/em>. See the following figure.<\/p>\n<figure id=\"attachment_965\" aria-describedby=\"caption-attachment-965\" style=\"width: 649px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/06\/Wrapper-Functions.png\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"965\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2018\/06\/24\/calling-go-functions-from-lisp-part-2\/wrapper-functions\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2018\/06\/Wrapper-Functions.png\" data-orig-size=\"649,487\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&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=\"Wrapper Functions\" data-image-description=\"&lt;p&gt;Wrapper Functions&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Wrapper Functions&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2018\/06\/Wrapper-Functions.png\" class=\"size-full wp-image-965\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/06\/Wrapper-Functions.png?resize=649%2C487\" alt=\"Wrapper Functions\" width=\"649\" height=\"487\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/06\/Wrapper-Functions.png?w=649&amp;ssl=1 649w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/06\/Wrapper-Functions.png?resize=300%2C225&amp;ssl=1 300w\" sizes=\"(max-width: 649px) 100vw, 649px\" \/><\/a><figcaption id=\"caption-attachment-965\" class=\"wp-caption-text\"><strong>Wrapper Functions<\/strong><\/figcaption><\/figure>\n<p>Building the DLL is a two-step process:<\/p>\n<blockquote><p><span style=\"color: #0000ff;\">&gt; gcc -c GoFunctionsWrapper.c<\/span><\/p>\n<p><span style=\"color: #0000ff;\">&gt; gcc -shared -o GoFunctionsWrapper.dll GoFunctionsWrapper.o GoFunctions.lib<\/span><\/p><\/blockquote>\n<p>We have to copy <em><strong>GoFunctionsWrapper.dll<\/strong><\/em> and <em><strong>GoFunctions.lib<\/strong><\/em> to our Lisp project directory (or make sure they are in executable path).<\/p>\n<h2><em><strong>Lisp Layer:<\/strong><\/em><\/h2>\n<p>Now we are ready to write our <em><strong>LispWorks Lisp<\/strong><\/em> code. As discussed in the earlier article, we have to declare the <em><strong>DLL<\/strong><\/em> functions in Lisp and ensure that the <em><strong>DLL<\/strong><\/em> is registered properly.<\/p>\n<figure id=\"attachment_966\" aria-describedby=\"caption-attachment-966\" style=\"width: 661px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/06\/Declaring-the-DLL-Functions.png\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"966\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2018\/06\/24\/calling-go-functions-from-lisp-part-2\/declaring-the-dll-functions\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2018\/06\/Declaring-the-DLL-Functions.png\" data-orig-size=\"661,268\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&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=\"Declaring the DLL Functions\" data-image-description=\"&lt;p&gt;Declaring the DLL Functions&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Declaring the DLL Functions&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2018\/06\/Declaring-the-DLL-Functions.png\" class=\"size-full wp-image-966\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/06\/Declaring-the-DLL-Functions.png?resize=661%2C268\" alt=\"Declaring the DLL Functions\" width=\"661\" height=\"268\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/06\/Declaring-the-DLL-Functions.png?w=661&amp;ssl=1 661w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/06\/Declaring-the-DLL-Functions.png?resize=300%2C122&amp;ssl=1 300w\" sizes=\"(max-width: 661px) 100vw, 661px\" \/><\/a><figcaption id=\"caption-attachment-966\" class=\"wp-caption-text\"><strong>Declaring the DLL Functions<\/strong><\/figcaption><\/figure>\n<p>Now comes the interesting part. Since channels are meaningful only in concurrent programs, in order to use and test them, we have to write a multi-threaded Lisp program. Here is the simplest one that uses the <em><strong>Go<\/strong><\/em> functions we have implemented:<\/p>\n<figure id=\"attachment_967\" aria-describedby=\"caption-attachment-967\" style=\"width: 517px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/06\/Multi-threaded-Access.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"967\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2018\/06\/24\/calling-go-functions-from-lisp-part-2\/multi-threaded-access\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2018\/06\/Multi-threaded-Access.png\" data-orig-size=\"517,156\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&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=\"Multi-threaded Access\" data-image-description=\"&lt;p&gt;Multi-threaded Access&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Multi-threaded Access&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2018\/06\/Multi-threaded-Access.png\" class=\"size-full wp-image-967\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/06\/Multi-threaded-Access.png?resize=517%2C156\" alt=\"Multi-threaded Access\" width=\"517\" height=\"156\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/06\/Multi-threaded-Access.png?w=517&amp;ssl=1 517w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/06\/Multi-threaded-Access.png?resize=300%2C91&amp;ssl=1 300w\" sizes=\"(max-width: 517px) 100vw, 517px\" \/><\/a><figcaption id=\"caption-attachment-967\" class=\"wp-caption-text\"><strong>Multi-threaded Access<\/strong><\/figcaption><\/figure>\n<p>I am writing to the channel in a separate thread (similar to <em><strong>goroutines<\/strong><\/em>), while reading from the same channel in the main thread.<\/p>\n<p>Here is the output when I run the function:<\/p>\n<figure id=\"attachment_968\" aria-describedby=\"caption-attachment-968\" style=\"width: 383px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/06\/Testing-Normal.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"968\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2018\/06\/24\/calling-go-functions-from-lisp-part-2\/testing-normal\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2018\/06\/Testing-Normal.png\" data-orig-size=\"383,224\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&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 Channel\" data-image-description=\"&lt;p&gt;Testing Channel&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Testing Channel&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2018\/06\/Testing-Normal.png\" class=\"size-full wp-image-968\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/06\/Testing-Normal.png?resize=383%2C224\" alt=\"Testing Channel\" width=\"383\" height=\"224\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/06\/Testing-Normal.png?w=383&amp;ssl=1 383w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/06\/Testing-Normal.png?resize=300%2C175&amp;ssl=1 300w\" sizes=\"(max-width: 383px) 100vw, 383px\" \/><\/a><figcaption id=\"caption-attachment-968\" class=\"wp-caption-text\"><strong>Testing Channel<\/strong><\/figcaption><\/figure>\n<p>Super. What will happen if we write to the channel (unbuffered) and read from it in the same thread? Deadlock, right? Here is the version I wrote to test that behavior:<\/p>\n<figure id=\"attachment_969\" aria-describedby=\"caption-attachment-969\" style=\"width: 398px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/06\/Deadlock-Version.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"969\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2018\/06\/24\/calling-go-functions-from-lisp-part-2\/deadlock-version\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2018\/06\/Deadlock-Version.png\" data-orig-size=\"398,99\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&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=\"Deadlock Version\" data-image-description=\"&lt;p&gt;Deadlock Version&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Deadlock Version&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2018\/06\/Deadlock-Version.png\" class=\"size-full wp-image-969\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/06\/Deadlock-Version.png?resize=398%2C99\" alt=\"Deadlock Version\" width=\"398\" height=\"99\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/06\/Deadlock-Version.png?w=398&amp;ssl=1 398w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/06\/Deadlock-Version.png?resize=300%2C75&amp;ssl=1 300w\" sizes=\"(max-width: 398px) 100vw, 398px\" \/><\/a><figcaption id=\"caption-attachment-969\" class=\"wp-caption-text\"><strong>Deadlock Version<\/strong><\/figcaption><\/figure>\n<p>And here is output:<\/p>\n<figure id=\"attachment_970\" aria-describedby=\"caption-attachment-970\" style=\"width: 293px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/06\/Testing-Deadlock.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"970\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2018\/06\/24\/calling-go-functions-from-lisp-part-2\/testing-deadlock\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2018\/06\/Testing-Deadlock.png\" data-orig-size=\"293,52\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&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 Deadlock\" data-image-description=\"&lt;p&gt;Testing Deadlock&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Testing Deadlock&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2018\/06\/Testing-Deadlock.png\" class=\"size-full wp-image-970\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/06\/Testing-Deadlock.png?resize=293%2C52\" alt=\"Testing Deadlock\" width=\"293\" height=\"52\" \/><\/a><figcaption id=\"caption-attachment-970\" class=\"wp-caption-text\"><strong>Testing Deadlock<\/strong><\/figcaption><\/figure>\n<p>As expected, the program is deadlocked because after the first element is written, it cannot be consumed by another thread!<\/p>\n<p>So there we are. This example shows that we are able to use <em><strong>Go&#8217;s channels<\/strong> <\/em>via exported functions in a foreign language, in this case <em><strong>Lisp<\/strong><\/em>.<\/p>\n<p>As I mentioned in the beginning of this article, before using <em><strong>Go<\/strong><\/em> functions in a foreign language, we have to convince ourselves that this has definite advantages. Remember we now have two runtimes in our code, one from <em><strong>Go<\/strong><\/em> and another from <em><strong>Lisp<\/strong><\/em>. This can cause subtle problems in a large program, so we have to be careful, especially when passing objects around the two different runtimes.<\/p>\n<p>Download the sources from <a href=\"http:\/\/www.rangakrish.com\/downloads\/GoFromLisp.zip\" target=\"_blank\" rel=\"noopener\">here<\/a>. Have a great weekend!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 support for concurrency via Goroutines. [&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":[141,18,17],"tags":[110,142,99],"class_list":["post-963","post","type-post","status-publish","format-standard","hentry","category-golang","category-lisp","category-programming","tag-common-lisp","tag-go-language","tag-lispworks"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9OLnF-fx","jetpack-related-posts":[{"id":944,"url":"https:\/\/www.rangakrish.com\/index.php\/2018\/06\/10\/calling-lisp-functions-from-go-language\/","url_meta":{"origin":963,"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":928,"url":"https:\/\/www.rangakrish.com\/index.php\/2018\/05\/27\/calling-go-functions-from-lisp\/","url_meta":{"origin":963,"position":1},"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":2645,"url":"https:\/\/www.rangakrish.com\/index.php\/2021\/12\/25\/calling-lisp-functions-from-d-language\/","url_meta":{"origin":963,"position":2},"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":2057,"url":"https:\/\/www.rangakrish.com\/index.php\/2020\/07\/19\/calling-lisp-functions-from-elixir\/","url_meta":{"origin":963,"position":3},"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":3017,"url":"https:\/\/www.rangakrish.com\/index.php\/2023\/02\/16\/calling-external-dll-functions-from-julia\/","url_meta":{"origin":963,"position":4},"title":"Calling External DLL Functions from Julia","author":"admin","date":"February 16, 2023","format":false,"excerpt":"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\u2026","rel":"","context":"In &quot;Julia&quot;","block_context":{"text":"Julia","link":"https:\/\/www.rangakrish.com\/index.php\/category\/julia\/"},"img":{"alt_text":"The \"lispEval\" Function","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/code-300x117.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/code-300x117.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/code-300x117.jpg?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":2334,"url":"https:\/\/www.rangakrish.com\/index.php\/2021\/02\/28\/calling-c-methods-from-lispworks-lisp-through-com-interface\/","url_meta":{"origin":963,"position":5},"title":"Calling C# Methods from LispWorks Lisp through COM Interface","author":"admin","date":"February 28, 2021","format":false,"excerpt":"In an earlier article, I showed how to invoke C# methods from Sicstus Prolog. Today, I would like to detail the steps for doing the same from LispWorks Lisp. LispWorks Enterprise Edition comes budled with support for COM and Automation. This is what we will be using. What this means\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"The COM Server in C#","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/02\/C-Code-300x267.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/963","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=963"}],"version-history":[{"count":0,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/963\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/media?parent=963"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/categories?post=963"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/tags?post=963"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}