Some small correction from the imperative to a more functional style

after some reading of sicp
This commit is contained in:
Christian Egli 2010-03-19 17:35:33 +01:00
parent aa1a0daac2
commit 3a30bc763b
1 changed files with 14 additions and 13 deletions

View File

@ -257,17 +257,17 @@ a path to the current task."
(setq previous-level level) (setq previous-level level)
(setq resolved-tasks (append resolved-tasks (list task))))))) (setq resolved-tasks (append resolved-tasks (list task)))))))
(defun org-taskjuggler-assign-resource-ids (resources) (defun org-taskjuggler-assign-resource-ids (resources &optional unique-ids)
"Given a list of resources return the same list, assigning a "Given a list of resources return the same list, assigning a
unique id to each resource." unique id to each resource."
(let (unique-ids (cond
unique-id ((null resources) nil)
resource resolved-resources) (t
(dolist (resource resources resolved-resources) (let* ((resource (car resources))
(setq unique-id (org-taskjuggler-get-unique-id resource unique-ids)) (unique-id (org-taskjuggler-get-unique-id resource unique-ids)))
(push unique-id unique-ids)
(push (cons "unique-id" unique-id) resource) (push (cons "unique-id" unique-id) resource)
(setq resolved-resources (append resolved-resources (list resource)))))) (cons resource (org-taskjuggler-assign-resource-ids (cdr resources)
(cons unique-id unique-ids)))))))
(defun org-taskjuggler-resolve-dependencies (tasks) (defun org-taskjuggler-resolve-dependencies (tasks)
(let ((previous-level 0) (let ((previous-level 0)
@ -323,11 +323,12 @@ unique id to each resource."
(defun org-taskjuggler-find-task-with-id (id tasks) (defun org-taskjuggler-find-task-with-id (id tasks)
"Find ID in tasks. If found return the path of task. Otherwise return nil." "Find ID in tasks. If found return the path of task. Otherwise return nil."
(let ((task-id (cdr (assoc "ID" (car tasks))))
(path (cdr (assoc "path" (car tasks)))))
(cond (cond
((null tasks) nil) ((null tasks) nil)
((equal (cdr (assoc "ID" (car tasks))) id) ((equal task-id id) path)
(cdr (assoc "path" (car tasks)))) (t (org-taskjuggler-find-task-with-id id (cdr tasks))))))
(t (org-taskjuggler-find-task-with-id id (cdr tasks)))))
(defun org-taskjuggler-get-unique-id (item unique-ids) (defun org-taskjuggler-get-unique-id (item unique-ids)
"Return a unique id for an ITEM which can be a task or a resource. "Return a unique id for an ITEM which can be a task or a resource.