bug#54163: guile 3.0.8 'make check' fails

2022-02-26 Thread Vijay Marupudi
> FAIL: test-out-of-memory

It looks like this test has not been very functional for a while, rlb
has marked it as an expected failure for Debian.

Link to his patch:
https://salsa.debian.org/rlb/deb-guile/-/blob/deb/guile-3.0/d/sid/master/debian/patches/0005-Mark-test-out-of-memory-as-an-expected-failure-for-n.patch

~ Vijay





bug#54143: [PATCH] Add string-split-substring to ice-9 string-fun

2022-02-24 Thread Vijay Marupudi
Hello,

I've attached a patch adding a new function, (string-split-substring str
substr), that splits a string into a list of multiple strings delimited
by a substring. The behavior matches (string-split str char/pred)
exactly.

~ Vijay

>From 3c0940082ff49695ac9c2147c900b959be5f8e70 Mon Sep 17 00:00:00 2001
From: Vijay Marupudi 
Date: Sat, 12 Feb 2022 22:00:57 -0500
Subject: [PATCH] Add string-split-substring

* /ref/api-data.texi: Added documentation
* module/ice-9/string-fun.scm: Added implementation
* test-suite/tests/strings.test: Added tests
---
 doc/ref/api-data.texi | 10 ++
 module/ice-9/string-fun.scm   | 23 ++-
 test-suite/tests/strings.test | 22 +-
 3 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/doc/ref/api-data.texi b/doc/ref/api-data.texi
index 8658b9785..a5fcc47b1 100644
--- a/doc/ref/api-data.texi
+++ b/doc/ref/api-data.texi
@@ -4245,6 +4245,16 @@ Return a new string where every instance of @var{substring} in string
 @end lisp
 @end deffn
 
+@deffn {Scheme Procedure} string-split-substring str substring
+Split the string @var{str} into a list of substrings delimited by the
+appearance of substring @var{substring}. For example:
+
+@lisp
+(string-replace-substring "item-1::item-2::item-3::item-4" "::")
+@result{} ("item-1" "item-2" "item-3" "item-4")
+@end lisp
+@end deffn
+
 @node Representing Strings as Bytes
 @subsubsection Representing Strings as Bytes
 
diff --git a/module/ice-9/string-fun.scm b/module/ice-9/string-fun.scm
index 03e0238fa..a1d4c0366 100644
--- a/module/ice-9/string-fun.scm
+++ b/module/ice-9/string-fun.scm
@@ -26,7 +26,7 @@
 	   separate-fields-before-char string-prefix-predicate string-prefix=?
 	   sans-surrounding-whitespace sans-trailing-whitespace
 	   sans-leading-whitespace sans-final-newline has-trailing-newline?
-   string-replace-substring))
+   string-replace-substring string-split-substring))
 
 
 ;;;
@@ -313,3 +313,24 @@
(else
 (display (substring/shared str start)
 
+(define (string-split-substring str substr)
+  "Split the string @var{str} into a list of substrings delimited by the
+substring @var{substr}."
+
+  (define substrlen (string-length substr))
+  (define strlen (string-length str))
+
+  (define (loop index start)
+(cond
+ ((>= start strlen) (list ""))
+ ((not index) (list (substring str start)))
+ (else
+  (cons (substring str start index)
+(let ((new-start (+ index substrlen)))
+  (loop (string-contains str substr new-start)
+new-start))
+
+  (cond
+   ((string-contains str substr) => (lambda (idx) (loop idx 0)))
+   (else (list str
+
diff --git a/test-suite/tests/strings.test b/test-suite/tests/strings.test
index 7393bc8ec..8bc26e3e3 100644
--- a/test-suite/tests/strings.test
+++ b/test-suite/tests/strings.test
@@ -699,4 +699,24 @@
 
   (pass-if "string-replace-substring"
 (string=? (string-replace-substring "a ring of strings" "ring" "rut")
-  "a rut of struts")))
+  "a rut of struts"))
+
+  (pass-if "string-split-substring - empty string"
+(equal? (string-split-substring "" "foo")
+'("")))
+
+  (pass-if "string-split-substring - non-empty, no delimiters"
+(equal? (string-split-substring "testing" "foo")
+'("testing")))
+
+  (pass-if "string-split-substring - non-empty, delimiters"
+(equal? (string-split-substring "testingfoobar" "foo")
+'("testing" "bar")))
+
+  (pass-if "string-split-substring - non-empty, leading delimiters"
+(equal? (string-split-substring "foobar" "foo")
+'("" "bar")))
+
+  (pass-if "string-split-substring - non-empty, trailing delimiters"
+(equal? (string-split-substring "barfoo" "foo")
+(list "bar" ""
-- 
2.35.1



bug#54142: [PATCH] Add srfi 214 - flexvectors

2022-02-24 Thread Vijay Marupudi
Hello,

I've attached a patch that adds support for dynamic vectors, aka
flexvectors.

Tests and documentation included.

~ Vijay

>From 42206dec4d5e9ae51665c6e98ef07715b89b12fe Mon Sep 17 00:00:00 2001
From: Vijay Marupudi 
Date: Tue, 18 Jan 2022 20:52:08 -0500
Subject: [PATCH] Added srfi-214: flexvectors

Included code, documentation, and tests
---
 doc/ref/api-data.texi  | 842 -
 doc/ref/srfi-modules.texi  |   6 +
 module/Makefile.am |   1 +
 module/srfi/srfi-214.scm   | 735 
 test-suite/Makefile.am |   1 +
 test-suite/tests/srfi-214.test | 437 +
 6 files changed, 2021 insertions(+), 1 deletion(-)
 create mode 100644 module/srfi/srfi-214.scm
 create mode 100644 test-suite/tests/srfi-214.test

diff --git a/doc/ref/api-data.texi b/doc/ref/api-data.texi
index b6c2c4d61..1ba7b57a9 100644
--- a/doc/ref/api-data.texi
+++ b/doc/ref/api-data.texi
@@ -26,7 +26,8 @@ complex.
 * Bit Vectors:: Vectors of bits.
 * Bytevectors:: Sequences of bytes.
 * Arrays::  Multidimensional matrices.
-* VLists::  Vector-like lists.
+* VLists::  Vector-like lists
+* Flexvectors:: Mutable vectors with adjustable size
 * Record Overview:: Walking through the maze of record APIs.
 * SRFI-9 Records::  The standard, recommended record API.
 * Records:: Guile's historical record API.
@@ -8393,6 +8394,845 @@ Return a new vlist whose contents correspond to @var{lst}.
 Return a new list whose contents match those of @var{vlist}.
 @end deffn
 
+@node Flexvectors
+@subsection Flexvectors
+@cindex flexvector
+
+Flexvectors are sometimes better known as a @url{https://en.wikipedia.org/wiki/Dynamic_array,dynamic arrays}. This data
+structure has a wide variety of names in different languages:
+
+@itemize @bullet{}
+
+@item
+JavaScript and Ruby call it an array
+@item
+Python calls it a list
+@item
+Java calls it an ArrayList (and, before that, it was called a Vector)
+
+@end itemize
+
+
+Flexvectors have the same O(1) random-access performance guarantees as
+ordinary vectors. Additionally, appending to the back of a flexvector
+has the same (amortized) performance as setting an existing location in
+the same flexvector.
+
+Functions in this module can be obtained with:
+
+@example
+(use-modules (srfi srfi-214))
+@end example
+
+The material in this section was derived from the
+@url{https://srfi.schemers.org/srfi-214/srfi-214.html,SRFI-214} proposal
+written by Adam Nelson, whose copyright notice is as follows.
+
+@quotation
+(C) Adam Nelson 2020-2021.
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+@end quotation
+
+@subsubsection Constructors
+
+@deffn {Scheme Procedure} make-flexvector size [fill]
+
+Creates and returns a flexvector of size @var{size}. If @var{fill} is
+specified, all of the elements of the vector are initialized to
+@var{fill}. Otherwise, their contents are indeterminate.
+
+
+@example
+(make-flexvector 5 3) @result{} #
+@end example
+@end deffn
+
+@deffn {Scheme Procedure} flexvector x ...
+
+Creates and returns a flexvector whose elements are @var{x ...}.
+
+@example
+(flexvector 0 1 2 3 4) @result{} #
+@end example
+@end deffn
+
+@deffn {Scheme Procedure} flexvector-unfold p f g initial-seed ...
+@deffnx {Scheme Procedure} flexvector-unfold-right p f g initial-seed ...
+
+The fundamental flexvector constructor. @code{flexvector-unfold} is
+modeled on SRFI 1 @code{unfold} instead of SRFI 133
+@code{vector-unfold} because flexvectors are not limited to a
+predetermined length.
+
+@example
+;; List of squares: 1^2 ... 10^2
+(flexvector-unfold (lambda (x) (> x 10)) (lambda (x) (* x x)) (lambda (x) (+ x 1)) 1)
+@result{} #
+@end example
+@end deffn
+
+@deffn {Scheme Procedure} flexvector-copy fv [start [end]]
+@deffnx {

bug#54141: [PATCH] Allow utf[8/16/32]->string functions to take start and ends bounds

2022-02-24 Thread Vijay Marupudi
Hello,

I have attached a patch that extend the bytevector->string functions to
take an start and end range.

The second patch changes the r7rs compatibility layer to use this new
functionality instead of the making a new bytevector as an intermediate
step.

~ Vijay

>From c6be127b4818d43a0244592c18a52de113d3ff08 Mon Sep 17 00:00:00 2001
From: Vijay Marupudi 
Date: Thu, 20 Jan 2022 22:19:25 -0500
Subject: [PATCH 1/2] Allow utf8->string, utf16->string, utf32->string to take
 ranges

Added the following new functions, that behave like substring, but for
bytevector to string conversion.

scm_utf8_range_to_string (SCM, SCM, SCM);
scm_utf16_range_to_string (SCM, SCM, SCM, SCM);
scm_utf32_range_to_string (SCM, SCM, SCM, SCM);

* doc/ref/api-data.texi: Updated documentation to reflect new function
  and range constraints
* libguile/bytevectors.c: Added new function.
* libguile/bytevectors.h: Added new function declaration.
* test-suite/tests/bytevectors.test: Added tests for exceptions and
  behavior for edge cases
---
 doc/ref/api-data.texi |  15 +++-
 libguile/bytevectors.c| 144 +++---
 libguile/bytevectors.h|   3 +
 test-suite/tests/bytevectors.test |  37 
 4 files changed, 164 insertions(+), 35 deletions(-)

diff --git a/doc/ref/api-data.texi b/doc/ref/api-data.texi
index b6c2c4d61..44b64454f 100644
--- a/doc/ref/api-data.texi
+++ b/doc/ref/api-data.texi
@@ -7139,16 +7139,25 @@ UTF-32 (aka. UCS-4) encoding of @var{str}.  For UTF-16 and UTF-32,
 it defaults to big endian.
 @end deffn
 
-@deffn {Scheme Procedure} utf8->string utf
-@deffnx {Scheme Procedure} utf16->string utf [endianness]
-@deffnx {Scheme Procedure} utf32->string utf [endianness]
+@deffn {Scheme Procedure} utf8->string utf [start [end]]
+@deffnx {Scheme Procedure} utf16->string utf [endianness [start [end]]]
+@deffnx {Scheme Procedure} utf32->string utf [endianness [start [end]]]
 @deffnx {C Function} scm_utf8_to_string (utf)
+@deffnx {C Function} scm_utf8_range_to_string (utf, start, end)
 @deffnx {C Function} scm_utf16_to_string (utf, endianness)
+@deffnx {C Function} scm_utf16_range_to_string (utf, endianness, start, end)
 @deffnx {C Function} scm_utf32_to_string (utf, endianness)
+@deffnx {C Function} scm_utf32_range_to_string (utf, endianness, start, end)
+
 Return a newly allocated string that contains from the UTF-8-, UTF-16-,
 or UTF-32-decoded contents of bytevector @var{utf}.  For UTF-16 and UTF-32,
 @var{endianness} should be the symbol @code{big} or @code{little}; when omitted,
 it defaults to big endian.
+
+@var{start} and @var{end}, when provided, must be exact integers
+satisfying:
+
+0 <= @var{start} <= @var{end} <= @code{(bytevector-length @var{utf})}.
 @end deffn
 
 @node Bytevectors as Arrays
diff --git a/libguile/bytevectors.c b/libguile/bytevectors.c
index f42fbb427..12d299042 100644
--- a/libguile/bytevectors.c
+++ b/libguile/bytevectors.c
@@ -2061,25 +2061,46 @@ SCM_DEFINE (scm_string_to_utf32, "string->utf32",
 
 /* Produce the body of a function that converts a UTF-encoded bytevector to a
string.  */
-#define UTF_TO_STRING(_utf_width)	\
+#define UTF_TO_STRING(_utf_width, utf, endianness, start, end)  \
   SCM str = SCM_BOOL_F;			\
   int err;\
   char *c_str = NULL;   \
   char c_utf_name[MAX_UTF_ENCODING_NAME_LEN];\
   char *c_utf;  \
-  size_t c_strlen = 0, c_utf_len = 0;	\
+  size_t c_strlen = 0, c_utf_len, c_start, c_end;   \
 	\
-  SCM_VALIDATE_BYTEVECTOR (1, utf);	\
-  if (scm_is_eq (endianness, SCM_UNDEFINED))\
-endianness = sym_big;		\
+  SCM_VALIDATE_BYTEVECTOR (1, (utf));	\
+  if (scm_is_eq ((endianness), SCM_UNDEFINED))  \
+(endianness) = sym_big;		\
   else	\
-SCM_VALIDATE_SYMBOL (2, endianness);\
+SCM_VALIDATE_SYMBOL (2, (endianness));\
 	\
-  c_utf_len = SCM_BYTEVECTOR_LENGTH (utf);\
-  c_utf = (char *) SCM_BYTEVECTOR_CONTENTS (utf);			\
-  utf_encoding_name (c_utf_name, (_utf_width), endianness);		\
+  c_utf_len = SCM_BYTEVECTOR_LENGTH ((utf));\
+  c_utf = (char *) SCM_BYTEVECTOR_CONTENTS ((utf));			\
+  utf_encoding_name (c_utf_name, (_utf_width), (endianness));		\
+\
+  if (!scm_is_eq ((start), SCM_UNDEFINED))  \
+{   \
+  c_start = scm_to_unsigned_integer ((start), 0, c_utf_len);\
+}   \
+  else  \
+{

bug#49452: Confusing behavior with (include) used in file in GUILE_LOAD_PATH

2021-07-08 Thread Vijay Marupudi
Hello Bengt,

Unfortunately that still doesn't work :( I think they should be
considered the same though, when this bug gets fixed.

Vijay

On 7/7/21 4:22 PM, Bengt Richter wrote:
> Hi Vijay,
> 
> On +2021-07-06 19:31:38 -0500, Vijay Marupudi wrote:
>> Hello all,
>>
>> It is unclear to me what the intended behavior for (include
>> "filename.scm") is, so I'm sending an email about this potential bug.
>>
>> The Local Inclusion docs
>> <https://www.gnu.org/software/guile/manual/html_node/Local-Inclusion.html>
>> seem to state that relative paths are found relative to the file that
>> included them.
>>
>>> If file-name is a relative path, it is searched for relative to the
>>> path that contains the file that the include form appears in.
>>
>> So if I have a file "/libraries/libname/main.scm" than has (include
>> "./helpers.scm"), then the file "/libraries/libname/helpers.scm"
>> *should* (I think) be imported.
>>
> 
> A little nit, but
> (include "filename.scm")
> is not identical to
> (include "./filename.scm")
> so might it be worth trying
>(include "helpers.scm")
> in your code?
> 
> And/or should the docs explain that both ways of writing a relative
> file name in this context are or are not acceptable?
> 
> Might some macro dislike leading dots?
> 
> Long shot ;-)
> 
>> But this does not seem to work if "/libraries" is in the GUILE_LOAD_PATH
>> and my current working directory is somewhere else, say "/home/user" and
>> I'm running "/home/user/program.scm" that imports the (libname main)
>> library from "/libraries". Then Guile seems to try to include the
>> "libname/helpers.scm" file from the current directory, which does not
>> exist.
>>
>> Conversations with leoprikler in IRC have revealed to me that
>> call-with-include-port is the function responsible for this behavior
>> <https://git.savannah.gnu.org/cgit/guile.git/tree/module/ice-9/psyntax.scm#n3231>.
>> `syntax-source` returns a file path relative to the load path, and
>> include tries to use that path to open a file relative to the current
>> working directory.
>>
>> In Guile's bug guidelines
>> <https://www.gnu.org/software/guile/docs/docs-2.2/guile-ref/Reporting-Bugs.html>,
>> to me this fits
>>
>> * Whenever documentation and actual behavior differ, you have certainly
>>   found a bug, either in the documentation or in the program.
>>
>> and potentially
>>
>> * When some part of the documentation is not clear and does not make
>>   sense to you even after re-reading the section, it is a bug.
>>
>> I believe this is a bug, but I may be wrong, so emailing to clarify.
>> Thank you!
>>
>> Vijay Marupudi
>> PhD Student in Human Centered-Computing
>> Georgia Institute of Technology
>>
>>
>>
>>
> 





bug#49452: Confusing behavior with (include) used in file in GUILE_LOAD_PATH

2021-07-08 Thread Vijay Marupudi
Thank you Taylan. This does appear to be the same bug. This bug can be
closed as a duplicate. Looks like Andy Wingo suggested a potential fix,
but there was no follow-up. If someone is willing to show me the ropes
when I need them, I can take a stab at learning the Guile codebase and
fixing the bug.

Vijay

On 7/7/21 3:29 AM, Taylan Kammer wrote:
> On 07.07.2021 02:31, Vijay Marupudi wrote:
>> Hello all,
>>
>> It is unclear to me what the intended behavior for (include
>> "filename.scm") is, so I'm sending an email about this potential bug.
>>
>> The Local Inclusion docs
>> <https://www.gnu.org/software/guile/manual/html_node/Local-Inclusion.html>
>> seem to state that relative paths are found relative to the file that
>> included them.
>>
>>> If file-name is a relative path, it is searched for relative to the
>>> path that contains the file that the include form appears in.
>>
>> So if I have a file "/libraries/libname/main.scm" than has (include
>> "./helpers.scm"), then the file "/libraries/libname/helpers.scm"
>> *should* (I think) be imported.
>>
>> But this does not seem to work if "/libraries" is in the GUILE_LOAD_PATH
>> and my current working directory is somewhere else, say "/home/user" and
>> I'm running "/home/user/program.scm" that imports the (libname main)
>> library from "/libraries". Then Guile seems to try to include the
>> "libname/helpers.scm" file from the current directory, which does not
>> exist.
>>
>> Conversations with leoprikler in IRC have revealed to me that
>> call-with-include-port is the function responsible for this behavior
>> <https://git.savannah.gnu.org/cgit/guile.git/tree/module/ice-9/psyntax.scm#n3231>.
>> `syntax-source` returns a file path relative to the load path, and
>> include tries to use that path to open a file relative to the current
>> working directory.
>>
>> In Guile's bug guidelines
>> <https://www.gnu.org/software/guile/docs/docs-2.2/guile-ref/Reporting-Bugs.html>,
>> to me this fits
>>
>> * Whenever documentation and actual behavior differ, you have certainly
>>   found a bug, either in the documentation or in the program.
>>
>> and potentially
>>
>> * When some part of the documentation is not clear and does not make
>>   sense to you even after re-reading the section, it is a bug.
>>
>> I believe this is a bug, but I may be wrong, so emailing to clarify.
>> Thank you!
>>
>> Vijay Marupudi
>> PhD Student in Human Centered-Computing
>> Georgia Institute of Technology
> 
> Hi Vijay,
> 
> I believe this is the same bug as this one I reported 5-6 years ago:
> 
> https://bugs.gnu.org/21613
> 
> Sadly there was no progress on it as far as I know.
> 





bug#49452: Confusing behavior with (include) used in file in GUILE_LOAD_PATH

2021-07-06 Thread Vijay Marupudi
Hello all,

It is unclear to me what the intended behavior for (include
"filename.scm") is, so I'm sending an email about this potential bug.

The Local Inclusion docs
<https://www.gnu.org/software/guile/manual/html_node/Local-Inclusion.html>
seem to state that relative paths are found relative to the file that
included them.

> If file-name is a relative path, it is searched for relative to the
> path that contains the file that the include form appears in.

So if I have a file "/libraries/libname/main.scm" than has (include
"./helpers.scm"), then the file "/libraries/libname/helpers.scm"
*should* (I think) be imported.

But this does not seem to work if "/libraries" is in the GUILE_LOAD_PATH
and my current working directory is somewhere else, say "/home/user" and
I'm running "/home/user/program.scm" that imports the (libname main)
library from "/libraries". Then Guile seems to try to include the
"libname/helpers.scm" file from the current directory, which does not
exist.

Conversations with leoprikler in IRC have revealed to me that
call-with-include-port is the function responsible for this behavior
<https://git.savannah.gnu.org/cgit/guile.git/tree/module/ice-9/psyntax.scm#n3231>.
`syntax-source` returns a file path relative to the load path, and
include tries to use that path to open a file relative to the current
working directory.

In Guile's bug guidelines
<https://www.gnu.org/software/guile/docs/docs-2.2/guile-ref/Reporting-Bugs.html>,
to me this fits

* Whenever documentation and actual behavior differ, you have certainly
  found a bug, either in the documentation or in the program.

and potentially

* When some part of the documentation is not clear and does not make
  sense to you even after re-reading the section, it is a bug.

I believe this is a bug, but I may be wrong, so emailing to clarify.
Thank you!

Vijay Marupudi
PhD Student in Human Centered-Computing
Georgia Institute of Technology