Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use a library as a #lang?

Tags:

racket

I have a few files that start like this:

#lang racket/base
(require "my-library.rkt")

I would be very happy if I could start my files with:

#lang my-library

Is it possible to use a library as a #lang? What changes would I need to make to my-library.rkt?

like image 467
Ben Greenman Avatar asked Mar 09 '26 15:03

Ben Greenman


1 Answers

If your library isn't going to do anything "lang like", and you merely want to eliminate the require? You could:

  1. Change my-library.rkt as Chris describes: Add (provide (all-from-out racket/base)). But don't bother creating any my-library/lang/reader.rkt file.

  2. To use it: #lang s-exp "my-library.rkt". Note the s-exp, so technically this doesn't answer your question exactly. :)

Keep in mind that you can shadow bindings in my-library.rkt now that it's being used as a lang instead of being required.

like image 193
Greg Hendershott Avatar answered Mar 13 '26 17:03

Greg Hendershott



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!