help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: elisp: returning a local variable


From: Buchs, Kevin
Subject: RE: elisp: returning a local variable
Date: Tue, 12 Mar 2013 15:41:05 -0500

I'm not accomplished in elisp, but it seems to me that you have
recognized the inherent attribute of a local variable. The return value
of your defun is the return value of the last form evaluated - which is
let. That returns the last form evaluated in it, which is dolist, which
explicitly returns nil (C-h f dolist). So, you have defined a function
that returns nil. I would suggest you might be able to follow (dolist
...) with (retval) to return your list. I assume you are wanting to
eliminate links and other special files, or otherwise you would just use
file-expand-wildcards alone.

I note how you declared the function (interactive), which causes me to
ask exactly what you mean by returning the list. Hopefully you are
calling get-all-subdirectories from another lisp function.

Kevin Buchs | Senior Engineer | SPPDG | 507-538-5459 |
buchs.kevin@mayo.edu
Mayo Clinic | 200 First Street SW | Rochester, MN 55905 |
http://www.mayo.edu

(defun get-all-subdirectories ()
  "Returns a list of directories in the current working folder"
  (interactive)
  (let ((src-list (file-expand-wildcards "*"))
        (retval ()))
    (dolist (fname src-list)
      (when (file-directory-p fname) (push fname retval))
      )
    )
  )     

Which does indeed assemble a list of subdirectories into retval, but I
can't figure out how to return it as the return value of the function
(yes, I could setq to global variable, but I prefer not to do this).



reply via email to

[Prev in Thread] Current Thread [Next in Thread]