#include <R.h>
#include <Rdefines.h>

SEXP loop_apply(/*SEXP n*/int n, SEXP f, SEXP rho) {
//  if(!isFunction(f)) error("'f' must be a function");
//  if(!isEnvironment(rho)) error("'rho' should be an environment");

  int n1 = n;
//  int n1 = INTEGER(n)[0];
  printf("N1: %d\n", n);
  /*SEXP results, R_fcall;
  PROTECT(results = allocVector(VECSXP, n1));
  PROTECT(R_fcall = lang2(f, R_NilValue));

  SEXP ii;
  for(int i = 0; i < n1; i++) {
    PROTECT(ii = ScalarInteger(i + 1));
    SETCADR(R_fcall, ii);
    SET_VECTOR_ELT(results, i, eval(R_fcall, rho));

    UNPROTECT(1);
  }

  UNPROTECT(2);
  printf("RETURNING RESULTS\n");
  printf("SIZE OF RESULTS %lu\n", sizeof(results));
  if (results == NULL)
     printf("WARNING NULL RESULT\n");
  else
     printf("RESULT IS NOT NULL\n");
  return results;*/
  return NULL;
}
