1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-16 00:30:21 +02:00

srfi-1 delete delete!: move from C to Scheme

* libguile/srfi-1.c (scm_srfi1_delete, scm_srfi1_delete_x): delete.
* libguile/srfi-1.h (scm_srfi1_delete, scm_srfi1_delete_x): delete.
* module/srfi/srfi-1.scm: add delete and delete!.
This commit is contained in:
Rob Browning 2024-07-16 23:19:15 -05:00
parent c5f26d4c27
commit a816b2484b
3 changed files with 35 additions and 113 deletions

View file

@ -982,6 +982,41 @@ CLIST1 ... CLISTN, that satisfies PRED."
(else
(lp (map cdr lists) (+ i 1)))))))
;;; Deletion
(define* (delete x lst #:optional (pred equal?))
"Return a list containing the elements of @var{lst} but with
those equal to @var{x} deleted. The returned elements will be in the
same order as they were in @var{lst}.
Equality is determined by @var{pred}, or @code{equal?} if not given. An
equality call is made just once for each element, but the order in which
the calls are made on the elements is unspecified.
The equality calls are always @code{(pred x elem)}, ie.@: the given
@var{x} is first. This means for instance elements greater than 5 can
be deleted with @code{(delete 5 lst <)}.
@var{lst} is not modified, but the returned list might share a common
tail with @var{lst}."
(remove (lambda (elem) (pred x elem)) lst))
(define* (delete! x lst #:optional (pred equal?))
"Return a list containing the elements of @var{lst} but with
those equal to @var{x} deleted. The returned elements will be in the
same order as they were in @var{lst}.
Equality is determined by @var{pred}, or @code{equal?} if not given. An
equality call is made just once for each element, but the order in which
the calls are made on the elements is unspecified.
The equality calls are always @code{(pred x elem)}, ie.@: the given
@var{x} is first. This means for instance elements greater than 5 can
be deleted with @code{(delete 5 lst <)}.
@var{lst} may be modified to construct the returned list."
(remove! (lambda (elem) (pred x elem)) lst))
;;; Association lists
(define alist-cons acons)