Ejemplo n.º 1
0
 ListTerm deleteFromList(Term element, ListTerm l, Unifier un) {
   Unifier bak = un;
   ListTerm r = new ListTermImpl();
   ListTerm last = r;
   for (Term t : l) {
     boolean u = un.unifies(element, t);
     if (u) un = bak.clone();
     else last = last.append(t.clone());
   }
   return r;
 }
Ejemplo n.º 2
0
  @Override
  public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
    checkArguments(args);

    if (args[0].isNumeric() && args[1].isString()) {
      return un.unifies(
          args[2], deleteFromString((int) ((NumberTerm) args[0]).solve(), (StringTerm) args[1]));
    }
    if (args[0].isNumeric() && args[1].isList()) {
      return un.unifies(
          args[2], deleteFromList((int) ((NumberTerm) args[0]).solve(), (ListTerm) args[1]));
    }
    if (args[0].isString() && args[1].isString()) {
      return un.unifies(args[2], deleteFromString((StringTerm) args[0], (StringTerm) args[1]));
    }

    // first element as term
    if (args[1].isList()) {
      return un.unifies(args[2], deleteFromList(args[0], (ListTerm) args[1], un.clone()));
    }
    throw new JasonException("Incorrect use of the internal action '.delete' (see documentation).");
  }