Node:Signalling Type Errors, Next:, Previous:Non-immediate Datatypes, Up:How Guile does it



18.2.6 Signalling Type Errors

Every function visible at the Scheme level should aggressively check the types of its arguments, to avoid misinterpreting a value, and perhaps causing a segmentation fault. Guile provides some macros to make this easier.

void SCM_ASSERT (int test, SCM obj, unsigned int position, const char *subr) Macro
If test is zero, signal a "wrong type argument" error, attributed to the subroutine named subr, operating on the value obj, which is the position'th argument of subr.

int SCM_ARG1 Macro
int SCM_ARG2 Macro
int SCM_ARG3 Macro
int SCM_ARG4 Macro
int SCM_ARG5 Macro
int SCM_ARG6 Macro
int SCM_ARG7 Macro
One of the above values can be used for position to indicate the number of the argument of subr which is being checked. Alternatively, a positive integer number can be used, which allows to check arguments after the seventh. However, for parameter numbers up to seven it is preferable to use SCM_ARGN instead of the corresponding raw number, since it will make the code easier to understand.

int SCM_ARGn Macro
Passing a value of zero or SCM_ARGn for position allows to leave it unspecified which argument's type is incorrect. Again, SCM_ARGn should be preferred over a raw zero constant.