From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tim Visher Newsgroups: gmane.emacs.help Subject: Generic `tree-seq` function definition? Date: Fri, 6 Sep 2013 10:00:27 -0400 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: ger.gmane.org 1378476087 28109 80.91.229.3 (6 Sep 2013 14:01:27 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 6 Sep 2013 14:01:27 +0000 (UTC) To: emacs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Sep 06 16:01:28 2013 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1VHwbI-0003eK-K0 for geh-help-gnu-emacs@m.gmane.org; Fri, 06 Sep 2013 16:01:28 +0200 Original-Received: from localhost ([::1]:37811 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VHwbI-0001kD-8n for geh-help-gnu-emacs@m.gmane.org; Fri, 06 Sep 2013 10:01:28 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44587) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VHwb1-0001jm-C5 for help-gnu-emacs@gnu.org; Fri, 06 Sep 2013 10:01:16 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VHwaz-0004lF-Sw for help-gnu-emacs@gnu.org; Fri, 06 Sep 2013 10:01:11 -0400 Original-Received: from mail-vc0-x229.google.com ([2607:f8b0:400c:c03::229]:42126) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VHwaz-0004l5-MR for help-gnu-emacs@gnu.org; Fri, 06 Sep 2013 10:01:09 -0400 Original-Received: by mail-vc0-f169.google.com with SMTP id ib11so2263723vcb.28 for ; Fri, 06 Sep 2013 07:01:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=9yA2Wo3f97mmkZ4P9B6LQS3RhPRc97DwCz6O03QUK4E=; b=QqVOUETPr+kyvDE52UwlvrwIkQ4pMHUmjZgS3WCtRjFSumuOQieq4ukZcI4jjbRKOv zCWnxvuxvr25Nw9avrafsuNoKEfa141GNLDYz2pFg1WmIhzXqrvSW13LOTzqewwkgWQC QYJy5RvGfz/tykz4YwKJhuBV/oQa05S7B12OjL2qjwimzqLCQ7TNsA2UlQjgwB7268c8 ykVxfi4wEKwnJRNbYyYpzs00rbOYFc0l4+zi2qkeaKjDWK0j10G6KmdwmN5dasU5Qu9n uJsSzvxZTZ5OzrhzFVV0DZ5ULU7GUfhb46Lqt7/zp0Yq4g1A5yHmN6/hx+OO3Ob+hEl2 zHpg== X-Received: by 10.221.44.136 with SMTP id ug8mr2478181vcb.13.1378476068735; Fri, 06 Sep 2013 07:01:08 -0700 (PDT) Original-Received: by 10.221.54.129 with HTTP; Fri, 6 Sep 2013 07:00:27 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400c:c03::229 X-Content-Filtered-By: Mailman/MimeDel 2.1.14 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:93292 Archived-At: 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