Task

Write a program that will list everything in the current folder,   similar to:

   the Unix utility   “ls”   [1]       or 
   the Windows terminal command   “DIR” 


The output must be sorted, but printing extended details and producing multi-column output is not required.



Example output
For the list of paths:

/foo/bar
/foo/bar/1
/foo/bar/2
/foo/bar/a
/foo/bar/b



When the program is executed in   `/foo`,   it should print:

bar

and when the program is executed in   `/foo/bar`,   it should print:

1
2
a
b



#lang racket/base
 
;; Racket's `directory-list' produces a sorted list of files
(define (ls) (for-each displayln (directory-list)))
 
;; Code to run when this file is running directly
(module+ main
  (ls))
 
(module+ test
  (require tests/eli-tester racket/port racket/file)
  (define (make-directory-tree)
    (make-directory* "foo/bar")
    (for ([f '("1" "2" "a" "b")])
      (with-output-to-file (format "foo/bar/~a"f) #:exists 'replace newline)))
  (make-directory-tree)
  (define (ls/str dir)
    (parameterize ([current-directory dir]) (with-output-to-string ls)))
  (test (ls/str "foo") => "bar\n"
        (ls/str "foo/bar") => "1\n2\na\nb\n"))