
int intern(int x) {
  int ret;
  int processing;
  int temp;
  int hash_index;
  int sublist;
  int y;
  int ycar;
  int atomlist_size;

  // check for uniqueness of new symbol. if its not
  // in the atomlist add it. if its found return the
  // original and forget the new one.

  atomlist_size = Mveclength(atomlist);
  hash_index = hash_atom(x, atomlist_size);
  sublist = vector_ref(atomlist, hash_index);
  y = sublist;

  ret = 0;
  processing = 1;
  while (processing) {
    if (Mnotnull(y)) {
      ycar = Mcar(y);
      if (symboleq(x, ycar)) { // forget the new token
        ret = ycar; // return existing token
        processing = 0;
      }
      else
        y = Mcdr(y);
    }
    else
      processing = 0;
  }

  if (ret == 0) {
    // atom not found - add it
    temp = vector_set(atomlist, hash_index, kons(x, sublist));
    ret = x;
  }

  return ret;
}

int atomize_string() {
  int primitive_proc_idx;
  int symbol;
  init_token();
  primitive_proc_idx = get_integer_val(get_token());
  init_token();
  stack_arg1 = get_token(); // necessary evil using stack_arg1
  symbol = intern(string_to_symbol(stack_arg1));
  MsymProcSet(symbol, primitive_proc_idx);
  return symbol;
}
