First Encounter with the Ring Programming Language

Written by on August 7, 2021 in C++, Programming, Ring Language with 0 Comments

The Ring Programming Language, designed by Mahmoud Fayed,  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 “Beginning Ring Programming” 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. 

The language seems to have many interesting features, but two things attracted my attention:

* Natural language programming

* Ease of embedding in C/C++

“Natural language programming” definitely sounds like great fun, but I am not a great fan of that idea. Personally, I prefer languages such as Mathematica’s Wolfram language whose claim to fame (among other things) is brevity and expressiveness.

For those who are interested, this article by the author of Ring programming language discusses an example of Natural language programming in Ring.

For the purpose of today’s article, I decided to explore the idea of embedding Ring in a C++ program.

First, I downloaded and installed the environment on my Windows 64-bit machine. Here is the directory structure after installation:

Ring Installation Directory

Ring Installation Directory

I then created a new “Console C++ Project” in Visual Studio (mine is Visual Studio 2019, ver 16.10.4).

Here is the main source file:

Sample Program

Sample Program

The project settings must be updated with the following elements:

  • Additional Include Directory: G:\ring\language\include
  • Additional Library Directory: G:\ring\lib
  • Additional Library Dependency: ring.lib
  • Finally, the DLL file “G:\ring\bin\ring.dll” must be in the PATH.

About the Code

There is nothing fancy in the code. Instead of making the calls to the underlying “C” functions directly, I wrote a simple wrapper that contains a function for executing Ring code fragments. Of course, more functionality can be included in this layer.

The program creates two different Ring environments 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.

Here is the output from the program:

Program Output

Program Output

As this example shows, it is indeed quite straightforward to embed Ring runtime in a C/C++ program. I intend to explore some of the other features of Ring in the weeks to come and will share my experience.

Here is the C++ source used in this article.

Have a nice weekend!

Tags: ,

Subscribe

If you enjoyed this article, subscribe now to receive more just like it.

Subscribe via RSS Feed

Leave a Reply

Your email address will not be published. Required fields are marked *

Top