ToStringInPrologFormat() public static method

Converts an arbitrary object to a string in Prolog format.
public static ToStringInPrologFormat ( object value ) : string
value object
return string
Exemplo n.º 1
0
 private void DumpPrologStack(PrologContext context)
 {
     if (context.GoalStackDepth > 0)
     {
         for (ushort i = 0; i <= context.CurrentFrame; i++)
         {
             Structure g = context.GoalStackGoal(i);
             if (g != null)
             {
                 ushort frame = i;
                 while (frame != 0)
                 {
                     //Output.Write("{0}/", frame);
                     Output.Write("  ");
                     frame = context.GoalStackParent(frame);
                 }
                 //Output.Write(' ');
                 //Output.Write("{0}<{1}: ", i, PrologContext.GoalStackParent(i));
                 Output.WriteLine(Term.ToStringInPrologFormat(g));
             }
         }
     }
     else
     {
         Output.WriteLine("Goal stack is empty.");
     }
 }
Exemplo n.º 2
0
 void PrintNextQuerySolution()
 {
     try
     {
         PrologContext.ResetStepLimit();
         timer.Reset();
         timer.Start();
         bool gotOne = prologModeAnswerStream.MoveNext();
         timer.Stop();
         if (gotOne)
         {
             if (freeVariablesInCurrentQuery.Count > 0)
             {
                 foundOneSolution = true;
                 foreach (LogicVariable v in freeVariablesInCurrentQuery)
                 {
                     Output.WriteLine("{0} = {1}", v.Name, Term.ToStringInPrologFormat(Term.Deref(v)));
                 }
             }
             else
             {
                 Output.WriteLine("yes");
                 prologModeAnswerStream = null;
             }
         }
         else
         {
             Output.WriteLine(foundOneSolution?"no more solutions found":"no");
             prologModeAnswerStream = null;
         }
         if (timeCommands)
         {
             double ms = timer.Elapsed.TotalMilliseconds;
             Output.WriteLine("{0:###}ms, {1} inference steps, {2:0.##} KLIPS.\n", ms, prologContext.StepsUsed, prologContext.StepsUsed / ms);
         }
     }
     catch (Exception)
     {
         prologModeAnswerStream = null;
         throw;
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Generate a stack trace that's close enough to a normal mono stack dump that the Unity logger will understand it.
        /// </summary>
        /// <param name="sourcePath">Path for the source file being loaded.</param>
        /// <param name="lineNumber">Current line number in the source file.</param>
        /// <param name="toplevelCommand">Original prolog command to output, if stack is empty.</param>
        /// <param name="fullTrace">If true, the complete stack is dumped, otherwise, just the starting frames.</param>
        /// <returns></returns>
        public string StackTrace(string sourcePath, int lineNumber, string toplevelCommand, bool fullTrace)
        {
            ushort startingFrame = fullTrace ? this.CurrentFrame : (ushort)Math.Min((int)this.CurrentFrame, 30);
            var    result        = new StringBuilder();

            if (this.GoalStackDepth > 0)
            {
                for (int i = startingFrame; i >= 0; i--)
                {
                    Structure g = this.GoalStackGoal((ushort)i);
                    if (g != null)
                    {
                        var frame = (ushort)i;
                        while (frame != 0)
                        {
                            //Output.Write("{0}/", frame);
                            result.Append("  ");
                            frame = this.GoalStackParent(frame);
                        }
                        //Output.Write(' ');
                        //Output.Write("{0}<{1}: ", i, PrologContext.GoalStackParent(i));
                        result.Append(Term.ToStringInPrologFormat(g));
                        var rule = goalStackCurrentRules[i];
                        if (rule != null)
                        {
                            result.AppendFormat(" (at {0}:{1})", rule.SourceFile, rule.SourceLineNumber);
                        }
                        result.AppendLine();
                    }
                }
            }
            else
            {
                result.AppendFormat("{0} (at {1}:{2})\n", toplevelCommand, sourcePath, lineNumber);
            }
            return(result.ToString());
        }
Exemplo n.º 4
0
 // ReSharper disable once InconsistentNaming
 void LoadCSVRow(int rowNumber, Structure row)
 {
     if (!this.IsTrue(new Structure("load_csv_row", rowNumber, row)))
     {
         throw new Exception(string.Format("Failed to load CSV row number {0} : {1}", rowNumber, Term.ToStringInPrologFormat(row)));
     }
 }