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

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

Open
tbolsh opened this issue Jan 12, 2018 · 1 comment
Open

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

tbolsh opened this issue Jan 12, 2018 · 1 comment

Comments

@tbolsh
Copy link

tbolsh commented Jan 12, 2018

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?

@deosjr
Copy link

deosjr commented Jan 16, 2018

After trying to figure out what you want to do here, I suggest you solve this in Prolog.
Something like the following will bind just fine:

mId := golog.NewMachine().Consult(`test_unify(X, X).`)
solutions := mId.ProveAll(`W=atom, test_unify(P, W).`)
for _, solution := range solutions {
	fmt.Printf("pattern: variable is %s\n", solution.ByName_("P"))
}

If that does not solve your problem, could you give some more background as to why you want to create a machine with prebound variables in it?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants