On a separate note, your ":flatten" function gave me idea... it would be nice to be able to tell the debugger the variable that contains the array element count for dynamically allocated arrays (like telling "flatten" the fields that point to the prev/next element.) AM_COUNT and/or AM_CAPACITY in the snapshot I posted. With AM_COUNT the debugger could dynamically resize the array. good stuff
I am working on flatten to accept array-slices (the .. intrinsic).
Then you will be able to do stuff like
:f_(src,
list[0 .. :_.list_count-1]!
[array]
)
The "!" marks the end of the .. mapping, so it can be used as array inside the flatten.
Basically, in OO terms
type TFoo = class
Children: TList; // stores TFoo
Parent: TFoo;
end;
And then I need to find time for one more trick...
Imagine you are an a random child node, but want to see the entire Tree. So you need to follow up an unknown amount of parents
:f_( :f_(anychild, parent, [last]),
list[0 .. :_.list_count-1]!
[array]
)
And the "last" option should mean: Only return the last value found (as value, not as array). Since neither nil, nor err is in option, that should be the root node.
(This could be an intrinsic of its own, but it really has the same internals, so....)
And if TFoo is just the data node, and there is TFooWithChildren for nodes that have children, then you need typecasts. But you don't want to cast a leaf-node TFoo into a TFooWithChildren, because then you follow trash pointers. For that you can then use the existing :cc() intrinsic.