newLISP Fan Club

Forum => newLISP in the real world => Topic started by: csfreebird on April 11, 2014, 11:40:40 AM

Title: Pass one function to handle scanned file
Post by: csfreebird on April 11, 2014, 11:40:40 AM
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:

(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:

./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
Title: Re: Pass one function to handle scanned file
Post by: csfreebird on April 11, 2014, 12:00:30 PM
My bad, forgot to pass file-op to next call

   (recursive-access-dir (append dir-path nde "/") file-op)
Title: Re: Pass one function to handle scanned file
Post by: rickyboy on April 11, 2014, 12:11:11 PM
Should you change this:


(eval (list file-op nde))
To this?:


(file-op nde)
(Not to solve your original issue.  It's an extra consideration.  Cheers!)
Title: Re: Pass one function to handle scanned file
Post by: csfreebird on April 11, 2014, 05:52:50 PM
Yes, thanks. I changed it:

(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)))))