Skip to content
This repository was archived by the owner on Nov 15, 2019. It is now read-only.
This repository was archived by the owner on Nov 15, 2019. It is now read-only.

Can't create an interpreter with pre-bound variables. #24

@tbolsh

Description

@tbolsh

Sorry - it might be a rookie error.
I am trying to create an interpreter with some variables bound to values. I want this variables to have a name, for example:

	mId := golog.NewMachine().Consult(`test_unify(X, X).`)
	t, v := term.NewAtom("atom"), term.NewVar("W")
	b, _ := term.NewBindings().WithNames(psm.Set("W", v)).Bind(v, t)
	mId = mId.SetBindings(b)
	solutions := mId.ProveAll(`test_unify(P, W).`)
	for _, solution := range solutions {
		fmt.Printf("pattern: variable is %s\n", solution.ByName_("P"))
	}

I get

panic: Can't set names when names have already been set
goroutine 1 [running]:
github.com/mndrix/golog/term.(*envMap).WithNames(0xc420368560, 0x5ca2e0, 0xc4202a7a40, 0x5ca100, 0xc420368560)
/home/diguser/projects/Watson/Engine/apicache/src/github.com/mndrix/golog/term/bindings.go:135 +0x140
github.com/mndrix/golog.(*machine).ProveAll(0xc4200928c0, 0x506540, 0x54a550, 0x1, 0x1, 0x253)
/home/diguser/projects/Watson/Engine/apicache/src/github.com/mndrix/golog/machine.go:341 +0x218

If I do not use .WithNames(psm.Set("W", v)). then there is no effect of binding variable to value, because it cannot be found by name (ByName_).

I checked the code and understand why it is happening, but how can I get around it other then creating a text representation of my long list of atoms? Is that possible?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions