Exemplo n.º 1
0
 public override Metastructure MetaMetaUnify(Metastructure value, out IEnumerable<CutState> filter)
 {
     var s = value as Suspension;
     if (s == null) throw new ArgumentTypeException("MetaMetaUnify", "value", value, typeof(Suspension));
     if (context != s.context) throw new ArgumentException("Can't unify suspended goals across PrologContexts.");
     
     filter = Prover(CombineGoals(DelayedGoal, s.DelayedGoal));
     return MakeSuspension(null, CombineGoals(FrozenGoal, s.FrozenGoal));
 }
Exemplo n.º 2
0
        internal override Metastructure MetaMetaUnify(Metastructure theirMetaStructure, PrologContext context)
        {
            var s = theirMetaStructure as Suspension;
            if (s == null) throw new ArgumentTypeException("MetaMetaUnify", "theirMetaStructure", theirMetaStructure, typeof(Suspension));
            if (context != s.context) throw new ArgumentException("Can't unify suspended goals across PrologContexts.");

            context.WakeUpGoal(CombineGoals(DelayedGoal, s.DelayedGoal));
            return MakeSuspension(null, CombineGoals(FrozenGoal, s.FrozenGoal));
        }
Exemplo n.º 3
0
        internal IEnumerable <CutState> MetaUnify(Metastructure m)
        {
            if (IsBound)
            {
                throw new InvalidOperationException("Cannot meta-unify a bound variable");
            }
            Metastructure          old    = MetaBinding;
            IEnumerable <CutState> filter = null;

            if (old != null)
            {
                var merged = old.MetaMetaUnify(m, out filter);
                if (merged != null)
                {
                    mValue = merged;
                }
                else
                {
                    // All we have a suspended goal, which is now in the filter
                    // there's no frozen goal, so we just unbind the variable
                    // and see what the filter does.
                    mValue = this;
                }
            }
            else
            {
                mValue = m;
            }

            try
            {
                if (filter != null)
#pragma warning disable 414, 168, 219
                {
                    // ReSharper disable UnusedVariable
                    foreach (var ignore in filter)
                    // ReSharper restore UnusedVariable
#pragma warning restore 414, 168, 219
                    {
                        yield return(CutState.Continue);
                    }
                }
                else
                {
                    yield return(CutState.Continue);
                }
            }
            finally
            {
                mValue = old;
            }
        }
Exemplo n.º 4
0
        IEnumerable <bool> UnifyMetaMeta(Metastructure myMetaStructure, Metastructure theirMetaStructure, LogicVariable them)
        {
            IEnumerable <CutState> filter;

            mValue     = myMetaStructure.MetaMetaUnify(theirMetaStructure, out filter);
            them.Value = this;
#pragma warning disable 414, 168, 219
            // ReSharper disable UnusedVariable
            foreach (var ignore in filter)
            // ReSharper restore UnusedVariable
#pragma warning restore 414, 168, 219
            {
                yield return(false);
            }
            mValue      = myMetaStructure;
            them.mValue = theirMetaStructure; //null;
            //them.IsBound = false;
        }
Exemplo n.º 5
0
 internal bool UnifyWithCanonicalValue(object value, PrologContext context)
 {
     if (!IsBound)
     {
         Metastructure m = MetaBinding;
         if (m == null)
         {
             // We're binding a truly unbound variable to something.
             if (value != this)
             {
                 var xl = value as LogicVariable;
                 if (xl != null)
                 {
                     Metastructure xm2;
                     if ((xm2 = xl.MetaBinding) != null)
                     {
                         // We're binding a truly unbound variable to a meta-bound variable
                         xl.UnifyMetaVar(xm2, this, context);
                         return(true);
                     }
                 }
                 SaveAndUpdate(value, context); // sets IsBound
             }
             return(true);
         }
         // This is an attributed (metabound) variable
         var l = value as LogicVariable;
         if (l == null)
         {
             UnifyMetaTerm(m, value, context);
             return(true);
         }
         Metastructure m2 = l.MetaBinding;
         if (m2 == null)
         {
             // Need to alias l to this, that's most easily done by letting l unify to this.
             UnifyMetaVar(m, l, context);
             return(true);
         }
         UnifyMetaMeta(m, m2, l, context);
         return(true);
     }
     return(Value.Equals(value));
 }
Exemplo n.º 6
0
        IEnumerable <bool> UnifyMetaTerm(Metastructure m, object value)
        {
            Value = value;
            try
            {
#pragma warning disable 414, 168, 219
                // ReSharper disable UnusedVariable
                foreach (var ignore in m.MetaTermUnify(value))
                // ReSharper restore UnusedVariable
#pragma warning restore 414, 168, 219
                {
                    yield return(false);
                }
            }
            finally
            {
                mValue = m;
                //IsBound = false;
            }
        }
Exemplo n.º 7
0
 internal IEnumerable <bool> UnifyWithCanonicalValue(object value)
 {
     if (!IsBound)
     {
         Metastructure m = MetaBinding;
         if (m == null)
         {
             // We're binding a truly unbound variable to something.
             if (value != this)
             {
                 var xl = value as LogicVariable;
                 if (xl != null)
                 {
                     Metastructure xm2;
                     if ((xm2 = xl.MetaBinding) != null)
                     {
                         // We're binding a truly unbound variable to a meta-bound variable
                         return(xl.UnifyMetaVar(xm2, this));
                     }
                 }
                 Value = value; // sets IsBound
             }
             return(SucceedOnceAndThenUnBind());
         }
         // This is an attributed (metabound) variable
         var l = value as LogicVariable;
         if (l == null)
         {
             return(UnifyMetaTerm(m, value));
         }
         Metastructure m2 = l.MetaBinding;
         if (m2 == null)
         {
             // Need to alis l to this, that's most easily done by letting l unify to this.
             return(UnifyMetaVar(m, l));
         }
         return(UnifyMetaMeta(m, m2, l));
     }
     return(ToEnumerator(Value.Equals(value)));
 }
Exemplo n.º 8
0
 IEnumerable<bool> UnifyMetaMeta(Metastructure myMetaStructure, Metastructure theirMetaStructure, LogicVariable them)
 {
     IEnumerable<CutState> filter;
     object mergedMetaValue = myMetaStructure.MetaMetaUnify(theirMetaStructure, out filter);
     mValue = mergedMetaValue??this;
     them.Value = this;
     #pragma warning disable 414, 168, 219
     // ReSharper disable UnusedVariable
     foreach (var ignore in filter)
         // ReSharper restore UnusedVariable
     #pragma warning restore 414, 168, 219
         yield return false;
     mValue = myMetaStructure;
     them.mValue = theirMetaStructure; //null;
     //them.IsBound = false;
 }
Exemplo n.º 9
0
 /// <summary>
 /// This is an attributed variable with attribute myMetaStructure, unify it with attributed variable them, with attribute theirMetaStructure.
 /// </summary>
 /// <param name="myMetaStructure">This variable's metavalue</param>
 /// <param name="theirMetaStructure">The meta-value of the variable we're unifying with</param>
 /// <param name="them">The variable to unify with</param>
 /// <param name="context">Prolog context</param>
 void UnifyMetaMeta(Metastructure myMetaStructure, Metastructure theirMetaStructure, LogicVariable them, PrologContext context)
 {
     SaveAndUpdate(myMetaStructure.MetaMetaUnify(theirMetaStructure, context), context);
     them.SaveAndUpdate(this, context);
 }
Exemplo n.º 10
0
        internal IEnumerable<CutState> MetaUnify(Metastructure m)
        {
            if (IsBound) throw new InvalidOperationException("Cannot meta-unify a bound variable");
            Metastructure old = MetaBinding;
            IEnumerable<CutState> filter = null;
            if (old != null)
            {
                var merged = old.MetaMetaUnify(m, out filter);
                if (merged != null)
                    mValue = merged;
                else
                    // All we have a suspended goal, which is now in the filter
                    // there's no frozen goal, so we just unbind the variable
                    // and see what the filter does.
                    mValue = this;
            }
            else
            {
                mValue = m;
            }

            try
            {
                if (filter != null)
            #pragma warning disable 414, 168, 219
                    // ReSharper disable UnusedVariable
                    foreach (var ignore in filter)
                        // ReSharper restore UnusedVariable
            #pragma warning restore 414, 168, 219
                        yield return CutState.Continue;
                else
                    yield return CutState.Continue;
            }
            finally
            {
                mValue = old;
            }
        }
Exemplo n.º 11
0
 internal IEnumerable<CutState> AddSuspendedGoal(Structure goal, PrologContext context)
 {
     var old = MetaBinding;
     mValue = new Metastructure(goal, null, context, old);
     try
     {
         yield return CutState.Continue;
     }
     finally
     {
         mValue = (object)old??this;
     }
 }
Exemplo n.º 12
0
 internal IEnumerable<CutState> AddFrozenGoal(Structure goal, PrologContext context)
 {
     var old = MetaBinding;
     mValue = new Metastructure(null, goal, context, old);
     try
     {
         yield return CutState.Continue;
     }
     finally
     {
         mValue = old;
     }
 }
Exemplo n.º 13
0
 /// <summary>
 /// This is an atributed variable with metastructure m, unify with unattributed and unbound variable v.
 /// </summary>
 /// <param name="m">This variable's metavalue</param>
 /// <param name="l">The completely unbound logic variable to which we are binding.</param>
 /// <param name="context">Prolog context</param>
 void UnifyMetaVar(Metastructure m, LogicVariable l, PrologContext context)
 {
     System.Diagnostics.Debug.Assert(l.MetaBinding == null);
     l.SaveAndUpdate(this, context);
     this.SaveAndUpdate(m.MetaVarUnify(l, context), context);
 }
Exemplo n.º 14
0
 /// <summary>
 /// This is an atributed variable with metastructure m, unify with unattributed and unbound variable v.
 /// </summary>
 /// <param name="m">This variable's metavalue</param>
 /// <param name="l">The completely unbound logic variable to which we are binding.</param>
 /// <param name="context">Prolog context</param>
 void UnifyMetaVar(Metastructure m, LogicVariable l, PrologContext context)
 {
     Debug.Assert(l.MetaBinding == null);
     l.SaveAndUpdate(this, context);
     this.SaveAndUpdate(m.MetaVarUnify(l, context), context);
 }
Exemplo n.º 15
0
        /// <summary>
        /// Merge the information from two Metastructures into one new metastructure.
        /// </summary>
        /// <param name="theirMetaStructure">The Metastructure to merge with.</param>
        /// <param name="context">Context in which to execute suspended goals.</param>
        /// <returns>The merged Metastructure.</returns>
        public Metastructure MetaMetaUnify(Metastructure theirMetaStructure, PrologContext context)
        {
            if (theirMetaStructure == null) throw new ArgumentTypeException("MetaMetaUnify", "theirMetaStructure", theirMetaStructure, typeof(Metastructure));
            if (context != theirMetaStructure.Context) throw new ArgumentException("Can't unify suspended goals across PrologContexts.");

            context.WakeUpGoal(CombineGoals(DelayedGoal, theirMetaStructure.DelayedGoal));
            return MakeSuspension(null, CombineGoals(FrozenGoal, theirMetaStructure.FrozenGoal));
        }
Exemplo n.º 16
0
 /// <summary>
 /// This is an attributed variable with attribute m, unify it with value.
 /// </summary>
 /// <param name="m">Current attribute</param>
 /// <param name="value">Value to give it</param>
 /// <param name="context">Prolog context (to get trail and wakeup list)</param>
 /// <returns>Success</returns>
 void UnifyMetaTerm(Metastructure m, object value, PrologContext context)
 {
     Value = value;
     m.MetaTermUnify(value, context);
 }
Exemplo n.º 17
0
 internal abstract Metastructure MetaMetaUnify(Metastructure theirMetaStructure, PrologContext context);
Exemplo n.º 18
0
 void UnifyMetaVar(Metastructure m, LogicVariable l, PrologContext context)
 {
     System.Diagnostics.Debug.Assert(l.MetaBinding == null);
     l.SaveAndUpdate(this, context);
     m.MetaVarUnify(l, context);
 }
Exemplo n.º 19
0
 /// <summary>
 /// This is an attributed variable with attribute m, unify it with value.
 /// </summary>
 /// <param name="m">Current attribute</param>
 /// <param name="value">Value to give it</param>
 /// <param name="context">Prolog context (to get trail and wakeup list)</param>
 /// <returns>Success</returns>
 void UnifyMetaTerm(Metastructure m, object value, PrologContext context)
 {
     Value = value;
     m.MetaTermUnify(value, context);
 }
Exemplo n.º 20
0
 IEnumerable<bool> UnifyMetaTerm(Metastructure m, object value)
 {
     Value = value;
     try
     {
     #pragma warning disable 414, 168, 219
         // ReSharper disable UnusedVariable
         foreach (var ignore in m.MetaTermUnify(value))
             // ReSharper restore UnusedVariable
     #pragma warning restore 414, 168, 219
             yield return false;
     }
     finally
     {
         mValue = m;
         //IsBound = false;
     }
 }
Exemplo n.º 21
0
 internal IEnumerable<CutState> MetaUnify(Metastructure m)
 {
     if (IsBound) throw new InvalidOperationException("Cannot meta-unify a bound variable");
     Metastructure old = MetaBinding;
     IEnumerable<CutState> filter = null;
     mValue = old != null ? old.MetaMetaUnify(m, out filter) : m;
     try
     {
         if (filter != null)
     #pragma warning disable 414, 168, 219
             // ReSharper disable UnusedVariable
             foreach (var ignore in filter)
                 // ReSharper restore UnusedVariable
     #pragma warning restore 414, 168, 219
                 yield return CutState.Continue;
         else
             yield return CutState.Continue;
     }
     finally
     {
         mValue = old;
     }
 }
Exemplo n.º 22
0
 IEnumerable<bool> UnifyMetaVar(Metastructure m, LogicVariable l)
 {
     Debug.Assert(l.MetaBinding == null);
     l.Value = this;
     IEnumerable<CutState> goal;
     mValue = (object)m.MetaVarUnify(l, out goal)??this;
     try
     {
     #pragma warning disable 414, 168, 219
         // ReSharper disable UnusedVariable
         foreach (var ignore in goal)
             // ReSharper restore UnusedVariable
     #pragma warning restore 414, 168, 219
             yield return false;
     }
     finally
     {
         // Reset our own binding to its previous binding
         mValue = m;
         // Reset binding of l
         l.mValue = l;
         //l.IsBound = false;
     }
 }
Exemplo n.º 23
0
 /// <summary>
 /// This is an attributed variable with attribute myMetaStructure, unify it with attributed variable them, with attribute theirMetaStructure.
 /// </summary>
 /// <param name="myMetaStructure">This variable's metavalue</param>
 /// <param name="theirMetaStructure">The meta-value of the variable we're unifying with</param>
 /// <param name="them">The variable to unify with</param>
 /// <param name="context">Prolog context</param>
 void UnifyMetaMeta(Metastructure myMetaStructure, Metastructure theirMetaStructure, LogicVariable them, PrologContext context)
 {
     SaveAndUpdate(myMetaStructure.MetaMetaUnify(theirMetaStructure, context), context);
     them.SaveAndUpdate(this, context);
 }
Exemplo n.º 24
0
 public Metastructure(Structure delayedGoal, Structure frozenGoal, PrologContext prologContext, Metastructure old)
     : this(CombineGoals(delayedGoal, old?.DelayedGoal),
          CombineGoals(frozenGoal, old?.FrozenGoal),
          prologContext)
 {
 }
Exemplo n.º 25
0
 public abstract Metastructure MetaMetaUnify(Metastructure value, out IEnumerable<CutState> filter);