Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

carpentry-org/using

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

using

Context managers for Carp. An experiment.

Installation

You can include using in your project like this:

(load "git@github.com:carpentry-org/using@0.0.3")

Usage

using relies on the interface close, which will take in a resource of some kind, clean it up, and return the result of the expression.

If that function is defined, you can do things like that:

(println*
  &(using (Result.unsafe-from-success (File.open "example")) f
    &(File.read-all &f)))

The file that was opened will be automatically closed once the scope is exited.

So, to reiterate: all you need to work with using is to have a function close that works on your type! It’s like manual borrow-checking for resource things! Nifty, eh?

And if you need to support multiple forms, using-do is your friend!


Have fun!

Releases

Packages

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.