This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Suggestion: SCM_DEBUG_REST_ARGUMENTS


Hi!

A lot of guile's functions accept rest arguments which have to form a
proper list.  If the evaluator passes these arguments, this is
guaranteed.  However, if guile functions are called from user code, the
user code may be broken and provide something that is not a proper list as
rest arguments.

Thus we have to face the question whether functions that take rest
arguments should check whether the rest arguments do really form a proper
list.  To do this right, however, is time consuming, since it has to be
checked that there are no cycles, etc.

The current situation is, that most of guile's functions that take rest
arguments do this in a half-hearted manner, i. e. they don't check for
cycles, but check if the last element is '().

Thus, I suggest the following solution:

- normally, don't do _any_ checks on the list of rest arguments, but
  assume that they form a proper list.
- If SCM_DEBUG_REST_ARGUMENTS is 1, perform an exhaustive check on the
  list of rest arguments, i. e. check for properness of the list and
  whether it is cyclic.

Example:

#define SCM_VALIDATE_REST_ARGUMENTS(x) \
  do { if (SCM_DEBUG_REST_ARGUMENTS && scm_ilength (x) < 0) \
         SCM_MISC_ERROR ("Rest arguments do not form a proper list."); \
     } while (0)

This is likely to give a minor speedup for the common case, but still
allows developers of extensions to debug their code.  If nobody objects, I
will add SCM_DEBUG_REST_ARGUMENTS and SCM_VALIDATE_REST_ARGUMENTS and will
change corresponding code to make use of it.

Best regards
Dirk


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]