On Thu, Aug 24, 2017 at 2:14 PM, Philip McGrath <[email protected]>
wrote:

> (->* (hash?)
>      ()
>      #:rest (and/c list?
>                    (λ (lst)
>                      (let ([len (length lst)])
>                        (and (even? len)
>                             (not (= 0 len))))))
>      hash?)
>
> -Philip
>

Thanks, Philip!


>
> On Thu, Aug 24, 2017 at 1:08 PM, David Storrs <[email protected]>
> wrote:
>
>> I'd like to be able to write a function that makes it easy to set one or
>> more keys in a hash, without worrying about whether the hash is mutable or
>> not.  It could be called in any of the following ways:
>>
>> (define imm-h (hash 'a 1))
>> (define mut-h (make-hash '((a . 1))))
>>
>> (safe-hash-set imm-hash 'x 2)       ; returns (hash 'a 1 'x 2)
>> (safe-hash-set imm-hash 'x 2 'y 7) ; returns (hash 'a 1 'x 2 'y 7)
>>
>> (safe-hash-set mut-hash 'x 2)        ; returns (begin (hash-set! mut-h 'x
>> 2) mut-h)
>> (safe-hash-set mut-hash 'x 2 'y 7)  ; returns (begin (hash-set! mut-h 'x
>> 2) (hash-set! mut-h 'y 7) mut-h)
>>
>> This definition isn't quite what I need:
>> (define (safe-hash-set h  . args)
>>     (->* (hash?) () #:rest (non-empty-listof any/c) hash?)
>>     ...)
>>
>> I want to be able to say "the rest argument is a list that has an even
>> number of elements and more than zero elements", but I'm not sure how to
>> capture that.  Thoughts?
>>
>> Dave
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to