
@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.

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

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

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…

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

What is happening here?

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

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 -)

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

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


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


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

(line 185)

@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.

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

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. :))

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.

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

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.

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?

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.

Should Slack be listed here?

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

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

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.

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

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).

Ohhh, I missed the word “result”

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

Matthias is pretty responsive to PR’s

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

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

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

lmao I don’t even know what it does

ideally rackunit would just do this automatically

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.

I setup something with sexp-diff that works pretty well

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

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?

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

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

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 …