
#include <libq.h>

MODULE(creverse)

FUNCTION(creverse,creverse,argc,argv)
{
  if (argc == 1) {
    expr x = argv[0], y = mknil, hd, tl;
    while (y && iscons(x, &hd, &tl)) {
      expr z = mkcons(hd, y);
      y = z; x = tl;
    }
    if (!y)
      return __ERROR;
    else if (isnil(x))
      return y;
    else {
      dispose(y);
      return __FAIL;
    }
  } else
    return __FAIL;
}

