classracket

Error trying to run example code for a Racket class definition


I am trying to run this code from the documentation that defines a class:

#lang racket/class

(define book-class%
  (class object%
    (field (pages 5))
    (define/public (letters)
      (* pages 500))
    (super-new)))

It gets an error when I try and run it:

Welcome to DrRacket, version 8.15 [cs]. Language: Determine language from source; memory limit: 128 MB. standard-module-name-resolver: collection not found for module path: racket/class/lang/reader
collection: "racket/class/lang" in collection directories:
/home/bert/snap/racket/26/.local/share/racket/8.15/collects
/snap/racket/current/usr/share/racket/collects/ ... [166 additional linked and package directories] no package suggestions are available .[update catalog]

Interactions disabled.

I originally installed from a snap command , but then installed it from the shell script that comes from their website due to the fact that I couldn't get the Help->Racket Documentation to display under the original install. But after this error I went and tried to delete the shell install (which goes in your $HOME directory) and my installation is now from the Ubuntu Software application.

I clicked on [update catalog] in the above error message and it checks for updates at pkgs.racket-lang.org but the error remains after the update/check.


Solution

  • I just tested this on the OneCompiler online Racket compiler. Your code gives me the same error as you report. But if I change the first line to #lang racket everything appears to work. So I'd try changing that first line.