Example #1
0
 public boolean atom_length_2(Term arg0, Term len) throws PrologError {
   arg0 = arg0.getTerm();
   if (arg0 instanceof Var) throw PrologError.instantiation_error(engine.getEngineManager(), 1);
   if (!arg0.isAtom()) throw PrologError.type_error(engine.getEngineManager(), 1, "atom", arg0);
   Struct atom = (Struct) arg0;
   return unify(len, new Int(atom.getName().length()));
 }
Example #2
0
 public boolean char_code_2(Term arg0, Term arg1) throws PrologError {
   arg0 = arg0.getTerm();
   arg1 = arg1.getTerm();
   if (arg1 instanceof Var) {
     if (arg0.isAtom()) {
       String st = ((Struct) arg0).getName();
       if (st.length() <= 1) return unify(arg1, new Int(st.charAt(0)));
       else throw PrologError.type_error(engine.getEngineManager(), 1, "character", arg0);
     } else throw PrologError.type_error(engine.getEngineManager(), 1, "character", arg0);
   } else if ((arg1 instanceof Int) || (arg1 instanceof alice.tuprolog.Long)) {
     char c = (char) ((Number) arg1).intValue();
     return unify(arg0, new Struct("" + c));
   } else throw PrologError.type_error(engine.getEngineManager(), 2, "integer", arg1);
 }
Example #3
0
  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);
    }
  }
Example #4
0
 public boolean sub_atom_guard_5(Term arg0, Term arg1, Term arg2, Term arg3, Term arg4)
     throws PrologError {
   arg0 = arg0.getTerm();
   if (!arg0.isAtom()) throw PrologError.type_error(engine.getEngineManager(), 1, "atom", arg0);
   return true;
 }