* libguile/list.c: (delq1): Create. (delv1): Create. (delete1): Create. * doc/ref/api-data.texi (List Modification): Document it. ---
Hi Guile, There was some discussion on IRC a while back about how it was odd there were destructive delete1! and similar functions, but no nondestructive variants. This patch aims to fix that. doc/ref/api-data.texi | 52 ++++++++++++++++++++++++------------------- libguile/list.c | 36 ++++++++++++++++++++++++++++++ libguile/list.h | 3 +++ 3 files changed, 68 insertions(+), 23 deletions(-) diff --git a/doc/ref/api-data.texi b/doc/ref/api-data.texi index 3b9933d97..c94846842 100644 --- a/doc/ref/api-data.texi +++ b/doc/ref/api-data.texi @@ -6000,39 +6000,45 @@ Deleting}), and also an @code{lset-difference} which can delete multiple @var{item}s in one call (@ref{SRFI-1 Set Operations}). @end deffn -@deffn {Scheme Procedure} delq! item lst -@deffnx {Scheme Procedure} delv! item lst -@deffnx {Scheme Procedure} delete! item lst -@deffnx {C Function} scm_delq_x (item, lst) -@deffnx {C Function} scm_delv_x (item, lst) -@deffnx {C Function} scm_delete_x (item, lst) -These procedures are destructive versions of @code{delq}, @code{delv} -and @code{delete}: they modify the pointers in the existing @var{lst} -rather than creating a new list. Caveat evaluator: Like other -destructive list functions, these functions cannot modify the binding of -@var{lst}, and so cannot be used to delete the first element of -@var{lst} destructively. -@end deffn - -@deffn {Scheme Procedure} delq1! item lst +@deffn {Scheme Procedure} delq1 item lst @deffnx {C Function} scm_delq1_x (item, lst) -Like @code{delq!}, but only deletes the first occurrence of +Like @code{delq}, but only deletes the first occurrence of @var{item} from @var{lst}. Tests for equality using -@code{eq?}. See also @code{delv1!} and @code{delete1!}. +@code{eq?}. See also @code{delv1} and @code{delete1}. @end deffn -@deffn {Scheme Procedure} delv1! item lst +@deffn {Scheme Procedure} delv1 item lst @deffnx {C Function} scm_delv1_x (item, lst) -Like @code{delv!}, but only deletes the first occurrence of +Like @code{delv}, but only deletes the first occurrence of @var{item} from @var{lst}. Tests for equality using -@code{eqv?}. See also @code{delq1!} and @code{delete1!}. +@code{eqv?}. See also @code{delq1} and @code{delete1}. @end deffn -@deffn {Scheme Procedure} delete1! item lst +@deffn {Scheme Procedure} delete1 item lst @deffnx {C Function} scm_delete1_x (item, lst) -Like @code{delete!}, but only deletes the first occurrence of +Like @code{delete}, but only deletes the first occurrence of @var{item} from @var{lst}. Tests for equality using -@code{equal?}. See also @code{delq1!} and @code{delv1!}. +@code{equal?}. See also @code{delq1} and @code{delv1}. +@end deffn + +@deffn {Scheme Procedure} delq! item lst +@deffnx {Scheme Procedure} delv! item lst +@deffnx {Scheme Procedure} delete! item lst +@deffnx {Scheme Procedure} delq1! item lst +@deffnx {Scheme Procedure} delv1! item lst +@deffnx {Scheme Procedure} delete1! item lst +@deffnx {C Function} scm_delq_x (item, lst) +@deffnx {C Function} scm_delv_x (item, lst) +@deffnx {C Function} scm_delete_x (item, lst) +@deffnx {C Function} scm_delq1_x (item, lst) +@deffnx {C Function} scm_delv1_x (item, lst) +@deffnx {C Function} scm_delete1_x (item, lst) +These procedures are destructive versions of @code{delq}, @code{delv}, +@code{delete}, @code{delq1}, @code{delv1}, and @code{delete1}: they +modify the pointers in the existing @var{lst} rather than creating a new +list. Caveat evaluator: Like other destructive list functions, these +functions cannot modify the binding of @var{lst}, and so cannot be used +to delete the first element of @var{lst} destructively. @end deffn @deffn {Scheme Procedure} filter pred lst diff --git a/libguile/list.c b/libguile/list.c index 8063a15d1..af8e6222e 100644 --- a/libguile/list.c +++ b/libguile/list.c @@ -949,6 +949,42 @@ SCM_DEFINE (scm_delete1_x, "delete1!", 2, 0, 0, } #undef FUNC_NAME +SCM_DEFINE (scm_delq1, "delq1", 2, 0, 0, + (SCM item, SCM lst), + "Like @code{delq}, but only deletes the first occurrence of\n" + "@var{item} from @var{lst}. Tests for equality using\n" + "@code{eq?}. See also @code{delv1} and @code{delete1}.") +#define FUNC_NAME s_scm_delq1 +{ + SCM copy = scm_list_copy (lst); + return scm_delq1_x (item, copy); +} +#undef FUNC_NAME + +SCM_DEFINE (scm_delv1, "delv1", 2, 0, 0, + (SCM item, SCM lst), + "Like @code{delv}, but only deletes the first occurrence of\n" + "@var{item} from @var{lst}. Tests for equality using\n" + "@code{eqv?}. See also @code{delq1} and @code{delete1}.") +#define FUNC_NAME s_scm_delv1 +{ + SCM copy = scm_list_copy (lst); + return scm_delv1_x (item, copy); +} +#undef FUNC_NAME + +SCM_DEFINE (scm_delete1, "delete1", 2, 0, 0, + (SCM item, SCM lst), + "Like @code{delete}, but only deletes the first occurrence of\n" + "@var{item} from @var{lst}. Tests for equality using\n" + "@code{equal?}. See also @code{delq1} and @code{delv1}.") +#define FUNC_NAME s_scm_delete1 +{ + SCM copy = scm_list_copy (lst); + return scm_delete1_x (item, copy); +} +#undef FUNC_NAME + SCM_DEFINE (scm_filter, "filter", 2, 0, 0, (SCM pred, SCM list), "Return all the elements of 2nd arg @var{list} that satisfy predicate @var{pred}.\n" diff --git a/libguile/list.h b/libguile/list.h index 5ebcc8a82..bf9f6d90e 100644 --- a/libguile/list.h +++ b/libguile/list.h @@ -63,6 +63,9 @@ SCM_API SCM scm_delete (SCM item, SCM lst); SCM_API SCM scm_delq1_x (SCM item, SCM lst); SCM_API SCM scm_delv1_x (SCM item, SCM lst); SCM_API SCM scm_delete1_x (SCM item, SCM lst); +SCM_API SCM scm_delq1 (SCM item, SCM lst); +SCM_API SCM scm_delv1 (SCM item, SCM lst); +SCM_API SCM scm_delete1 (SCM item, SCM lst); SCM_API SCM scm_filter (SCM pred, SCM list); SCM_API SCM scm_filter_x (SCM pred, SCM list); SCM_API SCM scm_copy_tree (SCM obj); -- 2.45.1