Pass one function to handle scanned file

Q&A's, tips, howto's

Pass one function to handle scanned file

Postby csfreebird » Fri Apr 11, 2014 6:40 pm

Hi, I have one function from wiki to iterate folder tree recursively, It works fine. Then I want to modify it to accept a function as argument to handle the scanned file, I try function and macro, but failed. Below is my function version:
Code: Select all
(define (recursive-access-dir dir-path file-op)
  (println dir-path)
  (dolist (nde (directory dir-path {^[^.]}))
    (if (directory? (append dir-path nde))
   (recursive-access-dir (append dir-path nde "/"))
      (begin
       (println nde)
       (eval (list file-op nde)))))
  )
(recursive-access-dir "/home/dean/work/gitlab_cloud/newlisp/cppwizard/console/" println)
(exit)


I got error message:
Code: Select all
./test.lsp
newlisp armory home folder: /home/dean/github/newlisp_armory
/home/dean/work/gitlab_cloud/newlisp/cppwizard/console/
/home/dean/work/gitlab_cloud/newlisp/cppwizard/console/builder/
profile

ERR: invalid function : (nil "profile")
called from user defined function recursive-access-dir
called from user defined function recursive-access-dir
csfreebird
 
Posts: 107
Joined: Tue Jan 15, 2013 11:54 am
Location: China, Beijing

Re: Pass one function to handle scanned file

Postby csfreebird » Fri Apr 11, 2014 7:00 pm

My bad, forgot to pass file-op to next call
(recursive-access-dir (append dir-path nde "/") file-op)
csfreebird
 
Posts: 107
Joined: Tue Jan 15, 2013 11:54 am
Location: China, Beijing

Re: Pass one function to handle scanned file

Postby rickyboy » Fri Apr 11, 2014 7:11 pm

Should you change this:

Code: Select all
(eval (list file-op nde))

To this?:

Code: Select all
(file-op nde)

(Not to solve your original issue. It's an extra consideration. Cheers!)
(λx. x x) (λx. x x)
rickyboy
 
Posts: 587
Joined: Fri Apr 08, 2005 7:13 pm
Location: Front Royal, Virginia

Re: Pass one function to handle scanned file

Postby csfreebird » Sat Apr 12, 2014 12:52 am

Yes, thanks. I changed it:
Code: Select all
(define (recursive-access-dir dir-path file-op)
  (dolist (nde (directory dir-path {^[^.]}))
    (if (directory? (append dir-path nde))
   (recursive-access-dir (append dir-path nde "/") file-op)
       (file-op (append dir-path nde)))))
csfreebird
 
Posts: 107
Joined: Tue Jan 15, 2013 11:54 am
Location: China, Beijing


Return to newLISP in the real world

Who is online

Users browsing this forum: No registered users and 1 guest