Opening Pollen source in DrRacket causes no-arg call to root
#268
Closed
opened 3 years ago by otherjoel
·
8 comments
Loading…
Reference in New Issue
There is no content yet.
Delete Branch '%!s(<nil>)'
Deleting a branch is permanent. It CANNOT be undone. Continue?
Using Racket 8.4.0.8 on macOS/AArch64, in a folder with this
pollen.rkt
:—and another file
test.html.pm
:Simply opening
test.html.pm
in DrRacket will cause the REPL to open and display the results of an apparent call toroot
with no arguments:If the definition of
root
for the current project assumes that it is called with at least one element, then simply opening a Pollen source instantly gets you a REPL with an error and “Interactions disabled”. If you do actually “Run” the file, the REPL displays the expected result.I could be wrong (I’m starting to revisit Pollen projects after a few months away) but I am pretty sure that this is new behavior. I don't recall ever having to build checks for “called with no elements” into any of my Pollen projects before.
This sounds like a new (Dr)Racket bug related to the auto-running behavior. I’m on 8.3.0.7. The Pollen source does not auto-run when opened, and when I explicitly hit Run I get the right result:
When opening a file in DrRacket, DrRacket will runs a program that consists only of the #lang line (so in this case, the program that has only
#lang pollen
). Could that explain this behavior?The reason DrRacket does that is to try to get a reasonable initial namespace for the interactions window. The hypothesis I had (apparently wrong!) is that an "empty" program wouldn't have any particular effects but would result in a reasonable set of bindings in a namespace. If there's some other heuristic I could employ to try to get a reasonable initial setup for that first interactions window, I'm game to try it.
That might even still work in this case, if it were possible to run the empty program in such a way as to ensure that an upward search from
current-directory
would never find apollen.rkt
module.Is that something that can be done from within pollen? I'm not sure that that would be generic enough to put into drracket (since it would then apply to all languages).
Pollen is a popular Racket package. Like other popular packages, it brings new users into Racket. If the Racket maintainers are going to ship compatibility-breaking changes (especially in a minor release) without testing against popular Racket packages, it is a strong negative signal to the users and maintainers of these packages.
Beyond the behavior observed here, it should be apparent why “run an empty source file on startup” is a bad idea:
an empty source file may raise an error because it’s syntactically invalid (e.g.,
web-server/insta
)an empty source file may still incur expensive startup costs (e.g., open a database connection, load disk cache)
an empty source file may have irreversible or one-shot side effects (e.g., run is logged to disk)
more broadly, the
#lang
line triggers execution of another source file, which can contain anything, so this new policy incurs the risk of unbounded side effects, including failure to terminate.FWIW as a UI matter, this is not behavior anyone reasonably expects when opening any source file in any code editor.
Still, I am always willing to investigate bona fide bugs. If Pollen is violating documented Racket behavior, guidelines, norms, etc. — please post a link. The parts of Pollen that cooperate with DrRacket have not been changed in at least four years. That doesn’t mean they’re correct, but they are stable.
If DrRacket seeks certain information from a
#lang
, one might’ve supposed that the correct approach is for DrRacket to query the#lang
using the affordance that exists for exactly that purpose: theget-info
function (with a key likedrracket:whatever-you-want
).These are good points. Thank you.
Thanks to both of you for looking at this. It is at least clear to me now that this is not a Pollen issue!
That heuristic seems somewhat worrying in other cases as well. For example, writing this module with
#lang s-exp "wrap.rkt"
would mean opening it in DrRacket would run the whole program.