unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Generic `tree-seq` function definition?
@ 2013-09-06 14:00 Tim Visher
  0 siblings, 0 replies; 3+ messages in thread
From: Tim Visher @ 2013-09-06 14:00 UTC (permalink / raw)
  To: emacs

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Generic `tree-seq` function definition?
       [not found] <mailman.1476.1378476077.10748.help-gnu-emacs@gnu.org>
@ 2013-09-06 15:17 ` Stefan Monnier
  2013-09-06 16:05   ` Tim Visher
  0 siblings, 1 reply; 3+ messages in thread
From: Stefan Monnier @ 2013-09-06 15:17 UTC (permalink / raw)
  To: help-gnu-emacs

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

This is the `walk' symbol.  You want the `walk' function instead.
I.e. use #'walk


        Stefan


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Generic `tree-seq` function definition?
  2013-09-06 15:17 ` Generic `tree-seq` function definition? Stefan Monnier
@ 2013-09-06 16:05   ` Tim Visher
  0 siblings, 0 replies; 3+ messages in thread
From: Tim Visher @ 2013-09-06 16:05 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs

On Fri, Sep 6, 2013 at 11:17 AM, Stefan Monnier
<monnier@iro.umontreal.ca> wrote:
> > (defun tree-seq (branch? children root)
> >   (cl-labels ((walk (node)
> >                     (cons node
> >                           (if (funcall branch? node)
> >                               (cl-mapcan 'walk (cddr (funcall children
>                                            ^^^^^
>
> This is the `walk' symbol.  You want the `walk' function instead.
> I.e. use #'walk

Thank you!

--

In Christ,

Timmy V.

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



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-09-06 16:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.1476.1378476077.10748.help-gnu-emacs@gnu.org>
2013-09-06 15:17 ` Generic `tree-seq` function definition? Stefan Monnier
2013-09-06 16:05   ` Tim Visher
2013-09-06 14:00 Tim Visher

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).