unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* [PATCH] Add nondestructive delq1, delv1, and delete1.
@ 2024-06-29  0:19 Richard Sent
  2024-06-29  2:52 ` The Guile junk drawer and a C plea (was: [PATCH] Add nondestructive delq1, delv1, and delete1.) Thompson, David
  0 siblings, 1 reply; 81+ messages in thread
From: Richard Sent @ 2024-06-29  0:19 UTC (permalink / raw)
  To: guile-devel; +Cc: Richard Sent

* 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




^ permalink raw reply related	[flat|nested] 81+ messages in thread

end of thread, other threads:[~2024-07-26 16:37 UTC | newest]

Thread overview: 81+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-29  0:19 [PATCH] Add nondestructive delq1, delv1, and delete1 Richard Sent
2024-06-29  2:52 ` The Guile junk drawer and a C plea (was: [PATCH] Add nondestructive delq1, delv1, and delete1.) Thompson, David
2024-06-29  7:37   ` Mikael Djurfeldt
2024-06-29  8:12     ` The Guile junk drawer and a C plea Dr. Arne Babenhauserheide
2024-06-29  8:33       ` Damien Mattei
2024-06-29  9:59         ` Dr. Arne Babenhauserheide
2024-06-29  9:07     ` The Guile junk drawer and a C plea (was: [PATCH] Addnondestructive delq1, delv1, and delete1.) Maxime Devos
2024-06-29 10:41     ` Maxime Devos
2024-06-29 18:12       ` The Guile junk drawer and a C plea Dr. Arne Babenhauserheide
2024-06-29 18:18         ` Lassi Kortela
2024-06-29 18:27         ` Maxime Devos
2024-06-29 19:04           ` GRFI [was: The Guile junk drawer and a C plea] Matt Wette
2024-06-29 19:13             ` Lassi Kortela
2024-07-02 19:42               ` Jason Hemann
2024-06-29 19:39             ` Jean Abou Samra
2024-06-29 21:53       ` The Guile junk drawer and a C plea Philip McGrath
2024-06-29 22:41         ` Maxime Devos
2024-06-30  7:12           ` Dr. Arne Babenhauserheide
2024-06-30  9:45             ` Maxime Devos
2024-06-30 14:34               ` Dr. Arne Babenhauserheide
2024-07-01  9:06                 ` Maxime Devos
2024-07-01 10:42                   ` Dr. Arne Babenhauserheide
2024-06-30  6:16         ` #lang header Lassi Kortela
2024-06-30  0:17     ` The Guile junk drawer and a C plea Thompson, David
2024-07-17  2:25     ` The Guile junk drawer and a C plea (was: [PATCH] Add nondestructive delq1, delv1, and delete1.) Olivier Dion
2024-07-17 10:01       ` Library namespaces (guile ...) and (srfi ...) Lassi Kortela
2024-07-17 10:45       ` The Guile junk drawer and a C plea Dr. Arne Babenhauserheide
2024-07-17 10:53         ` MSavoritias
2024-07-17 11:12           ` Lassi Kortela
2024-07-17 15:44             ` Olivier Dion
2024-07-17 16:09               ` tomas
2024-07-17 16:29                 ` Attila Lendvai
2024-07-17 20:32                   ` Dr. Arne Babenhauserheide
2024-07-18  9:04                     ` Attila Lendvai
2024-07-18 15:11                       ` Dr. Arne Babenhauserheide
2024-07-17 20:33           ` Dr. Arne Babenhauserheide
2024-07-18 22:56             ` Greg Troxel
2024-07-19  8:46               ` Maxime Devos
2024-07-20  9:34                 ` Attila Lendvai
2024-07-20 13:01                   ` [PATCH] " Dr. Arne Babenhauserheide
2024-07-20 13:30                     ` Name of the standard library Lassi Kortela
2024-07-20 14:52                       ` Dr. Arne Babenhauserheide
2024-07-20 15:24                         ` Lassi Kortela
2024-07-20 15:46                           ` Dr. Arne Babenhauserheide
2024-07-20 16:04                             ` Portable code Lassi Kortela
2024-07-20 16:24                               ` Dr. Arne Babenhauserheide
2024-07-20 16:37                                 ` Lassi Kortela
2024-07-20 21:48                                   ` Dr. Arne Babenhauserheide
2024-07-26  9:21                                     ` Lassi Kortela
2024-07-20 16:11                             ` Name of the standard library Maxime Devos
2024-07-20 16:26                               ` Dr. Arne Babenhauserheide
2024-07-20 16:48                                 ` Maxime Devos
2024-07-20 18:42                                   ` Portable imports Lassi Kortela
2024-07-20 19:18                                     ` Maxime Devos
2024-07-20 19:46                                       ` Encoding library names Lassi Kortela
2024-07-20 20:35                                         ` Maxime Devos
2024-07-21  5:55                                       ` Portable imports tomas
2024-07-20 19:23                                     ` Maxime Devos
2024-07-20 16:54                                 ` Name of the standard library Lassi Kortela
2024-07-20 21:56                                   ` Dr. Arne Babenhauserheide
2024-07-26  9:38                                     ` Lassi Kortela
2024-07-20 15:43                         ` Maxime Devos
2024-07-20 15:58                           ` Lassi Kortela
2024-07-21  7:15                         ` MSavoritias
2024-07-21  8:04                           ` Dr. Arne Babenhauserheide
2024-07-26 16:37                             ` Library names describe APIs Lassi Kortela
2024-07-21 16:50                           ` Name of the standard library Ricardo Wurmus
2024-07-21 13:00                         ` Attila Lendvai
2024-07-20 16:01                       ` Maxime Devos
2024-07-20 16:27                         ` Lassi Kortela
2024-07-20 16:55                           ` Maxime Devos
2024-07-21 12:16                     ` [PATCH] The Guile junk drawer and a C plea Attila Lendvai
2024-07-21 21:10                       ` Dr. Arne Babenhauserheide
2024-07-22 14:52                         ` Attila Lendvai
2024-07-20 15:26                   ` Maxime Devos
2024-07-17 11:04         ` Lassi Kortela
2024-06-29 18:38   ` The Guile junk drawer and a C plea (was: [PATCH] Add nondestructive delq1, delv1, and delete1.) Jean Abou Samra
2024-06-29 19:02   ` The Guile junk drawer and a C plea Richard Sent
2024-06-29 23:51     ` Thompson, David
2024-06-30  7:23       ` Dr. Arne Babenhauserheide
2024-07-01  2:55   ` Maxim Cournoyer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).