<commit_before>package golog

import . "github.com/mndrix/golog/term"

import "github.com/mndrix/ps"

// Frame represents a single frame in a Golog machine's call stack
type Frame interface {
    // Env returns this stack frame's current bindings
    Env() Bindings

    // Goal returns this stack frame's current goal
    Goal() Term

    // HasChoicePoint returns true if this stack frame has unexplored
    // choicepoints
    HasChoicePoint() bool

    // NewChild creates a child stack frame similar to this one with
    // this one as the child's parent
    NewChild(Term, Bindings, *ps.List, *ps.List) Frame

    // Parent returns this stack frame's parent stack frame
    Parent() Frame

    // TakeChoicePoint returns the next choice point in line
    // (nil if there isn't one) and a new frame with the remaining
    // choice points intact
    TakeChoicePoint() (ChoicePoint, Frame)
}

var frameBottom frame
func init() {
    frameBottom.parent = &frameBottom  // infinite parental loop
    frameBottom.env = NewBindings()
    frameBottom.disjs = ps.NewList()
    frameBottom.conjs = ps.NewList()
}

// NewFrame returns a new, empty stack from
func NewFrame() Frame {
    return &frameBottom
}

type frame struct {
    env     Bindings
    parent  *frame
    goal    Term
    disjs   *ps.List     // of ChoicePoint
    conjs   *ps.List     // of Continuation
}

func (f *frame) clone() *frame {
    var f1 frame
    f1.env = f.env
    f1.parent = f.parent
    f1.goal = f.goal
    f1.disjs = f.disjs
    f1.conjs = f1.conjs
    return &f1
}

func (parent *frame) NewChild(goal Term, env Bindings, conjs, disjs *ps.List) Frame {
    child := parent.clone()
    child.parent = parent
    child.goal = goal
    if env != nil {
        child.env = env
    }
    if conjs != nil {
        child.conjs = conjs
    }
    if disjs != nil {
        child.disjs = disjs
    }

    return child
}

func (f *frame) TakeChoicePoint() (ChoicePoint, Frame) {
    if f.disjs == nil || f.disjs.IsNil() {<commit_msg>Refactor frame.NewChild<commit_after>package golog

import . "github.com/mndrix/golog/term"

import "github.com/mndrix/ps"

// Frame represents a single frame in a Golog machine's call stack
type Frame interface {
    // Env returns this stack frame's current bindings
    Env() Bindings

    // Goal returns this stack frame's current goal
    Goal() Term

    // HasChoicePoint returns true if this stack frame has unexplored
    // choicepoints
    HasChoicePoint() bool

    // NewChild creates a child stack frame similar to this one with
    // this one as the child's parent
    NewChild(Term, Bindings, *ps.List, *ps.List) Frame

    // Parent returns this stack frame's parent stack frame
    Parent() Frame

    // TakeChoicePoint returns the next choice point in line
    // (nil if there isn't one) and a new frame with the remaining
    // choice points intact
    TakeChoicePoint() (ChoicePoint, Frame)
}

var frameBottom frame
func init() {
    frameBottom.parent = &frameBottom  // infinite parental loop
    frameBottom.env = NewBindings()
    frameBottom.disjs = ps.NewList()
    frameBottom.conjs = ps.NewList()
}

// NewFrame returns a new, empty stack from
func NewFrame() Frame {
    return &frameBottom
}

type frame struct {
    env     Bindings
    parent  *frame
    goal    Term
    disjs   *ps.List     // of ChoicePoint
    conjs   *ps.List     // of Continuation
}

func (f *frame) clone() *frame {
    var f1 frame
    f1.env = f.env
    f1.parent = f.parent
    f1.goal = f.goal
    f1.disjs = f.disjs
    f1.conjs = f1.conjs
    return &f1
}

func (f *frame) update(goal Term, env Bindings, conjs, disjs *ps.List) *frame {
    newb := f.clone()
    newb.goal = goal
    if env != nil {
        newb.env = env
    }
    if conjs != nil {
        newb.conjs = conjs
    }
    if disjs != nil {
        newb.disjs = disjs
    }
    return newb
}
func (f *frame) NewChild(goal Term, env Bindings, conjs, disjs *ps.List) Frame {
    child := f.update(goal, env, conjs, disjs)
    child.parent = f
    return child
}

func (f *frame) TakeChoicePoint() (ChoicePoint, Frame) {
    if f.disjs == nil || f.disjs.IsNil() {
{'fraction_non_alphanumeric': 0.09821858449687049, 'fraction_numerical': 0.0038517091959557053, 'mean_word_length': 2.5063291139240507, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2379493', 'n_tokens_mistral': 1355, 'n_tokens_neox': 1311, 'n_words': 453}