Create library for exercises in Concrete Abstractions, Chapter 2, Recursion

I would like to create a library with my own factorial, in order to call it when I need it without writing again or copying again the code.

How should I save it, and how do I have to import it where I will need it (compiler lines such import / provide)?

  1. Save as factorial.rkt.

  2. Add (provide factorial)

  3. Use (require factorial)

(But I notice that there’s no language specified. Are you using the Teaching languages?)

1 Like

The (require factorial) would only work if it's main.rkt in a factorial collection. If it's not part of a collection, (require "factorial.rkt") works in the same directory. More at https://docs.racket-lang.org/guide/module-paths.html (Guide).

1 Like

I would like to start putting the file providing the factorial in the same folder where the program that requires has its place.

Here is the result

image
Both files saved as indicated. Error persists.

(require “factorial.rkt”)

1 Like