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

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

Generic `tree-seq` function definition?


From: Tim Visher
Subject: Generic `tree-seq` function definition?
Date: Fri, 6 Sep 2013 10:00:27 -0400

Hey everyone,

I'm trying to implement a generic `tree-seq` function (like [the one found
in clojure][]).

It seems very straightforward and other than translating some things
between Clojure and Elisp seemed like it should've gone off without a hitch.

But it doesn't work.

Can anyone venture a guess as to why?

The basic thing that seems to fail is that cl-labels doesn't seem to know
how to drop a local function into a map operation. You can see that from
the `one` function. When one is called directly it returns correctly but
when you try to map it it blows up in the same way.

(defun tree-seq (branch? children root)
  (cl-labels ((walk (node)
                    (cons node
                          (if (funcall branch? node)
                              (cl-mapcan 'walk (cddr (funcall children
node)))))))
    (walk root)))

(tree-seq 'file-directory-p
          (lambda (directory)
            (directory-files directory t))
          "~/Dropbox/sensitive")


(cl-labels ((one (x)
                 (if (integerp x)
                     x

                   (one 10))))

  (one (one 'a)))

;;; Boom!
;; (cl-labels ((one (x)
;;                  (if (integerp x)
;;                      x
;;                    (cl-mapcar 'one '(10 11 12)))))
;;   (one (one 'a)))


https://gist.github.com/timvisher/6458093#file-sensitive-el-L31-L54

Thanks in advance!

--

In Christ,

Timmy V.

http://blog.twonegatives.com/
http://five.sentenc.es/ -- Spend less time on mail


reply via email to

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