From: Christian Egli <christian.egli@alumni.ethz.ch>
To: emacs-orgmode@gnu.org
Subject: [PATCH 3/5] Replace recursive functions with iterative ones
Date: Wed, 16 Mar 2011 12:05:00 +0100 [thread overview]
Message-ID: <1300273502-12977-4-git-send-email-christian.egli@alumni.ethz.ch> (raw)
In-Reply-To: <1300273502-12977-1-git-send-email-christian.egli@alumni.ethz.ch>
* org-taskjuggler.el (org-taskjuggler-compute-task-leafiness):
(org-taskjuggler-assign-resource-ids): Replace recursive
implementation with an iterative one.
That way we can avoid to have ask users to increase
`max-lisp-eval-depth'.
---
lisp/org-taskjuggler.el | 48 ++++++++++++++++++++++++----------------------
1 files changed, 25 insertions(+), 23 deletions(-)
diff --git a/lisp/org-taskjuggler.el b/lisp/org-taskjuggler.el
index 2d16790..5b3f16f 100644
--- a/lisp/org-taskjuggler.el
+++ b/lisp/org-taskjuggler.el
@@ -397,31 +397,33 @@ a path to the current task."
"Figure out if each task is a leaf by looking at it's level,
and the level of its successor. If the successor is higher (ie
deeper), then it's not a leaf."
- (cond
- ((null tasks) nil)
- ;; if a task has no successors it is a leaf
- ((null (car (cdr tasks)))
- (cons (cons (cons "leaf-node" t) (car tasks))
- (org-taskjuggler-compute-task-leafiness (cdr tasks))))
- ;; if the successor has a lower level than task it is a leaf
- ((<= (cdr (assoc "level" (car (cdr tasks)))) (cdr (assoc "level" (car tasks))))
- (cons (cons (cons "leaf-node" t) (car tasks))
- (org-taskjuggler-compute-task-leafiness (cdr tasks))))
- ;; otherwise examine the rest of the tasks
- (t (cons (car tasks) (org-taskjuggler-compute-task-leafiness (cdr tasks))))))
-
-(defun org-taskjuggler-assign-resource-ids (resources &optional unique-ids)
+ (let (new-list)
+ (while (car tasks)
+ (let ((task (car tasks))
+ (successor (car (cdr tasks))))
+ (cond
+ ;; if a task has no successors it is a leaf
+ ((null successor)
+ (push (cons (cons "leaf-node" t) task) new-list))
+ ;; if the successor has a lower level than task it is a leaf
+ ((<= (cdr (assoc "level" successor)) (cdr (assoc "level" task)))
+ (push (cons (cons "leaf-node" t) task) new-list))
+ ;; otherwise examine the rest of the tasks
+ (t (push task new-list))))
+ (setq tasks (cdr tasks)))
+ (print new-list)
+ (nreverse new-list)))
+
+(defun org-taskjuggler-assign-resource-ids (resources)
"Given a list of resources return the same list, assigning a
unique id to each resource."
- (cond
- ((null resources) nil)
- (t
- (let* ((resource (car resources))
- (unique-id (org-taskjuggler-get-unique-id resource unique-ids)))
- (push (cons "unique-id" unique-id) resource)
- (cons resource
- (org-taskjuggler-assign-resource-ids (cdr resources)
- (cons unique-id unique-ids)))))))
+ (let (unique-ids new-list)
+ (dolist (resource resources new-list)
+ (let ((unique-id (org-taskjuggler-get-unique-id resource unique-ids)))
+ (push (cons "unique-id" unique-id) resource)
+ (push unique-id unique-ids)
+ (push resource new-list)))
+ (nreverse new-list)))
(defun org-taskjuggler-resolve-dependencies (tasks)
(let ((previous-level 0)
--
1.7.1
next prev parent reply other threads:[~2011-03-16 11:05 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-16 11:04 [PATCH 0/5] Improvements to Taskjuggler export Christian Egli
2011-03-16 11:04 ` [PATCH 1/5] Add some minimal infrastructure to handle export to both tj2 and tj3 Christian Egli
2011-03-17 8:44 ` [Accepted] [O, " Bastien Guerry
2011-03-17 8:59 ` [PATCH " Bastien
2011-03-17 10:39 ` Christian Egli
2011-03-17 10:56 ` Bastien
2011-03-16 11:04 ` [PATCH 2/5] Mark a task as a milestone if it is a leaf node and cannot be scheduled Christian Egli
2011-03-17 8:45 ` [Accepted] [O, " Bastien Guerry
2011-03-16 11:05 ` Christian Egli [this message]
2011-03-16 11:05 ` [PATCH 4/5] Remove a spurious debug statement Christian Egli
2011-03-16 11:05 ` [PATCH 5/5] Escape double quotes in headlines Christian Egli
2011-03-17 8:49 ` [Accepted] [O,5/5] " Bastien Guerry
2011-03-16 20:33 ` [PATCH 0/5] Improvements to Taskjuggler export Marc-Oliver Ihm
2011-03-17 8:57 ` Bastien
2011-03-17 20:47 ` Christian Egli
2011-03-17 20:46 ` Christian Egli
2011-03-17 8:56 ` Bastien
2011-03-17 10:42 ` Christian Egli
2011-03-17 10:58 ` Bastien
2011-03-18 7:54 ` Christian Egli
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1300273502-12977-4-git-send-email-christian.egli@alumni.ethz.ch \
--to=christian.egli@alumni.ethz.ch \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
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).