d_run
2018-9-3 15:38:34

Question about contracts: trying to randomly generate some hash inputs like so:

(contract-random-generate (hash/c integer? boolean?))

But cannot:

> (contract-random-generate (hash/c integer? boolean?))
; contract-random-generate: unable to construct any generator for contract:
;   (hash/c integer? boolean?) [,bt for context]

d_run
2018-9-3 15:38:42

How would I do this?


samth
2018-9-3 16:04:29

@d_run that sounds like hashes are unsupported


samth
2018-9-3 16:06:53

probably relatively easy to add in racket/contract/private/hash.rkt


shu--hung
2018-9-3 17:23:43

An indirect workaround: (make-immutable-hash (contract-random-generate (listof (cons/c integer? boolean?))))


d_run
2018-9-3 20:22:10

with raco setup is there a way to just recompile the <collects>/racket/private/contract ?


d_run
2018-9-3 20:22:44

something like raco setup -l collects/racket/private/contract ?


samth
2018-9-3 20:23:40

@d_run raco setup racket/private/contract


d_run
2018-9-3 21:10:25

hmmm


d_run
2018-9-3 21:10:28
$ ./racket/bin/raco setup racket/private/contract
collection-path: collection not found
  collection: "racket/private/contract"
  in collection directories:
   /Users/shibuya/Library/Racket/development/collects
   /Users/shibuya/github/racket/racket/collects
   ... [184 additional linked and package directories]

samth
2018-9-3 21:11:06

ah, you transposed private and contract from my original message to your question


d_run
2018-9-3 21:12:09

derp


d_run
2018-9-3 21:13:50

yah that got it - thanks


philip.mcgrath
2018-9-3 22:49:46

@d_run Another workaround would be to use flat-named-contract to attach a generator function. If you need an even more general workaround, you could acomplish the same thing with make-contract, prop:contract, etc. (But it would be great to add generation support to hash/c!)


d_run
2018-9-4 00:31:53

well I seem to be stumbling onto something


d_run
2018-9-4 00:31:56
$ ./racket/bin/racket -i
Welcome to Racket v7.0.0.17.
> (require racket/contract)
> (contract-random-generate (hash/c number? (listof number?)))
'#hash((0 . (0 1.308710636691283e-07)))

d_run
2018-9-4 00:33:15
> (contract-random-generate (hash/c number? (hash/c number? string?)))
'#hash((-150.0-2147483647.0i
        .
        #hash((-2147483647.0-185.0i
               .
               "\uA7CBጚ䛡\U000351CD𫑫\U000B46B6\U000FAAC2\U0008DD1F\U000AA812⛕\U0010D6B6\U000D8D2B\U00048EBE㷎\U00035091𩣲Ų볈⢍읿ଓ愒妙\U0009F757㏥\U00072BE1彞辯逰能\U0005F69E뮝\U0004ACA7\U00071BC1\U00099D0F𧎝ᐾ\U00093943㜷\U0001F964髣\U00062741꧖粫\U00065E50\U00087B85\U000D696F\U000C8D02\U00046E0D\U000BE119魥\U00013BFF\U000A502D\U0009C413㍡刬ᑨ\U000CD8EC鵸\U000342E6ⷲꪌ㔱\U0003579F\U000E3620똠\U000459D9죄膅骖䎷駥\U000D72A8\U000A201E\U000BFD8E\U000FC781\U00052888᧳玠u逫煃ᨠ鷊\U0008B647遤縙髆ᇪ🞛\U00056173\U0009FDD4\U000B2F5A熑藬\U000F4E9B\U00067EF7\U0002DAA6"))))

shu--hung
2018-9-4 00:43:32

that looks correct


d_run
2018-9-4 00:48:37

need to write tests, run tests, etc - then will try and get a PR ready


d_run
2018-9-4 01:00:02

Where would I find tests for the contracts?




d_run
2018-9-4 01:06:25

ah cool! figured it was in a pkg but couldn’t find it, thanks


d_run
2018-9-4 01:29:01

and ./racket/bin/raco test -l tests/racket/test would run those right?


d_run
2018-9-4 01:44:50

ah looks like $ ./racket/bin/raco test -m ~/github/racket/pkgs/racket-test/tests/racket/contract will just run the contracts


dan
2018-9-4 01:58:00

I usually just run the all.rkt file in that directory as racket all.rkt which should run them all, you should be able to run individual test files the same way


d_run
2018-9-4 02:17:46

ah cool thanks