diff --git a/src/pebblisp.h b/src/pebblisp.h index bb3c753..51e00c5 100644 --- a/src/pebblisp.h +++ b/src/pebblisp.h @@ -10,17 +10,21 @@ #define array_length(_array) (sizeof(_array) / sizeof((_array)[0])) -#define fn(_name, _docs, ...) static const char * const _name ## Doc = _docs; \ +#define UNPACK(...) __VA_ARGS__ + +#define fn(_name, _docs, ...) \ +static const char * const _name ## Doc = _docs; \ static const char * const _name ## Tests[] = {__VA_ARGS__}; \ static_assert(array_length(_name ## Tests) % 2 == 0, "Array of test strings must have exactly one expected result for each test."); \ Object _name(Object* params, int length, struct Environment* env) -#define fnn(_name, _symbol, _docs, ...)\ -static const char * const _name ## Doc = _docs;\ -static const char * const _name ## Symbol = _symbol;\ -static const char * const _name ## Tests[] = {__VA_ARGS__}; \ -static_assert(array_length(_name ## Tests) % 2 == 0, "Array of test strings must have exactly one expected result for each test."); \ -Object _name(Object* params, int length, struct Environment* env) +#define tfn(_name, _type, _docs, ...) \ +static const Type _name ## Type[] = UNPACK _type; \ +fn(_name, _docs, __VA_ARGS__) + +#define fnn(_name, _symbol, _docs, ...) \ +static const char * const _name ## Symbol = _symbol; \ +fn(_name, _docs, __VA_ARGS__) struct Slice { const char* text; diff --git a/src/plfunc.h b/src/plfunc.h index 5d98465..a9f6b4e 100644 --- a/src/plfunc.h +++ b/src/plfunc.h @@ -52,12 +52,12 @@ fn(prepend, "(pre (2 3) 1)", "( 1 2 3 )", ); -/// LIST => NUMBER -fn(len, - "Returns the length of the given list, or a NOT_A_LIST error if the expression is not a list.", - "(len (2 3))", "2", - "(len ())", "0", - "(len \"string\")", "NOT_A_LIST", +tfn(len, + ({ TYPE_LIST, TYPE_NUMBER }), + "Returns the length of the given list, or a NOT_A_LIST error if the expression is not a list.", + "(len (2 3))", "2", + "(len ())", "0", + "(len \"string\")", "NOT_A_LIST", ); /// LIST, FUNCY, ANY => ANY