Login
7 branches 0 tags
Ben (Win10) Moved testsuite to /testsuite and improved its handling in the wasm build 71fb293 3 years ago 559 Commits
nujel / lib / collection / list.c
/* Nujel - Copyright (C) 2020-2022 - Benjamin Vincent Schulenburg
 * This project uses the MIT license, a copy should be included under /LICENSE */
#include "list.h"

#include <stdarg.h>

/* Return the length of the list V */
int lListLength(lVal *v){
	int i = 0;
	for(lVal *n = v;(n != NULL) && (lCar(n) != NULL); n = lCdr(n)){i++;}
	return i;
}

/* A convenient way to generate a list */
lVal *lList(int length, ...){
	lVal *ret = NULL, *l;
	va_list varArgs;
	va_start(varArgs,length);
	for(;length;length--){
		lVal *t = va_arg(varArgs, lVal *);
		if(ret == NULL){
			ret = l = RVP(lCons(NULL,NULL));
		}else{
			l = l->vList.cdr = lCons(NULL,NULL);
		}
		l->vList.car = t;
	}
	va_end(varArgs);
	return ret;
}