From e68f4a854244d3454fbae67bbf43777813687c4a Mon Sep 17 00:00:00 2001 From: c-kloukinas Date: Fri, 24 Apr 2026 14:59:42 +0100 Subject: [PATCH] Add a test key to make-ptree to test its IDs (eg, equalp for string IDs). --- docs/src/Ptrees.md | 4 ++-- src/ptree.lisp | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/docs/src/Ptrees.md b/docs/src/Ptrees.md index b518493..d84b611 100644 --- a/docs/src/Ptrees.md +++ b/docs/src/Ptrees.md @@ -51,7 +51,7 @@ The underlying issue is that futures have no knowledge of the computation tree i Ptrees may be built dynamically as follows. ```lisp -(let ((tree (make-ptree))) +(let ((tree (make-ptree :test #'eq))) (ptree-fn 'area '(width height) (lambda (w h) (* w h)) tree) (ptree-fn 'width '(border) (lambda (b) (+ 7 (* 2 b))) tree) (ptree-fn 'height '(border) (lambda (b) (+ 5 (* 2 b))) tree) @@ -61,7 +61,7 @@ Ptrees may be built dynamically as follows. ; => 63 ``` -This code resembles the expansion of the ptree macro example above. Note that a node identifier need not be a symbol; any object suitable for eql comparison will do. +This code resembles the expansion of the ptree macro example above. Note that a node identifier need not be a symbol; any object suitable for `eq`/`eql`/`equal`/`equalp` (default is `eql`) comparison will do. clear-ptree restores the tree to its original uncomputed state. clear-ptree-errors restores to the last pre-error state. diff --git a/src/ptree.lisp b/src/ptree.lisp index aa93bd5..f02c9c2 100644 --- a/src/ptree.lisp +++ b/src/ptree.lisp @@ -239,9 +239,12 @@ "A ptree is a computation represented by a tree together with functionality to execute the tree in parallel.")) -(defun make-ptree () +(defun make-ptree ( &key (test #'eql) ) "Create a ptree instance." - (make-ptree-instance)) + (let ((p (make-ptree-instance))) + (with-ptree-slots (nodes) p + (setf nodes (make-hash-table :test test))) + p)) (defun/type compute-ptree (root ptree kernel) (node ptree kernel) node (declare #.*normal-optimize*)