Snippets

Patrick Logan Prolog Evaluation In Go Using Byrd Boxes

Created by Patrick Logan
box := NewByrdBox(predicate)
// ...
control := make(chan struct{})    // Could be a channel of useful information instead
exit, except := box.Call(bindings, control)
// e.g. maybe interacting with a user...
select {
case soln, ok <- exit: {
        if !ok {
            // Failed...
        }
        // Use the solution...
        // ...
        control <- struct{}{}    // e.g. ready for the next solution
    }
case intermediate, ok <- except: {
        if !ok {
            // Stopped... maybe control was closed
        }
        // Use the intermediate value
        // e.g. maybe trace/debug info, e.g. a sub-goal byrd box was created so draw it
        // e.g. maybe the value is an exception or a breakpoint so display it and prompt for an action
        control <- struct{}{}    // e.g. maybe user continued the debugger. could be a "step" or a "continue" message instead of an empty struct
    }
}
// ...
close(control)    // e.g. maybe the user's tired of all this debugging and needs a coffee

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.