Re: [racket-users] Help in understanding 'letrec' example

2021-05-14 Thread Utkarsh Singh
Hi David,

On 2021-05-13, 13:12 -0400, David Storrs  wrote:

> Incidentally, a more concise way of doing this would be:
>
> (define target (build-path "tarzan")) ; convert to path only once
> (for/or ([item (in-directory "/tmp/test")]) ; or whatever directory
> you want to start in
>   (equal? target (file-name-from-path item)))

Thanks! This looks good.

-- 
Utkarsh Singh
http://utkarshsingh.xyz

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/87sg2p759w.fsf%40gmail.com.


[racket-users] Re: Help in understanding 'letrec' example

2021-05-09 Thread Utkarsh Singh
Hi,

> We are finding a file (or directory) with name "tarzan" inside all
> directories inside given path upto given depth.
>
> Recursion is needed here, because  tarzan-near-top-of-tree? calls 
> tarzan-in-directory? and  tarzan-in-directory? calls 
> tarzan-near-top-of-tree? for each file in given directory.

Thanks! I finally understood it.

Here is the explanation (for reference):

Consider a sample directory called test with following structure (ASCII
art using 'tree' command):

test
├── dir1
│   └── subdir1
│   └── file1
└── dir2

Our code will first recursively search for all file in dir1 upto depth 4
and then move to dir2.  Using ormap insures that search for 'tarzan'
will stop at first match (or first true result).
-- 
Utkarsh Singh
http://utkarshsingh.xyz

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/87h7jcp6fm.fsf%40gmail.com.


[racket-users] Help in understanding 'letrec' example

2021-05-08 Thread Utkarsh Singh
Hi,

First of all I would like to thank Racket community for creating and
maintaining top quality documentation at https://docs.racket-lang.org/
and even providing a local copy for it.

Currently I am having some difficulties in understanding this letrec
example from Racket Guide docs
(https://docs.racket-lang.org/guide/let.html#%28part._.Recursive_.Binding__letrec%29):

(letrec ([tarzan-near-top-of-tree?
  (lambda (name path depth)
(or (equal? name "tarzan")
(and (directory-exists? path)
 (tarzan-in-directory? path depth]
 [tarzan-in-directory?
  (lambda (dir depth)
(cond
  [(zero? depth) #f]
  [else
   (ormap
(λ (elem)
  (tarzan-near-top-of-tree? (path-element->string elem)
(build-path dir elem)
(- depth 1)))
(directory-list dir))]))])
  (tarzan-near-top-of-tree? "tmp"
(find-system-path 'temp-dir)
4))

Problem:
I having some problem on how recursion is working here and what is the
problem we are solving here.  Are we finding a file with (name?
"tarzan") or something else?

-- 
Utkarsh Singh
http://utkarshsingh.xyz

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/87h7jdslzh.fsf%40gmail.com.