[Top][All Lists]

[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
    (walk root)))

(tree-seq 'file-directory-p
          (lambda (directory)
            (directory-files directory t))

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

                   (one 10))))

  (one (one 'a)))

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

Thanks in advance!


In Christ,

Timmy V. -- Spend less time on mail

reply via email to

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