[r6rs-discuss] [Formal] proc in hash-table-update! should not mutate hash-table

From: William D Clinger <will>
Date: Sat Feb 24 15:41:32 2007

I am posting this as an individual member of the Scheme
community. I am not speaking for the R6RS editors, and
this message should not be confused with the editors'
eventual formal response.

Daniel Villeneuve wrote:
> > Your definition of vector-map seems buggy to me.
>
> But I did not find any wording in R6RS that would forbid
> this behavior.

Which represents, in my opinion, one of a great many
similar errors in the current draft.

> What about a constraint worded like this?

I think specifications like the following would be
simpler and more useful.

    (map proc list1 list2 ...) procedure

    Proc should be a procedure that takes as many arguments as
    there are lists, the lists should all have the same length,
    and proc should not mutate any of the lists.

    The map procedure applies proc element-wise to the lists and
    returns a newly allocated list of the results, in order.
    The dynamic order in which proc is applied to the elements
    of the lists is unspecified.

    When all arguments are as they should be, the map procedure
    must behave as though it had been defined by

        (define (map proc list1 . lists)
          (define (map1 proc list)
            (if (null? list)
                '()
                (cons (proc (car list))
                      (map1 proc (cdr list)))))
          (cond ((null? lists) (map1 proc list1))
                ((null? list1) '())
                (else
                 (cons (apply proc (car list1) (map1 car lists))
                       (apply map proc (cdr list1)
                                       (map1 cdr lists))))))

    (vector-map proc vector1 vector2 ...) procedure

    Proc should be a procedure that takes as many arguments as
    there are vectors, the vectors should all have the same
    length, and proc should not mutate any of the vectors.

    The map procedure applies proc element-wise to the vectors
    and returns a newly allocated vector of the results, in
    order. The dynamic order in which proc is applied to the
    elements of the vectors is unspecified.

    When all arguments are as they should be, the vector-map
    procedure must behave as though it had been defined by

        (define (vector-map proc vector1 . vectors)
          (list->vector
           (apply map proc (vector->list vector1)
                           (map vector->list vectors))))

The exact wording is the responsibility of the project editor.

Will
Received on Sat Feb 24 2007 - 15:41:27 UTC

This archive was generated by hypermail 2.3.0 : Wed Oct 23 2024 - 09:15:01 UTC