// (c) MIT 2003.  All rights reserved.

// $Id: LispTMS.java,v 1.12 2003/03/06 00:40:49 moltmans Exp $
// LispTMS.java -- 
// Author: Michael Oltmans <moltmans@ai.mit.edu> 
// Created: <Fri Jan 26 14:31:13 2001> 
// Time-stamp: <2001-04-06 10:33:17 moltmans> 
package rec.annotate.lisp;

import java.net.URL;
import rec.util.DebugWindow;
import java.util.*;
import com.franz.jlinker.JavaLinkDist;
import java.io.File;

/**
 * LispTMS.java
 *
 *
 * Created: Fri Jan 26 14:31:20 2001
 *
 * @author <a href="mailto:moltmans@ai.mit.edu">Michael Oltmans</a>
 * @version
 */

public class LispTMS extends Lisp {
  public LispTMS () {
    this(null);
  }

  public LispTMS (String lispExe)
  {
    super(lispExe);
    connectToLisp();
    if (readEval("(defvar *BPS-path* \"" + makeFile("/") + "\")") != null &&
	loadFile("bps-init.lsp") &&
	readEval("(bps::load-bps-system \"ltms\" \"ltre\" \"load-ltre\" :LOAD-BINARY)") != null &&
 	readEval("(in-ltre (create-ltre \"Java-TMS\"))") != null)
    {
      DebugWindow.addLine( "Lisp", "Loaded the TMS" );
    } // end of if ()
    else {
      DebugWindow.addLine( "Lisp", "Error loading the TMS" );
    } // end of else
  }

  public void assume(String fact, String reason) 
  {
    readEval("(assume! '" + fact + " " +  reason + ")");
  }

  public void assume(String[] fact, String reason) 
  {
    assume(list(fact), reason);
  }

  public void retract(String fact, String reason)
  {
    readEval("(retract! '" + fact + " " + reason + ")");
  }

  public void retract(String[] fact, String reason)
  {
    retract(list(fact), reason);
  }
  

//    public void assert(String[] fact, String[] reason) 
//    {
//      assert(list(fact), list(reason, true));
//    }

//    public void assert(String fact, String reason) 
//    {
//      readEval("(assert! '" + fact + " " + reason + ")");
//    }

  public void runRules()
  {
    runInLisp("run-rules");
  }

  public boolean isIn(String form)
  {
    return runInLisp("in?", form).isNonNil();
  }

  public boolean isOut(String form)
  {
    return runInLisp("out?", form).isNonNil();
  }

  public List fetchInFacts(String form)
  {
    DebugWindow.addLine("Lisp", "Not Implimented: LispTMS.fetchInFacts");
    
    return new LinkedList();
  }
  

//    public List fetch(String pattern) 
//    {
//      LispObj result = ("(fetch " + "'" + pattern + ")");
//      if () {
      
//      } // end of if ()
    
//    }
  
  
  
}// LispTMS
