niko
2021-10-9 09:54:49

@mflatt thanks! I’ll give that a try. I’ve been using xvfb-run with some success; the main use I have for the GUI is visualizing traces, but now that I found apply-reduction-relation*, I think even that is less useful.


niko
2021-10-9 09:55:13

Is there a way to write a unit test that compares two values and prints a nice diff (and fails) if they are different?


niko
2021-10-9 09:55:26

Basically I have an “expected value” and an “actual value”


niko
2021-10-9 09:55:44

I guess that’s probably the most basic case, I realize now :smiley: let me see if I can find the docs on unit tests in racket…


ben.knoble
2021-10-9 11:13:30

I think it’s the rackunit library, and check-equal/test-equal


spdegabrielle
2021-10-9 11:30:45

What is happening here?


joel
2021-10-9 13:03:47

I don’t think rackunit does diffs though. On failure it will just print the entire expected & actual values


dvanhorn
2021-10-9 13:22:30

If you have your own function to compute the diff, you use the message parameter to show it. Something like this… #lang racket (require rackunit) (define-syntax-rule (check-equal?/d actual expected diff) (check-equal? actual expected (diff actual expected))) (check-equal?/d 5 4 -)


dvanhorn
2021-10-9 13:22:44

This would show: -------------------- . FAILURE name: check-equal? location: unsaved-editor:13:0 message: 1 actual: 5 expected: 4 --------------------


mikiawm
2021-10-9 14:18:22

Hi, How can I format racket code in emacs racket-mode?


soegaard2
2021-10-9 14:22:03

soegaard2
2021-10-9 14:22:55

I have an “indent the whole buffer” function in my .emacs:



soegaard2
2021-10-9 14:24:02

I have bound the command to cmd-i: (define-key racket-mode-map (kbd "s-i") #'my-racket-indent-whole-buffer)


soegaard2
2021-10-9 14:24:17

(line 185)


greg
2021-10-9 14:26:09

@mikiawm You can use the usual indent-region on whatever region you have selected.

@soegaard2 defined a small command to select the whole buffer (like doing the mark-whole-buffer command) first, so it indents the whole buffer.


greg
2021-10-9 14:26:44

There is also prog-indent-sexp, which will indent just the s-expression following point.


greg
2021-10-9 14:27:20

These are all commands that work generally, e.g. in modes for other programming languages, in Emacs. (Although the indent-sexp flavor only works for lisps, of course. :))


greg
2021-10-9 14:28:16

That’s why I wrote “the usual” command up above. Not implying you should already know it. I just mean that, once you learn it, it will work generally, which is nice.


greg
2021-10-9 14:29:22

In fact @soegaard2’s indent-whole-buffer command will work in other prog modes, too.


soegaard2
2021-10-9 14:30:00

I think there are some non-Emacs users that decide to try out racket-mode. It might be worth mentioning indent-region and friends in the racket-mode documentation - even though it isn’t part of racket-mode per se.


greg
2021-10-9 14:31:38

I’ve also used the sexp-diff package to show diffs for e.g. complicated x-expressions. But I don’t recall exactly how I used it with check-equal?. I think it’s somewhere in the code for my markdown pkg?


greg
2021-10-9 14:32:38

It was long ago, so, also I probably didn’t have a spiffy way of integrating it into rackunit or with a special check function or macro. You could probably improve.


soegaard2
2021-10-9 17:08:14

Should Slack be listed here?


sorawee
2021-10-9 17:16:09

There are two tabs of “Community”. The first one doesn’t have Slack, Discord, IRC. The second one does


soegaard2
2021-10-9 17:18:15

I didn’t scroll that far. I saw “Vibrant Community” and thought that was it.


dvanhorn
2021-10-9 17:29:48

Is it possible to control the width of results displayed in scribble examples? I often have examples whose results are way too wide for the page.


sorawee
2021-10-9 17:34:50

IIUC, Scribble enters a newline when the source code does, so it should be fixable by adjusting the source code


soegaard2
2021-10-9 17:39:08

Is it the result of an evaluation, that is too wide?

If so, you can adjust the parameters used by current-print. (assuming you are using the examples for to produce the examples).

https://docs.racket-lang.org/scribble/eval.html#%28form._%28%28lib._scribble%2Fexample..rkt%29._examples%29%29


sorawee
2021-10-9 17:41:30

Ohhh, I missed the word “result”


soegaard2
2021-10-9 17:42:09

I did too at first (think the result was what was displayed).


spdegabrielle
2021-10-9 17:42:46

Matthias is pretty responsive to PR’s


hazel
2021-10-9 18:19:20

how do I deal with a unit signature where rename is one of the defined functions? in particular, I’m stuck with this unit signature: (define-signature val^ ([collapse-W^ : (W^ → W)] [collapse-W^-by-arities : (W^ → (Immutable-HashTable Natural W))] #;[V/ : (S → V → V)] [W⊔ : (W W → W)] [V⊔ : (V^ V^ → V^)] [V⊔₁ : (V V^ → V^)] [Ctx-with-site : (Ctx ℓ → Ctx)] [Ctx-with-origin : (Ctx ℓ → Ctx)] [Ctx-flip : (Ctx → Ctx)] [C-flat? : (V Σ → Boolean)] [C^-flat? : (V^ Σ → Boolean)] [arity : (V → (Option Arity))] [guard-arity : (Fn/C → Arity)] [make-renamings : ((U (Listof Symbol) -formals) W (Symbol → Boolean) → Renamings)] [rename : (Renamings → (case-> [T → (Option T)] [(U T -b) → (Option (U T -b))]))] [T-root : (T:@ → (℘ α))] [ac-Ps : (-st-ac (℘ P) → (℘ P))] [merge/compact : (∀ (X) (X X → (Option (Listof X))) X (℘ X) → (℘ X))] [merge/compact₁ : (∀ (X) (X X → (Option X)) X (℘ X) → (℘ X))] [Vect/C-fields : (Vect/C → (Values α ℓ Index))] [St/C-fields : (St/C → (Values α ℓ -𝒾))] [St/C-tag : (St/C → -𝒾)] [Clo-escapes : ((U -formals (Listof Symbol)) E H ℓ → (℘ α))] )) and when trying to (define-values/invoke-unit/infer val@) , I get: main.rkt> (define-values/invoke-unit/infer val@) ; /home/hazel/src/soft-contract/soft-contract/runtime/signatures.rkt:234:4: rename: misuse of unit import and export keyword ; in: rename ; Context (plain; to see better errortrace context, re-run with C-u prefix): unfortunately, I can’t just change the name of the function, it’s not my code


sorawee
2021-10-9 18:21:18

But can you use rename to rename rename to something else?


sorawee
2021-10-9 18:22:07

(I am not familiar with unit, btw, but this is the first thought I have)


hazel
2021-10-9 18:22:22

lmao I don’t even know what it does


notjack
2021-10-9 19:25:45

ideally rackunit would just do this automatically


joel
2021-10-9 19:27:24

I kind of ran into this with the unit tests I’ve been writing recently for my RSS feed library. Some of the expected values are strings that are quite long, and pinpointing failures can be a bit tough.


niko
2021-10-9 21:23:45

I setup something with sexp-diff that works pretty well


niko
2021-10-9 21:24:16

<https://github.com/dada-lang/dada-model/blob/e4a515d576f9e9a9549df9512eaa20922ae021db/racket/dada.rkt#L126-L131|this is the code>, if you’re curious


dvanhorn
2021-10-10 00:03:52

Thanks, yes, I’m using examples and the results are too wide — so I guess what I’m asking is is there a parameter that influences the width print uses?


dan
2021-10-10 00:18:45

Does this work in untyped racket? Ie trying to define-values/invoke-unit from a signature containing rename?


hazel
2021-10-10 00:19:54

it somehow works from Typed Racket, too — somehow, this code actually does run, it just errors when I try to invoke it myself, and I can’t figure out for the life of me what it’s doing


dan
2021-10-10 00:23:37

So it works when you try to invoke inside a module, but not from the repl?

Signatures can sort of inherit from others so rename there allows renaming elements from “parent” signatures. And typically when implementing/invoking a unit you can choose to rename elements from import/export signatures, so it sort of makes sense to me how this can go wrong, but I haven’t looked at the implementation in a long time …