From dde0f83e989fadb4b4f76707f08f56570e491660 Mon Sep 17 00:00:00 2001 From: "carpentry-heartbeat[bot]" Date: Tue, 18 Aug 2026 01:20:28 +0200 Subject: [PATCH] fix(examples): make the file example compile and run honestly `File.read` dispatches through the generic `read-from-file` interface, so `(File.read &f 2)` left the Result's success type unresolved and codegen died with `I found an unresolved generic type (Fn [(Ref (Result r54 String) t59)] String) for the expression str`. Annotate the call the way the file library's own docs and tests do. The example also opened `example` with the default `a+` mode, so each run appended another "hi" and the read reported the *first* run's write, not this one's; the file grew by two bytes forever. `w+` truncates, so a run shows what it claims to show regardless of what earlier runs left behind. Pin the dependency to file@0.3.0. Every other dependency load across the org pins a release; `@master` can change what the example means without a commit here. The README's `using` snippet fails to compile for the same reason, and also took a reference to a temporary Result that dies before it is printed. Both snippets were verified by running them. --- README.md | 2 +- examples/file.carp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2688c76..0978c8f 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ If that function is defined, you can do things like that: ```clojure (println* &(using (Result.unsafe-from-success (File.open "example")) f - &(File.read-all &f))) + (the (Result String String) (File.read-all &f)))) ``` The file that was opened will be automatically closed once the scope is exited. diff --git a/examples/file.carp b/examples/file.carp index b1c1ae2..847ddde 100644 --- a/examples/file.carp +++ b/examples/file.carp @@ -1,11 +1,11 @@ (load "main.carp") -(load "git@github.com:carpentry-org/file.git@master") +(load "git@github.com:carpentry-org/file.git@0.3.0") (implements close File.close) (defn main [] (println* - &(using-do (Result.unsafe-from-success (File.open "example")) f + &(using-do (Result.unsafe-from-success (File.open-with "example" "w+")) f (ignore (File.write &f "hi")) (File.rewind &f) - (File.read &f 2)))) + (the (Result String String) (File.read &f 2)))))