xo-interpreter2: + nil + cons

This commit is contained in:
Roland Conybeare 2026-03-11 16:19:40 -05:00
commit 87f08a4e4d
2 changed files with 24 additions and 4 deletions

View file

@ -26,11 +26,14 @@ namespace xo {
DList(xo::obj<AGCObject> 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<AGCObject,DList> 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<AGCObject> car,
DList * cdr);
/** like @c _cons(mm,car,cdr), but return fop wrapper **/
static obj<AGCObject,DList> cons(obj<AAllocator> mm,
obj<AGCObject> car,
DList * cdr);
/** DList length is at least 1 **/
bool is_empty() const noexcept;
/** DList models a finite sequence **/

View file

@ -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<AGCObject>(), nullptr);
@ -28,6 +28,12 @@ namespace xo {
return &s_null;
}
obj<AGCObject,DList>
DList::nil()
{
return obj<AGCObject,DList>(_nil());
}
DList *
DList::_cons(obj<AAllocator> mm,
obj<AGCObject> car,
@ -38,6 +44,14 @@ namespace xo {
return new (mem) DList(car, cdr);
}
obj<AGCObject,DList>
DList::cons(obj<AAllocator> mm,
obj<AGCObject> car,
DList * cdr)
{
return obj<AGCObject,DList>(_cons(mm, car, cdr));
}
#ifdef OBSOLETE
DList *
DList::list(obj<AAllocator> mm,
@ -137,8 +151,6 @@ namespace xo {
obj<APrintable> elt
= FacetRegistry::instance().variant<APrintable, AGCObject>(l->head_);
assert(elt.data());
if (!pps->print_upto(elt))