I was trying to require a file that is inside a directory via a relative path. Surprisingly, this did not work, but resulted in an error. For example, I have the file dir.dot/x.rkt (the content does not matter). When typing (require "dir.dot/x.rkt"), I get the following error:
string:1:9: require: bad module-path string
at: "dir.dot/x.rkt"
in: (require "dir.dot/x.rkt")
[,bt for context]
If I change into the directory and require the file it works. I would not have expected this behavior; is there a reason for this?
Yes, that seems to do the trick; thank you. I'm a bit surprised that this other option exists as I don't really understand why the two cases are treated differently. (And the docs only mention the user expansion.)
The path cannot be empty or contain a leading or trailing slash, path elements before than [sic] the last one cannot include a file suffix (i.e., a . in an element other than . or ..), and the only allowed characters are ASCII letters, ASCII digits, -, +, _, ., /, and % (emphasis mine).
Not relevant to the specific question you're asking, but related:
When using relative filepaths, define-runtime-path is a big help. It constructs an absolute path from a relative path starting from the current file so that you don't need to worry about what the current directory is at any given moment:
#lang racket
(require racket/runtime-path)
(define-runtime-path here ".") ;; 'here' is relative to this file
(println (build-path "." "foo"))
(println (build-path here "foo"))
This is speculation rather than an answer, but I wouldn't be surprised to discover that this could be a problem (or perhaps "bad interaction") with the way that file extensions are handled on certain platforms, possibly including Windows.
I'd be slightly leery of using define-runtime-path to require racket files; it seems probable to me that you'd be disrupting the ability of packages to overlap on collections.