HTDP2e part 4: 20.3 Refining Functions dir.rkt

34 views
Skip to first unread message

Aron Zvi

unread,
Mar 19, 2020, 6:01:59 AM3/19/20
to Racket Users
Hey guys,

In part 4 section 20.3 Refining Functions I am using (require htdp/dir) and (create-dir DIR-PATH). I get back a Dir instance with name value being a full path symbol of the folder. ie. (make-dir '/Users/SSS/Documents/xyz empty empty). 
This does not seem to be in line with the exercises in the section where it seems that I should be getting back just the folder name.
I am missing something? 




Ben Greenman

unread,
Mar 19, 2020, 10:21:23 AM3/19/20
to Racket Users
Nope, you're supposed to get a dir structure.

When I call create-dir with a full path, I get a struct with a full
path symbol inside. But when I call create-dir with just the folder
name, the struct only contains the folder name. Maybe that explains
the confusion with the exercises?

But! create-dir does not return a Dir.v3 as section 20.3 says. See the
docs for htdp/dir for the correct data definitions:

https://docs.racket-lang.org/teachpack/dir.html

Aron Zvi

unread,
Mar 20, 2020, 2:15:36 AM3/20/20
to Racket Users
Thanks for your reply Ben.

I understand that I am supposed to be getting a Dir instance.
My confusion is indeed regarding the value of the name field of Dir for which I get a (full) path symbol of the directory and not just the folder name as I would expect.

When I run (create-dir "test") and the test folder is in the same folder as my racket racket file (using just the folder name as you suggested), I get the following Dir instance for which the symbol is still the path to the folder from the given root

(make-dir
 'test
 (list
  (make-dir
   'test/a
   (list (make-dir 'test/a/docs '() '()))
   (list (make-file ".DS_Store" 6148 (make-date 2020 3 20 13 7 33) "") (make-file "me.txt" 0 (make-date 2020 3 20 13 1 42) ""))))
 (list (make-file ".DS_Store" 6148 (make-date 2020 3 20 13 7 28) "")))

I am expecting to get this 

(make-dir
 'test
 (list
  (make-dir
   'a
   (list (make-dir 'docs '() '()))
   (list (make-file ".DS_Store" 6148 (make-date 2020 3 20 13 7 33) "") (make-file "me.txt" 0 (make-date 2020 3 20 13 1 42) ""))))
 (list (make-file ".DS_Store" 6148 (make-date 2020 3 20 13 7 28) "")))

Ben Greenman

unread,
Mar 20, 2020, 10:25:44 AM3/20/20
to Aron Zvi, Racket Users
On 3/20/20, Aron Zvi <aro...@gmail.com> wrote:
> Thanks for your reply Ben.
>
> I understand that I am supposed to be getting a Dir instance.
> My confusion is indeed regarding the value of the name field of Dir for
> which I get a (full) path symbol of the directory and not just the folder
> name as I would expect.
>
> When I run (create-dir "test") and the test folder is in the same folder as
>
> my racket racket file (using just the folder name as you suggested), I get
> the following Dir instance for which the symbol is still the path to the
> folder from the given root
>
> (make-dir
> 'test
> (list
> (make-dir
> *'test/a*
> (list (make-dir *'test/a/docs* '() '()))
> (list (make-file ".DS_Store" 6148 (make-date 2020 3 20 13 7 33) "")
> (make-file "me.txt" 0 (make-date 2020 3 20 13 1 42) ""))))
> (list (make-file ".DS_Store" 6148 (make-date 2020 3 20 13 7 28) "")))
>
> *I am expecting to get this *
>
> (make-dir
> 'test
> (list
> (make-dir
> *'a*
> (list (make-dir *'docs* '() '()))
> (list (make-file ".DS_Store" 6148 (make-date 2020 3 20 13 7 33) "")
> (make-file "me.txt" 0 (make-date 2020 3 20 13 1 42) ""))))
> (list (make-file ".DS_Store" 6148 (make-date 2020 3 20 13 7 28) "")))

Ok, I see how that makes Exercise 339 more difficult. Thanks for
pointing this out.

In Racket, I would use `symbol->string` and `file-name-from-path` to
get the name.

In ISL, I'd use `symbol->string` and `string->list` to get started,
then design a function that takes takes all the characters after the
last #\/ character in a list (or all characters if there is no #\/)
Reply all
Reply to author
Forward
0 new messages