From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?Aleix_Conchillo_Flaqu=C3=A9?= Newsgroups: gmane.lisp.guile.devel Subject: Re: [PATCH] vectors: add (vector-last) support Date: Tue, 25 May 2021 12:04:12 -0700 Message-ID: References: <20210212200348.34042-1-aconchillo@gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000c55da805c32c3162" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="35550"; mail-complaints-to="usenet@ciao.gmane.io" To: guile-devel Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Tue May 25 21:04:42 2021 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 1llcM4-0008y0-Sm for guile-devel@m.gmane-mx.org; Tue, 25 May 2021 21:04:40 +0200 Original-Received: from localhost ([::1]:46860 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1llcM3-0004YP-U4 for guile-devel@m.gmane-mx.org; Tue, 25 May 2021 15:04:39 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:57118) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1llcLs-0004YF-HS for guile-devel@gnu.org; Tue, 25 May 2021 15:04:28 -0400 Original-Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]:38827) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1llcLq-0006h4-A8 for guile-devel@gnu.org; Tue, 25 May 2021 15:04:28 -0400 Original-Received: by mail-pf1-x42e.google.com with SMTP id e17so13737771pfl.5 for ; Tue, 25 May 2021 12:04:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=kYFTalkSFBBGmEO9IBGvhedlNKNk9TvOdwHc9q0bNIE=; b=o7GwxCnTcERNKX1/iyrZtIyobhQe0ONRUb2eYBgW1ALfmvHpUqm8GEfl/EcyWqo+6O CQlPJWlInJ45TCjlpke/G728+gH/1g0Q8mA9EYfma/C95XgzmH5qiDckKf3VuLOIIB5+ D4kdfTJQ2zySJW+8cVPpUvFs0vuJ1JAqMDlgpXwAm3c2eaOICaABQyRMxsWQeuoEKaDt B8KTzlZQPAPc7PQo7uTrL4ePWSxb0D+dQfdHtRdshpq+xdEW5LqKFnyl09FQVPjm8T1Y Yrt/5+k+9NnV3lfUWasMS3gGfwpWgb80B1VBYWfZB30uZmmZt5ea+WtBl66iM+BOERNJ TLWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=kYFTalkSFBBGmEO9IBGvhedlNKNk9TvOdwHc9q0bNIE=; b=eCKDRePIGVoZ3acAvMPAw5y5++jEIVQFmleTfoLnG0InHeANnUeHCPfJPJDyaNCAnb 6ib0SQozV/SfujXbVS5lbLguRlO2iAIg9NNMczPT/znATnBFvzmk7V4LeIZgjHpV1xHL oah8YY7XhoUqGQm+xejkJaaTS/ObFfJyskixlgEVNEOEBwFxAc2RGlMHwLs8btW+Myq6 +rx6mfMXSkidbVAZAQHKFKzU9GK1iUy2knfZ2MR8w7gy5tR00DD7G54C9je41f8in4N6 8MdSiGJjtNItZxbIlZxyoBP8eyJg9VuQ65u0iGHSkCBgzURXZYXA97KSEkwcqTzrU26/ q8Rg== X-Gm-Message-State: AOAM532tjPXJ1yPyS4btMOdw6QMkCQSCGstE71bwr/S4JHFWmeDdLegk y8ycBlBqbZXHivMgpqCL3Q23tlSVLL/v/enAfdxQYd3UIkc= X-Google-Smtp-Source: ABdhPJyg0dZOLrl81pwuMe2REdoc1yNHjKQ6lIH6Fkb8uwJPs0lhnoz7XAgkZVGEaXNrkFswFlWT02eEHgeiOI1KkRY= X-Received: by 2002:a62:cec9:0:b029:2e3:9125:c280 with SMTP id y192-20020a62cec90000b02902e39125c280mr28523175pfg.11.1621969464547; Tue, 25 May 2021 12:04:24 -0700 (PDT) In-Reply-To: <20210212200348.34042-1-aconchillo@gmail.com> Received-SPF: pass client-ip=2607:f8b0:4864:20::42e; envelope-from=aconchillo@gmail.com; helo=mail-pf1-x42e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.23 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" Xref: news.gmane.io gmane.lisp.guile.devel:20778 Archived-At: --000000000000c55da805c32c3162 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable ping! On Fri, Feb 12, 2021, 12:03 PM Aleix Conchillo Flaqu=C3=A9 wrote: > * libguile/vectors.c: add (vector-last) support. > > * libguile/vectors.h: define scm_vector_last and scm_c_vector_last. > > * doc/ref/api-data.texi (Vector Accessors): add documentation for > (vector-last). > > Signed-off-by: Aleix Conchillo Flaqu=C3=A9 > --- > doc/ref/api-data.texi | 10 ++++++++++ > libguile/vectors.c | 30 +++++++++++++++++++++++++++++- > libguile/vectors.h | 6 ++++-- > test-suite/tests/srfi-43.test | 12 +++++++++++- > 4 files changed, 54 insertions(+), 4 deletions(-) > > diff --git a/doc/ref/api-data.texi b/doc/ref/api-data.texi > index 2ad13f5a5..0878c1173 100644 > --- a/doc/ref/api-data.texi > +++ b/doc/ref/api-data.texi > @@ -6354,6 +6354,16 @@ Return the contents of position @var{k} (a > @code{size_t}) of > @var{vec}. > @end deftypefn > > +@rnindex vector-last > +@deffn {Scheme Procedure} vector-last vec > +@deffnx {C Function} scm_vector_last (vec) > +Return the contents of the last element of @var{vec}. > +@end deffn > + > +@deftypefn {C Function} SCM scm_c_vector_last (SCM vec) > +Return the contents of the last element of @var{vec}. > +@end deftypefn > + > A vector created by one of the dynamic vector constructor procedures > (@pxref{Vector Creation}) can be modified using the following > procedures. > diff --git a/libguile/vectors.c b/libguile/vectors.c > index 0f1e6085e..f079f1f53 100644 > --- a/libguile/vectors.c > +++ b/libguile/vectors.c > @@ -193,7 +193,35 @@ scm_c_vector_ref (SCM v, size_t k) > } > #undef FUNC_NAME > > -SCM_DEFINE (scm_vector_set_x, "vector-set!", 3, 0, 0, > +SCM_DEFINE (scm_vector_last, "vector-last", 1, 0, 0, > + (SCM vector), > + "@samp{Vector-ref} returns the contents of the last element > of\n" > + "@var{vector}.\n\n" > + "@lisp\n" > + "(vector-ref '#(3 1 27 5)) @result{} 5\n" > + "@end lisp") > +#define FUNC_NAME s_scm_vector_last > +{ > + return scm_c_vector_last (vector); > +} > +#undef FUNC_NAME > + > +SCM > +scm_c_vector_last (SCM v) > +#define FUNC_NAME s_scm_vector_last > +{ > + SCM_VALIDATE_VECTOR (1, v); > + > + size_t len =3D SCM_I_VECTOR_LENGTH (v); > + > + if (len =3D=3D 0) > + scm_out_of_range (NULL, 0); > + > + return scm_c_vector_ref (v, len - 1); > +} > +#undef FUNC_NAME > + > +SCM_DEFINE (scm_vector_set_x, "vector-set!", 3, 0, 0, > (SCM vector, SCM k, SCM obj), > "@var{k} must be a valid index of @var{vector}.\n" > "@code{Vector-set!} stores @var{obj} in element @var{k} of > @var{vector}.\n" > diff --git a/libguile/vectors.h b/libguile/vectors.h > index 41e2c8909..08fe19f49 100644 > --- a/libguile/vectors.h > +++ b/libguile/vectors.h > @@ -1,7 +1,7 @@ > #ifndef SCM_VECTORS_H > #define SCM_VECTORS_H > > -/* Copyright 1995-1996,1998,2000-2002,2004-2006,2008-2009,2011,2014,2018 > +/* Copyright > 1995-1996,1998,2000-2002,2004-2006,2008-2009,2011,2014,2018,2020 > Free Software Foundation, Inc. > > This file is part of Guile. > @@ -32,13 +32,14 @@ SCM_API SCM scm_vector_p (SCM x); > SCM_API SCM scm_vector_length (SCM v); > SCM_API SCM scm_vector (SCM l); > SCM_API SCM scm_vector_ref (SCM v, SCM k); > +SCM_API SCM scm_vector_last (SCM v); > SCM_API SCM scm_vector_set_x (SCM v, SCM k, SCM obj); > SCM_API SCM scm_make_vector (SCM k, SCM fill); > SCM_API SCM scm_vector_to_list (SCM v); > SCM_API SCM scm_vector_fill_x (SCM v, SCM fill_x); > SCM_API SCM scm_vector_move_left_x (SCM vec1, SCM start1, SCM end1, > SCM vec2, SCM start2); > -SCM_API SCM scm_vector_move_right_x (SCM vec1, SCM start1, SCM end1, > +SCM_API SCM scm_vector_move_right_x (SCM vec1, SCM start1, SCM end1, > SCM vec2, SCM start2); > SCM_API SCM scm_vector_copy (SCM vec); > > @@ -47,6 +48,7 @@ SCM_API int scm_is_simple_vector (SCM obj); > SCM_API SCM scm_c_make_vector (size_t len, SCM fill); > SCM_API size_t scm_c_vector_length (SCM vec); > SCM_API SCM scm_c_vector_ref (SCM vec, size_t k); > +SCM_API SCM scm_c_vector_last (SCM vec); > SCM_API void scm_c_vector_set_x (SCM vec, size_t k, SCM obj); > SCM_API const SCM *scm_vector_elements (SCM vec, > scm_t_array_handle *h, > diff --git a/test-suite/tests/srfi-43.test b/test-suite/tests/srfi-43.tes= t > index 554843e75..4d0093974 100644 > --- a/test-suite/tests/srfi-43.test > +++ b/test-suite/tests/srfi-43.test > @@ -1,6 +1,6 @@ > ;;;; srfi-43.test --- test suite for SRFI-43 Vector library -*- scheme -= *- > ;;;; > -;;;; Copyright (C) 2014 Free Software Foundation, Inc. > +;;;; Copyright (C) 2014, 2020 Free Software Foundation, Inc. > ;;;; > ;;;; This library is free software; you can redistribute it and/or > ;;;; modify it under the terms of the GNU Lesser General Public > @@ -390,6 +390,16 @@ > (pass-if-error "non-vector" (vector-ref '(a b c) 0)) > (pass-if-error "inexact index" (vector-ref '#(a b c) 1.0))) > > +;; > +;; vector-last > +;; > + > +(with-test-prefix "vector-last" > + (pass-if-equal "single element" 'a (vector-last '#(a))) > + (pass-if-equal "multiple elements" 'c (vector-last '#(a b c))) > + (pass-if-error "empty vector" (vector-last '#())) > + (pass-if-error "non-vector" (vector-last '(a b c)))) > + > ;; > ;; vector-length > ;; > -- > 2.30.0 > > --000000000000c55da805c32c3162 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
ping!

On Fri, Feb 12, 2021, 12:03 PM Aleix Conchillo Flaqu= =C3=A9 <aconchillo@gmail.com= > wrote:
* libguile/vectors.c: a= dd (vector-last) support.

* libguile/vectors.h: define scm_vector_last and scm_c_vector_last.

* doc/ref/api-data.texi (Vector Accessors): add documentation for
(vector-last).

Signed-off-by: Aleix Conchillo Flaqu=C3=A9 <aconchillo@gmail.com&g= t;
---
=C2=A0doc/ref/api-data.texi=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| 10 +++++++++= +
=C2=A0libguile/vectors.c=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 | 30 ++++= +++++++++++++++++++++++++-
=C2=A0libguile/vectors.h=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 |=C2=A0 6= ++++--
=C2=A0test-suite/tests/srfi-43.test | 12 +++++++++++-
=C2=A04 files changed, 54 insertions(+), 4 deletions(-)

diff --git a/doc/ref/api-data.texi b/doc/ref/api-data.texi
index 2ad13f5a5..0878c1173 100644
--- a/doc/ref/api-data.texi
+++ b/doc/ref/api-data.texi
@@ -6354,6 +6354,16 @@ Return the contents of position @var{k} (a @code{siz= e_t}) of
=C2=A0@var{vec}.
=C2=A0@end deftypefn

+@rnindex vector-last
+@deffn {Scheme Procedure} vector-last vec
+@deffnx {C Function} scm_vector_last (vec)
+Return the contents of the last element of @var{vec}.
+@end deffn
+
+@deftypefn {C Function} SCM scm_c_vector_last (SCM vec)
+Return the contents of the last element of @var{vec}.
+@end deftypefn
+
=C2=A0A vector created by one of the dynamic vector constructor procedures<= br> =C2=A0(@pxref{Vector Creation}) can be modified using the following
=C2=A0procedures.
diff --git a/libguile/vectors.c b/libguile/vectors.c
index 0f1e6085e..f079f1f53 100644
--- a/libguile/vectors.c
+++ b/libguile/vectors.c
@@ -193,7 +193,35 @@ scm_c_vector_ref (SCM v, size_t k)
=C2=A0}
=C2=A0#undef FUNC_NAME

-SCM_DEFINE (scm_vector_set_x, "vector-set!", 3, 0, 0,
+SCM_DEFINE (scm_vector_last, "vector-last", 1, 0, 0,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(SCM vector),
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 "@samp{Vector-ref} returns = the contents of the last element of\n"
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 "@var{vector}.\n\n" +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 "@lisp\n"
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 "(vector-ref '#(3 1 27 = 5)) @result{} 5\n"
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 "@end lisp")
+#define FUNC_NAME s_scm_vector_last
+{
+=C2=A0 return scm_c_vector_last (vector);
+}
+#undef FUNC_NAME
+
+SCM
+scm_c_vector_last (SCM v)
+#define FUNC_NAME s_scm_vector_last
+{
+=C2=A0 SCM_VALIDATE_VECTOR (1, v);
+
+=C2=A0 size_t len =3D SCM_I_VECTOR_LENGTH (v);
+
+=C2=A0 if (len =3D=3D 0)
+=C2=A0 =C2=A0 scm_out_of_range (NULL, 0);
+
+=C2=A0 return scm_c_vector_ref (v, len - 1);
+}
+#undef FUNC_NAME
+
+SCM_DEFINE (scm_vector_set_x, "vector-set!", 3, 0, 0,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (SCM vector, SCM k, SCM obj),
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"@var{k} must be a val= id index of @var{vector}.\n"
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"@code{Vector-set!} st= ores @var{obj} in element @var{k} of @var{vector}.\n"
diff --git a/libguile/vectors.h b/libguile/vectors.h
index 41e2c8909..08fe19f49 100644
--- a/libguile/vectors.h
+++ b/libguile/vectors.h
@@ -1,7 +1,7 @@
=C2=A0#ifndef SCM_VECTORS_H
=C2=A0#define SCM_VECTORS_H

-/* Copyright 1995-1996,1998,2000-2002,2004-2006,2008-2009,2011,2014,2018 +/* Copyright 1995-1996,1998,2000-2002,2004-2006,2008-2009,2011,2014,2018,2= 020
=C2=A0 =C2=A0 =C2=A0 Free Software Foundation, Inc.

=C2=A0 =C2=A0 This file is part of Guile.
@@ -32,13 +32,14 @@ SCM_API SCM scm_vector_p (SCM x);
=C2=A0SCM_API SCM scm_vector_length (SCM v);
=C2=A0SCM_API SCM scm_vector (SCM l);
=C2=A0SCM_API SCM scm_vector_ref (SCM v, SCM k);
+SCM_API SCM scm_vector_last (SCM v);
=C2=A0SCM_API SCM scm_vector_set_x (SCM v, SCM k, SCM obj);
=C2=A0SCM_API SCM scm_make_vector (SCM k, SCM fill);
=C2=A0SCM_API SCM scm_vector_to_list (SCM v);
=C2=A0SCM_API SCM scm_vector_fill_x (SCM v, SCM fill_x);
=C2=A0SCM_API SCM scm_vector_move_left_x (SCM vec1, SCM start1, SCM end1, =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 SCM vec2, SCM start2);=
-SCM_API SCM scm_vector_move_right_x (SCM vec1, SCM start1, SCM end1,
+SCM_API SCM scm_vector_move_right_x (SCM vec1, SCM start1, SCM end1,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0SCM vec2, SCM st= art2);
=C2=A0SCM_API SCM scm_vector_copy (SCM vec);

@@ -47,6 +48,7 @@ SCM_API int scm_is_simple_vector (SCM obj);
=C2=A0SCM_API SCM scm_c_make_vector (size_t len, SCM fill);
=C2=A0SCM_API size_t scm_c_vector_length (SCM vec);
=C2=A0SCM_API SCM scm_c_vector_ref (SCM vec, size_t k);
+SCM_API SCM scm_c_vector_last (SCM vec);
=C2=A0SCM_API void scm_c_vector_set_x (SCM vec, size_t k, SCM obj);
=C2=A0SCM_API const SCM *scm_vector_elements (SCM vec,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 scm_t_ar= ray_handle *h,
diff --git a/test-suite/tests/srfi-43.test b/test-suite/tests/srfi-43.test<= br> index 554843e75..4d0093974 100644
--- a/test-suite/tests/srfi-43.test
+++ b/test-suite/tests/srfi-43.test
@@ -1,6 +1,6 @@
=C2=A0;;;; srfi-43.test --- test suite for SRFI-43 Vector library -*- schem= e -*-
=C2=A0;;;;
-;;;; Copyright (C) 2014 Free Software Foundation, Inc.
+;;;; Copyright (C) 2014, 2020 Free Software Foundation, Inc.
=C2=A0;;;;
=C2=A0;;;; This library is free software; you can redistribute it and/or =C2=A0;;;; modify it under the terms of the GNU Lesser General Public
@@ -390,6 +390,16 @@
=C2=A0 =C2=A0(pass-if-error "non-vector" (vector-ref '(a b c)= 0))
=C2=A0 =C2=A0(pass-if-error "inexact index" (vector-ref '#(a = b c) 1.0)))

+;;
+;; vector-last
+;;
+
+(with-test-prefix "vector-last"
+=C2=A0 (pass-if-equal "single element" 'a (vector-last '= #(a)))
+=C2=A0 (pass-if-equal "multiple elements" 'c (vector-last &#= 39;#(a b c)))
+=C2=A0 (pass-if-error "empty vector" (vector-last '#()))
+=C2=A0 (pass-if-error "non-vector" (vector-last '(a b c))))<= br> +
=C2=A0;;
=C2=A0;; vector-length
=C2=A0;;
--
2.30.0

--000000000000c55da805c32c3162--