Developing a go bot embedding ichiban Prolog

submited by
Style Pass
2024-09-23 19:30:16

Ichiban Prolog is a #golang implementation of an ISO compatible Prolog. To learn how to embed it, I decided to add Prolog support to Hellabot, a simple irc bot.

Because the code to develop the trigger is in go, it requires to re-compile the bot every time a new trigger is created/updated. Because of this, embedding a language that can read the code externally is an attractive solution. In this case, I have selected Prolog due to being a flexible, high level language, extremely well documented and ideal to parse text using Prolog’s DCGs.

Our strategy to remove the recompilation dependency, we will update bot to read Prolog code from a file that can be edited any time by the user. In this post, the Prolog code will be loaded when Hellabot triggers the even on message reception. This will allow the user to change the bot’s logic without the need to recompile and redeploy the bot.

To make this job easier, we first simplify the trigger struct to have a single function that will execute the Prolog code. This new Exec() function will trigger the condition and execute the action in a single step. To make this possible we create a new struct to be used for Prolog triggers:

Leave a Comment