cperivol
2022-1-21 15:56:58

hello, I am looking for a function (-> contract? any/c boolean?) that checks if a value satisfies a contract, is there such a thing?


sorawee
2022-1-21 15:58:51

That’s in general undecidable, right?


cperivol
2022-1-21 15:59:01

how so?


sorawee
2022-1-21 15:59:33

E.g., when the contract is a function contract, and the value is a function value.


sorawee
2022-1-21 15:59:48

Then you are asking about the behavior of the function


sorawee
2022-1-21 15:59:57

And this easily becomes the halting problem.


cperivol
2022-1-21 16:00:27

Ah ok, yes of course


cperivol
2022-1-21 16:02:09

So the kind of implementation I had in mind was something that looks like (define/contract (check v) (-> my-contract/c void?) #t)


cperivol
2022-1-21 16:03:23

where my-conctact/c is a parameter and the contract error is caught and instead of it #f is returned etc, I think the point is clear though


sorawee
2022-1-21 16:04:34

So, there’s a class of contracts that’s flat. These contracts are immediately checked, and you can use them as predicates too



sorawee
2022-1-21 16:05:06

Does that work for your purpose?


sorawee
2022-1-21 16:06:06

E.g.,

(define (flat-contract-satisfies? c v) (c v))


cperivol
2022-1-21 16:06:24

yes that’s exactly what I wanted but hash/c is not a flat contract :disappointed:


cperivol
2022-1-21 16:06:51

the contract I wanted to check was a hash/c


sorawee
2022-1-21 16:07:29

Where does hash/c come from? Are you the person who writes it?


sorawee
2022-1-21 16:07:47

hash/c could be flat by providing it the option


cperivol
2022-1-21 16:08:11

yes, I have this contract that is (define path/c (hash/c symbol? (sequence/c or-group/c))) and I want to test that it works for some values


massung
2022-1-21 16:08:18

Are you able to be more specific w/ the contract? For example, I think hash-eq? is a flat contract.


cperivol
2022-1-21 16:08:19

yes! thank you


cperivol
2022-1-21 16:10:09

I am assuming there is no flat contract variant for sequence/c


cperivol
2022-1-21 16:10:58

looks like flat contracts are directly callable, nice


sorawee
2022-1-21 16:11:14

Yeah. sequence in general could be infinite, so I think flat contract wouldn’t work well there.


cperivol
2022-1-21 16:12:14

I used list/c for now and I will worry about it some other time


cperivol
2022-1-21 16:12:23

thanks @sorawee, much appreciated


sorawee
2022-1-21 16:12:32

You probably want listof, I think.


sorawee
2022-1-21 16:13:09

Well, I guess it depends on what you want to do.


cperivol
2022-1-21 16:15:57

what’s the difference?


sorawee
2022-1-21 16:16:30

(list/c number? boolean? number?) recognizes (list 1 #t 3)


sorawee
2022-1-21 16:16:42

(listof number?) recognizes (list 1 2 3)


cperivol
2022-1-21 16:17:02

excellent, thank you


capfredf
2022-1-21 16:23:53

is this test expected tor run for more than 20 mins (it started 20 mins ago, and it is still running) raco test: "/home/capfredf/code/racket/racket/share/pkgs/../../../pkgs/racket-benchmarks/tests/racket/benchmarks/shootout/k-nucleotide.rkt" raco test: @(test-responsible '(eli jay mflatt robby samth stamourv))


cperivol
2022-1-21 16:48:54

is there a require ish statement that I can run on the REPL to run the tests of a submodule, something along the lines of (force-require (sumbod "path.rkt" types-submod cheap-tests))


cperivol
2022-1-21 16:49:43

?


greg
2022-1-21 16:49:47

I want to like JavaScript but I’m bothered by all the extra equal signs and curly braces.


soegaard2
2022-1-21 16:50:16

greg
2022-1-21 16:51:47

raco test has a command-line flag for a submodule to run.


greg
2022-1-21 16:52:42

I think -m?


badkins
2022-1-21 16:53:22

I’ve been reading through David Flanagan’s “JavaScript: The Definitive Guide” 7th ed., and JavaScript has much improved over years ago :) Still doesn’t hold a candle to Racket IMO, but the improvements are welcome for when I need to enhance a web app. I’ve realized I no longer need jQuery since native JS does everything I need now in ES6+


cperivol
2022-1-21 16:53:48

I would prefer the tests to be run in the repl… If it’s not possible I will probably resort to that


greg
2022-1-21 16:54:38

Nope it’s -s.


greg
2022-1-21 16:55:04

If you’re using Racket Mode you can put point inside any submodule form and C-c C-c to run that submodule.


greg
2022-1-21 16:55:15

From an edit buffer. That’s not “in the REPL” tho.


cperivol
2022-1-21 16:55:56

I did (require (submod (file "/path/to/file.rkt") types-submod cheap-tests)) and it works but it doesn’t run the displayln statements in the top level of cheap-tests


greg
2022-1-21 16:57:37

I’m not sure off the top of my head. (FWIW I usually have a Makefile for tests, and sometimes slow or extra tests get their own target and use that raco test flag to run a submodule. And then M-x compile make xxx.)


james275
2022-1-21 16:58:06

It’s just syntax. You get used to it. You can also (mostly) make your tooling take care of the syntax for you to focus on semantics.


soegaard2
2022-1-21 16:58:43

It’s not just syntax. It’s also the split between commands and expressions.


greg
2022-1-21 16:59:12

I’m kind of confused how doing the require doesn’t result in the displayln.


cperivol
2022-1-21 17:00:00

You are right the cursor in the module does the trick, nice!


cperivol
2022-1-21 17:01:20

But still I find it surprising too


james275
2022-1-21 17:11:19

I meant the === and the curly braces.


soegaard2
2022-1-21 17:11:51

Ah! I think Greg is partly joking :slightly_smiling_face:


james275
2022-1-21 17:12:16

Makes sense.


soegaard2
2022-1-21 17:12:45

I am not 100% sure…


capfredf
2022-1-21 17:28:23

Thanks for the information


samth
2022-1-21 18:43:02

Probably it’s already been required


capfredf
2022-1-21 20:40:28

@alexharsanyi I am running raco test -p plot-test , and I am getting a lot of test failures like: GNATS#13620: stacked-histogram loops when given an empty list of labels > gnats13620-contour-intervals FAILURE name: fail location: /home/capfredf/code/racket-extra-pkgs/plot/plot-test/plot/tests/helpers.rkt:210:4 params: '() message: "draw steps not the same, new set written to /home/capfredf/code/racket-extra-pkgs/plot/plot-test/plot/tests/PRs/./test-data/new-gnats13620-ci.dat" -------------------- -------------------- GNATS#13620: stacked-histogram loops when given an empty list of labels > gnats13620-contour-intervals3d FAILURE name: fail location: /home/capfredf/code/racket-extra-pkgs/plot/plot-test/plot/tests/helpers.rkt:254:4 params: '() message: "draw steps not the same, new set written to /home/capfredf/code/racket-extra-pkgs/plot/plot-test/plot/tests/PRs/./test-data/new-gnats13620-ci3d.dat" -------------------- I haven’t made changes to plot-test. I am testing changes to rackunit. The racket I’m using was built from source (f856aa). Am I missing anything? Do you have any ideas why those tests failed?


greg
2022-1-21 21:09:20

Ah sorry I was trying satirize people complaining about “all the parentheses” and flip that around. :smile:


greg
2022-1-21 21:10:11

Although === is genuinely hilarious; JavaScript, the good equality operator. :wink:


alexharsanyi
2022-1-21 21:55:14

This message indicates that the drawing of the plot has changed. There were some recent changes to the draw library, which means that the latest plot package tests only pass with a recent snapshot build of Racket, but not with 8.3. There is a recent commit by Alexis King about this.


capfredf
2022-1-21 22:03:01

I didn’t make myself clear. I am using 8.4.0.3


alexharsanyi
2022-1-21 22:04:32

What I can suggest is to check the difference between draw steps to determine what might be wrong. You should have a new set of .dat files generated as part of running the tests. and you can use the the utility functions in the plot test to read them. They are gzip compressed sexp files.


capfredf
2022-1-21 22:06:01

I see. But anyway, thanks for your confirmation. it seems like those errors are not caused by the changed rackunit. (I ran those tests with the unchanged rackunit and those errors remained)


alexharsanyi
2022-1-21 22:09:46

Those tests are meant to catch the situation when the plots would change in a visible way. They are more likely to fail for changes to the plot package or changes to the draw package. Of course the tests themselves might have bugs…


samth
2022-1-22 02:46:19

Another possibility is font differences


alexharsanyi
2022-1-22 06:13:36

The plot tests will account for font differences and should not fail on different platforms… unless there’s a bug in that code as well