guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

guile-2.0 and slib


From: Chris Vine
Subject: guile-2.0 and slib
Date: Mon, 30 Dec 2013 16:30:51 +0000

Hi,

Although some of slib in release 3b4 now works with guile-2.0, slib's
srfi-63 arrays do not.  Although few will probably want to use srfi-63
arrays except for compatibility reasons, a number of other slib
procedures do so.  This causes other parts of slib which use arrays to
fail to compile with guile-2.0.

This is because helper procedures for sfri-63 arrays are implemented in
slib's guile-2.init by reference to guile's former uniform arrays,
which were removed in guile-2.0.  A patch is attached which substitutes
guile's typed arrays instead.

This comprises a direct translation from uniform array syntax to typed
array syntax.  The make-typed-wrapper helper procedure does the same as
the former make-uniform-wrapper, which includes the feature that a call
to (A:fixN32b 4) will produce a prototype of type #0u32 (rank 0),
whereas a call to (A:fixN32b) will produce a prototype of type #u32
(rank 1).  This doesn't matter - either seems to be conforming and work
correctly as a prototype - but I wasn't clear why one format was not
chosen for both.  If a rank 1 prototype were to be used in both cases,
make-typed-array could be used in the wrapper in place of
list->typed-array.

The only substantive change in make-array is to test the prototype for
an empty array.  The former version for uniform arrays fails to compile
with an empty prototype (array-ref is given an invalid index).  However,
srfi-63 states that "If the prototype has no elements, then the initial
contents of the returned array are unspecified", which implies that it
should compile. 

I hope this is an appropriate mailing list for slib related issues with
guile.  If not, any assistance on where it should go would be
appreciated.

Chris


--- slib/guile-2.init.orig      2013-12-28 13:17:16.324936077 +0000
+++ slib/guile-2.init   2013-12-30 12:24:28.715147778 +0000
@@ -559,13 +559,16 @@
     ra0))
 (define (array:copy! dest source)
   (array-map! dest identity source))
-;; DIMENSIONS->UNIFORM-ARRAY and list->uniform-array in Guile-1.6.4
-;; cannot make empty arrays.
+
 (define make-array
   (lambda (prot . args)
-    (dimensions->uniform-array args (array-prototype prot)
-                               (apply array-ref prot
-                                      (map car (array-shape prot))))))
+    (let ((fill (if (memv 0 (array-dimensions prot))
+                   *unspecified*
+                   (apply array-ref prot (map car (array-shape prot))))))
+      (apply make-typed-array
+            (array-type prot)
+            fill
+            args))))
 
 (define (list->array rank proto lst)
   (define dimensions
@@ -618,27 +621,24 @@
     vect))
 
 (define create-array make-array)
-(define (make-uniform-wrapper prot)
-  (if (string? prot) (set! prot (string->number prot)))
-  (if prot
-      (lambda opt
-        (if (null? opt)
-            (list->uniform-array 1 prot (list prot))
-            (list->uniform-array 0 prot (car opt))))
-      vector))
-(define ac64 (make-uniform-wrapper "+i"))
-(define ac32 ac64)
-(define ar64 (make-uniform-wrapper "1/3"))
-(define ar32 (make-uniform-wrapper "1."))
-(define as64 vector)
-(define as32 (make-uniform-wrapper -32))
-(define as16 as32)
-(define as8  as32)
-(define au64 vector)
-(define au32 (make-uniform-wrapper  32))
-(define au16 au32)
-(define au8  au32)
-(define at1  (make-uniform-wrapper  #t))
+(define (make-typed-wrapper pair)
+  (lambda opt
+    (if (null? opt)
+       (list->typed-array (car pair) 1 (list (cdr pair)))
+       (list->typed-array (car pair) 0 (car opt)))))
+(define ac64 (make-typed-wrapper '(c64 . 0.0+0.0i)))
+(define ac32 (make-typed-wrapper '(c32 . 0.0+0.0i)))
+(define ar64 (make-typed-wrapper '(f64 . 0.0)))
+(define ar32 (make-typed-wrapper '(f32 . 0.0)))
+(define as64 (make-typed-wrapper '(s64 . 0)))
+(define as32 (make-typed-wrapper '(s32 . 0)))
+(define as16 (make-typed-wrapper '(s16 . 0)))
+(define as8  (make-typed-wrapper '(s8 . 0)))
+(define au64 (make-typed-wrapper '(u64 . 0)))
+(define au32 (make-typed-wrapper '(u32 . 0)))
+(define au16 (make-typed-wrapper '(u16 . 0)))
+(define au8  (make-typed-wrapper '(u8 . 0)))
+(define at1  (make-typed-wrapper '(b . #f)))
 
 ;;; New SRFI-58 names
 ;; flonums



reply via email to

[Prev in Thread] Current Thread [Next in Thread]