Path function appropriate for

I can imagine defining file paths something like this:
(define file1
(string-append
(path->string (expand-user-path))
()
"file1"))

  1. What is recommended for ?
  2. My current racket installation has:
    (string-append
    (path->string (expand-user-path))
    ".plt-scheme/4.2.1/collects/DG/"
    "<...>"
    "file1"))
    To make use of should I:
    a) move my dirs of modules here: ?
    OR
    b) re-install Racket & place my dirs of modules here: ?

What are you trying to accomplish? If we know the goal we can give better help.

Here are a couple possibilities and my suggestions, which someone else might have better answers to:

  1. How do I include a module into my code so that I can use its functionality?

Check out 'require':
https://docs.racket-lang.org/guide/module-paths.html
https://docs.racket-lang.org/reference/require.html

Simple examples, see the docs for caveats, exceptions, and additional features:

(require "main.rkt") ; load the file 'main.rkt' which is in the same directory as the current file
(require "../utils/hash.rkt") ; load the file 'hash.rkt' which is up one level then down into the 'utils' directory
(require struct-plus-plus) ; Load the 'struct-plus-plus' module. Racket will figure out where it is

  1. How do I refer to a file from a known location relative to the current file when that file is not a module?

; Assume that current directory is /Users/dstorrs/code

#lang racket
(require racket/runtime-path)
(define here ".")
(define-runtime-path this-dir ".")
(define without-runtime-path (build-path here 'up "projects" "main.rkt"))
(define with-runtime-path (build-path this-dir 'up "projects" "main.rkt"))
(displayln (~a "Using define, you get: " (~v without-runtime-path)))
(displayln (~a "Using define-runtime-path, you get: " (~v with-runtime-path)))
(path->string with-runtime-path)
(build-path this-dir "../foo/bar/") ; you can build paths in one chunk too

Output:
Using define, you get: #<path:./../projects/main.rkt>
Using define-runtime-path, you get: #<path:/Users/dstorrs/code/./../projects/main.rkt>
"/Users/dstorrs/code/./../projects/main.rkt"
#<path:/Users/dstorrs/code/./../foo/bar/>

1 Like

Maybe I just need to create a package with the path: ".plt-scheme/4.2.1/collects/DG/"
Then the path definition would be like this:
(define file1 (string-append (path->string (expand-user-path)) "file1"))

No wonder there is difficulty in understanding what I have written since Discourse is removing chunks of it.
Here is another try:
Maybe I just need to create a package with the path: ".plt-scheme/4.2.1/collects/DG/"
Then the path definition would be something like this:
(define file1 (string-append (path->string (expand-user-path)) pkg "file1"))

I assume that if I create a package then there is some function, maybe just the name of the package, that will return the path of the package. That is all that I am after.
Thanks

It sounds like you want to refer to files that are in a known location with respect to the source code. So, for instance, I might have a file called "email-processor.rkt" with a file called "email-rules.csv" that's in the same directory. In this case, I would echo Ryan Culpepper's suggestion that you use the runtime-path functions. here's a snippet of code that illustrates what I mean:

#lang racket

(require racket/runtime-path)

(define-runtime-path here ".")

(file->string (build-path here "email-rules.csv"))

Again, it would help if you would tell us what you are trying to achieve. What is the purpose of this code? Are you loading configuration data, calling out to a shell script, or what?

If you want to find the path to an installed module, then install the fc package: raco fc: Finding Collections

$ raco pkg install raco-find-collection

Once it's installed, you can do this to find the path of a module:

$ raco fc struct-plus-plus
/Users/dstorrs/projects/struct-plus-plus

$ raco fc module-i-do-not-have
raco-find-collection: could not find the collection path "module-i-do-not-have"

2 Likes

Currently, my system returns these:
(require setup/dirs)
(find-user-collects-dir) ;=> #path:/home/don/.racket/8.1/collects
; but I want it to return: #.plt-scheme/4.2.1/collects>
(find-collects-dir) ;=> #path:/home/don/racket/collects/
; but I want it to return: #.plt-scheme/4.2.1/collects>

(define-runtime-path here ".")
(file->string (build-path here "email-rules.csv"))

I believe I should use:
(collection-file-path "alpha-bool.ss" "DG" "all") ;returns:
#path:/home/don/.plt-scheme/4.2.1/collects/DG/all/alpha-bool.ss

instead of using:
(define-runtime-path here "/home/don/.plt-scheme/4.2.1/collects/DG/all/")
(file->string (build-path here "email-rules.csv"))

However, before I start using collection-file-path, I want to be confident in my ability to manage the collects paths so that I only have one available.
Since my system currently has collect paths that I am not using, I'd like to remove them.
Am I correct in thinking that the only way to remove them is to uninstall Racket installations that I am not using?

I was previously looking for a function that returned only:
#path:/home/don/.plt-scheme/4.2.1/collects

(get-collects-search-dirs) returns multiple paths associated with multiple installations:
'(#path:/home/don/.racket/8.1/collects #path:/home/don/racket/collects/ #path:/home/don/.plt-scheme/4.2.1/collects)
I'd prefer that this or a similar function returned the one path:
'(#path:/home/don/.plt-scheme/4.2.1/collects)
Does this mean that I'd have to uninstall racket installations that are associated with the other paths?
Then (get-collects-search-dirs) would not list the unwanted collects paths?
(I have never made use of the collects paths that I want to eliminate.)

I am using racket 8.1 so the question arises:
How do I configure racket 8.1 to use a collects path that is not the default:
#path:/home/don/.racket/8.1/collects

Wow. I have PLT Scheme v4.2.1 on my machine but it's from 2009, which I suppose is the first time I tried to pick a Lisp. You've been doing this a while, eh?

It sounds like you want to do two things:

  1. Specify where you want collections to load from
  2. Eliminate all loading options aside from the one you specify

For #1 you can set the environment variable "PLTCOLLECTS" 18.2 Libraries and Collections

For #2 I don't know.