// Path: engine/jprol-core/src/main/java/com/igormaznitsa/jprol/data/Terms.java
// public static TermList newList(final Term term) {
//   return new TermList(term);
// }
// 
// Path: engine/jprol-core/src/main/java/com/igormaznitsa/jprol/data/Terms.java
// public static TermStruct newStruct(final Term functor) {
//   return new TermStruct(functor);
// }
// 
// Path: engine/jprol-core/src/main/java/com/igormaznitsa/jprol/utils/Utils.java
// public static TermList createOrAppendToList(final TermList nullableList, final Term term) {
//   final TermList newList = Terms.newList(term);
// 
//   if (nullableList != null && !nullableList.isNullList()) {
//     newList.setTail(nullableList.getTail());
//     nullableList.setTail(newList);
//   }
// 
//   return newList;
// }
// 
// Path: engine/jprol-core/src/main/java/com/igormaznitsa/jprol/exceptions/ProlCriticalError.java
// public class ProlCriticalError extends Error {
// 
//   private static final long serialVersionUID = 1340153646373377400L;
// 
//   public ProlCriticalError(final Throwable cause) {
//     super(cause);
//   }
// 
//   public ProlCriticalError(final String message, final Throwable cause) {
//     super(message, cause);
//   }
// 
//   public ProlCriticalError(final String message) {
//     super(message);
//   }
// 
//   public ProlCriticalError() {
//     super();
//   }
// 
// }


import static com.igormaznitsa.jprol.data.TermType.LIST;
import static com.igormaznitsa.jprol.data.TermType.VAR;
import static com.igormaznitsa.jprol.data.Terms.newList;
import static com.igormaznitsa.jprol.data.Terms.newStruct;
import static com.igormaznitsa.jprol.utils.Utils.createOrAppendToList;
import com.igormaznitsa.jprol.exceptions.ProlCriticalError;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Stream;

    while (list != Terms.NULL_LIST) {
      if (list.getTermType() == LIST) {
        if (notfirst) {
          builder.append(',');
        }
        final TermList asList = (TermList) list;
        builder.append(asList.getHead().toSrcString());
        list = asList.getTail();
      } else {
        if (notfirst) {
          builder.append('|');
        }
        builder.append(list.toSrcString());
        break;
      }
      notfirst = true;
    }

    builder.append(']');
    return builder.toString();
  }

  @Override
  public String getSignature() {
    return "./2";
  }

  public final void replaceLastElement(final Term newLastElement) {
    if (isNullList()) {
// Path: engine/jprol-core/src/main/java/com/igormaznitsa/jprol/data/Terms.java
// public static TermList newList(final Term term) {
//   return new TermList(term);
// }
// 
// Path: engine/jprol-core/src/main/java/com/igormaznitsa/jprol/data/Terms.java
// public static TermStruct newStruct(final Term functor) {
//   return new TermStruct(functor);
// }
// 
// Path: engine/jprol-core/src/main/java/com/igormaznitsa/jprol/utils/Utils.java
// public static TermList createOrAppendToList(final TermList nullableList, final Term term) {
//   final TermList newList = Terms.newList(term);
// 
//   if (nullableList != null && !nullableList.isNullList()) {
//     newList.setTail(nullableList.getTail());
//     nullableList.setTail(newList);
//   }
// 
//   return newList;
// }
// 
// Path: engine/jprol-core/src/main/java/com/igormaznitsa/jprol/exceptions/ProlCriticalError.java
// public class ProlCriticalError extends Error {
// 
//   private static final long serialVersionUID = 1340153646373377400L;
// 
//   public ProlCriticalError(final Throwable cause) {
//     super(cause);
//   }
// 
//   public ProlCriticalError(final String message, final Throwable cause) {
//     super(message, cause);
//   }
// 
//   public ProlCriticalError(final String message) {
//     super(message);
//   }
// 
//   public ProlCriticalError() {
//     super();
//   }
// 
// }


// Path: engine/jprol-core/src/main/java/com/igormaznitsa/jprol/data/TermList.java
import static com.igormaznitsa.jprol.data.TermType.LIST;
import static com.igormaznitsa.jprol.data.TermType.VAR;
import static com.igormaznitsa.jprol.data.Terms.newList;
import static com.igormaznitsa.jprol.data.Terms.newStruct;
import static com.igormaznitsa.jprol.utils.Utils.createOrAppendToList;
import com.igormaznitsa.jprol.exceptions.ProlCriticalError;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Stream;


    while (list != Terms.NULL_LIST) {
      if (list.getTermType() == LIST) {
        if (notfirst) {
          builder.append(',');
        }
        final TermList asList = (TermList) list;
        builder.append(asList.getHead().toSrcString());
        list = asList.getTail();
      } else {
        if (notfirst) {
          builder.append('|');
        }
        builder.append(list.toSrcString());
        break;
      }
      notfirst = true;
    }

    builder.append(']');
    return builder.toString();
  }

  @Override
  public String getSignature() {
    return "./2";
  }

  public final void replaceLastElement(final Term newLastElement) {
    if (isNullList()) {
      throw new ProlCriticalError("Attemption to change Null list");