
— Racket Stories
Hi All,
Racket Stories has close to 400 links to Racket related stuff.
Help me get to 500.
Submit blog posts, libraries, one off Racket hacks, …
New or old doesn’t matter - if it is interesting to you, it’s probably interesting to others as well.
Don’t forget to vote on the stories.
/soegaard

Is there a way (command line tool?) to find out about unused require
s and/or provide
s of identifiers that aren’t anymore in the module?

By the way, I didn’t even know about define-syntax-parse-rule
, even the whole https://docs.racket-lang.org/syntax/index.html document(s). The documentation on Racket macros is kind of overwhelming, so much that it’s sometimes difficult to know which APIs to use (especially as a beginner in macros). But I guess it’ll become clearer when I’m more used to macros and writing a few.

DrRacket and racket-mode can detect them - but I don’t know of a command line tool.

I thought this was also exposed as a raco
command.

Maybe it is?

raco check-requires

I had to look it up.

It doesn’t check “unused provides”, though. To do that you’d need some inter-file database. Well, for provides at the top file module level.

(Weird timing, I’ve been experimenting with making such a database. But that’s WIP.)

@sschwarzer ^

It’s working \o/
#lang racket
(require define2)
(define (foo bar [baz 'b] #:fizz fizz #:buzz [buzz #t])
#t)
; Examples of syntax errors:
(foo)
#;(foo 'a 'b 'c #:fizz 'f)
#;(foo 'a)
#;(foo 'a #:fizz 'f #:beurre 'b)
Compile without running: $ raco make define2-example.rkt
And get nice syntax errors at compile time: foo: missing mandatory positional arguments;
header: (foo bar (baz) #:fizz (#:buzz))
at: (foo)
in: (foo)
foo: too many positional arguments;
header: (foo bar (baz) #:fizz (#:buzz))
at: (foo 'a 'b 'c #:fizz 'f)
in: (foo 'a 'b 'c #:fizz 'f)
foo: missing keywords;
header: (foo bar (baz) #:fizz (#:buzz))
at: (foo 'a)
in: (foo 'a)
foo: unknown keyword;
header: (foo bar (baz) #:fizz (#:buzz))
at: #:beurre
in: (foo 'a #:fizz 'f #:beurre 'b)
@notjack

Yeah ideally the guide should be an intro, and it should link out to the appropriate parts of the references.

It’s even nicer in DrRacket of course (again at compile time, no need to run the program)

Does it support the curry notation?

ah, not yet, good point. It supports rest arguments though

hm actually, I need to test (later), but it should support the curry notation to some extent (at least the first level)

Code is here:https://github.com/Metaxal/define2/blob/syntax-errors/define.rkt#L59 All comments welcome! (note that for now it’s in the syntax-errors
branch)

Yes, it works also in the curried version, but syntax errors are reported only for the first level

this is awesome!!

The docs for my resyntax
package haven’t been updated in a day or two, is the build server taking longer than usual again?

This is really nice! The only thing similar to this I’ve seen is messages to the “optimizer” logger topic — but you have to have a logger window open to notice, and, they’re effectively warnings not errors. So this seems much better!

Dumb question (I may have missed previous discussion): Why doesn’t Racket’s define
already do this?

backward compatibility and increased code size, probably

(it’s backwards incompatible because it causes modules with dead code to stop compiling if the dead code calls functions incorrectly)

I just uploaded https://github.com/sorawee/mixfix, a library that supports mixfix notation, to the package index. Meanwhile, here’s a locally rendered documentation. Any feedback is welcome!

Had to go see the README to get it, but this is awesome! Destructuring let/lambda/define next, anyone?

@ben.knoble have you seen generic-bind
?

No, maybe I will be interested… it’s the one thing I miss from Clojure, honestly.


That’s cool; it’s unfortunate that the syntax is a bit different. In Clojure, the syntax for the destructuring looks exactly like the literal syntax.

It can’t look exactly like the normal syntax in racket, because if it did then (define (foo x) 4)
would be ambiguous (does it mean define a function foo
with a parameter x
that returns 4, or match 4 against the pattern (foo x)
?)

Yeah, I do understand that.

This is really cool!

Anyone knows how to make #:fail-when
in syntax-parse
avoid having both in
and at
when they are the same?

In the Typed Racket REPL, the type of an expression is printed along with the value. Is that done by reifying the type as a runtime value for printing, or is a string representation just constructed statically?

I would guess the latter, because of phase crossing


When I eval
a module, it doesn’t print out the values in the module body. Why is that? What do I need to do to get it to print the values?

You need to require
it, right?

There are terms like “instantiate”, “visit”, etc. I don’t recall which is which, but require
will do those things.

Oh duh. Ugh. So given this: (eval #'(module foo racket/base
(or 1 2 3)))
I then need to require 'foo

Extremely cool (to me) resyntax
thing: the testing framework I wrote for testing refactoring changes now automatically checks that the stdout and stderr of refactored programs doesn’t change

It would be really great if the build server has a status page that displays its schedule or something indicating that it’s alive.
If the server is just being slow, that’s totally fine for me. But if it errors, that should be reported. The problem is that I don’t know how to distinguish the two.
(And I feel bad every time I ping Matthew and Sam re: “is the server down?” and it turns out that it’s just being slow)