[racket-dev] [plt] Push #20898: master branch updated

From: Will M. Farr (wmfarr at gmail.com)
Date: Fri Aug 20 14:05:12 EDT 2010


Thanks very much for the comments.  I'll get to work preparing an updated version using #:size soon, and send it to Sam for pushing.  As for the issue of a #:size that doesn't match the length of the iteration, I have been thinking about adding a check inside the loop (for sizes that are too small), and a check outside the loop (for sizes that are too large).  If the size does not match the number of loop iterations would it be better to (error 'for/vector "loop iterations (~a) and vector size (~a) do not match" iter size), raise one of the exn:fail:contract type exceptions, or manually construct a blame object and (raise-blame-error ...), or ...?  If it were simply my code, I would just call (error ...), but that's maybe not the best in a general purpose library.


On Aug 19, 2010, at 5:57 PM, Matthew Flatt wrote:

> At Thu, 19 Aug 2010 18:45:43 -0400, samth at racket-lang.org wrote:
>> +(define-syntax for*/flvector
>> +  (lambda (stx)
>> +    (syntax-case stx ()
>> +      ((for*/flvector (for-clause ...) body)
>> +       (syntax/loc stx
>> +         (list->flvector (for*/list (for-clause ...) body))))
>> +      ((for*/flvector length-expr (for-clause ...) body)
>> +       (syntax/loc stx
>> +         (for*/flvector (for-clause ...) body))))))
> I'm not comfortable with overloading based on the number of forms (the
> same with `for/vector' and `for*/vector'), since the `for' forms
> normally allow multiple expressions and internal definitions in the
> `for' body.
> It would be better to use a `#:size' keyword when supplying a specific
> size instead of relying on the number of forms within `for/vector'.
>> + at defform*[((for/vector (for-clause ...) body)
>> +           (for/vector length-expr (for-clause ...) body))]
> Along the same lines: the `body' meta-variable must always be followed
> by `...+' in a syntax description. If you allow only one expression,
> it's `expr' insteda of `body'. (But I think the solution here is to
> change the syntax so that the docs will have `body ...+'.)
>> + at defform*[((for*/vector (for-clause ...) body)
>> +           (for*/vector length-expr (for-clause ...) body))])]{
>> +
>> +Iterates like @scheme[for] or @scheme[for*], but the values of the
>> + at scheme[body] expression are placed in a vector whose length is the
>> +number of iterations.  The optional @scheme[length-expr], if present,
>> +is evaluated to determine the length of the vector in advance of the
>> +iteration; if @scheme[length-expr] is provided, the computation is
>> +more efficient.}
> The documentation doesn't answer the question that you asked before,
> which is what happens when the result of `length-expr' doesn't match
> the number of iterations. There appear to be no tests for that case,
> either.
> _________________________________________________
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/dev

Posted on the dev mailing list.