# Does glob ever return strings? If not, should we update the docs?

**URL:** <https://racket.discourse.group/t/does-glob-ever-return-strings-if-not-should-we-update-the-docs/3049>\
**Category:** General\
**Created:** [July 24, 2024, 8:14pm UTC](https://racket.discourse.group/t/does-glob-ever-return-strings-if-not-should-we-update-the-docs/3049 "2024-07-24T20:14:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![benknoble](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/benknoble/32/16_2.png) [@benknoble](https://racket.discourse.group/u/benknoble)\
**Post date:** [July 24, 2024, 8:14pm UTC](https://racket.discourse.group/t/does-glob-ever-return-strings-if-not-should-we-update-the-docs/3049/1 "2024-07-24T20:14:50Z")

</div>

I've only been able to observe `glob` from `file/glob` returning paths, but it is documented as returning a `(listof path-string?)`. Are there actually cases where it returns strings? A few quick experiments indicate it only returns path values (which is fine by me, since I'd like to sort the results and use them as paths, so having a uniform result type makes that easier). I couldn't follow the underlying code with just a few minutes of study, so I figured I'd ask here instead.

---

<div class="post-metadata">

**Author:** ![greghendershott](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/greghendershott/32/98_2.png) [@greghendershott](https://racket.discourse.group/u/greghendershott)\
**Post date:** [July 25, 2024, 1:38pm UTC](https://racket.discourse.group/t/does-glob-ever-return-strings-if-not-should-we-update-the-docs/3049/2 "2024-07-25T13:38:44Z")

</div>

Although I didn't study it exhaustively, and could easily be wrong, I think it uses values coming from [`in-directory`](https://docs.racket-lang.org/reference/sequences.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._in-directory%29%29), whose contract says `path-string?`. So that's probably why `file/glob` should also use `path-string?`.

However:

Glancing at `in-directory` source, it uses a locally defined function `dir-list`:

```scheme
  (define (dir-list full-d d acc)
    (for/fold ([acc acc]) ([f (in-list (reverse (sort (directory-list full-d) path<?)))])
	      (cons (build-path d f) acc)))

```

Those values come from a `directory-list` function defined `#%kernel`; I can't quickly view its definition. But notice how `dir-list` is `sort`-ing the values with `path<?`. That would fail unless all `path?` items -- can't be `path-string?`.

So: It seems to me that if the contract and doc for `file/glob` ought to change, then so should those for `in-directory`. That latter's doc already talks about sorting using `path<?`, so it kind of implies the contract could be `path?` instead of `path-string?`.

Also: It's not entirely clear to me, but I think the relevant contract might be `path-for-some-system?` -- not `path?` ???

* * *

p.s. I've always found `path-string?` confusing. It actually behaves like "path-or-path-string?":

```scheme
  (define-values (path-string?)
    (lambda (s)
      (or (path? s) 
          (and (string? s)
               (or (relative-path? s)
                   (absolute-path? s))))))

```

Clean sheet of paper, it would probably be clearer to have all of:

- `path?` i.e. a path struct, not a string
- `path-string?` new meaning: _string_ that is an absolute or relative path
- `path-or-path-string?` i.e. what today's `path-string?` means
- The little conversions that everyone seems to write: `path-or-path-string->path` and `path-or-path-string->path-string?`.

But naming is hard and backward compatible naming is harder.

---

<div class="post-metadata">

**Author:** ![benknoble](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/benknoble/32/16_2.png) [@benknoble](https://racket.discourse.group/u/benknoble)\
**Post date:** [July 27, 2024, 2:01pm UTC](https://racket.discourse.group/t/does-glob-ever-return-strings-if-not-should-we-update-the-docs/3049/3 "2024-07-27T14:01:01Z")

</div>

@greghendershott In [glob: clarify that only path values are returned by benknoble · Pull Request #5047 · racket/racket · GitHub](https://github.com/racket/racket/pull/5047/commits/9e99d0b14e9b233fcafe3029c3fc98d09731fd9f) I've added you as a coauthor for your help using the author information that seems most recently associated with you, but GitHub doesn't connect it to your GitHub account. Let me know if I should try something different.

---

<div class="post-metadata">

**Author:** ![greghendershott](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/greghendershott/32/98_2.png) [@greghendershott](https://racket.discourse.group/u/greghendershott)\
**Post date:** [July 27, 2024, 2:09pm UTC](https://racket.discourse.group/t/does-glob-ever-return-strings-if-not-should-we-update-the-docs/3049/4 "2024-07-27T14:09:37Z")

</div>

1. Thank you but no need to co-author me on the commit.

2. Request: Could you please delete the portion of the post above which shows my email addresses?

(I realize anyone can get these using git tools/repos. But I don't like leaving these around on web sites like this, where web scrapers can slurp for spam. Web sites like GitHub and [pkgs.racket-lang.com](http://pkgs.racket-lang.com) obscure email addresses, so same spirit please?)

(And no worries. I'm not upset. Just my preference. Thanks!!)

---

<div class="post-metadata">

**Author:** ![benknoble](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/benknoble/32/16_2.png) [@benknoble](https://racket.discourse.group/u/benknoble)\
**Post date:** [July 27, 2024, 2:24pm UTC](https://racket.discourse.group/t/does-glob-ever-return-strings-if-not-should-we-update-the-docs/3049/5 "2024-07-27T14:24:27Z")

</div>

Done! (Turns out it was a typo, anyway, which I’ll also fix elsewhere when I get back to my computer.)
