schemeguile

Does GNU Guile not have the vector->string function?


According to scheme.org Implementations GNU Guile supports the R6 and R7 versions of Scheme. And the guile executable has command line arguments of "--r6rs" and "--r7rs". And the Guile website says

As the R7RS is a much less ambitious standard than the R6RS (see Guile and Scheme), it is very easy for Guile to support. As such, Guile is a fully conforming implementation of R7RS, with the exception of the occasional bug and a couple of unimplemented features:

  • The R7RS specifies a syntax for reading circular data structures using datum labels, such as #0=(1 2 3 . #0#). Guile’s reader does not support this syntax currently; https://bugs.gnu.org/38236.
  • As with R6RS, a number of lexical features of R7RS conflict with Guile’s historical syntax. In addition to r6rs-hex-escapes and hungry-eol-escapes (see Incompatibilities with the R6RS), the r7rs-symbols reader feature needs to be explicitly enabled.

And the Index at scheme.org shows vector->string as part of R7RS small. However, when I run Guile with the --r7rs option, it doesn't recognize vector->string.

"Unbound variable: vector->string"

The same code works with MIT/GNU Scheme

(display (vector->string #(#\H #\i #\!)))  ; => "Hi!"

Solution

  • Their absence does seem to be an oversight in R7RS support, yes. Consider filing a bug report about it?

    In the meantime, here's versions of string->vector and vector->string for Guile.

    (use-modules (srfi srfi-43))
    
    (define* (string->vector s #:optional (start 0) (end (string-length s)))
      (vector-unfold
       (lambda (i) (string-ref s (+ start i))) (- end start)))
    
    (define* (vector->string v #:optional (start 0) (end (vector-length v)))
      (string-tabulate (lambda (i) (vector-ref v (+ start i))) (- end start)))