// Path: engine/jprol-core/src/main/java/com/igormaznitsa/jprol/data/Terms.java
// public static TermVar newVar(final String name) {
//   return new TermVar(name);
// }
// 
// Path: engine/jprol-core/src/main/java/com/igormaznitsa/jprol/exceptions/ProlInstantiationErrorException.java
// public class ProlInstantiationErrorException extends ProlAbstractCatcheableException {
// 
//   private static final long serialVersionUID = -5157739502740121566L;
// 
//   private static final Term TERM_ERROR = newAtom("instantiation_error");
// 
//   public ProlInstantiationErrorException(final Term culprit, final Throwable cause) {
//     super(culprit, cause);
//   }
// 
//   public ProlInstantiationErrorException(final String message, final Term culprit,
//                                          final Throwable cause) {
//     super(message, culprit, cause);
//   }
// 
//   public ProlInstantiationErrorException(final String message, final Term culprit) {
//     super(message, culprit);
//   }
// 
//   public ProlInstantiationErrorException(final Term culprit) {
//     super(culprit);
//   }
// 
// 
//   @Override
//   public Term getErrorTerm() {
//     return TERM_ERROR;
//   }
// 
//   @Override
//   public TermStruct getAsStruct() {
//     return this.makeErrorStruct(TERM_ERROR, this.getCulprit());
//   }
// }


import static com.igormaznitsa.jprol.data.TermType.VAR;
import static com.igormaznitsa.jprol.data.Terms.newVar;
import com.igormaznitsa.jprol.exceptions.ProlInstantiationErrorException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Stream;
    this("_$" + Long.toHexString(ANONYM_GENERATOR.incrementAndGet()), true);
  }

  public final int getVarUid() {
    return this.uid;
  }

  @Override
  public TermType getTermType() {
    return VAR;
  }

  @Override
  public Term makeClone() {
    final Term value = this.getThisValue();
    TermVar result = this.isAnonymous() ? newVar() : newVar(this.getText());
    if (value != null) {
      final Map<Integer, TermVar> vars = new HashMap<>();
      vars.put(this.getVarUid(), result);
      result.setThisValue(doMakeClone(vars));
    }
    return result;
  }

  @Override
  public Number toNumber() {
    final Term data = this.getValue();
    if (data instanceof NumericTerm) {
      return data.toNumber();
    }
// Path: engine/jprol-core/src/main/java/com/igormaznitsa/jprol/data/Terms.java
// public static TermVar newVar(final String name) {
//   return new TermVar(name);
// }
// 
// Path: engine/jprol-core/src/main/java/com/igormaznitsa/jprol/exceptions/ProlInstantiationErrorException.java
// public class ProlInstantiationErrorException extends ProlAbstractCatcheableException {
// 
//   private static final long serialVersionUID = -5157739502740121566L;
// 
//   private static final Term TERM_ERROR = newAtom("instantiation_error");
// 
//   public ProlInstantiationErrorException(final Term culprit, final Throwable cause) {
//     super(culprit, cause);
//   }
// 
//   public ProlInstantiationErrorException(final String message, final Term culprit,
//                                          final Throwable cause) {
//     super(message, culprit, cause);
//   }
// 
//   public ProlInstantiationErrorException(final String message, final Term culprit) {
//     super(message, culprit);
//   }
// 
//   public ProlInstantiationErrorException(final Term culprit) {
//     super(culprit);
//   }
// 
// 
//   @Override
//   public Term getErrorTerm() {
//     return TERM_ERROR;
//   }
// 
//   @Override
//   public TermStruct getAsStruct() {
//     return this.makeErrorStruct(TERM_ERROR, this.getCulprit());
//   }
// }


// Path: engine/jprol-core/src/main/java/com/igormaznitsa/jprol/data/TermVar.java
import static com.igormaznitsa.jprol.data.TermType.VAR;
import static com.igormaznitsa.jprol.data.Terms.newVar;
import com.igormaznitsa.jprol.exceptions.ProlInstantiationErrorException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Stream;

    this("_$" + Long.toHexString(ANONYM_GENERATOR.incrementAndGet()), true);
  }

  public final int getVarUid() {
    return this.uid;
  }

  @Override
  public TermType getTermType() {
    return VAR;
  }

  @Override
  public Term makeClone() {
    final Term value = this.getThisValue();
    TermVar result = this.isAnonymous() ? newVar() : newVar(this.getText());
    if (value != null) {
      final Map<Integer, TermVar> vars = new HashMap<>();
      vars.put(this.getVarUid(), result);
      result.setThisValue(doMakeClone(vars));
    }
    return result;
  }

  @Override
  public Number toNumber() {
    final Term data = this.getValue();
    if (data instanceof NumericTerm) {
      return data.toNumber();
    }
    throw new ProlInstantiationErrorException("NonInstantiated variable", this);