From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Richard Sent Newsgroups: gmane.lisp.guile.devel Subject: [PATCH] Add nondestructive delq1, delv1, and delete1. Date: Fri, 28 Jun 2024 20:19:29 -0400 Message-ID: <20240629002027.13853-1-richard@freakingpenguin.com> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3679"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Richard Sent To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Sat Jun 29 03:13:12 2024 Return-path: Envelope-to: guile-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sNMeO-0000m2-Ex for guile-devel@m.gmane-mx.org; Sat, 29 Jun 2024 03:13:12 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sNMe9-0004Py-6V; Fri, 28 Jun 2024 21:12:57 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sNLug-00064H-6W for guile-devel@gnu.org; Fri, 28 Jun 2024 20:25:58 -0400 Original-Received: from mail-108-mta145.mxroute.com ([136.175.108.145]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sNLue-0001NV-AP for guile-devel@gnu.org; Fri, 28 Jun 2024 20:25:57 -0400 Original-Received: from filter006.mxroute.com ([136.175.111.3] filter006.mxroute.com) (Authenticated sender: mN4UYu2MZsgR) by mail-108-mta145.mxroute.com (ZoneMTA) with ESMTPSA id 190615da3a500017a3.001 for (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Sat, 29 Jun 2024 00:20:45 +0000 X-Zone-Loop: 57374af060059c8640e59a535b5c5be690f335dfb20e X-Originating-IP: [136.175.111.3] DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=freakingpenguin.com; s=x; h=Content-Transfer-Encoding:MIME-Version: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=GBcc5aqJDEXH5cJfLtQNK1W0vcXohyzb4LxLOHUwEDE=; b=U/1glNIjuklwqrM0s4eLlHT599 Az3ENfYxYmQQfIy9HbHxM5vcXfxpoIEoUrq7SyTt+VmkjPpbngPZ2KO9x++/rV2sJKY/c/mAhkQo1 0PDrw4afqrU+/TdE9WSrD9m+CUHVCdFZMTIhNJxVEL+LhshUn405G9a+rxypymgfanp8NYGdO10JE lhJIJMlmoO8ip87VXglcKH+G+ipMJEQcDbuCG+Cbtu9bBVlgglck8buxKqiHyG9yZ15WAwQNiSdKB fxlutEsVicduLz0U8+EoxNi+T86gEOBKcNdlw7/gVbdf/Lyy4NFZ6y4mqWIuGaL7uNsKE+MdizWyP KTM0R3eA==; X-Authenticated-Id: richard@freakingpenguin.com Received-SPF: pass client-ip=136.175.108.145; envelope-from=richard@freakingpenguin.com; helo=mail-108-mta145.mxroute.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Fri, 28 Jun 2024 21:12:52 -0400 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.devel:22495 Archived-At: * 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