Axiom.Runtime.AbstractMachineState.Call C# (CSharp) Method

Call() public method

Call a predicate that takes no arguments
public Call ( string predicateName ) : bool
predicateName string predicate name only.
return bool
        public bool Call(string predicateName)
        {
            AMProgram program = (AMProgram)_program;

            AMInstructionSet iset = new AMInstructionSet();

            if (!program.IsDefined(predicateName + "/0"))
            {
                return false;
            }

            // Add the call instruction
            program.P = new ProgramNode(iset.CreateInstruction("call", predicateName, "0"));

            program.AddProgramNode(program.P);

            // Add the halt insturction
            program.AddInstruction(iset.CreateInstruction("halt"));

            // Execute the program
            Transition();

            return !_fail;
        }

Same methods

AbstractMachineState::Call ( string predicateName, int arity, object args ) : bool
AbstractMachineState::Call ( string predicatename, int arity, object args, bool more ) : bool

Usage Example

Ejemplo n.º 1
0
        public void Call()
        {
            ArrayList prog = new ArrayList();
            prog.Add(new NopInstruction());
            prog.Add(new HaltInstruction());

            AbstractMachineState state = new AbstractMachineState(new AMFactory());
            state.Initialize(prog);

            AMProgram program = (AMProgram)state.Program;

            ArrayList predicateCode = new ArrayList();

            AMInstructionSet iset = new AMInstructionSet();

            // say_hello(X) :- write(X).

            predicateCode.Add(iset.CreateInstruction("bcall", "write/1"));
            predicateCode.Add(iset.CreateInstruction("proceed"));

            AbstractTerm X0 = (AbstractTerm)state["X0"];

            X0.Assign(new ConstantTerm("Hello, World!"));

            program.AssertFirst("say_hello", 1, predicateCode);

            Assert.IsTrue(state.Call("say_hello", 1, new object[] { "Hello man" }));
        }