{"id":2496,"date":"2021-08-07T19:26:17","date_gmt":"2021-08-07T13:56:17","guid":{"rendered":"https:\/\/www.rangakrish.com\/?p=2496"},"modified":"2021-08-21T15:45:39","modified_gmt":"2021-08-21T10:15:39","slug":"first-encounter-with-the-ring-programming-language","status":"publish","type":"post","link":"https:\/\/www.rangakrish.com\/index.php\/2021\/08\/07\/first-encounter-with-the-ring-programming-language\/","title":{"rendered":"First Encounter with the Ring Programming Language"},"content":{"rendered":"<p>The <a href=\"https:\/\/ring-lang.sourceforge.io\" target=\"_blank\" rel=\"noopener\"><em><strong>Ring Programming Language<\/strong><\/em><\/a>, designed by Mahmoud Fayed,<span class=\"Apple-converted-space\">\u00a0 <\/span>has been around since 2016. I came to know of it quite accidentally two weeks ago when I received a promotional email from <em><strong>Apress<\/strong><\/em> about their book <em><strong>&#8220;Beginning Ring Programming&#8221;<\/strong><\/em> by Mansour Ayouni, published in 2020. I immediately did a google search about the language and finding it interesting, ordered the book. I am still going through the book.<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<p>The language seems to have many interesting features, but two things attracted my attention:<\/p>\n<blockquote><p>* Natural language programming<\/p>\n<p>* Ease of embedding in C\/C++<\/p><\/blockquote>\n<p><em><strong>&#8220;Natural language programming&#8221;<\/strong><\/em> definitely sounds like great fun, but I am not a great fan of that idea. Personally, I prefer languages such as <a href=\"https:\/\/www.wolfram.com\/language\/\" target=\"_blank\" rel=\"noopener\"><em><strong>Mathematica&#8217;s<\/strong> <strong>Wolfram<\/strong><\/em><\/a> language whose claim to fame (among other things) is brevity and expressiveness.<\/p>\n<p>For those who are interested, <a href=\"https:\/\/www.codeproject.com\/Articles\/1138605\/Natural-Language-Programming-in-the-Ring-Programmi\" target=\"_blank\" rel=\"noopener\"><em><strong>this article<\/strong><\/em><\/a> by the author of Ring programming language discusses an example of <em><strong>Natural language programming<\/strong><\/em> in <em><strong>Ring<\/strong><\/em>.<\/p>\n<p>For the purpose of today&#8217;s article, I decided to explore the idea of embedding <em><strong>Ring<\/strong><\/em> in a <em><strong>C++<\/strong><\/em> program.<\/p>\n<p>First, I downloaded and installed the environment on my <em><strong>Windows<\/strong> <\/em>64-bit machine. Here is the directory structure after installation:<\/p>\n<figure id=\"attachment_2497\" aria-describedby=\"caption-attachment-2497\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/08\/directory.jpg?ssl=1\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" data-attachment-id=\"2497\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/08\/07\/first-encounter-with-the-ring-programming-language\/directory\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/08\/directory.jpg\" data-orig-size=\"1020,528\" 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;1628269004&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=\"Ring Installation Directory\" data-image-description=\"&lt;p&gt;Ring Installation Directory&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Ring Installation Directory&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/08\/directory.jpg\" class=\"wp-image-2497\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/08\/directory.jpg?resize=500%2C259&#038;ssl=1\" alt=\"Ring Installation Directory\" width=\"500\" height=\"259\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/08\/directory.jpg?resize=300%2C155&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/08\/directory.jpg?resize=768%2C398&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/08\/directory.jpg?w=1020&amp;ssl=1 1020w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2497\" class=\"wp-caption-text\"><strong>Ring Installation Directory<\/strong><\/figcaption><\/figure>\n<p>I then created a new <em><strong>&#8220;Console C++ Project&#8221;<\/strong><\/em> in <em><strong>Visual Studio<\/strong><\/em> (mine is <em><strong>Visual Studio 2019, ver 16.10.4<\/strong><\/em>).<\/p>\n<p>Here is the main source file:<\/p>\n<figure id=\"attachment_2498\" aria-describedby=\"caption-attachment-2498\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/08\/Code.jpg?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"2498\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/08\/07\/first-encounter-with-the-ring-programming-language\/code-17\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/08\/Code.jpg\" data-orig-size=\"882,1097\" 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;1628324102&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=\"Sample Program\" data-image-description=\"&lt;p&gt;Sample Program&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Sample Program&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/08\/Code-823x1024.jpg\" class=\"wp-image-2498\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/08\/Code.jpg?resize=500%2C622&#038;ssl=1\" alt=\"Sample Program\" width=\"500\" height=\"622\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/08\/Code.jpg?resize=241%2C300&amp;ssl=1 241w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/08\/Code.jpg?resize=823%2C1024&amp;ssl=1 823w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/08\/Code.jpg?resize=768%2C955&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/08\/Code.jpg?w=882&amp;ssl=1 882w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2498\" class=\"wp-caption-text\"><strong>Sample Program<\/strong><\/figcaption><\/figure>\n<p>The project settings must be updated with the following elements:<\/p>\n<ul>\n<li>Additional Include Directory: <em><strong>G:\\ring\\language\\include<\/strong><\/em><\/li>\n<li>Additional Library Directory: <em><strong>G:\\ring\\lib<\/strong><\/em><\/li>\n<li>Additional Library Dependency: <em><strong>ring.lib<\/strong><\/em><\/li>\n<li>Finally, the DLL file <em><strong>&#8220;G:\\ring\\bin\\ring.dll&#8221;<\/strong><\/em> must be in the <em><strong>PATH<\/strong><\/em>.<\/li>\n<\/ul>\n<h3>About the Code<\/h3>\n<p>There is nothing fancy in the code. Instead of making the calls to the underlying <em><strong>&#8220;C&#8221;<\/strong><\/em> functions directly, I wrote a simple wrapper that contains a function for executing <em><strong>Ring<\/strong><\/em> code fragments. Of course, more functionality can be included in this layer.<\/p>\n<p>The program creates two different <em><strong>Ring<\/strong> <strong>environments<\/strong><\/em> and executes code in each. The key point to note is that the two environments represent completely independent states and hence creating and modifying variables in one environment does not affect the other.<\/p>\n<p>Here is the output from the program:<\/p>\n<figure id=\"attachment_2499\" aria-describedby=\"caption-attachment-2499\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/08\/Output.jpg?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"2499\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/08\/07\/first-encounter-with-the-ring-programming-language\/output-5\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/08\/Output.jpg\" data-orig-size=\"562,241\" 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;1628362449&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\/08\/Output.jpg\" class=\"wp-image-2499\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/08\/Output.jpg?resize=500%2C214&#038;ssl=1\" alt=\"Program Output\" width=\"500\" height=\"214\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/08\/Output.jpg?resize=300%2C129&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/08\/Output.jpg?w=562&amp;ssl=1 562w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2499\" class=\"wp-caption-text\"><strong>Program Output<\/strong><\/figcaption><\/figure>\n<p>As this example shows, it is indeed quite straightforward to embed <em><strong>Ring<\/strong><\/em> runtime in a <em><strong>C\/C++<\/strong><\/em> program. I intend to explore some of the other features of <em><strong>Ring<\/strong><\/em> in the weeks to come and will share my experience.<\/p>\n<p>Here is the <a href=\"http:\/\/www.rangakrish.com\/downloads\/TestRing.cpp\" target=\"_blank\" rel=\"noopener\"><em><strong>C++<\/strong> <strong>source<\/strong><\/em><\/a> used in this article.<\/p>\n<p>Have a nice weekend!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Ring Programming Language, designed by Mahmoud Fayed,\u00a0 has been around since 2016. I came to know of it quite accidentally two weeks ago when I received a promotional email from Apress about their book &#8220;Beginning Ring Programming&#8221; by Mansour Ayouni, published in 2020. I immediately did a google search about the language and finding [&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_post_was_ever_published":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}},"categories":[49,17,289],"tags":[67,288],"class_list":["post-2496","post","type-post","status-publish","format-standard","hentry","category-c","category-programming","category-ring-language","tag-c","tag-ring-programming-language"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9OLnF-Eg","jetpack-related-posts":[{"id":2506,"url":"https:\/\/www.rangakrish.com\/index.php\/2021\/08\/21\/loop-command-in-ring-programming-language\/","url_meta":{"origin":2496,"position":0},"title":"&#8220;Loop&#8221; Command in Ring Programming Language","author":"admin","date":"August 21, 2021","format":false,"excerpt":"In my last article, I had written about how easy it is to execute Ring code from within C\/C++. Today's article takes a look at the \"Loop\" command. This command is very similar to \"continue\" in many languages such as C++, Java, Python. etc. It is used to skip the\u2026","rel":"","context":"In &quot;Programming&quot;","block_context":{"text":"Programming","link":"https:\/\/www.rangakrish.com\/index.php\/category\/programming\/"},"img":{"alt_text":"\"Continue\" in Java","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/08\/javacode-300x183.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":2516,"url":"https:\/\/www.rangakrish.com\/index.php\/2021\/09\/04\/ring-language-dynamic-behavior-of-classes-and-objects\/","url_meta":{"origin":2496,"position":1},"title":"Ring Language: Dynamic Behavior of Classes and Objects","author":"admin","date":"September 4, 2021","format":false,"excerpt":"We have been exploring the Ring Programming Language\u00a0in the last two articles.\u00a0Ring is a dynamic programming language with many interesting features. In today's article, let us try to understand how this dynamic behavior is reflected in Classes and Objects. In Ring, we can define classes at runtime. One way to\u2026","rel":"","context":"In &quot;Programming&quot;","block_context":{"text":"Programming","link":"https:\/\/www.rangakrish.com\/index.php\/category\/programming\/"},"img":{"alt_text":"Dynamic Class Creation","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/image1-300x146.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1278,"url":"https:\/\/www.rangakrish.com\/index.php\/2018\/12\/02\/book-review-functional-programming-in-c\/","url_meta":{"origin":2496,"position":2},"title":"Book Review: Functional Programming in C++","author":"admin","date":"December 2, 2018","format":false,"excerpt":"Title: Functional Programming in C++: How to improve your C++ programs using functional techniques Author: Ivan Cukic Publisher: Manning Publications Co. Year: 2019 This book came out recently, about a week ago. I bought it immediately, and when I started to read it, I couldn\u2019t put it down! Very informative\u2026","rel":"","context":"In &quot;Book Review&quot;","block_context":{"text":"Book Review","link":"https:\/\/www.rangakrish.com\/index.php\/category\/book-review\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2922,"url":"https:\/\/www.rangakrish.com\/index.php\/2022\/10\/06\/why-learn-prolog\/","url_meta":{"origin":2496,"position":3},"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":[]},{"id":3070,"url":"https:\/\/www.rangakrish.com\/index.php\/2023\/04\/02\/building-v-language-dll\/","url_meta":{"origin":2496,"position":4},"title":"Building V Language DLL","author":"admin","date":"April 2, 2023","format":false,"excerpt":"The relatively new V Programming Language (Vlang) boasts of some interesting features such as \u201cfast compilation\u201d and runtime performance \u201cas fast as C\u201d, at the same time being a \u201csimple language\u201d. As I normally do with other languages that I learn and use, I decided to see how easy it\u2026","rel":"","context":"In &quot;Programming&quot;","block_context":{"text":"Programming","link":"https:\/\/www.rangakrish.com\/index.php\/category\/programming\/"},"img":{"alt_text":"V Program","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/04\/V-source-267x300.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":2927,"url":"https:\/\/www.rangakrish.com\/index.php\/2022\/10\/20\/why-learn-lisp\/","url_meta":{"origin":2496,"position":5},"title":"Why Learn Lisp?","author":"admin","date":"October 20, 2022","format":false,"excerpt":"In the last article, I had shared my views on why programmers should learn Prolog, preferably as the first language. What language should one learn next? I strongly pitch for Lisp, to be precise, \u201cCommon Lisp\u201d. Lisp happens to be the second oldest (1958) programming language, only after Fortran (1957)!\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/2496","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=2496"}],"version-history":[{"count":0,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/2496\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/media?parent=2496"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/categories?post=2496"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/tags?post=2496"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}