From 87f08a4e4da8bc3e2ef12bb500347bc7f7436d53 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Wed, 11 Mar 2026 16:19:40 -0500 Subject: [PATCH] xo-interpreter2: + nil + cons --- include/xo/object2/DList.hpp | 10 +++++++++- src/object2/DList.cpp | 18 +++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/include/xo/object2/DList.hpp b/include/xo/object2/DList.hpp index 01ef3eb..8009f7b 100644 --- a/include/xo/object2/DList.hpp +++ b/include/xo/object2/DList.hpp @@ -26,11 +26,14 @@ namespace xo { DList(xo::obj h, DList * r) : head_{h}, rest_{r} {} - /** sentinel for null list. + /** sentinel for null list. Idempotent. * Application code may prefer ListOps::nil() **/ static DList * _nil(); + /** like _nil(), but retrn fop wrapper **/ + static obj nil(); + /** list with first element @p car, * followed by contents of list @p cdr. * Shares structure with @p cdr @@ -40,6 +43,11 @@ namespace xo { obj car, DList * cdr); + /** like @c _cons(mm,car,cdr), but return fop wrapper **/ + static obj cons(obj mm, + obj car, + DList * cdr); + /** DList length is at least 1 **/ bool is_empty() const noexcept; /** DList models a finite sequence **/ diff --git a/src/object2/DList.cpp b/src/object2/DList.cpp index 25770d0..7ef06f3 100644 --- a/src/object2/DList.cpp +++ b/src/object2/DList.cpp @@ -17,7 +17,7 @@ namespace xo { using xo::print::APrintable; using xo::mm::AGCObject; using xo::facet::FacetRegistry; - using xo::facet::typeseq; + //using xo::facet::typeseq; namespace scm { static DList s_null(obj(), nullptr); @@ -28,6 +28,12 @@ namespace xo { return &s_null; } + obj + DList::nil() + { + return obj(_nil()); + } + DList * DList::_cons(obj mm, obj car, @@ -38,6 +44,14 @@ namespace xo { return new (mem) DList(car, cdr); } + obj + DList::cons(obj mm, + obj car, + DList * cdr) + { + return obj(_cons(mm, car, cdr)); + } + #ifdef OBSOLETE DList * DList::list(obj mm, @@ -137,8 +151,6 @@ namespace xo { obj elt = FacetRegistry::instance().variant(l->head_); - - assert(elt.data()); if (!pps->print_upto(elt))