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())); }
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); } }
@SuppressWarnings("unchecked") public Clause(Struct s) { this( s.getName().equals(":-") ? (H) Term.unmarshal(s.getArg(0)) : (H) Term.unmarshal(s), s.getName().equals(":-") ? (B) Term.unmarshal(s.getArg(1)) : null); }