コード例 #1
0
ファイル: FamilyClausesList.java プロジェクト: adlange/IN2SEC
  // Updates indexes, deleting informations about the last removed clause
  public void unregister(ClauseInfo ci) {
    Term clause = ci.getHead();
    if (clause instanceof Struct) {
      Struct g = (Struct) clause.getTerm();

      if (g.getArity() == 0) {
        return;
      }

      Term t = g.getArg(0).getTerm();
      if (t instanceof Var) {
        numCompClausesIndex.removeShared(ci);
        constantCompClausesIndex.removeShared(ci);
        structCompClausesIndex.removeShared(ci);

        listCompClausesList.remove(ci);
      } else if (t.isAtomic()) {
        if (t instanceof Number) {
          numCompClausesIndex.delete((Number) t, ci);
        } else if (t instanceof Struct) {
          constantCompClausesIndex.delete(((Struct) t).getName(), ci);
        }
      } else if (t instanceof Struct) {
        if (t.isList()) {
          listCompClausesList.remove(ci);
        } else {
          structCompClausesIndex.delete(((Struct) t).getPredicateIndicator(), ci);
        }
      }
    }
  }
コード例 #2
0
ファイル: StateException.java プロジェクト: erbuka/andrea
 // verifica se c'? un catcher unificabile con l'argomento dell'eccezione
 // lanciata
 private boolean javaMatch(Term arg1, Term exceptionTerm) {
   if (!arg1.isList()) return false;
   Struct list = (Struct) arg1;
   if (list.isEmptyList()) return false;
   Iterator<? extends Term> it = list.listIterator();
   while (it.hasNext()) {
     Term nextTerm = (Term) it.next();
     if (!nextTerm.isCompound()) continue;
     Struct element = (Struct) nextTerm;
     if (!element.getName().equals(",")) continue;
     if (element.getArity() != 2) continue;
     if (element.getArg(0).match(exceptionTerm)) {
       return true;
     }
   }
   return false;
 }
コード例 #3
0
ファイル: ISOLibrary.java プロジェクト: wvelandia/tuprolog
  public boolean atom_chars_2(Term arg0, Term arg1) throws PrologError {
    arg0 = arg0.getTerm();
    arg1 = arg1.getTerm();
    if (arg0 instanceof Var) {
      if (!arg1.isList()) {
        throw PrologError.type_error(engine.getEngineManager(), 2, "list", arg1);
      }
      Struct list = (Struct) arg1;
      if (list.isEmptyList()) {
        return unify(arg0, new Struct(""));
      }
      String st = "";
      while (!(list.isEmptyList())) {
        String st1 = list.getTerm(0).toString();
        try {
          if (st1.startsWith("'") && st1.endsWith("'")) {
            st1 = st1.substring(1, st1.length() - 1);
          }
        } catch (Exception ex) {
        }
        ;
        st = st.concat(st1);
        list = (Struct) list.getTerm(1);
      }
      return unify(arg0, new Struct(st));
    } else {
      if (!arg0.isAtom()) {
        throw PrologError.type_error(engine.getEngineManager(), 1, "atom", arg0);
      }
      String st = ((Struct) arg0).getName();
      Term[] tlist = new Term[st.length()];
      for (int i = 0; i < st.length(); i++) {
        tlist[i] = new Struct(new String(new char[] {st.charAt(i)}));
      }
      Struct list = new Struct(tlist);
      /*
       * for (int i=0; i<st.length(); i++){ Struct ch=new Struct(new
       * String(new char[]{ st.charAt(st.length()-i-1)} )); list=new
       * Struct( ch, list); }
       */

      return unify(arg1, list);
    }
  }
コード例 #4
0
ファイル: Var.java プロジェクト: wvelandia/tuprolog
 public boolean isList() {
   Term t = getTerm();
   if (t == this) return false;
   else return t.isList();
 }