
void notnumber() {
  printf("not number");
  writeln();
  cleanup_();
  return; // return not reached
}

void notinteger() {
  printf("not integer");
  writeln();
  cleanup_();
  return; // return not reached
}

int get_integer_val(int integer) {
  if (!Mintegerp(integer))
    notinteger();
  else
    return Mintvecref(integer);
}

void isnumbervector(int x) {
  if (!Mvectorp(x))
    notnumber();
  else
    return;
}

void arenumbersvectors(int x, int y) {
  if (!(Mvectorp(x) && Mvectorp(y)))
    notnumber();
  else
    return;
}

int equalp_vector(int x, int y) {
  int i;
  int len1;
  int len2;
  int processing;
  int ret;

  len1 = Mveclength(x);
  len2 = Mveclength(y);
  if (len1 != len2)
    return Mfalse;
  else {
    ret = Mtrue; // by default
    processing = 1;
    i = 0;
    while (processing) {
      if (i < len1) {
        if (equalp(vector_ref(x, i), vector_ref(y, i)) != Mtrue) {
          processing = 0;
          ret = Mfalse;
        }
        else
          i = i + 1;
      }
      else
        processing = 0;
    }
    return ret;
  }
}

int eqv_vector(int x, int y) {
  int i;
  int len1;
  int len2;
  int processing;
  int ret;

  if (MgetVecSubtype(x) != MgetVecSubtype(y))
    return Mfalse;

  len1 = Mveclength(x);
  len2 = Mveclength(y);
  if (len1 != len2)
    return Mfalse;
  else {
    ret = Mtrue; // by default
    processing = 1;
    i = 0;
    while (processing) {
      if (i < len1) {
        if (Mvecref(x, i + 1) != Mvecref(y, i + 1)) {
          processing = 0;
          ret = Mfalse;
        }
        else
          i = i + 1;
      }
      else
        processing = 0;
    }
    return ret;
  }
}

int pairp(int x) {
  if (Mpairp(x))
    return Mtrue;
  else
    return Mfalse;
}

int listp(int x) {
  int processing;
  int ret;
  int a;
  int b;
  a = x;
  b = x;
  processing = 1;
  while (processing) {
    if (Mnull(b)) {
      processing = 0;
      ret = Mtrue;
    }
    else
    if (!Mpairp(b)) {
      processing = 0;
      ret = Mfalse;
    }
    else
    if (!Mpairp(a)) {
      processing = 0;
      ret = Mfalse;
    }
    else
    if (Meq(a, Mcdr(b))) {
      processing = 0;
      ret = Mfalse;
    }
    else {
      a = Mcdr(a);
      b = Mcdr(b);
      if (Mnull(b)) {
	processing = 0;
        ret = Mtrue;
      }
      else
      if (!Mpairp(b)) {
	processing = 0;
        ret = Mfalse;
      }
      else
        b = Mcdr(b);
    }
  }
  return ret;
}

int symbolp(int x) {
  if (Msymbolp(x))
    return Mtrue;
  else
    return Mfalse;
}

int eq(int x, int y) {
  if (Meq(x, y))
    return Mtrue;
  else
    return Mfalse;
}

int eqv(int x, int y) {
  if (Meq(x, y))
    return Mtrue;
  else
  if ((Mvectorp(x) && Mvectorp(y)))
    return eqv_vector(x, y);
  else
    return Mfalse;
}

int numberp(int x) {
  if (Mnumberp(x))
    return Mtrue;
  else
    return Mfalse;
}

int stringp(int x) {
  if (Mstringp(x))
    return Mtrue;
  else
    return Mfalse;
}

int equalp(int x, int y) {
  int processing;
  int ret;
  ret = Mfalse; // by default
  processing = 1;
  while (processing) {
    if (eqv(x, y) == Mtrue) {
      processing = 0;
      ret = Mtrue;
    }
    else
    if ((Mpairp(x) && Mpairp(y))) {
      if (equalp(kar(x), kar(y)) != Mtrue) {
        processing = 0;
        ret = Mfalse;
      }
      else {
        x = kdr(x);
        y = kdr(y);
      }
    }
    else {
      processing = 0;
      if (MvectorpProper(x) && MvectorpProper(y)) {
        if (equalp_vector(x, y) == Mtrue)
          ret = Mtrue;
        else
          ret = Mfalse;
      }
      else
        ret = Mfalse;
    }
  }
  return ret;
}

int charp(int x) {
  if (Mcharp(x))
    return Mtrue;
  else
    return Mfalse;
}

int chareq(int x, int y) {
  if (Meq(x, y))
    return Mtrue;
  else
    return Mfalse;
}

int charalpha(int x) {
  x = MgetChar(x);
  if ((x >= 'a') && (x <= 'z'))
    return Mtrue;
  else
  if ((x >= 'A') && (x <= 'Z'))
    return Mtrue;
  else
    return Mfalse;
}

int charnum(int x) {
  if (isdigit(MgetChar(x)))
    return Mtrue;
  else
    return Mfalse;
}

int eof_object(int x) {
  if (x == eofatom)
    return Mtrue;
  else
    return Mfalse;
}

int procedurep(int x) {
  if (Mprocp(x))
    return Mtrue;
  else
    return Mfalse;
}

int boolp(int x) {
  if (Mboolp(x))
    return Mtrue;
  else
    return Mfalse;
}

int integerp(int x) {
  if (Mintegerp(x))
    return Mtrue;
  else
    return Mfalse;
}
