in-directory sorted results

已查看 58 次
跳至第一个未读帖子

evdubs

未读,
2020年8月2日 21:38:192020/8/2
收件人 Racket Users
Hello,

The docs for in-directory state:

> The immediate content of each directory is reported as sorted by path<?, and the content of a subdirectory is reported before subsequent paths within the directory.

However, the docs also show:

> (current-directory (collection-path "info"))
> (for/list ([f (in-directory)])
     f)
'(#<path:main.rkt>
  #<path:compiled>
  #<path:compiled/main_rkt.dep>
  #<path:compiled/main_rkt.zo>)

Isn't this not getting sorted correctly? I am seeing that calls to (in-directory) do not have sorted results, but calls to (in-directory "path") do have sorted results.

Evan

Matthew Flatt

未读,
2020年8月3日 08:28:332020/8/3
收件人 evdubs、Racket Users
At Sun, 2 Aug 2020 18:38:18 -0700 (PDT), evdubs wrote:
> However, the docs also show:
>
> > (current-directory (collection-path "info"))
> > (for/list ([f (in-directory)])
> f)
> '(#<path:main.rkt>
> #<path:compiled>
> #<path:compiled/main_rkt.dep>
> #<path:compiled/main_rkt.zo>)
>
> Isn't this not getting sorted correctly? I am seeing that calls to
> (in-directory) do not have sorted results, but calls to (in-directory
> "path") do have sorted results.

You're right that the documentation's example is incorrect, and I'll
fix that.

Most examples in the documentation are rendered by running them, so the
results can't get out-of-sync like this. Since the `in-directory`
example involves the filesystem, though, the example result is written
out in the documentation source, and it wasn't updated when the sorting
guarantee was added to `in-directory`.

Matthew

evdubs

未读,
2020年8月3日 09:05:552020/8/3
收件人 Racket Users
Sorry, I cherry-picked the doc example as an "easy" example that others might be able to easily observe.

However, please imagine the following filesystem:

/var/tmp/test/1.txt
/var/tmp/test/2.txt
/var/tmp/test/3.txt
/var/tmp/test/4.txt

The following shows these files in order:

> (for/list ([f (in-directory "/var/tmp/test")]) (displayln f))

However, the following does not have the same order:

> (current-directory "/var/tmp/test")
> (for/list ([f (in-directory)]) (displayln f))


Does this help? What is interesting to me is that in-directory can call directory-list (which seems to call sort) or dir-list, which also calls sort and directory-list.

Perhaps I just need to wait for your fix.

Evan

evdubs

未读,
2020年8月6日 23:24:192020/8/6
收件人 Racket Users
I created a PR for a possible fix for this. I am unsure if the (directory-list) implementation in kw-file.rkt needs to be calling sort.

Evan
回复全部
回复作者
转发
0 个新帖子