Get the latest tech news
Developing a Go bot embedding Ichiban Prolog
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. Hellabot design requires to program its triggers using a two step process as described in the code below: type Trigger struct { // Returns true if this trigger applies to the passed in message Condition func(*Bot, *Message) bool // The action to perform if Condition is true // return true if the message was 'consumed' Action func(*Bot, *Message) bool }
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. For this we transform the different fields of the*hbot.Message to Prolog terms using a function called MessageToTerms() and store its results in a string to be loaded by the next step. In our code we will have a single solution “This is the Prolog message”, but in case we had multiple ones the for sols.Next() { [...] } loop would ensure we capture all of them and return it to the client via the call irc.Reply().
Or read this on Hacker News