# Path function appropriate for

**URL:** <https://racket.discourse.group/t/path-function-appropriate-for/246>\
**Category:** Questions & Answers\
**Created:** [November 24, 2021, 4:22pm UTC](https://racket.discourse.group/t/path-function-appropriate-for/246 "2021-11-24T16:22:51Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Don](https://avatars.discourse-cdn.com/v4/letter/d/ed655f/32.png) [@Don](https://racket.discourse.group/u/Don)\
**Post date:** [November 24, 2021, 4:22pm UTC](https://racket.discourse.group/t/path-function-appropriate-for/246/1 "2021-11-24T16:22:51Z")

</div>

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: ?

---

<div class="post-metadata">

**Author:** ![dstorrs](https://avatars.discourse-cdn.com/v4/letter/d/898d66/32.png) [@dstorrs](https://racket.discourse.group/u/dstorrs)\
**Post date:** [November 24, 2021, 5:01pm UTC](https://racket.discourse.group/t/path-function-appropriate-for/246/2 "2021-11-24T17:01:37Z")

</div>

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/guide/module-paths.html)  
[https://docs.racket-lang.org/reference/require.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/\>

---

<div class="post-metadata">

**Author:** ![Don](https://avatars.discourse-cdn.com/v4/letter/d/ed655f/32.png) [@Don](https://racket.discourse.group/u/Don)\
**Post date:** [November 24, 2021, 6:41pm UTC](https://racket.discourse.group/t/path-function-appropriate-for/246/3 "2021-11-24T18:41:12Z")

</div>

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"))

---

<div class="post-metadata">

**Author:** ![Don](https://avatars.discourse-cdn.com/v4/letter/d/ed655f/32.png) [@Don](https://racket.discourse.group/u/Don)\
**Post date:** [November 24, 2021, 6:46pm UTC](https://racket.discourse.group/t/path-function-appropriate-for/246/4 "2021-11-24T18:46:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jbclements](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/jbclements/32/11_2.png) [@jbclements](https://racket.discourse.group/u/jbclements)\
**Post date:** [November 24, 2021, 7:04pm UTC](https://racket.discourse.group/t/path-function-appropriate-for/246/5 "2021-11-24T19:04:42Z")

</div>

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"))

```

---

<div class="post-metadata">

**Author:** ![dstorrs](https://avatars.discourse-cdn.com/v4/letter/d/898d66/32.png) [@dstorrs](https://racket.discourse.group/u/dstorrs)\
**Post date:** [November 24, 2021, 7:34pm UTC](https://racket.discourse.group/t/path-function-appropriate-for/246/6 "2021-11-24T19:34:29Z")

</div>

> [@Don](#):
>
> 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

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](https://docs.racket-lang.org/raco-fc/index.html)

> $ 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"

---

<div class="post-metadata">

**Author:** ![Don](https://avatars.discourse-cdn.com/v4/letter/d/ed655f/32.png) [@Don](https://racket.discourse.group/u/Don)\
**Post date:** [November 24, 2021, 9:25pm UTC](https://racket.discourse.group/t/path-function-appropriate-for/246/7 "2021-11-24T21:25:24Z")

</div>

## 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

---

<div class="post-metadata">

**Author:** ![dstorrs](https://avatars.discourse-cdn.com/v4/letter/d/898d66/32.png) [@dstorrs](https://racket.discourse.group/u/dstorrs)\
**Post date:** [November 24, 2021, 10:30pm UTC](https://racket.discourse.group/t/path-function-appropriate-for/246/8 "2021-11-24T22:30:54Z")

</div>

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&nbsp;Libraries and Collections](https://docs.racket-lang.org/reference/collects.html)

For #2 I don't know.
