unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* [patch] print non-vector 1d arrays as #1(...)
@ 2015-02-17 19:30 Llorens, Daniel
  0 siblings, 0 replies; only message in thread
From: Llorens, Daniel @ 2015-02-17 19:30 UTC (permalink / raw)
  To: guile-user@gnu.org, guile-devel


[-- Attachment #1.1: Type: text/plain, Size: 484 bytes --]


Some folks are justifiably confused when they can't call vector (or bytevector, etc.) routines on 1D arrays that are not vectors (or bytevectors, etc.) but print in the same way. This patch fixes this issue by making such objects print as #1(...).

The patch is trivial, I'll push to master if nobody objects.

This should also kinda fix https://debbugs.gnu.org/cgi/bugreport.cgi?bug=18224.

—
Daniel Llorens
daniel.llorens@viasat.com
☎︎ +1 760 476 7433







[-- Attachment #1.2: Type: text/html, Size: 996 bytes --]

[-- Attachment #2: 0001-Non-vector-1D-arrays-print-as-1.patch --]
[-- Type: application/octet-stream, Size: 1611 bytes --]

From 29a073150f4b7b05f92f7656e94cdd35d1e1cc6c Mon Sep 17 00:00:00 2001
From: Daniel Llorens <daniel.llorens@bluewin.ch>
Date: Tue, 17 Feb 2015 20:08:10 +0100
Subject: [PATCH] Non-vector 1D arrays print as #1(...)

* src/libguile/arrays.c (scm_i_print_array): print the dimension
  whenever array is a true scm_tc7_array.

* test-suite/tests/arrays.test: check that non-vector 1D arrays print as
  expected.
---
 libguile/arrays.c            | 2 +-
 test-suite/tests/arrays.test | 6 +++++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/libguile/arrays.c b/libguile/arrays.c
index 01eb8d6..3814a9b 100644
--- a/libguile/arrays.c
+++ b/libguile/arrays.c
@@ -880,7 +880,7 @@ scm_i_print_array (SCM array, SCM port, scm_print_state *pstate)
   scm_array_get_handle (array, &h);
 
   scm_putc_unlocked ('#', port);
-  if (h.ndims != 1 || h.dims[0].lbnd != 0)
+  if (SCM_I_ARRAYP (array))
     scm_intprint (h.ndims, 10, port);
   if (h.element_type != SCM_ARRAY_ELEMENT_TYPE_SCM)
     scm_write (scm_array_handle_element_type (&h), port);
diff --git a/test-suite/tests/arrays.test b/test-suite/tests/arrays.test
index e1c729d..e17739a 100644
--- a/test-suite/tests/arrays.test
+++ b/test-suite/tests/arrays.test
@@ -489,7 +489,11 @@
       (not (array-contents b))))
 
   (pass-if "literal array"
-    (not (not (array-contents #2((1 2 3) (4 5 6)))))))
+    (not (not (array-contents #2((1 2 3) (4 5 6))))))
+
+  (pass-if "writing 1D arrays that aren't vectors"
+    (string= (format #f "~a" (make-shared-array #(a b c) (lambda (i) (list (+ i 1))) 2))
+             "#1(b c)")))
 
 
 ;;;
-- 
2.2.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2015-02-17 19:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-17 19:30 [patch] print non-vector 1d arrays as #1(...) Llorens, Daniel

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).