|
make-specialized-array argument order
Bradley Lucier
(24 May 2022 20:40 UTC)
|
|
Re: make-specialized-array argument order Bradley Lucier (25 May 2022 15:34 UTC)
|
|
Re: make-specialized-array argument order
Alex Shinn
(26 May 2022 23:41 UTC)
|
|
Re: make-specialized-array argument order
Lucier, Bradley J
(27 May 2022 00:09 UTC)
|
|
Re: make-specialized-array argument order
Lucier, Bradley J
(27 May 2022 00:48 UTC)
|
|
Re: make-specialized-array argument order
Bradley Lucier
(26 May 2022 14:13 UTC)
|
On 5/24/22 4:39 PM, Bradley Lucier wrote:
> Which brought to mind whether keyword arguments would be best for
> specifying the argument list for make-specialized-array:
>
> (define (make-specialized-array
> interval
> #!key
> (storage-class (generic-storage-class))
> (initial-value (storage-class-default storage-class))
> (mutable? (specialized-array-default-mutable?))
> (safe? (specialized-array-default-safe?)))
> ...)
>
> Are keyword arguments widely enough supported for this to be a good
> thing to do?
>
> If not, which argument order would be better?
Keyword arguments seem to make it easier to use, and easier to code.
Here's a version (untested) using keywords:
(define (make-specialized-array interval
#!rest rest
#!key
(storagae-class generic-storage-class)
(initial-value (if (storage-class?
storage-class) (storage-class-default storage-class) #f)) ;; error in
storage-class will be caught later
(safe? (specialized-array-default-safe?)))
(cond ((not (storage-class? storage-class))
(apply error "make-specialized-array: storage-class is not a
known storage class: " interval rest))
((not ((storage-class-checker storage-class) initial-value))
(apply error "make-specialized-array: initial-value cannot be
manipulated by the storage class: " interval rest))
((not (boolean? safe?))
(apply error "make-specialized-array: safe? is not a boolean:
" interval rest))
(else
(%%make-specialized-array interval
initial-value
storage-class
safe?))))
and here's the current version using case-lambda:
(define make-specialized-array
(let ()
(define (one-arg interval initial-value storage-class safe?)
(cond ((not (interval? interval))
(error "make-specialized-array: The first argument is not
an interval: "
interval))
(else
(%%make-specialized-array interval
initial-value
storage-class
safe?))))
(define (three-args interval initial-value storage-class safe?)
(cond ((not (storage-class? storage-class))
(error "make-specialized-array: The third argument is not
a storage-class: "
interval initial-value storage-class))
((not ((storage-class-checker storage-class) initial-value))
(error "make-specialized-array: The second argument cannot
be manipulated by the third (a storage class): "
interval initial-value storage-class))
(else
(one-arg interval
initial-value
storage-class
safe?))))
(define (four-args interval initial-value storage-class safe?)
(cond ((not (boolean? safe?))
(error "make-specialized-array: The fourth argument is not
a boolean: "
interval initial-value storage-class safe?))
(else
(three-args interval
initial-value
storage-class
safe?))))
(case-lambda
((interval)
(one-arg interval
(storage-class-default generic-storage-class)
generic-storage-class
(specialized-array-default-safe?)))
((interval initial-value)
(one-arg interval
initial-value
generic-storage-class
(specialized-array-default-safe?)))
((interval initial-value storage-class)
(three-args interval
initial-value
storage-class
(specialized-array-default-safe?)))
((interval initial-value storage-class safe?)
(four-args interval
initial-value
storage-class
safe?)))))