
notjack
2021-7-21 03:50:47
Alright here’s a puzzler for you all. This code: (define xs (set 1 2 3))
(define/contract checked-xs (set/c number? #:lazy? lazy?) xs)
(set-add checked-xs 'foo)
…runs without error if lazy?
is false, but throws an error at the set-add
expression if lazy?
is true. Now, I get why this happens: the lazily-checked variant of set/c
decided that insertions into the (immutable, persistent) set should satisfy the contract as well. My question for you all is: is this inconsistency bad? If racket/set
were to be redesigned, would you change it? And what if lazy contracts were the default, would your answers to these questions change?